All files / player-browser/src/chart lane-sides.ts

100% Statements 9/9
100% Branches 4/4
100% Functions 4/4
100% Lines 5/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                          1765x 1761x 1761x 1506x         1718x    
import type { PlaySide } from '@be-music/player-scene-model';
 
/**
 * Returns whether a BMS channel string belongs to the given play-side. Used by per-side gameplay overlays (LANE COVER /
 * HIDDEN / SUDDEN masks) so each side can render an independent shutter without leaking onto the other side's lanes on
 * a DP chart.
 *
 * Channel layout (LR2 convention): - 1P keyboard: `11..15` + `18` + `19`; scratch: `16` - 2P keyboard: `21..25` + `28`
 * + `29`; scratch: `26`
 *
 * Anything else (BGM, BGA, BPM, etc.) returns `false` for BOTH sides — those don't appear in `laneX` anyway.
 */
export function isChannelOnSide(channel: string, side: PlaySide): boolean {
  if (channel.length !== 2) return false;
  const head = channel[0];
  if (side === '1P') return head === '1';
  return head === '2';
}
 
/** The play sides with a lane among `channels`, 1P first: the sides a play keeps lane covers for. */
export function resolveLaneSides(channels: readonly string[]): PlaySide[] {
  return (['1P', '2P'] as const).filter((side) => channels.some((channel) => isChannelOnSide(channel, side)));
}