revert: looping animatronics

pull/458/head
Allison Ryan 3 years ago
parent d2dd83ff66
commit 8a63b100e8

@ -21,6 +21,7 @@ class FlutterForestBonusBehavior extends Component
final bumpers = parent.children.whereType<DashBumper>();
final signpost = parent.firstChild<Signpost>()!;
final animatronic = parent.firstChild<DashAnimatronic>()!;
for (final bumper in bumpers) {
bumper.bloc.stream.listen((state) {
@ -37,6 +38,7 @@ class FlutterForestBonusBehavior extends Component
if (signpost.bloc.isFullyProgressed()) {
bloc.add(const BonusActivated(GameBonus.dashNest));
add(BonusBallSpawningBehavior());
animatronic.playing = true;
signpost.bloc.onProgressed();
}
}

@ -40,11 +40,7 @@ class FlutterForest extends Component with ZIndex {
BumperNoiseBehavior(),
],
)..initialPosition = Vector2(21.8, -46.75),
DashAnimatronic(
children: [
AnimatronicLoopingBehavior(animationCoolDown: 4),
],
)..position = Vector2(20, -66),
DashAnimatronic()..position = Vector2(20, -66),
FlutterForestBonusBehavior(),
],
) {

@ -12,11 +12,13 @@ class SparkyComputerBonusBehavior extends Component
void onMount() {
super.onMount();
final sparkyComputer = parent.firstChild<SparkyComputer>()!;
final animatronic = parent.firstChild<SparkyAnimatronic>()!;
sparkyComputer.bloc.stream.listen((state) async {
final listenWhen = state == SparkyComputerState.withBall;
if (!listenWhen) return;
bloc.add(const BonusActivated(GameBonus.sparkyTurboCharge));
animatronic.playing = true;
});
}
}

@ -33,11 +33,7 @@ class SparkyScorch extends Component {
BumperNoiseBehavior(),
],
)..initialPosition = Vector2(-3.3, -52.55),
SparkyAnimatronic(
children: [
AnimatronicLoopingBehavior(animationCoolDown: 3),
],
)..position = Vector2(-14, -58.2),
SparkyAnimatronic()..position = Vector2(-14, -58.2),
SparkyComputer(
children: [
ScoringContactBehavior(points: Points.twoHundredThousand)

@ -6,11 +6,10 @@ import 'package:pinball_components/pinball_components.dart';
/// {@endtemplate}
class DashAnimatronic extends SpriteAnimationComponent with HasGameRef {
/// {@macro dash_animatronic}
DashAnimatronic({Iterable<Component>? children})
DashAnimatronic()
: super(
anchor: Anchor.center,
playing: false,
children: children,
);
@override
@ -38,6 +37,9 @@ class DashAnimatronic extends SpriteAnimationComponent with HasGameRef {
textureSize: textureSize,
loop: false,
),
);
)..onComplete = () {
animation?.reset();
playing = false;
};
}
}

@ -8,11 +8,10 @@ import 'package:pinball_flame/pinball_flame.dart';
class SparkyAnimatronic extends SpriteAnimationComponent
with HasGameRef, ZIndex {
/// {@macro sparky_animatronic}
SparkyAnimatronic({Iterable<Component>? children})
SparkyAnimatronic()
: super(
anchor: Anchor.center,
playing: false,
children: children,
) {
zIndex = ZIndexes.sparkyAnimatronic;
}
@ -42,6 +41,9 @@ class SparkyAnimatronic extends SpriteAnimationComponent
textureSize: textureSize,
loop: false,
),
);
)..onComplete = () {
animation?.reset();
playing = false;
};
}
}

@ -56,13 +56,17 @@ void main() {
},
);
flameTester.test('adds new children', (game) async {
final component = Component();
final dashAnimatronic = DashAnimatronic(
children: [component],
);
await game.ensureAdd(dashAnimatronic);
expect(dashAnimatronic.children, contains(component));
});
flameTester.test(
'stops animating after animation completes',
(game) async {
final dashAnimatronic = DashAnimatronic();
await game.ensureAdd(dashAnimatronic);
dashAnimatronic.playing = true;
game.update(4);
expect(dashAnimatronic.playing, isFalse);
},
);
});
}

@ -58,13 +58,19 @@ void main() {
},
);
flameTester.test('adds new children', (game) async {
final component = Component();
final sparkyAnimatronic = SparkyAnimatronic(
children: [component],
);
await game.ensureAdd(sparkyAnimatronic);
expect(sparkyAnimatronic.children, contains(component));
});
flameTester.test(
'stops animating after animation completes',
(game) async {
final sparkyAnimatronic = SparkyAnimatronic();
await game.ensureAdd(sparkyAnimatronic);
sparkyAnimatronic.playing = true;
final animationDuration =
game.firstChild<SparkyAnimatronic>()!.animation!.totalDuration();
game.update(animationDuration);
expect(sparkyAnimatronic.playing, isFalse);
},
);
});
}

@ -16,7 +16,10 @@ class _TestGame extends Forge2DGame {
@override
Future<void> onLoad() async {
images.prefix = '';
await images.load(theme.Assets.images.dash.ball.keyName);
await images.loadAll([
Assets.images.dash.animatronic.keyName,
theme.Assets.images.dash.ball.keyName,
]);
}
Future<void> pump(
@ -53,7 +56,7 @@ void main() {
void _contactedBumper(DashBumper bumper) => bumper.bloc.onBallContacted();
flameTester.testGameWidget(
'adds GameBonus.dashNest to the game '
'adds GameBonus.dashNest to the game and plays animatronic '
'when bumpers are activated three times',
setUp: (game, tester) async {
await game.onLoad();
@ -64,9 +67,10 @@ void main() {
DashBumper.test(bloc: DashBumperCubit()),
DashBumper.test(bloc: DashBumperCubit()),
];
final animatronic = DashAnimatronic();
final signpost = Signpost.test(bloc: SignpostCubit());
await game.pump(parent, gameBloc: gameBloc);
await parent.ensureAddAll([...bumpers, signpost]);
await parent.ensureAddAll([...bumpers, animatronic, signpost]);
await parent.ensureAdd(behavior);
expect(game.descendants().whereType<DashBumper>(), equals(bumpers));
@ -80,6 +84,7 @@ void main() {
verify(
() => gameBloc.add(const BonusActivated(GameBonus.dashNest)),
).called(1);
expect(animatronic.playing, isTrue);
},
);
@ -95,9 +100,10 @@ void main() {
DashBumper.test(bloc: DashBumperCubit()),
DashBumper.test(bloc: DashBumperCubit()),
];
final animatronic = DashAnimatronic();
final signpost = Signpost.test(bloc: SignpostCubit());
await game.pump(parent, gameBloc: gameBloc);
await parent.ensureAddAll([...bumpers, signpost]);
await parent.ensureAddAll([...bumpers, animatronic, signpost]);
await parent.ensureAdd(behavior);
expect(game.descendants().whereType<DashBumper>(), equals(bumpers));
@ -128,9 +134,10 @@ void main() {
DashBumper.test(bloc: DashBumperCubit()),
DashBumper.test(bloc: DashBumperCubit()),
];
final animatronic = DashAnimatronic();
final signpost = Signpost.test(bloc: SignpostCubit());
await game.pump(parent, gameBloc: gameBloc);
await parent.ensureAddAll([...bumpers, signpost]);
await parent.ensureAddAll([...bumpers, animatronic, signpost]);
await parent.ensureAdd(behavior);
expect(game.descendants().whereType<DashBumper>(), equals(bumpers));

@ -17,6 +17,7 @@ class _TestGame extends Forge2DGame {
Assets.images.sparky.computer.top.keyName,
Assets.images.sparky.computer.base.keyName,
Assets.images.sparky.computer.glow.keyName,
Assets.images.sparky.animatronic.keyName,
Assets.images.sparky.bumper.a.lit.keyName,
Assets.images.sparky.bumper.a.dimmed.keyName,
Assets.images.sparky.bumper.b.lit.keyName,
@ -57,14 +58,15 @@ void main() {
final flameTester = FlameTester(_TestGame.new);
flameTester.testGameWidget(
'adds GameBonus.sparkyTurboCharge to the game '
'adds GameBonus.sparkyTurboCharge to the game and plays animatronic '
'when SparkyComputerState.withBall is emitted',
setUp: (game, tester) async {
final behavior = SparkyComputerBonusBehavior();
final parent = SparkyScorch.test();
final sparkyComputer = SparkyComputer();
final animatronic = SparkyAnimatronic();
await parent.add(sparkyComputer);
await parent.addAll([sparkyComputer, animatronic]);
await game.pump(parent, gameBloc: gameBloc);
await parent.ensureAdd(behavior);
@ -74,6 +76,7 @@ void main() {
verify(
() => gameBloc.add(const BonusActivated(GameBonus.sparkyTurboCharge)),
).called(1);
expect(animatronic.playing, isTrue);
},
);
});

Loading…
Cancel
Save