forked from WikiDeck/wikideck
[ui-pvp] onAct resolves on host acceptance; collection passes through the server duel profile
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -186,7 +186,12 @@ export function DuelOnlinePlay({ modeId, modeName, deck, entry, accountToken, on
|
||||
if (seat && status && !done) await pvp.resign(seat).catch(() => {});
|
||||
onExit();
|
||||
};
|
||||
const act = (a: unknown) => { if (seat) pvp.act(seat, a).then(apply, e => { setError(message(e)); void poll(); }); };
|
||||
/** Resolves once the host accepts the action and rejects on error, so ui-duel's board can send a declaration sequence (#58). */
|
||||
const act = async (a: unknown): Promise<void> => {
|
||||
if (!seat) throw new Error('Not seated.');
|
||||
try { apply(await pvp.act(seat, a)); }
|
||||
catch (e) { setError(message(e)); void poll(); throw e; }
|
||||
};
|
||||
const invite = seat?.invite ?? status?.invite;
|
||||
const link = invite ? inviteUrl(invite) : '';
|
||||
const copy = async () => {
|
||||
@@ -203,7 +208,7 @@ export function DuelOnlinePlay({ modeId, modeName, deck, entry, accountToken, on
|
||||
return <section className="play-panel" aria-labelledby="duel-title">
|
||||
<div className="section-eyebrow">{eyebrow}</div>
|
||||
<h2 id="duel-title">{status.phase === 'finished' ? (status.outcome?.winner === null ? 'Draw' : won ? 'Victory' : 'Defeat') : `vs ${opp}`}</h2>
|
||||
{status.phase === 'playing' && <DuelBoardPlaceholder legal={status.legalActions ?? []} onAct={act} opponent={opp} />}
|
||||
{status.phase === 'playing' && <DuelBoardPlaceholder legal={status.legalActions ?? []} onAct={a => { act(a).catch(() => {}); }} opponent={opp} />}
|
||||
{error && <p className="dock-error small" role="alert">{error}</p>}
|
||||
<div className="play-dock"><div className="play-actions">
|
||||
<button className="button outline" onClick={leave}>{status.phase === 'finished' ? <><ArrowLeft size={16} /> Back</> : 'Resign'}</button>
|
||||
|
||||
@@ -10,6 +10,8 @@ export const DEFAULT_COPY_LIMIT = 4;
|
||||
export type CollectionCard = {
|
||||
tokenId: string; pageId: number; title: string; revisionId?: number;
|
||||
url?: string; imageUrl?: string; extract?: string; category?: string; height?: number;
|
||||
/** Server-derived, frozen duel profile (ownership adds it for ui-duel's bot match, #58). Passed through untouched. */
|
||||
duel?: unknown;
|
||||
};
|
||||
export type Collection = {
|
||||
deckSize: number; copyLimit: number; cards: CollectionCard[];
|
||||
@@ -37,7 +39,7 @@ export function parseCollection(v: unknown): Collection {
|
||||
seen.add(tokenId);
|
||||
cards.push({ tokenId, pageId, title: str(c.title, 200) || `Page ${pageId}`, revisionId: int(c.revisionId, 1),
|
||||
url: httpUrl(c.url), imageUrl: httpUrl(c.imageUrl ?? c.image), extract: str(c.extract, 600) || undefined,
|
||||
category: str(c.category, 40) || undefined, height: int(c.height) });
|
||||
category: str(c.category, 40) || undefined, height: int(c.height), ...(c.duel && typeof c.duel === 'object' ? { duel: c.duel } : {}) });
|
||||
}
|
||||
return { deckSize: int(o.deckSize, 1, 200) ?? DEFAULT_DECK_SIZE, copyLimit: int(o.copyLimit, 1, 200) ?? DEFAULT_COPY_LIMIT, cards, source: 'server' };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user