import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { parseCsvObjects } from './csv.ts'; export type CardKind = 'avatar' | 'server' | 'program' | 'hardware' | 'execution'; export interface CardDef { name: string; kind: CardKind; /** Printed RAM: play cost and salvage value. Avatars and Servers print none. */ ram: number; cores: number; /** Expansion Slots (Hardware ports). */ slots: number; /** V / B / G / P, when printed. */ type: string; /** Card text; flavor text for Avatars. */ text: string; ability?: { name: string; cost: number; text: string }; } export interface CardPool { all: CardDef[]; byName: Map; } const KIND_BY_TEMPLATE: Record = { 'Avatar Front': 'avatar', 'Server Front': 'server', 'Server Front Alt': 'server', 'Program Front': 'program', 'Hardware Front': 'hardware', 'Execution Front': 'execution', }; export const DEFAULT_CARDS_CSV = fileURLToPath( new URL('../../decks/files-deck-1/cards.csv', import.meta.url), ); const num = (s: string | undefined): number => (s ? Number(s) : 0); /** Loads the Cider deck CSV. Reference cards (Turn Sequence) are skipped. */ export function loadCards(path = DEFAULT_CARDS_CSV): CardPool { const all: CardDef[] = []; const byName = new Map(); for (const row of parseCsvObjects(readFileSync(path, 'utf8'))) { const kind = KIND_BY_TEMPLATE[row['Front Template']]; if (!kind) continue; const card: CardDef = { name: row['Name'], kind, ram: num(row['RAM']), cores: num(row['Cores']), slots: num(row['Expansion Slots']), type: row['Type'], text: row['Description'], }; if (row['Ability Name']) { card.ability = { name: row['Ability Name'], cost: num(row['Ability Cost']), text: row['Ability Description'], }; } if (byName.has(card.name)) throw new Error(`Duplicate card name in ${path}: ${card.name}`); all.push(card); byName.set(card.name, card); } return { all, byName }; }