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:
@@ -430,5 +430,6 @@ export function useEncounter() {
|
||||
undo: undoAction,
|
||||
redo: redoAction,
|
||||
makeStore,
|
||||
withUndo,
|
||||
} as const;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user