From 5b09601fda06995e00750a3337bd1fafbe4949ce Mon Sep 17 00:00:00 2001 From: cigjonser <79514190+cigjonser@users.noreply.github.com> Date: Mon, 6 Mar 2023 19:41:23 -0800 Subject: [PATCH 1/3] Update hud_margin_component.dart --- .../flame/lib/src/components/input/hud_margin_component.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/flame/lib/src/components/input/hud_margin_component.dart b/packages/flame/lib/src/components/input/hud_margin_component.dart index ae421ee100a..f44d4f940a0 100644 --- a/packages/flame/lib/src/components/input/hud_margin_component.dart +++ b/packages/flame/lib/src/components/input/hud_margin_component.dart @@ -69,9 +69,7 @@ class HudMarginComponent extends PositionComponent @override void onGameResize(Vector2 gameSize) { super.onGameResize(gameSize); - if (isMounted) { - _updateMargins(); - } + _updateMargins(); } void _updateMargins() { From 084dd03290876c3a2f28a55de0a10eff5d472111 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Tue, 7 Mar 2023 22:56:43 +0100 Subject: [PATCH 2/3] Add test for joystick fix --- .../test/components/joystick_component_test.dart | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/flame/test/components/joystick_component_test.dart b/packages/flame/test/components/joystick_component_test.dart index 6cd9fc88e0b..1740014c073 100644 --- a/packages/flame/test/components/joystick_component_test.dart +++ b/packages/flame/test/components/joystick_component_test.dart @@ -37,6 +37,20 @@ void main() { joystick.delta.setValues(-1.0, 1.0); expect(joystick.direction, JoystickDirection.downLeft); }); + + testWithGame<_GameHasDraggables>( + 'properly re-positions onGameSize', _GameHasDraggables.new, + (game) async { + game.onGameResize(Vector2(100, 200)); + final joystick = JoystickComponent( + knob: CircleComponent(radius: 5.0), + size: 20, + margin: const EdgeInsets.only(left: 20, bottom: 20), + ); + joystick.loaded.then((_) => game.onGameResize(Vector2(200, 100))); + await game.ensureAdd(joystick); + expect(joystick.position, Vector2(30, 70)); + }); }); group('Joystick input tests', () { From 758f66d1b32713ab6182fe689906dbaae25f6350 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Tue, 7 Mar 2023 23:04:16 +0100 Subject: [PATCH 3/3] Add trailing comma --- .../components/joystick_component_test.dart | 80 ++++++++++--------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/packages/flame/test/components/joystick_component_test.dart b/packages/flame/test/components/joystick_component_test.dart index 1740014c073..2cfa1a4aee7 100644 --- a/packages/flame/test/components/joystick_component_test.dart +++ b/packages/flame/test/components/joystick_component_test.dart @@ -10,47 +10,51 @@ class _GameHasDraggables extends FlameGame with HasDraggables {} void main() { group('JoystickDirection tests', () { testWithGame<_GameHasDraggables>( - 'can convert angle to JoystickDirection', _GameHasDraggables.new, - (game) async { - final joystick = JoystickComponent( - knob: CircleComponent(radius: 5.0), - size: 20, - margin: const EdgeInsets.only(left: 20, bottom: 20), - ); - await game.ensureAdd(joystick); + 'can convert angle to JoystickDirection', + _GameHasDraggables.new, + (game) async { + final joystick = JoystickComponent( + knob: CircleComponent(radius: 5.0), + size: 20, + margin: const EdgeInsets.only(left: 20, bottom: 20), + ); + await game.ensureAdd(joystick); - expect(joystick.direction, JoystickDirection.idle); - joystick.delta.setValues(1.0, 0.0); - expect(joystick.direction, JoystickDirection.right); - joystick.delta.setValues(0.0, -1.0); - expect(joystick.direction, JoystickDirection.up); - joystick.delta.setValues(1.0, -1.0); - expect(joystick.direction, JoystickDirection.upRight); - joystick.delta.setValues(-1.0, -1.0); - expect(joystick.direction, JoystickDirection.upLeft); - joystick.delta.setValues(-1.0, 0.0); - expect(joystick.direction, JoystickDirection.left); - joystick.delta.setValues(0.0, 1.0); - expect(joystick.direction, JoystickDirection.down); - joystick.delta.setValues(1.0, 1.0); - expect(joystick.direction, JoystickDirection.downRight); - joystick.delta.setValues(-1.0, 1.0); - expect(joystick.direction, JoystickDirection.downLeft); - }); + expect(joystick.direction, JoystickDirection.idle); + joystick.delta.setValues(1.0, 0.0); + expect(joystick.direction, JoystickDirection.right); + joystick.delta.setValues(0.0, -1.0); + expect(joystick.direction, JoystickDirection.up); + joystick.delta.setValues(1.0, -1.0); + expect(joystick.direction, JoystickDirection.upRight); + joystick.delta.setValues(-1.0, -1.0); + expect(joystick.direction, JoystickDirection.upLeft); + joystick.delta.setValues(-1.0, 0.0); + expect(joystick.direction, JoystickDirection.left); + joystick.delta.setValues(0.0, 1.0); + expect(joystick.direction, JoystickDirection.down); + joystick.delta.setValues(1.0, 1.0); + expect(joystick.direction, JoystickDirection.downRight); + joystick.delta.setValues(-1.0, 1.0); + expect(joystick.direction, JoystickDirection.downLeft); + }, + ); testWithGame<_GameHasDraggables>( - 'properly re-positions onGameSize', _GameHasDraggables.new, - (game) async { - game.onGameResize(Vector2(100, 200)); - final joystick = JoystickComponent( - knob: CircleComponent(radius: 5.0), - size: 20, - margin: const EdgeInsets.only(left: 20, bottom: 20), - ); - joystick.loaded.then((_) => game.onGameResize(Vector2(200, 100))); - await game.ensureAdd(joystick); - expect(joystick.position, Vector2(30, 70)); - }); + 'properly re-positions onGameSize', + _GameHasDraggables.new, + (game) async { + game.onGameResize(Vector2(100, 200)); + final joystick = JoystickComponent( + knob: CircleComponent(radius: 5.0), + size: 20, + margin: const EdgeInsets.only(left: 20, bottom: 20), + ); + joystick.loaded.then((_) => game.onGameResize(Vector2(200, 100))); + await game.ensureAdd(joystick); + expect(joystick.position, Vector2(30, 70)); + }, + ); }); group('Joystick input tests', () {