- Introduced contentHelpers for table and room template lookups. - Created level1Rooms.ts with various room templates for level 1. - Added level1Tables.ts containing encounter tables for animals, martial, dogs, people, fungal, guards, workers, and room types. - Implemented room generation functions in rooms.ts to create rooms based on templates and tables. - Added tests for room generation logic in rooms.test.ts to ensure correct functionality.
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import type { ContentPack, RoomTemplate, TableDefinition } from "@/types/content";
|
|
import type { TableLookupResult } from "@/rules/tables";
|
|
|
|
export function findTableByCode(content: ContentPack, code: string): TableDefinition {
|
|
const table = content.tables.find((entry) => entry.code === code);
|
|
|
|
if (!table) {
|
|
throw new Error(`Unknown table code: ${code}`);
|
|
}
|
|
|
|
return table;
|
|
}
|
|
|
|
export function findRoomTemplateById(
|
|
content: ContentPack,
|
|
roomTemplateId: string,
|
|
): RoomTemplate {
|
|
const roomTemplate = content.roomTemplates.find((entry) => entry.id === roomTemplateId);
|
|
|
|
if (!roomTemplate) {
|
|
throw new Error(`Unknown room template id: ${roomTemplateId}`);
|
|
}
|
|
|
|
return roomTemplate;
|
|
}
|
|
|
|
export function findRoomTemplateForLookup(
|
|
content: ContentPack,
|
|
lookup: TableLookupResult,
|
|
): RoomTemplate {
|
|
const roomReference = lookup.entry.references?.find((reference) => reference.type === "room");
|
|
|
|
if (!roomReference) {
|
|
throw new Error(`Lookup result ${lookup.tableId}:${lookup.entryKey} does not point to a room.`);
|
|
}
|
|
|
|
return findRoomTemplateById(content, roomReference.id);
|
|
}
|