All files / player-ui/src/playfield judgment-display-data.ts

69.23% Statements 9/13
66.66% Branches 16/24
80% Functions 4/5
71.42% Lines 5/7

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 29 30              9x 7x 4x       4x                       1x        
import type { BeMusicJudgmentDisplayData, BeMusicJudgmentWord } from '../models.ts';
 
/** Whether two judgment displays show the same words in the same place. */
export function sameJudgmentDisplay(
  a: BeMusicJudgmentDisplayData | undefined,
  b: BeMusicJudgmentDisplayData | undefined,
): boolean {
  if (a === b) return true;
  if (a === undefined || b === undefined || a.y !== b.y || a.words.length !== b.words.length) return false;
  return a.words.every((word, index) => sameWord(word, b.words[index]!));
}
 
function sameWord(a: BeMusicJudgmentWord, b: BeMusicJudgmentWord): boolean {
  return (
    a.text === b.text &&
    a.color === b.color &&
    a.x === b.x &&
    a.y === b.y &&
    a.mode === b.mode &&
    a.combo === b.combo &&
    sameDetails(a.details, b.details)
  );
}
 
function sameDetails(a: BeMusicJudgmentWord['details'], b: BeMusicJudgmentWord['details']): boolean {
  Eif (a === b) return true;
  if (a === undefined || b === undefined || a.length !== b.length) return false;
  return a.every((detail, index) => detail.text === b[index]!.text && detail.color === b[index]!.color);
}