mirror of https://github.com/flutter/pinball.git
feat: add dino game bonus (#301)
* feat: connect dino bonus * fix: remove ball on spit * refactor: move logic to cubit * chore: update test casespull/307/head
parent
30cb1f9daf
commit
9784091f84
@ -0,0 +1 @@
|
||||
export 'chrome_dino_bonus_behavior.dart';
|
@ -0,0 +1,24 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:pinball_flame/pinball_flame.dart';
|
||||
|
||||
/// Adds a [GameBonus.dinoChomp] when a [Ball] is chomped by the [ChromeDino].
|
||||
class ChromeDinoBonusBehavior extends Component
|
||||
with HasGameRef<PinballGame>, ParentIsA<DinoDesert> {
|
||||
@override
|
||||
void onMount() {
|
||||
super.onMount();
|
||||
final chromeDino = parent.firstChild<ChromeDino>()!;
|
||||
|
||||
// TODO(alestiago): Refactor subscription management once the following is
|
||||
// merged:
|
||||
// https://github.com/flame-engine/flame/pull/1538
|
||||
chromeDino.bloc.stream.listen((state) {
|
||||
final listenWhen = state.status == ChromeDinoStatus.chomping;
|
||||
if (!listenWhen) return;
|
||||
|
||||
gameRef.read<GameBloc>().add(const BonusActivated(GameBonus.dinoChomp));
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
// ignore_for_file: cascade_invocations
|
||||
|
||||
import 'package:bloc_test/bloc_test.dart';
|
||||
import 'package:flame_test/flame_test.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:pinball/game/components/dino_desert/behaviors/behaviors.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
|
||||
import '../../../../helpers/helpers.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
final assets = [
|
||||
Assets.images.dino.animatronic.head.keyName,
|
||||
Assets.images.dino.animatronic.mouth.keyName,
|
||||
Assets.images.dino.topWall.keyName,
|
||||
Assets.images.dino.bottomWall.keyName,
|
||||
Assets.images.slingshot.upper.keyName,
|
||||
Assets.images.slingshot.lower.keyName,
|
||||
];
|
||||
|
||||
group('ChromeDinoBonusBehavior', () {
|
||||
late GameBloc gameBloc;
|
||||
|
||||
setUp(() {
|
||||
gameBloc = MockGameBloc();
|
||||
whenListen(
|
||||
gameBloc,
|
||||
const Stream<GameState>.empty(),
|
||||
initialState: const GameState.initial(),
|
||||
);
|
||||
});
|
||||
|
||||
final flameBlocTester = FlameBlocTester<PinballGame, GameBloc>(
|
||||
gameBuilder: EmptyPinballTestGame.new,
|
||||
blocBuilder: () => gameBloc,
|
||||
assets: assets,
|
||||
);
|
||||
|
||||
flameBlocTester.testGameWidget(
|
||||
'adds GameBonus.dinoChomp to the game '
|
||||
'when ChromeDinoStatus.chomping is emitted',
|
||||
setUp: (game, tester) async {
|
||||
final behavior = ChromeDinoBonusBehavior();
|
||||
final parent = DinoDesert.test();
|
||||
final chromeDino = ChromeDino();
|
||||
|
||||
await parent.add(chromeDino);
|
||||
await game.ensureAdd(parent);
|
||||
await parent.ensureAdd(behavior);
|
||||
|
||||
chromeDino.bloc.onChomp(MockBall());
|
||||
await tester.pump();
|
||||
|
||||
verify(
|
||||
() => gameBloc.add(const BonusActivated(GameBonus.dinoChomp)),
|
||||
).called(1);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
Loading…
Reference in new issue