All files / player-browser/src/view/beatoraja option-refs.ts

100% Statements 7/7
90.9% Branches 20/22
100% Functions 2/2
100% Lines 6/6

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 40 41 42 43                          6x 2x 2x                             6x 6x 6x                    
import type { BeMusicJSON } from '@be-music/chart-source';
import type { PlayOptions } from '@be-music/player-scene-model';
import {
  resolveBeatorajaOptionIndex,
  resolveBeatorajaPlayOptionIndex,
  type BeatorajaOptionIndexInput,
} from '@be-music/skin-beatoraja/scene';
 
/**
 * The long-note mode a chart names itself (`#LNMODE`, bmson `ln_type`), numbered from 1; `undefined` for a chart that
 * leaves it to the player's LN MODE.
 */
export function chartOwnLongNoteMode(json: BeMusicJSON): number | undefined {
  if (json.sourceFormat === 'bms') return json.bms.lnMode;
  const lnType = json.bmson.info.lnType;
  return lnType === undefined || lnType === 0 ? undefined : lnType;
}
 
/**
 * The image index of an option image on beatoraja's decide, play and result screens: the LNMODE image shows the
 * chart's own mode on the play and result screens (`chart`), else the player's LN MODE, and the option buttons' labels
 * read the play options. `undefined` for a ref that is no option image.
 */
export function resolveBeatorajaOptionRef(
  ref: number,
  input: { chart?: BeMusicJSON; playOptions?: Partial<PlayOptions> } & Omit<
    BeatorajaOptionIndexInput,
    'lnMode' | 'longNoteMode' | 'hsFix'
  >,
): number | undefined {
  const playOptions = input.playOptions ?? {};
  const lnMode = input.chart === undefined ? undefined : chartOwnLongNoteMode(input.chart);
  return (
    resolveBeatorajaOptionIndex(ref, {
      ...(lnMode !== undefined ? { lnMode } : {}),
      ...(playOptions.longNoteMode !== undefined ? { longNoteMode: playOptions.longNoteMode } : {}),
      ...(playOptions.hsFix !== undefined ? { hsFix: playOptions.hsFix } : {}),
      ...(input.lamp !== undefined ? { lamp: input.lamp } : {}),
      ...(input.lampOp !== undefined ? { lampOp: input.lampOp } : {}),
    }) ?? resolveBeatorajaPlayOptionIndex(ref, playOptions)
  );
}