36 lines
1.4 KiB
JavaScript
36 lines
1.4 KiB
JavaScript
import dungeonCatalog from "../src/game/generated/dungeonLeaderboardCatalog.generated.json" with { type: "json" };
|
|
|
|
const knownIds = new Set(dungeonCatalog.dungeons.map((dungeon) => dungeon.id));
|
|
const modes = ["regular", "biteSized", "randomizedBiteSized"];
|
|
|
|
export const DEFAULT_DUNGEON_QUEUE_POLICY = Object.freeze({
|
|
schemaVersion: 1,
|
|
disabled: { regular: [], biteSized: [], randomizedBiteSized: [] },
|
|
});
|
|
|
|
function modeForId(id) {
|
|
if (id.startsWith("randomized-bite-sized-")) return "randomizedBiteSized";
|
|
if (id.startsWith("bite-sized-")) return "biteSized";
|
|
return "regular";
|
|
}
|
|
|
|
export function normalizeDungeonQueuePolicy(value) {
|
|
if (!value || typeof value !== "object" || Array.isArray(value) || value.schemaVersion !== 1
|
|
|| !value.disabled || typeof value.disabled !== "object" || Array.isArray(value.disabled)) {
|
|
throw new Error("A version 1 dungeon queue policy is required.");
|
|
}
|
|
if (Object.keys(value.disabled).some((mode) => !modes.includes(mode))) {
|
|
throw new Error("Unknown dungeon queue mode.");
|
|
}
|
|
const disabled = {};
|
|
for (const mode of modes) {
|
|
const ids = value.disabled[mode];
|
|
if (!Array.isArray(ids) || ids.some((id) => typeof id !== "string" || !knownIds.has(id) || modeForId(id) !== mode)
|
|
|| new Set(ids).size !== ids.length) {
|
|
throw new Error(`Invalid disabled dungeon IDs for ${mode}.`);
|
|
}
|
|
disabled[mode] = [...ids].sort();
|
|
}
|
|
return { schemaVersion: 1, disabled };
|
|
}
|