From 3083ea8f7348541f6be730903d290cf6e6243fd0 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Sun, 30 Jul 2023 10:40:27 +0200 Subject: [PATCH] Fix tests --- packages/flame/test/camera/camera_component_test.dart | 6 +++--- .../test/camera/viewports/circular_viewport_test.dart | 10 ++++++++-- .../viewports/fixed_aspect_ratio_viewport_test.dart | 7 +++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/flame/test/camera/camera_component_test.dart b/packages/flame/test/camera/camera_component_test.dart index 99834e391c9..5ac71e97e9f 100644 --- a/packages/flame/test/camera/camera_component_test.dart +++ b/packages/flame/test/camera/camera_component_test.dart @@ -200,15 +200,15 @@ void main() { final nested = []; final it = game.componentsAtPoint(Vector2(400, 300), nested).iterator; expect(it.moveNext(), true); + expect(it.current, camera.viewport); + expect(nested, [Vector2(400, 300), Vector2(300, 200)]); + expect(it.moveNext(), true); expect(it.current, component); expect(nested, [Vector2(400, 300), Vector2(100, 50), Vector2(50, 20)]); expect(it.moveNext(), true); expect(it.current, world); expect(nested, [Vector2(400, 300), Vector2(100, 50)]); expect(it.moveNext(), true); - expect(it.current, camera.viewport); - expect(nested, [Vector2(400, 300), Vector2(300, 200)]); - expect(it.moveNext(), true); expect(it.current, game); expect(nested, [Vector2(400, 300)]); expect(it.moveNext(), false); diff --git a/packages/flame/test/camera/viewports/circular_viewport_test.dart b/packages/flame/test/camera/viewports/circular_viewport_test.dart index 8573a74999d..edc60d5ea89 100644 --- a/packages/flame/test/camera/viewports/circular_viewport_test.dart +++ b/packages/flame/test/camera/viewports/circular_viewport_test.dart @@ -95,15 +95,18 @@ void main() { testWithFlameGame('hit testing', (game) async { final world = _MyWorld(); + final viewport = CircularViewport.ellipse(80, 20) + ..position = Vector2(20, 30); final camera = CameraComponent( world: world, - viewport: CircularViewport.ellipse(80, 20)..position = Vector2(20, 30), + viewport: viewport, ); game.addAll([world, camera]); await game.ready(); bool hit(double x, double y) { - return game.componentsAtPoint(Vector2(x, y)).first == world; + final components = game.componentsAtPoint(Vector2(x, y)).toList(); + return components.first == viewport && components[1] == world; } expect(hit(10, 20), false); @@ -118,6 +121,9 @@ void main() { final nestedPoints = []; final center = Vector2(100, 50); for (final component in game.componentsAtPoint(center, nestedPoints)) { + if (component == viewport) { + continue; + } expect(component, world); expect(nestedPoints.last, Vector2.zero()); break; diff --git a/packages/flame/test/camera/viewports/fixed_aspect_ratio_viewport_test.dart b/packages/flame/test/camera/viewports/fixed_aspect_ratio_viewport_test.dart index 80d5fa16c66..b8fff2cb71a 100644 --- a/packages/flame/test/camera/viewports/fixed_aspect_ratio_viewport_test.dart +++ b/packages/flame/test/camera/viewports/fixed_aspect_ratio_viewport_test.dart @@ -71,9 +71,10 @@ void main() { testWithFlameGame('hit testing', (game) async { final world = World(); + final viewport = FixedAspectRatioViewport(aspectRatio: 1); final camera = CameraComponent( world: world, - viewport: FixedAspectRatioViewport(aspectRatio: 1), + viewport: viewport, ); game.addAll([world, camera]); game.onGameResize(Vector2(100, 200)); @@ -81,7 +82,9 @@ void main() { bool hit(double x, double y) { final components = game.componentsAtPoint(Vector2(x, y)).toList(); - return components.isNotEmpty && components.first == world; + return components.isNotEmpty && + components.first == viewport && + components[1] == world; } for (final x in [0.0, 5.0, 50.0, 100.0]) {