Feature: add creature lookup functionality and combat state management

This commit is contained in:
Keith Solomon
2026-03-15 13:35:13 -05:00
parent 4dde4bff99
commit ec0de5b0b8
5 changed files with 359 additions and 2 deletions

View File

@@ -1,4 +1,9 @@
import type { ContentPack, RoomTemplate, TableDefinition } from "@/types/content";
import type {
ContentPack,
CreatureDefinition,
RoomTemplate,
TableDefinition,
} from "@/types/content";
import type { TableLookupResult } from "@/rules/tables";
export function findTableByCode(content: ContentPack, code: string): TableDefinition {
@@ -36,3 +41,23 @@ export function findRoomTemplateForLookup(
return findRoomTemplateById(content, roomReference.id);
}
function normalizeName(value: string) {
return value.trim().toLowerCase().replace(/\s+/g, " ");
}
export function findCreatureByName(
content: ContentPack,
creatureName: string,
): CreatureDefinition {
const normalizedTarget = normalizeName(creatureName);
const creature = content.creatures.find(
(entry) => normalizeName(entry.name) === normalizedTarget,
);
if (!creature) {
throw new Error(`Unknown creature name: ${creatureName}`);
}
return creature;
}