All files / app-play/src chart-shape.ts

80% Statements 8/10
57.89% Branches 11/19
100% Functions 3/3
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58                          14x       14x                     14x                               10x 10x 10x 10x               6x    
import {
  pickBeatorajaPlayableSkinVariant,
  pickBeatorajaPlayableVariant,
  type BeatorajaPlayableVariant,
  type BeatorajaThemeBundle,
} from '@be-music/player-browser/skin';
import { resolveLibraryChartPlayVariant, type LibraryChart } from '@be-music/player-scene-model';
 
/**
 * Maps a song's parsed chart variant onto the `{ keys, isDouble, isPMS }` shape `pickBeatorajaPlayableVariant`
 * expects. Pure derivation — no state, no side effects.
 */
export function chartShapeFor(chartEntry: LibraryChart): { keys: number; isDouble: boolean; isPMS: boolean } {
  const variant = resolveLibraryChartPlayVariant(chartEntry);
  // `'48'` is the DP form of the 24-key keyboard mode, so it reports 24 keys per side plus `isDouble` — the same
  // per-side convention the That-Which-Must-Not-Be-Named `'14'` / `'10'` variants use.
  const keys =
    variant === '24' || variant === '48'
      ? 24
      : variant === '14'
        ? 14
        : variant === '10'
          ? 10
          : variant === '7'
            ? 7
            : variant === '5'
              ? 5
              : 9;
  return {
    keys,
    isDouble: variant === '14' || variant === '10' || variant === '48',
    isPMS: variant === '9',
  };
}
 
/**
 * Resolves the actual skin variant the beatoraja gameplay path will mount for a chart. Returns the
 * desired variant verbatim when the theme ships it, the closest playable fallback otherwise, or
 * `undefined` when the theme has nothing playable.
 */
export function resolveBeatorajaSkinVariant(
  bundle: BeatorajaThemeBundle | undefined,
  chartEntry: LibraryChart,
): BeatorajaPlayableVariant | undefined {
  Iif (!bundle) return undefined;
  const desired = pickBeatorajaPlayableVariant(chartShapeFor(chartEntry));
  Iif (desired === undefined) return undefined;
  return pickBeatorajaPlayableSkinVariant(bundle.theme.playSkins, desired);
}
 
/**
 * Quick predicate — `true` when the loaded beatoraja theme can render this song's gameplay scene. Threads through
 * {@link resolveBeatorajaSkinVariant} so the answer matches what the play path would actually mount.
 */
export function canPlayChartBeatoraja(bundle: BeatorajaThemeBundle | undefined, chartEntry: LibraryChart): boolean {
  return resolveBeatorajaSkinVariant(bundle, chartEntry) !== undefined;
}