Implement the 005-set-initiative feature that adds initiative values to combatants with automatic descending sort and active turn preservation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
advanceTurnUseCase,
|
||||
editCombatantUseCase,
|
||||
removeCombatantUseCase,
|
||||
setInitiativeUseCase,
|
||||
} from "@initiative/application";
|
||||
import type { CombatantId, DomainEvent, Encounter } from "@initiative/domain";
|
||||
import {
|
||||
@@ -92,6 +93,19 @@ export function useEncounter() {
|
||||
[makeStore],
|
||||
);
|
||||
|
||||
const setInitiative = useCallback(
|
||||
(id: CombatantId, value: number | undefined) => {
|
||||
const result = setInitiativeUseCase(makeStore(), id, value);
|
||||
|
||||
if (isDomainError(result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
setEvents((prev) => [...prev, ...result]);
|
||||
},
|
||||
[makeStore],
|
||||
);
|
||||
|
||||
return {
|
||||
encounter,
|
||||
events,
|
||||
@@ -99,5 +113,6 @@ export function useEncounter() {
|
||||
addCombatant,
|
||||
removeCombatant,
|
||||
editCombatant,
|
||||
setInitiative,
|
||||
} as const;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user