Merge branch 'main' into chore/remove-end-override

pull/30/head
Allison Ryan 4 years ago committed by GitHub
commit 587c228912
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1 @@
include: package:very_good_analysis/analysis_options.2.4.0.yaml include: package:very_good_analysis/analysis_options.2.4.0.yaml
linter:
rules:
public_member_api_docs: false

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

@ -5,6 +5,8 @@
// license that can be found in the LICENSE file or at // license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT. // https://opensource.org/licenses/MIT.
// ignore_for_file: public_member_api_docs
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:pinball/l10n/l10n.dart'; import 'package:pinball/l10n/l10n.dart';

@ -5,6 +5,8 @@
// license that can be found in the LICENSE file or at // license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT. // https://opensource.org/licenses/MIT.
// ignore_for_file: public_member_api_docs
import 'dart:async'; import 'dart:async';
import 'dart:developer'; import 'dart:developer';

@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';

@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs
part of 'game_bloc.dart'; part of 'game_bloc.dart';
@immutable @immutable
@ -5,16 +7,22 @@ abstract class GameEvent extends Equatable {
const GameEvent(); const GameEvent();
} }
/// {@template ball_lost_game_event}
/// Event added when a user drops a ball off the screen. /// Event added when a user drops a ball off the screen.
/// {@endtemplate}
class BallLost extends GameEvent { class BallLost extends GameEvent {
/// {@macro ball_lost_game_event}
const BallLost(); const BallLost();
@override @override
List<Object?> get props => []; List<Object?> get props => [];
} }
/// {@template scored_game_event}
/// Event added when a user increases their score. /// Event added when a user increases their score.
/// {@endtemplate}
class Scored extends GameEvent { class Scored extends GameEvent {
/// {@macro scored_game_event}
const Scored({ const Scored({
required this.points, required this.points,
}) : assert(points > 0, 'Points must be greater than 0'); }) : assert(points > 0, 'Points must be greater than 0');

@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs
part of 'game_bloc.dart'; part of 'game_bloc.dart';
/// {@template game_state} /// {@template game_state}

@ -3,29 +3,36 @@ import 'package:flame_bloc/flame_bloc.dart';
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
/// {@template ball}
/// A solid, [BodyType.dynamic] sphere that rolls and bounces along the
/// [PinballGame].
/// {@endtemplate}
class Ball extends PositionBodyComponent<PinballGame, SpriteComponent> class Ball extends PositionBodyComponent<PinballGame, SpriteComponent>
with BlocComponent<GameBloc, GameState> { with BlocComponent<GameBloc, GameState> {
/// {@macro ball}
Ball({ Ball({
required Vector2 position, required Vector2 position,
}) : _position = position, }) : _position = position,
super(size: ballSize); super(size: Vector2.all(2));
static final ballSize = Vector2.all(2);
/// The initial position of the [Ball] body.
final Vector2 _position; final Vector2 _position;
/// Asset location of the sprite that renders with the [Ball].
///
/// Sprite is preloaded by [PinballGameAssetsX].
static const spritePath = 'components/ball.png'; static const spritePath = 'components/ball.png';
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
final sprite = await gameRef.loadSprite(spritePath); final sprite = await gameRef.loadSprite(spritePath);
positionComponent = SpriteComponent(sprite: sprite, size: ballSize); positionComponent = SpriteComponent(sprite: sprite, size: size);
} }
@override @override
Body createBody() { Body createBody() {
final shape = CircleShape()..radius = ballSize.x / 2; final shape = CircleShape()..radius = size.x / 2;
final fixtureDef = FixtureDef(shape)..density = 1; final fixtureDef = FixtureDef(shape)..density = 1;
@ -37,6 +44,11 @@ class Ball extends PositionBodyComponent<PinballGame, SpriteComponent>
return world.createBody(bodyDef)..createFixture(fixtureDef); return world.createBody(bodyDef)..createFixture(fixtureDef);
} }
/// Removes the [Ball] from a [PinballGame]; spawning a new [Ball] if
/// any are left.
///
/// Triggered by [BottomWallBallContactCallback] when the [Ball] falls into
/// a [BottomWall].
void lost() { void lost() {
shouldRemove = true; shouldRemove = true;

@ -1,9 +1,9 @@
import 'dart:async'; import 'dart:async';
import 'dart:math' as math; import 'dart:math' as math;
import 'package:flame/components.dart' show SpriteComponent;
import 'package:flame/input.dart'; import 'package:flame/input.dart';
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
@ -12,19 +12,15 @@ import 'package:pinball/game/game.dart';
/// ///
/// [Flipper] can be controlled by the player in an arc motion. /// [Flipper] can be controlled by the player in an arc motion.
/// {@endtemplate flipper} /// {@endtemplate flipper}
class Flipper extends BodyComponent with KeyboardHandler { class Flipper extends PositionBodyComponent with KeyboardHandler {
/// {@macro flipper} /// {@macro flipper}
Flipper._({ Flipper._({
required Vector2 position, required Vector2 position,
required this.side, required this.side,
required List<LogicalKeyboardKey> keys, required List<LogicalKeyboardKey> keys,
}) : _position = position, }) : _position = position,
_keys = keys { _keys = keys,
// TODO(alestiago): Use sprite instead of color when provided. super(size: Vector2(width, height));
paint = Paint()
..color = const Color(0xFF00FF00)
..style = PaintingStyle.fill;
}
/// A left positioned [Flipper]. /// A left positioned [Flipper].
Flipper.left({ Flipper.left({
@ -50,6 +46,11 @@ class Flipper extends BodyComponent with KeyboardHandler {
], ],
); );
/// Asset location of the sprite that renders with the [Flipper].
///
/// Sprite is preloaded by [PinballGameAssetsX].
static const spritePath = 'components/flipper.png';
/// The width of the [Flipper]. /// The width of the [Flipper].
static const width = 12.0; static const width = 12.0;
@ -75,6 +76,20 @@ class Flipper extends BodyComponent with KeyboardHandler {
/// [onKeyEvent] method listens to when one of these keys is pressed. /// [onKeyEvent] method listens to when one of these keys is pressed.
final List<LogicalKeyboardKey> _keys; final List<LogicalKeyboardKey> _keys;
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite(spritePath);
positionComponent = SpriteComponent(
sprite: sprite,
size: size,
);
if (side == BoardSide.right) {
positionComponent?.flipHorizontally();
}
}
/// Applies downward linear velocity to the [Flipper], moving it to its /// Applies downward linear velocity to the [Flipper], moving it to its
/// resting position. /// resting position.
void _moveDown() { void _moveDown() {
@ -148,6 +163,7 @@ class Flipper extends BodyComponent with KeyboardHandler {
// TODO(erickzanardo): Remove this once the issue is solved: // TODO(erickzanardo): Remove this once the issue is solved:
// https://github.com/flame-engine/flame/issues/1417 // https://github.com/flame-engine/flame/issues/1417
// ignore: public_member_api_docs
final Completer hasMounted = Completer<void>(); final Completer hasMounted = Completer<void>();
@override @override

@ -6,13 +6,18 @@ import 'package:pinball/game/components/components.dart';
/// {@template wall} /// {@template wall}
/// A continuos generic and [BodyType.static] barrier that divides a game area. /// A continuos generic and [BodyType.static] barrier that divides a game area.
/// {@endtemplate} /// {@endtemplate}
// TODO(alestiago): Remove [Wall] for [Pathway.straight].
class Wall extends BodyComponent { class Wall extends BodyComponent {
/// {@macro wall}
Wall({ Wall({
required this.start, required this.start,
required this.end, required this.end,
}); });
/// The [start] of the [Wall].
final Vector2 start; final Vector2 start;
/// The [end] of the [Wall].
final Vector2 end; final Vector2 end;
@override @override
@ -39,6 +44,7 @@ class Wall extends BodyComponent {
/// [BottomWallBallContactCallback]. /// [BottomWallBallContactCallback].
/// {@endtemplate} /// {@endtemplate}
class BottomWall extends Wall { class BottomWall extends Wall {
/// {@macro bottom_wall}
BottomWall(Forge2DGame game) BottomWall(Forge2DGame game)
: super( : super(
start: game.screenToWorld(game.camera.viewport.effectiveSize), start: game.screenToWorld(game.camera.viewport.effectiveSize),

@ -6,6 +6,7 @@ extension PinballGameAssetsX on PinballGame {
Future<void> preLoadAssets() async { Future<void> preLoadAssets() async {
await Future.wait([ await Future.wait([
images.load(Ball.spritePath), images.load(Ball.spritePath),
images.load(Flipper.spritePath),
]); ]);
} }
} }

@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs
import 'dart:async'; import 'dart:async';
import 'package:flame/input.dart'; import 'package:flame/input.dart';
import 'package:flame_bloc/flame_bloc.dart'; import 'package:flame_bloc/flame_bloc.dart';

@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs
import 'package:flame/game.dart'; import 'package:flame/game.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';

@ -1,6 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pinball/game/game.dart';
/// {@template game_over_dialog}
/// [Dialog] displayed when the [PinballGame] is over.
/// {@endtemplate}
class GameOverDialog extends StatelessWidget { class GameOverDialog extends StatelessWidget {
/// {@macro game_over_dialog}
const GameOverDialog({Key? key}) : super(key: key); const GameOverDialog({Key? key}) : super(key: key);
@override @override

@ -5,6 +5,8 @@
// license that can be found in the LICENSE file or at // license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT. // https://opensource.org/licenses/MIT.
// ignore_for_file: public_member_api_docs
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';

@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
import 'package:pinball/l10n/l10n.dart'; import 'package:pinball/l10n/l10n.dart';

@ -1,3 +1,6 @@
// ignore_for_file: public_member_api_docs
// TODO(allisonryan0002): Document this section when the API is stable.
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:pinball_theme/pinball_theme.dart'; import 'package:pinball_theme/pinball_theme.dart';

@ -1,3 +1,6 @@
// ignore_for_file: public_member_api_docs
// TODO(allisonryan0002): Document this section when the API is stable.
part of 'theme_cubit.dart'; part of 'theme_cubit.dart';
class ThemeState extends Equatable { class ThemeState extends Equatable {

@ -15,6 +15,7 @@ void main() {
'loads correctly', 'loads correctly',
(game) async { (game) async {
final anchor = Anchor(position: Vector2.zero()); final anchor = Anchor(position: Vector2.zero());
await game.ready();
await game.ensureAdd(anchor); await game.ensureAdd(anchor);
expect(game.contains(anchor), isTrue); expect(game.contains(anchor), isTrue);
@ -25,6 +26,7 @@ void main() {
flameTester.test( flameTester.test(
'positions correctly', 'positions correctly',
(game) async { (game) async {
await game.ready();
final position = Vector2.all(10); final position = Vector2.all(10);
final anchor = Anchor(position: position); final anchor = Anchor(position: position);
await game.ensureAdd(anchor); await game.ensureAdd(anchor);
@ -37,6 +39,7 @@ void main() {
flameTester.test( flameTester.test(
'is static', 'is static',
(game) async { (game) async {
await game.ready();
final anchor = Anchor(position: Vector2.zero()); final anchor = Anchor(position: Vector2.zero());
await game.ensureAdd(anchor); await game.ensureAdd(anchor);

@ -18,6 +18,7 @@ void main() {
flameTester.test( flameTester.test(
'has transparent color by default when no color is specified', 'has transparent color by default when no color is specified',
(game) async { (game) async {
await game.ready();
final pathway = Pathway.straight( final pathway = Pathway.straight(
position: Vector2.zero(), position: Vector2.zero(),
start: Vector2(10, 10), start: Vector2(10, 10),
@ -38,6 +39,7 @@ void main() {
flameTester.test( flameTester.test(
'has a color when is specified', 'has a color when is specified',
(game) async { (game) async {
await game.ready();
const defaultColor = Colors.blue; const defaultColor = Colors.blue;
final pathway = Pathway.straight( final pathway = Pathway.straight(
@ -59,6 +61,7 @@ void main() {
flameTester.test( flameTester.test(
'loads correctly', 'loads correctly',
(game) async { (game) async {
await game.ready();
final pathway = Pathway.straight( final pathway = Pathway.straight(
position: Vector2.zero(), position: Vector2.zero(),
start: Vector2(10, 10), start: Vector2(10, 10),
@ -75,6 +78,7 @@ void main() {
flameTester.test( flameTester.test(
'positions correctly', 'positions correctly',
(game) async { (game) async {
await game.ready();
final position = Vector2.all(10); final position = Vector2.all(10);
final pathway = Pathway.straight( final pathway = Pathway.straight(
position: position, position: position,
@ -92,6 +96,7 @@ void main() {
flameTester.test( flameTester.test(
'is static', 'is static',
(game) async { (game) async {
await game.ready();
final pathway = Pathway.straight( final pathway = Pathway.straight(
position: Vector2.zero(), position: Vector2.zero(),
start: Vector2(10, 10), start: Vector2(10, 10),
@ -109,6 +114,7 @@ void main() {
flameTester.test( flameTester.test(
'has only one ChainShape when singleWall is true', 'has only one ChainShape when singleWall is true',
(game) async { (game) async {
await game.ready();
final pathway = Pathway.straight( final pathway = Pathway.straight(
position: Vector2.zero(), position: Vector2.zero(),
start: Vector2(10, 10), start: Vector2(10, 10),
@ -128,6 +134,7 @@ void main() {
flameTester.test( flameTester.test(
'has two ChainShape when singleWall is false (default)', 'has two ChainShape when singleWall is false (default)',
(game) async { (game) async {
await game.ready();
final pathway = Pathway.straight( final pathway = Pathway.straight(
position: Vector2.zero(), position: Vector2.zero(),
start: Vector2(10, 10), start: Vector2(10, 10),
@ -150,6 +157,7 @@ void main() {
flameTester.test( flameTester.test(
'loads correctly', 'loads correctly',
(game) async { (game) async {
await game.ready();
final pathway = Pathway.arc( final pathway = Pathway.arc(
position: Vector2.zero(), position: Vector2.zero(),
width: width, width: width,
@ -166,6 +174,7 @@ void main() {
flameTester.test( flameTester.test(
'positions correctly', 'positions correctly',
(game) async { (game) async {
await game.ready();
final position = Vector2.all(10); final position = Vector2.all(10);
final pathway = Pathway.arc( final pathway = Pathway.arc(
position: position, position: position,
@ -183,6 +192,7 @@ void main() {
flameTester.test( flameTester.test(
'is static', 'is static',
(game) async { (game) async {
await game.ready();
final pathway = Pathway.arc( final pathway = Pathway.arc(
position: Vector2.zero(), position: Vector2.zero(),
width: width, width: width,
@ -208,6 +218,7 @@ void main() {
flameTester.test( flameTester.test(
'loads correctly', 'loads correctly',
(game) async { (game) async {
await game.ready();
final pathway = Pathway.bezierCurve( final pathway = Pathway.bezierCurve(
position: Vector2.zero(), position: Vector2.zero(),
controlPoints: controlPoints, controlPoints: controlPoints,
@ -223,6 +234,7 @@ void main() {
flameTester.test( flameTester.test(
'positions correctly', 'positions correctly',
(game) async { (game) async {
await game.ready();
final position = Vector2.all(10); final position = Vector2.all(10);
final pathway = Pathway.bezierCurve( final pathway = Pathway.bezierCurve(
position: position, position: position,
@ -239,6 +251,7 @@ void main() {
flameTester.test( flameTester.test(
'is static', 'is static',
(game) async { (game) async {
await game.ready();
final pathway = Pathway.bezierCurve( final pathway = Pathway.bezierCurve(
position: Vector2.zero(), position: Vector2.zero(),
controlPoints: controlPoints, controlPoints: controlPoints,

@ -16,6 +16,7 @@ void main() {
flameTester.test( flameTester.test(
'loads correctly', 'loads correctly',
(game) async { (game) async {
await game.ready();
final plunger = Plunger(position: Vector2.zero()); final plunger = Plunger(position: Vector2.zero());
await game.ensureAdd(plunger); await game.ensureAdd(plunger);

@ -37,6 +37,7 @@ void main() {
flameTester.test( flameTester.test(
'loads correctly', 'loads correctly',
(game) async { (game) async {
await game.ready();
final wall = Wall( final wall = Wall(
start: Vector2.zero(), start: Vector2.zero(),
end: Vector2(100, 0), end: Vector2(100, 0),

Loading…
Cancel
Save