✨Feature: add creature lookup functionality and combat state management
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user