From 9cf4214c2f17a28410cab352af21e40f902a711f Mon Sep 17 00:00:00 2001 From: alestiago Date: Sun, 1 May 2022 21:15:29 +0100 Subject: [PATCH] refactor: removes Blueprint --- packages/pinball_flame/lib/src/blueprint.dart | 46 ---------- .../test/src/blueprint_test.dart | 86 ------------------- 2 files changed, 132 deletions(-) delete mode 100644 packages/pinball_flame/lib/src/blueprint.dart delete mode 100644 packages/pinball_flame/test/src/blueprint_test.dart diff --git a/packages/pinball_flame/lib/src/blueprint.dart b/packages/pinball_flame/lib/src/blueprint.dart deleted file mode 100644 index c7bd5a5e..00000000 --- a/packages/pinball_flame/lib/src/blueprint.dart +++ /dev/null @@ -1,46 +0,0 @@ -import 'package:flame/components.dart'; -import 'package:flame/game.dart'; - -// TODO(erickzanardo): Keeping this inside our code base so we can experiment -// with the idea, but this is a potential upstream change on Flame. - -/// {@template blueprint} -/// A [Blueprint] is a virtual way of grouping [Component]s that are related. -/// {@endtemplate blueprint} -class Blueprint { - /// {@macro blueprint} - Blueprint({ - Iterable? components, - Iterable? blueprints, - }) { - if (components != null) _components.addAll(components); - if (blueprints != null) { - _blueprints.addAll(blueprints); - for (final blueprint in blueprints) { - _components.addAll(blueprint.components); - } - } - } - - final List _components = []; - - final List _blueprints = []; - - Future _addToParent(Component parent) async { - await parent.addAll(_components); - } - - /// Returns a copy of the components built by this blueprint. - List get components => List.unmodifiable(_components); - - /// Returns a copy of the blueprints built by this blueprint. - List get blueprints => List.unmodifiable(_blueprints); -} - -/// Adds helper methods regarding [Blueprint]s to [FlameGame]. -extension FlameGameBlueprint on Component { - /// Shortcut to add a [Blueprint]s components to its parent. - Future addFromBlueprint(Blueprint blueprint) async { - await blueprint._addToParent(this); - } -} diff --git a/packages/pinball_flame/test/src/blueprint_test.dart b/packages/pinball_flame/test/src/blueprint_test.dart deleted file mode 100644 index 402d5059..00000000 --- a/packages/pinball_flame/test/src/blueprint_test.dart +++ /dev/null @@ -1,86 +0,0 @@ -// ignore_for_file: cascade_invocations - -import 'package:flame/components.dart'; -import 'package:flame/game.dart'; -import 'package:flame_test/flame_test.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:pinball_flame/pinball_flame.dart'; - -void main() { - TestWidgetsFlutterBinding.ensureInitialized(); - - group('Blueprint', () { - final flameTester = FlameTester(FlameGame.new); - - test('correctly sets and gets components', () { - final component1 = Component(); - final component2 = Component(); - final blueprint = Blueprint( - components: [ - component1, - component2, - ], - ); - - expect(blueprint.components.length, 2); - expect(blueprint.components, contains(component1)); - 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: [ - Component(), - Component(), - ], - ); - await game.addFromBlueprint(blueprint); - await game.ready(); - - for (final component in blueprint.components) { - expect(game.children.contains(component), isTrue); - } - }); - - flameTester.test('adds components from a child Blueprint', (game) async { - final childBlueprint = Blueprint( - components: [ - Component(), - Component(), - ], - ); - final parentBlueprint = Blueprint( - components: [ - Component(), - Component(), - ], - blueprints: [ - childBlueprint, - ], - ); - - await game.addFromBlueprint(parentBlueprint); - await game.ready(); - - for (final component in childBlueprint.components) { - expect(game.children, contains(component)); - expect(parentBlueprint.components, contains(component)); - } - for (final component in parentBlueprint.components) { - expect(game.children, contains(component)); - } - }); - }); -}