Exact source used by this build. SHA-256: 17c9185f089e81745863bbf9bbe555c98128fbe640d019f4fdd079b891570c8b.
1 import json from "../../../data/forage/tables.json";
2 import { ITEMS } from "../items";
3 import { AREA_MAPS } from "../maps";
4 import { ForageTableSchema } from "./schema";
5 import type { ContentDomain } from "../types";
6 export * from "./schema";
7 export const FORAGE_TABLES = ForageTableSchema.array().parse(json);
8 export function validateForageReferences(value: unknown, itemIds: readonly string[], items: readonly { id: string; category: string }[] = ITEMS): void {
9 const tables = ForageTableSchema.array().parse(value), ids = new Set(itemIds);
10 if (new Set(tables.map((table) => `${table.areaId}:${table.season}`)).size !== tables.length) throw new Error("Duplicate area/season forage table");
11 for (const table of tables) {
12 const area = AREA_MAPS[table.areaId];
13 if (!area) throw new Error(`Forage table references missing area ${table.areaId}`);
14 if (!area.outdoor) throw new Error(`Forage table area ${table.areaId} must be outdoors`);
15 for (const entry of table.entries) {
16 if (!ids.has(entry.itemId)) throw new Error(`Forage table references missing item ${entry.itemId}`);
17 if (items.find((item) => item.id === entry.itemId)?.category !== "forage") throw new Error(`Forage table item ${entry.itemId} must have forage category`);
18 }
19 }
20 }
21 export const forageDomain: ContentDomain = { id: "forage", data: FORAGE_TABLES, validate() { validateForageReferences(json, ITEMS.map((item) => item.id)); } };
22 forageDomain.validate();
23