All files / chart-model/src hdx-long-note-mode.ts

100% Statements 7/7
100% Branches 10/10
100% Functions 2/2
100% Lines 6/6

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        3522x 3522x           58063x 2176x 2176x   58063x    
import type { BeMusicJSON } from '@be-music/chart-source';
 
/** charatbeatHDX's initial-only LONGMODE: 0 = CN, 1 = HCN. Preserve the vendor's documented case. */
export function parseHDXLongNoteMode(declaration: string): 2 | 3 | undefined {
  const match = /^charatbeatHDX:LONGMODE[\t ]+([01])[\t ]*$/.exec(declaration);
  return match ? (match[1] === '0' ? 2 : 3) : undefined;
}
 
/** Last valid whole declaration; unrelated or malformed later options do not erase the earlier setting. */
export function resolveHDXLongNoteMode(json: Pick<BeMusicJSON, 'bms'>): 2 | 3 | undefined {
  let mode: 2 | 3 | undefined;
  for (const declaration of json.bms.options ?? (json.bms.option ? [json.bms.option] : [])) {
    const next = parseHDXLongNoteMode(declaration);
    if (next !== undefined) mode = next;
  }
  return mode;
}