diff --git a/shared/tests/turn.characterization.test.js b/shared/tests/turn.characterization.test.js index 3457c2e..9ec161f 100644 --- a/shared/tests/turn.characterization.test.js +++ b/shared/tests/turn.characterization.test.js @@ -6,7 +6,6 @@ const shared = require('@ttrpg/shared'); const { sortParticipantsByInitiative, computeTurnOrderAfterRemoval, - computeTurnOrderAfterAddition, startEncounter, nextTurn, togglePause, @@ -326,26 +325,6 @@ describe('computeTurnOrderAfterRemoval', () => { }); }); -describe('computeTurnOrderAfterAddition', () => { - test('not started = empty', () => { - const out = computeTurnOrderAfterAddition(enc([]), 'a'); - expect(out).toEqual({}); - }); - - test('returns insertAt (1-list: caller splices + syncs)', () => { - const e = enc([p('a',3)], { isStarted: true, turnOrderIds: ['a'], participants: [p('a',3)] }); - const out = computeTurnOrderAfterAddition(e, 'a'); - // already present → no-op - expect(out).toEqual({}); - }); - - test('no-op if already present', () => { - const e = enc([], { isStarted: true, turnOrderIds: ['a', 'b'] }); - const out = computeTurnOrderAfterAddition(e, 'a'); - expect(out).toEqual({}); - }); -}); - describe('addParticipant', () => { test('appends participant', () => { const np = p('z', 7); diff --git a/shared/turn.js b/shared/turn.js index b87fc71..f57b102 100644 --- a/shared/turn.js +++ b/shared/turn.js @@ -114,26 +114,6 @@ const computeTurnOrderAfterRemoval = (encounter, removedId, updatedParticipants) // current pointer — no re-sort anywhere except startEncounter. // Tie rule: insert AFTER existing same-init (preserves creation order). // NOTE: 1-list model — caller syncs participants[] in same pos as insert target. -const computeTurnOrderAfterAddition = (encounter, addedId) => { - if (!encounter.isStarted) return {}; - const currentIds = encounter.turnOrderIds || []; - if (currentIds.includes(addedId)) return {}; - const added = (encounter.participants || []).find(p => p.id === addedId); - if (!added) return {}; - // find first id with strictly lower initiative; insert before it (== after all >= ) - const initOf = id => { - const p = (encounter.participants || []).find(x => x.id === id); - return p ? (p.initiative || 0) : 0; - }; - const addedInit = added.initiative || 0; - let insertAt = currentIds.length; - for (let i = 0; i < currentIds.length; i++) { - if (initOf(currentIds[i]) < addedInit) { insertAt = i; break; } - } - return { insertAt }; // caller splices participants[] at this pos, then syncs -}; - -// ---------------------------------------------------------------------------- // Participant factory (mirrors ParticipantManager.handleAddParticipant shape) // ---------------------------------------------------------------------------- @@ -326,7 +306,7 @@ function togglePause(encounter) { // ADD_PARTICIPANT — appends participant. (Initiative rolled by caller via build*.) // If encounter already started, also slot participant into turnOrderIds by -// initiative (via computeTurnOrderAfterAddition). +// initiative (slotIndexForInit). 1-list model. function addParticipant(encounter, participant) { if ((encounter.participants || []).some(p => p.id === participant.id)) { throw new Error(`Participant with id "${participant.id}" already exists in encounter.`); @@ -630,7 +610,6 @@ module.exports = { sortParticipantsByInitiative, syncTurnOrder, computeTurnOrderAfterRemoval, - computeTurnOrderAfterAddition, makeParticipant, buildCharacterParticipant, buildMonsterParticipant,