All files / player-engine/src/core landmine.ts

100% Statements 3/3
100% Branches 2/2
100% Functions 1/1
100% Lines 3/3

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        303x                                   6058x 6058x            
import { DEFAULT_LANDMINE_DAMAGE, resolveLandmineDamage } from '@be-music/chart-model';
import { normalizeObjectKey, type BeMusicEvent, type BeMusicSourceFormat } from '@be-music/chart-source';
 
/** Gauge damage of a mine whose value carries none. Same value as `DEFAULT_LANDMINE_DAMAGE` in `@be-music/chart-model`. */
export const DEFAULT_LANDMINE_GAUGE_DAMAGE: number = DEFAULT_LANDMINE_DAMAGE;
 
export interface LandmineGaugeEffect {
  objectValue: string;
  damage: number;
  gaugeDelta: number;
}
 
/**
 * Resolves the gauge damage a landmine object deals when hit, with the normalized object value it was read from. The
 * damage rule (BMS value as base-36 percentage, bmson `damage`, the default) is `resolveLandmineDamage` in
 * `@be-music/chart-model`; a resolved chart (`resolveChart`) already carries it on each mine.
 */
export function resolveLandmineGaugeEffect(
  landmineEvent: Pick<BeMusicEvent, 'value' | 'bmson'>,
  base: 36 | 62 = 36,
  sourceFormat: BeMusicSourceFormat = 'bms',
): LandmineGaugeEffect {
  const damage = resolveLandmineDamage(landmineEvent, base, sourceFormat);
  return {
    objectValue: normalizeObjectKey(landmineEvent.value, base),
    damage,
    gaugeDelta: -damage,
  };
}