All files / skin-beatoraja/src/scene replay-slots.ts

100% Statements 15/15
100% Branches 6/6
100% Functions 4/4
100% Lines 12/12

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 44 45        52x                       9x 9x               3x 12x 3x                 28x 28x 112x   28x 28x 28x    
import type { ReplaySlotState } from '@be-music/player-scene-model';
import { BEATORAJA_BUTTON, BEATORAJA_REPLAY_SLOT_OP } from '../runtime-ids.ts';
 
/** The replay buttons, by slot: `replay1`-`replay4` of beatoraja's `EventFactory` (19, 316-318). */
const REPLAY_BUTTONS: readonly number[] = [
  BEATORAJA_BUTTON.REPLAY,
  BEATORAJA_BUTTON.REPLAY2,
  BEATORAJA_BUTTON.REPLAY3,
  BEATORAJA_BUTTON.REPLAY4,
];
 
/**
 * The replay slot (0-3) a skin button names: on the select screen it plays that slot, on a result screen it saves into
 * it (beatoraja's `getReplayEventConsumer`). `undefined` for any other button.
 */
export function beatorajaReplayButtonSlot(act: number): number | undefined {
  const slot = REPLAY_BUTTONS.indexOf(act);
  return slot >= 0 ? slot : undefined;
}
 
/**
 * The ops a result screen lights for its replay slots (beatoraja's `createReplayProperty` on an `AbstractResult`): one
 * of none / exists / saved per slot.
 */
export function resolveBeatorajaResultReplayOps(slots: readonly ReplaySlotState[]): number[] {
  const ops: number[] = [];
  slots.slice(0, 4).forEach((state, slot) => ops.push(BEATORAJA_REPLAY_SLOT_OP[state][slot]!));
  return ops;
}
 
/**
 * The ops the select screen lights for a chart or course bar's replay slots (beatoraja's `createReplayProperty` on a
 * `SelectableBar`): none or exists per slot, and the slot picked for REPLAY (`OPTION_SELECT_REPLAYDATA`, none when
 * `selected` is −1).
 */
export function resolveBeatorajaSelectReplayOps(exists: readonly boolean[], selected: number): number[] {
  const ops: number[] = [];
  for (let slot = 0; slot < 4; slot += 1) {
    ops.push((exists[slot] === true ? BEATORAJA_REPLAY_SLOT_OP.exists : BEATORAJA_REPLAY_SLOT_OP.none)[slot]!);
  }
  const picked = BEATORAJA_REPLAY_SLOT_OP.selected[selected];
  if (picked !== undefined) ops.push(picked);
  return ops;
}