diff options
Diffstat (limited to 'web/src/lib/data/gameData.ts')
| -rw-r--r-- | web/src/lib/data/gameData.ts | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/web/src/lib/data/gameData.ts b/web/src/lib/data/gameData.ts index 10e1c60..5925b65 100644 --- a/web/src/lib/data/gameData.ts +++ b/web/src/lib/data/gameData.ts @@ -12,6 +12,17 @@ import type { // --- Raw JSON shapes (the subset the UI needs) ---------------------------- +/** One summon of a character class (the reference `SummonModel`). */ +interface RawSummon { + level?: number; + gfx?: string; + health?: number; + move?: number; + attack?: number; + range?: number; + standees?: number; +} + interface RawClass { name: string; edition: string; @@ -22,6 +33,13 @@ interface RawClass { /** `adds`/`removes` per perk slot (the reference `PerkModel`). */ perks?: { text?: string; adds?: string[]; removes?: string[] }[]; perksFH?: { text?: string; adds?: string[]; removes?: string[] }[]; + /** Summon models, keyed by name (the reference `summons`). */ + summons?: Record<string, RawSummon>; +} + +/** The generic item summons (`summons.json`). */ +interface RawSummonsFile { + summons: Record<string, RawSummon>; } interface RawMonsterStats { @@ -82,6 +100,8 @@ export interface ClassData { /** The full perk-slot data (text + adds + removes) for the perks menu. */ perkDetails: PerkDetail[]; perkDetailsFH: PerkDetail[]; + /** The class's summonable figures. */ + summons: SummonModel[]; } /** One perk slot (the reference `PerkModel`). */ @@ -91,6 +111,22 @@ export interface PerkDetail { removes: string[]; } +/** + * A summonable figure (the reference `SummonModel`). `gfx` is empty for + * class summons without fixed art (a colour standee is chosen in the menu); + * item summons carry their own artwork name. + */ +export interface SummonModel { + name: string; + level: number; + standees: number; + health: number; + move: number; + attack: number; + range: number; + gfx: string; +} + export interface MonsterData { name: string; display: string; @@ -188,6 +224,38 @@ export class GameDataClient { constructor(private readonly base = '/data') {} + private summonsPromise: Promise<SummonModel[]> | null = null; + + /** + * The generic item summons (the reference `itemSummonData`, from + * `summons.json`): summonable figures independent of any class. + */ + summons(): Promise<SummonModel[]> { + if (this.summonsPromise) return this.summonsPromise; + this.summonsPromise = fetch(`${this.base}/summons.json`) + .then((r) => (r.ok ? r.json() : null)) + .then((raw: RawSummonsFile | null) => + Object.entries(raw?.summons ?? {}).map(([name, s]) => + this.toSummon(name, s) + ) + ) + .catch(() => [] as SummonModel[]); + return this.summonsPromise; + } + + private toSummon(name: string, s: RawSummon): SummonModel { + return { + name, + level: s.level ?? 0, + standees: s.standees ?? 1, + health: typeof s.health === 'string' ? Number(s.health) || 2 : s.health ?? 2, + move: s.move ?? 0, + attack: s.attack ?? 0, + range: s.range ?? 0, + gfx: s.gfx ?? '' + }; + } + /** The list of campaign/edition names (order from `editions.json`). */ campaigns(): Promise<string[]> { if (this.campaignsCache) return Promise.resolve(this.campaignsCache); @@ -331,7 +399,10 @@ export class GameDataClient { perks: (c.perks ?? []).map((p) => p.adds ?? []), perksFH: (c.perksFH ?? []).map((p) => p.adds ?? []), perkDetails: toDetails(c.perks), - perkDetailsFH: toDetails(c.perksFH) + perkDetailsFH: toDetails(c.perksFH), + summons: Object.entries(c.summons ?? {}).map(([name, s]) => + this.toSummon(name, s) + ) }; } |
