Rework backend #1
+11
-6
@@ -1213,7 +1213,8 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters }) {
|
||||
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) => {
|
||||
acc[p.initiative] = (acc[p.initiative] || 0) + 1;
|
||||
@@ -1595,14 +1596,18 @@ function InitiativeControls({ campaignId, encounter, encounterPath }) {
|
||||
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 {
|
||||
await storage.updateDoc(encounterPath, {
|
||||
isStarted: true,
|
||||
isPaused: false,
|
||||
round: 1,
|
||||
currentTurnParticipantId: sortedParticipants[0].id,
|
||||
participants: sortedParticipants,
|
||||
currentTurnParticipantId: firstActive.id,
|
||||
turnOrderIds: sortedParticipants.map(p => p.id)
|
||||
});
|
||||
|
||||
@@ -1635,9 +1640,9 @@ function InitiativeControls({ campaignId, encounter, encounterPath }) {
|
||||
let newTurnOrderIds = encounter.turnOrderIds;
|
||||
|
||||
if (!newPausedState && encounter.isPaused) {
|
||||
const activeParticipants = encounter.participants.filter(p => p.isActive);
|
||||
const sortedParticipants = sortParticipantsByInitiative(activeParticipants, encounter.participants);
|
||||
newTurnOrderIds = sortedParticipants.map(p => p.id);
|
||||
// 1-list model: no re-sort on resume. turnOrderIds already mirrors
|
||||
// participants[] (set at start/add/reorder). Resume = unpause only.
|
||||
newTurnOrderIds = encounter.turnOrderIds;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user