fix: deactivate bonus word while effect (#61)

* fix: fixed error activating bottom letter while bonus word animation

* test: coverage for test isEnabled

* Update lib/game/components/bonus_word.dart

Co-authored-by: Alejandro Santiago <dev@alestiago.com>

* chore: test method name

Co-authored-by: Alejandro Santiago <dev@alestiago.com>
Co-authored-by: Erick <erickzanardoo@gmail.com>
pull/74/head
Rui Miguel Alonso 4 years ago committed by GitHub
parent a111fd417e
commit 5f90e62258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,31 +36,39 @@ class BonusWord extends Component with BlocComponent<GameBloc, GameState> {
for (var i = 0; i < letters.length; i++) { for (var i = 0; i < letters.length; i++) {
final letter = letters[i]; final letter = letters[i];
letter.add( letter
SequenceEffect( ..isEnabled = false
[ ..add(
ColorEffect( SequenceEffect(
i.isOdd ? BonusLetter._activeColor : BonusLetter._disableColor, [
const Offset(0, 1),
EffectController(duration: 0.25),
),
ColorEffect(
i.isOdd ? BonusLetter._disableColor : BonusLetter._activeColor,
const Offset(0, 1),
EffectController(duration: 0.25),
),
],
repeatCount: 4,
)..onFinishCallback = () {
letter.add(
ColorEffect( ColorEffect(
BonusLetter._disableColor, i.isOdd
? BonusLetter._activeColor
: BonusLetter._disableColor,
const Offset(0, 1), const Offset(0, 1),
EffectController(duration: 0.25), EffectController(duration: 0.25),
), ),
); ColorEffect(
}, i.isOdd
); ? BonusLetter._disableColor
: BonusLetter._activeColor,
const Offset(0, 1),
EffectController(duration: 0.25),
),
],
repeatCount: 4,
)..onFinishCallback = () {
letter
..isEnabled = true
..add(
ColorEffect(
BonusLetter._disableColor,
const Offset(0, 1),
EffectController(duration: 0.25),
),
);
},
);
} }
} }
} }
@ -107,6 +115,13 @@ class BonusLetter extends BodyComponent<PinballGame>
final String _letter; final String _letter;
final int _index; final int _index;
/// Indicates if a [BonusLetter] can be activated on [Ball] contact.
///
/// It is disabled whilst animating and enabled again once the animation
/// completes. The animation is triggered when [GameBonus.word] is
/// awarded.
bool isEnabled = true;
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
@ -172,6 +187,8 @@ class BonusLetterBallContactCallback
extends ContactCallback<Ball, BonusLetter> { extends ContactCallback<Ball, BonusLetter> {
@override @override
void begin(Ball ball, BonusLetter bonusLetter, Contact contact) { void begin(Ball ball, BonusLetter bonusLetter, Contact contact) {
bonusLetter.activate(); if (bonusLetter.isEnabled) {
bonusLetter.activate();
}
} }
} }

@ -300,12 +300,26 @@ void main() {
test('calls ball.activate', () { test('calls ball.activate', () {
final ball = MockBall(); final ball = MockBall();
final bonusLetter = MockBonusLetter(); final bonusLetter = MockBonusLetter();
final contactCallback = BonusLetterBallContactCallback(); final contactCallback = BonusLetterBallContactCallback();
when(() => bonusLetter.isEnabled).thenReturn(true);
contactCallback.begin(ball, bonusLetter, MockContact()); contactCallback.begin(ball, bonusLetter, MockContact());
verify(bonusLetter.activate).called(1); verify(bonusLetter.activate).called(1);
}); });
test("doesn't call ball.activate when letter is disabled", () {
final ball = MockBall();
final bonusLetter = MockBonusLetter();
final contactCallback = BonusLetterBallContactCallback();
when(() => bonusLetter.isEnabled).thenReturn(false);
contactCallback.begin(ball, bonusLetter, MockContact());
verifyNever(bonusLetter.activate);
});
}); });
}); });
} }

Loading…
Cancel
Save