All files / player-browser/src/skin/be-music hold-top.ts

100% Statements 13/13
92.85% Branches 13/14
100% Functions 1/1
100% Lines 8/8

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                10x 29x   4x 8x 5x 5x 4x   4x      
import type { BeMusicLaneFrame, BeMusicLongNote } from '@be-music/player-skin-sdk';
 
/**
 * Fills each held lane's `holdTop`: the top of the long note held in it this frame (the note in the `'held'` state over
 * the lane, the one nearest the judgement line if two are), no higher than the lane's own top. A held lane with no such
 * note this frame keeps `holdTop` unset. Pure apart from writing the lanes it is given.
 */
export function resolveHoldTops(lanes: readonly BeMusicLaneFrame[], longNotes: readonly BeMusicLongNote[]): void {
  for (const lane of lanes) {
    if (lane.holding !== true) continue;
    let held: BeMusicLongNote | undefined;
    for (const note of longNotes) {
      if (note.state !== 'held') continue;
      const centre = note.x + note.w / 2;
      if (centre < lane.x || centre > lane.x + lane.w) continue;
      Eif (held === undefined || note.bottom > held.bottom) held = note;
    }
    if (held !== undefined) lane.holdTop = Math.max(lane.top, held.top);
  }
}