Merge branch 'main' into refactor/remove-component-from-blueprint

pull/218/head
Alejandro Santiago 3 years ago committed by GitHub
commit 45cac3fc6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,38 @@
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:sandbox/common/common.dart';
import 'package:sandbox/stories/ball/basic_ball_game.dart';
class BaseboardGame extends BasicBallGame with Traceable {
static const info = '''
Shows how the Baseboards are rendered.
- Activate the "trace" parameter to overlay the body.
- Tap anywhere on the screen to spawn a ball into the game.
''';
@override
Future<void> onLoad() async {
await super.onLoad();
await images.loadAll([
Assets.images.baseboard.left.keyName,
Assets.images.baseboard.right.keyName,
]);
final center = screenToWorld(camera.viewport.canvasSize! / 2);
final leftBaseboard = Baseboard(side: BoardSide.left)
..initialPosition = center - Vector2(25, 0)
..priority = 1;
final rightBaseboard = Baseboard(side: BoardSide.right)
..initialPosition = center + Vector2(25, 0)
..priority = 1;
await addAll([
leftBaseboard,
rightBaseboard,
]);
await traceAllBodies();
}
}

@ -1,24 +0,0 @@
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:sandbox/common/common.dart';
class BasicBaseboardGame extends BasicGame {
static const info = 'Shows how a Baseboard works.';
@override
Future<void> onLoad() async {
await super.onLoad();
final center = screenToWorld(camera.viewport.canvasSize! / 2);
final leftBaseboard = Baseboard(side: BoardSide.left)
..initialPosition = center - Vector2(25, 0);
final rightBaseboard = Baseboard(side: BoardSide.right)
..initialPosition = center + Vector2(25, 0);
await addAll([
leftBaseboard,
rightBaseboard,
]);
}
}

@ -1,15 +1,15 @@
import 'package:dashbook/dashbook.dart';
import 'package:flame/game.dart';
import 'package:sandbox/common/common.dart';
import 'package:sandbox/stories/baseboard/basic_baseboard_game.dart';
import 'package:sandbox/stories/baseboard/baseboard_game.dart';
void addBaseboardStories(Dashbook dashbook) {
dashbook.storiesOf('Baseboard').add(
'Basic',
(context) => GameWidget(
game: BasicBaseboardGame(),
game: BaseboardGame()..trace = context.boolProperty('Trace', true),
),
codeLink: buildSourceLink('baseboard/basic.dart'),
info: BasicBaseboardGame.info,
codeLink: buildSourceLink('baseboard_game/basic.dart'),
info: BaseboardGame.info,
);
}

@ -16,6 +16,11 @@ class BoundariesGame extends BasicBallGame with Traceable {
Future<void> onLoad() async {
await super.onLoad();
await images.loadAll([
Assets.images.boundary.outer.keyName,
Assets.images.boundary.bottom.keyName,
]);
await addFromBlueprint(Boundaries());
await ready();

@ -33,6 +33,11 @@ class FlipperGame extends BasicBallGame with KeyboardEvents, Traceable {
Future<void> onLoad() async {
await super.onLoad();
await images.loadAll([
Assets.images.flipper.left.keyName,
Assets.images.flipper.right.keyName,
]);
final center = screenToWorld(camera.viewport.canvasSize! / 2);
leftFlipper = Flipper(side: BoardSide.left)

@ -15,6 +15,12 @@ class SlingshotGame extends BasicBallGame with Traceable {
@override
Future<void> onLoad() async {
await super.onLoad();
await images.loadAll([
Assets.images.slingshot.upper.keyName,
Assets.images.slingshot.lower.keyName,
]);
await addFromBlueprint(Slingshots());
camera.followVector2(Vector2.zero());
await traceAllBodies();

@ -15,6 +15,7 @@ class Blueprint {
}) {
if (components != null) _components.addAll(components);
if (blueprints != null) {
_blueprints.addAll(blueprints);
for (final blueprint in blueprints) {
_components.addAll(blueprint.components);
}
@ -23,12 +24,17 @@ class Blueprint {
final List<Component> _components = [];
final List<Component> _blueprints = [];
Future<void> _addToParent(Component parent) async {
await parent.addAll(_components);
}
/// Returns a copy of the components built by this blueprint.
List<Component> get components => List.unmodifiable(_components);
/// Returns a copy of the blueprints built by this blueprint.
List<Component> get blueprints => List.unmodifiable(_blueprints);
}
/// Adds helper methods regarding [Blueprint]s to [FlameGame].

@ -27,6 +27,18 @@ void main() {
expect(blueprint.components, contains(component2));
});
test('correctly sets and gets blueprints', () {
final blueprint2 = Blueprint(
components: [Component()],
);
final blueprint1 = Blueprint(
components: [Component()],
blueprints: [blueprint2],
);
expect(blueprint1.blueprints, contains(blueprint2));
});
flameTester.test('adds the components to parent on attach', (game) async {
final blueprint = Blueprint(
components: [

Loading…
Cancel
Save