All files / chart-model/src generic-bmson.ts

100% Statements 8/8
100% Branches 9/9
100% Functions 1/1
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  597x                   119350x 5542x 5542x 3848x 3848x    
/** Two visible channel banks, each with lane codes 1–9 and A–Z. */
export const MAX_GENERIC_BMSON_KEYS = 70;
 
export type GenericBmsonPlayVariant = `generic-${number}`;
 
/**
 * The key count of a `generic-Nkeys` hint with 1–70 keys; undefined for any other hint. A malformed or out-of-range
 * `generic-` hint is an unknown hint like any other, so the chart is read as `beat-7k` where its lanes fit, as beatoraja
 * reads an unsupported `mode_hint` (BMSONDecoder warns and uses BEAT_7K).
 */
export function resolveGenericBmsonKeyCount(modeHint: unknown): number | undefined {
  if (typeof modeHint !== 'string') return undefined;
  const match = /^generic-(\d+)keys?$/.exec(modeHint.trim());
  if (!match) return undefined;
  const count = Number(match[1]);
  return Number.isSafeInteger(count) && count >= 1 && count <= MAX_GENERIC_BMSON_KEYS ? count : undefined;
}