Exact source used by this build. SHA-256: d2b8890bafc554b6ee9ec6e28cb8b8552c08ab2d4cea04b10f36e637c7cd17ec.

1 import json from "../../../data/shops/shops.json";
2 import { ITEMS } from "../items";
3 import { AREA_MAPS, isMapBlocked } from "../maps";
4 import { ShopSchema } from "./schema";
5 import type { ContentDomain } from "../types";
6 export * from "./schema";
7 export const SHOPS = ShopSchema.array().parse(json);
8 export function validateShopReferences(value: unknown, itemIds: readonly string[]): void {
9   const shops = ShopSchema.array().parse(value), ids = new Set(itemIds);
10   if (new Set(shops.map((shop) => shop.id)).size !== shops.length) throw new Error("Shop ids must be unique");
11   for (const shop of shops) {
12     const area = AREA_MAPS[shop.areaId];
13     if (!area) throw new Error(`Shop ${shop.id} references missing area ${shop.areaId}`);
14     if (shop.x >= area.width || shop.y >= area.height || isMapBlocked(area, shop.x, shop.y)) throw new Error(`Shop ${shop.id} must be on an accessible tile`);
15     if (area.warps.some((warp) => shop.x >= warp.x && shop.x < warp.x + warp.width && shop.y >= warp.y && shop.y < warp.y + warp.height)) throw new Error(`Shop ${shop.id} overlaps a warp`);
16     if (new Set(shop.stock.map((stock) => stock.id)).size !== shop.stock.length) throw new Error(`Duplicate stock id in ${shop.id}`);
17     for (const stock of shop.stock) if (!ids.has(stock.itemId)) throw new Error(`Shop ${shop.id} references missing item ${stock.itemId}`);
18   }
19 }
20 export const shopsDomain: ContentDomain = { id: "shops", data: SHOPS, validate() { validateShopReferences(json, ITEMS.map((item) => item.id)); } };
21 shopsDomain.validate();
22