forked from phenom/healer-man
Release Healer Man 0.1.7
This commit is contained in:
1 parent
b12fb84859
commit
eca6b5db9b
99 files changed
+1931
-150
No files matched your search
@@ -0,0 +1,36 @@
|
||||
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<Record<number, AbilityDefinition>>;
|
||||
}
|
||||
|
||||
interface CoaAbilityCatalogShardModule {
|
||||
readonly default: CoaAbilityCatalogShard;
|
||||
}
|
||||
|
||||
const shardLoaders = import.meta.glob<CoaAbilityCatalogShardModule>("./generated/coaAbilities/*.json");
|
||||
const loadCache = new Map<CoaClassId, Promise<CoaAbilityCatalogShard>>();
|
||||
|
||||
export function loadCoaAbilityCatalogShard(classId: CoaClassId): Promise<CoaAbilityCatalogShard> {
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user