import type { CoaClassId } from "../app/characterCatalog"; import type { AbilityDefinition, ClassResourceProfile } from "./abilityCatalog"; export interface CoaAbilityCatalogShard { readonly schemaVersion: 1; readonly classId: CoaClassId; readonly abilities: readonly AbilityDefinition[]; readonly resource: ClassResourceProfile; readonly triggeredAbilitiesBySpellId: Readonly>; } interface CoaAbilityCatalogShardModule { readonly default: CoaAbilityCatalogShard; } const shardLoaders = import.meta.glob("./generated/coaAbilities/*.json"); const loadCache = new Map>(); export function loadCoaAbilityCatalogShard(classId: CoaClassId): Promise { const cached = loadCache.get(classId); if (cached) return cached; const key = `./generated/coaAbilities/${classId}.json`; const loader = shardLoaders[key]; if (!loader) return Promise.reject(new Error(`No Conquest ability catalog exists for ${classId}.`)); const pending = loader().then((module) => { if (module.default.schemaVersion !== 1 || module.default.classId !== classId) { throw new Error(`Conquest ability catalog ${classId} has incompatible metadata.`); } return module.default; }).catch((error: unknown) => { loadCache.delete(classId); throw error; }); loadCache.set(classId, pending); return pending; }