utils-book provides the functions that drive the core game loop: receiving a book (JSON payload) from the RGS and processing its events array one-by-one in order.
createPlayBookUtils()
Factory function that returns playBookEvent and playBookEvents. You pass it the bookEventHandlerMap for your game once at startup.
Parameters
Return value
playBookEvents()
Processes an entire book.events array, resolving each handler one after another using sequence() from utils-shared. The order of events is critical — it determines the visual sequence of the game (e.g. spin before win reveal).
bookEvents is automatically injected into the context of every handler call, so handlers can inspect the full event list.
sequence() from utils-shared resolves async functions one-after-another, unlike Promise.all() which fires them simultaneously. This is essential for maintaining the correct animation order.
playBookEvent()
Dispatches a single bookEvent to the matching handler in bookEventHandlerMap. If no handler is found for bookEvent.type, an error is logged.
This is also used directly by the MODE_<GAME_MODE>/bookEvent/<TYPE> Storybook stories to test individual events in isolation.
Types
Real-world usage
createMultiBookUtils()
For games that receive multiple books simultaneously (e.g. multi-way games), createMultiBookUtils provides helpers to split, merge, and re-assemble books into rounds.
booksToRounds()
Splits multiple books into parallel rounds aligned by a splitBy event type.
roundsToBooks()
Reassembles rounds back into per-book arrays: