diff --git a/lib/game/bloc/game_state.dart b/lib/game/bloc/game_state.dart index c45da958..8fcab789 100644 --- a/lib/game/bloc/game_state.dart +++ b/lib/game/bloc/game_state.dart @@ -5,7 +5,7 @@ enum GameBonus { /// Bonus achieved when the ball activates all Google letters. googleWord, - /// Bonus achieved when the user activates all dash nest bumpers. + /// Bonus achieved when the user activates all dash bumpers. dashNest, /// Bonus achieved when a ball enters Sparky's computer. diff --git a/lib/game/components/flutter_forest/behaviors/flutter_forest_bonus_behavior.dart b/lib/game/components/flutter_forest/behaviors/flutter_forest_bonus_behavior.dart index bf1b52c4..3c4ef02a 100644 --- a/lib/game/components/flutter_forest/behaviors/flutter_forest_bonus_behavior.dart +++ b/lib/game/components/flutter_forest/behaviors/flutter_forest_bonus_behavior.dart @@ -7,9 +7,9 @@ import 'package:pinball_flame/pinball_flame.dart'; /// Bonus obtained at the [FlutterForest]. /// -/// When all [DashNestBumper]s are hit at least once three times, the [Signpost] +/// When all [DashBumper]s are hit at least once three times, the [Signpost] /// progresses. When the [Signpost] fully progresses, the [GameBonus.dashNest] -/// is awarded, and the [DashNestBumper.main] releases a new [Ball]. +/// is awarded, and the [DashBumper.main] releases a new [Ball]. class FlutterForestBonusBehavior extends Component with ParentIsA, @@ -19,14 +19,14 @@ class FlutterForestBonusBehavior extends Component void onMount() { super.onMount(); - final bumpers = parent.children.whereType(); + final bumpers = parent.children.whereType(); final signpost = parent.firstChild()!; final animatronic = parent.firstChild()!; for (final bumper in bumpers) { bumper.bloc.stream.listen((state) { final activatedAllBumpers = bumpers.every( - (bumper) => bumper.bloc.state == DashNestBumperState.active, + (bumper) => bumper.bloc.state == DashBumperState.active, ); if (activatedAllBumpers) { diff --git a/lib/game/components/flutter_forest/flutter_forest.dart b/lib/game/components/flutter_forest/flutter_forest.dart index 1cc055ae..39783bb1 100644 --- a/lib/game/components/flutter_forest/flutter_forest.dart +++ b/lib/game/components/flutter_forest/flutter_forest.dart @@ -9,7 +9,7 @@ import 'package:pinball_flame/pinball_flame.dart'; /// {@template flutter_forest} /// Area positioned at the top right of the board where the [Ball] can bounce -/// off [DashNestBumper]s. +/// off [DashBumper]s. /// {@endtemplate} class FlutterForest extends Component with ZIndex { /// {@macro flutter_forest} @@ -22,19 +22,19 @@ class FlutterForest extends Component with ZIndex { BumperNoiseBehavior(), ], )..initialPosition = Vector2(7.95, -58.35), - DashNestBumper.main( + DashBumper.main( children: [ ScoringContactBehavior(points: Points.twoHundredThousand), BumperNoiseBehavior(), ], )..initialPosition = Vector2(18.55, -59.35), - DashNestBumper.a( + DashBumper.a( children: [ ScoringContactBehavior(points: Points.twentyThousand), BumperNoiseBehavior(), ], )..initialPosition = Vector2(8.95, -51.95), - DashNestBumper.b( + DashBumper.b( children: [ ScoringContactBehavior(points: Points.twentyThousand), BumperNoiseBehavior(), diff --git a/packages/pinball_components/lib/src/components/components.dart b/packages/pinball_components/lib/src/components/components.dart index 2f420181..3e8d0db5 100644 --- a/packages/pinball_components/lib/src/components/components.dart +++ b/packages/pinball_components/lib/src/components/components.dart @@ -10,7 +10,7 @@ export 'boundaries.dart'; export 'camera_zoom.dart'; export 'chrome_dino/chrome_dino.dart'; export 'dash_animatronic.dart'; -export 'dash_nest_bumper/dash_nest_bumper.dart'; +export 'dash_bumper/dash_bumper.dart'; export 'dino_walls.dart'; export 'error_component.dart'; export 'fire_effect.dart'; diff --git a/packages/pinball_components/lib/src/components/dash_animatronic.dart b/packages/pinball_components/lib/src/components/dash_animatronic.dart index faa604e9..bb7d983b 100644 --- a/packages/pinball_components/lib/src/components/dash_animatronic.dart +++ b/packages/pinball_components/lib/src/components/dash_animatronic.dart @@ -2,7 +2,7 @@ import 'package:flame/components.dart'; import 'package:pinball_components/pinball_components.dart'; /// {@template dash_animatronic} -/// Animated Dash that sits on top of the [DashNestBumper.main]. +/// Animated Dash that sits on top of the [DashBumper.main]. /// {@endtemplate} class DashAnimatronic extends SpriteAnimationComponent with HasGameRef { /// {@macro dash_animatronic} diff --git a/packages/pinball_components/lib/src/components/dash_bumper/behaviors/behaviors.dart b/packages/pinball_components/lib/src/components/dash_bumper/behaviors/behaviors.dart new file mode 100644 index 00000000..0167887f --- /dev/null +++ b/packages/pinball_components/lib/src/components/dash_bumper/behaviors/behaviors.dart @@ -0,0 +1 @@ +export 'dash_bumper_ball_contact_behavior.dart'; diff --git a/packages/pinball_components/lib/src/components/dash_nest_bumper/behaviors/dash_nest_bumper_contact_behavior.dart b/packages/pinball_components/lib/src/components/dash_bumper/behaviors/dash_bumper_ball_contact_behavior.dart similarity index 79% rename from packages/pinball_components/lib/src/components/dash_nest_bumper/behaviors/dash_nest_bumper_contact_behavior.dart rename to packages/pinball_components/lib/src/components/dash_bumper/behaviors/dash_bumper_ball_contact_behavior.dart index 934adef6..d147515c 100644 --- a/packages/pinball_components/lib/src/components/dash_nest_bumper/behaviors/dash_nest_bumper_contact_behavior.dart +++ b/packages/pinball_components/lib/src/components/dash_bumper/behaviors/dash_bumper_ball_contact_behavior.dart @@ -2,8 +2,7 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_flame/pinball_flame.dart'; -class DashNestBumperBallContactBehavior - extends ContactBehavior { +class DashBumperBallContactBehavior extends ContactBehavior { @override void beginContact(Object other, Contact contact) { super.beginContact(other, contact); diff --git a/packages/pinball_components/lib/src/components/dash_bumper/cubit/dash_bumper_cubit.dart b/packages/pinball_components/lib/src/components/dash_bumper/cubit/dash_bumper_cubit.dart new file mode 100644 index 00000000..84e626c4 --- /dev/null +++ b/packages/pinball_components/lib/src/components/dash_bumper/cubit/dash_bumper_cubit.dart @@ -0,0 +1,17 @@ +import 'package:bloc/bloc.dart'; + +part 'dash_bumper_state.dart'; + +class DashBumperCubit extends Cubit { + DashBumperCubit() : super(DashBumperState.inactive); + + /// Event added when the bumper contacts with a ball. + void onBallContacted() { + emit(DashBumperState.active); + } + + /// Event added when the bumper should return to its initial configuration. + void onReset() { + emit(DashBumperState.inactive); + } +} diff --git a/packages/pinball_components/lib/src/components/dash_bumper/cubit/dash_bumper_state.dart b/packages/pinball_components/lib/src/components/dash_bumper/cubit/dash_bumper_state.dart new file mode 100644 index 00000000..f15d2e57 --- /dev/null +++ b/packages/pinball_components/lib/src/components/dash_bumper/cubit/dash_bumper_state.dart @@ -0,0 +1,10 @@ +part of 'dash_bumper_cubit.dart'; + +/// Indicates the [DashBumperCubit]'s current state. +enum DashBumperState { + /// A lit up bumper. + active, + + /// A dimmed bumper. + inactive, +} diff --git a/packages/pinball_components/lib/src/components/dash_nest_bumper/dash_nest_bumper.dart b/packages/pinball_components/lib/src/components/dash_bumper/dash_bumper.dart similarity index 70% rename from packages/pinball_components/lib/src/components/dash_nest_bumper/dash_nest_bumper.dart rename to packages/pinball_components/lib/src/components/dash_bumper/dash_bumper.dart index d657c485..1b960610 100644 --- a/packages/pinball_components/lib/src/components/dash_nest_bumper/dash_nest_bumper.dart +++ b/packages/pinball_components/lib/src/components/dash_bumper/dash_bumper.dart @@ -5,17 +5,17 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flutter/material.dart'; import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/src/components/bumping_behavior.dart'; -import 'package:pinball_components/src/components/dash_nest_bumper/behaviors/behaviors.dart'; +import 'package:pinball_components/src/components/dash_bumper/behaviors/behaviors.dart'; import 'package:pinball_flame/pinball_flame.dart'; -export 'cubit/dash_nest_bumper_cubit.dart'; +export 'cubit/dash_bumper_cubit.dart'; -/// {@template dash_nest_bumper} -/// Bumper with a nest appearance. +/// {@template dash_bumper} +/// Bumper for the flutter forest. /// {@endtemplate} -class DashNestBumper extends BodyComponent with InitialPosition { - /// {@macro dash_nest_bumper} - DashNestBumper._({ +class DashBumper extends BodyComponent with InitialPosition { + /// {@macro dash_bumper} + DashBumper._({ required double majorRadius, required double minorRadius, required String activeAssetPath, @@ -28,19 +28,22 @@ class DashNestBumper extends BodyComponent with InitialPosition { super( renderBody: false, children: [ - _DashNestBumperSpriteGroupComponent( + _DashBumperSpriteGroupComponent( activeAssetPath: activeAssetPath, inactiveAssetPath: inactiveAssetPath, position: spritePosition, current: bloc.state, ), - DashNestBumperBallContactBehavior(), + DashBumperBallContactBehavior(), ...?children, ], ); - /// {@macro dash_nest_bumper} - DashNestBumper.main({ + /// {@macro dash_bumper} + /// + /// [DashBumper.main], usually positioned with a [DashAnimatronic] on top of + /// it. + DashBumper.main({ Iterable? children, }) : this._( majorRadius: 5.1, @@ -48,15 +51,18 @@ class DashNestBumper extends BodyComponent with InitialPosition { activeAssetPath: Assets.images.dash.bumper.main.active.keyName, inactiveAssetPath: Assets.images.dash.bumper.main.inactive.keyName, spritePosition: Vector2(0, -0.3), - bloc: DashNestBumperCubit(), + bloc: DashBumperCubit(), children: [ ...?children, BumpingBehavior(strength: 20), ], ); - /// {@macro dash_nest_bumper} - DashNestBumper.a({ + /// {@macro dash_bumper} + /// + /// [DashBumper.a] is positioned at the right side of the [DashBumper.main] in + /// the flutter forest. + DashBumper.a({ Iterable? children, }) : this._( majorRadius: 3, @@ -64,15 +70,18 @@ class DashNestBumper extends BodyComponent with InitialPosition { activeAssetPath: Assets.images.dash.bumper.a.active.keyName, inactiveAssetPath: Assets.images.dash.bumper.a.inactive.keyName, spritePosition: Vector2(0.3, -1.3), - bloc: DashNestBumperCubit(), + bloc: DashBumperCubit(), children: [ ...?children, BumpingBehavior(strength: 20), ], ); - /// {@macro dash_nest_bumper} - DashNestBumper.b({ + /// {@macro dash_bumper} + /// + /// [DashBumper.b] is positioned at the left side of the [DashBumper.main] in + /// the flutter forest. + DashBumper.b({ Iterable? children, }) : this._( majorRadius: 3.1, @@ -80,25 +89,26 @@ class DashNestBumper extends BodyComponent with InitialPosition { activeAssetPath: Assets.images.dash.bumper.b.active.keyName, inactiveAssetPath: Assets.images.dash.bumper.b.inactive.keyName, spritePosition: Vector2(0.4, -1.2), - bloc: DashNestBumperCubit(), + bloc: DashBumperCubit(), children: [ ...?children, BumpingBehavior(strength: 20), ], ); - /// Creates an [DashNestBumper] without any children. + /// Creates a [DashBumper] without any children. /// - /// This can be used for testing [DashNestBumper]'s behaviors in isolation. + /// This can be used for testing [DashBumper]'s behaviors in isolation. @visibleForTesting - DashNestBumper.test({required this.bloc}) + DashBumper.test({required this.bloc}) : _majorRadius = 3, _minorRadius = 2.5; final double _majorRadius; final double _minorRadius; - final DashNestBumperCubit bloc; + // ignore: public_member_api_docs + final DashBumperCubit bloc; @override void onRemove() { @@ -121,14 +131,14 @@ class DashNestBumper extends BodyComponent with InitialPosition { } } -class _DashNestBumperSpriteGroupComponent - extends SpriteGroupComponent - with HasGameRef, ParentIsA { - _DashNestBumperSpriteGroupComponent({ +class _DashBumperSpriteGroupComponent + extends SpriteGroupComponent + with HasGameRef, ParentIsA { + _DashBumperSpriteGroupComponent({ required String activeAssetPath, required String inactiveAssetPath, required Vector2 position, - required DashNestBumperState current, + required DashBumperState current, }) : _activeAssetPath = activeAssetPath, _inactiveAssetPath = inactiveAssetPath, super( @@ -146,9 +156,9 @@ class _DashNestBumperSpriteGroupComponent parent.bloc.stream.listen((state) => current = state); final sprites = { - DashNestBumperState.active: + DashBumperState.active: Sprite(gameRef.images.fromCache(_activeAssetPath)), - DashNestBumperState.inactive: + DashBumperState.inactive: Sprite(gameRef.images.fromCache(_inactiveAssetPath)), }; this.sprites = sprites; diff --git a/packages/pinball_components/lib/src/components/dash_nest_bumper/behaviors/behaviors.dart b/packages/pinball_components/lib/src/components/dash_nest_bumper/behaviors/behaviors.dart deleted file mode 100644 index 839cbd67..00000000 --- a/packages/pinball_components/lib/src/components/dash_nest_bumper/behaviors/behaviors.dart +++ /dev/null @@ -1 +0,0 @@ -export 'dash_nest_bumper_contact_behavior.dart'; diff --git a/packages/pinball_components/lib/src/components/dash_nest_bumper/cubit/dash_nest_bumper_cubit.dart b/packages/pinball_components/lib/src/components/dash_nest_bumper/cubit/dash_nest_bumper_cubit.dart deleted file mode 100644 index 04d511a4..00000000 --- a/packages/pinball_components/lib/src/components/dash_nest_bumper/cubit/dash_nest_bumper_cubit.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:bloc/bloc.dart'; - -part 'dash_nest_bumper_state.dart'; - -class DashNestBumperCubit extends Cubit { - DashNestBumperCubit() : super(DashNestBumperState.inactive); - - /// Event added when the bumper contacts with a ball. - void onBallContacted() { - emit(DashNestBumperState.active); - } - - /// Event added when the bumper should return to its initial configuration. - void onReset() { - emit(DashNestBumperState.inactive); - } -} diff --git a/packages/pinball_components/lib/src/components/dash_nest_bumper/cubit/dash_nest_bumper_state.dart b/packages/pinball_components/lib/src/components/dash_nest_bumper/cubit/dash_nest_bumper_state.dart deleted file mode 100644 index c169069f..00000000 --- a/packages/pinball_components/lib/src/components/dash_nest_bumper/cubit/dash_nest_bumper_state.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'dash_nest_bumper_cubit.dart'; - -/// Indicates the [DashNestBumperCubit]'s current state. -enum DashNestBumperState { - /// A lit up bumper. - active, - - /// A dimmed bumper. - inactive, -} diff --git a/packages/pinball_components/lib/src/components/signpost/signpost.dart b/packages/pinball_components/lib/src/components/signpost/signpost.dart index 115f1845..3ba486c1 100644 --- a/packages/pinball_components/lib/src/components/signpost/signpost.dart +++ b/packages/pinball_components/lib/src/components/signpost/signpost.dart @@ -9,7 +9,7 @@ export 'cubit/signpost_cubit.dart'; /// {@template signpost} /// A sign, found in the Flutter Forest. /// -/// Lights up a new sign whenever all three [DashNestBumper]s are hit. +/// Lights up a new sign whenever all three [DashBumper]s are hit. /// {@endtemplate} class Signpost extends BodyComponent with InitialPosition { /// {@macro signpost} diff --git a/packages/pinball_components/lib/src/components/sparky_bumper/sparky_bumper.dart b/packages/pinball_components/lib/src/components/sparky_bumper/sparky_bumper.dart index b0e1b0c8..ed000201 100644 --- a/packages/pinball_components/lib/src/components/sparky_bumper/sparky_bumper.dart +++ b/packages/pinball_components/lib/src/components/sparky_bumper/sparky_bumper.dart @@ -11,7 +11,7 @@ import 'package:pinball_flame/pinball_flame.dart'; export 'cubit/sparky_bumper_cubit.dart'; /// {@template sparky_bumper} -/// Bumper for Sparky area. +/// Bumper for the Sparky Scorch. /// {@endtemplate} class SparkyBumper extends BodyComponent with InitialPosition, ZIndex { /// {@macro sparky_bumper} diff --git a/packages/pinball_components/sandbox/lib/stories/flutter_forest/small_dash_nest_bumper_a_game.dart b/packages/pinball_components/sandbox/lib/stories/flutter_forest/dash_bumper_a_game.dart similarity index 77% rename from packages/pinball_components/sandbox/lib/stories/flutter_forest/small_dash_nest_bumper_a_game.dart rename to packages/pinball_components/sandbox/lib/stories/flutter_forest/dash_bumper_a_game.dart index 071f6aa1..d81540b0 100644 --- a/packages/pinball_components/sandbox/lib/stories/flutter_forest/small_dash_nest_bumper_a_game.dart +++ b/packages/pinball_components/sandbox/lib/stories/flutter_forest/dash_bumper_a_game.dart @@ -4,8 +4,8 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball_components/pinball_components.dart'; import 'package:sandbox/stories/ball/basic_ball_game.dart'; -class SmallDashNestBumperAGame extends BallGame { - SmallDashNestBumperAGame() +class DashBumperAGame extends BallGame { + DashBumperAGame() : super( imagesFileNames: [ Assets.images.dash.bumper.a.active.keyName, @@ -14,7 +14,7 @@ class SmallDashNestBumperAGame extends BallGame { ); static const description = ''' - Shows how a SmallDashNestBumper ("a") is rendered. + Shows how the "a" DashBumper is rendered. - Activate the "trace" parameter to overlay the body. '''; @@ -24,7 +24,7 @@ class SmallDashNestBumperAGame extends BallGame { await super.onLoad(); camera.followVector2(Vector2.zero()); - await add(DashNestBumper.a()..priority = 1); + await add(DashBumper.a()..priority = 1); await traceAllBodies(); } } diff --git a/packages/pinball_components/sandbox/lib/stories/flutter_forest/small_dash_nest_bumper_b_game.dart b/packages/pinball_components/sandbox/lib/stories/flutter_forest/dash_bumper_b_game.dart similarity index 77% rename from packages/pinball_components/sandbox/lib/stories/flutter_forest/small_dash_nest_bumper_b_game.dart rename to packages/pinball_components/sandbox/lib/stories/flutter_forest/dash_bumper_b_game.dart index a47b9962..05664a3a 100644 --- a/packages/pinball_components/sandbox/lib/stories/flutter_forest/small_dash_nest_bumper_b_game.dart +++ b/packages/pinball_components/sandbox/lib/stories/flutter_forest/dash_bumper_b_game.dart @@ -4,8 +4,8 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball_components/pinball_components.dart'; import 'package:sandbox/stories/ball/basic_ball_game.dart'; -class SmallDashNestBumperBGame extends BallGame { - SmallDashNestBumperBGame() +class DashBumperBGame extends BallGame { + DashBumperBGame() : super( imagesFileNames: [ Assets.images.dash.bumper.b.active.keyName, @@ -14,7 +14,7 @@ class SmallDashNestBumperBGame extends BallGame { ); static const description = ''' - Shows how a SmallDashNestBumper ("b") is rendered. + Shows how the "b" DashBumper is rendered. - Activate the "trace" parameter to overlay the body. '''; @@ -24,7 +24,7 @@ class SmallDashNestBumperBGame extends BallGame { await super.onLoad(); camera.followVector2(Vector2.zero()); - await add(DashNestBumper.b()..priority = 1); + await add(DashBumper.b()..priority = 1); await traceAllBodies(); } } diff --git a/packages/pinball_components/sandbox/lib/stories/flutter_forest/big_dash_nest_bumper_game.dart b/packages/pinball_components/sandbox/lib/stories/flutter_forest/dash_bumper_main_game.dart similarity index 79% rename from packages/pinball_components/sandbox/lib/stories/flutter_forest/big_dash_nest_bumper_game.dart rename to packages/pinball_components/sandbox/lib/stories/flutter_forest/dash_bumper_main_game.dart index 3580a175..6a927eb9 100644 --- a/packages/pinball_components/sandbox/lib/stories/flutter_forest/big_dash_nest_bumper_game.dart +++ b/packages/pinball_components/sandbox/lib/stories/flutter_forest/dash_bumper_main_game.dart @@ -4,8 +4,8 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball_components/pinball_components.dart'; import 'package:sandbox/stories/ball/basic_ball_game.dart'; -class BigDashNestBumperGame extends BallGame { - BigDashNestBumperGame() +class DashBumperMainGame extends BallGame { + DashBumperMainGame() : super( imagesFileNames: [ Assets.images.dash.bumper.main.active.keyName, @@ -14,7 +14,7 @@ class BigDashNestBumperGame extends BallGame { ); static const description = ''' - Shows how a BigDashNestBumper is rendered. + Shows how the "main" DashBumper is rendered. - Activate the "trace" parameter to overlay the body. '''; @@ -25,7 +25,7 @@ class BigDashNestBumperGame extends BallGame { camera.followVector2(Vector2.zero()); await add( - DashNestBumper.main()..priority = 1, + DashBumper.main()..priority = 1, ); await traceAllBodies(); } diff --git a/packages/pinball_components/sandbox/lib/stories/flutter_forest/stories.dart b/packages/pinball_components/sandbox/lib/stories/flutter_forest/stories.dart index dd557a27..fcd64f79 100644 --- a/packages/pinball_components/sandbox/lib/stories/flutter_forest/stories.dart +++ b/packages/pinball_components/sandbox/lib/stories/flutter_forest/stories.dart @@ -1,9 +1,9 @@ import 'package:dashbook/dashbook.dart'; import 'package:sandbox/common/common.dart'; -import 'package:sandbox/stories/flutter_forest/big_dash_nest_bumper_game.dart'; +import 'package:sandbox/stories/flutter_forest/dash_bumper_a_game.dart'; +import 'package:sandbox/stories/flutter_forest/dash_bumper_b_game.dart'; +import 'package:sandbox/stories/flutter_forest/dash_bumper_main_game.dart'; import 'package:sandbox/stories/flutter_forest/signpost_game.dart'; -import 'package:sandbox/stories/flutter_forest/small_dash_nest_bumper_a_game.dart'; -import 'package:sandbox/stories/flutter_forest/small_dash_nest_bumper_b_game.dart'; void addFlutterForestStories(Dashbook dashbook) { dashbook.storiesOf('Flutter Forest') @@ -13,18 +13,18 @@ void addFlutterForestStories(Dashbook dashbook) { gameBuilder: (_) => SignpostGame(), ) ..addGame( - title: 'Big Dash Nest Bumper', - description: BigDashNestBumperGame.description, - gameBuilder: (_) => BigDashNestBumperGame(), + title: 'Main Dash Bumper', + description: DashBumperMainGame.description, + gameBuilder: (_) => DashBumperMainGame(), ) ..addGame( - title: 'Small Dash Nest Bumper A', - description: SmallDashNestBumperAGame.description, - gameBuilder: (_) => SmallDashNestBumperAGame(), + title: 'Dash Bumper A', + description: DashBumperAGame.description, + gameBuilder: (_) => DashBumperAGame(), ) ..addGame( - title: 'Small Dash Nest Bumper B', - description: SmallDashNestBumperBGame.description, - gameBuilder: (_) => SmallDashNestBumperBGame(), + title: 'Dash Bumper B', + description: DashBumperBGame.description, + gameBuilder: (_) => DashBumperBGame(), ); } diff --git a/packages/pinball_components/test/src/components/dash_nest_bumper/behaviors/dash_nest_bumper_ball_contact_behavior_test.dart b/packages/pinball_components/test/src/components/dash_nest_bumper/behaviors/dash_bumper_ball_contact_behavior_test.dart similarity index 55% rename from packages/pinball_components/test/src/components/dash_nest_bumper/behaviors/dash_nest_bumper_ball_contact_behavior_test.dart rename to packages/pinball_components/test/src/components/dash_nest_bumper/behaviors/dash_bumper_ball_contact_behavior_test.dart index 10627df6..3c8f51db 100644 --- a/packages/pinball_components/test/src/components/dash_nest_bumper/behaviors/dash_nest_bumper_ball_contact_behavior_test.dart +++ b/packages/pinball_components/test/src/components/dash_nest_bumper/behaviors/dash_bumper_ball_contact_behavior_test.dart @@ -6,11 +6,11 @@ import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; import 'package:pinball_components/pinball_components.dart'; -import 'package:pinball_components/src/components/dash_nest_bumper/behaviors/behaviors.dart'; +import 'package:pinball_components/src/components/dash_bumper/behaviors/behaviors.dart'; import '../../../../helpers/helpers.dart'; -class _MockDashNestBumperCubit extends Mock implements DashNestBumperCubit {} +class _MockDashBumperCubit extends Mock implements DashBumperCubit {} class _MockBall extends Mock implements Ball {} @@ -21,33 +21,33 @@ void main() { final flameTester = FlameTester(TestGame.new); group( - 'DashNestBumperBallContactBehavior', + 'DashBumperBallContactBehavior', () { test('can be instantiated', () { expect( - DashNestBumperBallContactBehavior(), - isA(), + DashBumperBallContactBehavior(), + isA(), ); }); flameTester.test( 'beginContact emits onBallContacted when contacts with a ball', (game) async { - final behavior = DashNestBumperBallContactBehavior(); - final bloc = _MockDashNestBumperCubit(); + final behavior = DashBumperBallContactBehavior(); + final bloc = _MockDashBumperCubit(); whenListen( bloc, - const Stream.empty(), - initialState: DashNestBumperState.active, + const Stream.empty(), + initialState: DashBumperState.active, ); - final dashNestBumper = DashNestBumper.test(bloc: bloc); - await dashNestBumper.add(behavior); - await game.ensureAdd(dashNestBumper); + final bumper = DashBumper.test(bloc: bloc); + await bumper.add(behavior); + await game.ensureAdd(bumper); behavior.beginContact(_MockBall(), _MockContact()); - verify(dashNestBumper.bloc.onBallContacted).called(1); + verify(bumper.bloc.onBallContacted).called(1); }, ); }, diff --git a/packages/pinball_components/test/src/components/dash_nest_bumper/cubit/dash_nest_bumper_cubit_test.dart b/packages/pinball_components/test/src/components/dash_nest_bumper/cubit/dash_bumper_cubit_test.dart similarity index 53% rename from packages/pinball_components/test/src/components/dash_nest_bumper/cubit/dash_nest_bumper_cubit_test.dart rename to packages/pinball_components/test/src/components/dash_nest_bumper/cubit/dash_bumper_cubit_test.dart index 7e26bbf3..1b255cd5 100644 --- a/packages/pinball_components/test/src/components/dash_nest_bumper/cubit/dash_nest_bumper_cubit_test.dart +++ b/packages/pinball_components/test/src/components/dash_nest_bumper/cubit/dash_bumper_cubit_test.dart @@ -4,20 +4,20 @@ import 'package:pinball_components/pinball_components.dart'; void main() { group( - 'DashNestBumperCubit', + 'DashBumperCubit', () { - blocTest( + blocTest( 'onBallContacted emits active', - build: DashNestBumperCubit.new, + build: DashBumperCubit.new, act: (bloc) => bloc.onBallContacted(), - expect: () => [DashNestBumperState.active], + expect: () => [DashBumperState.active], ); - blocTest( + blocTest( 'onReset emits inactive', - build: DashNestBumperCubit.new, + build: DashBumperCubit.new, act: (bloc) => bloc.onReset(), - expect: () => [DashNestBumperState.inactive], + expect: () => [DashBumperState.inactive], ); }, ); diff --git a/packages/pinball_components/test/src/components/dash_nest_bumper/dash_bumper_test.dart b/packages/pinball_components/test/src/components/dash_nest_bumper/dash_bumper_test.dart new file mode 100644 index 00000000..a8ad8410 --- /dev/null +++ b/packages/pinball_components/test/src/components/dash_nest_bumper/dash_bumper_test.dart @@ -0,0 +1,139 @@ +// ignore_for_file: cascade_invocations + +import 'package:bloc_test/bloc_test.dart'; +import 'package:flame/components.dart'; +import 'package:flame_test/flame_test.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mocktail/mocktail.dart'; +import 'package:pinball_components/pinball_components.dart'; +import 'package:pinball_components/src/components/bumping_behavior.dart'; +import 'package:pinball_components/src/components/dash_bumper/behaviors/behaviors.dart'; + +import '../../../helpers/helpers.dart'; + +class _MockDashBumperCubit extends Mock implements DashBumperCubit {} + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + group('DashBumper', () { + final flameTester = FlameTester( + () => TestGame( + [ + Assets.images.dash.bumper.main.active.keyName, + Assets.images.dash.bumper.main.inactive.keyName, + Assets.images.dash.bumper.a.active.keyName, + Assets.images.dash.bumper.a.inactive.keyName, + Assets.images.dash.bumper.b.active.keyName, + Assets.images.dash.bumper.b.inactive.keyName, + ], + ), + ); + + flameTester.test('"main" loads correctly', (game) async { + final bumper = DashBumper.main(); + await game.ensureAdd(bumper); + expect(game.contains(bumper), isTrue); + }); + + flameTester.test('"a" loads correctly', (game) async { + final bumper = DashBumper.a(); + await game.ensureAdd(bumper); + + expect(game.contains(bumper), isTrue); + }); + + flameTester.test('"b" loads correctly', (game) async { + final bumper = DashBumper.b(); + await game.ensureAdd(bumper); + expect(game.contains(bumper), isTrue); + }); + + // ignore: public_member_api_docs + flameTester.test('closes bloc when removed', (game) async { + final bloc = _MockDashBumperCubit(); + whenListen( + bloc, + const Stream.empty(), + initialState: DashBumperState.inactive, + ); + when(bloc.close).thenAnswer((_) async {}); + final bumper = DashBumper.test(bloc: bloc); + + await game.ensureAdd(bumper); + game.remove(bumper); + await game.ready(); + + verify(bloc.close).called(1); + }); + + flameTester.test('adds a bumperBallContactBehavior', (game) async { + final bumper = DashBumper.a(); + await game.ensureAdd(bumper); + expect( + bumper.children.whereType().single, + isNotNull, + ); + }); + + group("'main' adds", () { + flameTester.test('new children', (game) async { + final component = Component(); + final bumper = DashBumper.main( + children: [component], + ); + await game.ensureAdd(bumper); + expect(bumper.children, contains(component)); + }); + + flameTester.test('a BumpingBehavior', (game) async { + final bumper = DashBumper.main(); + await game.ensureAdd(bumper); + expect( + bumper.children.whereType().single, + isNotNull, + ); + }); + }); + + group("'a' adds", () { + flameTester.test('new children', (game) async { + final component = Component(); + final bumper = DashBumper.a( + children: [component], + ); + await game.ensureAdd(bumper); + expect(bumper.children, contains(component)); + }); + + flameTester.test('a BumpingBehavior', (game) async { + final bumper = DashBumper.a(); + await game.ensureAdd(bumper); + expect( + bumper.children.whereType().single, + isNotNull, + ); + }); + }); + + group("'b' adds", () { + flameTester.test('new children', (game) async { + final component = Component(); + final bumper = DashBumper.b( + children: [component], + ); + await game.ensureAdd(bumper); + expect(bumper.children, contains(component)); + }); + + flameTester.test('a BumpingBehavior', (game) async { + final bumper = DashBumper.b(); + await game.ensureAdd(bumper); + expect( + bumper.children.whereType().single, + isNotNull, + ); + }); + }); + }); +} diff --git a/packages/pinball_components/test/src/components/dash_nest_bumper/dash_nest_bumper_test.dart b/packages/pinball_components/test/src/components/dash_nest_bumper/dash_nest_bumper_test.dart deleted file mode 100644 index baf2132f..00000000 --- a/packages/pinball_components/test/src/components/dash_nest_bumper/dash_nest_bumper_test.dart +++ /dev/null @@ -1,137 +0,0 @@ -// ignore_for_file: cascade_invocations - -import 'package:bloc_test/bloc_test.dart'; -import 'package:flame/components.dart'; -import 'package:flame_test/flame_test.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:mocktail/mocktail.dart'; -import 'package:pinball_components/pinball_components.dart'; -import 'package:pinball_components/src/components/bumping_behavior.dart'; -import 'package:pinball_components/src/components/dash_nest_bumper/behaviors/behaviors.dart'; - -import '../../../helpers/helpers.dart'; - -class _MockDashNestBumperCubit extends Mock implements DashNestBumperCubit {} - -void main() { - TestWidgetsFlutterBinding.ensureInitialized(); - - group('DashNestBumper', () { - final assets = [ - Assets.images.dash.bumper.main.active.keyName, - Assets.images.dash.bumper.main.inactive.keyName, - Assets.images.dash.bumper.a.active.keyName, - Assets.images.dash.bumper.a.inactive.keyName, - Assets.images.dash.bumper.b.active.keyName, - Assets.images.dash.bumper.b.inactive.keyName, - ]; - final flameTester = FlameTester(() => TestGame(assets)); - - flameTester.test('"main" loads correctly', (game) async { - final bumper = DashNestBumper.main(); - await game.ensureAdd(bumper); - expect(game.contains(bumper), isTrue); - }); - - flameTester.test('"a" loads correctly', (game) async { - final bumper = DashNestBumper.a(); - await game.ensureAdd(bumper); - - expect(game.contains(bumper), isTrue); - }); - - flameTester.test('"b" loads correctly', (game) async { - final bumper = DashNestBumper.b(); - await game.ensureAdd(bumper); - expect(game.contains(bumper), isTrue); - }); - - flameTester.test('closes bloc when removed', (game) async { - final bloc = _MockDashNestBumperCubit(); - whenListen( - bloc, - const Stream.empty(), - initialState: DashNestBumperState.inactive, - ); - when(bloc.close).thenAnswer((_) async {}); - final dashNestBumper = DashNestBumper.test(bloc: bloc); - - await game.ensureAdd(dashNestBumper); - game.remove(dashNestBumper); - await game.ready(); - - verify(bloc.close).called(1); - }); - - flameTester.test('adds a DashNestBumperBallContactBehavior', (game) async { - final dashNestBumper = DashNestBumper.a(); - await game.ensureAdd(dashNestBumper); - expect( - dashNestBumper.children - .whereType() - .single, - isNotNull, - ); - }); - - group("'main' adds", () { - flameTester.test('new children', (game) async { - final component = Component(); - final dashNestBumper = DashNestBumper.main( - children: [component], - ); - await game.ensureAdd(dashNestBumper); - expect(dashNestBumper.children, contains(component)); - }); - - flameTester.test('a BumpingBehavior', (game) async { - final dashNestBumper = DashNestBumper.main(); - await game.ensureAdd(dashNestBumper); - expect( - dashNestBumper.children.whereType().single, - isNotNull, - ); - }); - }); - - group("'a' adds", () { - flameTester.test('new children', (game) async { - final component = Component(); - final dashNestBumper = DashNestBumper.a( - children: [component], - ); - await game.ensureAdd(dashNestBumper); - expect(dashNestBumper.children, contains(component)); - }); - - flameTester.test('a BumpingBehavior', (game) async { - final dashNestBumper = DashNestBumper.a(); - await game.ensureAdd(dashNestBumper); - expect( - dashNestBumper.children.whereType().single, - isNotNull, - ); - }); - }); - - group("'b' adds", () { - flameTester.test('new children', (game) async { - final component = Component(); - final dashNestBumper = DashNestBumper.b( - children: [component], - ); - await game.ensureAdd(dashNestBumper); - expect(dashNestBumper.children, contains(component)); - }); - - flameTester.test('a BumpingBehavior', (game) async { - final dashNestBumper = DashNestBumper.b(); - await game.ensureAdd(dashNestBumper); - expect( - dashNestBumper.children.whereType().single, - isNotNull, - ); - }); - }); - }); -} diff --git a/test/game/components/flutter_forest/behaviors/flutter_forest_bonus_behavior_test.dart b/test/game/components/flutter_forest/behaviors/flutter_forest_bonus_behavior_test.dart index 0b75a61e..7fc1946b 100644 --- a/test/game/components/flutter_forest/behaviors/flutter_forest_bonus_behavior_test.dart +++ b/test/game/components/flutter_forest/behaviors/flutter_forest_bonus_behavior_test.dart @@ -53,8 +53,7 @@ void main() { final flameTester = FlameTester(_TestGame.new); - void _contactedBumper(DashNestBumper bumper) => - bumper.bloc.onBallContacted(); + void _contactedBumper(DashBumper bumper) => bumper.bloc.onBallContacted(); flameTester.testGameWidget( 'adds GameBonus.dashNest to the game ' @@ -64,9 +63,9 @@ void main() { final behavior = FlutterForestBonusBehavior(); final parent = FlutterForest.test(); final bumpers = [ - DashNestBumper.test(bloc: DashNestBumperCubit()), - DashNestBumper.test(bloc: DashNestBumperCubit()), - DashNestBumper.test(bloc: DashNestBumperCubit()), + DashBumper.test(bloc: DashBumperCubit()), + DashBumper.test(bloc: DashBumperCubit()), + DashBumper.test(bloc: DashBumperCubit()), ]; final animatronic = DashAnimatronic(); final signpost = Signpost.test(bloc: SignpostCubit()); @@ -74,7 +73,7 @@ void main() { await parent.ensureAddAll([...bumpers, animatronic, signpost]); await parent.ensureAdd(behavior); - expect(game.descendants().whereType(), equals(bumpers)); + expect(game.descendants().whereType(), equals(bumpers)); bumpers.forEach(_contactedBumper); await tester.pump(); bumpers.forEach(_contactedBumper); @@ -96,9 +95,9 @@ void main() { final behavior = FlutterForestBonusBehavior(); final parent = FlutterForest.test(); final bumpers = [ - DashNestBumper.test(bloc: DashNestBumperCubit()), - DashNestBumper.test(bloc: DashNestBumperCubit()), - DashNestBumper.test(bloc: DashNestBumperCubit()), + DashBumper.test(bloc: DashBumperCubit()), + DashBumper.test(bloc: DashBumperCubit()), + DashBumper.test(bloc: DashBumperCubit()), ]; final animatronic = DashAnimatronic(); final signpost = Signpost.test(bloc: SignpostCubit()); @@ -106,7 +105,7 @@ void main() { await parent.ensureAddAll([...bumpers, animatronic, signpost]); await parent.ensureAdd(behavior); - expect(game.descendants().whereType(), equals(bumpers)); + expect(game.descendants().whereType(), equals(bumpers)); bumpers.forEach(_contactedBumper); await tester.pump(); bumpers.forEach(_contactedBumper); @@ -130,9 +129,9 @@ void main() { final behavior = FlutterForestBonusBehavior(); final parent = FlutterForest.test(); final bumpers = [ - DashNestBumper.test(bloc: DashNestBumperCubit()), - DashNestBumper.test(bloc: DashNestBumperCubit()), - DashNestBumper.test(bloc: DashNestBumperCubit()), + DashBumper.test(bloc: DashBumperCubit()), + DashBumper.test(bloc: DashBumperCubit()), + DashBumper.test(bloc: DashBumperCubit()), ]; final animatronic = DashAnimatronic(); final signpost = Signpost.test(bloc: SignpostCubit()); @@ -140,7 +139,7 @@ void main() { await parent.ensureAddAll([...bumpers, animatronic, signpost]); await parent.ensureAdd(behavior); - expect(game.descendants().whereType(), equals(bumpers)); + expect(game.descendants().whereType(), equals(bumpers)); bumpers.forEach(_contactedBumper); await tester.pump(); diff --git a/test/game/components/flutter_forest/flutter_forest_test.dart b/test/game/components/flutter_forest/flutter_forest_test.dart index 470719d8..bce4b6ac 100644 --- a/test/game/components/flutter_forest/flutter_forest_test.dart +++ b/test/game/components/flutter_forest/flutter_forest_test.dart @@ -91,23 +91,23 @@ void main() { ); flameTester.test( - 'three DashNestBumper', + 'three DashBumper', (game) async { final component = FlutterForest(); await game.pump(component); expect( - game.descendants().whereType().length, + game.descendants().whereType().length, equals(3), ); }, ); flameTester.test( - 'three DashNestBumpers with BumperNoiseBehavior', + 'three DashBumpers with BumperNoiseBehavior', (game) async { final component = FlutterForest(); await game.pump(component); - final bumpers = game.descendants().whereType(); + final bumpers = game.descendants().whereType(); for (final bumper in bumpers) { expect( bumper.firstChild(),