t1k:cocos:playable:fsm
| Field | Value |
|---|---|
| Module | playable |
| Version | 0.5.6 |
| Effort | high |
| Tools | — |
Keywords: ads, cocos, fsm, playable, state machine, state manager
How to invoke
Section titled “How to invoke”/t1k:cocos:playable:fsmState Machine (FSM)
Section titled “State Machine (FSM)”Singleton StateManager with type-safe, async state transitions. States self-register via @State decorator at module load time. See t1k-cocos-playable-gameflow for how GameView drives the flow.
Details
Section titled “Details”- API reference: architecture, APIs, decorator registration
- Workflow examples: typical ad flow, state definition, transitions, update loop
Common Mistakes
Section titled “Common Mistakes”- Importing state files after calling
changeState()—@Statedecorator runs at import time; states not imported are not registered - Not awaiting
changeState()—onEntermay not complete before next logic runs - Subscribing signals in
onEnterwithout unsubscribing inonExit— signal leaks persist across states - Calling
sm.reset()mid-transition — leaves currentState inconsistent; only use on scene reload - Implementing constructor logic instead of
onEnter—@Statecallsnew StateClass()at decoration time, before game starts
Gotchas
Section titled “Gotchas”- Decorator order matters —
@Statemust run beforeStateManager.start(); if a state-file is tree-shaken out at build, the decorator never runs and the state silently isn’t registered. Import the state files explicitly from a barrel. - Async transitions must await previous-state cleanup — racing
enter()of state B beforeexit()of state A finishes leaks subscriptions. - Singleton survives scene reload — call
StateManager.reset()on scene replay or stale state leaks across replays.