|
|
@ -1,6 +1,4 @@
|
|
|
|
// ignore_for_file: cascade_invocations
|
|
|
|
// ignore_for_file: cascade_invocations
|
|
|
|
import 'dart:math' as math;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
|
import 'package:flame_test/flame_test.dart';
|
|
|
|
import 'package:flame_test/flame_test.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
@ -18,98 +16,98 @@ class TestBodyComponent extends BodyComponent with Elevated {
|
|
|
|
void main() {
|
|
|
|
void main() {
|
|
|
|
final flameTester = FlameTester(Forge2DGame.new);
|
|
|
|
final flameTester = FlameTester(Forge2DGame.new);
|
|
|
|
|
|
|
|
|
|
|
|
group('Prioritized', () {
|
|
|
|
group('Elevated', () {
|
|
|
|
test('correctly sets and gets', () {
|
|
|
|
test('correctly sets and gets', () {
|
|
|
|
final component = TestBodyComponent()
|
|
|
|
final component = TestBodyComponent()
|
|
|
|
..elevation = Elevation.spaceship.order;
|
|
|
|
..elevation = Elevation.spaceship.order;
|
|
|
|
expect(component.elevation, Elevation.spaceship);
|
|
|
|
expect(component.elevation, Elevation.spaceship.order);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.test(
|
|
|
|
flameTester.test(
|
|
|
|
'priority correctly before being loaded',
|
|
|
|
'elevation correctly before being loaded',
|
|
|
|
(game) async {
|
|
|
|
(game) async {
|
|
|
|
const expectedPriority = Elevation.spaceship;
|
|
|
|
const expectedElevation = Elevation.spaceship;
|
|
|
|
final component = TestBodyComponent()
|
|
|
|
final component = TestBodyComponent()
|
|
|
|
..elevation = expectedPriority.order;
|
|
|
|
..elevation = expectedElevation.order;
|
|
|
|
await game.ensureAdd(component);
|
|
|
|
await game.ensureAdd(component);
|
|
|
|
// TODO(alestiago): modify once component.loaded is available.
|
|
|
|
// TODO(alestiago): modify once component.loaded is available.
|
|
|
|
await component.mounted;
|
|
|
|
await component.mounted;
|
|
|
|
|
|
|
|
|
|
|
|
expect(component.elevation, equals(expectedPriority));
|
|
|
|
expect(component.elevation, equals(expectedElevation.order));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.test(
|
|
|
|
flameTester.test(
|
|
|
|
'priority correctly before being loaded '
|
|
|
|
'elevation correctly before being loaded '
|
|
|
|
'when multiple different sets',
|
|
|
|
'when multiple different sets',
|
|
|
|
(game) async {
|
|
|
|
(game) async {
|
|
|
|
const expectedPriority = Elevation.spaceship;
|
|
|
|
const expectedElevation = Elevation.spaceship;
|
|
|
|
final component = TestBodyComponent()
|
|
|
|
final component = TestBodyComponent()
|
|
|
|
..elevation = Elevation.jetpack.order;
|
|
|
|
..elevation = Elevation.jetpack.order;
|
|
|
|
|
|
|
|
|
|
|
|
expect(component.elevation, isNot(equals(expectedPriority)));
|
|
|
|
expect(component.elevation, isNot(equals(expectedElevation.order)));
|
|
|
|
component.elevation = expectedPriority.order;
|
|
|
|
component.elevation = expectedElevation.order;
|
|
|
|
|
|
|
|
|
|
|
|
await game.ensureAdd(component);
|
|
|
|
await game.ensureAdd(component);
|
|
|
|
// TODO(alestiago): modify once component.loaded is available.
|
|
|
|
// TODO(alestiago): modify once component.loaded is available.
|
|
|
|
await component.mounted;
|
|
|
|
await component.mounted;
|
|
|
|
|
|
|
|
|
|
|
|
expect(component.elevation, expectedPriority);
|
|
|
|
expect(component.elevation, expectedElevation.order);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.test(
|
|
|
|
flameTester.test(
|
|
|
|
'priority correctly after being loaded',
|
|
|
|
'elevation correctly after being loaded',
|
|
|
|
(game) async {
|
|
|
|
(game) async {
|
|
|
|
const expectedPriority = Elevation.spaceship;
|
|
|
|
const expectedElevation = Elevation.spaceship;
|
|
|
|
final component = TestBodyComponent();
|
|
|
|
final component = TestBodyComponent();
|
|
|
|
await game.ensureAdd(component);
|
|
|
|
await game.ensureAdd(component);
|
|
|
|
component.elevation = expectedPriority.order;
|
|
|
|
component.elevation = expectedElevation.order;
|
|
|
|
expect(component.elevation, expectedPriority);
|
|
|
|
expect(component.elevation, expectedElevation.order);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.test(
|
|
|
|
flameTester.test(
|
|
|
|
'priority correctly after being loaded '
|
|
|
|
'elevation correctly after being loaded '
|
|
|
|
'when multiple different sets',
|
|
|
|
'when multiple different sets',
|
|
|
|
(game) async {
|
|
|
|
(game) async {
|
|
|
|
const expectedPriority = Elevation.spaceship;
|
|
|
|
const expectedElevation = Elevation.spaceship;
|
|
|
|
final component = TestBodyComponent();
|
|
|
|
final component = TestBodyComponent();
|
|
|
|
await game.ensureAdd(component);
|
|
|
|
await game.ensureAdd(component);
|
|
|
|
|
|
|
|
|
|
|
|
component.elevation = Elevation.jetpack.order;
|
|
|
|
component.elevation = Elevation.jetpack.order;
|
|
|
|
expect(component.elevation, isNot(equals(expectedPriority)));
|
|
|
|
expect(component.elevation, isNot(equals(expectedElevation.order)));
|
|
|
|
component.elevation = expectedPriority.order;
|
|
|
|
component.elevation = expectedElevation.order;
|
|
|
|
|
|
|
|
|
|
|
|
expect(component.elevation, expectedPriority);
|
|
|
|
expect(component.elevation, expectedElevation.order);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.test(
|
|
|
|
flameTester.test(
|
|
|
|
'defaults to Priority.board '
|
|
|
|
'defaults to Elevation.board '
|
|
|
|
'when no priority is given',
|
|
|
|
'when no elevation is given',
|
|
|
|
(game) async {
|
|
|
|
(game) async {
|
|
|
|
final component = TestBodyComponent();
|
|
|
|
final component = TestBodyComponent();
|
|
|
|
await game.ensureAdd(component);
|
|
|
|
await game.ensureAdd(component);
|
|
|
|
expect(component.elevation, equals(Elevation.board));
|
|
|
|
expect(component.elevation, equals(Elevation.board.order));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
group('PriorityOrder', () {
|
|
|
|
group('ElevationOrder', () {
|
|
|
|
test('board is the lowest priority', () {
|
|
|
|
test('board is the lowest elevation', () {
|
|
|
|
for (final priority in Elevation.values) {
|
|
|
|
for (final elevation in Elevation.values) {
|
|
|
|
if (priority != Elevation.board) {
|
|
|
|
if (elevation != Elevation.board) {
|
|
|
|
expect(priority.order, greaterThan(Elevation.board.order));
|
|
|
|
expect(elevation.order, greaterThan(Elevation.board.order));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test('jetpack has greater priority than board', () {
|
|
|
|
test('jetpack has greater elevation than board', () {
|
|
|
|
expect(Elevation.jetpack.order, greaterThan(Elevation.board.order));
|
|
|
|
expect(Elevation.jetpack.order, greaterThan(Elevation.board.order));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test('spaceship has greater priority than board and next ramps', () {
|
|
|
|
test('spaceship has greater elevation than board and next ramps', () {
|
|
|
|
expect(Elevation.spaceship.order, greaterThan(Elevation.jetpack.order));
|
|
|
|
expect(Elevation.spaceship.order, greaterThan(Elevation.jetpack.order));
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
Elevation.spaceship.order,
|
|
|
|
Elevation.spaceship.order,
|
|
|
@ -117,7 +115,7 @@ void main() {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test('spaceshipExitRail has greater priority than board', () {
|
|
|
|
test('spaceshipExitRail has greater elevation than board', () {
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
Elevation.spaceshipExitRail.order,
|
|
|
|
Elevation.spaceshipExitRail.order,
|
|
|
|
greaterThan(Elevation.board.order),
|
|
|
|
greaterThan(Elevation.board.order),
|
|
|
|