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 c72b88f8bb - Show all commits
+16 -3
View File
@@ -52,9 +52,22 @@ const computeTurnOrderAfterRemoval = (encounter, removedId, updatedParticipants)
const updates = { turnOrderIds: newIds }; const updates = { turnOrderIds: newIds };
if (encounter.currentTurnParticipantId === removedId) { if (encounter.currentTurnParticipantId === removedId) {
const removedPos = currentIds.indexOf(removedId); const removedPos = currentIds.indexOf(removedId);
const candidates = [...currentIds.slice(removedPos + 1), ...currentIds.slice(0, removedPos)]; // first try next-active AFTER removed (same round, no wrap)
const nextId = candidates.find(id => updatedParticipants.find(p => p.id === id && p.isActive)) ?? null; const after = currentIds.slice(removedPos + 1);
updates.currentTurnParticipantId = nextId; const nextSameRound = after.find(id =>
updatedParticipants.find(p => p.id === id && p.isActive));
if (nextSameRound) {
updates.currentTurnParticipantId = nextSameRound;
} else {
// wrap: no active after removed → advance to first active at top of
// order AND bump round. Without the bump, nextTurn sees current already
// at order[0] and replays the whole round (BUG-5).
const before = currentIds.slice(0, removedPos);
const nextId = before.find(id =>
updatedParticipants.find(p => p.id === id && p.isActive)) ?? null;
updates.currentTurnParticipantId = nextId;
if (nextId) updates.round = (encounter.round || 1) + 1;
}
} }
return updates; return updates;
}; };