Rework backend #1

Merged
robert merged 86 commits from rework-backend into main 2026-07-01 19:29:34 -04:00
Showing only changes of commit 7c3ec105d5 - Show all commits
+11 -6
View File
@@ -1213,7 +1213,8 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters }) {
setDraggedItemId(null); setDraggedItemId(null);
}; };
const sortedParticipants = sortParticipantsByInitiative(participants, participants); // 1-list model: participants[] IS the display order. No re-sort.
const sortedParticipants = participants;
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;
@@ -1595,14 +1596,18 @@ function InitiativeControls({ campaignId, encounter, encounterPath }) {
return; return;
} }
const sortedParticipants = sortParticipantsByInitiative(activeParticipants, encounter.participants); // 1-list model: sort ALL participants by init (active+inactive),
// first active = current. Matches shared.startEncounter.
const sortedParticipants = sortParticipantsByInitiative(encounter.participants, encounter.participants);
const firstActive = sortedParticipants.find(p => p.isActive);
try { try {
await storage.updateDoc(encounterPath, { await storage.updateDoc(encounterPath, {
isStarted: true, isStarted: true,
isPaused: false, isPaused: false,
round: 1, round: 1,
currentTurnParticipantId: sortedParticipants[0].id, participants: sortedParticipants,
currentTurnParticipantId: firstActive.id,
turnOrderIds: sortedParticipants.map(p => p.id) turnOrderIds: sortedParticipants.map(p => p.id)
}); });
@@ -1635,9 +1640,9 @@ function InitiativeControls({ campaignId, encounter, encounterPath }) {
let newTurnOrderIds = encounter.turnOrderIds; let newTurnOrderIds = encounter.turnOrderIds;
if (!newPausedState && encounter.isPaused) { if (!newPausedState && encounter.isPaused) {
const activeParticipants = encounter.participants.filter(p => p.isActive); // 1-list model: no re-sort on resume. turnOrderIds already mirrors
const sortedParticipants = sortParticipantsByInitiative(activeParticipants, encounter.participants); // participants[] (set at start/add/reorder). Resume = unpause only.
newTurnOrderIds = sortedParticipants.map(p => p.id); newTurnOrderIds = encounter.turnOrderIds;
} }
try { try {