Atomic addCombatant with optional CombatantInit bag
addCombatant now accepts an optional init parameter for pre-filled stats (HP, AC, initiative, creatureId, color, icon, playerCharacterId), making combatant creation a single atomic operation with domain validation. This eliminates the multi-step store.save() bypass in addFromBestiary and addFromPlayerCharacter, and removes the CombatantOpts/applyCombatantOpts helpers. Also extracts shared initiative sort logic into initiative-sort.ts used by both addCombatant and setInitiative. Closes #15 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
addCombatant,
|
||||
type CombatantId,
|
||||
type CombatantInit,
|
||||
type DomainError,
|
||||
type DomainEvent,
|
||||
isDomainError,
|
||||
@@ -11,9 +12,10 @@ export function addCombatantUseCase(
|
||||
store: EncounterStore,
|
||||
id: CombatantId,
|
||||
name: string,
|
||||
init?: CombatantInit,
|
||||
): DomainEvent[] | DomainError {
|
||||
const encounter = store.get();
|
||||
const result = addCombatant(encounter, id, name);
|
||||
const result = addCombatant(encounter, id, name, init);
|
||||
|
||||
if (isDomainError(result)) {
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user