Clicking an already-selected color or icon in the create/edit form now deselects it. PCs without a color use the default combatant styling; PCs without an icon show no icon. Domain, application, persistence, and display layers all updated to handle the optional fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
33 lines
724 B
TypeScript
33 lines
724 B
TypeScript
import {
|
|
type DomainError,
|
|
type DomainEvent,
|
|
editPlayerCharacter,
|
|
isDomainError,
|
|
type PlayerCharacterId,
|
|
} from "@initiative/domain";
|
|
import type { PlayerCharacterStore } from "./ports.js";
|
|
|
|
interface EditFields {
|
|
readonly name?: string;
|
|
readonly ac?: number;
|
|
readonly maxHp?: number;
|
|
readonly color?: string | null;
|
|
readonly icon?: string | null;
|
|
}
|
|
|
|
export function editPlayerCharacterUseCase(
|
|
store: PlayerCharacterStore,
|
|
id: PlayerCharacterId,
|
|
fields: EditFields,
|
|
): DomainEvent[] | DomainError {
|
|
const characters = store.getAll();
|
|
const result = editPlayerCharacter(characters, id, fields);
|
|
|
|
if (isDomainError(result)) {
|
|
return result;
|
|
}
|
|
|
|
store.save([...result.characters]);
|
|
return result.events;
|
|
}
|