✨Feature: add level 1 content including room templates, encounter tables, and room generation logic
- 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.
This commit is contained in:
91
src/rules/rooms.test.ts
Normal file
91
src/rules/rooms.test.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { sampleContentPack } from "@/data/sampleContentPack";
|
||||
|
||||
import {
|
||||
createLevelShell,
|
||||
createRoomStateFromTemplate,
|
||||
generateLevel1StartRoom,
|
||||
generateRoomFromTable,
|
||||
} from "./rooms";
|
||||
|
||||
function createSequenceRoller(values: number[]) {
|
||||
let index = 0;
|
||||
|
||||
return () => {
|
||||
const next = values[index];
|
||||
index += 1;
|
||||
return next;
|
||||
};
|
||||
}
|
||||
|
||||
describe("room generation", () => {
|
||||
it("creates the level 1 start room from its template", () => {
|
||||
const result = generateLevel1StartRoom(sampleContentPack);
|
||||
|
||||
expect(result.templateSource).toBe("direct-template");
|
||||
expect(result.room.roomClass).toBe("start");
|
||||
expect(result.room.position).toEqual({ x: 0, y: 0 });
|
||||
expect(result.room.exits).toHaveLength(1);
|
||||
expect(result.room.exits[0]?.direction).toBe("north");
|
||||
});
|
||||
|
||||
it("generates a small room from the encoded small-room table", () => {
|
||||
const result = generateRoomFromTable({
|
||||
content: sampleContentPack,
|
||||
roomId: "room.level1.small.001",
|
||||
level: 1,
|
||||
roomTableCode: "L1SR",
|
||||
position: { x: 2, y: 1 },
|
||||
roller: createSequenceRoller([5, 5]),
|
||||
});
|
||||
|
||||
expect(result.lookup?.roll.total).toBe(10);
|
||||
expect(result.room.templateId).toBe("room.level1.small.heated-space");
|
||||
expect(result.room.dimensions).toEqual({ width: 2, height: 3 });
|
||||
expect(result.room.exits).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("generates a large room from the encoded large-room table", () => {
|
||||
const result = generateRoomFromTable({
|
||||
content: sampleContentPack,
|
||||
roomId: "room.level1.large.001",
|
||||
level: 1,
|
||||
roomTableCode: "L1LR",
|
||||
position: { x: 4, y: 3 },
|
||||
roller: createSequenceRoller([4, 4]),
|
||||
});
|
||||
|
||||
expect(result.lookup?.roll.total).toBe(8);
|
||||
expect(result.room.templateId).toBe("room.level1.large.sparring-chamber");
|
||||
expect(result.room.dimensions).toEqual({ width: 6, height: 6 });
|
||||
expect(result.room.exits).toHaveLength(3);
|
||||
expect(result.room.flags).toContain("large");
|
||||
});
|
||||
|
||||
it("respects explicit template exits when they are defined", () => {
|
||||
const room = createRoomStateFromTemplate(
|
||||
sampleContentPack,
|
||||
"room.level1.custom.start",
|
||||
1,
|
||||
"room.level1.entry",
|
||||
{ x: 0, y: 0 },
|
||||
);
|
||||
|
||||
expect(room.exits).toEqual([
|
||||
expect.objectContaining({
|
||||
direction: "north",
|
||||
exitType: "door",
|
||||
discovered: true,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("creates a clean level shell for future dungeon state", () => {
|
||||
const level = createLevelShell(1);
|
||||
|
||||
expect(level.themeName).toBe("The Entry");
|
||||
expect(level.rooms).toEqual({});
|
||||
expect(level.discoveredRoomOrder).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user