From cad558b8b3b220359345cc93533a279d3b4ab01e Mon Sep 17 00:00:00 2001 From: Allison Ryan Date: Thu, 14 Apr 2022 17:03:40 -0500 Subject: [PATCH] refactor: use onComplete --- .../lib/src/components/dash_animatronic.dart | 14 +++----------- .../lib/src/components/sparky_animatronic.dart | 14 +++----------- .../test/src/components/dash_animatronic_test.dart | 3 +-- .../src/components/sparky_animatronic_test.dart | 3 +-- 4 files changed, 8 insertions(+), 26 deletions(-) diff --git a/packages/pinball_components/lib/src/components/dash_animatronic.dart b/packages/pinball_components/lib/src/components/dash_animatronic.dart index 634c5574..b3d03d3f 100644 --- a/packages/pinball_components/lib/src/components/dash_animatronic.dart +++ b/packages/pinball_components/lib/src/components/dash_animatronic.dart @@ -38,17 +38,9 @@ class DashAnimatronic extends SpriteAnimationComponent with HasGameRef { textureSize: textureSize, loop: false, ), - ); - } - - @override - void update(double dt) { - super.update(dt); - if (animation != null) { - if (animation!.isLastFrame) { - animation!.reset(); + )..onComplete = () { + animation?.reset(); playing = false; - } - } + }; } } diff --git a/packages/pinball_components/lib/src/components/sparky_animatronic.dart b/packages/pinball_components/lib/src/components/sparky_animatronic.dart index c9493eca..a999ed91 100644 --- a/packages/pinball_components/lib/src/components/sparky_animatronic.dart +++ b/packages/pinball_components/lib/src/components/sparky_animatronic.dart @@ -38,17 +38,9 @@ class SparkyAnimatronic extends SpriteAnimationComponent with HasGameRef { textureSize: textureSize, loop: false, ), - ); - } - - @override - void update(double dt) { - super.update(dt); - if (animation != null) { - if (animation!.isLastFrame) { - animation!.reset(); + )..onComplete = () { + animation?.reset(); playing = false; - } - } + }; } } diff --git a/packages/pinball_components/test/src/components/dash_animatronic_test.dart b/packages/pinball_components/test/src/components/dash_animatronic_test.dart index 11c34749..a9adf339 100644 --- a/packages/pinball_components/test/src/components/dash_animatronic_test.dart +++ b/packages/pinball_components/test/src/components/dash_animatronic_test.dart @@ -56,8 +56,7 @@ void main() { await game.ensureAdd(dashAnimatronic); dashAnimatronic.playing = true; - dashAnimatronic.animation?.setToLast(); - game.update(1); + game.update(4); expect(dashAnimatronic.playing, isFalse); }, diff --git a/packages/pinball_components/test/src/components/sparky_animatronic_test.dart b/packages/pinball_components/test/src/components/sparky_animatronic_test.dart index 58394989..6794f8a7 100644 --- a/packages/pinball_components/test/src/components/sparky_animatronic_test.dart +++ b/packages/pinball_components/test/src/components/sparky_animatronic_test.dart @@ -56,8 +56,7 @@ void main() { await game.ensureAdd(sparkyAnimatronic); sparkyAnimatronic.playing = true; - sparkyAnimatronic.animation?.setToLast(); - game.update(1); + game.update(3); expect(sparkyAnimatronic.playing, isFalse); },