diff options
Diffstat (limited to 'web/src/lib/data/classInfo.ts')
| -rw-r--r-- | web/src/lib/data/classInfo.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/web/src/lib/data/classInfo.ts b/web/src/lib/data/classInfo.ts new file mode 100644 index 0000000..6bbded0 --- /dev/null +++ b/web/src/lib/data/classInfo.ts @@ -0,0 +1,29 @@ +/** + * Class-metadata lookup for the rows: art, colour, per-level health. Loaded + * from the campaign edition JSON (via the shared `gameData` client) and + * cached per class. + */ + +import { gameData, type ClassData } from './gameData'; + +export type { ClassData }; + +const cache = new Map<string, Promise<ClassData | null>>(); + +export function classInfo(edition: string, className: string): Promise<ClassData | null> { + const key = `${edition}/${className}`; + let promise = cache.get(key); + if (!promise) { + promise = gameData + .loadCampaign(edition) + .then((c) => c.classes.find((x) => x.id === className) ?? null) + .catch(() => null); + cache.set(key, promise); + } + return promise; +} + +/** True for the Escort / Objective classes (no initiative input). */ +export function isObjectiveOrEscort(className: string): boolean { + return className === 'Escort' || className === 'Objective'; +} |
