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

@@ -12,6 +12,7 @@ import {
setCrUseCase,
setHpUseCase,
setInitiativeUseCase,
setSideUseCase,
setTempHpUseCase,
toggleConcentrationUseCase,
toggleConditionUseCase,
@@ -54,6 +55,7 @@ type EncounterAction =
| { type: "set-temp-hp"; id: CombatantId; tempHp: number | undefined }
| { type: "set-ac"; id: CombatantId; value: number | undefined }
| { type: "set-cr"; id: CombatantId; value: string | undefined }
| { type: "set-side"; id: CombatantId; value: "party" | "enemy" }
| {
type: "toggle-condition";
id: CombatantId;
@@ -321,6 +323,7 @@ function dispatchEncounterAction(
| { type: "set-temp-hp" }
| { type: "set-ac" }
| { type: "set-cr" }
| { type: "set-side" }
| { type: "toggle-condition" }
| { type: "toggle-concentration" }
>,
@@ -364,6 +367,9 @@ function dispatchEncounterAction(
case "set-cr":
result = setCrUseCase(store, action.id, action.value);
break;
case "set-side":
result = setSideUseCase(store, action.id, action.value);
break;
case "toggle-condition":
result = toggleConditionUseCase(store, action.id, action.conditionId);
break;
@@ -506,6 +512,11 @@ export function useEncounter() {
dispatch({ type: "set-cr", id, value }),
[],
),
setSide: useCallback(
(id: CombatantId, value: "party" | "enemy") =>
dispatch({ type: "set-side", id, value }),
[],
),
toggleCondition: useCallback(
(id: CombatantId, conditionId: ConditionId) =>
dispatch({ type: "toggle-condition", id, conditionId }),