addState method
Define a state. Must be called before start. Calling after start throws, because addState defines the machine's shape once; it's not meant to be mutated while running.
Implementation
CStateMachine<T> addState(
String name, {
void Function()? onEnter,
void Function()? onExit,
void Function(double dt)? onUpdate,
}) {
if (_started) {
throw StateError(
'addState("$name") called after start() — define all states before starting.',
);
}
if (_states.containsKey(name)) {
throw ArgumentError('State "$name" already defined.');
}
_states[name] = .new(
name,
onEnter: onEnter,
onExit: onExit,
onUpdate: onUpdate,
);
return this;
}