All files / player-engine/src/ruleset practice-gauge.ts

97.05% Statements 33/34
94.73% Branches 18/19
100% Functions 11/11
96.77% Lines 30/31

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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176                419x                         419x                     419x   419x                                     419x                     1788x   451x   460x   437x   440x           17x         75x 74x         419x     419x                                       69x                 419x       7542x   1676x 12151x           19693x 419x                       133x 33x   15x   11x   4x       3x           12327x                 9581x    
import type { RulesetId } from './definitions.ts';
 
/**
 * PRACTICE's `GAUGE TYPE` per judge ruleset (#933). PRACTICE is beatoraja's mode (`PracticeConfiguration`), usable under
 * every ruleset; its gauge list is the judge ruleset's own gauges, spelled as that ruleset's gauge ids.
 */
 
/** beatoraja PRACTICE `GAUGE TYPE`, in source order: the six single gauges, then the three class gauges. */
export const BEATORAJA_PRACTICE_GAUGE_TYPES = [
  'ASSIST-EASY',
  'EASY',
  'NORMAL',
  'HARD',
  'EX-HARD',
  'HAZARD',
  'CLASS',
  'EXCLASS',
  'EXHARDCLASS',
] as const;
 
/** LR2's single-play gauges in source order, followed by the corrected HAZARD. */
export const LR2_PRACTICE_GAUGE_TYPES = [
  'GROOVE',
  'HARD',
  'DEATH',
  'EASY',
  'P-ATTACK',
  'G-ATTACK',
  'DEATH-CORRECTED',
] as const;
 
/** That-Which-Must-Not-Be-Named's single-play gauges, gentlest first. */
const ____PRACTICE_GAUGE_TYPES = ['ASSISTED-EASY', 'EASY', 'NORMAL', 'HARD', 'EX-HARD'] as const;
/** plugout has no PRACTICE: Be-Music's offers its single-play gauges, by their ids (`PLUGOUT_GAUGE_IDS`). */
const PLUGOUT_PRACTICE_GAUGE_TYPES = [
  'EASY',
  'NORMAL',
  'HARD',
  'HAZARD',
  'EX-EASY',
  'EX-NORMAL',
  'EX-HARD',
  'EX-HAZARD',
] as const;
 
/** A PRACTICE `GAUGE TYPE` of any ruleset: a gauge id, read under the judge ruleset it belongs to. */
export type PracticeGaugeType =
  | (typeof BEATORAJA_PRACTICE_GAUGE_TYPES)[number]
  | (typeof LR2_PRACTICE_GAUGE_TYPES)[number]
  | (typeof ____PRACTICE_GAUGE_TYPES)[number]
  | (typeof PLUGOUT_PRACTICE_GAUGE_TYPES)[number];
 
/** Every ruleset's PRACTICE gauge types, each once: what a stored PRACTICE gauge may hold. */
export const PRACTICE_GAUGE_TYPES: readonly PracticeGaugeType[] = [
  ...new Set<PracticeGaugeType>([
    ...BEATORAJA_PRACTICE_GAUGE_TYPES,
    ...LR2_PRACTICE_GAUGE_TYPES,
    ...____PRACTICE_GAUGE_TYPES,
    ...PLUGOUT_PRACTICE_GAUGE_TYPES,
  ]),
];
 
/** The PRACTICE gauge types `ruleset` offers, in its own order. */
export function resolvePracticeGaugeTypes(ruleset: RulesetId): readonly PracticeGaugeType[] {
  switch (ruleset) {
    case 'lr2':
      return LR2_PRACTICE_GAUGE_TYPES;
    case 'beatoraja':
      return BEATORAJA_PRACTICE_GAUGE_TYPES;
    case 'plugout':
      return PLUGOUT_PRACTICE_GAUGE_TYPES;
    default:
      return ____PRACTICE_GAUGE_TYPES;
  }
}
 
/** The PRACTICE gauge a ruleset starts with: its default recovery gauge (LR2 GROOVE, else NORMAL). */
export function resolveDefaultPracticeGauge(ruleset: RulesetId): PracticeGaugeType {
  return ruleset === 'lr2' ? 'GROOVE' : 'NORMAL';
}
 
/** Whether `value` is a PRACTICE gauge type: of `ruleset` when given, else of any ruleset. */
export function isPracticeGaugeType(value: unknown, ruleset?: RulesetId): value is PracticeGaugeType {
  if (typeof value !== 'string') return false;
  return ruleset === undefined
    ? PRACTICE_GAUGE_TYPE_SET.has(value)
    : (resolvePracticeGaugeTypes(ruleset) as readonly string[]).includes(value);
}
 
const PRACTICE_GAUGE_TYPE_SET: ReadonlySet<string> = new Set(PRACTICE_GAUGE_TYPES);
 
/** The rulesets whose PRACTICE gauges a pick can name. */
const PRACTICE_GAUGE_SOURCES: readonly RulesetId[] = ['lr2', 'beatoraja', '____', 'plugout'];
 
/**
 * A PRACTICE `GAUGE TYPE` of one source, whatever ruleset judges the play: `beatoraja:ASSIST-EASY` under LR2 plays on
 * beatoraja's ASSIST EASY, as a source-qualified gauge pick does (ADR 0019).
 */
export type QualifiedPracticeGaugeType = `${RulesetId}:${PracticeGaugeType}`;
 
/**
 * The gauge a PRACTICE play runs on. A bare {@link PracticeGaugeType} is the judge ruleset's own; a
 * {@link QualifiedPracticeGaugeType} keeps its source's gauge and that source's TOTAL reading under every judge ruleset.
 */
export type PracticeGaugePick = PracticeGaugeType | QualifiedPracticeGaugeType;
 
/**
 * Splits a PRACTICE gauge pick into its source (`undefined` for a bare one) and its gauge type, or `undefined` when
 * `value` is none. A qualified pick names a gauge its own source's PRACTICE list offers; it is never mapped to a
 * lookalike.
 */
export function splitPracticeGaugePick(value: unknown): Readonly<PracticeGaugePickParts> | undefined {
  return typeof value === 'string' ? PRACTICE_GAUGE_PICK_PARTS.get(value) : undefined;
}
 
interface PracticeGaugePickParts {
  source: RulesetId | undefined;
  type: PracticeGaugeType;
}
 
/** Every PRACTICE gauge pick and its parts, so a pick is split by one lookup: the table is fixed. */
const PRACTICE_GAUGE_PICK_PARTS: ReadonlyMap<string, Readonly<PracticeGaugePickParts>> = new Map<
  string,
  Readonly<PracticeGaugePickParts>
>([
  ...PRACTICE_GAUGE_TYPES.map((type) => [type, Object.freeze({ source: undefined, type })] as const),
  ...PRACTICE_GAUGE_SOURCES.flatMap((source) =>
    resolvePracticeGaugeTypes(source).map(
      (type) => [qualifyPracticeGaugePick(source, type), Object.freeze({ source, type })] as const,
    ),
  ),
]);
 
/** The PRACTICE gauge picks valid under each judge ruleset: its own bare gauges and every qualified one. */
const QUALIFIED_PRACTICE_GAUGE_PICKS = [...PRACTICE_GAUGE_PICK_PARTS.keys()].filter((pick) => pick.includes(':'));
const PRACTICE_GAUGE_PICKS_BY_RULESET = {
  lr2: new Set([...LR2_PRACTICE_GAUGE_TYPES, ...QUALIFIED_PRACTICE_GAUGE_PICKS]),
  beatoraja: new Set([...BEATORAJA_PRACTICE_GAUGE_TYPES, ...QUALIFIED_PRACTICE_GAUGE_PICKS]),
  ____: new Set([...____PRACTICE_GAUGE_TYPES, ...QUALIFIED_PRACTICE_GAUGE_PICKS]),
  plugout: new Set([...PLUGOUT_PRACTICE_GAUGE_TYPES, ...QUALIFIED_PRACTICE_GAUGE_PICKS]),
};
 
/**
 * Whether `value` is a PRACTICE gauge pick: a qualified one of any source, or a bare one of `ruleset` when given (else of
 * any ruleset).
 */
export function isPracticeGaugePick(value: unknown, ruleset?: RulesetId): value is PracticeGaugePick {
  if (typeof value !== 'string') return false;
  switch (ruleset) {
    case undefined:
      return PRACTICE_GAUGE_PICK_PARTS.has(value);
    case 'lr2':
      return PRACTICE_GAUGE_PICKS_BY_RULESET.lr2.has(value);
    case 'beatoraja':
      return PRACTICE_GAUGE_PICKS_BY_RULESET.beatoraja.has(value);
    case 'plugout':
      return PRACTICE_GAUGE_PICKS_BY_RULESET.plugout.has(value);
    default:
      return PRACTICE_GAUGE_PICKS_BY_RULESET.____.has(value);
  }
}
 
/** `type` as `source`'s PRACTICE gauge. */
export function qualifyPracticeGaugePick(source: RulesetId, type: PracticeGaugeType): QualifiedPracticeGaugeType {
  return `${source}:${type}`;
}
 
/**
 * Whether PRACTICE's `JUDGERANK` and `TOTAL` take effect under `ruleset`. beatoraja and LR2 read them (a judgerank
 * percent on their own window tables, an absolute TOTAL); That-Which-Must-Not-Be-Named's windows are fixed and its
 * gauges do not use TOTAL.
 */
export function practiceReadsJudgeRankAndTotal(ruleset: RulesetId): boolean {
  return ruleset !== '____';
}