Implement the 009-combatant-hp feature that adds optional max HP and current HP tracking per combatant with +/- controls, direct entry, and persistence
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -41,12 +41,30 @@ export function loadEncounter(): Encounter | null {
|
||||
|
||||
const rehydrated = combatants.map((c) => {
|
||||
const entry = c as Record<string, unknown>;
|
||||
return {
|
||||
const base = {
|
||||
id: combatantId(entry.id as string),
|
||||
name: entry.name as string,
|
||||
initiative:
|
||||
typeof entry.initiative === "number" ? entry.initiative : undefined,
|
||||
};
|
||||
|
||||
// Validate and attach HP fields if valid
|
||||
const maxHp = entry.maxHp;
|
||||
const currentHp = entry.currentHp;
|
||||
if (typeof maxHp === "number" && Number.isInteger(maxHp) && maxHp >= 1) {
|
||||
const validCurrentHp =
|
||||
typeof currentHp === "number" &&
|
||||
Number.isInteger(currentHp) &&
|
||||
currentHp >= 0 &&
|
||||
currentHp <= maxHp;
|
||||
return {
|
||||
...base,
|
||||
maxHp,
|
||||
currentHp: validCurrentHp ? currentHp : maxHp,
|
||||
};
|
||||
}
|
||||
|
||||
return base;
|
||||
});
|
||||
|
||||
const result = createEncounter(
|
||||
|
||||
Reference in New Issue
Block a user