Skip to content
Work in progress. These docs describe Spawnite at launch, and some parts are still being built.

MatchMachine

const MatchMachine: Machine<{ countdownSeconds: number; endedTick: number | null; isOpen: boolean; isOvertime: boolean; laps: number; lapsCompleted: number; matchNumber: number; outcome: MatchOutcome; reason: string; score: number; scoreToWin: number; startedNumber: number; startedTick: number | null; timeLimitSeconds: number; timeUpScores: number | null; timeUpTick: number | null; }, EventsIn<{ countdown: { on: { CANCEL: Waiting; DEFEAT: Ended; RESET: Waiting; }; wait: { seconds: (machineArgs) => number; then: Playing; }; }; ended: { on: { RESET: Waiting; }; }; playing: { on: { DEFEAT: Ended; DRAW: Ended; RESET: Waiting; VICTORY: Ended; }; }; waiting: { on: { DEFEAT: Ended; RESET: Waiting; START: readonly [{ guard: (machineArgs) => boolean; target: Countdown; }, { target: Playing; }]; }; }; }>, ValueIn<{ countdown: { on: { CANCEL: Waiting; DEFEAT: Ended; RESET: Waiting; }; wait: { seconds: (machineArgs) => number; then: Playing; }; }; ended: { on: { RESET: Waiting; }; }; playing: { on: { DEFEAT: Ended; DRAW: Ended; RESET: Waiting; VICTORY: Ended; }; }; waiting: { on: { DEFEAT: Ended; RESET: Waiting; START: readonly [{ guard: (machineArgs) => boolean; target: Countdown; }, { target: Playing; }]; }; }; }>, StateTags<{ countdown: { on: { CANCEL: Waiting; DEFEAT: Ended; RESET: Waiting; }; wait: { seconds: (machineArgs) => number; then: Playing; }; }; ended: { on: { RESET: Waiting; }; }; playing: { on: { DEFEAT: Ended; DRAW: Ended; RESET: Waiting; VICTORY: Ended; }; }; waiting: { on: { DEFEAT: Ended; RESET: Waiting; START: readonly [{ guard: (machineArgs) => boolean; target: Countdown; }, { target: Playing; }]; }; }; }>>

A match as a machine: playing, then ended; spawned in Waiting it waits for START, and in Countdown it waits out its countdown first. CANCEL takes a countdown back to Waiting, as a member’s leave does; RESET takes any state back to Waiting for the next contest. VICTORY and DRAW end it while it plays; DEFEAT ends it from any state before Ended. A bare send writes no outcome and no winner: endMatch does. Its context: score, the coins scored while it played; scoreToWin, laps and timeLimitSeconds, a zero turning a rule off; the ticks it started and ended on, from which readMatchElapsedSeconds derives the seconds played, outcome, reason, the contest’s matchNumber, which a reset raises, whether it is isOpen to joins, and whether it plays its overtime.