diff --git a/.gitignore b/.gitignore index 6a6c6fc..51fa152 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ lerna-debug.log* node_modules dist dist-ssr +.vite *.local # Editor directories and files diff --git a/src/core/cards/card-library.ts b/src/core/cards/card-library.ts index 8449ed7..3043124 100644 --- a/src/core/cards/card-library.ts +++ b/src/core/cards/card-library.ts @@ -1,82 +1,21 @@ import type { CardData } from './card.types'; +import { ALL_CARDS } from './definitions'; /** - * Central card library. All card definitions live here, keyed by id. - * Content is data — add cards by adding entries, not code paths. + * Central card library. Card *definitions* live one-per-file under ./definitions + * and are registered in ./definitions/index.ts; this module indexes them by id. + * Content is data — add cards by adding a file, not by editing code paths here. */ -export const CARD_LIBRARY: Record = { - strike: { - id: 'strike', - name: 'Strike', - type: 'attack', - rarity: 'starter', - cost: 1, - target: 'enemy', - description: 'Deal 6 damage.', - effect: { damage: 6 }, - }, - defend: { - id: 'defend', - name: 'Defend', - type: 'skill', - rarity: 'starter', - cost: 1, - target: 'self', - description: 'Gain 5 block.', - effect: { block: 5 }, - }, - bash: { - id: 'bash', - name: 'Bash', - type: 'attack', - rarity: 'starter', - cost: 2, - target: 'enemy', - description: 'Deal 10 damage.', - effect: { damage: 10 }, - }, - quick_slash: { - id: 'quick_slash', - name: 'Quick Slash', - type: 'attack', - rarity: 'common', - cost: 1, - target: 'enemy', - description: 'Deal 4 damage. Draw 1 card.', - effect: { damage: 4, draw: 1 }, - }, - cleave: { - id: 'cleave', - name: 'Cleave', - type: 'attack', - rarity: 'common', - cost: 1, - target: 'all-enemies', - description: 'Deal 8 damage to ALL enemies.', - effect: { damage: 8 }, - }, - flurry: { - id: 'flurry', - name: 'Flurry', - type: 'attack', - rarity: 'uncommon', - cost: 1, - target: 'enemy', - description: 'Deal 3 damage 3 times.', - effect: { damage: 3, hits: 3 }, - }, - adrenaline: { - id: 'adrenaline', - name: 'Adrenaline', - type: 'skill', - rarity: 'uncommon', - cost: 0, - target: 'none', - description: 'Gain 1 energy. Draw 2 cards. Exhaust.', - effect: { energy: 1, draw: 2 }, - exhaust: true, - }, -}; +export const CARD_LIBRARY: Record = buildLibrary(); + +function buildLibrary(): Record { + const library: Record = {}; + for (const card of ALL_CARDS) { + if (library[card.id]) throw new Error(`Duplicate card id: ${card.id}`); + library[card.id] = card; + } + return library; +} /** Look up a card definition by id; throws early on typos rather than failing silently. */ export function getCard(id: string): CardData { diff --git a/src/core/cards/definitions/adrenaline.ts b/src/core/cards/definitions/adrenaline.ts new file mode 100644 index 0000000..f93d1db --- /dev/null +++ b/src/core/cards/definitions/adrenaline.ts @@ -0,0 +1,13 @@ +import type { CardData } from '../card.types'; + +export const adrenaline: CardData = { + id: 'adrenaline', + name: 'Adrenaline', + type: 'skill', + rarity: 'uncommon', + cost: 0, + target: 'none', + description: 'Gain 1 energy. Draw 2 cards. Exhaust.', + effect: { energy: 1, draw: 2 }, + exhaust: true, +}; diff --git a/src/core/cards/definitions/bash.ts b/src/core/cards/definitions/bash.ts new file mode 100644 index 0000000..050b3cc --- /dev/null +++ b/src/core/cards/definitions/bash.ts @@ -0,0 +1,12 @@ +import type { CardData } from '../card.types'; + +export const bash: CardData = { + id: 'bash', + name: 'Bash', + type: 'attack', + rarity: 'starter', + cost: 2, + target: 'enemy', + description: 'Deal 10 damage.', + effect: { damage: 10 }, +}; diff --git a/src/core/cards/definitions/cleave.ts b/src/core/cards/definitions/cleave.ts new file mode 100644 index 0000000..5156070 --- /dev/null +++ b/src/core/cards/definitions/cleave.ts @@ -0,0 +1,12 @@ +import type { CardData } from '../card.types'; + +export const cleave: CardData = { + id: 'cleave', + name: 'Cleave', + type: 'attack', + rarity: 'common', + cost: 1, + target: 'all-enemies', + description: 'Deal 8 damage to ALL enemies.', + effect: { damage: 8 }, +}; diff --git a/src/core/cards/definitions/defend.ts b/src/core/cards/definitions/defend.ts new file mode 100644 index 0000000..8e246bb --- /dev/null +++ b/src/core/cards/definitions/defend.ts @@ -0,0 +1,12 @@ +import type { CardData } from '../card.types'; + +export const defend: CardData = { + id: 'defend', + name: 'Defend', + type: 'skill', + rarity: 'starter', + cost: 1, + target: 'self', + description: 'Gain 5 block.', + effect: { block: 5 }, +}; diff --git a/src/core/cards/definitions/flurry.ts b/src/core/cards/definitions/flurry.ts new file mode 100644 index 0000000..1bbf399 --- /dev/null +++ b/src/core/cards/definitions/flurry.ts @@ -0,0 +1,12 @@ +import type { CardData } from '../card.types'; + +export const flurry: CardData = { + id: 'flurry', + name: 'Flurry', + type: 'attack', + rarity: 'uncommon', + cost: 1, + target: 'enemy', + description: 'Deal 3 damage 3 times.', + effect: { damage: 3, hits: 3 }, +}; diff --git a/src/core/cards/definitions/index.ts b/src/core/cards/definitions/index.ts new file mode 100644 index 0000000..d97cc0d --- /dev/null +++ b/src/core/cards/definitions/index.ts @@ -0,0 +1,24 @@ +import type { CardData } from '../card.types'; + +import { strike } from './strike'; +import { defend } from './defend'; +import { bash } from './bash'; +import { quickSlash } from './quick-slash'; +import { cleave } from './cleave'; +import { flurry } from './flurry'; +import { adrenaline } from './adrenaline'; + +/** + * Card manifest. Every card definition is registered here exactly once. + * Adding a card = create ./.ts, then add one import + one array entry. + * The library (card-library.ts) keys these by id and enforces uniqueness. + */ +export const ALL_CARDS: readonly CardData[] = [ + strike, + defend, + bash, + quickSlash, + cleave, + flurry, + adrenaline, +]; diff --git a/src/core/cards/definitions/quick-slash.ts b/src/core/cards/definitions/quick-slash.ts new file mode 100644 index 0000000..802fcd4 --- /dev/null +++ b/src/core/cards/definitions/quick-slash.ts @@ -0,0 +1,12 @@ +import type { CardData } from '../card.types'; + +export const quickSlash: CardData = { + id: 'quick_slash', + name: 'Quick Slash', + type: 'attack', + rarity: 'common', + cost: 1, + target: 'enemy', + description: 'Deal 4 damage. Draw 1 card.', + effect: { damage: 4, draw: 1 }, +}; diff --git a/src/core/cards/definitions/strike.ts b/src/core/cards/definitions/strike.ts new file mode 100644 index 0000000..eb8fa29 --- /dev/null +++ b/src/core/cards/definitions/strike.ts @@ -0,0 +1,12 @@ +import type { CardData } from '../card.types'; + +export const strike: CardData = { + id: 'strike', + name: 'Strike', + type: 'attack', + rarity: 'starter', + cost: 1, + target: 'enemy', + description: 'Deal 6 damage.', + effect: { damage: 6 }, +};