|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
|
|
import 'dart:collection';
|
|
|
|
|
|
|
|
|
|
import 'package:flame/components.dart';
|
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
|
|
import 'package:flame_test/flame_test.dart';
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
@ -13,6 +14,104 @@ import '../../helpers/helpers.dart';
|
|
|
|
|
void main() {
|
|
|
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
final flameTester = FlameTester(PinballGameTest.create);
|
|
|
|
|
|
|
|
|
|
group('FlipperGroup', () {
|
|
|
|
|
flameTester.test(
|
|
|
|
|
'loads correctly',
|
|
|
|
|
(game) async {
|
|
|
|
|
final flipperGroup = FlipperGroup(
|
|
|
|
|
position: Vector2.zero(),
|
|
|
|
|
spacing: 0,
|
|
|
|
|
);
|
|
|
|
|
await game.ensureAdd(flipperGroup);
|
|
|
|
|
|
|
|
|
|
expect(game.contains(flipperGroup), isTrue);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
group('constructor', () {
|
|
|
|
|
flameTester.test(
|
|
|
|
|
'positions correctly',
|
|
|
|
|
(game) async {
|
|
|
|
|
final position = Vector2.all(10);
|
|
|
|
|
final flipperGroup = FlipperGroup(
|
|
|
|
|
position: position,
|
|
|
|
|
spacing: 0,
|
|
|
|
|
);
|
|
|
|
|
await game.ensureAdd(flipperGroup);
|
|
|
|
|
|
|
|
|
|
expect(flipperGroup.position, equals(position));
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('children', () {
|
|
|
|
|
bool Function(Component) flipperSelector(BoardSide side) =>
|
|
|
|
|
(component) => component is Flipper && component.side == side;
|
|
|
|
|
flameTester.test(
|
|
|
|
|
'has only one left Flipper',
|
|
|
|
|
(game) async {
|
|
|
|
|
final flipperGroup = FlipperGroup(
|
|
|
|
|
position: Vector2.zero(),
|
|
|
|
|
spacing: 0,
|
|
|
|
|
);
|
|
|
|
|
await game.ensureAdd(flipperGroup);
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
() => flipperGroup.children.singleWhere(
|
|
|
|
|
flipperSelector(BoardSide.left),
|
|
|
|
|
),
|
|
|
|
|
returnsNormally,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
flameTester.test(
|
|
|
|
|
'has only one right Flipper',
|
|
|
|
|
(game) async {
|
|
|
|
|
final flipperGroup = FlipperGroup(
|
|
|
|
|
position: Vector2.zero(),
|
|
|
|
|
spacing: 0,
|
|
|
|
|
);
|
|
|
|
|
await game.ensureAdd(flipperGroup);
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
() => flipperGroup.children.singleWhere(
|
|
|
|
|
flipperSelector(BoardSide.right),
|
|
|
|
|
),
|
|
|
|
|
returnsNormally,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
flameTester.test(
|
|
|
|
|
'spaced correctly',
|
|
|
|
|
(game) async {
|
|
|
|
|
final flipperGroup = FlipperGroup(
|
|
|
|
|
position: Vector2.zero(),
|
|
|
|
|
spacing: 2,
|
|
|
|
|
);
|
|
|
|
|
await game.ready();
|
|
|
|
|
await game.ensureAdd(flipperGroup);
|
|
|
|
|
|
|
|
|
|
final leftFlipper = flipperGroup.children.singleWhere(
|
|
|
|
|
flipperSelector(BoardSide.left),
|
|
|
|
|
) as Flipper;
|
|
|
|
|
final rightFlipper = flipperGroup.children.singleWhere(
|
|
|
|
|
flipperSelector(BoardSide.right),
|
|
|
|
|
) as Flipper;
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
leftFlipper.body.position.x +
|
|
|
|
|
leftFlipper.size.x +
|
|
|
|
|
flipperGroup.spacing,
|
|
|
|
|
equals(rightFlipper.body.position.x),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group(
|
|
|
|
|
'Flipper',
|
|
|
|
|
() {
|
|
|
|
@ -21,9 +120,11 @@ void main() {
|
|
|
|
|
(game) async {
|
|
|
|
|
final leftFlipper = Flipper.left(position: Vector2.zero());
|
|
|
|
|
final rightFlipper = Flipper.right(position: Vector2.zero());
|
|
|
|
|
await game.ready();
|
|
|
|
|
await game.ensureAddAll([leftFlipper, rightFlipper]);
|
|
|
|
|
|
|
|
|
|
expect(game.contains(leftFlipper), isTrue);
|
|
|
|
|
expect(game.contains(rightFlipper), isTrue);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|