From f48bf4d654d65626839cf33d8e33a8ee026c7b2e Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Wed, 7 Oct 2020 09:20:28 +0200 Subject: [PATCH] All components must call super --- doc/examples/effects/simple/lib/main_move.dart | 4 ++-- doc/examples/joystick/lib/player.dart | 1 + doc/examples/particles/lib/main.dart | 1 + lib/components/component.dart | 2 ++ lib/components/joystick/joystick_component.dart | 1 + lib/components/particle_component.dart | 1 + lib/components/position_component.dart | 4 ---- lib/components/sprite_batch_component.dart | 3 --- lib/components/timer_component.dart | 5 ++++- 9 files changed, 12 insertions(+), 10 deletions(-) diff --git a/doc/examples/effects/simple/lib/main_move.dart b/doc/examples/effects/simple/lib/main_move.dart index ab09b0220..7928b3671 100644 --- a/doc/examples/effects/simple/lib/main_move.dart +++ b/doc/examples/effects/simple/lib/main_move.dart @@ -16,10 +16,10 @@ class MyGame extends BaseGame with TapDetector { } @override - void onTapUp(details) { + void onTapUp(TapUpDetails details) { square.addEffect(MoveEffect( path: [ - details.localPosition.toVector2().clone(), + details.localPosition.toVector2(), Vector2(100, 100), Vector2(50, 120), Vector2(200, 400), diff --git a/doc/examples/joystick/lib/player.dart b/doc/examples/joystick/lib/player.dart index 2781dbd51..75a3a7aad 100644 --- a/doc/examples/joystick/lib/player.dart +++ b/doc/examples/joystick/lib/player.dart @@ -37,6 +37,7 @@ class Player extends Component implements JoystickListener { @override void update(double dt) { + super.update(dt); if (_move) { moveFromAngle(dt); } diff --git a/doc/examples/particles/lib/main.dart b/doc/examples/particles/lib/main.dart index 2fed640ff..a68819c5b 100644 --- a/doc/examples/particles/lib/main.dart +++ b/doc/examples/particles/lib/main.dart @@ -590,6 +590,7 @@ class TrafficLightComponent extends Component { @override void update(double dt) { + super.update(dt); colorChangeTimer.update(dt); } diff --git a/lib/components/component.dart b/lib/components/component.dart index 99caf733f..a0647a074 100644 --- a/lib/components/component.dart +++ b/lib/components/component.dart @@ -1,6 +1,7 @@ import 'dart:ui'; import 'package:flutter/painting.dart'; +import 'package:meta/meta.dart'; import '../effects/effects.dart'; import '../extensions/vector2.dart'; @@ -19,6 +20,7 @@ abstract class Component { /// The time [t] in seconds (with microseconds precision provided by Flutter) since the last update cycle. /// This time can vary according to hardware capacity, so make sure to update your state considering this. /// All components on [BaseGame] are always updated by the same amount. The time each one takes to update adds up to the next update cycle. + @mustCallSuper void update(double dt) { _effects.forEach((e) => e.update(dt)); _effects.removeWhere((e) => e.hasFinished()); diff --git a/lib/components/joystick/joystick_component.dart b/lib/components/joystick/joystick_component.dart index 4c0d3e4dd..939372d4c 100644 --- a/lib/components/joystick/joystick_component.dart +++ b/lib/components/joystick/joystick_component.dart @@ -65,6 +65,7 @@ class JoystickComponent extends JoystickController { @override void update(double t) { + super.update(t); directional?.update(t); actions?.forEach((action) => action.update(t)); } diff --git a/lib/components/particle_component.dart b/lib/components/particle_component.dart index de1e08289..a30bc13a6 100644 --- a/lib/components/particle_component.dart +++ b/lib/components/particle_component.dart @@ -35,6 +35,7 @@ class ParticleComponent extends Component { /// Passes update chain to child [Particle]. @override void update(double dt) { + super.update(dt); particle.update(dt); } } diff --git a/lib/components/position_component.dart b/lib/components/position_component.dart index f2759a343..3ff9489a3 100644 --- a/lib/components/position_component.dart +++ b/lib/components/position_component.dart @@ -182,10 +182,6 @@ abstract class PositionComponent extends Component { canvas.restore(); } - @mustCallSuper - @override - void update(double dt) => super.update(dt); - void _renderChild(Canvas canvas, Component c) { if (!c.loaded()) { return; diff --git a/lib/components/sprite_batch_component.dart b/lib/components/sprite_batch_component.dart index 23dc590a3..c3270cc67 100644 --- a/lib/components/sprite_batch_component.dart +++ b/lib/components/sprite_batch_component.dart @@ -25,7 +25,4 @@ class SpriteBatchComponent extends Component { paint: paint, ); } - - @override - void update(double t) {} } diff --git a/lib/components/timer_component.dart b/lib/components/timer_component.dart index 108eb766c..7c58855e4 100644 --- a/lib/components/timer_component.dart +++ b/lib/components/timer_component.dart @@ -10,7 +10,10 @@ class TimerComponent extends Component { TimerComponent(this.timer); @override - void update(double dt) => timer.update(dt); + void update(double dt) { + super.update(dt); + timer.update(dt); + } @override void render(Canvas canvas) {}