48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
import {
|
|
contentPackHasUpdate,
|
|
contentPackIsUsable,
|
|
installContentForLogicalUrls,
|
|
installContentPack,
|
|
} from "../content/contentManager";
|
|
import {
|
|
RANDOMIZED_BITE_SIZED_STOCKADES_DUNGEON_ID,
|
|
dungeonContentPackId,
|
|
} from "../game/dungeonContentSource";
|
|
import { randomizedBiteSizedDefinitionForSeed } from "../game/dungeonRegistry";
|
|
|
|
export function randomizedBiteSizedModelUrls(seed: string): readonly string[] {
|
|
const definition = randomizedBiteSizedDefinitionForSeed(seed);
|
|
return [...new Set(Object.values(definition.entities).flatMap((entity) => (
|
|
entity.visual.model?.url ? [entity.visual.model.url] : []
|
|
)))].sort();
|
|
}
|
|
|
|
interface RandomizedContentDependencies {
|
|
readonly development: boolean;
|
|
readonly installPack: (packId: string) => Promise<void>;
|
|
readonly installUrls: (urls: readonly string[]) => Promise<void>;
|
|
readonly packIsUsable: (packId: string) => boolean;
|
|
readonly packHasUpdate: (packId: string) => boolean;
|
|
}
|
|
|
|
const DEFAULT_DEPENDENCIES: RandomizedContentDependencies = {
|
|
development: import.meta.env.DEV,
|
|
installPack: installContentPack,
|
|
installUrls: installContentForLogicalUrls,
|
|
packIsUsable: contentPackIsUsable,
|
|
packHasUpdate: contentPackHasUpdate,
|
|
};
|
|
|
|
/** Downloads the rolled location and creature packs before the seeded run enters gameplay. */
|
|
export async function ensureRandomizedBiteSizedRunContent(
|
|
seed: string,
|
|
dependencies: RandomizedContentDependencies = DEFAULT_DEPENDENCIES,
|
|
): Promise<void> {
|
|
if (dependencies.development) return;
|
|
const basePackId = dungeonContentPackId(RANDOMIZED_BITE_SIZED_STOCKADES_DUNGEON_ID);
|
|
if (!dependencies.packIsUsable(basePackId) || dependencies.packHasUpdate(basePackId)) {
|
|
await dependencies.installPack(basePackId);
|
|
}
|
|
await dependencies.installUrls(randomizedBiteSizedModelUrls(seed));
|
|
}
|