All files / player-engine/src/replay result-lamp.ts

100% Statements 11/11
100% Branches 6/6
100% Functions 2/2
100% Lines 9/9

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                          737x 737x             737x 737x 737x 737x                       932x 932x 932x    
import { resolveClearLamp, resolveMissCount, type ClearLamp, type PlayClearLampFacts } from '../ruleset/clear-lamp.ts';
import type { RulesetId } from '../ruleset/definitions.ts';
import type { ReplayRulesetResult } from './format.ts';
 
/**
 * The clear lamp of one play's result under `ruleset` (a simulated result, or the engine's own), by the one clear-lamp
 * rule (`resolveClearLamp`): LR2 awards a full combo before checking the gauge; other rulesets require a clear, then
 * the lamp of the gauge it cleared on, kept to the ruleset's own lamps.
 */
export function resolveRulesetResultLamp(
  result: Pick<ReplayRulesetResult, 'judge' | 'noteCount' | 'gauge' | 'fullCombo'>,
  ruleset: RulesetId,
): ClearLamp {
  const { pgreat, great, good } = result.judge;
  const score: PlayClearLampFacts['score'] = {
    total: result.noteCount,
    perfect: pgreat,
    great,
    good,
    emptyPoor: result.judge.emptyPoor,
  };
  if (result.fullCombo !== undefined) score.fullCombo = result.fullCombo;
  const facts: PlayClearLampFacts = { ruleset, cleared: result.gauge.cleared, gauge: result.gauge.type, score };
  if (result.gauge.source !== undefined) facts.gaugeSource = result.gauge.source;
  return resolveClearLamp(facts);
}
 
/**
 * The BP of one play's result (or one course stage's) under any ruleset (`resolveMissCount`): its BADs, POORs and empty
 * POORs, plus the notes a play that failed or was given up mid-way never judged, as LR2 and beatoraja count them
 * (OpenLR2 L9436-L9439, beatoraja `BMSPlayer` L915). A mine POOR (`minePoor`, which LR2 counts in its POOR) judges no
 * note.
 */
export function resolveRulesetResultMissCount(
  result: Pick<ReplayRulesetResult, 'judge' | 'noteCount' | 'minePoor'>,
): number {
  const { pgreat, great, good, bad, poor } = result.judge;
  const judged = pgreat + great + good + bad + poor - (result.minePoor ?? 0);
  return resolveMissCount(result.judge, result.noteCount - judged);
}