refactor: renamed DashNestBumper to DashBumper

pull/381/head
alestiago 3 years ago
parent b8f26b81de
commit 3eb44b6658

@ -7,7 +7,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.

@ -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<FlutterForest>,
@ -19,7 +19,7 @@ class FlutterForestBonusBehavior extends Component
void onMount() {
super.onMount();
final bumpers = parent.children.whereType<DashNestBumper>();
final bumpers = parent.children.whereType<DashBumper>();
final signpost = parent.firstChild<Signpost>()!;
final animatronic = parent.firstChild<DashAnimatronic>()!;
final canvas = gameRef.descendants().whereType<ZCanvasComponent>().single;
@ -27,7 +27,7 @@ class FlutterForestBonusBehavior extends Component
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) {

@ -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(),

@ -22,7 +22,7 @@ class BonusAnimation extends StatefulWidget {
Key? key,
VoidCallback? onCompleted,
}) : this._(
Assets.images.bonusAnimation.dashNest.keyName,
Assets.images.bonusAnimation.DashBumper.keyName,
onCompleted: onCompleted,
key: key,
);
@ -75,7 +75,7 @@ class BonusAnimation extends StatefulWidget {
static List<Future> loadAssets() {
Flame.images.prefix = '';
return [
Flame.images.load(Assets.images.bonusAnimation.dashNest.keyName),
Flame.images.load(Assets.images.bonusAnimation.DashBumper.keyName),
Flame.images.load(Assets.images.bonusAnimation.sparkyTurboCharge.keyName),
Flame.images.load(Assets.images.bonusAnimation.dinoChomp.keyName),
Flame.images.load(Assets.images.bonusAnimation.androidSpaceship.keyName),

@ -26,7 +26,7 @@ class $AssetsImagesBonusAnimationGen {
'assets/images/bonus_animation/android_spaceship.png');
/// File path: assets/images/bonus_animation/dash_nest.png
AssetGenImage get dashNest =>
AssetGenImage get DashBumper =>
const AssetGenImage('assets/images/bonus_animation/dash_nest.png');
/// File path: assets/images/bonus_animation/dino_chomp.png

@ -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';

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

@ -4,8 +4,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<DashNestBumper> {
class DashBumperBallContactBehavior extends ContactBehavior<DashBumper> {
@override
void beginContact(Object other, Contact contact) {
super.beginContact(other, contact);

@ -2,18 +2,18 @@
import 'package:bloc/bloc.dart';
part 'dash_nest_bumper_state.dart';
part 'dash_bumper_state.dart';
class DashNestBumperCubit extends Cubit<DashNestBumperState> {
DashNestBumperCubit() : super(DashNestBumperState.inactive);
class DashBumperCubit extends Cubit<DashBumperState> {
DashBumperCubit() : super(DashBumperState.inactive);
/// Event added when the bumper contacts with a ball.
void onBallContacted() {
emit(DashNestBumperState.active);
emit(DashBumperState.active);
}
/// Event added when the bumper should return to its initial configuration.
void onReset() {
emit(DashNestBumperState.inactive);
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: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}
/// {@template dash_bumper}
/// Bumper with a nest appearance.
/// {@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,19 @@ 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({
Iterable<Component>? children,
}) : this._(
majorRadius: 5.1,
@ -48,15 +48,15 @@ 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({
Iterable<Component>? children,
}) : this._(
majorRadius: 3,
@ -64,15 +64,15 @@ 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({
Iterable<Component>? children,
}) : this._(
majorRadius: 3.1,
@ -80,18 +80,18 @@ 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 an [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;
@ -99,7 +99,7 @@ class DashNestBumper extends BodyComponent with InitialPosition {
final double _minorRadius;
// ignore: public_member_api_docs
final DashNestBumperCubit bloc;
final DashBumperCubit bloc;
@override
void onRemove() {
@ -122,14 +122,14 @@ class DashNestBumper extends BodyComponent with InitialPosition {
}
}
class _DashNestBumperSpriteGroupComponent
extends SpriteGroupComponent<DashNestBumperState>
with HasGameRef, ParentIsA<DashNestBumper> {
_DashNestBumperSpriteGroupComponent({
class _DashBumperSpriteGroupComponent
extends SpriteGroupComponent<DashBumperState>
with HasGameRef, ParentIsA<DashBumper> {
_DashBumperSpriteGroupComponent({
required String activeAssetPath,
required String inactiveAssetPath,
required Vector2 position,
required DashNestBumperState current,
required DashBumperState current,
}) : _activeAssetPath = activeAssetPath,
_inactiveAssetPath = inactiveAssetPath,
super(
@ -147,9 +147,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;

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

@ -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 BigDashBumperGame extends BallGame {
BigDashBumperGame()
: 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 a BigDashBumper 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();
}

@ -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 SmallDashBumperAGame extends BallGame {
SmallDashBumperAGame()
: 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 a SmallDashBumper ("a") 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();
}
}

@ -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 SmallDashBumperBGame extends BallGame {
SmallDashBumperBGame()
: 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 a SmallDashBumper ("b") 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();
}
}

@ -13,18 +13,18 @@ void addFlutterForestStories(Dashbook dashbook) {
gameBuilder: (_) => SignpostGame(),
)
..addGame(
title: 'Big Dash Nest Bumper',
description: BigDashNestBumperGame.description,
gameBuilder: (_) => BigDashNestBumperGame(),
title: 'Big Dash Bumper',
description: BigDashBumperGame.description,
gameBuilder: (_) => BigDashBumperGame(),
)
..addGame(
title: 'Small Dash Nest Bumper A',
description: SmallDashNestBumperAGame.description,
gameBuilder: (_) => SmallDashNestBumperAGame(),
title: 'Small Dash Bumper A',
description: SmallDashBumperAGame.description,
gameBuilder: (_) => SmallDashBumperAGame(),
)
..addGame(
title: 'Small Dash Nest Bumper B',
description: SmallDashNestBumperBGame.description,
gameBuilder: (_) => SmallDashNestBumperBGame(),
title: 'Small Dash Bumper B',
description: SmallDashBumperBGame.description,
gameBuilder: (_) => SmallDashBumperBGame(),
);
}

@ -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<DashNestBumperBallContactBehavior>(),
DashBumperBallContactBehavior(),
isA<DashBumperBallContactBehavior>(),
);
});
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<DashNestBumperState>.empty(),
initialState: DashNestBumperState.active,
const Stream<DashBumperState>.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);
},
);
},

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

@ -58,20 +58,19 @@ 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 '
'adds GameBonus.DashBumper to the game '
'when bumpers are activated three times',
setUp: (game, tester) async {
await game.onLoad();
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());
@ -79,7 +78,7 @@ void main() {
await parent.ensureAddAll([...bumpers, animatronic, signpost]);
await parent.ensureAdd(behavior);
expect(game.descendants().whereType<DashNestBumper>(), equals(bumpers));
expect(game.descendants().whereType<DashBumper>(), equals(bumpers));
bumpers.forEach(_contactedBumper);
await tester.pump();
bumpers.forEach(_contactedBumper);
@ -101,9 +100,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());
@ -111,7 +110,7 @@ void main() {
await parent.ensureAddAll([...bumpers, animatronic, signpost]);
await parent.ensureAdd(behavior);
expect(game.descendants().whereType<DashNestBumper>(), equals(bumpers));
expect(game.descendants().whereType<DashBumper>(), equals(bumpers));
bumpers.forEach(_contactedBumper);
await tester.pump();
bumpers.forEach(_contactedBumper);
@ -135,9 +134,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());
@ -145,7 +144,7 @@ void main() {
await parent.ensureAddAll([...bumpers, animatronic, signpost]);
await parent.ensureAdd(behavior);
expect(game.descendants().whereType<DashNestBumper>(), equals(bumpers));
expect(game.descendants().whereType<DashBumper>(), equals(bumpers));
bumpers.forEach(_contactedBumper);
await tester.pump();

@ -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<DashNestBumper>().length,
game.descendants().whereType<DashBumper>().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<DashNestBumper>();
final bumpers = game.descendants().whereType<DashBumper>();
for (final bumper in bumpers) {
expect(
bumper.firstChild<BumperNoiseBehavior>(),

@ -63,7 +63,7 @@ void main() {
group('listenWhen', () {
test(
'is true when the bonusHistory has changed '
'with a new GameBonus.dashNest',
'with a new GameBonus.DashBumper',
() {
final previous = GameState.initial();
final state = previous.copyWith(
@ -79,7 +79,7 @@ void main() {
test(
'is false when the bonusHistory has changed '
'with a bonus different than GameBonus.dashNest', () {
'with a bonus different than GameBonus.DashBumper', () {
final previous =
GameState.initial().copyWith(bonusHistory: [GameBonus.dashNest]);
final state = previous.copyWith(

@ -22,7 +22,7 @@ void main() {
});
group('loads SpriteAnimationWidget correctly for', () {
testWidgets('dashNest', (tester) async {
testWidgets('DashBumper', (tester) async {
await tester.pumpApp(
BonusAnimation.dashNest(),
);

Loading…
Cancel
Save