feat: reroll initiative in participant editor with persisted init mod
Add a dice button beside the Initiative field in the participant edit modal that rolls d20 + Init Mod; Cancel/Save guard accidental changes. Persist initMod on participant creation (quick-add monster, roster character/NPC, Add All) and expose it as an editable field in the modal. Roster NPCs added via the character dropdown now enter as npc type, and the duplicate guard keys on originalCharacterId regardless of type.
This commit is contained in:
1 parent
05e8c262b7
commit
8ecd31d570
3 files changed
+134
-7
No files matched your search
+39
-7
@@ -606,6 +606,7 @@ function CreateEncounterForm({ onCreate, onCancel, defaultRuleset = '5e' }) {
|
||||
function EditParticipantModal({ participant, onClose, onSave }) {
|
||||
const [name, setName] = useState(participant.name);
|
||||
const [initiative, setInitiative] = useState(participant.initiative);
|
||||
const [initMod, setInitMod] = useState(participant.initMod != null ? participant.initMod : '');
|
||||
const [currentHp, setCurrentHp] = useState(participant.currentHp);
|
||||
const [maxHp, setMaxHp] = useState(participant.maxHp);
|
||||
const [hpFormula, setHpFormula] = useState(participant.hpFormula || '');
|
||||
@@ -627,6 +628,7 @@ function EditParticipantModal({ participant, onClose, onSave }) {
|
||||
onSave({
|
||||
name: name.trim(),
|
||||
initiative: parseInt(initiative, 10),
|
||||
initMod: initMod !== '' ? parseInt(initMod, 10) : null,
|
||||
currentHp: finalCurrentHp,
|
||||
maxHp: finalMaxHp,
|
||||
hpFormula: (participant.type === 'monster' || participant.type === 'npc') ? (hpFormula.trim() || null) : null,
|
||||
@@ -650,15 +652,37 @@ function EditParticipantModal({ participant, onClose, onSave }) {
|
||||
</div>
|
||||
<div className="flex gap-4">
|
||||
<div className="flex-1">
|
||||
<label htmlFor="edit-initiative" className="block text-sm font-medium text-stone-300">Initiative</label>
|
||||
<label htmlFor="edit-initmod" className="block text-sm font-medium text-stone-300">Init Mod</label>
|
||||
<input
|
||||
type="number"
|
||||
id="edit-initiative"
|
||||
value={initiative}
|
||||
onChange={(e) => setInitiative(e.target.value)}
|
||||
id="edit-initmod"
|
||||
value={initMod}
|
||||
onChange={(e) => setInitMod(e.target.value)}
|
||||
placeholder="0"
|
||||
className="mt-1 block w-full px-3 py-2 bg-stone-800 border border-stone-700 rounded-md shadow-sm focus:outline-none focus:ring-amber-600 focus:border-amber-600 sm:text-sm text-white"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<label htmlFor="edit-initiative" className="block text-sm font-medium text-stone-300">Initiative</label>
|
||||
<div className="mt-1 flex gap-2">
|
||||
<input
|
||||
type="number"
|
||||
id="edit-initiative"
|
||||
value={initiative}
|
||||
onChange={(e) => setInitiative(e.target.value)}
|
||||
className="block w-full px-3 py-2 bg-stone-800 border border-stone-700 rounded-md shadow-sm focus:outline-none focus:ring-amber-600 focus:border-amber-600 sm:text-sm text-white"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setInitiative(rollD20() + (parseInt(initMod, 10) || 0))}
|
||||
aria-label="Reroll initiative"
|
||||
title="Roll d20 + Init Mod"
|
||||
className="px-3 py-2 text-sm font-medium text-white bg-violet-700 hover:bg-violet-800 rounded-md transition-colors flex items-center"
|
||||
>
|
||||
<Dices size={16} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<label className="block text-sm font-medium text-stone-300">AC</label>
|
||||
<input
|
||||
@@ -1232,7 +1256,7 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
|
||||
if (!character) {
|
||||
return;
|
||||
}
|
||||
if (participants.some(p => p.type === 'character' && p.originalCharacterId === selectedCharacterId)) {
|
||||
if (participants.some(p => p.originalCharacterId === selectedCharacterId)) {
|
||||
showInfo(`${character.name} is already in this encounter.`);
|
||||
return;
|
||||
}
|
||||
@@ -1249,13 +1273,20 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
|
||||
}
|
||||
}
|
||||
|
||||
let finalType = participantType;
|
||||
if (participantType === 'monster' && participantAsNpc) finalType = 'npc';
|
||||
if (participantType === 'character') {
|
||||
const character = campaignCharacters.find(c => c.id === selectedCharacterId);
|
||||
if (character?.isNpc) finalType = 'npc';
|
||||
}
|
||||
const computedInitiative = manualInit ? finalInitiative : (initiativeRoll + modifier);
|
||||
const newParticipant = {
|
||||
id: generateId(),
|
||||
name: nameToAdd,
|
||||
type: participantType === 'monster' && participantAsNpc ? 'npc' : participantType,
|
||||
originalCharacterId: participantType === 'character' ? selectedCharacterId : null,
|
||||
type: finalType,
|
||||
originalCharacterId: ['character', 'npc'].includes(finalType) ? selectedCharacterId : null,
|
||||
initiative: computedInitiative,
|
||||
initMod: modifier,
|
||||
maxHp: currentMaxHp,
|
||||
currentHp: currentMaxHp,
|
||||
hpFormula: participantType === 'monster' ? (hpFormula.trim() || null) : null,
|
||||
@@ -1311,6 +1342,7 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
|
||||
type: 'character',
|
||||
originalCharacterId: char.id,
|
||||
initiative: finalInitiative,
|
||||
initMod: modifier,
|
||||
maxHp: char.defaultMaxHp || DEFAULT_MAX_HP,
|
||||
currentHp: char.defaultMaxHp || DEFAULT_MAX_HP,
|
||||
conditions: [],
|
||||
|
||||
Reference in new issue
Block a user