feat(offline): per-seat medals in local games; drop the you-won text + lobby medal
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Has been skipped
CI / integration (pull_request) Has been skipped
CI / ui (pull_request) Successful in 1m6s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m42s

For a local (offline) game the outcome is not always about a single
'you' (hotseat is 2-4 players), so:
- Game.svelte: a finished local game no longer shows the viewer-centric
  'you won/lost/draw' status; instead each seat plaque shows a per-seat
  place medal, left of the name (result.seatMedal — trophy for the winner,
  then places by score; a draw medals everyone).
- Lobby.svelte: a local game shows no lobby medal (resultBadge is
  viewer-centric and no seat matches the account) — its result lives on
  the in-game plaques.
- result.ts: seatMedal(game, seat), unit-tested.
This commit is contained in:
Ilia Denisov
2026-07-07 14:54:44 +02:00
parent 52d0c559f9
commit 0ed34c7720
4 changed files with 57 additions and 5 deletions
+27 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { resultBadge } from './result';
import { resultBadge, seatMedal } from './result';
import type { GameView, Seat } from './model';
const seat = (s: number, accountId: string, score: number, isWinner = false): Seat => ({
@@ -75,3 +75,29 @@ describe('resultBadge', () => {
expect(resultBadge(second, 'me')).toEqual({ key: 'result.place2', emoji: '🥈' });
});
});
describe('seatMedal', () => {
it('is empty for a game still in progress', () => {
expect(seatMedal(game([seat(0, 'a', 5), seat(1, 'b', 3)], 'active'), 0)).toBe('');
});
it('finished two-player: winner gets the trophy, the other second place', () => {
const g = game([seat(0, 'a', 300, true), seat(1, 'b', 200)]);
expect(seatMedal(g, 0)).toBe('🏆');
expect(seatMedal(g, 1)).toBe('🥈');
});
it('finished draw (no winner): every seat gets the medal', () => {
const g = game([seat(0, 'a', 200), seat(1, 'b', 200)]);
expect(seatMedal(g, 0)).toBe('🏅');
expect(seatMedal(g, 1)).toBe('🏅');
});
it('finished four-player: places each seat by score', () => {
const g = game([seat(0, 'a', 100), seat(1, 'b', 400, true), seat(2, 'c', 300), seat(3, 'd', 200)]);
expect(seatMedal(g, 1)).toBe('🏆'); // winner
expect(seatMedal(g, 2)).toBe('🥈'); // 2nd by score
expect(seatMedal(g, 3)).toBe('🥉'); // 3rd
expect(seatMedal(g, 0)).toBe('🏅'); // 4th
});
});