refactor: multiball blink

pull/235/head
RuiAlonso 3 years ago
parent cbe698d171
commit 1c1cf96b94

@ -12,9 +12,11 @@ class MultiballsBehavior extends Component
BlocComponent<GameBloc, GameState> { BlocComponent<GameBloc, GameState> {
@override @override
bool listenWhen(GameState? previousState, GameState newState) { bool listenWhen(GameState? previousState, GameState newState) {
final hasMultiball = newState.bonusHistory.contains(GameBonus.dashNest);
final hasChanged = previousState?.bonusHistory != newState.bonusHistory; final hasChanged = previousState?.bonusHistory != newState.bonusHistory;
return hasChanged && hasMultiball; final lastBonusIsMultiball = newState.bonusHistory.isNotEmpty &&
newState.bonusHistory.last == GameBonus.dashNest;
return hasChanged && lastBonusIsMultiball;
} }
@override @override

@ -21,7 +21,6 @@ class MultiballBlinkingBehavior extends Component with ParentIsA<Multiball> {
} }
} }
// TODO(ruimiguel): try to improve with TimerComponent?
Future<void> _animate() async { Future<void> _animate() async {
if (!_isAnimating) { if (!_isAnimating) {
_isAnimating = true; _isAnimating = true;

@ -55,9 +55,10 @@ void main() {
test( test(
'is false when the bonusHistory has changed ' 'is false when the bonusHistory has changed '
'with a bonus different than GameBonus.dashNest', () { 'with a bonus different than GameBonus.dashNest', () {
final previous = GameState.initial(); final previous =
GameState.initial().copyWith(bonusHistory: [GameBonus.dashNest]);
final state = previous.copyWith( final state = previous.copyWith(
bonusHistory: [GameBonus.androidSpaceship], bonusHistory: [...previous.bonusHistory, GameBonus.androidSpaceship],
); );
expect( expect(
@ -67,6 +68,7 @@ void main() {
}); });
test('is false when the bonusHistory state is the same', () { test('is false when the bonusHistory state is the same', () {
final previous = GameState.initial();
final state = GameState( final state = GameState(
score: 10, score: 10,
multiplier: 1, multiplier: 1,
@ -74,7 +76,6 @@ void main() {
bonusHistory: const [], bonusHistory: const [],
); );
final previous = GameState.initial();
expect( expect(
MultiballsBehavior().listenWhen(previous, state), MultiballsBehavior().listenWhen(previous, state),
isFalse, isFalse,

Loading…
Cancel
Save