diff --git a/src/game/OnlinePlay.tsx b/src/game/OnlinePlay.tsx index 5695129..bac1ca1 100644 --- a/src/game/OnlinePlay.tsx +++ b/src/game/OnlinePlay.tsx @@ -219,7 +219,7 @@ export function DuelOnlinePlay({ modeId, modeName, deck, entry, accountToken, on return
{eyebrow}
-

{status?.phase === 'expired' ? 'This lobby expired' : !seat ? (error ? 'Could not start' : 'Connecting…') : status?.phase === 'starting' ? 'Starting…' : entry.kind === 'quick' ? 'Finding an opponent' : 'Waiting for your opponent'}

+

{status?.phase === 'expired' ? 'This lobby expired' : !seat ? (error ? 'Could not start' : 'Connecting…') : status?.phase === 'starting' ? 'Starting…' : status?.phase === 'drafting' ? 'Drafting…' : entry.kind === 'quick' ? 'Finding an opponent' : 'Waiting for your opponent'}

{seat && link && status?.phase !== 'expired' && <>

Send this link to the person you want to play. It opens this lobby, and they bring their own {deck.length}-card deck.

{link}
diff --git a/src/game/online.ts b/src/game/online.ts index f8b2635..c97a55c 100644 --- a/src/game/online.ts +++ b/src/game/online.ts @@ -81,7 +81,7 @@ export const online = { export type DuelSeat = { lobbyId: string; seat: 0 | 1; token: string; invite?: string }; export type DuelStatus = { lobbyId: string; version: number; - phase: 'waiting' | 'starting' | 'playing' | 'finished' | 'expired'; + phase: 'waiting' | 'starting' | 'drafting' | 'playing' | 'finished' | 'expired'; seat: 0 | 1 | null; players: { name: string; rating?: number }[]; outcome: { winner: 0 | 1 | null; reason: string } | null; matchId?: string; invite?: string; @@ -92,7 +92,7 @@ export type LadderEntry = { name: string; rating: number | null; wins: number; l const sid = (v: unknown, max = 128) => (typeof v === 'string' && /^[A-Za-z0-9_-]{1,128}$/.test(v) ? v.slice(0, max) : ''); const seatNo = (v: unknown): 0 | 1 | null => (v === 0 || v === 1 ? v : null); -const PHASES = new Set(['waiting', 'starting', 'playing', 'finished', 'expired']); +const PHASES = new Set(['waiting', 'starting', 'drafting', 'playing', 'finished', 'expired']); export function parseSeat(v: unknown): DuelSeat { const o = (v && typeof v === 'object' ? v : {}) as Record; @@ -162,13 +162,9 @@ async function duelCall(path: string, init: DuelInit = {}): Promise<{ status: nu export const pvp = { createPrivate: (modeId: string, deck: string[], idToken: string) => duelCall(`modes/${id(modeId)}/lobbies`, { body: { deck, private: true, idToken } }).then(r => parseSeat(r.data)), - /** GET /invites/:code resolves the private lobby, then a normal join with our deck. */ - joinInvite: async (code: string, deck: string[], idToken: string) => { - const lobby = (await duelCall(`invites/${id(code)}`)).data as Record | null; - const lobbyId = sid(lobby?.lobbyId); - if (!lobbyId) throw new Error('This invite link has expired or was already used.'); - return parseSeat((await duelCall(`lobbies/${id(lobbyId)}/join`, { body: { deck, idToken } })).data); - }, + /** POST /invites/:code/join (host-pvp, docs/game/HOSTING.md "Seats, invites, quick match and polling"). */ + joinInvite: (code: string, deck: string[], idToken: string) => + duelCall(`invites/${id(code)}/join`, { body: { deck, idToken } }).then(r => parseSeat(r.data)), quick: (modeId: string, deck: string[], idToken: string) => duelCall(`modes/${id(modeId)}/quick`, { body: { deck, idToken } }).then(r => parseSeat(r.data)), /** Returns null when the host answers 204 (nothing changed since `version`). */ diff --git a/src/game/recap/model.ts b/src/game/recap/model.ts index 787d38e..dad773e 100644 --- a/src/game/recap/model.ts +++ b/src/game/recap/model.ts @@ -85,7 +85,8 @@ export function parseMatchRecord(v: unknown): MatchRecord { matchId: str(o.matchId ?? o.id, 128), modeId: str(o.modeId, 64) || undefined, modeName: str(o.modeName, 64) || undefined, players: [names[0], names[1]], startedAt: int(o.startedAt), endedAt: int(o.endedAt ?? o.finishedAt), winner, reason: str(r.reason, 60) || undefined, turns: int(o.turns ?? r.turns), - strength: pair(o.strength, x => int(x) ?? 0), played: pair(o.played, refs), lost: pair(o.lost, refs), log, raw: v, + // host-pvp records carry `decks` (engine cards per seat); their sizes are each side's strength. + strength: pair(o.strength, x => int(x) ?? 0) ?? pair(o.decks, x => (Array.isArray(x) ? x.length : 0)), played: pair(o.played, refs), lost: pair(o.lost, refs), log, raw: v, }; } diff --git a/tests/ui-pvp-recap.test.ts b/tests/ui-pvp-recap.test.ts index 058edc1..ef5b3aa 100644 --- a/tests/ui-pvp-recap.test.ts +++ b/tests/ui-pvp-recap.test.ts @@ -94,3 +94,12 @@ test('story markup becomes text runs; card titles cannot inject markup', () => { const seen = [doc.lead, ...doc.sections.flatMap(s => s.paragraphs)].flatMap(runs); assert.ok(!seen.some(r => r.cite === 9)); }); + +test('a host-pvp match record (winner/reason at top level, decks, no replay yet) still yields a plain recap', () => { + const doc = fallbackRecap(parseMatchRecord({ matchId: 'a'.repeat(32), modeId: 'classic', seed: 's', rules: {}, players: [{ id: 'x', name: 'alice' }, { id: 'y', name: 'bob' }], + winner: 1, reason: 'concede', startedAt: Date.UTC(2026, 10, 18, 1), endedAt: Date.UTC(2026, 10, 18, 1, 20), decks: [new Array(40).fill({}), new Array(40).fill({})], actions: [] })); + assert.equal(doc.title, 'Match of 18 November 2026'); + assert.equal(doc.infobox.result, 'Victory for bob'); + assert.deepEqual(doc.infobox.strength, ['40 cards', '40 cards']); + assert.match(doc.sections.flatMap(s => s.paragraphs).join(' '), /alice withdrew from the engagement\./); +});