All files / player-scene-model/src/course-view course-combo.ts

100% Statements 4/4
100% Branches 6/6
100% Functions 2/2
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                              13x 13x               37x 37x    
/**
 * The course-wide combo a course stage shows: carried in from the previous stage and running on with the stage's own
 * combo until the first break, then the stage combo itself (beatoraja `JudgeManager.coursecombo`, LR2
 * `now_combo_course`). The judge engine keeps the same figure for the replay; a screen follows it from the combo
 * readings the engine publishes.
 */
export interface CourseComboState {
  combo: number;
  maxCombo: number;
  /** The stage combo last seen. */
  stageCombo: number;
}
 
/** The course combo a stage starts from: the carried-in combo and max combo, or nothing for a course's first stage. */
export function createCourseCombo(carryIn?: { combo: number; maxCombo: number }): CourseComboState {
  const combo = carryIn?.combo ?? 0;
  return { combo, maxCombo: Math.max(carryIn?.maxCombo ?? 0, combo), stageCombo: 0 };
}
 
/**
 * The course combo after a new stage-combo reading: a rise adds to the course combo, a drop means the combo broke and
 * the course combo is the stage combo again. Returns a new state; the one given is not changed.
 */
export function reduceCourseCombo(state: Readonly<CourseComboState>, stageCombo: number): CourseComboState {
  const combo = stageCombo >= state.stageCombo ? state.combo + (stageCombo - state.stageCombo) : stageCombo;
  return { combo, stageCombo, maxCombo: Math.max(state.maxCombo, combo) };
}