mania-judge 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/dist/chunk-CfYAbeIz.mjs +13 -0
- package/dist/index-Zuz8HPVe.d.mts +35 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +324 -0
- package/dist/osu-parsers/index.d.mts +2 -0
- package/dist/osu-parsers/index.mjs +2 -0
- package/dist/osu-parsers/node.d.mts +13 -0
- package/dist/osu-parsers/node.mjs +9 -0
- package/dist/shared-D-sop3c6.d.mts +15 -0
- package/dist/shared-DJFUXeEy.mjs +69 -0
- package/dist/types-3MDvQQxi.d.mts +66 -0
- package/package.json +67 -0
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# mania-judge
|
|
2
|
+
|
|
3
|
+
Work in progress.
|
|
4
|
+
|
|
5
|
+
Simulates osu!stable mania judgements.
|
|
6
|
+
|
|
7
|
+
## Status
|
|
8
|
+
|
|
9
|
+
- Implemented: judgements, combo, and life.
|
|
10
|
+
- Not implemented: score.
|
|
11
|
+
- Tap-only: accurate in current tests except for a few life mismatches.
|
|
12
|
+
- Hold: not expected to be exact yet because the precise stable hold algorithm is still unknown.
|
|
13
|
+
- Hold accuracy error across 47 fixtures: `0.00%` min, `0.39%` max, `0.16%` average.
|
|
14
|
+
- Mod coverage: `HT`, `DT`, `HR`, `EZ`, and `MR`.
|
|
15
|
+
- Not supported: `RD`.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Main entry
|
|
20
|
+
|
|
21
|
+
Use the main entry if you already have `osuData`. This path does not need the parser peer dependencies.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { v1, calcAccuracy } from 'mania-judge'
|
|
25
|
+
|
|
26
|
+
const judgements = v1.playOsu(osuData)
|
|
27
|
+
const frames = v1.generateFramesOsu(judgements, osuData.hp)
|
|
28
|
+
const lastFrame = frames.at(-1)
|
|
29
|
+
|
|
30
|
+
if (lastFrame) {
|
|
31
|
+
const accuracy = calcAccuracy(lastFrame.resultCounts, v1.accTable)
|
|
32
|
+
console.log(lastFrame.resultCounts, lastFrame.maxCombo, lastFrame.life, accuracy)
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Parser entries
|
|
37
|
+
|
|
38
|
+
Use these entries if you want to parse `.osu` and `.osr`. They require the peer dependencies `osu-classes`, `osu-mania-stable`, and `osu-parsers`.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { parse } from 'mania-judge/osu-parsers'
|
|
42
|
+
|
|
43
|
+
const result = await parse(beatmapContent, replayBuffer)
|
|
44
|
+
console.log(result.osuData)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { parseFromPath } from 'mania-judge/osu-parsers/node'
|
|
49
|
+
|
|
50
|
+
const result = await parseFromPath('map.osu', 'score.osr')
|
|
51
|
+
console.log(result.osuData)
|
|
52
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll as t };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { _ as TimeLineFrame, c as HoldJudgementV1, d as JudgementV1, m as OsuData, n as BaseJudgement, o as HitResultTable, p as Note, r as Columns, s as HitWindows, t as Action } from "./types-3MDvQQxi.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/osu-v1/judgement.d.ts
|
|
4
|
+
declare const accTable: Readonly<HitResultTable<number>>;
|
|
5
|
+
declare function baseWindows(od: number): HitWindows;
|
|
6
|
+
declare function playColumn(notes: Note[], actions: Action[], windows: HitWindows): JudgementV1[];
|
|
7
|
+
declare function play(noteColumns: Columns<Note>, actionColumns: Columns<Action>, windows: HitWindows): Columns<JudgementV1>;
|
|
8
|
+
declare function playOsu(data: OsuData): Columns<JudgementV1>;
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/osu-v1/health.d.ts
|
|
11
|
+
declare function createLifeTable(hp: number, hpMultiplierNormal?: number): HitResultTable<number>;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/osu-v1/timeline.d.ts
|
|
14
|
+
declare function generateFrames(judgementColumns: Columns<JudgementV1>, lifeTable: HitResultTable<number>): TimeLineFrame[];
|
|
15
|
+
declare function generateFramesOsu(judgementColumns: Columns<JudgementV1>, hp: number): TimeLineFrame[];
|
|
16
|
+
declare namespace index_d_exports {
|
|
17
|
+
export { accTable, baseWindows, createLifeTable, generateFrames, generateFramesOsu, play, playColumn, playOsu };
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/column.d.ts
|
|
21
|
+
declare function createActionCursor(actions: Action[]): {
|
|
22
|
+
readonly time: number;
|
|
23
|
+
setNextTime(nextTime: number): void;
|
|
24
|
+
getHoldingAction(): Action | null;
|
|
25
|
+
getNextAction(): Action | null;
|
|
26
|
+
};
|
|
27
|
+
type ActionCursor = ReturnType<typeof createActionCursor>;
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/extensions.d.ts
|
|
30
|
+
declare function truncWindows(windows: Readonly<HitWindows>, scale?: number): HitWindows;
|
|
31
|
+
declare function calcAccuracy(resultCounts: Readonly<HitResultTable<number>>, accTable: Readonly<HitResultTable<number>>): number;
|
|
32
|
+
declare function compareJudgements<T extends BaseJudgement<Note>>(a: T, b: T): number;
|
|
33
|
+
declare function isHoldJudgement(judgement: JudgementV1): judgement is HoldJudgementV1;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { ActionCursor as a, truncWindows as i, compareJudgements as n, createActionCursor as o, isHoldJudgement as r, index_d_exports as s, calcAccuracy as t };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { _ as TimeLineFrame, a as HitResult, c as HoldJudgementV1, d as JudgementV1, f as JudgementV2, g as TapNote, h as TapJudgement, i as HIT_RESULTS, l as HoldJudgementV2, m as OsuData, n as BaseJudgement, o as HitResultTable, p as Note, r as Columns, s as HitWindows, t as Action, u as HoldNote } from "./types-3MDvQQxi.mjs";
|
|
2
|
+
import { a as ActionCursor, i as truncWindows, n as compareJudgements, o as createActionCursor, r as isHoldJudgement, s as index_d_exports, t as calcAccuracy } from "./index-Zuz8HPVe.mjs";
|
|
3
|
+
export { Action, ActionCursor, BaseJudgement, Columns, HIT_RESULTS, HitResult, HitResultTable, HitWindows, HoldJudgementV1, HoldJudgementV2, HoldNote, JudgementV1, JudgementV2, Note, OsuData, TapJudgement, TapNote, TimeLineFrame, calcAccuracy, compareJudgements, createActionCursor, isHoldJudgement, truncWindows, index_d_exports as v1 };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
|
|
2
|
+
//#region src/types.ts
|
|
3
|
+
const HIT_RESULTS = {
|
|
4
|
+
Perfect: 0,
|
|
5
|
+
Great: 1,
|
|
6
|
+
Good: 2,
|
|
7
|
+
Ok: 3,
|
|
8
|
+
Meh: 4,
|
|
9
|
+
Miss: 5
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/column.ts
|
|
13
|
+
function createActionCursor(actions) {
|
|
14
|
+
let index = 0;
|
|
15
|
+
let time = Number.MIN_SAFE_INTEGER;
|
|
16
|
+
let holdingAction = null;
|
|
17
|
+
return {
|
|
18
|
+
get time() {
|
|
19
|
+
return time;
|
|
20
|
+
},
|
|
21
|
+
setNextTime(nextTime) {
|
|
22
|
+
if (nextTime > time) {
|
|
23
|
+
time = nextTime;
|
|
24
|
+
while (index < actions.length && actions[index].release < time) index++;
|
|
25
|
+
if (index < actions.length && actions[index].press < time) holdingAction = actions[index++];
|
|
26
|
+
else holdingAction = null;
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
getHoldingAction() {
|
|
30
|
+
return holdingAction;
|
|
31
|
+
},
|
|
32
|
+
getNextAction() {
|
|
33
|
+
if (index < actions.length) return actions[index];
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/extensions.ts
|
|
40
|
+
const epsilon = 1e-6;
|
|
41
|
+
function truncWindows(windows, scale = 1) {
|
|
42
|
+
const truncated = [...windows];
|
|
43
|
+
for (let i = 0; i < truncated.length; i++) truncated[i] = Math.trunc(truncated[i] * scale + epsilon);
|
|
44
|
+
return truncated;
|
|
45
|
+
}
|
|
46
|
+
function calcAccuracy(resultCounts, accTable) {
|
|
47
|
+
let total = 0;
|
|
48
|
+
let acc = 0;
|
|
49
|
+
for (let i = HIT_RESULTS.Perfect; i <= HIT_RESULTS.Miss; i++) {
|
|
50
|
+
total += resultCounts[i];
|
|
51
|
+
acc += resultCounts[i] * accTable[i];
|
|
52
|
+
}
|
|
53
|
+
return total > 0 ? acc / total : 0;
|
|
54
|
+
}
|
|
55
|
+
function compareJudgements(a, b) {
|
|
56
|
+
if (a.exit !== b.exit) return a.exit - b.exit;
|
|
57
|
+
if (a.note.start !== b.note.start) return a.note.start - b.note.start;
|
|
58
|
+
return a.note.column - b.note.column;
|
|
59
|
+
}
|
|
60
|
+
function isHoldJudgement(judgement) {
|
|
61
|
+
return judgement.note.end !== void 0;
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/osu-v1/judgement.ts
|
|
65
|
+
const accTable = [
|
|
66
|
+
1,
|
|
67
|
+
1,
|
|
68
|
+
2 / 3,
|
|
69
|
+
1 / 3,
|
|
70
|
+
1 / 6,
|
|
71
|
+
0
|
|
72
|
+
];
|
|
73
|
+
function baseWindows(od) {
|
|
74
|
+
return [
|
|
75
|
+
16,
|
|
76
|
+
64 - 3 * od,
|
|
77
|
+
97 - 3 * od,
|
|
78
|
+
127 - 3 * od,
|
|
79
|
+
151 - 3 * od,
|
|
80
|
+
188 - 3 * od
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
function judgeTap(note, cursor, windows) {
|
|
84
|
+
const judgement = {
|
|
85
|
+
note,
|
|
86
|
+
enter: Math.max(note.start - windows[HIT_RESULTS.Miss], cursor.time),
|
|
87
|
+
exit: note.start + windows[HIT_RESULTS.Ok],
|
|
88
|
+
actions: [],
|
|
89
|
+
result: HIT_RESULTS.Miss
|
|
90
|
+
};
|
|
91
|
+
while (cursor.getNextAction() && cursor.getNextAction().press < judgement.enter) cursor.setNextTime(cursor.getNextAction().press + 1);
|
|
92
|
+
if (cursor.getNextAction() && cursor.getNextAction().press < judgement.exit) {
|
|
93
|
+
const action = cursor.getNextAction();
|
|
94
|
+
judgement.exit = action.press;
|
|
95
|
+
judgement.actions.push(action);
|
|
96
|
+
cursor.setNextTime(action.press + 1);
|
|
97
|
+
const delta = Math.abs(action.press - note.start);
|
|
98
|
+
for (let i = HIT_RESULTS.Perfect; i <= HIT_RESULTS.Miss; i++) if (delta <= windows[i]) {
|
|
99
|
+
judgement.result = i;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
} else cursor.setNextTime(judgement.exit);
|
|
103
|
+
cursor.setNextTime(judgement.note.start);
|
|
104
|
+
return judgement;
|
|
105
|
+
}
|
|
106
|
+
function generateTick(hold, action) {
|
|
107
|
+
const tickInterval = 100;
|
|
108
|
+
const ticks = [];
|
|
109
|
+
const first = action.press + tickInterval;
|
|
110
|
+
const stop = Math.min(action.release, hold.end);
|
|
111
|
+
for (let t = first; t < stop; t += tickInterval) ticks.push(t);
|
|
112
|
+
return ticks;
|
|
113
|
+
}
|
|
114
|
+
function judgeHold(note, cursor, windows, nextNote) {
|
|
115
|
+
const judgement = {
|
|
116
|
+
note,
|
|
117
|
+
enter: Math.max(note.start - windows[HIT_RESULTS.Miss], cursor.time),
|
|
118
|
+
exit: note.end + windows[HIT_RESULTS.Ok],
|
|
119
|
+
actions: [],
|
|
120
|
+
result: HIT_RESULTS.Miss,
|
|
121
|
+
ticks: []
|
|
122
|
+
};
|
|
123
|
+
const factors = [
|
|
124
|
+
1.2,
|
|
125
|
+
1.1,
|
|
126
|
+
1,
|
|
127
|
+
1,
|
|
128
|
+
1,
|
|
129
|
+
1
|
|
130
|
+
];
|
|
131
|
+
while (cursor.getNextAction() && cursor.getNextAction().press < judgement.enter) cursor.setNextTime(cursor.getNextAction().release + 1);
|
|
132
|
+
while (cursor.getNextAction() && cursor.getNextAction().release < note.end - windows[HIT_RESULTS.Meh]) {
|
|
133
|
+
const action = cursor.getNextAction();
|
|
134
|
+
judgement.actions.push(action);
|
|
135
|
+
cursor.setNextTime(action.release + 1);
|
|
136
|
+
if (judgement.breakTime === void 0) {
|
|
137
|
+
judgement.breakTime = action.release;
|
|
138
|
+
judgement.ticks = generateTick(note, action);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (cursor.getNextAction() && cursor.getNextAction().press >= judgement.exit) {
|
|
142
|
+
cursor.setNextTime(judgement.exit);
|
|
143
|
+
return judgement;
|
|
144
|
+
}
|
|
145
|
+
if (cursor.getNextAction()) {
|
|
146
|
+
const action = cursor.getNextAction();
|
|
147
|
+
if (nextNote && nextNote.end !== void 0 && action.press > note.start + windows[HIT_RESULTS.Meh] && action.press >= nextNote.start - windows[HIT_RESULTS.Miss]) {
|
|
148
|
+
judgement.exit = action.press;
|
|
149
|
+
cursor.setNextTime(action.press);
|
|
150
|
+
return judgement;
|
|
151
|
+
}
|
|
152
|
+
judgement.actions.push(action);
|
|
153
|
+
let press = action.press;
|
|
154
|
+
let release = action.release;
|
|
155
|
+
if (action.press < note.start - windows[HIT_RESULTS.Meh]) press = note.end - 1;
|
|
156
|
+
if (action.release >= note.end + windows[HIT_RESULTS.Meh]) release = note.end + windows[HIT_RESULTS.Meh];
|
|
157
|
+
cursor.setNextTime(release + 1);
|
|
158
|
+
const headDelta = Math.abs(press - note.start);
|
|
159
|
+
const tailDelta = Math.abs(release - note.end);
|
|
160
|
+
for (let i = HIT_RESULTS.Perfect; i <= HIT_RESULTS.Ok; i++) {
|
|
161
|
+
const window = windows[i] * factors[i];
|
|
162
|
+
if (headDelta <= window && headDelta + tailDelta <= window * 2) {
|
|
163
|
+
judgement.result = i;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (judgement.result === HIT_RESULTS.Miss) judgement.result = HIT_RESULTS.Meh;
|
|
168
|
+
if (judgement.result <= HIT_RESULTS.Great && judgement.breakTime !== void 0) judgement.result = HIT_RESULTS.Good;
|
|
169
|
+
if (judgement.breakTime === void 0) judgement.ticks = generateTick(note, action);
|
|
170
|
+
judgement.exit = release;
|
|
171
|
+
}
|
|
172
|
+
cursor.setNextTime(note.end);
|
|
173
|
+
return judgement;
|
|
174
|
+
}
|
|
175
|
+
function playColumn(notes, actions, windows) {
|
|
176
|
+
const judgements = [];
|
|
177
|
+
const cursor = createActionCursor(actions);
|
|
178
|
+
for (let i = 0; i < notes.length; i++) {
|
|
179
|
+
const note = notes[i];
|
|
180
|
+
const nextNote = notes[i + 1];
|
|
181
|
+
if (note.end === void 0) judgements.push(judgeTap(note, cursor, windows));
|
|
182
|
+
else judgements.push(judgeHold(note, cursor, windows, nextNote));
|
|
183
|
+
}
|
|
184
|
+
return judgements;
|
|
185
|
+
}
|
|
186
|
+
function play(noteColumns, actionColumns, windows) {
|
|
187
|
+
const judgements = [];
|
|
188
|
+
for (let i = 0; i < noteColumns.length; i++) judgements.push(playColumn(noteColumns[i], actionColumns[i], windows));
|
|
189
|
+
return judgements;
|
|
190
|
+
}
|
|
191
|
+
function playOsu(data) {
|
|
192
|
+
const windows = truncWindows(baseWindows(data.od), data.windowScale);
|
|
193
|
+
return play(data.noteColumns, data.actionColumns, windows);
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/utils.ts
|
|
197
|
+
function clamp(value, min, max) {
|
|
198
|
+
return Math.min(Math.max(value, min), max);
|
|
199
|
+
}
|
|
200
|
+
function difficultyRange(difficulty, min, mid, max) {
|
|
201
|
+
if (difficulty > 5) return mid + (max - mid) * ((difficulty - 5) / 5);
|
|
202
|
+
if (difficulty < 5) return mid + (mid - min) * ((difficulty - 5) / 5);
|
|
203
|
+
return mid;
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/osu-v1/health.ts
|
|
207
|
+
function getLifeIncreaseFor(result, hp, hpMultiplierNormal = 1) {
|
|
208
|
+
switch (result) {
|
|
209
|
+
case HIT_RESULTS.Perfect: return hpMultiplierNormal * (.0055 - hp * 5e-4);
|
|
210
|
+
case HIT_RESULTS.Great: return hpMultiplierNormal * (.005 - hp * 5e-4);
|
|
211
|
+
case HIT_RESULTS.Good: return hpMultiplierNormal * (.004 - hp * 4e-4);
|
|
212
|
+
case HIT_RESULTS.Ok: return 0;
|
|
213
|
+
case HIT_RESULTS.Meh: return -(hp + 1) * .0016;
|
|
214
|
+
case HIT_RESULTS.Miss: return -(hp + 1) * .0075;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function computeHpMultiplierNormal(judgementColumns, hp) {
|
|
218
|
+
const sortedByStart = judgementColumns.flat().sort((left, right) => left.note.start - right.note.start || compareJudgements(left, right));
|
|
219
|
+
if (sortedByStart.length === 0) return 1;
|
|
220
|
+
const hpRecoveryAvailable = difficultyRange(hp, .04, .02, 0);
|
|
221
|
+
let hpMultiplierNormal = 1;
|
|
222
|
+
while (true) {
|
|
223
|
+
let currentHpUncapped = 1;
|
|
224
|
+
for (const judgement of sortedByStart) {
|
|
225
|
+
if (isHoldJudgement(judgement)) for (const _tickTime of judgement.ticks) {
|
|
226
|
+
const tickIncrease = getLifeIncreaseFor(HIT_RESULTS.Great, hp, hpMultiplierNormal);
|
|
227
|
+
currentHpUncapped += tickIncrease;
|
|
228
|
+
}
|
|
229
|
+
const topLevelIncrease = getLifeIncreaseFor(HIT_RESULTS.Perfect, hp, hpMultiplierNormal);
|
|
230
|
+
currentHpUncapped += topLevelIncrease;
|
|
231
|
+
}
|
|
232
|
+
if ((currentHpUncapped - 1) / Math.max(1, sortedByStart.length) < hpRecoveryAvailable) {
|
|
233
|
+
hpMultiplierNormal *= 1.01;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
return hpMultiplierNormal;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function createLifeTable(hp, hpMultiplierNormal = 1) {
|
|
240
|
+
return [
|
|
241
|
+
getLifeIncreaseFor(HIT_RESULTS.Perfect, hp, hpMultiplierNormal),
|
|
242
|
+
getLifeIncreaseFor(HIT_RESULTS.Great, hp, hpMultiplierNormal),
|
|
243
|
+
getLifeIncreaseFor(HIT_RESULTS.Good, hp, hpMultiplierNormal),
|
|
244
|
+
getLifeIncreaseFor(HIT_RESULTS.Ok, hp, hpMultiplierNormal),
|
|
245
|
+
getLifeIncreaseFor(HIT_RESULTS.Meh, hp, hpMultiplierNormal),
|
|
246
|
+
getLifeIncreaseFor(HIT_RESULTS.Miss, hp, hpMultiplierNormal)
|
|
247
|
+
];
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/osu-v1/timeline.ts
|
|
251
|
+
function createEvents(judgement) {
|
|
252
|
+
const events = [{
|
|
253
|
+
time: judgement.exit,
|
|
254
|
+
judgement,
|
|
255
|
+
result: judgement.result,
|
|
256
|
+
affectsResultCounts: true
|
|
257
|
+
}];
|
|
258
|
+
if (isHoldJudgement(judgement)) for (const tick of judgement.ticks) events.push({
|
|
259
|
+
time: tick,
|
|
260
|
+
judgement,
|
|
261
|
+
result: HIT_RESULTS.Great,
|
|
262
|
+
affectsResultCounts: false
|
|
263
|
+
});
|
|
264
|
+
return events;
|
|
265
|
+
}
|
|
266
|
+
function compareEvents(left, right) {
|
|
267
|
+
if (left.time !== right.time) return left.time - right.time;
|
|
268
|
+
return compareJudgements(left.judgement, right.judgement);
|
|
269
|
+
}
|
|
270
|
+
function generateFrames(judgementColumns, lifeTable) {
|
|
271
|
+
const sorted = judgementColumns.flat().flatMap(createEvents).sort(compareEvents);
|
|
272
|
+
const frames = [];
|
|
273
|
+
const last = {
|
|
274
|
+
time: 0,
|
|
275
|
+
combo: 0,
|
|
276
|
+
maxCombo: 0,
|
|
277
|
+
resultCounts: [
|
|
278
|
+
0,
|
|
279
|
+
0,
|
|
280
|
+
0,
|
|
281
|
+
0,
|
|
282
|
+
0,
|
|
283
|
+
0
|
|
284
|
+
],
|
|
285
|
+
life: 1
|
|
286
|
+
};
|
|
287
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
288
|
+
const event = sorted[i];
|
|
289
|
+
last.time = event.time;
|
|
290
|
+
if (event.result < HIT_RESULTS.Miss) {
|
|
291
|
+
last.combo++;
|
|
292
|
+
if (last.combo > last.maxCombo) last.maxCombo = last.combo;
|
|
293
|
+
} else last.combo = 0;
|
|
294
|
+
if (event.affectsResultCounts) last.resultCounts[event.result]++;
|
|
295
|
+
last.life += lifeTable[event.result];
|
|
296
|
+
last.life = clamp(last.life, 0, 1);
|
|
297
|
+
if (sorted[i + 1]?.time === event.time) continue;
|
|
298
|
+
frames.push({
|
|
299
|
+
time: last.time,
|
|
300
|
+
combo: last.combo,
|
|
301
|
+
maxCombo: last.maxCombo,
|
|
302
|
+
resultCounts: [...last.resultCounts],
|
|
303
|
+
life: last.life
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return frames;
|
|
307
|
+
}
|
|
308
|
+
function generateFramesOsu(judgementColumns, hp) {
|
|
309
|
+
return generateFrames(judgementColumns, createLifeTable(hp, computeHpMultiplierNormal(judgementColumns, hp)));
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/osu-v1/index.ts
|
|
313
|
+
var osu_v1_exports = /* @__PURE__ */ __exportAll({
|
|
314
|
+
accTable: () => accTable,
|
|
315
|
+
baseWindows: () => baseWindows,
|
|
316
|
+
createLifeTable: () => createLifeTable,
|
|
317
|
+
generateFrames: () => generateFrames,
|
|
318
|
+
generateFramesOsu: () => generateFramesOsu,
|
|
319
|
+
play: () => play,
|
|
320
|
+
playColumn: () => playColumn,
|
|
321
|
+
playOsu: () => playOsu
|
|
322
|
+
});
|
|
323
|
+
//#endregion
|
|
324
|
+
export { HIT_RESULTS, calcAccuracy, compareJudgements, createActionCursor, isHoldJudgement, truncWindows, osu_v1_exports as v1 };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { m as OsuData } from "../types-3MDvQQxi.mjs";
|
|
2
|
+
import { n as convertReplay, r as parseWithMods, t as convertBeatmap } from "../shared-D-sop3c6.mjs";
|
|
3
|
+
import * as _$osu_mania_stable0 from "osu-mania-stable";
|
|
4
|
+
import * as _$osu_classes0 from "osu-classes";
|
|
5
|
+
|
|
6
|
+
//#region src/osu-parsers/node.d.ts
|
|
7
|
+
declare const parseFromPath: (beatmapPath: string, replayPath: string) => Promise<{
|
|
8
|
+
osuData: OsuData;
|
|
9
|
+
rawBeatmap: _$osu_mania_stable0.ManiaBeatmap;
|
|
10
|
+
rawScore: _$osu_classes0.Score;
|
|
11
|
+
}>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { convertBeatmap, convertReplay, parseFromPath, parseWithMods };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { n as convertReplay, r as parseWithMods, t as convertBeatmap } from "../shared-DJFUXeEy.mjs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
//#region src/osu-parsers/node.ts
|
|
4
|
+
const parseFromPath = async (beatmapPath, replayPath) => {
|
|
5
|
+
const [beatmapContent, replayBuffer] = await Promise.all([readFile(beatmapPath, "utf8"), readFile(replayPath)]);
|
|
6
|
+
return parseWithMods(beatmapContent, replayBuffer);
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { convertBeatmap, convertReplay, parseFromPath, parseWithMods };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { m as OsuData, p as Note, r as Columns, t as Action } from "./types-3MDvQQxi.mjs";
|
|
2
|
+
import { ManiaBeatmap, ManiaReplayFrame } from "osu-mania-stable";
|
|
3
|
+
import * as _$osu_classes0 from "osu-classes";
|
|
4
|
+
|
|
5
|
+
//#region src/osu-parsers/shared.d.ts
|
|
6
|
+
type ReplayBufferLike = ArrayBuffer | SharedArrayBuffer | Uint8Array | Buffer;
|
|
7
|
+
declare const convertBeatmap: (beatmap: ManiaBeatmap) => Columns<Note>;
|
|
8
|
+
declare const convertReplay: (frames: ManiaReplayFrame[], columns: number) => Columns<Action>;
|
|
9
|
+
declare const parseWithMods: (beatmapContent: string, replayBuffer: ReplayBufferLike) => Promise<{
|
|
10
|
+
osuData: OsuData;
|
|
11
|
+
rawBeatmap: ManiaBeatmap;
|
|
12
|
+
rawScore: _$osu_classes0.Score;
|
|
13
|
+
}>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { convertReplay as n, parseWithMods as r, convertBeatmap as t };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { BeatmapDecoder, ScoreDecoder } from "osu-parsers";
|
|
2
|
+
import { Hold, ManiaRuleset } from "osu-mania-stable";
|
|
3
|
+
import { ModBitwise } from "osu-classes";
|
|
4
|
+
//#region src/osu-parsers/shared.ts
|
|
5
|
+
const ruleset = new ManiaRuleset();
|
|
6
|
+
const beatmapDecoder = new BeatmapDecoder();
|
|
7
|
+
const scoreDecoder = new ScoreDecoder();
|
|
8
|
+
const convertBeatmap = (beatmap) => {
|
|
9
|
+
const columnsArray = Array.from({ length: beatmap.totalColumns }, () => []);
|
|
10
|
+
for (const hitObject of beatmap.hitObjects) {
|
|
11
|
+
const note = {
|
|
12
|
+
column: hitObject.column,
|
|
13
|
+
start: hitObject.startTime,
|
|
14
|
+
end: hitObject instanceof Hold ? hitObject.endTime : void 0
|
|
15
|
+
};
|
|
16
|
+
columnsArray[note.column].push(note);
|
|
17
|
+
}
|
|
18
|
+
return columnsArray;
|
|
19
|
+
};
|
|
20
|
+
const convertReplay = (frames, columns) => {
|
|
21
|
+
const columnsArray = Array.from({ length: columns }, () => []);
|
|
22
|
+
const lastPressTime = Array.from({ length: columns }, () => null);
|
|
23
|
+
for (const frame of frames) {
|
|
24
|
+
if (frame.startTime < 0) continue;
|
|
25
|
+
for (let i = 0; i < columns; i++) if (frame.actions.has(10 + i)) {
|
|
26
|
+
if (lastPressTime[i] === null) lastPressTime[i] = frame.startTime;
|
|
27
|
+
} else if (lastPressTime[i] !== null) {
|
|
28
|
+
columnsArray[i].push({
|
|
29
|
+
column: i,
|
|
30
|
+
press: lastPressTime[i],
|
|
31
|
+
release: frame.startTime
|
|
32
|
+
});
|
|
33
|
+
lastPressTime[i] = null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return columnsArray;
|
|
37
|
+
};
|
|
38
|
+
const parseWithMods = async (beatmapContent, replayBuffer) => {
|
|
39
|
+
const beatmap = beatmapDecoder.decodeFromString(beatmapContent, false);
|
|
40
|
+
const score = await scoreDecoder.decodeFromBuffer(replayBuffer, true);
|
|
41
|
+
score.info.ruleset = ruleset;
|
|
42
|
+
const maniaBeatmap = ruleset.applyToBeatmap(beatmap);
|
|
43
|
+
const columns = maniaBeatmap.totalColumns;
|
|
44
|
+
const maniaFrames = ruleset.applyToReplay(score.replay, maniaBeatmap).frames;
|
|
45
|
+
const mods = score.info.mods;
|
|
46
|
+
const maniaBeatmapWithMods = mods === null || mods.bitwise === 0 ? maniaBeatmap : ruleset.applyToBeatmapWithMods(maniaBeatmap, mods);
|
|
47
|
+
const osuData = {
|
|
48
|
+
od: beatmap.difficulty.overallDifficulty,
|
|
49
|
+
hp: beatmap.difficulty.drainRate,
|
|
50
|
+
windowScale: 1,
|
|
51
|
+
noteColumns: convertBeatmap(maniaBeatmapWithMods),
|
|
52
|
+
actionColumns: convertReplay(maniaFrames, columns)
|
|
53
|
+
};
|
|
54
|
+
if (mods?.has(ModBitwise.Easy)) {
|
|
55
|
+
osuData.windowScale = 1.4;
|
|
56
|
+
osuData.hp *= .5;
|
|
57
|
+
} else if (mods?.has(ModBitwise.HardRock)) {
|
|
58
|
+
osuData.windowScale = 1 / 1.4;
|
|
59
|
+
osuData.hp = Math.min(osuData.hp * 1.4, 10);
|
|
60
|
+
} else if (mods?.has(ModBitwise.DoubleTime)) osuData.windowScale = 1.5;
|
|
61
|
+
else if (mods?.has(ModBitwise.HalfTime)) osuData.windowScale = .75;
|
|
62
|
+
return {
|
|
63
|
+
osuData,
|
|
64
|
+
rawBeatmap: maniaBeatmap,
|
|
65
|
+
rawScore: score
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
export { convertReplay as n, parseWithMods as r, convertBeatmap as t };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
interface TapNote {
|
|
3
|
+
column: number;
|
|
4
|
+
start: number;
|
|
5
|
+
end?: undefined;
|
|
6
|
+
}
|
|
7
|
+
interface HoldNote {
|
|
8
|
+
column: number;
|
|
9
|
+
start: number;
|
|
10
|
+
end: number;
|
|
11
|
+
}
|
|
12
|
+
type Note = TapNote | HoldNote;
|
|
13
|
+
interface Action {
|
|
14
|
+
column: number;
|
|
15
|
+
press: number;
|
|
16
|
+
release: number;
|
|
17
|
+
}
|
|
18
|
+
type Columns<T> = T[][];
|
|
19
|
+
interface OsuData {
|
|
20
|
+
od: number;
|
|
21
|
+
hp: number;
|
|
22
|
+
windowScale: number;
|
|
23
|
+
noteColumns: Columns<Note>;
|
|
24
|
+
actionColumns: Columns<Action>;
|
|
25
|
+
}
|
|
26
|
+
declare const HIT_RESULTS: {
|
|
27
|
+
readonly Perfect: 0;
|
|
28
|
+
readonly Great: 1;
|
|
29
|
+
readonly Good: 2;
|
|
30
|
+
readonly Ok: 3;
|
|
31
|
+
readonly Meh: 4;
|
|
32
|
+
readonly Miss: 5;
|
|
33
|
+
};
|
|
34
|
+
type HitResult = (typeof HIT_RESULTS)[keyof typeof HIT_RESULTS];
|
|
35
|
+
type HitResultTable<T> = [T, T, T, T, T, T];
|
|
36
|
+
type HitWindows = HitResultTable<number>;
|
|
37
|
+
interface BaseJudgement<T extends Note> {
|
|
38
|
+
note: T;
|
|
39
|
+
enter: number;
|
|
40
|
+
exit: number;
|
|
41
|
+
actions: Action[];
|
|
42
|
+
}
|
|
43
|
+
interface TapJudgement extends BaseJudgement<TapNote> {
|
|
44
|
+
result: HitResult;
|
|
45
|
+
}
|
|
46
|
+
interface HoldJudgementV1 extends BaseJudgement<HoldNote> {
|
|
47
|
+
result: HitResult;
|
|
48
|
+
breakTime?: number;
|
|
49
|
+
ticks: number[];
|
|
50
|
+
}
|
|
51
|
+
interface HoldJudgementV2 extends BaseJudgement<HoldNote> {
|
|
52
|
+
headResult: HitResult;
|
|
53
|
+
tailResult: HitResult;
|
|
54
|
+
breakTime?: number;
|
|
55
|
+
}
|
|
56
|
+
type JudgementV1 = TapJudgement | HoldJudgementV1;
|
|
57
|
+
type JudgementV2 = TapJudgement | HoldJudgementV2;
|
|
58
|
+
interface TimeLineFrame {
|
|
59
|
+
time: number;
|
|
60
|
+
combo: number;
|
|
61
|
+
maxCombo: number;
|
|
62
|
+
resultCounts: HitResultTable<number>;
|
|
63
|
+
life: number;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { TimeLineFrame as _, HitResult as a, HoldJudgementV1 as c, JudgementV1 as d, JudgementV2 as f, TapNote as g, TapJudgement as h, HIT_RESULTS as i, HoldJudgementV2 as l, OsuData as m, BaseJudgement as n, HitResultTable as o, Note as p, Columns as r, HitWindows as s, Action as t, HoldNote as u };
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mania-judge",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Simulate osu!stable mania judgements.",
|
|
6
|
+
"author": "zzzzv",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/zzzzv/mania-judge#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/zzzzv/mania-judge.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/zzzzv/mania-judge/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"osu",
|
|
18
|
+
"mania",
|
|
19
|
+
"replay"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./dist/index.mjs",
|
|
23
|
+
"./osu-parsers": "./dist/osu-parsers/index.mjs",
|
|
24
|
+
"./osu-parsers/node": "./dist/osu-parsers/node.mjs",
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsdown",
|
|
32
|
+
"dev": "tsdown --watch",
|
|
33
|
+
"generate:test-json:tap-only": "node --env-file=.env --import tsx tests/generate-test-json.ts tap-only",
|
|
34
|
+
"generate:test-json:hold": "node --env-file=.env --import tsx tests/generate-test-json.ts hold",
|
|
35
|
+
"generate:test-json:mods": "node --env-file=.env --import tsx tests/generate-test-json.ts mods",
|
|
36
|
+
"generate:test-files": "node --import tsx tests/generate-osu-files.ts",
|
|
37
|
+
"test": "vitest",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"prepublishOnly": "pnpm run build"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"osu-classes": "^3.2.0-beta.0",
|
|
43
|
+
"osu-mania-stable": "^5.0.1",
|
|
44
|
+
"osu-parsers": "^4.2.0-beta.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependenciesMeta": {
|
|
47
|
+
"osu-classes": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"osu-mania-stable": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"osu-parsers": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@types/node": "^25.5.0",
|
|
59
|
+
"@typescript/native-preview": "7.0.0-dev.20260328.1",
|
|
60
|
+
"jszip": "^3.10.1",
|
|
61
|
+
"osu-stable-db": "^0.2.4",
|
|
62
|
+
"tsdown": "^0.21.7",
|
|
63
|
+
"tsx": "^4.21.0",
|
|
64
|
+
"typescript": "^6.0.2",
|
|
65
|
+
"vitest": "^4.1.2"
|
|
66
|
+
}
|
|
67
|
+
}
|