All files / player-engine/src/replay gauge-histories.ts

100% Statements 4/4
100% Branches 6/6
100% Functions 1/1
100% Lines 4/4

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                                                                                          13x 13x   13x 13x    
/**
 * A replay's gauge under each gauge of its ruleset: what the play's gauge graph would have drawn had it been played on
 * that gauge. beatoraja keeps every gauge's log during a play and its result screen steps the graph through them
 * (`MusicResult` CHANGE_GRAPH); a Be-Music play runs the gauges it needs, so the others are re-simulated from the
 * replay. Pure and deterministic, like the simulation it observes.
 */
 
import type { RulesetCourseKind } from '../ruleset/course.ts';
import type { RulesetId } from '../ruleset/definitions.ts';
import { resolveGaugeShiftLadder } from '../ruleset/gauge-shift.ts';
import { resolveGaugePickSource } from '../ruleset/gauge-type.ts';
import type { BeMusicReplay } from './format.ts';
import { simulateReplayGaugeSamples } from './simulate.ts';
 
/** One gauge's run over a replay: its value before the first judgment and just after each one. */
export interface ReplayGaugeHistory {
  /** The ruleset's own gauge id (`NORMAL`, `EX-HARD`, `GROOVE`, ...). */
  readonly gauge: string;
  /** The gauge's starting value, in percent of its maximum. */
  readonly initial: number;
  /** The gauge just after each judgment, in scoring order: chart µs and percent of its maximum. */
  readonly samples: readonly { readonly atUs: number; readonly gauge: number }[];
}
 
export interface ReplayGaugeHistoriesOptions {
  /** The ruleset to judge under; the replay's own by default. */
  readonly ruleset?: RulesetId;
  /** The course kind whose gauges to run instead of a single play's. */
  readonly courseKind?: RulesetCourseKind;
  /**
   * Chart µs the play stopped at, when it stopped early (its gauge emptied): judgments after it are left out, since
   * the play made none.
   */
  readonly untilUs?: number;
}
 
/**
 * The gauge histories of `replay` under each gauge of the ruleset's line-up (`resolveGaugeShiftLadder`), gentlest
 * first. Each gauge runs on its own from its starting value, with no auto-shift, and to the end of the inputs even
 * when it empties, so a survival gauge that fails stays at 0 as the graph draws it.
 */
export function resolveReplayGaugeHistories(
  replay: BeMusicReplay,
  options: ReplayGaugeHistoriesOptions = {},
): ReplayGaugeHistory[] {
  const ruleset = options.ruleset ?? replay.play.judgeRuleset ?? 'lr2';
  const untilUs = options.untilUs ?? Number.POSITIVE_INFINITY;
  // The line-up is the gauge's own source's: a qualified pick steps through that source's gauges (#1171).
  const source = resolveGaugePickSource(replay.play.gauge, ruleset);
  return simulateReplayGaugeSamples(replay, ruleset, resolveGaugeShiftLadder(source, options.courseKind), untilUs);
}