|
|
@ -9,7 +9,7 @@ import 'package:pinball_flame/pinball_flame.dart';
|
|
|
|
class MultiballBlinkingBehavior extends TimerComponent
|
|
|
|
class MultiballBlinkingBehavior extends TimerComponent
|
|
|
|
with ParentIsA<Multiball> {
|
|
|
|
with ParentIsA<Multiball> {
|
|
|
|
/// {@macro multiball_blinking_behavior}
|
|
|
|
/// {@macro multiball_blinking_behavior}
|
|
|
|
MultiballBlinkingBehavior() : super(period: 0.01);
|
|
|
|
MultiballBlinkingBehavior() : super(period: 0.1);
|
|
|
|
|
|
|
|
|
|
|
|
final _maxBlinks = 10;
|
|
|
|
final _maxBlinks = 10;
|
|
|
|
int _blinksCounter = 0;
|
|
|
|
int _blinksCounter = 0;
|
|
|
@ -19,21 +19,29 @@ class MultiballBlinkingBehavior extends TimerComponent
|
|
|
|
final animationEnabled =
|
|
|
|
final animationEnabled =
|
|
|
|
state.animationState == MultiballAnimationState.animated;
|
|
|
|
state.animationState == MultiballAnimationState.animated;
|
|
|
|
final canBlink = _blinksCounter < _maxBlinks;
|
|
|
|
final canBlink = _blinksCounter < _maxBlinks;
|
|
|
|
|
|
|
|
|
|
|
|
if (animationEnabled && canBlink) {
|
|
|
|
if (animationEnabled && canBlink) {
|
|
|
|
_animate();
|
|
|
|
_start();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
_stop();
|
|
|
|
_stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _animate() async {
|
|
|
|
void _start() {
|
|
|
|
if (!_isAnimating) {
|
|
|
|
if (!_isAnimating) {
|
|
|
|
_isAnimating = true;
|
|
|
|
_isAnimating = true;
|
|
|
|
parent.bloc.onBlink();
|
|
|
|
timer
|
|
|
|
_blinksCounter++;
|
|
|
|
..reset()
|
|
|
|
|
|
|
|
..start();
|
|
|
|
|
|
|
|
_animate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _animate() {
|
|
|
|
|
|
|
|
parent.bloc.onBlink();
|
|
|
|
|
|
|
|
_blinksCounter++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _stop() {
|
|
|
|
void _stop() {
|
|
|
|
if (_isAnimating) {
|
|
|
|
if (_isAnimating) {
|
|
|
|
_isAnimating = false;
|
|
|
|
_isAnimating = false;
|
|
|
@ -46,19 +54,23 @@ class MultiballBlinkingBehavior extends TimerComponent
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
await super.onLoad();
|
|
|
|
await super.onLoad();
|
|
|
|
timer.stop();
|
|
|
|
|
|
|
|
parent.bloc.stream.listen(_onNewState);
|
|
|
|
parent.bloc.stream.listen(_onNewState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void onTick() {
|
|
|
|
void onTick() {
|
|
|
|
super.onTick();
|
|
|
|
super.onTick();
|
|
|
|
if (_isAnimating) {
|
|
|
|
if (!_isAnimating) {
|
|
|
|
timer
|
|
|
|
|
|
|
|
..reset()
|
|
|
|
|
|
|
|
..start();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
timer.stop();
|
|
|
|
timer.stop();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (_blinksCounter < _maxBlinks) {
|
|
|
|
|
|
|
|
_animate();
|
|
|
|
|
|
|
|
timer
|
|
|
|
|
|
|
|
..reset()
|
|
|
|
|
|
|
|
..start();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
timer.stop();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|