From 9bcce32b485d8323e5846154617a5f1bdf1e4812 Mon Sep 17 00:00:00 2001 From: alestiago Date: Mon, 9 May 2022 15:15:38 +0100 Subject: [PATCH] feat: resetting google word bonus --- lib/game/components/game_bloc_status_listener.dart | 10 ++++++++++ .../behaviors/google_word_bonus_behavior.dart | 2 +- .../google_word/cubit/google_word_cubit.dart | 10 +++++----- .../google_word/cubit/google_word_cubit_test.dart | 2 +- .../behaviors/google_word_bonus_behavior_test.dart | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/game/components/game_bloc_status_listener.dart b/lib/game/components/game_bloc_status_listener.dart index 4178a71d..3343b5ff 100644 --- a/lib/game/components/game_bloc_status_listener.dart +++ b/lib/game/components/game_bloc_status_listener.dart @@ -21,6 +21,7 @@ class GameBlocStatusListener extends Component break; case GameStatus.playing: readProvider().play(PinballAudio.backgroundMusic); + _resetBonuses(); gameRef .descendants() .whereType() @@ -46,6 +47,15 @@ class GameBlocStatusListener extends Component } } + void _resetBonuses() { + gameRef + .descendants() + .whereType>() + .single + .bloc + .onReset(); + } + void _addFlipperKeyControls(Flipper flipper) { flipper ..add(FlipperKeyControllingBehavior()) diff --git a/lib/game/components/google_gallery/behaviors/google_word_bonus_behavior.dart b/lib/game/components/google_gallery/behaviors/google_word_bonus_behavior.dart index 787fcefc..c5ff90cf 100644 --- a/lib/game/components/google_gallery/behaviors/google_word_bonus_behavior.dart +++ b/lib/game/components/google_gallery/behaviors/google_word_bonus_behavior.dart @@ -17,7 +17,7 @@ class GoogleWordBonusBehavior extends Component { onNewState: (state) { readBloc() .add(const BonusActivated(GameBonus.googleWord)); - readBloc().onBonusAwarded(); + readBloc().onReset(); add(BonusBallSpawningBehavior()); }, ), diff --git a/packages/pinball_components/lib/src/components/google_word/cubit/google_word_cubit.dart b/packages/pinball_components/lib/src/components/google_word/cubit/google_word_cubit.dart index 197771d6..154d550d 100644 --- a/packages/pinball_components/lib/src/components/google_word/cubit/google_word_cubit.dart +++ b/packages/pinball_components/lib/src/components/google_word/cubit/google_word_cubit.dart @@ -11,6 +11,11 @@ class GoogleWordCubit extends Cubit { int _lastLitLetter = 0; + void onReset() { + emit(GoogleWordState.initial()); + _lastLitLetter = 0; + } + void onRolloverContacted() { final spriteStatesMap = {...state.letterSpriteStates}; if (_lastLitLetter < _lettersInGoogle) { @@ -22,9 +27,4 @@ class GoogleWordCubit extends Cubit { _lastLitLetter++; } } - - void onBonusAwarded() { - emit(GoogleWordState.initial()); - _lastLitLetter = 0; - } } diff --git a/packages/pinball_components/test/src/components/google_word/cubit/google_word_cubit_test.dart b/packages/pinball_components/test/src/components/google_word/cubit/google_word_cubit_test.dart index 08acfae8..d315b7c4 100644 --- a/packages/pinball_components/test/src/components/google_word/cubit/google_word_cubit_test.dart +++ b/packages/pinball_components/test/src/components/google_word/cubit/google_word_cubit_test.dart @@ -27,7 +27,7 @@ void main() { blocTest( 'onBonusAwarded emits initial state', build: GoogleWordCubit.new, - act: (bloc) => bloc.onBonusAwarded(), + act: (bloc) => bloc.onReset(), expect: () => [GoogleWordState.initial()], ); }, diff --git a/test/game/components/google_gallery/behaviors/google_word_bonus_behavior_test.dart b/test/game/components/google_gallery/behaviors/google_word_bonus_behavior_test.dart index 4b3ec2bd..e5a25264 100644 --- a/test/game/components/google_gallery/behaviors/google_word_bonus_behavior_test.dart +++ b/test/game/components/google_gallery/behaviors/google_word_bonus_behavior_test.dart @@ -114,7 +114,7 @@ void main() { verify( () => gameBloc.add(const BonusActivated(GameBonus.googleWord)), ).called(1); - verify(googleWordBloc.onBonusAwarded).called(1); + verify(googleWordBloc.onReset).called(1); }, );