Add scoreboard countdown timer and sound effects
- Timer: one per event, set from the control room (duration, presets, start/pause/resume/reset, show/hide, T shortcut). Rules are pure functions in src/lib/timer.ts; the server's clock sets the end time and each screen counts down locally, corrected for its own clock. Needs supabase/migrations/0002_timer.sql. - Sound effects on the scoreboard, synthesised with Web Audio (no files): drum-roll + crash per revealed team, fanfare for first place, a chime on game change, ticks for the last 10 seconds and a buzzer at zero. Triggers are pure functions comparing consecutive payloads. - 'Turn sound on' button on the scoreboard, since browsers block audio until a click; the choice is remembered across reloads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+16
-1
@@ -59,12 +59,27 @@ type ScoreboardPayload = {
|
||||
rank?: number; total?: number;
|
||||
// v1 sends totals only; no per-game points.
|
||||
}>;
|
||||
updatedAt: string;
|
||||
// null while the host has the timer hidden; sent regardless of score visibility
|
||||
timer: {
|
||||
status: 'idle' | 'running' | 'paused' | 'finished';
|
||||
remainingMs: number; // as of updatedAt
|
||||
endsAt: string | null; // set while running
|
||||
durationMs: number;
|
||||
} | null;
|
||||
updatedAt: string; // server clock; screens use it to correct their own
|
||||
};
|
||||
```
|
||||
During reveal mode, teams not yet revealed are sent without rank/total, alphabetically and before the revealed ones, so their order leaks nothing.
|
||||
When frozen, rank/total come from `frozen_snapshot` but `currentGame` stays live. A missing or invalid snapshot is treated as hidden, never as live.
|
||||
|
||||
## Timer and sound
|
||||
- Timer state lives on `events` (see DATA_MODEL.md). `src/lib/timer.ts` holds the rules as pure
|
||||
functions; server actions apply them using the server's clock. Screens count down locally
|
||||
between pings from `endsAt`, offset by `updatedAt` minus their own clock.
|
||||
- Sound effects are synthesised in `src/lib/sound.ts` with the Web Audio API. Which sound a
|
||||
change triggers is decided by pure functions in `src/lib/scoreboard-sounds.ts`; the
|
||||
scoreboard compares each new payload with the previous one. No sound data travels over Realtime.
|
||||
|
||||
## Folder layout
|
||||
```
|
||||
src/
|
||||
|
||||
+7
-1
@@ -59,5 +59,11 @@ human a short "how to test this manually" checklist. Don't start the next phase
|
||||
- Deploy to Vercel; set env vars; set Supabase auth redirect URLs to the Vercel domain.
|
||||
**Done when:** full dry run on the deployed URL: laptop admin + projector scoreboard + 2 phone judges.
|
||||
|
||||
## Phase 9 — Timer + sound effects
|
||||
- Apply `supabase/migrations/0002_timer.sql`, then `npm run gen:types`.
|
||||
- Timer rules in `src/lib/timer.ts` (tested); control-room panel (set, start/pause/reset, show/hide, `T`); scoreboard display.
|
||||
- Scoreboard sound effects: reveal drum-roll + crash/fanfare, game-change chime, last-10-seconds ticks + buzzer; "Turn sound on" button.
|
||||
**Done when:** a timer started in the control room counts down on the scoreboard with ticks and a buzzer, and a reveal plays its drum-roll.
|
||||
|
||||
## Stretch (only if asked)
|
||||
Participants within teams · co-host admins · countdown timer on scoreboard · sound effects on reveal · CSV export of results.
|
||||
Participants within teams · co-host admins · CSV export of results.
|
||||
|
||||
+2
-1
@@ -4,7 +4,7 @@ Full SQL in `supabase/migrations/0001_init.sql`.
|
||||
|
||||
| Table | Purpose | Key columns |
|
||||
|---|---|---|
|
||||
| `events` | A game night | `owner_id`, `scoreboard_token`, `scoreboard_visibility`, `frozen_snapshot`, `current_game_id`, `reveal_active`, `reveal_count` |
|
||||
| `events` | A game night | `owner_id`, `scoreboard_token`, `scoreboard_visibility`, `frozen_snapshot`, `current_game_id`, `reveal_active`, `reveal_count`, `timer_visible`, `timer_duration_ms`, `timer_remaining_ms`, `timer_ends_at` |
|
||||
| `teams` | Teams in an event | `name`, `color` (#RRGGBB), `sort_order` |
|
||||
| `games` | Activities | `scoring_mode`, `points_mode`, `multiplier`, `placement_points int[]`, `status`, `admin_notes`, `judge_notes`, `open_token`, `open_link_enabled`, `judging_locked`, `spotlight_team_id` |
|
||||
| `criteria` | Scoring blocks per game | `label`, `description`, `input_type`, `min_value`, `max_value`, `step`, `weight` |
|
||||
@@ -16,4 +16,5 @@ Full SQL in `supabase/migrations/0001_init.sql`.
|
||||
- `scores` unique on `(team_id, criterion_id, judge_id)` with `NULLS NOT DISTINCT`, so there's exactly one admin row per team+criterion → clean upserts.
|
||||
- In **judged** games, an admin row (`judge_id IS NULL`) is an **override** for that cell.
|
||||
- Deleting a criterion/team/judge cascades its scores.
|
||||
- Timer (`0002_timer.sql`): running = `timer_ends_at` set; paused = `timer_remaining_ms` set; reset = both null (full `timer_duration_ms`).
|
||||
- `frozen_snapshot` holds the `ScoreboardPayload` captured at freeze time.
|
||||
|
||||
+21
-2
@@ -62,7 +62,7 @@ This is the screen used during the night. Must be fast and hard to mess up.
|
||||
Recent adjustments list with undo.
|
||||
- Scoreboard visibility: **Visible / Frozen / Hidden** (see 4.3). Big obvious toggle.
|
||||
- "Open scoreboard" button (new tab) + "Reveal mode" button (see 4.3).
|
||||
- Keyboard shortcuts: `N` next game, `P` prev game, `H` cycle visibility, `?` help.
|
||||
- Keyboard shortcuts: `N` next game, `P` prev game, `H` cycle visibility, `T` start/pause timer, `?` help.
|
||||
|
||||
### 4.3 Scoreboard (`/s/[token]`)
|
||||
- Projector-first, 16:9, readable from the back of a hall.
|
||||
@@ -89,6 +89,25 @@ This is the screen used during the night. Must be fast and hard to mess up.
|
||||
- Open link (`/jo/[token]`): enter name → creates judge → redirects to personal link and stores it
|
||||
in localStorage so a refresh keeps them in.
|
||||
|
||||
### 4.5 Timer
|
||||
One countdown timer per event, run from the control room; not tied to a game.
|
||||
- Set a time (minutes + seconds, or presets 30s / 1 min / 2 min / 5 min). Setting a time resets the timer.
|
||||
- Start, pause, resume, reset. Show or hide it on the scoreboard; starting it also shows it.
|
||||
- The scoreboard shows it large above the standings. It is not a score, so it shows whether
|
||||
scores are visible, frozen or hidden.
|
||||
- The last 10 seconds are highlighted; at zero it shows "Time's up" until reset.
|
||||
- The server's clock decides when it ends, so every screen agrees even if a device clock is wrong.
|
||||
- Keyboard shortcut in the control room: `T` start/pause.
|
||||
|
||||
### 4.6 Sound effects (scoreboard only)
|
||||
Played by the scoreboard page, so they come out of the projector PC's speakers.
|
||||
- Reveal: a drum-roll, then a crash as each team appears; a fanfare for first place.
|
||||
- Game transition: a chime when the current game changes.
|
||||
- Timer: a tick for each of the last 10 seconds (sharper for the last 3) and a buzzer at zero.
|
||||
- Browsers only allow sound after a click on the page, so the scoreboard has a "Turn sound on"
|
||||
button. The choice is remembered, but after a reload one click anywhere is needed again.
|
||||
- Sounds are synthesised in the browser (no audio files). With reduced motion the drum-roll is skipped.
|
||||
|
||||
## 5. Non-functional
|
||||
- Live latency target < 1s on normal Wi-Fi.
|
||||
- Works with ~10 teams, ~20 games, ~10 judges per game without lag.
|
||||
@@ -98,4 +117,4 @@ This is the screen used during the night. Must be fast and hard to mess up.
|
||||
## 6. Out of scope (v1)
|
||||
- Individual contestants within teams (stretch: `participants` per team).
|
||||
- Multiple admins / co-hosts (stretch).
|
||||
- Timers/buzzers (stretch).
|
||||
- Per-game timers and buzzers for contestants (stretch). The event countdown timer is in 4.5.
|
||||
|
||||
Reference in New Issue
Block a user