StateMachine
:A finite state machine
stateMap
: Record<string, State>state
: State | undefinedenterState
(name: string) => voidMake the machine enter a state
param
name- The new state
onStateEnter
(name: string, cb: (sm: StateMachine, previous: string) => void) => voidSet a callback for when the machine enters a state
param
name- The state
param
cb- The callback
onStateUpdate
(name: string, cb: (sm: StateMachine, current: string) => void) => voidSet a callback for when the machine updates a state
param
name- The state
param
cb- The callback
onStateDraw
(name: string, cb: (sm: StateMachine, current: string) => void) => voidSet a callback for when the machine draws a state
param
name- The state
param
cb- The callback
onStateExit
(name: string, cb: (sm: StateMachine, next: string) => void) => voidSet a callback for when the machine exits a state
param
name- The state
param
cb- The callback
onStateTransition
(from: string, to: string, cb: (sm: StateMachine, from: string, to: string) => void) => voidSet a callback for when the machine transitions from one state to the other state
param
from- The state which is exited
param
to- The state which is entered
param
cb- The callback