Wrap initiative rolls with undo so they produce undo entries

Initiative rolls (single and bulk) called makeStore() directly from
useInitiativeRolls, bypassing the withUndo wrapper. Expose withUndo
from the encounter context and wrap both roll paths.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-03-27 00:06:50 +01:00
parent e9fd896934
commit 541e04b732
3 changed files with 9 additions and 14 deletions

View File

@@ -17,7 +17,7 @@ function rollDice(): number {
}
export function useInitiativeRolls() {
const { encounter, makeStore } = useEncounterContext();
const { encounter, makeStore, withUndo } = useEncounterContext();
const { getCreature } = useBestiaryContext();
const { showCreature } = useSidePanelContext();
@@ -28,12 +28,8 @@ export function useInitiativeRolls() {
(id: CombatantId, mode: RollMode = "normal") => {
const diceRolls: [number, ...number[]] =
mode === "normal" ? [rollDice()] : [rollDice(), rollDice()];
const result = rollInitiativeUseCase(
makeStore(),
id,
diceRolls,
getCreature,
mode,
const result = withUndo(() =>
rollInitiativeUseCase(makeStore(), id, diceRolls, getCreature, mode),
);
if (isDomainError(result)) {
setRollSingleSkipped(true);
@@ -43,22 +39,19 @@ export function useInitiativeRolls() {
}
}
},
[makeStore, getCreature, encounter.combatants, showCreature],
[makeStore, getCreature, withUndo, encounter.combatants, showCreature],
);
const handleRollAllInitiative = useCallback(
(mode: RollMode = "normal") => {
const result = rollAllInitiativeUseCase(
makeStore(),
rollDice,
getCreature,
mode,
const result = withUndo(() =>
rollAllInitiativeUseCase(makeStore(), rollDice, getCreature, mode),
);
if (!isDomainError(result) && result.skippedNoSource > 0) {
setRollSkippedCount(result.skippedNoSource);
}
},
[makeStore, getCreature],
[makeStore, getCreature, withUndo],
);
return {