All files / player-scene-model/src/play-options live-display-options.ts

100% Statements 13/13
100% Branches 6/6
100% Functions 1/1
100% Lines 11/11

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                189x                                                 189x             8x 8x 8x 19x 12x 12x 10x 10x   8x    
/**
 * The play options a running play takes at once: the ones that only change what is drawn, so switching them mid-play
 * moves no note, judgment or record. Every other option is read when the play starts.
 */
import { resolvePlayOptionValue } from './choices.ts';
import type { PlayOptions } from './options.ts';
 
/** The display-only play options a running play follows live. */
export const LIVE_DISPLAY_PLAY_OPTION_KEYS: readonly (keyof PlayOptions)[] = [
  'autoScratchNotes',
  'judgeCounts',
  'judgeDetail',
  'judgeDetailSplit',
  'judgeDisplay',
  'judgePosition',
  'laneBrightness',
  'lr2Acceleration',
  'lr2Char',
  'lr2Earthquake',
  'lr2Heartbeat',
  'lr2Nabeatsu',
  'lr2SideJump',
  'lr2SinCurve',
  'lr2SpiralEffect',
  'lr2SuperLoop',
  'lr2Tornado',
  'lr2Wave',
  'markProcessedNotes',
  'scoreTarget',
  'scoreTargetRate',
  'showJudgeArea',
];
 
const LIVE_KEYS: ReadonlySet<string> = new Set(LIVE_DISPLAY_PLAY_OPTION_KEYS);
 
/**
 * The part of `changes` a running play takes at once: its live display options, each validated as a stored value is
 * (`resolvePlayOptionValue`). `undefined` when nothing in `changes` is one.
 */
export function pickLiveDisplayPlayOptions(changes: Partial<PlayOptions>): Partial<PlayOptions> | undefined {
  const picked: Record<string, unknown> = {};
  let any = false;
  for (const [key, value] of Object.entries(changes)) {
    if (!LIVE_KEYS.has(key)) continue;
    const resolved = resolvePlayOptionValue(key as keyof PlayOptions, value);
    if (resolved === undefined) continue;
    picked[key] = resolved;
    any = true;
  }
  return any ? (picked as Partial<PlayOptions>) : undefined;
}