feat: applying assets to the spaceship

pull/101/head
Erick Zanardo 4 years ago
parent 72b8213f74
commit 9c11113c58

@ -1,5 +1,4 @@
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:pinball/flame/blueprint.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';

@ -9,7 +9,5 @@ export 'jetpack_ramp.dart';
export 'kicker.dart'; export 'kicker.dart';
export 'launcher_ramp.dart'; export 'launcher_ramp.dart';
export 'plunger.dart'; export 'plunger.dart';
export 'ramp_opening.dart';
export 'score_points.dart'; export 'score_points.dart';
export 'spaceship.dart';
export 'wall.dart'; export 'wall.dart';

@ -6,7 +6,6 @@ import 'package:flame/components.dart';
import 'package:flame_bloc/flame_bloc.dart'; import 'package:flame_bloc/flame_bloc.dart';
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pinball/flame/blueprint.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';

@ -7,10 +7,11 @@ import 'package:flame/extensions.dart';
import 'package:flame/input.dart'; import 'package:flame/input.dart';
import 'package:flame_bloc/flame_bloc.dart'; import 'package:flame_bloc/flame_bloc.dart';
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball/flame/blueprint.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
import 'package:pinball/gen/assets.gen.dart'; import 'package:pinball/gen/assets.gen.dart';
import 'package:pinball_theme/pinball_theme.dart' hide Assets; import 'package:pinball_theme/pinball_theme.dart' hide Assets;
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_theme/pinball_theme.dart';
class PinballGame extends Forge2DGame class PinballGame extends Forge2DGame
with FlameBloc, HasKeyboardHandlerComponents { with FlameBloc, HasKeyboardHandlerComponents {
@ -46,7 +47,13 @@ class PinballGame extends Forge2DGame
unawaited(_addPlunger()); unawaited(_addPlunger());
unawaited(_addBonusWord()); unawaited(_addBonusWord());
unawaited(_addPaths()); unawaited(_addPaths());
unawaited(addFromBlueprint(Spaceship())); unawaited(
addFromBlueprint(
Spaceship(
position: Vector2(-25, 32),
),
),
);
// Fix camera on the center of the board. // Fix camera on the center of the board.
camera camera

@ -3,8 +3,6 @@
/// FlutterGen /// FlutterGen
/// ***************************************************** /// *****************************************************
// ignore_for_file: directives_ordering,unnecessary_import
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
class $AssetsImagesGen { class $AssetsImagesGen {
@ -17,10 +15,8 @@ class $AssetsImagesGen {
class $AssetsImagesComponentsGen { class $AssetsImagesComponentsGen {
const $AssetsImagesComponentsGen(); const $AssetsImagesComponentsGen();
/// File path: assets/images/components/background.png
AssetGenImage get background => AssetGenImage get background =>
const AssetGenImage('assets/images/components/background.png'); const AssetGenImage('assets/images/components/background.png');
$AssetsImagesComponentsSpaceshipGen get spaceship => $AssetsImagesComponentsSpaceshipGen get spaceship =>
const $AssetsImagesComponentsSpaceshipGen(); const $AssetsImagesComponentsSpaceshipGen();
} }
@ -28,23 +24,14 @@ class $AssetsImagesComponentsGen {
class $AssetsImagesComponentsSpaceshipGen { class $AssetsImagesComponentsSpaceshipGen {
const $AssetsImagesComponentsSpaceshipGen(); const $AssetsImagesComponentsSpaceshipGen();
/// File path: assets/images/components/spaceship/android-bottom.png
AssetGenImage get androidBottom => const AssetGenImage( AssetGenImage get androidBottom => const AssetGenImage(
'assets/images/components/spaceship/android-bottom.png'); 'assets/images/components/spaceship/android-bottom.png');
/// File path: assets/images/components/spaceship/android-top.png
AssetGenImage get androidTop => AssetGenImage get androidTop =>
const AssetGenImage('assets/images/components/spaceship/android-top.png'); const AssetGenImage('assets/images/components/spaceship/android-top.png');
/// File path: assets/images/components/spaceship/lower.png
AssetGenImage get lower => AssetGenImage get lower =>
const AssetGenImage('assets/images/components/spaceship/lower.png'); const AssetGenImage('assets/images/components/spaceship/lower.png');
/// File path: assets/images/components/spaceship/saucer.png
AssetGenImage get saucer => AssetGenImage get saucer =>
const AssetGenImage('assets/images/components/spaceship/saucer.png'); const AssetGenImage('assets/images/components/spaceship/saucer.png');
/// File path: assets/images/components/spaceship/upper.png
AssetGenImage get upper => AssetGenImage get upper =>
const AssetGenImage('assets/images/components/spaceship/upper.png'); const AssetGenImage('assets/images/components/spaceship/upper.png');
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

@ -12,6 +12,7 @@ class $AssetsImagesGen {
/// File path: assets/images/ball.png /// File path: assets/images/ball.png
AssetGenImage get ball => const AssetGenImage('assets/images/ball.png'); AssetGenImage get ball => const AssetGenImage('assets/images/ball.png');
<<<<<<< HEAD
$AssetsImagesFlipperGen get flipper => const $AssetsImagesFlipperGen(); $AssetsImagesFlipperGen get flipper => const $AssetsImagesFlipperGen();
} }
@ -26,6 +27,12 @@ class $AssetsImagesFlipperGen {
/// File path: assets/images/flipper/right.png /// File path: assets/images/flipper/right.png
AssetGenImage get right => AssetGenImage get right =>
const AssetGenImage('assets/images/flipper/right.png'); const AssetGenImage('assets/images/flipper/right.png');
=======
AssetGenImage get spaceshipBridge =>
const AssetGenImage('assets/images/spaceship_bridge.png');
AssetGenImage get spaceshipSaucer =>
const AssetGenImage('assets/images/spaceship_saucer.png');
>>>>>>> 990de50 (feat: applying assets to the spaceship)
} }
class Assets { class Assets {

@ -5,4 +5,6 @@ export 'flipper.dart';
export 'initial_position.dart'; export 'initial_position.dart';
export 'joint_anchor.dart'; export 'joint_anchor.dart';
export 'layer.dart'; export 'layer.dart';
export 'ramp_opening.dart';
export 'shapes/shapes.dart'; export 'shapes/shapes.dart';
export 'spaceship.dart';

@ -1,7 +1,6 @@
// ignore_for_file: avoid_renaming_method_parameters // ignore_for_file: avoid_renaming_method_parameters
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
/// {@template ramp_orientation} /// {@template ramp_orientation}
@ -110,3 +109,4 @@ class RampOpeningBallContactCallback<Opening extends RampOpening>
} }
} }
} }

@ -5,23 +5,24 @@ import 'dart:math';
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball/flame/blueprint.dart'; import 'package:pinball_components/gen/assets.gen.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball/gen/assets.gen.dart';
import 'package:pinball_components/pinball_components.dart' hide Assets; import 'package:pinball_components/pinball_components.dart' hide Assets;
/// {@template spaceship}
/// A [Blueprint] which creates the spaceship feature. /// A [Blueprint] which creates the spaceship feature.
/// P@endtemplate}
class Spaceship extends Forge2DBlueprint { class Spaceship extends Forge2DBlueprint {
/// {@macro spaceship}
Spaceship({required this.position});
/// Total size of the spaceship /// Total size of the spaceship
static const radius = 10.0; static final size = Vector2(24, 18);
/// The [position] that the elements will be created
final Vector2 position;
@override @override
void build(_) { void build(_) {
final position = Vector2(
PinballGame.boardBounds.left + radius + 15,
PinballGame.boardBounds.center.dy + 30,
);
addAllContactCallback([ addAllContactCallback([
SpaceshipHoleBallContactCallback(), SpaceshipHoleBallContactCallback(),
SpaceshipEntranceBallContactCallback(), SpaceshipEntranceBallContactCallback(),
@ -31,9 +32,8 @@ class Spaceship extends Forge2DBlueprint {
SpaceshipSaucer()..initialPosition = position, SpaceshipSaucer()..initialPosition = position,
SpaceshipEntrance()..initialPosition = position, SpaceshipEntrance()..initialPosition = position,
SpaceshipBridge()..initialPosition = position, SpaceshipBridge()..initialPosition = position,
SpaceshipBridgeTop()..initialPosition = position + Vector2(0, 5.5), SpaceshipHole()..initialPosition = position - Vector2(4.8, 4.2),
SpaceshipHole()..initialPosition = position - Vector2(5, 4), SpaceshipHole()..initialPosition = position - Vector2(-7.2, 0.6),
SpaceshipHole()..initialPosition = position - Vector2(-5, 4),
SpaceshipWall()..initialPosition = position, SpaceshipWall()..initialPosition = position,
]); ]);
} }
@ -51,25 +51,15 @@ class SpaceshipSaucer extends BodyComponent with InitialPosition, Layered {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
final sprites = await Future.wait([ final sprite = await gameRef.loadSprite(
gameRef.loadSprite(Assets.images.components.spaceship.saucer.path), Assets.images.spaceshipSaucer.keyName,
gameRef.loadSprite(Assets.images.components.spaceship.upper.path),
]);
await add(
SpriteComponent(
sprite: sprites.first,
size: Vector2.all(Spaceship.radius * 2),
anchor: Anchor.center,
),
); );
await add( await add(
SpriteComponent( SpriteComponent(
sprite: sprites.last, sprite: sprite,
size: Vector2((Spaceship.radius * 2) + 0.5, Spaceship.radius), size: Spaceship.size,
anchor: Anchor.center, anchor: Anchor.center,
position: Vector2(0, -((Spaceship.radius * 2) / 3.5)),
), ),
); );
@ -78,7 +68,7 @@ class SpaceshipSaucer extends BodyComponent with InitialPosition, Layered {
@override @override
Body createBody() { Body createBody() {
final circleShape = CircleShape()..radius = Spaceship.radius; final circleShape = CircleShape()..radius = 3;
final bodyDef = BodyDef() final bodyDef = BodyDef()
..userData = this ..userData = this
@ -92,44 +82,9 @@ class SpaceshipSaucer extends BodyComponent with InitialPosition, Layered {
} }
} }
/// {@spaceship_bridge_top}
/// The bridge of the spaceship (the android head) is divided in two
// [BodyComponent]s, this is the top part of it which contains a single sprite
/// {@endtemplate}
class SpaceshipBridgeTop extends BodyComponent with InitialPosition {
/// {@macro spaceship_bridge_top}
SpaceshipBridgeTop() : super(priority: 6);
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite(
Assets.images.components.spaceship.androidTop.path,
);
await add(
SpriteComponent(
sprite: sprite,
anchor: Anchor.center,
size: Vector2((Spaceship.radius * 2) / 2.5 - 1, Spaceship.radius / 2.5),
),
);
}
@override
Body createBody() {
final bodyDef = BodyDef()
..userData = this
..position = initialPosition
..type = BodyType.static;
return world.createBody(bodyDef);
}
}
/// {@template spaceship_bridge} /// {@template spaceship_bridge}
/// The main part of the [SpaceshipBridge], this [BodyComponent] /// A [BodyComponent] that provides both the collision and the rotation
/// provides both the collision and the rotation animation for the bridge. /// animation for the bridge.
/// {@endtemplate} /// {@endtemplate}
class SpaceshipBridge extends BodyComponent with InitialPosition, Layered { class SpaceshipBridge extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_bridge} /// {@macro spaceship_bridge}
@ -144,17 +99,20 @@ class SpaceshipBridge extends BodyComponent with InitialPosition, Layered {
renderBody = false; renderBody = false;
final sprite = await gameRef.images.load( final sprite = await gameRef.images.load(
Assets.images.components.spaceship.androidBottom.path, Assets.images.spaceshipBridge.keyName,
); );
await add( await add(
SpriteAnimationComponent.fromFrameData( SpriteAnimationComponent.fromFrameData(
sprite, sprite,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 14, amount: 72,
stepTime: 0.2, amountPerRow: 24,
textureSize: Vector2(160, 114), stepTime: 0.05,
textureSize: Vector2(82, 100),
), ),
size: Vector2.all((Spaceship.radius * 2) / 2.5), size: Vector2(8.2, 10),
position: Vector2(0, -2),
anchor: Anchor.center, anchor: Anchor.center,
), ),
); );
@ -162,7 +120,7 @@ class SpaceshipBridge extends BodyComponent with InitialPosition, Layered {
@override @override
Body createBody() { Body createBody() {
final circleShape = CircleShape()..radius = Spaceship.radius / 2.5; final circleShape = CircleShape()..radius = 2;
final bodyDef = BodyDef() final bodyDef = BodyDef()
..userData = this ..userData = this
@ -193,7 +151,8 @@ class SpaceshipEntrance extends RampOpening {
@override @override
Shape get shape { Shape get shape {
const radius = Spaceship.radius * 2; renderBody = false;
final radius = Spaceship.size.y / 2;
return PolygonShape() return PolygonShape()
..setAsEdge( ..setAsEdge(
Vector2( Vector2(
@ -221,7 +180,7 @@ class SpaceshipHole extends BodyComponent with InitialPosition, Layered {
@override @override
Body createBody() { Body createBody() {
renderBody = false; renderBody = false;
final circleShape = CircleShape()..radius = Spaceship.radius / 40; final circleShape = CircleShape()..radius = 1.5;
final bodyDef = BodyDef() final bodyDef = BodyDef()
..userData = this ..userData = this
@ -247,36 +206,19 @@ class SpaceshipWall extends BodyComponent with InitialPosition, Layered {
layer = Layer.spaceship; layer = Layer.spaceship;
} }
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite(
Assets.images.components.spaceship.lower.path,
);
await add(
SpriteComponent(
sprite: sprite,
size: Vector2(Spaceship.radius * 2, Spaceship.radius + 1),
anchor: Anchor.center,
position: Vector2(-Spaceship.radius / 2, 0),
angle: 90 * pi / 180,
),
);
}
@override @override
Body createBody() { Body createBody() {
renderBody = false; renderBody = false;
final minorRadius = (Spaceship.size.y - 2) / 2;
final majorRadius = (Spaceship.size.x - 2) / 2;
final wallShape = ChainShape() final wallShape = ChainShape()
..createChain( ..createChain(
[ [
for (var angle = 20; angle <= 340; angle++) for (var angle = 20; angle <= 340; angle++)
Vector2( Vector2(
Spaceship.radius * cos(angle * pi / 180), minorRadius * cos(angle * pi / 180),
Spaceship.radius * sin(angle * pi / 180), majorRadius * sin(angle * pi / 180),
), ),
], ],
); );

@ -1 +1,2 @@
export 'components/components.dart'; export 'components/components.dart';
export 'flame/flame.dart';

@ -5,7 +5,7 @@ import 'package:flame/input.dart';
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class BasicGame extends Forge2DGame { abstract class BasicGame extends Forge2DGame {
BasicGame() { BasicGame() {
images.prefix = ''; images.prefix = '';
} }

@ -7,6 +7,7 @@
import 'package:dashbook/dashbook.dart'; import 'package:dashbook/dashbook.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:sandbox/stories/effects/effects.dart'; import 'package:sandbox/stories/effects/effects.dart';
import 'package:sandbox/stories/spaceship/spaceship.dart';
import 'package:sandbox/stories/stories.dart'; import 'package:sandbox/stories/stories.dart';
void main() { void main() {
@ -16,5 +17,6 @@ void main() {
addLayerStories(dashbook); addLayerStories(dashbook);
addEffectsStories(dashbook); addEffectsStories(dashbook);
addFlipperStories(dashbook); addFlipperStories(dashbook);
addSpaceshipStories(dashbook);
runApp(dashbook); runApp(dashbook);
} }

@ -0,0 +1,31 @@
import 'dart:async';
import 'package:flame/input.dart';
import 'package:flutter/material.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:sandbox/common/common.dart';
class BasicSpaceship extends BasicGame with TapDetector {
static String info = 'Renders a spaceship and allows balls to be '
'spawned upon click to test their interactions';
@override
Future<void> onLoad() async {
await super.onLoad();
camera.followVector2(Vector2.zero());
unawaited(
addFromBlueprint(Spaceship(position: Vector2.zero())),
);
}
@override
void onTapUp(TapUpInfo info) {
add(
Ball(baseColor: Colors.blue)
..initialPosition = info.eventPosition.game
..layer = Layer.jetpack,
);
}
}

@ -0,0 +1,13 @@
import 'package:dashbook/dashbook.dart';
import 'package:flame/game.dart';
import 'package:sandbox/common/common.dart';
import 'package:sandbox/stories/spaceship/basic.dart';
void addSpaceshipStories(Dashbook dashbook) {
dashbook.storiesOf('Spaceship').add(
'Basic',
(context) => GameWidget(game: BasicSpaceship()),
codeLink: buildSourceLink('spaceship/basic.dart'),
info: BasicSpaceship.info,
);
}

@ -142,13 +142,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0" version: "1.1.0"
geometry:
dependency: transitive
description:
path: "../../geometry"
relative: true
source: path
version: "1.0.0+1"
js: js:
dependency: transitive dependency: transitive
description: description:

@ -1,5 +1,26 @@
import 'dart:ui'; import 'dart:ui';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:mocktail/mocktail.dart'; import 'package:mocktail/mocktail.dart';
import 'package:pinball_components/pinball_components.dart';
class MockCanvas extends Mock implements Canvas {} class MockCanvas extends Mock implements Canvas {}
class MockFilter extends Mock implements Filter {}
class MockFixture extends Mock implements Fixture {}
class MockBody extends Mock implements Body {}
class MockBall extends Mock implements Ball {}
class MockGame extends Mock implements Forge2DGame {}
class MockSpaceshipEntrance extends Mock implements SpaceshipEntrance {}
class MockSpaceshipHole extends Mock implements SpaceshipHole {}
class MockContact extends Mock implements Contact {}
class MockContactCallback extends Mock
implements ContactCallback<Object, Object> {}

@ -2,8 +2,7 @@
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';
import 'package:mockingjay/mockingjay.dart'; import 'package:mocktail/mocktail.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import '../../helpers/helpers.dart'; import '../../helpers/helpers.dart';
@ -34,11 +33,11 @@ class TestRampOpeningBallContactCallback
void main() { void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(PinballGameTest.create); final flameTester = FlameTester(TestGame.new);
group('RampOpening', () { group('RampOpening', () {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(PinballGameTest.create); final flameTester = FlameTester(TestGame.new);
flameTester.test( flameTester.test(
'loads correctly', 'loads correctly',

@ -1,7 +1,6 @@
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart'; import 'package:mocktail/mocktail.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import '../../helpers/helpers.dart'; import '../../helpers/helpers.dart';
@ -11,10 +10,10 @@ void main() {
late Filter filterData; late Filter filterData;
late Fixture fixture; late Fixture fixture;
late Body body; late Body body;
late PinballGame game;
late Ball ball; late Ball ball;
late SpaceshipEntrance entrance; late SpaceshipEntrance entrance;
late SpaceshipHole hole; late SpaceshipHole hole;
late Forge2DGame game;
setUp(() { setUp(() {
filterData = MockFilter(); filterData = MockFilter();
@ -25,7 +24,7 @@ void main() {
body = MockBody(); body = MockBody();
when(() => body.fixtures).thenReturn([fixture]); when(() => body.fixtures).thenReturn([fixture]);
game = MockPinballGame(); game = MockGame();
ball = MockBall(); ball = MockBall();
when(() => ball.gameRef).thenReturn(game); when(() => ball.gameRef).thenReturn(game);

@ -1,10 +1,9 @@
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart'; import 'package:mocktail/mocktail.dart';
import 'package:pinball/flame/blueprint.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:pinball/game/game.dart';
import '../helpers/helpers.dart'; import '../../helpers/helpers.dart';
class MyBlueprint extends Blueprint { class MyBlueprint extends Blueprint {
@override @override
@ -52,19 +51,19 @@ void main() {
}); });
test('components can be added to it', () { test('components can be added to it', () {
final blueprint = MyBlueprint()..build(MockPinballGame()); final blueprint = MyBlueprint()..build(MockGame());
expect(blueprint.components.length, equals(3)); expect(blueprint.components.length, equals(3));
}); });
test('blueprints can be added to it', () { test('blueprints can be added to it', () {
final blueprint = MyComposedBlueprint()..build(MockPinballGame()); final blueprint = MyComposedBlueprint()..build(MockGame());
expect(blueprint.blueprints.length, equals(3)); expect(blueprint.blueprints.length, equals(3));
}); });
test('adds the components to a game on attach', () { test('adds the components to a game on attach', () {
final mockGame = MockPinballGame(); final mockGame = MockGame();
when(() => mockGame.addAll(any())).thenAnswer((_) async {}); when(() => mockGame.addAll(any())).thenAnswer((_) async {});
MyBlueprint().attach(mockGame); MyBlueprint().attach(mockGame);
@ -72,7 +71,7 @@ void main() {
}); });
test('adds components from a child Blueprint the to a game on attach', () { test('adds components from a child Blueprint the to a game on attach', () {
final mockGame = MockPinballGame(); final mockGame = MockGame();
when(() => mockGame.addAll(any())).thenAnswer((_) async {}); when(() => mockGame.addAll(any())).thenAnswer((_) async {});
MyComposedBlueprint().attach(mockGame); MyComposedBlueprint().attach(mockGame);
@ -82,7 +81,7 @@ void main() {
test( test(
'throws assertion error when adding to an already attached blueprint', 'throws assertion error when adding to an already attached blueprint',
() async { () async {
final mockGame = MockPinballGame(); final mockGame = MockGame();
when(() => mockGame.addAll(any())).thenAnswer((_) async {}); when(() => mockGame.addAll(any())).thenAnswer((_) async {});
final blueprint = MyBlueprint(); final blueprint = MyBlueprint();
await blueprint.attach(mockGame); await blueprint.attach(mockGame);
@ -99,13 +98,13 @@ void main() {
}); });
test('callbacks can be added to it', () { test('callbacks can be added to it', () {
final blueprint = MyForge2dBlueprint()..build(MockPinballGame()); final blueprint = MyForge2dBlueprint()..build(MockGame());
expect(blueprint.callbacks.length, equals(3)); expect(blueprint.callbacks.length, equals(3));
}); });
test('adds the callbacks to a game on attach', () async { test('adds the callbacks to a game on attach', () async {
final mockGame = MockPinballGame(); final mockGame = MockGame();
when(() => mockGame.addAll(any())).thenAnswer((_) async {}); when(() => mockGame.addAll(any())).thenAnswer((_) async {});
when(() => mockGame.addContactCallback(any())).thenAnswer((_) async {}); when(() => mockGame.addContactCallback(any())).thenAnswer((_) async {});
await MyForge2dBlueprint().attach(mockGame); await MyForge2dBlueprint().attach(mockGame);
@ -116,7 +115,7 @@ void main() {
test( test(
'throws assertion error when adding to an already attached blueprint', 'throws assertion error when adding to an already attached blueprint',
() async { () async {
final mockGame = MockPinballGame(); final mockGame = MockGame();
when(() => mockGame.addAll(any())).thenAnswer((_) async {}); when(() => mockGame.addAll(any())).thenAnswer((_) async {});
when(() => mockGame.addContactCallback(any())).thenAnswer((_) async {}); when(() => mockGame.addContactCallback(any())).thenAnswer((_) async {});
final blueprint = MyForge2dBlueprint(); final blueprint = MyForge2dBlueprint();
Loading…
Cancel
Save