All files / player-engine/src/course course-replay.ts

80% Statements 4/5
100% Branches 2/2
100% Functions 3/3
80% Lines 4/5

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                            42x       3x                     36x 36x          
import { computeChartFingerprint } from '@be-music/chart-model';
import type { BeMusicJSON } from '@be-music/chart-source';
import type { ReplayCourseInfo } from '../replay/course.ts';
import type { CourseDefinition } from './definition.ts';
 
/*
 * What the course runs (`CourseRun`, the NONSTOP pipeline) share when they write a course replay. Internal: not part
 * of `@be-music/player-engine/course`.
 */
 
/** The course as its replay records it. */
export function resolveReplayCourseInfo(
  definition: Pick<CourseDefinition, 'name' | 'kind' | 'constraints' | 'trophies' | 'release'>,
): ReplayCourseInfo {
  return {
    name: definition.name,
    kind: definition.kind,
    constraints: [...definition.constraints],
    trophies: definition.trophies.map((trophy) => ({ ...trophy })),
    ...(definition.release === false ? { release: false as const } : {}),
  };
}
 
/**
 * The chart fingerprint of a course stage's chart, as the recorder would record it had the stage been played: it names
 * the stage in the course replay and keys the course on the Leaderboard. `undefined` when the chart cannot be
 * fingerprinted.
 */
export function computeStageChartFingerprint(chart: BeMusicJSON, chartPath: string | undefined): string | undefined {
  try {
    return computeChartFingerprint(chart, { chartPath });
  } catch {
    return undefined;
  }
}