Implement the 018-combatant-concentration feature that adds a per-combatant concentration toggle with Brain icon, purple border accent, and damage pulse animation in the encounter tracker
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
44
packages/domain/src/toggle-concentration.ts
Normal file
44
packages/domain/src/toggle-concentration.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import type { DomainEvent } from "./events.js";
|
||||
import type { CombatantId, DomainError, Encounter } from "./types.js";
|
||||
|
||||
export interface ToggleConcentrationSuccess {
|
||||
readonly encounter: Encounter;
|
||||
readonly events: DomainEvent[];
|
||||
}
|
||||
|
||||
export function toggleConcentration(
|
||||
encounter: Encounter,
|
||||
combatantId: CombatantId,
|
||||
): ToggleConcentrationSuccess | DomainError {
|
||||
const targetIdx = encounter.combatants.findIndex((c) => c.id === combatantId);
|
||||
|
||||
if (targetIdx === -1) {
|
||||
return {
|
||||
kind: "domain-error",
|
||||
code: "combatant-not-found",
|
||||
message: `No combatant found with ID "${combatantId}"`,
|
||||
};
|
||||
}
|
||||
|
||||
const target = encounter.combatants[targetIdx];
|
||||
const wasConcentrating = target.isConcentrating === true;
|
||||
|
||||
const event: DomainEvent = wasConcentrating
|
||||
? { type: "ConcentrationEnded", combatantId }
|
||||
: { type: "ConcentrationStarted", combatantId };
|
||||
|
||||
const updatedCombatants = encounter.combatants.map((c) =>
|
||||
c.id === combatantId
|
||||
? { ...c, isConcentrating: wasConcentrating ? undefined : true }
|
||||
: c,
|
||||
);
|
||||
|
||||
return {
|
||||
encounter: {
|
||||
combatants: updatedCombatants,
|
||||
activeIndex: encounter.activeIndex,
|
||||
roundNumber: encounter.roundNumber,
|
||||
},
|
||||
events: [event],
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user