How-to
Add a bonus game
Nest a sub-FSM inside a BonusPhase.
Bonus games — "pick one of three chests", mini-slot, wheel-spin — run their own state machine. slotplate's pattern is to nest a sub-FSM inside a parent phase.
Steps
- Create
BonusPhase. Inenter, instantiate a newFSMwith bonus-only phases (bonusIntro,bonusRound,bonusReveal,bonusOutro). Run it to completion, then transition the parent FSM to the next state. - Add a
BonusSessionstore. It accumulates the bonus win without touchingBalanceStoreuntil the outro. The main-game balance is frozen during the bonus. - Add a scene if needed. If the bonus has its own display tree
(splash, different layout), add
BonusSceneinview/scenes/. Mount it on bonus entry, unmount on exit. Don't reuseMainScene— the lifecycles differ. - Add a presenter (
BonusPresenter) bridging the bonus store to the bonus scene. Same contract asReelsPresenter. - Wire the trigger.
stopSpinchecksctx.stores.data.bonus; if set, transition tobonusinstead ofwinShow.
Rules
- Main-game state stays frozen during the bonus. No main-game phase runs until the parent phase exits.
- Bonus phases follow all the same rules: one file each,
Ticker.schedulefor timing,Disposablefor cleanup. - The bonus FSM is scoped to the parent phase. Tear it down in
BonusPhase.exit. - The server decides all bonus outcomes — the client plays them back, like main-game spins.
Wire protocol for bonus
Your SpinResponse.bonus field carries the bonus id and payload. The
server can either (a) return the whole bonus outcome up front, or (b) send per-pick
updates as the user interacts. slotplate's contract is flexible — BonusPhase
can make follow-up requests via NetworkManager.pickChest(...) or similar.