onUpdate method
Fires onEnter (if not already fired for this state), evaluates transitions, fires onExit when leaving, then calls onUpdate for whichever state is current after any transition.
Implementation
@override
void onUpdate(double dt) {
if (!_started || _current == null) return;
final currentDef = _states[_current]!;
if (!_entered) {
_entered = true;
currentDef.onEnter?.call();
}
// Evaluate transitions out of the current state, first match wins.
for (final t in _transitions) {
if (t.from != _current) continue;
if (t.when()) {
currentDef.onExit?.call();
_current = t.to;
_timeInState = 0;
_entered = false;
_states[t.to]!.onEnter?.call();
_entered = true;
break; // only one transition per frame
}
}
_timeInState += dt;
_states[_current]!.onUpdate?.call(dt);
}