feat: disallowed adding components to a ComponentController

pull/121/head
alestiago 4 years ago
parent 07ddb1f7b6
commit 1019b669fa

@ -22,6 +22,11 @@ abstract class ComponentController<T extends Component> extends Component {
); );
await super.addToParent(parent); await super.addToParent(parent);
} }
@override
Future<void> add(Component component) {
throw Exception('ComponentController should not add other components.');
}
} }
/// Mixin that attaches a single [ComponentController] to a [Component]. /// Mixin that attaches a single [ComponentController] to a [Component].

@ -31,6 +31,7 @@ void main() {
); );
}, },
); );
flameTester.test( flameTester.test(
'throws AssertionError when not attached to controlled component', 'throws AssertionError when not attached to controlled component',
(game) async { (game) async {
@ -44,6 +45,20 @@ void main() {
); );
}, },
); );
flameTester.test(
'throws Exception when adding other component',
(game) async {
final component = ControlledComponent();
final controller = TestComponentController(component);
final anotherComponet = Component();
await expectLater(
() async => controller.add(anotherComponet),
throwsException,
);
},
);
}); });
group('Controls', () { group('Controls', () {

Loading…
Cancel
Save