feat: removed `Component` inheritance form `Blueprint` (#218)

pull/226/head
Alejandro Santiago 3 years ago committed by GitHub
parent 20529c1406
commit 06b7f29830
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,9 +29,12 @@ void main() {
'loads correctly',
(game) async {
final spaceshipRamp = SpaceshipRamp();
await game.ensureAdd(spaceshipRamp);
await game.addFromBlueprint(spaceshipRamp);
await game.ready();
expect(game.contains(spaceshipRamp), isTrue);
for (final component in spaceshipRamp.components) {
expect(game.contains(component), isTrue);
}
},
);

@ -1,16 +1,13 @@
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.
// 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,
/// but they need to be added directly on the [FlameGame] level.
/// A [Blueprint] is a virtual way of grouping [Component]s that are related.
/// {@endtemplate blueprint}
// TODO(alestiago): refactor with feat/make-blueprint-extend-component.
class Blueprint extends Component {
class Blueprint {
/// {@macro blueprint}
Blueprint({
Iterable<Component>? components,
@ -27,7 +24,7 @@ class Blueprint extends Component {
final List<Component> _components = [];
final List<Component> _blueprints = [];
final List<Blueprint> _blueprints = [];
Future<void> _addToParent(Component parent) async {
await parent.addAll(_components);
@ -37,7 +34,7 @@ class Blueprint extends Component {
List<Component> get components => List.unmodifiable(_components);
/// Returns a copy of the blueprints built by this blueprint.
List<Component> get blueprints => List.unmodifiable(_blueprints);
List<Blueprint> get blueprints => List.unmodifiable(_blueprints);
}
/// Adds helper methods regarding [Blueprint]s to [FlameGame].

@ -27,8 +27,8 @@ void main() {
group('SparkyFireZone', () {
flameTester.test('loads correctly', (game) async {
final sparkyFireZone = SparkyFireZone();
await game.ensureAdd(sparkyFireZone);
await game.addFromBlueprint(SparkyFireZone());
await game.ready();
});
group('loads', () {

Loading…
Cancel
Save