shared/duel/classify.ts: Q-id anchors -> P31 label regex (^human$) -> P279 -> categories -> description -> Doctrine. shared/duel/derive.ts: pure derive(chain, profile) -> DuelCard: fame cost 1-6, P+T budget per cost, DUEL_DESIGN §4 keywords (<=2, Figures only, taxed), Portals, Connected keys and tiers, flavour. shared/duel/effects.ts + text.ts: T1-T12 templates as EffectSpec data, MTG-register rules text. shared/duel/sample.ts + docs/game/duel-card-sample.json: 236-card DuelCard fixture. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.7 KiB
TypeScript
33 lines
1.7 KiB
TypeScript
/**
|
|
* Writes docs/game/duel-card-sample.json (card-sample.json → DuelCard[]) and prints the
|
|
* type / Portal / cost / keyword distributions. Offline. Usage:
|
|
* node --experimental-strip-types scripts/duel-card-sample.ts [--check]
|
|
* --check exits non-zero if the committed fixture is out of date.
|
|
*/
|
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
import { deriveSample, type SampleCard } from '../shared/duel/sample.ts';
|
|
import { DERIVE_VERSION } from '../shared/duel/derive.ts';
|
|
|
|
const root = new URL('../', import.meta.url);
|
|
const sample = JSON.parse(readFileSync(new URL('docs/game/card-sample.json', root), 'utf8')) as { cards: SampleCard[] };
|
|
const cards = deriveSample(sample.cards);
|
|
const out = JSON.stringify({ source: 'docs/game/card-sample.json', deriveVersion: DERIVE_VERSION, count: cards.length, cards }, null, 1) + '\n';
|
|
const path = new URL('docs/game/duel-card-sample.json', root);
|
|
|
|
const tally = (f: (c: typeof cards[number]) => string | number) => {
|
|
const m = new Map<string | number, number>();
|
|
for (const c of cards) m.set(f(c), (m.get(f(c)) ?? 0) + 1);
|
|
return [...m].sort((a, b) => String(a[0]).localeCompare(String(b[0]), 'en', { numeric: true }))
|
|
.map(([k, v]) => `${k} ${v} (${(100 * v / cards.length).toFixed(1)}%)`).join(', ');
|
|
};
|
|
console.log('type:', tally(c => c.type));
|
|
console.log('typedBy:', tally(c => c.typedBy));
|
|
console.log('portal:', tally(c => c.portal));
|
|
console.log('cost:', tally(c => c.cost));
|
|
console.log('subtype:', tally(c => `${c.type}/${c.subtype ?? '-'}`));
|
|
console.log('keywords:', tally(c => c.keywords.join('+') || 'none'));
|
|
|
|
if (process.argv.includes('--check')) {
|
|
if (readFileSync(path, 'utf8') !== out) { console.error('duel-card-sample.json is stale'); process.exit(1); }
|
|
} else writeFileSync(path, out);
|