feat: add encounter roster visibility and kill actions
- persist independent Hide Disabled and Hide Dead encounter controls - keep dead PCs exempt from Hide Dead while allowing Hide Disabled to hide any inactive participant - add confirmed Kill action that sets zero HP, dead, and inactive without deleting - add undoable Heal Full action above Revive - fix random initiative reroll test flake
This commit is contained in:
1 parent
0e7bc7c099
commit
15347bfdc8
5 files changed
+300
-27
No files matched your search
@@ -1,9 +1,9 @@
|
|||||||
// Generic (non-5e) ruleset: no death saves, negative HP allowed, down status.
|
// Generic (non-5e) ruleset: no death saves, negative HP allowed, down status.
|
||||||
const shared = require('@ttrpg/shared');
|
const shared = require('@ttrpg/shared');
|
||||||
const { mockCtx } = require('./_helpers');
|
const { mockCtx, undoLast } = require('./_helpers');
|
||||||
const {
|
const {
|
||||||
buildCharacterParticipant, buildMonsterParticipant,
|
buildCharacterParticipant, buildMonsterParticipant,
|
||||||
startEncounter, applyHpChange, deathSave, markDead, reviveParticipant,
|
startEncounter, applyHpChange, deathSave, markDead, reviveParticipant, healFullParticipant,
|
||||||
} = shared;
|
} = shared;
|
||||||
|
|
||||||
function char(id, hp = 100) {
|
function char(id, hp = 100) {
|
||||||
@@ -121,25 +121,48 @@ describe('generic ruleset', () => {
|
|||||||
expect(p.isActive).toBe(true);
|
expect(p.isActive).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('markDead sets status dead (character, stays active)', async () => {
|
test('markDead kills and disables character', async () => {
|
||||||
const { ctx } = mockCtx();
|
const { ctx } = mockCtx();
|
||||||
let e = enc([char('a', 10)]);
|
let e = enc([{ ...char('a', 10), tempHp: 4, deathSaveSuccesses: 2, deathSaveFailures: 1 }]);
|
||||||
e = await startEncounter(e, ctx);
|
e = await startEncounter(e, ctx);
|
||||||
e = await applyHpChange(e, 'a', 'damage', 10, ctx); // down
|
|
||||||
const newEnc = await markDead(e, 'a', ctx);
|
const newEnc = await markDead(e, 'a', ctx);
|
||||||
const p = newEnc.participants.find(x => x.id === 'a');
|
const p = newEnc.participants.find(x => x.id === 'a');
|
||||||
expect(p.status).toBe('dead');
|
expect(p).toMatchObject({
|
||||||
expect(p.isActive).toBe(true);
|
currentHp: 0, tempHp: 0, status: 'dead', isActive: false,
|
||||||
|
deathSaveSuccesses: 0, deathSaveFailures: 0, stableRegainHours: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
const undone = await undoLast(ctx, newEnc);
|
||||||
|
expect(undone.participants.find(x => x.id === 'a')).toMatchObject({
|
||||||
|
currentHp: 10, tempHp: 4, status: 'conscious', isActive: true,
|
||||||
|
deathSaveSuccesses: 2, deathSaveFailures: 1,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('markDead on monster = dead + inactive', async () => {
|
test('healFullParticipant restores dead participant to full, active, conscious; undo restores death', async () => {
|
||||||
|
const { ctx } = mockCtx();
|
||||||
|
let e = enc([{ ...char('a', 20), currentHp: 0, status: 'dead', isActive: false, deathSaveSuccesses: 2, deathSaveFailures: 1, conditions: ['unconscious'], stableRegainHours: 3 }]);
|
||||||
|
const healed = await healFullParticipant(e, 'a', ctx);
|
||||||
|
expect(healed.participants[0]).toMatchObject({
|
||||||
|
currentHp: 20, status: 'conscious', isActive: true,
|
||||||
|
deathSaveSuccesses: 0, deathSaveFailures: 0, stableRegainHours: null,
|
||||||
|
});
|
||||||
|
expect(healed.participants[0].conditions).not.toContain('unconscious');
|
||||||
|
|
||||||
|
const undone = await undoLast(ctx, healed);
|
||||||
|
expect(undone.participants[0]).toMatchObject({ currentHp: 0, status: 'dead', isActive: false, stableRegainHours: 3 });
|
||||||
|
expect(undone.participants[0].conditions).toContain('unconscious');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('markDead on monster = 0 HP + dead + inactive', async () => {
|
||||||
const { ctx } = mockCtx();
|
const { ctx } = mockCtx();
|
||||||
let e = enc([mon('m', 10)]);
|
let e = enc([mon('m', 10)]);
|
||||||
e = await startEncounter(e, ctx);
|
e = await startEncounter(e, ctx);
|
||||||
e = await applyHpChange(e, 'm', 'damage', 5, ctx); // down (5hp)
|
e = await applyHpChange(e, 'm', 'damage', 5, ctx); // 5 HP remain
|
||||||
const newEnc = await markDead(e, e.participants[0].id, ctx);
|
const newEnc = await markDead(e, e.participants[0].id, ctx);
|
||||||
const p = newEnc.participants[0];
|
const p = newEnc.participants[0];
|
||||||
expect(p.status).toBe('dead');
|
expect(p.status).toBe('dead');
|
||||||
|
expect(p.currentHp).toBe(0);
|
||||||
expect(p.isActive).toBe(false);
|
expect(p.isActive).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ describe('rerollAllInitiatives', () => {
|
|||||||
const orderBefore = [...e.turnOrderIds];
|
const orderBefore = [...e.turnOrderIds];
|
||||||
|
|
||||||
const out = await rerollAllInitiatives(e, ctx);
|
const out = await rerollAllInitiatives(e, ctx);
|
||||||
expect(find(out, 'a').initiative).not.toBe(10);
|
|
||||||
|
|
||||||
const undone = await undoLast(ctx, out);
|
const undone = await undoLast(ctx, out);
|
||||||
expect(find(undone, 'a').initiative).toBe(10);
|
expect(find(undone, 'a').initiative).toBe(10);
|
||||||
|
|||||||
+69
-7
@@ -237,6 +237,7 @@ function expandUndo(entry, currentEnc) {
|
|||||||
case 'death_save':
|
case 'death_save':
|
||||||
case 'stabilize':
|
case 'stabilize':
|
||||||
case 'revive':
|
case 'revive':
|
||||||
|
case 'heal_full':
|
||||||
case 'mark_dead':
|
case 'mark_dead':
|
||||||
case 'deactivate_dead_monster': {
|
case 'deactivate_dead_monster': {
|
||||||
// Full death-state restore: currentHp, status, death-save counters,
|
// Full death-state restore: currentHp, status, death-save counters,
|
||||||
@@ -249,6 +250,7 @@ function expandUndo(entry, currentEnc) {
|
|||||||
const restoreFields = (vals) => {
|
const restoreFields = (vals) => {
|
||||||
const out = {};
|
const out = {};
|
||||||
if (vals.currentHp !== undefined) out.currentHp = vals.currentHp;
|
if (vals.currentHp !== undefined) out.currentHp = vals.currentHp;
|
||||||
|
if (vals.tempHp !== undefined) out.tempHp = vals.tempHp;
|
||||||
if (vals.status !== undefined) out.status = vals.status;
|
if (vals.status !== undefined) out.status = vals.status;
|
||||||
if (vals.deathSaveSuccesses !== undefined) out.deathSaveSuccesses = vals.deathSaveSuccesses;
|
if (vals.deathSaveSuccesses !== undefined) out.deathSaveSuccesses = vals.deathSaveSuccesses;
|
||||||
if (vals.deathSaveFailures !== undefined) out.deathSaveFailures = vals.deathSaveFailures;
|
if (vals.deathSaveFailures !== undefined) out.deathSaveFailures = vals.deathSaveFailures;
|
||||||
@@ -1206,30 +1208,90 @@ async function reviveParticipant(encounter, participantId, ctx) {
|
|||||||
return commit(encounter, patch, log, ctx);
|
return commit(encounter, patch, log, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// markDead: DM manually sets status dead. Both rulesets. Monster = auto-inactive.
|
async function healFullParticipant(encounter, participantId, ctx) {
|
||||||
|
const participant = (encounter.participants || []).find(p => p.id === participantId);
|
||||||
|
if (!participant) throw new Error('Participant not found.');
|
||||||
|
const status = participant.status || (participant.currentHp <= 0 ? 'down' : 'conscious');
|
||||||
|
const oldValues = {
|
||||||
|
currentHp: participant.currentHp,
|
||||||
|
status,
|
||||||
|
deathSaveSuccesses: participant.deathSaveSuccesses || 0,
|
||||||
|
deathSaveFailures: participant.deathSaveFailures || 0,
|
||||||
|
stableRegainHours: participant.stableRegainHours !== undefined ? participant.stableRegainHours : null,
|
||||||
|
isActive: participant.isActive,
|
||||||
|
conditions: [...(participant.conditions || [])],
|
||||||
|
};
|
||||||
|
const updates = {
|
||||||
|
currentHp: participant.maxHp,
|
||||||
|
status: 'conscious',
|
||||||
|
deathSaveSuccesses: 0,
|
||||||
|
deathSaveFailures: 0,
|
||||||
|
stableRegainHours: null,
|
||||||
|
isActive: true,
|
||||||
|
};
|
||||||
|
const updatedParticipants = (encounter.participants || []).map(p =>
|
||||||
|
p.id === participantId ? { ...p, ...withDeathStatusConditions(p, updates) } : p
|
||||||
|
);
|
||||||
|
const newP = updatedParticipants.find(p => p.id === participantId);
|
||||||
|
const newValues = {
|
||||||
|
currentHp: newP.currentHp,
|
||||||
|
status: newP.status,
|
||||||
|
deathSaveSuccesses: newP.deathSaveSuccesses || 0,
|
||||||
|
deathSaveFailures: newP.deathSaveFailures || 0,
|
||||||
|
stableRegainHours: newP.stableRegainHours !== undefined ? newP.stableRegainHours : null,
|
||||||
|
isActive: newP.isActive,
|
||||||
|
conditions: [...(newP.conditions || [])],
|
||||||
|
};
|
||||||
|
return commit(encounter, { participants: updatedParticipants }, {
|
||||||
|
type: 'heal_full', participantId, participantName: participant.name,
|
||||||
|
message: `${participant.name} healed to full (${participant.maxHp} HP)`,
|
||||||
|
delta: { currentHp: participant.maxHp, status: 'conscious', isActive: true },
|
||||||
|
undo: { oldValues, newValues },
|
||||||
|
}, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
// markDead: DM manually kills participant. Sets 0 HP + inactive.
|
||||||
async function markDead(encounter, participantId, ctx) {
|
async function markDead(encounter, participantId, ctx) {
|
||||||
const participant = (encounter.participants || []).find(p => p.id === participantId);
|
const participant = (encounter.participants || []).find(p => p.id === participantId);
|
||||||
if (!participant) throw new Error('Participant not found.');
|
if (!participant) throw new Error('Participant not found.');
|
||||||
if (participant.status === 'dead') return encounter;
|
if (participant.status === 'dead') return encounter;
|
||||||
const oldValues = {
|
const oldValues = {
|
||||||
currentHp: participant.currentHp,
|
currentHp: participant.currentHp,
|
||||||
|
tempHp: participant.tempHp || 0,
|
||||||
status: participant.status || 'conscious',
|
status: participant.status || 'conscious',
|
||||||
|
deathSaveSuccesses: participant.deathSaveSuccesses || 0,
|
||||||
|
deathSaveFailures: participant.deathSaveFailures || 0,
|
||||||
|
stableRegainHours: participant.stableRegainHours !== undefined ? participant.stableRegainHours : null,
|
||||||
isActive: participant.isActive,
|
isActive: participant.isActive,
|
||||||
conditions: [...(participant.conditions || [])],
|
conditions: [...(participant.conditions || [])],
|
||||||
};
|
};
|
||||||
const updates = { status: 'dead', ...(participant.type === 'monster' ? { isActive: false } : {}) };
|
const updates = {
|
||||||
|
currentHp: 0,
|
||||||
|
tempHp: 0,
|
||||||
|
status: 'dead',
|
||||||
|
deathSaveSuccesses: 0,
|
||||||
|
deathSaveFailures: 0,
|
||||||
|
stableRegainHours: null,
|
||||||
|
isActive: false,
|
||||||
|
};
|
||||||
const updatedParticipants = (encounter.participants || []).map(p =>
|
const updatedParticipants = (encounter.participants || []).map(p =>
|
||||||
p.id === participantId ? { ...p, ...withDeathStatusConditions(p, updates) } : p
|
p.id === participantId ? { ...p, ...withDeathStatusConditions(p, updates) } : p
|
||||||
);
|
);
|
||||||
const newP = updatedParticipants.find(p => p.id === participantId);
|
const newP = updatedParticipants.find(p => p.id === participantId);
|
||||||
const newValues = {
|
const newValues = {
|
||||||
currentHp: newP.currentHp, status: newP.status,
|
currentHp: newP.currentHp,
|
||||||
isActive: newP.isActive, conditions: [...(newP.conditions || [])],
|
tempHp: newP.tempHp || 0,
|
||||||
|
status: newP.status,
|
||||||
|
deathSaveSuccesses: newP.deathSaveSuccesses || 0,
|
||||||
|
deathSaveFailures: newP.deathSaveFailures || 0,
|
||||||
|
stableRegainHours: newP.stableRegainHours !== undefined ? newP.stableRegainHours : null,
|
||||||
|
isActive: newP.isActive,
|
||||||
|
conditions: [...(newP.conditions || [])],
|
||||||
};
|
};
|
||||||
return commit(encounter, { participants: updatedParticipants }, {
|
return commit(encounter, { participants: updatedParticipants }, {
|
||||||
type: 'mark_dead', participantId, participantName: participant.name,
|
type: 'mark_dead', participantId, participantName: participant.name,
|
||||||
message: `${participant.name} marked dead`,
|
message: `${participant.name} killed`,
|
||||||
delta: { status: 'dead' },
|
delta: { status: 'dead', currentHp: 0, isActive: false },
|
||||||
undo: { oldValues, newValues },
|
undo: { oldValues, newValues },
|
||||||
}, ctx);
|
}, ctx);
|
||||||
}
|
}
|
||||||
@@ -1389,7 +1451,7 @@ module.exports = {
|
|||||||
makeEffect, makeParticipant, buildCharacterParticipant, buildMonsterParticipant,
|
makeEffect, makeParticipant, buildCharacterParticipant, buildMonsterParticipant,
|
||||||
startEncounter, nextTurn, togglePause,
|
startEncounter, nextTurn, togglePause,
|
||||||
addParticipant, addParticipants, updateParticipant, removeParticipant,
|
addParticipant, addParticipants, updateParticipant, removeParticipant,
|
||||||
toggleParticipantActive, applyHpChange, setTempHp, deathSave, stabilizeParticipant, reviveParticipant, markDead, toggleCondition,
|
toggleParticipantActive, applyHpChange, setTempHp, deathSave, stabilizeParticipant, reviveParticipant, healFullParticipant, markDead, toggleCondition,
|
||||||
addEffect, updateEffect, removeEffect,
|
addEffect, updateEffect, removeEffect,
|
||||||
reorderParticipants, endEncounter, rerollAllInitiatives,
|
reorderParticipants, endEncounter, rerollAllInitiatives,
|
||||||
activateDisplay, clearDisplay, toggleHidePlayerHp,
|
activateDisplay, clearDisplay, toggleHidePlayerHp,
|
||||||
|
|||||||
+92
-10
@@ -127,6 +127,7 @@ const {
|
|||||||
deathSave: combatDeathSave,
|
deathSave: combatDeathSave,
|
||||||
stabilizeParticipant,
|
stabilizeParticipant,
|
||||||
reviveParticipant,
|
reviveParticipant,
|
||||||
|
healFullParticipant,
|
||||||
markDead,
|
markDead,
|
||||||
toggleCondition: combatToggleCondition,
|
toggleCondition: combatToggleCondition,
|
||||||
reorderParticipants,
|
reorderParticipants,
|
||||||
@@ -1423,6 +1424,7 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
|
|||||||
const [draggedItemId, setDraggedItemId] = useState(null);
|
const [draggedItemId, setDraggedItemId] = useState(null);
|
||||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
||||||
const [itemToDelete, setItemToDelete] = useState(null);
|
const [itemToDelete, setItemToDelete] = useState(null);
|
||||||
|
const [killTarget, setKillTarget] = useState(null);
|
||||||
const [lastRollDetails, setLastRollDetails] = useState(null);
|
const [lastRollDetails, setLastRollDetails] = useState(null);
|
||||||
const [openConditionsId, setOpenConditionsId] = useState(null);
|
const [openConditionsId, setOpenConditionsId] = useState(null);
|
||||||
const [customConditionInput, setCustomConditionInput] = useState('');
|
const [customConditionInput, setCustomConditionInput] = useState('');
|
||||||
@@ -1439,6 +1441,16 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
|
|||||||
];
|
];
|
||||||
|
|
||||||
const participants = encounter.participants || [];
|
const participants = encounter.participants || [];
|
||||||
|
const isDeadParticipant = p => p.status === 'dead' || ((encounter.ruleset || '5e') === '5e' && p.type === 'monster' && p.currentHp === 0);
|
||||||
|
// Independent filters: Hide Disabled applies to every inactive participant,
|
||||||
|
// including dead PCs. Hide Dead applies only to dead monsters/NPCs.
|
||||||
|
const deadParticipants = participants.filter(p => isDeadParticipant(p) && p.type !== 'character');
|
||||||
|
const disabledParticipants = participants.filter(p => p.isActive === false);
|
||||||
|
const visibleParticipants = participants.filter(p => {
|
||||||
|
if (encounter.hideDisabledParticipants && p.isActive === false) return false;
|
||||||
|
if (encounter.hideDeadParticipants && isDeadParticipant(p) && p.type !== 'character') return false;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
const [editingField, setEditingField] = useState(null);
|
const [editingField, setEditingField] = useState(null);
|
||||||
const [editingId, setEditingId] = useState(null);
|
const [editingId, setEditingId] = useState(null);
|
||||||
const blurTimeoutRef = useRef(null);
|
const blurTimeoutRef = useRef(null);
|
||||||
@@ -1739,6 +1751,15 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleHealFull = async (participantId) => {
|
||||||
|
if (!db) return;
|
||||||
|
try {
|
||||||
|
await healFullParticipant(encounter, participantId, buildCtx(encounterPath));
|
||||||
|
} catch (err) {
|
||||||
|
showToast(err.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleMarkDead = async (participantId) => {
|
const handleMarkDead = async (participantId) => {
|
||||||
if (!db) return;
|
if (!db) return;
|
||||||
try {
|
try {
|
||||||
@@ -1748,6 +1769,20 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const confirmKill = async () => {
|
||||||
|
if (!killTarget) return;
|
||||||
|
await handleMarkDead(killTarget.id);
|
||||||
|
setKillTarget(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleParticipantVisibility = async (field) => {
|
||||||
|
try {
|
||||||
|
await storage.updateDoc(encounterPath, { [field]: !encounter[field] });
|
||||||
|
} catch (err) {
|
||||||
|
showToast('Failed to update participant visibility.');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleCritDamage = async (participantId) => {
|
const handleCritDamage = async (participantId) => {
|
||||||
if (!db) return;
|
if (!db) return;
|
||||||
try {
|
try {
|
||||||
@@ -1890,8 +1925,9 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
|
|||||||
setDraggedItemId(null);
|
setDraggedItemId(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 1-list model: participants[] IS the display order. No re-sort.
|
// 1-list model: participants[] IS display order. Visibility filters only render;
|
||||||
const sortedParticipants = participants;
|
// encounter data/order remain untouched.
|
||||||
|
const sortedParticipants = visibleParticipants;
|
||||||
|
|
||||||
const initiativeGroups = participants.reduce((acc, p) => {
|
const initiativeGroups = participants.reduce((acc, p) => {
|
||||||
acc[p.initiative] = (acc[p.initiative] || 0) + 1;
|
acc[p.initiative] = (acc[p.initiative] || 0) + 1;
|
||||||
@@ -2138,7 +2174,28 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<div className="mb-3 flex flex-wrap items-center gap-2 rounded-md border border-stone-700 bg-stone-950/60 p-2">
|
||||||
|
<span className="text-xs font-semibold uppercase tracking-wide text-stone-400">Roster visibility</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => toggleParticipantVisibility('hideDisabledParticipants')}
|
||||||
|
aria-pressed={!!encounter.hideDisabledParticipants}
|
||||||
|
className={`px-2 py-1 rounded text-xs border ${encounter.hideDisabledParticipants ? 'bg-amber-800 border-amber-500 text-white' : 'bg-stone-800 border-stone-600 text-stone-300'}`}
|
||||||
|
>
|
||||||
|
{encounter.hideDisabledParticipants ? 'Show' : 'Hide'} disabled ({disabledParticipants.length})
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => toggleParticipantVisibility('hideDeadParticipants')}
|
||||||
|
aria-pressed={!!encounter.hideDeadParticipants}
|
||||||
|
className={`px-2 py-1 rounded text-xs border ${encounter.hideDeadParticipants ? 'bg-amber-800 border-amber-500 text-white' : 'bg-stone-800 border-stone-600 text-stone-300'}`}
|
||||||
|
>
|
||||||
|
{encounter.hideDeadParticipants ? 'Show' : 'Hide'} dead ({deadParticipants.length})
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
{participants.length === 0 && <p className="text-sm text-stone-400">No participants added yet.</p>}
|
{participants.length === 0 && <p className="text-sm text-stone-400">No participants added yet.</p>}
|
||||||
|
{participants.length > 0 && visibleParticipants.length === 0 && <p className="text-sm text-stone-400 mb-2">All participants hidden.</p>}
|
||||||
|
|
||||||
|
|
||||||
<ul className="space-y-2">
|
<ul className="space-y-2">
|
||||||
@@ -2272,15 +2329,21 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
|
|||||||
</span>
|
</span>
|
||||||
<span className="ml-auto inline-flex items-center gap-1">
|
<span className="ml-auto inline-flex items-center gap-1">
|
||||||
{participantStatus === 'dead' && (
|
{participantStatus === 'dead' && (
|
||||||
<button onClick={() => handleRevive(p.id)} className="inline-flex items-center gap-1 px-2 py-0.5 text-xs rounded bg-emerald-800 hover:bg-emerald-700 text-white" title="Revive (clear dead status)">
|
<span className="inline-flex flex-col items-stretch gap-1">
|
||||||
<HeartPulse size={12} /> Revive
|
<button
|
||||||
</button>
|
onClick={() => handleHealFull(p.id)}
|
||||||
)}
|
className="inline-flex items-center justify-center gap-1 px-2 py-0.5 text-xs rounded bg-green-700 hover:bg-green-600 text-white"
|
||||||
{isGeneric && !isDead && (
|
title="Restore Max HP, consciousness, and active status"
|
||||||
<button onClick={() => handleMarkDead(p.id)} className="inline-flex items-center gap-1 px-2 py-0.5 text-xs rounded bg-red-900 hover:bg-red-800 text-white" title="Mark dead">
|
aria-label={`Heal ${p.name} to full`}
|
||||||
<HeartCrack size={12} /> Mark Dead
|
>
|
||||||
</button>
|
<HeartPulse size={12} /> Heal Full
|
||||||
|
</button>
|
||||||
|
<button onClick={() => handleRevive(p.id)} className="inline-flex items-center justify-center gap-1 px-2 py-0.5 text-xs rounded bg-emerald-800 hover:bg-emerald-700 text-white" title="Revive at 0 HP">
|
||||||
|
<HeartPulse size={12} /> Revive
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -2496,6 +2559,17 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{!isDead && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setKillTarget({ id: p.id, name: p.name })}
|
||||||
|
className="p-1 rounded transition-colors text-red-200 bg-red-950 hover:bg-red-900 border border-red-700"
|
||||||
|
title={`Kill ${p.name}: set 0 HP, dead, and inactive`}
|
||||||
|
aria-label={`Kill ${p.name}`}
|
||||||
|
>
|
||||||
|
<HeartCrack size={18} />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<button
|
<button
|
||||||
onClick={() => toggleParticipantActive(p.id)}
|
onClick={() => toggleParticipantActive(p.id)}
|
||||||
className={`p-1 rounded transition-all ring-2 ${p.isActive ? 'bg-emerald-700 hover:bg-emerald-600 text-white ring-emerald-300' : 'bg-red-900 hover:bg-red-800 text-red-100 ring-red-500'}`}
|
className={`p-1 rounded transition-all ring-2 ${p.isActive ? 'bg-emerald-700 hover:bg-emerald-600 text-white ring-emerald-300' : 'bg-red-900 hover:bg-red-800 text-red-100 ring-red-500'}`}
|
||||||
@@ -2566,6 +2640,14 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<ConfirmationModal
|
||||||
|
isOpen={!!killTarget}
|
||||||
|
onClose={() => setKillTarget(null)}
|
||||||
|
onConfirm={confirmKill}
|
||||||
|
title={`Kill ${killTarget?.name || 'participant'}?`}
|
||||||
|
message="Sets HP and Temp HP to 0, marks dead, and disables participant. Participant remains in encounter and can be shown or revived later."
|
||||||
|
/>
|
||||||
|
|
||||||
<ConfirmationModal
|
<ConfirmationModal
|
||||||
isOpen={showDeleteConfirm}
|
isOpen={showDeleteConfirm}
|
||||||
onClose={() => setShowDeleteConfirm(false)}
|
onClose={() => setShowDeleteConfirm(false)}
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
import { screen, fireEvent, waitFor, within } from '@testing-library/react';
|
||||||
|
import '@testing-library/jest-dom';
|
||||||
|
import {
|
||||||
|
setupReady, addMonsterViaUI, startCombatViaUI, MOCK_DB,
|
||||||
|
} from './testHelpers';
|
||||||
|
|
||||||
|
function encounterRow() {
|
||||||
|
const row = [...MOCK_DB._state.docs.entries()].find(([path]) => path.includes('/encounters/'));
|
||||||
|
return row ? { path: row[0], doc: MOCK_DB.get(row[0]) } : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function participant(name) {
|
||||||
|
return encounterRow().doc.participants.find(p => p.name === name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function card(name) {
|
||||||
|
return screen.getByTestId(`admin-participant-card-${participant(name).id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('encounter participant visibility and kill', () => {
|
||||||
|
test('Kill confirms, sets 0 HP/dead/inactive, and does not delete participant', async () => {
|
||||||
|
await setupReady('Kill Camp', 'Kill Encounter');
|
||||||
|
await addMonsterViaUI('Ogre', 59, 1);
|
||||||
|
|
||||||
|
fireEvent.click(within(card('Ogre')).getByRole('button', { name: 'Kill Ogre' }));
|
||||||
|
expect(await screen.findByText('Kill Ogre?')).toBeInTheDocument();
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: /^Cancel$/ }));
|
||||||
|
expect(participant('Ogre')).toMatchObject({ currentHp: 59, isActive: true });
|
||||||
|
|
||||||
|
fireEvent.click(within(card('Ogre')).getByRole('button', { name: 'Kill Ogre' }));
|
||||||
|
fireEvent.click(await screen.findByRole('button', { name: /^Confirm$/ }));
|
||||||
|
await waitFor(() => expect(participant('Ogre')).toMatchObject({ currentHp: 0, tempHp: 0, status: 'dead', isActive: false }));
|
||||||
|
expect(encounterRow().doc.participants).toHaveLength(1);
|
||||||
|
|
||||||
|
const deadCard = card('Ogre');
|
||||||
|
const healFull = within(deadCard).getByRole('button', { name: 'Heal Ogre to full' });
|
||||||
|
const revive = within(deadCard).getByRole('button', { name: /Revive/i });
|
||||||
|
expect(healFull.compareDocumentPosition(revive) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||||
|
fireEvent.click(healFull);
|
||||||
|
await waitFor(() => expect(participant('Ogre')).toMatchObject({ currentHp: 59, status: 'conscious', isActive: true }));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Hide dead never hides player characters', async () => {
|
||||||
|
await setupReady('PC Visibility Camp', 'PC Visibility Encounter');
|
||||||
|
await addMonsterViaUI('Dead Monster', 10, 1);
|
||||||
|
|
||||||
|
fireEvent.change(screen.getByLabelText('Name', { selector: '#characterName' }), { target: { value: 'Dead Hero' } });
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: 'Add Character' }));
|
||||||
|
await screen.findByText('Dead Hero');
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: /Add All \(Roll Init\)/i }));
|
||||||
|
await waitFor(() => expect(participant('Dead Hero')).toBeDefined());
|
||||||
|
|
||||||
|
for (const name of ['Dead Monster', 'Dead Hero']) {
|
||||||
|
fireEvent.click(within(card(name)).getByRole('button', { name: `Kill ${name}` }));
|
||||||
|
fireEvent.click(await screen.findByRole('button', { name: /^Confirm$/ }));
|
||||||
|
await waitFor(() => expect(participant(name).status).toBe('dead'));
|
||||||
|
await waitFor(() => expect(screen.queryByText(`Kill ${name}?`)).not.toBeInTheDocument());
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(screen.getByRole('button', { name: /Hide dead \(1\)/i })).toBeInTheDocument();
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: /Hide dead \(1\)/i }));
|
||||||
|
await waitFor(() => expect(screen.queryByText('Dead Monster')).not.toBeInTheDocument());
|
||||||
|
expect(screen.getByTestId(`admin-participant-card-${participant('Dead Hero').id}`)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Hide disabled and Hide dead are independent, persisted, and unchanged by pause', async () => {
|
||||||
|
await setupReady('Visibility Camp', 'Visibility Encounter');
|
||||||
|
await addMonsterViaUI('Alive', 10, 3);
|
||||||
|
await addMonsterViaUI('Disabled', 10, 2);
|
||||||
|
await addMonsterViaUI('Dead', 10, 1);
|
||||||
|
|
||||||
|
fireEvent.click(within(card('Disabled')).getByRole('button', { name: 'Disable participant' }));
|
||||||
|
await waitFor(() => expect(participant('Disabled').isActive).toBe(false));
|
||||||
|
fireEvent.click(within(card('Dead')).getByRole('button', { name: 'Kill Dead' }));
|
||||||
|
fireEvent.click(await screen.findByRole('button', { name: /^Confirm$/ }));
|
||||||
|
await waitFor(() => expect(participant('Dead').status).toBe('dead'));
|
||||||
|
|
||||||
|
// Disabled count includes dead+inactive. Filters overlap independently.
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: /Hide disabled \(2\)/i }));
|
||||||
|
await waitFor(() => expect(encounterRow().doc.hideDisabledParticipants).toBe(true));
|
||||||
|
expect(screen.queryByText('Disabled')).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Dead')).not.toBeInTheDocument();
|
||||||
|
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: /Show disabled \(2\)/i }));
|
||||||
|
await waitFor(() => expect(screen.getByText('Disabled')).toBeInTheDocument());
|
||||||
|
expect(screen.getByText('Dead')).toBeInTheDocument();
|
||||||
|
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: /Hide dead \(1\)/i }));
|
||||||
|
await waitFor(() => expect(encounterRow().doc.hideDeadParticipants).toBe(true));
|
||||||
|
expect(screen.queryByText('Dead')).not.toBeInTheDocument();
|
||||||
|
expect(screen.getByText('Disabled')).toBeInTheDocument();
|
||||||
|
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: /Hide disabled \(2\)/i }));
|
||||||
|
await waitFor(() => expect(encounterRow().doc.hideDisabledParticipants).toBe(true));
|
||||||
|
await startCombatViaUI();
|
||||||
|
expect(screen.queryByText('Disabled')).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Dead')).not.toBeInTheDocument();
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: /Pause Combat/i }));
|
||||||
|
expect(screen.queryByText('Disabled')).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Dead')).not.toBeInTheDocument();
|
||||||
|
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: /Show disabled \(2\)/i }));
|
||||||
|
await waitFor(() => expect(screen.getByText('Disabled')).toBeInTheDocument());
|
||||||
|
expect(screen.queryByText('Dead')).not.toBeInTheDocument();
|
||||||
|
expect(encounterRow().doc.hideDeadParticipants).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user