From 2fe16a66c838e9868325b12432e076ce51a679af Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 21:46:26 -0500 Subject: [PATCH] ui-duel: eligibility gate, DuelCard to board card mapping, zoom face fixes (#58) Co-Authored-By: Claude Opus 5.5 --- src/game/duel/DuelCardFace.tsx | 8 +++--- src/game/duel/DuelGate.tsx | 24 ++++++++++++++++++ src/game/duel/DuelPreview.tsx | 14 +++++++---- src/game/duel/cards.ts | 46 ++++++++++++++++++++++++++++++++++ src/game/duel/duel.css | 1 + tests/ui-duel-model.test.ts | 17 +++++++++++++ 6 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 src/game/duel/DuelGate.tsx create mode 100644 src/game/duel/cards.ts diff --git a/src/game/duel/DuelCardFace.tsx b/src/game/duel/DuelCardFace.tsx index 50d6fac..fc25b6e 100644 --- a/src/game/duel/DuelCardFace.tsx +++ b/src/game/duel/DuelCardFace.tsx @@ -55,20 +55,20 @@ export function DuelCardFace({ card, size = 'hand', state = {}, onClick, label, .filter(Boolean).join(' '); if (size === 'zoom') return
-

{card.title}

{card.cost}
+

{card.title}

{card.cost}

{typeLine(card)}{card.portal}

- {card.keywords.length > 0 &&

{card.keywords.join('. ')}.

} + {card.keywords.length > 0 && !card.keywords.every(k => card.rulesText.includes(k)) &&

{card.keywords.join('. ')}.

} {card.rulesText &&

{card.rulesText}

} {card.flavour &&

{card.flavour}{card.url ? [{refNumber ?? 1}] : null}

}
-
+
{card.revisionId ? `rev. ${card.revisionId}` : card.token ? 'Token' : ''} -
+
; const kwShown = card.keywords.slice(0, 2); diff --git a/src/game/duel/DuelGate.tsx b/src/game/duel/DuelGate.tsx new file mode 100644 index 0000000..d797c7d --- /dev/null +++ b/src/game/duel/DuelGate.tsx @@ -0,0 +1,24 @@ +import { Pickaxe } from 'lucide-react'; +import { eligibility } from './model.ts'; +import './duel.css'; + +/** + * Shown instead of a board when the player doesn't own a full deck (BRIEF decisions 1–2). There is + * no practice with borrowed cards: the only way forward is mining (or trading) for real cards. + */ +export function DuelGate({ owned, deckSize, onMine, onExit }: { owned: number; deckSize: number; onMine?: () => void; onExit?: () => void }) { + const e = eligibility(owned, deckSize); + const pct = Math.round((Math.min(owned, deckSize) / deckSize) * 100); + return
+
DUEL · {deckSize}-CARD DECKS
+

{e.label}

+
+

A duel deck is exactly {deckSize} cards, and every one is an NFT you own. You need {e.needed} more. + Each block you mine is a new card: a random Wikipedia article, frozen with its stats at the moment it was mined. + Trades with other players count too. Matches never move or burn your cards.

+
+ {onExit && } + {onMine && } +
+
; +} diff --git a/src/game/duel/DuelPreview.tsx b/src/game/duel/DuelPreview.tsx index fc61650..46ab5d8 100644 --- a/src/game/duel/DuelPreview.tsx +++ b/src/game/duel/DuelPreview.tsx @@ -1,23 +1,27 @@ import { useState } from 'react'; +import { DuelCardFace } from './DuelCardFace.tsx'; import { DuelTable } from './DuelTable.tsx'; -import { previewView } from './mock.ts'; +import { PREVIEW_POOL, previewView } from './mock.ts'; import type { DuelUIAction } from './model.ts'; -type Scene = 'main' | 'attack' | 'block' | 'over'; -const SCENES: Scene[] = ['main', 'attack', 'block', 'over']; +type Scene = 'main' | 'attack' | 'block' | 'over' | 'cards'; +const SCENES: Scene[] = ['main', 'attack', 'block', 'over', 'cards']; +const ZOOM = ['Jess Harnell', 'Agda (programming language)', "April 2021 nor'easter", 'Pathrail Mosque', 'Hiroshima Electric Railway', 'Heart rot']; /** Static board scenes from card-sample.json, for screenshots and review (`#duel-preview/`). Not a match. */ export function DuelPreview() { const initial = (location.hash.split('/')[1] as Scene) || 'main'; const [scene, setScene] = useState(SCENES.includes(initial) ? initial : 'main'); const [acted, setActed] = useState([]); - const { view, legal } = previewView(scene); + const { view, legal } = previewView(scene === 'cards' ? 'main' : scene); const onAct = (a: DuelUIAction) => setActed(l => [...l, JSON.stringify(a)]); return
- `(preview) ${a}`)] }} legal={legal} onAct={onAct} /> + {scene === 'cards' ?
+ {ZOOM.map(t => PREVIEW_POOL.find(c => c.title === t)).filter(c => !!c).map((c, i) => )} +
: `(preview) ${a}`)] }} legal={legal} onAct={onAct} />}
; } diff --git a/src/game/duel/cards.ts b/src/game/duel/cards.ts new file mode 100644 index 0000000..c66911c --- /dev/null +++ b/src/game/duel/cards.ts @@ -0,0 +1,46 @@ +// DuelCard (duel-cards, shared/duel/derive.ts) → BoardCard. Declared structurally so this file doesn't +// depend on an unmerged branch; once shared/duel/derive.ts is on the integration branch, `DuelCardLike` +// can become `DuelCard` with no other change. +import type { BoardCard, DuelCardType, Portal } from './model.ts'; +import { firstSentence } from './model.ts'; + +export type DuelCardLike = { + cardId: string; pageId: number; revisionId: number; title: string; type: DuelCardType; subtype: string | null; + portal: Portal; cost: number; power: number | null; toughness: number | null; keywords: readonly string[]; + rulesText: string; flavor: string; +}; + +/** What the chain (not the derivation) knows about the card's article: art and link. */ +export type ArticleBits = { image?: string; url?: string; extract?: string }; + +export const articleUrl = (title: string) => `https://en.wikipedia.org/wiki/${encodeURIComponent(title.replace(/ /g, '_'))}`; + +const SUBTYPE_LABEL: Record = { + organisation: 'Organisation', work: 'Work', sport: 'Sport', election: 'Election', conflict: 'Conflict', disaster: 'Disaster', + period: 'Period', mathematics: 'Mathematics', pathology: 'Pathology', language: 'Language', ideology: 'Ideology', team: 'Team', vehicle: 'Vehicle', +}; +/** "(1909–1994)", "(born 1963)", "(c.1872–1919)" in the description → "1909–1994", "1963–", "1872–1919". */ +export function lifespan(text: string | undefined): string | undefined { + const m = text?.match(/\((?:c\.\s?)?(\d{3,4})\s?[–-]\s?(?:c\.\s?)?(\d{3,4})(?!\d)[^)]*\)|\(born (\d{3,4})\)/); + if (!m) return undefined; + return m[3] ? `${m[3]}–` : `${m[1]}–${m[2]}`; +} + +/** The part after the em dash: "History · 1530–1537", "Society · Election". */ +export function subtypeLine(card: Pick): string { + const extra = card.type === 'Figure' ? lifespan(card.flavor) : card.subtype ? SUBTYPE_LABEL[card.subtype] : undefined; + return extra ? `${card.portal} · ${extra}` : card.portal; +} + +export function boardCard(card: DuelCardLike, article: ArticleBits = {}, live: Partial = {}): BoardCard { + const power = card.power ?? undefined, toughness = card.toughness ?? undefined; + return { + id: card.cardId, title: card.title, type: card.type, + subtype: subtypeLine(card), + portal: card.portal, cost: card.cost, power, toughness, basePower: power, baseToughness: toughness, + keywords: [...card.keywords], rulesText: card.rulesText, + flavour: firstSentence(card.flavor || article.extract), + image: article.image, url: article.url ?? articleUrl(card.title), revisionId: card.revisionId, + ...live, + }; +} diff --git a/src/game/duel/duel.css b/src/game/duel/duel.css index 56b1407..5893869 100644 --- a/src/game/duel/duel.css +++ b/src/game/duel/duel.css @@ -25,6 +25,7 @@ /* Battlefields: one scrollable row per side; 5 cards fit 344 px without scrolling. */ .duel-row{display:grid;grid-auto-flow:column;grid-auto-columns:minmax(62px,1fr);gap:4px;overflow-x:auto;overscroll-behavior-x:contain;scrollbar-width:none;min-height:102px;padding:4px 0;align-items:start} +.duel-zoomgrid .dface-zoom{align-self:start} .duel-row::-webkit-scrollbar{display:none} .duel-row.theirs{align-items:end} .duel-slot{position:relative;display:flex;flex-direction:column;align-items:stretch;max-width:110px} diff --git a/tests/ui-duel-model.test.ts b/tests/ui-duel-model.test.ts index d83debe..286be5b 100644 --- a/tests/ui-duel-model.test.ts +++ b/tests/ui-duel-model.test.ts @@ -89,3 +89,20 @@ test('preview scenes: a full 5 + 5 board with every card from the real sample', assert.ok(c.cost >= 1 && c.cost <= 6, c.title); } }); + +test('DuelCard → board card: type line from real data only, flavour is one sentence', async () => { + const { boardCard, lifespan } = await import('../src/game/duel/cards.ts'); + assert.equal(lifespan('Sultan of Aceh (1530–1537/9)'), '1530–1537'); + assert.equal(lifespan('American voice actor and singer (born 1963)'), '1963–'); + assert.equal(lifespan('American botanist (c.1872–1919)'), '1872–1919'); + assert.equal(lifespan('Species of grasshopper'), undefined); + const c = boardCard({ cardId: 't', pageId: 1, revisionId: 9, title: 'Salahuddin of Aceh', type: 'Figure', subtype: null, portal: 'History', + cost: 4, power: 4, toughness: 3, keywords: ['Legacy'], rulesText: 'Legacy.', flavor: 'Sultan of Aceh (1530–1537/9). Second sentence.' }); + assert.equal(typeLine(c), 'Figure — History · 1530–1537'); + assert.equal(c.flavour, 'Sultan of Aceh (1530–1537/9).'); + assert.equal(c.url, 'https://en.wikipedia.org/wiki/Salahuddin_of_Aceh'); + const e = boardCard({ cardId: 'e', pageId: 2, revisionId: 9, title: '1954 Gold Coast general election', type: 'Event', subtype: 'election', portal: 'Society', + cost: 4, power: null, toughness: null, keywords: [], rulesText: 'x', flavor: '' }); + assert.equal(typeLine(e), 'Event — Society · Election'); + assert.equal(e.power, undefined); +});