ui-duel: eligibility gate, DuelCard to board card mapping, zoom face fixes (#58)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 21:46:26 -05:00
co-authored by Claude Opus 5.5
parent 5a7cfba124
commit 2fe16a66c8
6 changed files with 101 additions and 9 deletions
+4 -4
View File
@@ -55,20 +55,20 @@ export function DuelCardFace({ card, size = 'hand', state = {}, onClick, label,
.filter(Boolean).join(' ');
if (size === 'zoom') return <article className={cls} aria-label={cardSummary(card)}>
<header className="dface-namebar"><h3 className="dface-name">{card.title}</h3><span className="dface-cost" aria-label={`Cost ${card.cost} Citations`}>{card.cost}</span></header>
<div className="dface-namebar"><h3 className="dface-name">{card.title}</h3><span className="dface-cost" aria-label={`Cost ${card.cost} Citations`}>{card.cost}</span></div>
<Art card={card} iconSize={34} />
<p className="dface-typeline"><TypeIcon type={card.type} size={13} /> {typeLine(card)}<span className="dface-portal">{card.portal}</span></p>
<div className="dface-textbox">
{card.keywords.length > 0 && <p className="dface-keywords">{card.keywords.join('. ')}.</p>}
{card.keywords.length > 0 && !card.keywords.every(k => card.rulesText.includes(k)) && <p className="dface-keywords">{card.keywords.join('. ')}.</p>}
{card.rulesText && <p className="dface-rules">{card.rulesText}</p>}
{card.flavour && <p className="dface-flavour">{card.flavour}{card.url
? <sup><a href={card.url} target="_blank" rel="noopener noreferrer" aria-label={`Wikipedia article: ${card.title}`}>[{refNumber ?? 1}]</a></sup>
: null}</p>}
</div>
<footer className="dface-footer">
<div className="dface-footer">
<span className="dface-rev">{card.revisionId ? `rev. ${card.revisionId}` : card.token ? 'Token' : ''}</span>
<Stats card={card} />
</footer>
</div>
</article>;
const kwShown = card.keywords.slice(0, 2);
+24
View File
@@ -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 <section className="duel-gate" aria-labelledby="duel-gate-title">
<div className="section-eyebrow">DUEL · {deckSize}-CARD DECKS</div>
<h2 id="duel-gate-title">{e.label}</h2>
<div className="duel-gate-bar" role="progressbar" aria-valuemin={0} aria-valuemax={deckSize} aria-valuenow={Math.min(owned, deckSize)} aria-label="Cards owned"><i style={{ width: `${pct}%` }} /></div>
<p className="muted">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.</p>
<div className="play-actions">
{onExit && <button className="button outline" onClick={onExit}>Back</button>}
{onMine && <button className="button dark" onClick={onMine}><Pickaxe size={16} /> Mine cards</button>}
</div>
</section>;
}
+9 -5
View File
@@ -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/<scene>`). Not a match. */
export function DuelPreview() {
const initial = (location.hash.split('/')[1] as Scene) || 'main';
const [scene, setScene] = useState<Scene>(SCENES.includes(initial) ? initial : 'main');
const [acted, setActed] = useState<string[]>([]);
const { view, legal } = previewView(scene);
const { view, legal } = previewView(scene === 'cards' ? 'main' : scene);
const onAct = (a: DuelUIAction) => setActed(l => [...l, JSON.stringify(a)]);
return <div className="duel-preview-page" style={{ padding: 0 }}>
<nav className="category-tabs" aria-label="Preview scene" style={{ padding: '4px 8px', display: location.hash.includes('clean') ? 'none' : undefined }}>
{SCENES.map(s => <button key={s} className={s === scene ? 'selected' : ''} onClick={() => { setScene(s); location.hash = `duel-preview/${s}`; }}>{s}</button>)}
{acted.length > 0 && <small style={{ marginLeft: 8 }}>last action: {acted.at(-1)}</small>}
</nav>
<DuelTable key={scene} view={{ ...view, log: [...view.log, ...acted.map(a => `(preview) ${a}`)] }} legal={legal} onAct={onAct} />
{scene === 'cards' ? <div className="duel" style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill,minmax(280px,1fr))', gap: 16, padding: 12 }}>
{ZOOM.map(t => PREVIEW_POOL.find(c => c.title === t)).filter(c => !!c).map((c, i) => <DuelCardFace key={c.id} card={c} size="zoom" refNumber={i + 1} />)}
</div> : <DuelTable key={scene} view={{ ...view, log: [...view.log, ...acted.map(a => `(preview) ${a}`)] }} legal={legal} onAct={onAct} />}
</div>;
}
+46
View File
@@ -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<string, string> = {
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<DuelCardLike, 'type' | 'subtype' | 'portal' | 'flavor'>): 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> = {}): 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,
};
}
+1
View File
@@ -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}
+17
View File
@@ -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);
});