From c72b88f8bb86a2f4744e43b64f33fde0597d93c7 Mon Sep 17 00:00:00 2001 From: david raistrick <1108844+keen99@users.noreply.github.com> Date: Wed, 1 Jul 2026 12:00:23 -0400 Subject: [PATCH] WIP turn.js: computeTurnOrderAfterRemoval bumps round on wrap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removal of current participant when no active after → advance to order[0] + bump round. Without bump, nextTurn replays whole round (BUG-5 pattern). Parser 500-40b: 24 skips/1 double (was 46/64). Down not zero. Remaining skips = replay async stale read (getDoc between turns), not turn.js. --- shared/turn.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/shared/turn.js b/shared/turn.js index eaafe7e..57c7835 100644 --- a/shared/turn.js +++ b/shared/turn.js @@ -52,9 +52,22 @@ const computeTurnOrderAfterRemoval = (encounter, removedId, updatedParticipants) const updates = { turnOrderIds: newIds }; if (encounter.currentTurnParticipantId === removedId) { const removedPos = currentIds.indexOf(removedId); - const candidates = [...currentIds.slice(removedPos + 1), ...currentIds.slice(0, removedPos)]; - const nextId = candidates.find(id => updatedParticipants.find(p => p.id === id && p.isActive)) ?? null; - updates.currentTurnParticipantId = nextId; + // first try next-active AFTER removed (same round, no wrap) + const after = currentIds.slice(removedPos + 1); + 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; };