refactor(turn): remove dead computeTurnOrderAfterAddition
Zero call sites. Old turn-array addition logic, superseded by 1-list slotIndexForInit model. Removed func, export, stale comment, and 3 characterization tests that only locked the dead func's behavior.
This commit is contained in:
@@ -6,7 +6,6 @@ const shared = require('@ttrpg/shared');
|
|||||||
const {
|
const {
|
||||||
sortParticipantsByInitiative,
|
sortParticipantsByInitiative,
|
||||||
computeTurnOrderAfterRemoval,
|
computeTurnOrderAfterRemoval,
|
||||||
computeTurnOrderAfterAddition,
|
|
||||||
startEncounter,
|
startEncounter,
|
||||||
nextTurn,
|
nextTurn,
|
||||||
togglePause,
|
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', () => {
|
describe('addParticipant', () => {
|
||||||
test('appends participant', () => {
|
test('appends participant', () => {
|
||||||
const np = p('z', 7);
|
const np = p('z', 7);
|
||||||
|
|||||||
+1
-22
@@ -114,26 +114,6 @@ const computeTurnOrderAfterRemoval = (encounter, removedId, updatedParticipants)
|
|||||||
// current pointer — no re-sort anywhere except startEncounter.
|
// current pointer — no re-sort anywhere except startEncounter.
|
||||||
// Tie rule: insert AFTER existing same-init (preserves creation order).
|
// Tie rule: insert AFTER existing same-init (preserves creation order).
|
||||||
// NOTE: 1-list model — caller syncs participants[] in same pos as insert target.
|
// 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)
|
// Participant factory (mirrors ParticipantManager.handleAddParticipant shape)
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -326,7 +306,7 @@ function togglePause(encounter) {
|
|||||||
|
|
||||||
// ADD_PARTICIPANT — appends participant. (Initiative rolled by caller via build*.)
|
// ADD_PARTICIPANT — appends participant. (Initiative rolled by caller via build*.)
|
||||||
// If encounter already started, also slot participant into turnOrderIds by
|
// If encounter already started, also slot participant into turnOrderIds by
|
||||||
// initiative (via computeTurnOrderAfterAddition).
|
// initiative (slotIndexForInit). 1-list model.
|
||||||
function addParticipant(encounter, participant) {
|
function addParticipant(encounter, participant) {
|
||||||
if ((encounter.participants || []).some(p => p.id === participant.id)) {
|
if ((encounter.participants || []).some(p => p.id === participant.id)) {
|
||||||
throw new Error(`Participant with id "${participant.id}" already exists in encounter.`);
|
throw new Error(`Participant with id "${participant.id}" already exists in encounter.`);
|
||||||
@@ -630,7 +610,6 @@ module.exports = {
|
|||||||
sortParticipantsByInitiative,
|
sortParticipantsByInitiative,
|
||||||
syncTurnOrder,
|
syncTurnOrder,
|
||||||
computeTurnOrderAfterRemoval,
|
computeTurnOrderAfterRemoval,
|
||||||
computeTurnOrderAfterAddition,
|
|
||||||
makeParticipant,
|
makeParticipant,
|
||||||
buildCharacterParticipant,
|
buildCharacterParticipant,
|
||||||
buildMonsterParticipant,
|
buildMonsterParticipant,
|
||||||
|
|||||||
Reference in New Issue
Block a user