StateMachineImpl

EntityStateMachineBaseceramic.StateMachineImpl (Class) → StateMachine, StateMachineComponent

Implementation class for StateMachine functionality.

StateMachineImpl provides the core implementation for type-safe state machines. It handles state transitions, lifecycle management, and state instance mapping. This class is typically not used directly - use StateMachine instead.

Features:

  • Type-safe state management with generic type T
  • Automatic enter/exit/update lifecycle calls
  • State instance mapping and lifecycle management
  • Observable state changes
  • Support for scheduling callbacks on state transitions

The generic parameter T can be:

  • String for string-based states
  • Enum for type-safe enum states
  • Any other type with proper toString() implementation

Instance Members

state: ceramic.StateMachineImpl.T

The current state


nextState: ceramic.StateMachineImpl.T

When transitioning from one state to another, this will be set to the next incoming state


invalidateState(): Void

set(key: ceramic.StateMachineImpl.T, stateInstance: State): Void

Associates a state instance with a state key.

Name Type Description
key ceramic.StateMachineImpl.T The state identifier (string, enum value, etc.)
stateInstance State The State instance to use for this state

get(key: ceramic.StateMachineImpl.T): State

Gets the state instance associated with a state key.

Name Type Description
key ceramic.StateMachineImpl.T The state identifier
Returns Description
State The State instance, or null if not found

update(delta: Float): Void
Name Type
delta Float

scheduleOnceEnterState(owner: Entity, state: ceramic.StateMachineImpl.T, callback: Function): Void

Schedules a callback to be called once when entering a specific state.

Name Type Description
owner Entity The entity that owns this callback (for cleanup)
state ceramic.StateMachineImpl.T The state to watch for
callback Function The function to call when entering the state

scheduleOnceExitState(owner: Entity, state: ceramic.StateMachineImpl.T, callback: Function): Void

Schedules a callback to be called once when exiting a specific state.

Name Type Description
owner Entity The entity that owns this callback (for cleanup)
state ceramic.StateMachineImpl.T The state to watch for
callback Function The function to call when exiting the state

new(): Void

Private Members

unobservedState: ceramic.StateMachineImpl.T

emitStateChange(current: ceramic.StateMachineImpl.T, previous: ceramic.StateMachineImpl.T): Void

Event when state field changes.

Name Type
current ceramic.StateMachineImpl.T
previous ceramic.StateMachineImpl.T

computeStateDefined(state: ceramic.StateMachineImpl.T): Bool
Name Type
state ceramic.StateMachineImpl.T
Returns
Bool

keyToString(key: ceramic.StateMachineImpl.T): String
Name Type
key ceramic.StateMachineImpl.T
Returns
String

Metadata

Name Parameters
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()
:build tracker.macros.ObservableMacro.build()
:autoBuild tracker.macros.ObservableMacro.build()
:build ceramic.macros.ComponentMacro.build()
:autoBuild ceramic.macros.ComponentMacro.build()