Persistent player character templates (name, AC, HP, color, icon) with full CRUD, bestiary-style search to add PCs to encounters with pre-filled stats, and color/icon visual distinction in combatant rows. Also stops the stat block panel from auto-opening when adding a creature. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
40 lines
933 B
TypeScript
40 lines
933 B
TypeScript
import type { DomainEvent } from "./events.js";
|
|
import type {
|
|
PlayerCharacter,
|
|
PlayerCharacterId,
|
|
} from "./player-character-types.js";
|
|
import type { DomainError } from "./types.js";
|
|
|
|
export interface DeletePlayerCharacterSuccess {
|
|
readonly characters: readonly PlayerCharacter[];
|
|
readonly events: DomainEvent[];
|
|
}
|
|
|
|
export function deletePlayerCharacter(
|
|
characters: readonly PlayerCharacter[],
|
|
id: PlayerCharacterId,
|
|
): DeletePlayerCharacterSuccess | DomainError {
|
|
const index = characters.findIndex((c) => c.id === id);
|
|
if (index === -1) {
|
|
return {
|
|
kind: "domain-error",
|
|
code: "player-character-not-found",
|
|
message: `Player character not found: ${id}`,
|
|
};
|
|
}
|
|
|
|
const removed = characters[index];
|
|
const newList = characters.filter((_, i) => i !== index);
|
|
|
|
return {
|
|
characters: newList,
|
|
events: [
|
|
{
|
|
type: "PlayerCharacterDeleted",
|
|
playerCharacterId: id,
|
|
name: removed.name,
|
|
},
|
|
],
|
|
};
|
|
}
|