All files / player-browser/src/session/play lr2-sort-objects.ts

83.33% Statements 15/18
72.72% Branches 8/11
100% Functions 2/2
86.66% Lines 13/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39      44x                             16x 16x 16x 84x 16x   16x 16000x 16000x         16x 84x 84x     16x    
import type { ResolvedChart } from '@be-music/chart-model';
 
// These objects do not take a destination but still affect the permutation of equal-time notes.
const NON_LANE_OPS = new Map([
  ['01', 1],
  ['03', 3],
  ['04', 4],
  ['05', 5],
  ['06', 6],
  ['07', 7],
  ['08', 8],
  ['09', 9],
]);
 
export function collectLR2SortObjects(
  chart: ResolvedChart,
  course = false,
): Array<{ order: number; timeMs: number; op: number }> {
  const { beatResolver, timing } = chart;
  const objects = [];
  if (chart.sourceFormat === 'bms') {
    Eif (!course && !chart.sortedEvents.some(({ channel }) => channel === '04' || channel === '07'))
      objects.push({ order: 0, timeMs: 0, op: 4 });
    // LR2's BMS loader creates 1,000 measure records per stage before it sorts.
    for (let measure = 0; measure < 1000; measure++) {
      const beat = beatResolver.measureToBeat(measure);
      objects.push({ order: beat, timeMs: timing.beatToSeconds(beat) * 1000, op: 2 });
    }
  } else E{
    for (const beat of chart.barLines) objects.push({ order: beat, timeMs: timing.beatToSeconds(beat) * 1000, op: 2 });
  }
  for (const event of chart.sortedEvents) {
    const op = NON_LANE_OPS.get(event.channel);
    Iif (op !== undefined)
      objects.push({ order: beatResolver.eventToBeat(event), timeMs: timing.eventToSeconds(event) * 1000, op });
  }
  return objects;
}