- game/round.ts: GameRound contract (start/submitAnswer/reveal/score) + RoundContext + RoomGameController (decouples room from engine) - game/registry.ts: register/createRound — adding a mode = one registerRound - game/engine.ts: server-authoritative orchestration. Per round: start → broadcast round:start → wait (timer OR all eligible voted) → reveal → apply score deltas → score:update; then game:end. DJ counts as eligible voter; round ends on first condition met. - handlers: game:start (host-only, validates rounds/modes) + round:vote wired to the engine - shared: add game:start client event - engine.test.ts: covers both end conditions + voteAck (bun test) - turbo/root: add test task Roadmap V1 step 3. No UI yet — concrete quiz mode + client come in step 4. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
25 lines
748 B
TypeScript
25 lines
748 B
TypeScript
// Registre des épreuves. Chaque mode s'enregistre via registerRound() ;
|
|
// le moteur instancie une manche fraîche par round via createRound().
|
|
|
|
import type { RoundType } from "@nerdware/shared"
|
|
import type { GameRound } from "./round"
|
|
|
|
export type RoundFactory = () => GameRound
|
|
|
|
const factories = new Map<RoundType, RoundFactory>()
|
|
|
|
export function registerRound(type: RoundType, factory: RoundFactory): void {
|
|
factories.set(type, factory)
|
|
}
|
|
|
|
export function createRound(type: RoundType): GameRound {
|
|
const factory = factories.get(type)
|
|
if (!factory) {
|
|
throw new Error(`Aucune épreuve enregistrée pour le type "${type}"`)
|
|
}
|
|
return factory()
|
|
}
|
|
|
|
export function hasRound(type: RoundType): boolean {
|
|
return factories.has(type)
|
|
}
|