diff --git a/TODO.md b/TODO.md index 8bee996..cad823e 100644 --- a/TODO.md +++ b/TODO.md @@ -5,6 +5,12 @@ REWORK_PLAN.md. ## Feature backlog +### CRITICAL BUG - storage + - docker for sql is not using persistant storage... + +### feat - campaign section rollup + + ### FEAT-M6: Transactional undo (moved from REWORK_PLAN) - Every mutating action writes event: `(type, payload, undo_payload, undone, ts)`. - Undo = apply `undo_payload` in same SQLite tx, flip `undone`. Transactional, @@ -17,7 +23,7 @@ REWORK_PLAN.md. ## Architecture: 1-list turn order model (DONE) - Single source: turnOrderIds === participants.map(id). No re-sort after startEncounter. nextTurn skips inactive (predicate), inactive stay in slot. -- Drag (reorder) overrides initiative — cross-init allowed, DM choice. +- Drag (reorder) overrides initiative --- cross-init allowed, DM choice. - startEncounter sorts ALL participants by init once, then frozen. - addParticipant splices by init pos. remove/toggle/reorder sync list. - Display renders participants[] directly (no sortParticipantsByInitiative). @@ -31,7 +37,7 @@ REWORK_PLAN.md. - Separate design + RED. Own work item. - Related: tie-break = drag order (current, works). Expose clearly. -### FEAT-1: Dead participants stay in turn order — DONE +### FEAT-1: Dead participants stay in turn order --- DONE - Fixed: `applyHpChange` no longer flips `isActive` or touches `turnOrderIds` on death/revive. Dead stay in rotation, `nextTurn` visits them, PCs get death-save turn. `isActive` = DM toggle only. @@ -40,7 +46,7 @@ REWORK_PLAN.md. ### FEAT-2: upgrade app internal logs to be parseable - Goal: combat logs in Firestore store enough structured state to run - skip/rotation analysis on ANY historic round — not just replay stdout. + skip/rotation analysis on ANY historic round --- not just replay stdout. - Current logs: `{timestamp, message, encounterName, undo}`. Parser must guess roster from message strings. Brittle. - Upgrade: add structured fields at turn-state mutation log sites in @@ -104,12 +110,12 @@ REWORK_PLAN.md. - Test: render App + DisplayView, toggle hide-HP, assert display still shows encounter (not paused). -### BUG-5: mid-round addParticipant/revive corrupts rotation — FIXED +### BUG-5: mid-round addParticipant/revive corrupts rotation --- FIXED - Fixed (commit `494327f`). Slot-array turn order + DRY advance core `nextActiveAfter`. Both nextTurn + computeTurnOrderAfterRemoval delegate. - 500-round replay: 0 skips, 0 double-acts. -### BUG-6: reorderParticipants doesn't update turnOrderIds — FIXED +### BUG-6: reorderParticipants doesn't update turnOrderIds --- FIXED - Fixed structurally by 1-list model (commit 5d3a060). turnOrderIds = participants.map(id) always. reorder cross-init allowed (DM override). Display === rotation by construction. @@ -181,8 +187,8 @@ REWORK_PLAN.md. - [ ] BUG-4: fix setDoc→updateDoc for all 5 activeDisplay sites - [x] BUG-5: fixed (1-list model, 500 rounds clean) - [x] BUG-6: fixed structurally (1-list model) -- [x] BUG-12: fixed — campaign selection follows activeDisplay -- [x] BUG-15: fixed — DisplayView no longer re-sorts (drag order preserved) +- [x] BUG-12: fixed --- campaign selection follows activeDisplay +- [x] BUG-15: fixed --- DisplayView no longer re-sorts (drag order preserved) - [x] BUG-8: ws adapter reconnect (implemented + GREEN) - [ ] BUG-10: deact+reactivate double-act - [ ] BUG-11: FE Combat.scenario crash diff --git a/src/App.js b/src/App.js index d451fa0..c5ccbef 100644 --- a/src/App.js +++ b/src/App.js @@ -8,7 +8,7 @@ import { UserCheck, UserX, HeartCrack, HeartPulse, Zap, EyeOff, ExternalLink, AlertTriangle, Play as PlayIcon, Pause as PauseIcon, SkipForward as SkipForwardIcon, StopCircle as StopCircleIcon, Users2, Dices, ChevronUp, ChevronDown, ScrollText, - Maximize2, Minimize2, Moon, Coffee + Maximize2, Minimize2, Moon, Coffee, Clock } from 'lucide-react'; // Custom CSS for death animation (player view only) @@ -781,6 +781,7 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters }) { const [selectedCharacterId, setSelectedCharacterId] = useState(''); const [monsterInitMod, setMonsterInitMod] = useState(MONSTER_DEFAULT_INIT_MOD); const [maxHp, setMaxHp] = useState(DEFAULT_MAX_HP); + const [manualInitiative, setManualInitiative] = useState(''); const [isNpc, setIsNpc] = useState(false); const [editingParticipant, setEditingParticipant] = useState(null); const [hpChangeValues, setHpChangeValues] = useState({}); @@ -817,6 +818,8 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters }) { let modifier = 0; let currentMaxHp = parseInt(maxHp, 10) || DEFAULT_MAX_HP; let participantIsNpc = false; + const manualInit = manualInitiative !== '' && !isNaN(parseInt(manualInitiative, 10)); + const finalInitiative = manualInit ? parseInt(manualInitiative, 10) : null; if (participantType === 'character') { const character = campaignCharacters.find(c => c.id === selectedCharacterId); @@ -836,13 +839,13 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters }) { participantIsNpc = isNpc; } - const finalInitiative = initiativeRoll + modifier; + const computedInitiative = manualInit ? finalInitiative : (initiativeRoll + modifier); const newParticipant = { id: generateId(), name: nameToAdd, type: participantType, originalCharacterId: participantType === 'character' ? selectedCharacterId : null, - initiative: finalInitiative, + initiative: computedInitiative, maxHp: currentMaxHp, currentHp: currentMaxHp, isNpc: participantType === 'monster' ? participantIsNpc : false, @@ -856,17 +859,18 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters }) { await storage.updateDoc(encounterPath, { participants: [...participants, newParticipant] }); - logAction(`${nameToAdd} added to encounter (Initiative: ${finalInitiative})`, { encounterName: encounter.name }, { + logAction(`${nameToAdd} added to encounter (Initiative: ${computedInitiative})`, { encounterName: encounter.name }, { encounterPath, updates: { participants: [...participants] }, }); setLastRollDetails({ name: nameToAdd, - roll: initiativeRoll, - mod: modifier, - total: finalInitiative, - type: participantIsNpc ? 'NPC' : participantType + roll: manualInit ? null : initiativeRoll, + mod: manualInit ? null : modifier, + total: computedInitiative, + type: participantIsNpc ? 'NPC' : participantType, + manual: manualInit, }); setTimeout(() => setLastRollDetails(null), ROLL_DISPLAY_DURATION); @@ -876,6 +880,7 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters }) { setSelectedCharacterId(''); setMonsterInitMod(MONSTER_DEFAULT_INIT_MOD); setIsNpc(false); + setManualInitiative(''); } catch (err) { console.error("Error adding participant:", err); alert("Failed to add participant. Please try again."); @@ -944,6 +949,24 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters }) { } }; + // Inline initiative edit (FEAT-3): blur/Enter commits. Re-syncs turnOrderIds. + const handleInlineInitiative = async (participantId, value) => { + if (!db) return; + const n = parseInt(value, 10); + if (isNaN(n)) return; + const updatedParticipants = participants.map(p => + p.id === participantId ? { ...p, initiative: n } : p + ); + try { + await storage.updateDoc(encounterPath, { + participants: updatedParticipants, + ...(encounter.isStarted ? syncTurnOrder(updatedParticipants) : {}), + }); + } catch (err) { + console.error("Error updating initiative:", err); + } + }; + const requestDeleteParticipant = (participantId, participantName) => { setItemToDelete({ id: participantId, name: participantName }); setShowDeleteConfirm(true); @@ -1307,6 +1330,19 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters }) { className="mt-1 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" /> +
+ + setManualInitiative(e.target.value)} + placeholder="auto" + className="mt-1 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" + /> +
+
+ + setManualInitiative(e.target.value)} + placeholder="auto" + className="mt-1 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" + /> +
)} @@ -1375,8 +1424,10 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters }) { {lastRollDetails && (

- {lastRollDetails.name} ({lastRollDetails.type === 'character' ? 'Character' : lastRollDetails.type === 'monster' ? 'Monster' : lastRollDetails.type}) - : Rolled d20 ({lastRollDetails.roll}) {formatInitMod(lastRollDetails.mod)} = {lastRollDetails.total} Initiative + {lastRollDetails.manual + ? `${lastRollDetails.name} (${lastRollDetails.type === 'character' ? 'Character' : lastRollDetails.type === 'monster' ? 'Monster' : lastRollDetails.type}): Set initiative ${lastRollDetails.total}` + : `${lastRollDetails.name} (${lastRollDetails.type === 'character' ? 'Character' : lastRollDetails.type === 'monster' ? 'Monster' : lastRollDetails.type}): Rolled d20 (${lastRollDetails.roll}) ${formatInitMod(lastRollDetails.mod)} = ${lastRollDetails.total} Initiative` + }

)} @@ -1422,9 +1473,26 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters }) { )} {isDead && {p.type === 'character' ? '(Unconscious)' : '(Dead)'}}

-

- Init: {p.initiative} | HP: {p.currentHp}/{p.maxHp} -

+
+ + + { if (e.target.value.length > 2) e.target.value = e.target.value.slice(0, 2); }} + onFocus={(e) => e.target.select()} + onBlur={(e) => { if (e.target.value !== String(p.initiative)) handleInlineInitiative(p.id, e.target.value); }} + onKeyDown={(e) => { if (e.key === 'Enter') e.target.blur(); }} + className="w-10 px-1 py-0.5 bg-stone-800 border border-stone-700 rounded-md shadow-sm text-white text-sm focus:outline-none focus:ring-1 focus:ring-amber-600 focus:border-amber-600" + aria-label={`Initiative for ${p.name}`} + /> + + HP: {p.currentHp}/{p.maxHp} +
{/* Death Saves - only player characters make death saving throws */} {isDead && encounter.isStarted && p.type === 'character' && ( @@ -2283,12 +2351,12 @@ function AdminView({ userId }) { {campaign.encounterCount === undefined ? '...' : campaign.encounterCount} Encounters - {campaign.createdAt && ( - - {new Date(campaign.createdAt).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', hour12: false })} - - )} + {campaign.createdAt && ( +
+ Created: {new Date(campaign.createdAt).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', hour12: false })} +
+ )}