import { contentPackHasUpdate, contentPackIsUsable, installContentForLogicalUrls, installContentPack, } from "../content/contentManager"; import { RANDOMIZED_BITE_SIZED_STOCKADES_DUNGEON_ID, dungeonContentPackId, } from "../game/dungeonContentSource"; import { biteSizedDefinitionForSelection } from "../game/dungeonRegistry"; import { preparedBiteSizedRunSelection, prepareBiteSizedLayoutContent } from "./biteSizedLayoutContent"; import { selectBiteSizedRun } from "../../shared/bite-sized-layouts.mjs"; import { useBiteSizedLayoutsStore } from "../game/biteSizedLayoutsStore"; export function randomizedBiteSizedModelUrls(seed: string, dungeonId = RANDOMIZED_BITE_SIZED_STOCKADES_DUNGEON_ID): readonly string[] { const selection = preparedBiteSizedRunSelection(dungeonId, seed) ?? selectBiteSizedRun(useBiteSizedLayoutsStore.getState().config, dungeonId, seed); const definition = biteSizedDefinitionForSelection(selection, 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; readonly installUrls: (urls: readonly string[]) => Promise; 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, dungeonId = RANDOMIZED_BITE_SIZED_STOCKADES_DUNGEON_ID, ): Promise { if (dependencies === DEFAULT_DEPENDENCIES) { await prepareBiteSizedLayoutContent(dungeonId, seed); return; } if (dependencies.development) return; const basePackId = dungeonContentPackId(dungeonId); if (!dependencies.packIsUsable(basePackId) || dependencies.packHasUpdate(basePackId)) { await dependencies.installPack(basePackId); } await dependencies.installUrls(randomizedBiteSizedModelUrls(seed, dungeonId)); }