Phase 11: mark buzzer answers, +1 for a correct one
The host marks the answering team "Got it" or "Wrong" (G / W). Wrong passes the turn to the next team in the buzz order; Got it closes the buzzers until "Next question" (B). Undo reverses either mark. In a direct game a correct answer adds 1 to the team's score in the game's first criterion, as an ordinary admin score row, so it flows through the scoring engine (multiplier, placement) and the existing range/step trigger. The point is written before the mark, so a refused point never leaves a "correct" with nothing behind it. Judged games only get the mark: the judges' scores stand. Needs supabase/migrations/0004_buzz_result.sql applied before deploying. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+14
-3
@@ -33,7 +33,7 @@ Admin mutations = server actions. `src/proxy.ts` (Next.js 16's name for middlewa
|
||||
- Public/judge access = token in URL → route handler validates with zod → service-role query scoped by that token.
|
||||
- Judge write checks: judge not revoked, game not locked/done, criterion belongs to judge's game, team belongs to the game's event, value within min/max and on step. (DB trigger also enforces range.)
|
||||
- Scoreboard API checks `scoreboard_visibility` and strips scores when `hidden`; returns `frozen_snapshot` when `frozen`.
|
||||
- Buzz checks: the token's team exists, its event's current game has `buzzer_enabled` and isn't done. The team and game come from the token alone — the request has no body. One row per (game, team), so a repeat press is a no-op.
|
||||
- Buzz checks: the token's team exists, its event's current game has `buzzer_enabled`, isn't done, and nobody has been marked correct for this question. The team and game come from the token alone — the request has no body. One row per (game, team), so a repeat press is a no-op.
|
||||
- Light rate limiting on judge PUT (20 req/s per token), buzz POST (5 req/s per token) and open-link join (3 req/s per link), in-memory per server instance. An open link can create at most 50 judges per game.
|
||||
|
||||
## Realtime (Broadcast "ping then refetch")
|
||||
@@ -73,8 +73,12 @@ type ScoreboardPayload = {
|
||||
} | null;
|
||||
// null unless the current game uses buzzers; sent regardless of score visibility
|
||||
buzzer: {
|
||||
open: boolean; // false once the game is done
|
||||
buzzes: Array<{ teamId: string; name: string; color: string; afterFirstMs: number }>; // in buzz order
|
||||
open: boolean; // false once a team got it, or the game is done
|
||||
buzzes: Array<{ // in buzz order
|
||||
teamId: string; name: string; color: string; afterFirstMs: number;
|
||||
result: 'correct' | 'wrong' | null; // the host's mark
|
||||
}>;
|
||||
answeringTeamId: string | null; // earliest unmarked buzz; null once someone got it
|
||||
} | null;
|
||||
updatedAt: string; // server clock; screens use it to correct their own
|
||||
};
|
||||
@@ -100,6 +104,13 @@ When frozen, rank/total come from `frozen_snapshot` but `currentGame` stays live
|
||||
- Buzzes follow rule 4 like everything else: the ping carries no data and each screen refetches.
|
||||
The buzzing phone gets its result in the POST response, so it doesn't wait for the ping.
|
||||
- Clearing = deleting the current game's rows (admin server action).
|
||||
- Marking an answer is the `markBuzz` server action. `checkMark` decides whether the mark is
|
||||
allowed and whether a point moves (+1 for a new "correct", −1 when one is undone);
|
||||
`bumpScore` gives the new cell value. In a direct game the point is written to the admin's
|
||||
score row for the game's first criterion — an ordinary score, so the scoring engine turns it
|
||||
into leaderboard points like any other and the `validate_score` trigger still guards range
|
||||
and step. The score is written before the mark, so a refused point leaves the answer unmarked.
|
||||
- A buzz is refused once any buzz of the game is marked correct, until the host clears.
|
||||
|
||||
## Folder layout
|
||||
```
|
||||
|
||||
@@ -73,5 +73,13 @@ human a short "how to test this manually" checklist. Don't start the next phase
|
||||
**Done when:** two phones on different teams buzz in a buzzer game; the control room and scoreboard
|
||||
show who was first within a second, and "Clear buzzers" resets both phones.
|
||||
|
||||
## Phase 11 — Buzzer answers
|
||||
- Apply `supabase/migrations/0004_buzz_result.sql`, then `npm run gen:types`.
|
||||
- `checkMark` / `bumpScore` / `answeringTeamId` in `src/lib/buzzer.ts` (tested); `markBuzz` server action.
|
||||
- Control room: "Got it" (`G`), "Wrong" (`W`), "Undo", "Next question" (`B`).
|
||||
- Phone and scoreboard follow whose turn it is; "correct" and "wrong" sounds.
|
||||
**Done when:** team A buzzes then team B; "Wrong" hands the turn to B; "Got it" gives B one point
|
||||
in the scoring grid and on the scoreboard; "Undo" takes it back; "Next question" resets the phones.
|
||||
|
||||
## Stretch (only if asked)
|
||||
Participants within teams · co-host admins · CSV export of results.
|
||||
|
||||
+3
-2
@@ -1,6 +1,6 @@
|
||||
# Data model
|
||||
|
||||
Full SQL in `supabase/migrations/` (`0001_init.sql`, then `0002_timer.sql`, `0003_buzzer.sql`).
|
||||
Full SQL in `supabase/migrations/` (`0001_init.sql`, then `0002_timer.sql`, `0003_buzzer.sql`, `0004_buzz_result.sql`).
|
||||
|
||||
| Table | Purpose | Key columns |
|
||||
|---|---|---|
|
||||
@@ -11,7 +11,7 @@ Full SQL in `supabase/migrations/` (`0001_init.sql`, then `0002_timer.sql`, `000
|
||||
| `judges` | Judges per game | `name`, `token`, `revoked`, `source` (nominated/open_link) |
|
||||
| `scores` | One value per (team, criterion, judge) | `judge_id` NULL = admin score (direct mode or override) |
|
||||
| `adjustments` | Bonus/penalty | `points` (+/-), `reason`, optional `game_id` |
|
||||
| `buzzes` | Who buzzed for the current question | `game_id`, `team_id`, `buzzed_at` |
|
||||
| `buzzes` | Who buzzed for the current question | `game_id`, `team_id`, `buzzed_at`, `result` (correct/wrong/NULL) |
|
||||
|
||||
## Notes
|
||||
- `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.
|
||||
@@ -19,4 +19,5 @@ Full SQL in `supabase/migrations/` (`0001_init.sql`, then `0002_timer.sql`, `000
|
||||
- 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`).
|
||||
- Buzzers (`0003_buzzer.sql`): `buzzes` is unique on `(game_id, team_id)` — one buzz per team per question; `buzzed_at` defaults to `clock_timestamp()` and decides the order. Clearing the buzzers deletes the game's rows. A trigger checks the team is in the game's event. `teams.buzzer_token` is a 128-bit token like the others; duplicating an event gives the copied teams new ones.
|
||||
- Buzzer answers (`0004_buzz_result.sql`): `buzzes.result` is the host's mark. The team answering is the earliest buzz with `result IS NULL`, unless some buzz is `correct` (question decided). The point for a correct answer is not stored on the buzz: it is +1 on the admin's `scores` row for the game's first criterion.
|
||||
- `frozen_snapshot` holds the `ScoreboardPayload` captured at freeze time.
|
||||
|
||||
+27
-14
@@ -65,9 +65,10 @@ 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).
|
||||
- Buzzers (buzzer games only): who buzzed, in order, with each team's gap behind the first; "Clear buzzers".
|
||||
- Buzzers (buzzer games only): who buzzed, in order, with each team's gap behind the first;
|
||||
"Got it" / "Wrong" for the team answering, "Undo" on a marked team, and "Next question".
|
||||
- Keyboard shortcuts: `N` next game, `P` prev game, `H` cycle visibility, `T` start/pause timer,
|
||||
`B` clear buzzers, `?` help.
|
||||
`G` got it, `W` wrong, `B` next question (clears the buzzers), `?` help.
|
||||
|
||||
### 4.3 Scoreboard (`/s/[token]`)
|
||||
- Projector-first, 16:9, readable from the back of a hall.
|
||||
@@ -111,24 +112,36 @@ Played by the scoreboard page, so they come out of the projector PC's speakers.
|
||||
- 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.
|
||||
- Buzzer: a two-note ding when a team is first to buzz.
|
||||
- Buzzer: a two-note ding when a team starts answering, a rising arpeggio for "got it" and two
|
||||
falling notes for "wrong".
|
||||
- Sounds are synthesised in the browser (no audio files). With reduced motion the drum-roll is skipped.
|
||||
|
||||
### 4.7 Buzzers (`/b/[token]`)
|
||||
For "first to answer" games. A game opts in with the "Teams buzz in" checkbox; scoring is unchanged
|
||||
(the host or the judges still enter the points).
|
||||
For "first to answer" games. A game opts in with the "Teams buzz in" checkbox.
|
||||
- Every team has one buzzer link for the whole night. Someone on the team opens it on a phone:
|
||||
team name, the current game, and one big "Buzz" button.
|
||||
- The button works only while the current game uses buzzers and isn't done. Otherwise the page
|
||||
says there's no buzzer for this game, and wakes up by itself when one starts.
|
||||
- The server decides the order, using the database's clock — never the phones' clocks.
|
||||
- A team buzzes once per question; pressing again does nothing. Later teams can still buzz, so
|
||||
the host knows who is next if the first answer is wrong.
|
||||
- The phone shows "You buzzed first!" (the screen turns the team's colour) or its place and who was first.
|
||||
- The control room lists the order with the gap behind the first buzz ("+0.42s"). "Clear buzzers"
|
||||
(or `B`) empties it for the next question.
|
||||
- The scoreboard shows "{Team} buzzed!" in the team's colour, with the following teams after it,
|
||||
and plays a ding. It is not a score, so it shows whether scores are visible, frozen or hidden.
|
||||
- A team buzzes once per question; pressing again does nothing. Later teams can still buzz and
|
||||
queue up behind the team answering.
|
||||
- The team answering is the earliest buzz the host hasn't marked. The host marks it:
|
||||
- **Got it** (`G`) — the question is decided and the buzzers close. In a direct game the team
|
||||
gets +1 in the game's first criterion (so the point follows the game's multiplier and
|
||||
placement rules like any other score). In a judged game nothing is added: the judges score.
|
||||
- **Wrong** (`W`) — that team is out for this question and the turn passes to the next team
|
||||
in the buzz order. With nobody waiting, the buzzers stay open for the other teams.
|
||||
- **Undo** on a marked team removes the mark, and takes the point back if it was "got it".
|
||||
- **Next question** (`B`) clears everything and opens the buzzers again.
|
||||
- If the point can't be added (the score is at the criterion's maximum, or +1 doesn't fit its
|
||||
step), the answer stays unmarked and the host sees why.
|
||||
- The phone's screen turns the team's colour while it is that team's turn ("You buzzed first!
|
||||
Answer now." / "Your turn! Answer now.") and when it got it. Otherwise it shows the team's
|
||||
place and who is answering, "Not this time" after a wrong answer, or who got it.
|
||||
- The control room lists the order with the gap behind the first buzz ("+0.42s") and each mark.
|
||||
- The scoreboard shows "{Team} buzzed!" in the team's colour with the waiting teams after it,
|
||||
"{Team} to answer" when the turn passes, and "{Team} got it!". It is not a score, so it shows
|
||||
whether scores are visible, frozen or hidden (the point itself follows the usual visibility rules).
|
||||
- The phone asks the browser to keep the screen on while the page is open.
|
||||
|
||||
## 5. Non-functional
|
||||
@@ -141,5 +154,5 @@ For "first to answer" games. A game opts in with the "Teams buzz in" checkbox; s
|
||||
- Individual contestants within teams (stretch: `participants` per team).
|
||||
- Multiple admins / co-hosts (stretch).
|
||||
- Per-game timers (stretch). The event countdown timer is in 4.5; team buzzers are in 4.7.
|
||||
- Buzzers for individual contestants, automatic points for buzzing first, and locking a team out
|
||||
after a wrong answer (the host just reads the next team from the order).
|
||||
- Buzzers for individual contestants, a configurable points value per correct answer, and
|
||||
penalties for a wrong answer (use the bonus/penalty panel).
|
||||
|
||||
+8
-3
@@ -91,11 +91,16 @@ Selected block filled in team colour. Tap the selected block again to clear.
|
||||
└─────────────────────────┘
|
||||
```
|
||||
One round button in the team's colour, as big as the screen allows; it reacts on touch-down, not
|
||||
on release. After buzzing it shows the team's place ("1st", "2nd"). First in: the whole screen
|
||||
on release. After buzzing it shows the team's place ("1st", "2nd"), then ✓ or ✗ once the host
|
||||
marks the answer. While it's the team's turn to answer, and when it got it, the whole screen
|
||||
turns the team's colour. Greyed out while there is no buzzer game.
|
||||
|
||||
On the scoreboard a buzz is a banner in the team's colour above the standings: "Lions buzzed!",
|
||||
then the later teams in small text. It pops in once; reduced motion shows it without the pop.
|
||||
On the scoreboard the buzzer is a banner in the answering team's colour above the standings:
|
||||
"Lions buzzed!" with the waiting teams in small text, "Eagles to answer" when the turn passes,
|
||||
"Eagles got it!" at the end. It pops in on each change; reduced motion shows it without the pop.
|
||||
|
||||
In the control room the answering team's row is highlighted (Floodlight) and carries the two
|
||||
buttons "Got it +1" and "Wrong"; marked rows show ✓ / ✗ and an "Undo".
|
||||
|
||||
## Copy
|
||||
Plain verbs: "Next game", "Hide scores", "Freeze scores", "Show scores", "Add bonus", "Copy judge link".
|
||||
|
||||
Reference in New Issue
Block a user