Add jsinspect-plus (AST-based structural duplication detector) to pnpm check with threshold 50 / min 3 instances. Fix all findings: - Extract condition icon/color maps to shared condition-styles.ts - Extract useClickOutside hook (5 components) - Extract dispatchAction + resolveAndRename in use-encounter - Extract runEncounterAction in application layer (13 use cases) - Extract findCombatant helper in domain (9 functions) - Extract TraitSection in stat-block (4 trait rendering blocks) - Extract DialogHeader in dialog.tsx (4 dialogs) Net result: -263 lines across 40 files. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
53 lines
1.1 KiB
TypeScript
53 lines
1.1 KiB
TypeScript
import type { DomainEvent } from "./events.js";
|
|
import {
|
|
type CombatantId,
|
|
type DomainError,
|
|
type Encounter,
|
|
findCombatant,
|
|
isDomainError,
|
|
} from "./types.js";
|
|
|
|
export interface SetAcSuccess {
|
|
readonly encounter: Encounter;
|
|
readonly events: DomainEvent[];
|
|
}
|
|
|
|
export function setAc(
|
|
encounter: Encounter,
|
|
combatantId: CombatantId,
|
|
value: number | undefined,
|
|
): SetAcSuccess | DomainError {
|
|
const found = findCombatant(encounter, combatantId);
|
|
if (isDomainError(found)) return found;
|
|
|
|
if (value !== undefined && (!Number.isInteger(value) || value < 0)) {
|
|
return {
|
|
kind: "domain-error",
|
|
code: "invalid-ac",
|
|
message: `AC must be a non-negative integer, got ${value}`,
|
|
};
|
|
}
|
|
|
|
const previousAc = found.combatant.ac;
|
|
|
|
const updatedCombatants = encounter.combatants.map((c) =>
|
|
c.id === combatantId ? { ...c, ac: value } : c,
|
|
);
|
|
|
|
return {
|
|
encounter: {
|
|
combatants: updatedCombatants,
|
|
activeIndex: encounter.activeIndex,
|
|
roundNumber: encounter.roundNumber,
|
|
},
|
|
events: [
|
|
{
|
|
type: "AcSet",
|
|
combatantId,
|
|
previousAc,
|
|
newAc: value,
|
|
},
|
|
],
|
|
};
|
|
}
|