All files / player-engine/src/core auto-scratch.ts

100% Statements 9/9
100% Branches 16/16
100% Functions 2/2
100% Lines 8/8

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                        20044x                     11205x 11205x 11205x 764x 605x 532x     764x    
/** Source AUTO SCRATCH switches, independently per play side. The older combined switch is a fallback only. */
export interface AutoScratchOptions {
  autoScratch?: boolean;
  autoScratch1P?: boolean;
  autoScratch2P?: boolean;
}
 
/** An explicit side switch takes precedence over the older combined setting for that side. */
export function resolveAutoScratchSides(options: Readonly<AutoScratchOptions>): {
  autoScratch1P: boolean;
  autoScratch2P: boolean;
} {
  return {
    autoScratch1P: options.autoScratch1P ?? options.autoScratch ?? false,
    autoScratch2P: options.autoScratch2P ?? options.autoScratch ?? false,
  };
}
 
/** Filters the chart's already-identified scratch channels to the sides actually assisted. */
export function resolveAutoScratchChannels(
  options: Readonly<AutoScratchOptions>,
  scratchChannels: Iterable<string>,
): ReadonlySet<string> {
  const sides = resolveAutoScratchSides(options);
  const channels = new Set<string>();
  if (!sides.autoScratch1P && !sides.autoScratch2P) return channels;
  for (const channel of scratchChannels) {
    if (channel.startsWith('1') ? sides.autoScratch1P : channel.startsWith('2') && sides.autoScratch2P) {
      channels.add(channel);
    }
  }
  return channels;
}