Add combatant side assignment for encounter difficulty
All checks were successful
CI / check (push) Successful in 2m18s
CI / build-image (push) Successful in 17s

Combatants can now be assigned to party or enemy side via a toggle
in the difficulty breakdown panel. Party-side NPCs subtract their XP
from the encounter total, letting allied NPCs reduce difficulty.
PCs default to party, non-PCs to enemy — users who don't use sides
see no change. Side persists across reload and export/import.

Closes #22

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-04-03 14:15:12 +02:00
parent 30e7ed4121
commit 94e1806112
23 changed files with 1359 additions and 455 deletions

View File

@@ -154,6 +154,47 @@ describe("loadEncounter", () => {
expect(loaded?.combatants[0].cr).toBe("2");
});
it("round-trip preserves combatant side field", () => {
const result = createEncounter(
[
{
id: combatantId("c-1"),
name: "Allied Guard",
cr: "2",
side: "party",
},
{
id: combatantId("c-2"),
name: "Goblin",
side: "enemy",
},
],
0,
1,
);
if (isDomainError(result)) throw new Error("unreachable");
saveEncounter(result);
const loaded = loadEncounter();
expect(loaded).not.toBeNull();
expect(loaded?.combatants[0].side).toBe("party");
expect(loaded?.combatants[1].side).toBe("enemy");
});
it("round-trip preserves combatant without side field as undefined", () => {
const result = createEncounter(
[{ id: combatantId("c-1"), name: "Custom" }],
0,
1,
);
if (isDomainError(result)) throw new Error("unreachable");
saveEncounter(result);
const loaded = loadEncounter();
expect(loaded).not.toBeNull();
expect(loaded?.combatants[0].side).toBeUndefined();
});
it("saving after modifications persists the latest state", () => {
const encounter = makeEncounter();
saveEncounter(encounter);