refactor: renamed `DashNestBumper` to `DashBumper` (#381)

* refactor: renamed DashNestBumper to DashBumper

* refactor: PR suggestions

* refactor: renamed stories

* refactor: renamed test names

* test: renamed test name

* docs: improved bumper docs

* docs: improve docs

* refactor: renamed stories
pull/394/head
Alejandro Santiago 3 years ago committed by GitHub
parent 75527d1fe1
commit fd87afb23b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,7 +5,7 @@ enum GameBonus {
/// Bonus achieved when the ball activates all Google letters. /// Bonus achieved when the ball activates all Google letters.
googleWord, googleWord,
/// Bonus achieved when the user activates all dash nest bumpers. /// Bonus achieved when the user activates all dash bumpers.
dashNest, dashNest,
/// Bonus achieved when a ball enters Sparky's computer. /// Bonus achieved when a ball enters Sparky's computer.

@ -7,9 +7,9 @@ import 'package:pinball_flame/pinball_flame.dart';
/// Bonus obtained at the [FlutterForest]. /// 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] /// 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 class FlutterForestBonusBehavior extends Component
with with
ParentIsA<FlutterForest>, ParentIsA<FlutterForest>,
@ -19,14 +19,14 @@ class FlutterForestBonusBehavior extends Component
void onMount() { void onMount() {
super.onMount(); super.onMount();
final bumpers = parent.children.whereType<DashNestBumper>(); final bumpers = parent.children.whereType<DashBumper>();
final signpost = parent.firstChild<Signpost>()!; final signpost = parent.firstChild<Signpost>()!;
final animatronic = parent.firstChild<DashAnimatronic>()!; final animatronic = parent.firstChild<DashAnimatronic>()!;
for (final bumper in bumpers) { for (final bumper in bumpers) {
bumper.bloc.stream.listen((state) { bumper.bloc.stream.listen((state) {
final activatedAllBumpers = bumpers.every( final activatedAllBumpers = bumpers.every(
(bumper) => bumper.bloc.state == DashNestBumperState.active, (bumper) => bumper.bloc.state == DashBumperState.active,
); );
if (activatedAllBumpers) { if (activatedAllBumpers) {

@ -9,7 +9,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template flutter_forest} /// {@template flutter_forest}
/// Area positioned at the top right of the board where the [Ball] can bounce /// Area positioned at the top right of the board where the [Ball] can bounce
/// off [DashNestBumper]s. /// off [DashBumper]s.
/// {@endtemplate} /// {@endtemplate}
class FlutterForest extends Component with ZIndex { class FlutterForest extends Component with ZIndex {
/// {@macro flutter_forest} /// {@macro flutter_forest}
@ -22,19 +22,19 @@ class FlutterForest extends Component with ZIndex {
BumperNoiseBehavior(), BumperNoiseBehavior(),
], ],
)..initialPosition = Vector2(7.95, -58.35), )..initialPosition = Vector2(7.95, -58.35),
DashNestBumper.main( DashBumper.main(
children: [ children: [
ScoringContactBehavior(points: Points.twoHundredThousand), ScoringContactBehavior(points: Points.twoHundredThousand),
BumperNoiseBehavior(), BumperNoiseBehavior(),
], ],
)..initialPosition = Vector2(18.55, -59.35), )..initialPosition = Vector2(18.55, -59.35),
DashNestBumper.a( DashBumper.a(
children: [ children: [
ScoringContactBehavior(points: Points.twentyThousand), ScoringContactBehavior(points: Points.twentyThousand),
BumperNoiseBehavior(), BumperNoiseBehavior(),
], ],
)..initialPosition = Vector2(8.95, -51.95), )..initialPosition = Vector2(8.95, -51.95),
DashNestBumper.b( DashBumper.b(
children: [ children: [
ScoringContactBehavior(points: Points.twentyThousand), ScoringContactBehavior(points: Points.twentyThousand),
BumperNoiseBehavior(), BumperNoiseBehavior(),

@ -10,7 +10,7 @@ export 'boundaries.dart';
export 'camera_zoom.dart'; export 'camera_zoom.dart';
export 'chrome_dino/chrome_dino.dart'; export 'chrome_dino/chrome_dino.dart';
export 'dash_animatronic.dart'; export 'dash_animatronic.dart';
export 'dash_nest_bumper/dash_nest_bumper.dart'; export 'dash_bumper/dash_bumper.dart';
export 'dino_walls.dart'; export 'dino_walls.dart';
export 'error_component.dart'; export 'error_component.dart';
export 'fire_effect.dart'; export 'fire_effect.dart';

@ -2,7 +2,7 @@ import 'package:flame/components.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
/// {@template dash_animatronic} /// {@template dash_animatronic}
/// Animated Dash that sits on top of the [DashNestBumper.main]. /// Animated Dash that sits on top of the [DashBumper.main].
/// {@endtemplate} /// {@endtemplate}
class DashAnimatronic extends SpriteAnimationComponent with HasGameRef { class DashAnimatronic extends SpriteAnimationComponent with HasGameRef {
/// {@macro dash_animatronic} /// {@macro dash_animatronic}

@ -2,8 +2,7 @@ import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart'; import 'package:pinball_flame/pinball_flame.dart';
class DashNestBumperBallContactBehavior class DashBumperBallContactBehavior extends ContactBehavior<DashBumper> {
extends ContactBehavior<DashNestBumper> {
@override @override
void beginContact(Object other, Contact contact) { void beginContact(Object other, Contact contact) {
super.beginContact(other, contact); super.beginContact(other, contact);

@ -0,0 +1,17 @@
import 'package:bloc/bloc.dart';
part 'dash_bumper_state.dart';
class DashBumperCubit extends Cubit<DashBumperState> {
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);
}
}

@ -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,
}

@ -5,17 +5,17 @@ import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_components/src/components/bumping_behavior.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'; import 'package:pinball_flame/pinball_flame.dart';
export 'cubit/dash_nest_bumper_cubit.dart'; export 'cubit/dash_bumper_cubit.dart';
/// {@template dash_nest_bumper} /// {@template dash_bumper}
/// Bumper with a nest appearance. /// Bumper for the flutter forest.
/// {@endtemplate} /// {@endtemplate}
class DashNestBumper extends BodyComponent with InitialPosition { class DashBumper extends BodyComponent with InitialPosition {
/// {@macro dash_nest_bumper} /// {@macro dash_bumper}
DashNestBumper._({ DashBumper._({
required double majorRadius, required double majorRadius,
required double minorRadius, required double minorRadius,
required String activeAssetPath, required String activeAssetPath,
@ -28,19 +28,22 @@ class DashNestBumper extends BodyComponent with InitialPosition {
super( super(
renderBody: false, renderBody: false,
children: [ children: [
_DashNestBumperSpriteGroupComponent( _DashBumperSpriteGroupComponent(
activeAssetPath: activeAssetPath, activeAssetPath: activeAssetPath,
inactiveAssetPath: inactiveAssetPath, inactiveAssetPath: inactiveAssetPath,
position: spritePosition, position: spritePosition,
current: bloc.state, current: bloc.state,
), ),
DashNestBumperBallContactBehavior(), DashBumperBallContactBehavior(),
...?children, ...?children,
], ],
); );
/// {@macro dash_nest_bumper} /// {@macro dash_bumper}
DashNestBumper.main({ ///
/// [DashBumper.main], usually positioned with a [DashAnimatronic] on top of
/// it.
DashBumper.main({
Iterable<Component>? children, Iterable<Component>? children,
}) : this._( }) : this._(
majorRadius: 5.1, majorRadius: 5.1,
@ -48,15 +51,18 @@ class DashNestBumper extends BodyComponent with InitialPosition {
activeAssetPath: Assets.images.dash.bumper.main.active.keyName, activeAssetPath: Assets.images.dash.bumper.main.active.keyName,
inactiveAssetPath: Assets.images.dash.bumper.main.inactive.keyName, inactiveAssetPath: Assets.images.dash.bumper.main.inactive.keyName,
spritePosition: Vector2(0, -0.3), spritePosition: Vector2(0, -0.3),
bloc: DashNestBumperCubit(), bloc: DashBumperCubit(),
children: [ children: [
...?children, ...?children,
BumpingBehavior(strength: 20), BumpingBehavior(strength: 20),
], ],
); );
/// {@macro dash_nest_bumper} /// {@macro dash_bumper}
DashNestBumper.a({ ///
/// [DashBumper.a] is positioned at the right side of the [DashBumper.main] in
/// the flutter forest.
DashBumper.a({
Iterable<Component>? children, Iterable<Component>? children,
}) : this._( }) : this._(
majorRadius: 3, majorRadius: 3,
@ -64,15 +70,18 @@ class DashNestBumper extends BodyComponent with InitialPosition {
activeAssetPath: Assets.images.dash.bumper.a.active.keyName, activeAssetPath: Assets.images.dash.bumper.a.active.keyName,
inactiveAssetPath: Assets.images.dash.bumper.a.inactive.keyName, inactiveAssetPath: Assets.images.dash.bumper.a.inactive.keyName,
spritePosition: Vector2(0.3, -1.3), spritePosition: Vector2(0.3, -1.3),
bloc: DashNestBumperCubit(), bloc: DashBumperCubit(),
children: [ children: [
...?children, ...?children,
BumpingBehavior(strength: 20), BumpingBehavior(strength: 20),
], ],
); );
/// {@macro dash_nest_bumper} /// {@macro dash_bumper}
DashNestBumper.b({ ///
/// [DashBumper.b] is positioned at the left side of the [DashBumper.main] in
/// the flutter forest.
DashBumper.b({
Iterable<Component>? children, Iterable<Component>? children,
}) : this._( }) : this._(
majorRadius: 3.1, majorRadius: 3.1,
@ -80,25 +89,26 @@ class DashNestBumper extends BodyComponent with InitialPosition {
activeAssetPath: Assets.images.dash.bumper.b.active.keyName, activeAssetPath: Assets.images.dash.bumper.b.active.keyName,
inactiveAssetPath: Assets.images.dash.bumper.b.inactive.keyName, inactiveAssetPath: Assets.images.dash.bumper.b.inactive.keyName,
spritePosition: Vector2(0.4, -1.2), spritePosition: Vector2(0.4, -1.2),
bloc: DashNestBumperCubit(), bloc: DashBumperCubit(),
children: [ children: [
...?children, ...?children,
BumpingBehavior(strength: 20), 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 @visibleForTesting
DashNestBumper.test({required this.bloc}) DashBumper.test({required this.bloc})
: _majorRadius = 3, : _majorRadius = 3,
_minorRadius = 2.5; _minorRadius = 2.5;
final double _majorRadius; final double _majorRadius;
final double _minorRadius; final double _minorRadius;
final DashNestBumperCubit bloc; // ignore: public_member_api_docs
final DashBumperCubit bloc;
@override @override
void onRemove() { void onRemove() {
@ -121,14 +131,14 @@ class DashNestBumper extends BodyComponent with InitialPosition {
} }
} }
class _DashNestBumperSpriteGroupComponent class _DashBumperSpriteGroupComponent
extends SpriteGroupComponent<DashNestBumperState> extends SpriteGroupComponent<DashBumperState>
with HasGameRef, ParentIsA<DashNestBumper> { with HasGameRef, ParentIsA<DashBumper> {
_DashNestBumperSpriteGroupComponent({ _DashBumperSpriteGroupComponent({
required String activeAssetPath, required String activeAssetPath,
required String inactiveAssetPath, required String inactiveAssetPath,
required Vector2 position, required Vector2 position,
required DashNestBumperState current, required DashBumperState current,
}) : _activeAssetPath = activeAssetPath, }) : _activeAssetPath = activeAssetPath,
_inactiveAssetPath = inactiveAssetPath, _inactiveAssetPath = inactiveAssetPath,
super( super(
@ -146,9 +156,9 @@ class _DashNestBumperSpriteGroupComponent
parent.bloc.stream.listen((state) => current = state); parent.bloc.stream.listen((state) => current = state);
final sprites = { final sprites = {
DashNestBumperState.active: DashBumperState.active:
Sprite(gameRef.images.fromCache(_activeAssetPath)), Sprite(gameRef.images.fromCache(_activeAssetPath)),
DashNestBumperState.inactive: DashBumperState.inactive:
Sprite(gameRef.images.fromCache(_inactiveAssetPath)), Sprite(gameRef.images.fromCache(_inactiveAssetPath)),
}; };
this.sprites = sprites; this.sprites = sprites;

@ -1,17 +0,0 @@
import 'package:bloc/bloc.dart';
part 'dash_nest_bumper_state.dart';
class DashNestBumperCubit extends Cubit<DashNestBumperState> {
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);
}
}

@ -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,
}

@ -9,7 +9,7 @@ export 'cubit/signpost_cubit.dart';
/// {@template signpost} /// {@template signpost}
/// A sign, found in the Flutter Forest. /// 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} /// {@endtemplate}
class Signpost extends BodyComponent with InitialPosition { class Signpost extends BodyComponent with InitialPosition {
/// {@macro signpost} /// {@macro signpost}

@ -11,7 +11,7 @@ import 'package:pinball_flame/pinball_flame.dart';
export 'cubit/sparky_bumper_cubit.dart'; export 'cubit/sparky_bumper_cubit.dart';
/// {@template sparky_bumper} /// {@template sparky_bumper}
/// Bumper for Sparky area. /// Bumper for the Sparky Scorch.
/// {@endtemplate} /// {@endtemplate}
class SparkyBumper extends BodyComponent with InitialPosition, ZIndex { class SparkyBumper extends BodyComponent with InitialPosition, ZIndex {
/// {@macro sparky_bumper} /// {@macro sparky_bumper}

@ -4,8 +4,8 @@ import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:sandbox/stories/ball/basic_ball_game.dart'; import 'package:sandbox/stories/ball/basic_ball_game.dart';
class SmallDashNestBumperAGame extends BallGame { class DashBumperAGame extends BallGame {
SmallDashNestBumperAGame() DashBumperAGame()
: super( : super(
imagesFileNames: [ imagesFileNames: [
Assets.images.dash.bumper.a.active.keyName, Assets.images.dash.bumper.a.active.keyName,
@ -14,7 +14,7 @@ class SmallDashNestBumperAGame extends BallGame {
); );
static const description = ''' 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. - Activate the "trace" parameter to overlay the body.
'''; ''';
@ -24,7 +24,7 @@ class SmallDashNestBumperAGame extends BallGame {
await super.onLoad(); await super.onLoad();
camera.followVector2(Vector2.zero()); camera.followVector2(Vector2.zero());
await add(DashNestBumper.a()..priority = 1); await add(DashBumper.a()..priority = 1);
await traceAllBodies(); await traceAllBodies();
} }
} }

@ -4,8 +4,8 @@ import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:sandbox/stories/ball/basic_ball_game.dart'; import 'package:sandbox/stories/ball/basic_ball_game.dart';
class SmallDashNestBumperBGame extends BallGame { class DashBumperBGame extends BallGame {
SmallDashNestBumperBGame() DashBumperBGame()
: super( : super(
imagesFileNames: [ imagesFileNames: [
Assets.images.dash.bumper.b.active.keyName, Assets.images.dash.bumper.b.active.keyName,
@ -14,7 +14,7 @@ class SmallDashNestBumperBGame extends BallGame {
); );
static const description = ''' 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. - Activate the "trace" parameter to overlay the body.
'''; ''';
@ -24,7 +24,7 @@ class SmallDashNestBumperBGame extends BallGame {
await super.onLoad(); await super.onLoad();
camera.followVector2(Vector2.zero()); camera.followVector2(Vector2.zero());
await add(DashNestBumper.b()..priority = 1); await add(DashBumper.b()..priority = 1);
await traceAllBodies(); await traceAllBodies();
} }
} }

@ -4,8 +4,8 @@ import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:sandbox/stories/ball/basic_ball_game.dart'; import 'package:sandbox/stories/ball/basic_ball_game.dart';
class BigDashNestBumperGame extends BallGame { class DashBumperMainGame extends BallGame {
BigDashNestBumperGame() DashBumperMainGame()
: super( : super(
imagesFileNames: [ imagesFileNames: [
Assets.images.dash.bumper.main.active.keyName, Assets.images.dash.bumper.main.active.keyName,
@ -14,7 +14,7 @@ class BigDashNestBumperGame extends BallGame {
); );
static const description = ''' static const description = '''
Shows how a BigDashNestBumper is rendered. Shows how the "main" DashBumper is rendered.
- Activate the "trace" parameter to overlay the body. - Activate the "trace" parameter to overlay the body.
'''; ''';
@ -25,7 +25,7 @@ class BigDashNestBumperGame extends BallGame {
camera.followVector2(Vector2.zero()); camera.followVector2(Vector2.zero());
await add( await add(
DashNestBumper.main()..priority = 1, DashBumper.main()..priority = 1,
); );
await traceAllBodies(); await traceAllBodies();
} }

@ -1,9 +1,9 @@
import 'package:dashbook/dashbook.dart'; import 'package:dashbook/dashbook.dart';
import 'package:sandbox/common/common.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/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) { void addFlutterForestStories(Dashbook dashbook) {
dashbook.storiesOf('Flutter Forest') dashbook.storiesOf('Flutter Forest')
@ -13,18 +13,18 @@ void addFlutterForestStories(Dashbook dashbook) {
gameBuilder: (_) => SignpostGame(), gameBuilder: (_) => SignpostGame(),
) )
..addGame( ..addGame(
title: 'Big Dash Nest Bumper', title: 'Main Dash Bumper',
description: BigDashNestBumperGame.description, description: DashBumperMainGame.description,
gameBuilder: (_) => BigDashNestBumperGame(), gameBuilder: (_) => DashBumperMainGame(),
) )
..addGame( ..addGame(
title: 'Small Dash Nest Bumper A', title: 'Dash Bumper A',
description: SmallDashNestBumperAGame.description, description: DashBumperAGame.description,
gameBuilder: (_) => SmallDashNestBumperAGame(), gameBuilder: (_) => DashBumperAGame(),
) )
..addGame( ..addGame(
title: 'Small Dash Nest Bumper B', title: 'Dash Bumper B',
description: SmallDashNestBumperBGame.description, description: DashBumperBGame.description,
gameBuilder: (_) => SmallDashNestBumperBGame(), gameBuilder: (_) => DashBumperBGame(),
); );
} }

@ -6,11 +6,11 @@ import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart'; import 'package:mocktail/mocktail.dart';
import 'package:pinball_components/pinball_components.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'; import '../../../../helpers/helpers.dart';
class _MockDashNestBumperCubit extends Mock implements DashNestBumperCubit {} class _MockDashBumperCubit extends Mock implements DashBumperCubit {}
class _MockBall extends Mock implements Ball {} class _MockBall extends Mock implements Ball {}
@ -21,33 +21,33 @@ void main() {
final flameTester = FlameTester(TestGame.new); final flameTester = FlameTester(TestGame.new);
group( group(
'DashNestBumperBallContactBehavior', 'DashBumperBallContactBehavior',
() { () {
test('can be instantiated', () { test('can be instantiated', () {
expect( expect(
DashNestBumperBallContactBehavior(), DashBumperBallContactBehavior(),
isA<DashNestBumperBallContactBehavior>(), isA<DashBumperBallContactBehavior>(),
); );
}); });
flameTester.test( flameTester.test(
'beginContact emits onBallContacted when contacts with a ball', 'beginContact emits onBallContacted when contacts with a ball',
(game) async { (game) async {
final behavior = DashNestBumperBallContactBehavior(); final behavior = DashBumperBallContactBehavior();
final bloc = _MockDashNestBumperCubit(); final bloc = _MockDashBumperCubit();
whenListen( whenListen(
bloc, bloc,
const Stream<DashNestBumperState>.empty(), const Stream<DashBumperState>.empty(),
initialState: DashNestBumperState.active, initialState: DashBumperState.active,
); );
final dashNestBumper = DashNestBumper.test(bloc: bloc); final bumper = DashBumper.test(bloc: bloc);
await dashNestBumper.add(behavior); await bumper.add(behavior);
await game.ensureAdd(dashNestBumper); await game.ensureAdd(bumper);
behavior.beginContact(_MockBall(), _MockContact()); behavior.beginContact(_MockBall(), _MockContact());
verify(dashNestBumper.bloc.onBallContacted).called(1); verify(bumper.bloc.onBallContacted).called(1);
}, },
); );
}, },

@ -4,20 +4,20 @@ import 'package:pinball_components/pinball_components.dart';
void main() { void main() {
group( group(
'DashNestBumperCubit', 'DashBumperCubit',
() { () {
blocTest<DashNestBumperCubit, DashNestBumperState>( blocTest<DashBumperCubit, DashBumperState>(
'onBallContacted emits active', 'onBallContacted emits active',
build: DashNestBumperCubit.new, build: DashBumperCubit.new,
act: (bloc) => bloc.onBallContacted(), act: (bloc) => bloc.onBallContacted(),
expect: () => [DashNestBumperState.active], expect: () => [DashBumperState.active],
); );
blocTest<DashNestBumperCubit, DashNestBumperState>( blocTest<DashBumperCubit, DashBumperState>(
'onReset emits inactive', 'onReset emits inactive',
build: DashNestBumperCubit.new, build: DashBumperCubit.new,
act: (bloc) => bloc.onReset(), act: (bloc) => bloc.onReset(),
expect: () => [DashNestBumperState.inactive], expect: () => [DashBumperState.inactive],
); );
}, },
); );

@ -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<DashBumperState>.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<DashBumperBallContactBehavior>().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<BumpingBehavior>().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<BumpingBehavior>().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<BumpingBehavior>().single,
isNotNull,
);
});
});
});
}

@ -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<DashNestBumperState>.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<DashNestBumperBallContactBehavior>()
.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<BumpingBehavior>().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<BumpingBehavior>().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<BumpingBehavior>().single,
isNotNull,
);
});
});
});
}

@ -53,8 +53,7 @@ void main() {
final flameTester = FlameTester(_TestGame.new); final flameTester = FlameTester(_TestGame.new);
void _contactedBumper(DashNestBumper bumper) => void _contactedBumper(DashBumper bumper) => bumper.bloc.onBallContacted();
bumper.bloc.onBallContacted();
flameTester.testGameWidget( flameTester.testGameWidget(
'adds GameBonus.dashNest to the game ' 'adds GameBonus.dashNest to the game '
@ -64,9 +63,9 @@ void main() {
final behavior = FlutterForestBonusBehavior(); final behavior = FlutterForestBonusBehavior();
final parent = FlutterForest.test(); final parent = FlutterForest.test();
final bumpers = [ final bumpers = [
DashNestBumper.test(bloc: DashNestBumperCubit()), DashBumper.test(bloc: DashBumperCubit()),
DashNestBumper.test(bloc: DashNestBumperCubit()), DashBumper.test(bloc: DashBumperCubit()),
DashNestBumper.test(bloc: DashNestBumperCubit()), DashBumper.test(bloc: DashBumperCubit()),
]; ];
final animatronic = DashAnimatronic(); final animatronic = DashAnimatronic();
final signpost = Signpost.test(bloc: SignpostCubit()); final signpost = Signpost.test(bloc: SignpostCubit());
@ -74,7 +73,7 @@ void main() {
await parent.ensureAddAll([...bumpers, animatronic, signpost]); await parent.ensureAddAll([...bumpers, animatronic, signpost]);
await parent.ensureAdd(behavior); await parent.ensureAdd(behavior);
expect(game.descendants().whereType<DashNestBumper>(), equals(bumpers)); expect(game.descendants().whereType<DashBumper>(), equals(bumpers));
bumpers.forEach(_contactedBumper); bumpers.forEach(_contactedBumper);
await tester.pump(); await tester.pump();
bumpers.forEach(_contactedBumper); bumpers.forEach(_contactedBumper);
@ -96,9 +95,9 @@ void main() {
final behavior = FlutterForestBonusBehavior(); final behavior = FlutterForestBonusBehavior();
final parent = FlutterForest.test(); final parent = FlutterForest.test();
final bumpers = [ final bumpers = [
DashNestBumper.test(bloc: DashNestBumperCubit()), DashBumper.test(bloc: DashBumperCubit()),
DashNestBumper.test(bloc: DashNestBumperCubit()), DashBumper.test(bloc: DashBumperCubit()),
DashNestBumper.test(bloc: DashNestBumperCubit()), DashBumper.test(bloc: DashBumperCubit()),
]; ];
final animatronic = DashAnimatronic(); final animatronic = DashAnimatronic();
final signpost = Signpost.test(bloc: SignpostCubit()); final signpost = Signpost.test(bloc: SignpostCubit());
@ -106,7 +105,7 @@ void main() {
await parent.ensureAddAll([...bumpers, animatronic, signpost]); await parent.ensureAddAll([...bumpers, animatronic, signpost]);
await parent.ensureAdd(behavior); await parent.ensureAdd(behavior);
expect(game.descendants().whereType<DashNestBumper>(), equals(bumpers)); expect(game.descendants().whereType<DashBumper>(), equals(bumpers));
bumpers.forEach(_contactedBumper); bumpers.forEach(_contactedBumper);
await tester.pump(); await tester.pump();
bumpers.forEach(_contactedBumper); bumpers.forEach(_contactedBumper);
@ -130,9 +129,9 @@ void main() {
final behavior = FlutterForestBonusBehavior(); final behavior = FlutterForestBonusBehavior();
final parent = FlutterForest.test(); final parent = FlutterForest.test();
final bumpers = [ final bumpers = [
DashNestBumper.test(bloc: DashNestBumperCubit()), DashBumper.test(bloc: DashBumperCubit()),
DashNestBumper.test(bloc: DashNestBumperCubit()), DashBumper.test(bloc: DashBumperCubit()),
DashNestBumper.test(bloc: DashNestBumperCubit()), DashBumper.test(bloc: DashBumperCubit()),
]; ];
final animatronic = DashAnimatronic(); final animatronic = DashAnimatronic();
final signpost = Signpost.test(bloc: SignpostCubit()); final signpost = Signpost.test(bloc: SignpostCubit());
@ -140,7 +139,7 @@ void main() {
await parent.ensureAddAll([...bumpers, animatronic, signpost]); await parent.ensureAddAll([...bumpers, animatronic, signpost]);
await parent.ensureAdd(behavior); await parent.ensureAdd(behavior);
expect(game.descendants().whereType<DashNestBumper>(), equals(bumpers)); expect(game.descendants().whereType<DashBumper>(), equals(bumpers));
bumpers.forEach(_contactedBumper); bumpers.forEach(_contactedBumper);
await tester.pump(); await tester.pump();

@ -91,23 +91,23 @@ void main() {
); );
flameTester.test( flameTester.test(
'three DashNestBumper', 'three DashBumper',
(game) async { (game) async {
final component = FlutterForest(); final component = FlutterForest();
await game.pump(component); await game.pump(component);
expect( expect(
game.descendants().whereType<DashNestBumper>().length, game.descendants().whereType<DashBumper>().length,
equals(3), equals(3),
); );
}, },
); );
flameTester.test( flameTester.test(
'three DashNestBumpers with BumperNoiseBehavior', 'three DashBumpers with BumperNoiseBehavior',
(game) async { (game) async {
final component = FlutterForest(); final component = FlutterForest();
await game.pump(component); await game.pump(component);
final bumpers = game.descendants().whereType<DashNestBumper>(); final bumpers = game.descendants().whereType<DashBumper>();
for (final bumper in bumpers) { for (final bumper in bumpers) {
expect( expect(
bumper.firstChild<BumperNoiseBehavior>(), bumper.firstChild<BumperNoiseBehavior>(),

Loading…
Cancel
Save