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 177 178 179 180 181 182 183 184 185 186 187 188 | 318x 318x 6042x 318x 318x 318x 318x 318x 318x 318x 318x 318x 318x 318x 2135x 3386x 482x 482x 482x 482x 482x 482x 946x 647x 647x 1162x 1162x 946x 727x 601x 601x 228x 228x 228x 601x 534x 268x 268x 465x 462x 462x 613x 613x 4898x 460x 482x 482x 482x 482x 482x 482x 482x 318x 306x 141x 113x | /**
* The `#DIFFICULTY` (1 BEGINNER … 5 INSANE) of a chart that names none, read from its names. LR2 shows such a chart
* without a difficulty; beatoraja fills one in from `#SUBTITLE` and `#TITLE` when it builds its song database
* (`SQLiteSongDatabaseAccessor`), and Be-Music follows it as LR2 has no rule of its own. The rules here go further than
* beatoraja's keyword match: they read the file name too, and were tuned against charts that do name their difficulty.
* When the names give none, beatoraja falls back to the note count (`estimateDifficultyFromNoteCount`), a far weaker
* guess. A difficulty read either way is an estimate, and a host marks it as one, the note-count one more strongly.
*/
/**
* Where a difficulty a screen shows comes from: the chart's own `#DIFFICULTY`, its names, or its note count. On charts
* that do name their difficulty, the names agree with it 97% of the time and the note count 60% (nearly always within
* one step).
*/
export type DifficultyBasis = 'chart' | 'names' | 'notes';
/** The names a chart's difficulty is read from. */
export interface DifficultyNames {
readonly title?: string;
readonly subtitle?: string;
/** bmson `info.chart_name`, read like the subtitle. */
readonly chartName?: string;
/** The chart's file name; an extension is dropped. */
readonly fileName?: string;
}
/** Whole words, strongest first: a specific name wins over a generic one in the same text. */
const WORD_LEVELS: ReadonlyArray<readonly [level: number, words: readonly string[]]> = [
[5, ['LEGGENDARIA', 'INSANE', 'BLACK', 'LUNATIC', 'MASTER', 'DARKANOTHER', 'BLACKANOTHER']],
[1, ['BEGINNER', 'BEGINER']],
[2, ['NORMAL', 'STANDARD']],
[3, ['HYPER']],
[4, ['ANOTHER']],
[5, ['EXTRA']],
[4, ['EX']],
[1, ['EASY', 'BASIC']],
[3, ['HARD']],
[2, ['LIGHT']],
];
const WORDS = new Map<string, { level: number; rank: number }>(
WORD_LEVELS.flatMap(([level, words], rank) => words.map((word) => [word, { level, rank }] as const)),
);
/** Words also read when glued to the end of a file name token (`silenteasy`, `boymganother2`). */
const GLUED_WORDS = ['BEGINNER', 'NORMAL', 'HYPER', 'ANOTHER', 'INSANE', 'EASY', 'HARD', 'LIGHT'] as const;
/** Abbreviations, read in a token of `[key count | SP | DP]` + abbreviation (+ digits): `7A`, `SPH`, `14N`. */
const ABBREVIATIONS: Readonly<Record<string, number>> = {
B: 1,
BG: 1,
BEG: 1,
EZ: 1,
N: 2,
NM: 2,
NOR: 2,
H: 3,
HD: 3,
HY: 3,
A: 4,
AN: 4,
ANO: 4,
X: 5,
I: 5,
INS: 5,
};
/** `L` is LIGHT in some packs and LEGGENDARIA in others: read only after SP / DP (`SPL`). */
const SP_DP_ONLY_ABBREVIATIONS: Readonly<Record<string, number>> = { L: 5 };
/** A lone `E` names anything; after a key count or SP / DP (`5E`, `SPE`) it is EASY. */
const PREFIXED_ONLY_ABBREVIATIONS: Readonly<Record<string, number>> = { E: 1 };
const TOKEN_SEPARATOR = /[^A-Z0-9+]+/u;
const WORD_TOKEN = /^(?:\d{1,2}K?(?:EYS?)?|[SD]P)?([A-Z]+)\+?\d*$/u;
const ABBREVIATION_TOKEN = /^(\d{1,2}|[SD]P)?([A-Z]{1,3})\d*$/u;
const STEM_SUFFIX = /(?:\d{1,2}|[SD]P)([A-Z]{1,3})$/u;
const NUMBERED_EX = /(?:^|[^A-Z])(?:[SD]P)?EX\d(?:$|[^0-9])/u;
const BRACKETED = /[[(<【〔「(]([^\])>】〕」)]*)/gu;
const TRAILING_DASHED = /[-~]\s*([^-~]+?)\s*[-~]\s*$/u;
function tokens(text: string): string[] {
return text
.toUpperCase()
.split(TOKEN_SEPARATOR)
.filter((token) => token.length > 0);
}
/** The subtitle (and bmson chart name) and the bracketed or trailing `-dashed-` parts of the title, not its bare words. */
function tagText(names: DifficultyNames): string {
const title = names.title ?? '';
const parts = [names.subtitle ?? '', names.chartName ?? ''];
for (const match of title.matchAll(BRACKETED)) parts.push(match[1] ?? '');
const dashed = TRAILING_DASHED.exec(title);
if (dashed !== null) parts.push(dashed[1] ?? '');
return parts.join(' ');
}
function matchWords(text: string): number | undefined {
let best: { level: number; rank: number } | undefined;
for (const token of tokens(text)) {
const word = WORD_TOKEN.exec(token)?.[1];
for (const candidate of word === undefined ? [token] : [token, word]) {
const found = WORDS.get(candidate);
if (found !== undefined && (best === undefined || found.rank < best.rank)) best = found;
}
}
return best?.level;
}
function matchAbbreviation(text: string): number | undefined {
for (const token of tokens(text).reverse()) {
const match = ABBREVIATION_TOKEN.exec(token);
if (match === null) continue;
const prefix = match[1];
const abbreviation = match[2]!;
const level =
ABBREVIATIONS[abbreviation] ??
(prefix === 'SP' || prefix === 'DP' ? SP_DP_ONLY_ABBREVIATIONS[abbreviation] : undefined) ??
(prefix !== undefined ? PREFIXED_ONLY_ABBREVIATIONS[abbreviation] : undefined);
if (level !== undefined) return level;
}
return undefined;
}
function matchStemSuffix(stem: string): number | undefined {
const abbreviation = STEM_SUFFIX.exec(stem.toUpperCase())?.[1];
return abbreviation !== undefined ? ABBREVIATIONS[abbreviation] : undefined;
}
/** `EX1` / `EX2`: extra charts beyond ANOTHER. */
function matchNumberedEx(stem: string): number | undefined {
return NUMBERED_EX.test(stem.toUpperCase()) ? 5 : undefined;
}
/** A difficulty word glued to a file name token, unless the title itself has that word (`hyperdiver` of Hyper Diver). */
function matchGluedWord(stem: string, title: string): number | undefined {
const bareTitle = title
.replace(BRACKETED, '')
.toUpperCase()
.replace(/[^A-Z]/gu, '');
for (const token of tokens(stem)) {
const core = token.replace(/\d+$/u, '');
for (const word of GLUED_WORDS) {
if (core.endsWith(word) && core !== word && !bareTitle.includes(word)) return WORDS.get(word)!.level;
}
}
return undefined;
}
function fileStem(fileName: string): string {
const base = fileName.slice(Math.max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\')) + 1);
const dot = base.lastIndexOf('.');
return dot > 0 ? base.slice(0, dot) : base;
}
/**
* The difficulty (1–5) a chart's names suggest, or `undefined` when they suggest none. Read in order, the first hit
* wins: a difficulty word in the subtitle or a bracketed part of the title (`[SP ANOTHER]`, `-5NORMAL-`), a word in the
* file name (`_hyper.bms`, `EX2`), a word glued to the file name (`silenteasy`), an abbreviation in the file name
* (`7a`, `SPH`, `14n`), and an abbreviation in the subtitle or brackets (`[A]`).
*/
export function estimateDifficultyFromNames(names: DifficultyNames): number | undefined {
const title = names.title ?? '';
const tags = tagText(names);
const stem = fileStem(names.fileName ?? '');
return (
matchWords(tags) ??
matchNumberedEx(stem) ??
matchWords(stem) ??
matchGluedWord(stem, title) ??
matchAbbreviation(stem) ??
matchStemSuffix(stem) ??
matchAbbreviation(tags)
);
}
/** beatoraja's note-count bounds: under 250 BEGINNER, 600 NORMAL, 1000 HYPER, 2000 ANOTHER, else INSANE. */
const NOTE_COUNT_BOUNDS = [250, 600, 1000, 2000] as const;
/**
* The difficulty (1–5) beatoraja gives a chart its names give none for, by its note count (`SQLiteSongDatabaseAccessor`):
* under 250 notes BEGINNER, 600 NORMAL, 1000 HYPER, 2000 ANOTHER, else INSANE. `undefined` for a chart without notes,
* which has nothing to rank.
*/
export function estimateDifficultyFromNoteCount(noteCount: number): number | undefined {
if (!Number.isFinite(noteCount) || noteCount <= 0) return undefined;
const index = NOTE_COUNT_BOUNDS.findIndex((bound) => noteCount < bound);
return index === -1 ? 5 : index + 1;
}
|