feat: death-save display, stable-hour recovery, reroll-all initiative

- Player display: death-save pips for dying participants (3 successes / 3 failures), stable shows note without pips
- stableRegainHours: 1d4 hours rolled on natural stabilization (3rd save success, manual stabilize, revive-to-stable); cleared on heal, damage-while-stable, inline HP edit, and death; undo/redo round-trips through all paths
- Roster writeback: end-of-encounter sync writes stable hours to characters (stable -> hours, conscious -> null); character card badge shows hours; stable state carried into new encounters via buildCharacterParticipant; editor Cur HP > 0 clears
- End-combat message corrected: states turn position and round reset while initiative values are kept
- Reroll All Initiative: d20 + initMod for every participant in a single write, undoable, pre-combat or paused only; confirmation modal in UI, hidden during active combat
- Add All (Roll Init) hoisted to Add Participants header row so it stays visible when the section is collapsed; header title remains the collapse toggle
This commit is contained in:
david raistrick committed 2026-09-23 20:39:28 -04:00
1 parent 8ecd31d570
commit 8d71f0ba4b
9 files changed
+664 -33

No files matched your search

+68
View File
@@ -204,3 +204,71 @@ describe('character writeback on endEncounter', () => {
expect(storage._writes.find(w => w.path === 'campaigns/camp1')).toBeUndefined();
});
});
describe('stable regain hours writeback', () => {
function ctxFor(storage) {
return {
storage,
encounterPath: 'campaigns/camp1/encounters/enc1',
logPath: 'logs/log1',
logCollection: 'logs',
displayPath: 'activeDisplay/status',
};
}
test('stable char carries stableRegainHours to roster', async () => {
const storage = makeMockStorage();
const players = [
{ id: 'char1', name: 'Fighter', defaultMaxHp: 30, defaultAc: 17, defaultCurrentHp: 30 },
];
storage._docs.set('campaigns/camp1', { id: 'camp1', name: 'Camp', players, syncCharacters: true });
const enc = makeEncounter({
participants: [
{ id: 'p1', name: 'Fighter', type: 'character', originalCharacterId: 'char1', initiative: 15, maxHp: 30, currentHp: 0, ac: 17, status: 'stable', stableRegainHours: 3 },
],
});
await endEncounter(enc, ctxFor(storage));
const campWrite = storage._writes.find(w => w.path === 'campaigns/camp1');
expect(campWrite).toBeDefined();
const fighter = campWrite.patch.players.find(p => p.id === 'char1');
expect(fighter.stableRegainHours).toBe(3);
});
test('conscious char clears stale roster stableRegainHours', async () => {
const storage = makeMockStorage();
const players = [
{ id: 'char1', name: 'Fighter', defaultMaxHp: 30, defaultAc: 17, defaultCurrentHp: 30, stableRegainHours: 2 },
];
storage._docs.set('campaigns/camp1', { id: 'camp1', name: 'Camp', players, syncCharacters: true });
const enc = makeEncounter({
participants: [
{ id: 'p1', name: 'Fighter', type: 'character', originalCharacterId: 'char1', initiative: 15, maxHp: 30, currentHp: 12, ac: 17, status: 'conscious' },
],
});
await endEncounter(enc, ctxFor(storage));
const campWrite = storage._writes.find(w => w.path === 'campaigns/camp1');
expect(campWrite).toBeDefined();
const fighter = campWrite.patch.players.find(p => p.id === 'char1');
expect(fighter.stableRegainHours).toBeNull();
});
});
describe('buildCharacterParticipant carries stable state', () => {
const { buildCharacterParticipant } = shared;
test('roster stable char becomes stable participant with hours', () => {
const char = { id: 'c1', name: 'Rogue', defaultMaxHp: 40, defaultCurrentHp: 0, defaultInitMod: 2, stableRegainHours: 4 };
const { participant } = buildCharacterParticipant(char);
expect(participant.currentHp).toBe(0);
expect(participant.status).toBe('stable');
expect(participant.stableRegainHours).toBe(4);
expect(participant.conditions).toContain('unconscious');
});
test('healthy roster char stays conscious, no hours', () => {
const char = { id: 'c2', name: 'Cleric', defaultMaxHp: 30, defaultCurrentHp: 30, defaultInitMod: 1 };
const { participant } = buildCharacterParticipant(char);
expect(participant.status).toBe('conscious');
expect(participant.stableRegainHours).toBeNull();
});
});