Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spydon committed Jul 30, 2023
1 parent 7360b70 commit 3083ea8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/flame/test/camera/camera_component_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ void main() {
final nested = <Vector2>[];
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);
Expand Down
10 changes: 8 additions & 2 deletions packages/flame/test/camera/viewports/circular_viewport_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -118,6 +121,9 @@ void main() {
final nestedPoints = <Vector2>[];
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,20 @@ 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));
await game.ready();

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]) {
Expand Down

0 comments on commit 3083ea8

Please sign in to comment.