Implement the 023-clear-encounter feature that adds a clear encounter button with confirmation dialog to remove all combatants and reset round/turn counters, with the cleared state persisting across page refreshes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
33
packages/domain/src/clear-encounter.ts
Normal file
33
packages/domain/src/clear-encounter.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { DomainEvent } from "./events.js";
|
||||
import type { DomainError, Encounter } from "./types.js";
|
||||
|
||||
export interface ClearEncounterSuccess {
|
||||
readonly encounter: Encounter;
|
||||
readonly events: DomainEvent[];
|
||||
}
|
||||
|
||||
export function clearEncounter(
|
||||
encounter: Encounter,
|
||||
): ClearEncounterSuccess | DomainError {
|
||||
if (encounter.combatants.length === 0) {
|
||||
return {
|
||||
kind: "domain-error",
|
||||
code: "encounter-already-empty",
|
||||
message: "Cannot clear an encounter that has no combatants",
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
encounter: {
|
||||
combatants: [],
|
||||
activeIndex: 0,
|
||||
roundNumber: 1,
|
||||
},
|
||||
events: [
|
||||
{
|
||||
type: "EncounterCleared",
|
||||
combatantCount: encounter.combatants.length,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user