addState<S extends Object> method
Registers state S with initial.
Implementation
@override
AppBuilder addState<S extends Object>(S initial) {
_assertOpen();
if (world.resources.contains<CurrentState<S>>()) {
throw StateError(
'A state machine for $S has already been added. Each state type is '
'registered exactly once; use a second enum for an orthogonal machine.',
);
}
final machine = StateMachineRuntime<S>(initial);
world.resources
..insert<CurrentState<S>>(machine.current)
..insert<NextState<S>>(machine.next);
// Registered eagerly so game code can `commands.insert<DespawnOnExit>`
// without any system having queried the type first.
world.ensureObjectStore<DespawnOnExit>();
_stateMachines.add(machine);
return this;
}