WIP turn.js: computeTurnOrderAfterRemoval bumps round on wrap
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.
This commit is contained in:
+15
-2
@@ -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);
|
||||||
|
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;
|
updates.currentTurnParticipantId = nextId;
|
||||||
|
if (nextId) updates.round = (encounter.round || 1) + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return updates;
|
return updates;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user