|
|
|
@ -1,9 +1,12 @@
|
|
|
|
|
import 'package:flame/components.dart';
|
|
|
|
|
import 'package:flame_forge2d/contact_callbacks.dart';
|
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
|
import 'package:mocktail/mocktail.dart';
|
|
|
|
|
import 'package:pinball_components/pinball_components.dart';
|
|
|
|
|
import 'package:pinball_flame/pinball_flame.dart';
|
|
|
|
|
|
|
|
|
|
import '../../helpers/helpers.dart';
|
|
|
|
|
import '../helpers/helpers.dart';
|
|
|
|
|
|
|
|
|
|
class TestContactCallback extends ContactCallback<dynamic, dynamic> {}
|
|
|
|
|
|
|
|
|
|
class MyBlueprint extends Blueprint {
|
|
|
|
|
@override
|
|
|
|
@ -51,19 +54,19 @@ void main() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('components can be added to it', () {
|
|
|
|
|
final blueprint = MyBlueprint()..build(MockGame());
|
|
|
|
|
final blueprint = MyBlueprint()..build(MockForge2DGame());
|
|
|
|
|
|
|
|
|
|
expect(blueprint.components.length, equals(3));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('blueprints can be added to it', () {
|
|
|
|
|
final blueprint = MyComposedBlueprint()..build(MockGame());
|
|
|
|
|
final blueprint = MyComposedBlueprint()..build(MockForge2DGame());
|
|
|
|
|
|
|
|
|
|
expect(blueprint.blueprints.length, equals(3));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('adds the components to a game on attach', () {
|
|
|
|
|
final mockGame = MockGame();
|
|
|
|
|
final mockGame = MockForge2DGame();
|
|
|
|
|
when(() => mockGame.addAll(any())).thenAnswer((_) async {});
|
|
|
|
|
MyBlueprint().attach(mockGame);
|
|
|
|
|
|
|
|
|
@ -71,7 +74,7 @@ void main() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('adds components from a child Blueprint the to a game on attach', () {
|
|
|
|
|
final mockGame = MockGame();
|
|
|
|
|
final mockGame = MockForge2DGame();
|
|
|
|
|
when(() => mockGame.addAll(any())).thenAnswer((_) async {});
|
|
|
|
|
MyComposedBlueprint().attach(mockGame);
|
|
|
|
|
|
|
|
|
@ -81,7 +84,7 @@ void main() {
|
|
|
|
|
test(
|
|
|
|
|
'throws assertion error when adding to an already attached blueprint',
|
|
|
|
|
() async {
|
|
|
|
|
final mockGame = MockGame();
|
|
|
|
|
final mockGame = MockForge2DGame();
|
|
|
|
|
when(() => mockGame.addAll(any())).thenAnswer((_) async {});
|
|
|
|
|
final blueprint = MyBlueprint();
|
|
|
|
|
await blueprint.attach(mockGame);
|
|
|
|
@ -94,17 +97,17 @@ void main() {
|
|
|
|
|
|
|
|
|
|
group('Forge2DBlueprint', () {
|
|
|
|
|
setUpAll(() {
|
|
|
|
|
registerFallbackValue(SpaceshipHoleBallContactCallback());
|
|
|
|
|
registerFallbackValue(TestContactCallback());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('callbacks can be added to it', () {
|
|
|
|
|
final blueprint = MyForge2dBlueprint()..build(MockGame());
|
|
|
|
|
final blueprint = MyForge2dBlueprint()..build(MockForge2DGame());
|
|
|
|
|
|
|
|
|
|
expect(blueprint.callbacks.length, equals(3));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('adds the callbacks to a game on attach', () async {
|
|
|
|
|
final mockGame = MockGame();
|
|
|
|
|
final mockGame = MockForge2DGame();
|
|
|
|
|
when(() => mockGame.addAll(any())).thenAnswer((_) async {});
|
|
|
|
|
when(() => mockGame.addContactCallback(any())).thenAnswer((_) async {});
|
|
|
|
|
await MyForge2dBlueprint().attach(mockGame);
|
|
|
|
@ -115,7 +118,7 @@ void main() {
|
|
|
|
|
test(
|
|
|
|
|
'throws assertion error when adding to an already attached blueprint',
|
|
|
|
|
() async {
|
|
|
|
|
final mockGame = MockGame();
|
|
|
|
|
final mockGame = MockForge2DGame();
|
|
|
|
|
when(() => mockGame.addAll(any())).thenAnswer((_) async {});
|
|
|
|
|
when(() => mockGame.addContactCallback(any())).thenAnswer((_) async {});
|
|
|
|
|
final blueprint = MyForge2dBlueprint();
|