SP slotplate
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.

idle waits for click spin debitBet + request stopSpin reels land on grid winShow spotlight + credit click response received allLanded win hold elapsed (or skip) no winlines → idle immediately skip() = forceStop skip() = forceStop skip() = cancel hold idle / resting phase active phase normal transition conditional shortcut
The outer FSM (shown). Add BonusPhase between stopSpin and winShow (or wherever your trigger lives) and run the inner FSM to completion.

Steps

  1. Create BonusPhase. In enter, instantiate a new FSM with bonus-only phases (bonusIntro, bonusRound, bonusReveal, bonusOutro). Run it to completion, then transition the parent FSM to the next state.
  2. Add a BonusSession store. It accumulates the bonus win without touching BalanceStore until the outro. The main-game balance is frozen during the bonus.
  3. Add a scene if needed. If the bonus has its own display tree (splash, different layout), add BonusScene in view/scenes/. Mount it on bonus entry, unmount on exit. Don't reuse MainScene — the lifecycles differ.
  4. Add a presenter (BonusPresenter) bridging the bonus store to the bonus scene. Same contract as ReelsPresenter.
  5. Wire the trigger. stopSpin checks ctx.stores.data.bonus; if set, transition to bonus instead of winShow.

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.schedule for timing, Disposable for 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.