mania-judge 0.2.0 → 0.3.1
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/LICENSE +21 -0
- package/README.md +15 -5
- package/dist/index.d.mts +66 -29
- package/dist/index.mjs +313 -81
- package/package.json +6 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 zzzzv
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,16 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
Work in progress.
|
|
4
4
|
|
|
5
|
-
Simulates osu!
|
|
5
|
+
Simulates osu!mania judgements.
|
|
6
6
|
|
|
7
7
|
## Status
|
|
8
8
|
|
|
9
|
+
- Score is not implemented.
|
|
10
|
+
- Mods: support is determined by osu-mania-io. Current tested coverage includes `HT`, `DT`, `HR`, `EZ`, and `MR`.
|
|
11
|
+
|
|
12
|
+
### v1
|
|
13
|
+
|
|
9
14
|
- Implemented: judgements, combo, and life.
|
|
10
|
-
- Not implemented: score.
|
|
11
15
|
- Tap-only: accurate in current tests.
|
|
12
|
-
- Hold:
|
|
13
|
-
-
|
|
14
|
-
|
|
16
|
+
- Hold: validated by accuracy-only tests with average error capped at 0.002 and max error capped at 0.004.
|
|
17
|
+
- Mods fixtures: accuracy-only tests cap average error at 0.002 and max error at 0.004.
|
|
18
|
+
|
|
19
|
+
### lazer
|
|
20
|
+
|
|
21
|
+
- Implemented: judgements.
|
|
22
|
+
- Tap-only: accurate in current tests.
|
|
23
|
+
- Hold: validated by accuracy-only tests with average error capped at 0.001 and max error capped at 0.002.
|
|
24
|
+
- Mods fixtures: accuracy-only tests cap average error at 0.0005 and max error at 0.002.
|
|
15
25
|
|
|
16
26
|
## Usage
|
|
17
27
|
|
package/dist/index.d.mts
CHANGED
|
@@ -35,27 +35,13 @@ declare const HIT_RESULTS: {
|
|
|
35
35
|
type HitResult = (typeof HIT_RESULTS)[keyof typeof HIT_RESULTS];
|
|
36
36
|
type HitResultTable<T> = [T, T, T, T, T, T];
|
|
37
37
|
type HitWindows = HitResultTable<number>;
|
|
38
|
-
interface
|
|
39
|
-
note:
|
|
38
|
+
interface TapJudgement {
|
|
39
|
+
note: TapNote;
|
|
40
40
|
enter: number;
|
|
41
41
|
exit: number;
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
interface TapJudgement extends BaseJudgement<TapNote> {
|
|
45
|
-
result: HitResult;
|
|
46
|
-
}
|
|
47
|
-
interface HoldJudgementV1 extends BaseJudgement<HoldNote> {
|
|
42
|
+
action?: Action;
|
|
48
43
|
result: HitResult;
|
|
49
|
-
breakTime?: number;
|
|
50
|
-
ticks: number[];
|
|
51
44
|
}
|
|
52
|
-
interface HoldJudgementV2 extends BaseJudgement<HoldNote> {
|
|
53
|
-
headResult: HitResult;
|
|
54
|
-
tailResult: HitResult;
|
|
55
|
-
breakTime?: number;
|
|
56
|
-
}
|
|
57
|
-
type JudgementV1 = TapJudgement | HoldJudgementV1;
|
|
58
|
-
type JudgementV2 = TapJudgement | HoldJudgementV2;
|
|
59
45
|
interface TimeLineFrame {
|
|
60
46
|
time: number;
|
|
61
47
|
combo: number;
|
|
@@ -64,21 +50,73 @@ interface TimeLineFrame {
|
|
|
64
50
|
life: number;
|
|
65
51
|
}
|
|
66
52
|
//#endregion
|
|
53
|
+
//#region src/osu-v1/types.d.ts
|
|
54
|
+
interface HoldJudgementV1 {
|
|
55
|
+
note: HoldNote;
|
|
56
|
+
enter: number;
|
|
57
|
+
exit: number;
|
|
58
|
+
actions: Action[];
|
|
59
|
+
result: HitResult;
|
|
60
|
+
breakTime?: number;
|
|
61
|
+
ticks: number[];
|
|
62
|
+
}
|
|
63
|
+
type JudgementV1 = TapJudgement | HoldJudgementV1;
|
|
64
|
+
declare function isHoldJudgement(judgement: JudgementV1): judgement is HoldJudgementV1;
|
|
65
|
+
declare function countResults(judgements: JudgementV1[]): HitResultTable<number>;
|
|
66
|
+
declare const accTable$1: Readonly<HitResultTable<number>>;
|
|
67
|
+
declare function baseWindows$1(od: number): HitWindows;
|
|
68
|
+
//#endregion
|
|
67
69
|
//#region src/osu-v1/judgement.d.ts
|
|
68
|
-
declare
|
|
69
|
-
declare function
|
|
70
|
-
declare function
|
|
71
|
-
declare function play(noteColumns: Columns<Note>, actionColumns: Columns<Action>, windows: HitWindows): Columns<JudgementV1>;
|
|
72
|
-
declare function playOsu(data: OsuData): Columns<JudgementV1>;
|
|
70
|
+
declare function playColumn$1(notes: Note[], actions: Action[], windows: HitWindows): JudgementV1[];
|
|
71
|
+
declare function play$1(noteColumns: Columns<Note>, actionColumns: Columns<Action>, windows: HitWindows): Columns<JudgementV1>;
|
|
72
|
+
declare function playOsu$1(data: OsuData): Columns<JudgementV1>;
|
|
73
73
|
//#endregion
|
|
74
74
|
//#region src/osu-v1/health.d.ts
|
|
75
75
|
declare function createLifeTable(hp: number, hpMultiplierNormal?: number): HitResultTable<number>;
|
|
76
76
|
//#endregion
|
|
77
77
|
//#region src/osu-v1/timeline.d.ts
|
|
78
|
-
declare function generateFrames(judgementColumns: Columns<JudgementV1>, lifeTable: HitResultTable<number>): TimeLineFrame[];
|
|
78
|
+
declare function generateFrames$1(judgementColumns: Columns<JudgementV1>, lifeTable: HitResultTable<number>): TimeLineFrame[];
|
|
79
79
|
declare function generateFramesOsu(judgementColumns: Columns<JudgementV1>, hp: number): TimeLineFrame[];
|
|
80
|
+
declare namespace index_d_exports$1 {
|
|
81
|
+
export { HoldJudgementV1, JudgementV1, accTable$1 as accTable, baseWindows$1 as baseWindows, countResults, createLifeTable, generateFrames$1 as generateFrames, generateFramesOsu, isHoldJudgement, play$1 as play, playColumn$1 as playColumn, playOsu$1 as playOsu };
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/osu-lazer/types.d.ts
|
|
85
|
+
interface HoldJudgementV2 {
|
|
86
|
+
note: HoldNote;
|
|
87
|
+
headEnter: number;
|
|
88
|
+
headExit: number;
|
|
89
|
+
tailEnter: number;
|
|
90
|
+
tailExit: number;
|
|
91
|
+
actions: Action[];
|
|
92
|
+
headResult: HitResult;
|
|
93
|
+
tailResult: HitResult;
|
|
94
|
+
breakTime?: number;
|
|
95
|
+
}
|
|
96
|
+
type JudgementV2 = TapJudgement | HoldJudgementV2;
|
|
97
|
+
declare function isHoldV2(judgement: JudgementV2): judgement is HoldJudgementV2;
|
|
98
|
+
/** Extract the statistics result from a judgement (head result for holds). */
|
|
99
|
+
declare function getResult(judgement: JudgementV2): HitResult;
|
|
100
|
+
/** Accuracy weights matching lazer's mania scoring (Perfect=305, Great=300, etc.). */
|
|
101
|
+
declare const accTable: Readonly<HitResultTable<number>>;
|
|
102
|
+
declare function baseWindows(od: number): HitWindows;
|
|
103
|
+
declare function tailWindows(headWindows: Readonly<HitWindows>): HitWindows;
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/osu-lazer/judgement.d.ts
|
|
106
|
+
declare function playColumn(notes: Note[], actions: Action[], windows: HitWindows, tailWindows?: HitWindows): JudgementV2[];
|
|
107
|
+
declare function play(noteColumns: Columns<Note>, actionColumns: Columns<Action>, windows: HitWindows, tailWindows?: HitWindows): Columns<JudgementV2>;
|
|
108
|
+
declare function playOsu(data: OsuData): Columns<JudgementV2>;
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/osu-lazer/timeline.d.ts
|
|
111
|
+
/**
|
|
112
|
+
* Generate timeline frames from judgement columns.
|
|
113
|
+
*
|
|
114
|
+
* Tracks combo, max combo, and result counts over time.
|
|
115
|
+
* Health/life simulation is not included (use the osu-v1 variant for that).
|
|
116
|
+
*/
|
|
117
|
+
declare function generateFrames(judgementColumns: Columns<JudgementV2>): TimeLineFrame[];
|
|
80
118
|
declare namespace index_d_exports {
|
|
81
|
-
export { accTable, baseWindows,
|
|
119
|
+
export { HoldJudgementV2, JudgementV2, accTable, baseWindows, generateFrames, getResult, isHoldV2, play, playColumn, playOsu, tailWindows };
|
|
82
120
|
}
|
|
83
121
|
//#endregion
|
|
84
122
|
//#region src/column.d.ts
|
|
@@ -112,11 +150,10 @@ declare function replayToActionColumns(frames: readonly {
|
|
|
112
150
|
readonly columns: readonly boolean[];
|
|
113
151
|
}[], keyCount: number): Columns<Action>;
|
|
114
152
|
//#endregion
|
|
115
|
-
//#region src/
|
|
153
|
+
//#region src/utils.d.ts
|
|
154
|
+
declare function clamp(value: number, min: number, max: number): number;
|
|
155
|
+
declare function difficultyRange(difficulty: number, min: number, mid: number, max: number): number;
|
|
116
156
|
declare function truncWindows(windows: Readonly<HitWindows>, scale?: number): HitWindows;
|
|
117
157
|
declare function calcAccuracy(resultCounts: Readonly<HitResultTable<number>>, accTable: Readonly<HitResultTable<number>>): number;
|
|
118
|
-
declare function compareJudgements<T extends BaseJudgement<Note>>(a: T, b: T): number;
|
|
119
|
-
declare function isHoldJudgement(judgement: JudgementV1): judgement is HoldJudgementV1;
|
|
120
|
-
declare function countResults(judgements: JudgementV1[]): HitResultTable<number>;
|
|
121
158
|
//#endregion
|
|
122
|
-
export { Action, ActionCursor,
|
|
159
|
+
export { Action, ActionCursor, Columns, HIT_RESULTS, HitResult, HitResultTable, HitWindows, type HoldJudgementV1, type HoldJudgementV2, HoldNote, type JudgementV1, type JudgementV2, Note, OsuData, TapJudgement, TapNote, TimeLineFrame, beatmapToNoteColumns, calcAccuracy, clamp, createActionCursor, difficultyRange, index_d_exports as lazer, replayToActionColumns, truncWindows, index_d_exports$1 as v1 };
|
package/dist/index.mjs
CHANGED
|
@@ -9,6 +9,42 @@ const HIT_RESULTS = {
|
|
|
9
9
|
Miss: 5
|
|
10
10
|
};
|
|
11
11
|
//#endregion
|
|
12
|
+
//#region src/osu-v1/types.ts
|
|
13
|
+
function isHoldJudgement(judgement) {
|
|
14
|
+
return judgement.note.end !== void 0;
|
|
15
|
+
}
|
|
16
|
+
function countResults(judgements) {
|
|
17
|
+
return judgements.reduce((sum, j) => {
|
|
18
|
+
sum[j.result] += 1;
|
|
19
|
+
return sum;
|
|
20
|
+
}, [
|
|
21
|
+
0,
|
|
22
|
+
0,
|
|
23
|
+
0,
|
|
24
|
+
0,
|
|
25
|
+
0,
|
|
26
|
+
0
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
const accTable$1 = [
|
|
30
|
+
1,
|
|
31
|
+
1,
|
|
32
|
+
2 / 3,
|
|
33
|
+
1 / 3,
|
|
34
|
+
1 / 6,
|
|
35
|
+
0
|
|
36
|
+
];
|
|
37
|
+
function baseWindows$1(od) {
|
|
38
|
+
return [
|
|
39
|
+
16,
|
|
40
|
+
64 - 3 * od,
|
|
41
|
+
97 - 3 * od,
|
|
42
|
+
127 - 3 * od,
|
|
43
|
+
151 - 3 * od,
|
|
44
|
+
188 - 3 * od
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
12
48
|
//#region src/column.ts
|
|
13
49
|
function createActionCursor(actions) {
|
|
14
50
|
let index = 0;
|
|
@@ -73,8 +109,16 @@ function replayToActionColumns(frames, keyCount) {
|
|
|
73
109
|
return columns;
|
|
74
110
|
}
|
|
75
111
|
//#endregion
|
|
76
|
-
//#region src/
|
|
112
|
+
//#region src/utils.ts
|
|
77
113
|
const epsilon = 1e-6;
|
|
114
|
+
function clamp(value, min, max) {
|
|
115
|
+
return Math.min(Math.max(value, min), max);
|
|
116
|
+
}
|
|
117
|
+
function difficultyRange(difficulty, min, mid, max) {
|
|
118
|
+
if (difficulty > 5) return mid + (max - mid) * ((difficulty - 5) / 5);
|
|
119
|
+
if (difficulty < 5) return mid + (mid - min) * ((difficulty - 5) / 5);
|
|
120
|
+
return mid;
|
|
121
|
+
}
|
|
78
122
|
function truncWindows(windows, scale = 1) {
|
|
79
123
|
const truncated = [...windows];
|
|
80
124
|
for (let i = 0; i < truncated.length; i++) truncated[i] = Math.trunc(truncated[i] * scale + epsilon);
|
|
@@ -89,60 +133,21 @@ function calcAccuracy(resultCounts, accTable) {
|
|
|
89
133
|
}
|
|
90
134
|
return total > 0 ? acc / total : 0;
|
|
91
135
|
}
|
|
92
|
-
function compareJudgements(a, b) {
|
|
93
|
-
if (a.exit !== b.exit) return a.exit - b.exit;
|
|
94
|
-
if (a.note.start !== b.note.start) return a.note.start - b.note.start;
|
|
95
|
-
return a.note.column - b.note.column;
|
|
96
|
-
}
|
|
97
|
-
function isHoldJudgement(judgement) {
|
|
98
|
-
return judgement.note.end !== void 0;
|
|
99
|
-
}
|
|
100
|
-
function countResults(judgements) {
|
|
101
|
-
return judgements.reduce((sum, j) => {
|
|
102
|
-
sum[j.result] += 1;
|
|
103
|
-
return sum;
|
|
104
|
-
}, [
|
|
105
|
-
0,
|
|
106
|
-
0,
|
|
107
|
-
0,
|
|
108
|
-
0,
|
|
109
|
-
0,
|
|
110
|
-
0
|
|
111
|
-
]);
|
|
112
|
-
}
|
|
113
136
|
//#endregion
|
|
114
137
|
//#region src/osu-v1/judgement.ts
|
|
115
|
-
|
|
116
|
-
1,
|
|
117
|
-
1,
|
|
118
|
-
2 / 3,
|
|
119
|
-
1 / 3,
|
|
120
|
-
1 / 6,
|
|
121
|
-
0
|
|
122
|
-
];
|
|
123
|
-
function baseWindows(od) {
|
|
124
|
-
return [
|
|
125
|
-
16,
|
|
126
|
-
64 - 3 * od,
|
|
127
|
-
97 - 3 * od,
|
|
128
|
-
127 - 3 * od,
|
|
129
|
-
151 - 3 * od,
|
|
130
|
-
188 - 3 * od
|
|
131
|
-
];
|
|
132
|
-
}
|
|
133
|
-
function judgeTap(note, cursor, windows) {
|
|
138
|
+
function judgeTap$1(note, cursor, windows) {
|
|
134
139
|
const judgement = {
|
|
135
140
|
note,
|
|
136
141
|
enter: Math.max(note.start - windows[HIT_RESULTS.Miss], cursor.time),
|
|
137
142
|
exit: note.start + windows[HIT_RESULTS.Ok],
|
|
138
|
-
|
|
143
|
+
action: void 0,
|
|
139
144
|
result: HIT_RESULTS.Miss
|
|
140
145
|
};
|
|
141
146
|
while (cursor.getNextAction() && cursor.getNextAction().press < judgement.enter) cursor.setNextTime(cursor.getNextAction().press + 1);
|
|
142
147
|
if (cursor.getNextAction() && cursor.getNextAction().press < judgement.exit) {
|
|
143
148
|
const action = cursor.getNextAction();
|
|
144
149
|
judgement.exit = action.press;
|
|
145
|
-
judgement.
|
|
150
|
+
judgement.action = action;
|
|
146
151
|
cursor.setNextTime(action.press + 1);
|
|
147
152
|
const delta = Math.abs(action.press - note.start);
|
|
148
153
|
for (let i = HIT_RESULTS.Perfect; i <= HIT_RESULTS.Miss; i++) if (delta <= windows[i]) {
|
|
@@ -161,7 +166,7 @@ function generateTick(hold, action) {
|
|
|
161
166
|
for (let t = first; t < stop; t += tickInterval) ticks.push(t);
|
|
162
167
|
return ticks;
|
|
163
168
|
}
|
|
164
|
-
function judgeHold(note, cursor, windows, nextNote) {
|
|
169
|
+
function judgeHold$1(note, cursor, windows, lnWindows, nextNote) {
|
|
165
170
|
const judgement = {
|
|
166
171
|
note,
|
|
167
172
|
enter: Math.max(note.start - windows[HIT_RESULTS.Miss], cursor.time),
|
|
@@ -170,14 +175,6 @@ function judgeHold(note, cursor, windows, nextNote) {
|
|
|
170
175
|
result: HIT_RESULTS.Miss,
|
|
171
176
|
ticks: []
|
|
172
177
|
};
|
|
173
|
-
const factors = [
|
|
174
|
-
1.2,
|
|
175
|
-
1.1,
|
|
176
|
-
1,
|
|
177
|
-
1,
|
|
178
|
-
1,
|
|
179
|
-
1
|
|
180
|
-
];
|
|
181
178
|
while (cursor.getNextAction() && cursor.getNextAction().press < judgement.enter) cursor.setNextTime(cursor.getNextAction().release + 1);
|
|
182
179
|
while (cursor.getNextAction() && cursor.getNextAction().release < note.end - windows[HIT_RESULTS.Meh]) {
|
|
183
180
|
const action = cursor.getNextAction();
|
|
@@ -208,7 +205,7 @@ function judgeHold(note, cursor, windows, nextNote) {
|
|
|
208
205
|
const headDelta = Math.abs(press - note.start);
|
|
209
206
|
const tailDelta = Math.abs(release - note.end);
|
|
210
207
|
for (let i = HIT_RESULTS.Perfect; i <= HIT_RESULTS.Ok; i++) {
|
|
211
|
-
const window =
|
|
208
|
+
const window = lnWindows[i];
|
|
212
209
|
if (headDelta <= window && headDelta + tailDelta <= window * 2) {
|
|
213
210
|
judgement.result = i;
|
|
214
211
|
break;
|
|
@@ -222,38 +219,42 @@ function judgeHold(note, cursor, windows, nextNote) {
|
|
|
222
219
|
cursor.setNextTime(note.end);
|
|
223
220
|
return judgement;
|
|
224
221
|
}
|
|
225
|
-
function playColumn(notes, actions, windows) {
|
|
222
|
+
function playColumn$1(notes, actions, windows) {
|
|
226
223
|
const judgements = [];
|
|
227
224
|
const cursor = createActionCursor(actions);
|
|
225
|
+
const lnFactors = [
|
|
226
|
+
1.2,
|
|
227
|
+
1.1,
|
|
228
|
+
1,
|
|
229
|
+
1,
|
|
230
|
+
1,
|
|
231
|
+
1
|
|
232
|
+
];
|
|
233
|
+
const lnWindows = truncWindows(windows.map((w, i) => w * lnFactors[i]), 1);
|
|
234
|
+
windows = truncWindows(windows, 1);
|
|
228
235
|
for (let i = 0; i < notes.length; i++) {
|
|
229
236
|
const note = notes[i];
|
|
230
237
|
const nextNote = notes[i + 1];
|
|
231
|
-
if (note.end === void 0) judgements.push(judgeTap(note, cursor, windows));
|
|
232
|
-
else judgements.push(judgeHold(note, cursor, windows, nextNote));
|
|
238
|
+
if (note.end === void 0) judgements.push(judgeTap$1(note, cursor, windows));
|
|
239
|
+
else judgements.push(judgeHold$1(note, cursor, windows, lnWindows, nextNote));
|
|
233
240
|
}
|
|
234
241
|
return judgements;
|
|
235
242
|
}
|
|
236
|
-
function play(noteColumns, actionColumns, windows) {
|
|
243
|
+
function play$1(noteColumns, actionColumns, windows) {
|
|
237
244
|
const judgements = [];
|
|
238
|
-
for (let i = 0; i < noteColumns.length; i++) judgements.push(playColumn(noteColumns[i], actionColumns[i], windows));
|
|
245
|
+
for (let i = 0; i < noteColumns.length; i++) judgements.push(playColumn$1(noteColumns[i], actionColumns[i], windows));
|
|
239
246
|
return judgements;
|
|
240
247
|
}
|
|
241
|
-
function playOsu(data) {
|
|
242
|
-
const windows =
|
|
243
|
-
return play(data.noteColumns, data.actionColumns, windows);
|
|
244
|
-
}
|
|
245
|
-
//#endregion
|
|
246
|
-
//#region src/utils.ts
|
|
247
|
-
function clamp(value, min, max) {
|
|
248
|
-
return Math.min(Math.max(value, min), max);
|
|
249
|
-
}
|
|
250
|
-
function difficultyRange(difficulty, min, mid, max) {
|
|
251
|
-
if (difficulty > 5) return mid + (max - mid) * ((difficulty - 5) / 5);
|
|
252
|
-
if (difficulty < 5) return mid + (mid - min) * ((difficulty - 5) / 5);
|
|
253
|
-
return mid;
|
|
248
|
+
function playOsu$1(data) {
|
|
249
|
+
const windows = baseWindows$1(data.od).map((w) => w * data.speedRate * data.windowScale);
|
|
250
|
+
return play$1(data.noteColumns, data.actionColumns, windows);
|
|
254
251
|
}
|
|
255
252
|
//#endregion
|
|
256
253
|
//#region src/osu-v1/health.ts
|
|
254
|
+
function compareJudgements(a, b) {
|
|
255
|
+
if (a.exit !== b.exit) return a.exit - b.exit;
|
|
256
|
+
return a.note.start - b.note.start;
|
|
257
|
+
}
|
|
257
258
|
function getLifeIncreaseFor(result, hp, hpMultiplierNormal = 1) {
|
|
258
259
|
switch (result) {
|
|
259
260
|
case HIT_RESULTS.Perfect: return hpMultiplierNormal * (.0055 - hp * 5e-4);
|
|
@@ -298,7 +299,7 @@ function createLifeTable(hp, hpMultiplierNormal = 1) {
|
|
|
298
299
|
}
|
|
299
300
|
//#endregion
|
|
300
301
|
//#region src/osu-v1/timeline.ts
|
|
301
|
-
function createEvents(judgement) {
|
|
302
|
+
function createEvents$1(judgement) {
|
|
302
303
|
const events = [{
|
|
303
304
|
time: judgement.exit,
|
|
304
305
|
judgement,
|
|
@@ -313,12 +314,14 @@ function createEvents(judgement) {
|
|
|
313
314
|
});
|
|
314
315
|
return events;
|
|
315
316
|
}
|
|
316
|
-
function compareEvents(left, right) {
|
|
317
|
+
function compareEvents$1(left, right) {
|
|
317
318
|
if (left.time !== right.time) return left.time - right.time;
|
|
318
|
-
|
|
319
|
+
const a = left.judgement, b = right.judgement;
|
|
320
|
+
if (a.exit !== b.exit) return a.exit - b.exit;
|
|
321
|
+
return a.note.start - b.note.start;
|
|
319
322
|
}
|
|
320
|
-
function generateFrames(judgementColumns, lifeTable) {
|
|
321
|
-
const sorted = judgementColumns.flat().flatMap(createEvents).sort(compareEvents);
|
|
323
|
+
function generateFrames$1(judgementColumns, lifeTable) {
|
|
324
|
+
const sorted = judgementColumns.flat().flatMap(createEvents$1).sort(compareEvents$1);
|
|
322
325
|
const frames = [];
|
|
323
326
|
const last = {
|
|
324
327
|
time: 0,
|
|
@@ -356,19 +359,248 @@ function generateFrames(judgementColumns, lifeTable) {
|
|
|
356
359
|
return frames;
|
|
357
360
|
}
|
|
358
361
|
function generateFramesOsu(judgementColumns, hp) {
|
|
359
|
-
return generateFrames(judgementColumns, createLifeTable(hp, computeHpMultiplierNormal(judgementColumns, hp)));
|
|
362
|
+
return generateFrames$1(judgementColumns, createLifeTable(hp, computeHpMultiplierNormal(judgementColumns, hp)));
|
|
360
363
|
}
|
|
361
364
|
//#endregion
|
|
362
365
|
//#region src/osu-v1/index.ts
|
|
363
366
|
var osu_v1_exports = /* @__PURE__ */ __exportAll({
|
|
367
|
+
accTable: () => accTable$1,
|
|
368
|
+
baseWindows: () => baseWindows$1,
|
|
369
|
+
countResults: () => countResults,
|
|
370
|
+
createLifeTable: () => createLifeTable,
|
|
371
|
+
generateFrames: () => generateFrames$1,
|
|
372
|
+
generateFramesOsu: () => generateFramesOsu,
|
|
373
|
+
isHoldJudgement: () => isHoldJudgement,
|
|
374
|
+
play: () => play$1,
|
|
375
|
+
playColumn: () => playColumn$1,
|
|
376
|
+
playOsu: () => playOsu$1
|
|
377
|
+
});
|
|
378
|
+
//#endregion
|
|
379
|
+
//#region src/osu-lazer/types.ts
|
|
380
|
+
function isHoldV2(judgement) {
|
|
381
|
+
return "headResult" in judgement;
|
|
382
|
+
}
|
|
383
|
+
/** Extract the statistics result from a judgement (head result for holds). */
|
|
384
|
+
function getResult(judgement) {
|
|
385
|
+
return isHoldV2(judgement) ? judgement.headResult : judgement.result;
|
|
386
|
+
}
|
|
387
|
+
/** Accuracy weights matching lazer's mania scoring (Perfect=305, Great=300, etc.). */
|
|
388
|
+
const accTable = [
|
|
389
|
+
305 / 305,
|
|
390
|
+
300 / 305,
|
|
391
|
+
200 / 305,
|
|
392
|
+
100 / 305,
|
|
393
|
+
50 / 305,
|
|
394
|
+
0
|
|
395
|
+
];
|
|
396
|
+
function baseWindows(od) {
|
|
397
|
+
return [
|
|
398
|
+
difficultyRange(od, 22.4, 19.4, 13.9),
|
|
399
|
+
difficultyRange(od, 64, 49, 34),
|
|
400
|
+
difficultyRange(od, 97, 82, 67),
|
|
401
|
+
difficultyRange(od, 127, 112, 97),
|
|
402
|
+
difficultyRange(od, 151, 136, 121),
|
|
403
|
+
difficultyRange(od, 188, 173, 158)
|
|
404
|
+
];
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Build 1.5× expanded windows for hold tail judgement.
|
|
408
|
+
* Matches lazer's CheckForResult which divides timeOffset by 1.5
|
|
409
|
+
* before comparing against the base (floor+0.5) windows:
|
|
410
|
+
* |delta| / 1.5 <= floor(base) + 0.5
|
|
411
|
+
* ⇔ |delta| <= (floor(base) + 0.5) * 1.5
|
|
412
|
+
*/
|
|
413
|
+
const RELEASE_WINDOW_LENIENCE = 1.5;
|
|
414
|
+
function tailWindows(headWindows) {
|
|
415
|
+
return headWindows.map((w) => (w + .5) * RELEASE_WINDOW_LENIENCE);
|
|
416
|
+
}
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region src/osu-lazer/judgement.ts
|
|
419
|
+
function judgeTap(note, cursor, windows, nextNote) {
|
|
420
|
+
const judgement = {
|
|
421
|
+
note,
|
|
422
|
+
enter: Math.max(note.start - windows[HIT_RESULTS.Miss], cursor.time),
|
|
423
|
+
exit: note.start + windows[HIT_RESULTS.Meh],
|
|
424
|
+
action: void 0,
|
|
425
|
+
result: HIT_RESULTS.Miss
|
|
426
|
+
};
|
|
427
|
+
while (cursor.getNextAction() && cursor.getNextAction().press < judgement.enter) cursor.setNextTime(cursor.getNextAction().press + 1);
|
|
428
|
+
if (cursor.getNextAction() && cursor.getNextAction().press <= judgement.exit) {
|
|
429
|
+
const action = cursor.getNextAction();
|
|
430
|
+
if (nextNote && action.press >= nextNote.start) {
|
|
431
|
+
cursor.setNextTime(action.press);
|
|
432
|
+
return judgement;
|
|
433
|
+
}
|
|
434
|
+
judgement.exit = action.press;
|
|
435
|
+
judgement.action = action;
|
|
436
|
+
cursor.setNextTime(action.press + 1);
|
|
437
|
+
const delta = Math.abs(action.press - note.start);
|
|
438
|
+
for (let i = HIT_RESULTS.Perfect; i <= HIT_RESULTS.Miss; i++) if (delta <= windows[i]) {
|
|
439
|
+
judgement.result = i;
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
} else cursor.setNextTime(judgement.exit);
|
|
443
|
+
return judgement;
|
|
444
|
+
}
|
|
445
|
+
function judgeHold(note, cursor, windows, tailWindows, nextNote) {
|
|
446
|
+
const missWindow = windows[HIT_RESULTS.Miss];
|
|
447
|
+
const mehWindow = windows[HIT_RESULTS.Meh];
|
|
448
|
+
const headEnter = Math.max(note.start - missWindow, cursor.time);
|
|
449
|
+
const headLateDeadline = Math.min(note.start + missWindow, note.end + mehWindow);
|
|
450
|
+
const judgement = {
|
|
451
|
+
note,
|
|
452
|
+
headEnter,
|
|
453
|
+
headExit: 0,
|
|
454
|
+
tailEnter: 0,
|
|
455
|
+
tailExit: 0,
|
|
456
|
+
actions: [],
|
|
457
|
+
headResult: HIT_RESULTS.Miss,
|
|
458
|
+
tailResult: HIT_RESULTS.Miss
|
|
459
|
+
};
|
|
460
|
+
while (cursor.getNextAction() && cursor.getNextAction().press < headEnter) cursor.setNextTime(cursor.getNextAction().press + 1);
|
|
461
|
+
if (!cursor.getNextAction() || cursor.getNextAction().press > headLateDeadline) {
|
|
462
|
+
const autoMissTime = Math.min(note.start + mehWindow, note.end + mehWindow);
|
|
463
|
+
judgement.headExit = autoMissTime;
|
|
464
|
+
judgement.tailEnter = autoMissTime;
|
|
465
|
+
judgement.tailExit = autoMissTime;
|
|
466
|
+
cursor.setNextTime(autoMissTime);
|
|
467
|
+
return judgement;
|
|
468
|
+
}
|
|
469
|
+
const action = cursor.getNextAction();
|
|
470
|
+
if (nextNote && action.press >= nextNote.start) {
|
|
471
|
+
cursor.setNextTime(action.press);
|
|
472
|
+
return judgement;
|
|
473
|
+
}
|
|
474
|
+
judgement.actions.push(action);
|
|
475
|
+
const headDelta = Math.abs(action.press - note.start);
|
|
476
|
+
for (let i = HIT_RESULTS.Perfect; i <= HIT_RESULTS.Miss; i++) if (headDelta <= windows[i]) {
|
|
477
|
+
judgement.headResult = i;
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
judgement.headExit = action.press;
|
|
481
|
+
const absTailDelta = Math.abs(action.release - note.end);
|
|
482
|
+
if (absTailDelta > tailWindows[HIT_RESULTS.Miss]) {
|
|
483
|
+
judgement.tailResult = HIT_RESULTS.Miss;
|
|
484
|
+
const missThreshold = Math.ceil(tailWindows[HIT_RESULTS.Miss]);
|
|
485
|
+
judgement.tailEnter = action.release > note.end ? note.end + missThreshold : note.end - missThreshold;
|
|
486
|
+
judgement.tailExit = judgement.tailEnter;
|
|
487
|
+
} else {
|
|
488
|
+
for (let i = HIT_RESULTS.Perfect; i <= HIT_RESULTS.Miss; i++) if (absTailDelta <= tailWindows[i]) {
|
|
489
|
+
judgement.tailResult = i;
|
|
490
|
+
break;
|
|
491
|
+
}
|
|
492
|
+
judgement.tailEnter = action.release;
|
|
493
|
+
judgement.tailExit = action.release;
|
|
494
|
+
}
|
|
495
|
+
if (judgement.headResult === HIT_RESULTS.Miss && judgement.tailResult < HIT_RESULTS.Meh) judgement.tailResult = HIT_RESULTS.Meh;
|
|
496
|
+
if (judgement.tailResult === HIT_RESULTS.Miss) judgement.breakTime = judgement.tailEnter;
|
|
497
|
+
cursor.setNextTime(action.release + 1);
|
|
498
|
+
return judgement;
|
|
499
|
+
}
|
|
500
|
+
function playColumn(notes, actions, windows, tailWindows) {
|
|
501
|
+
const judgements = [];
|
|
502
|
+
const cursor = createActionCursor(actions);
|
|
503
|
+
for (let i = 0; i < notes.length; i++) {
|
|
504
|
+
const note = notes[i];
|
|
505
|
+
const nextNote = notes[i + 1];
|
|
506
|
+
if (note.end === void 0) judgements.push(judgeTap(note, cursor, windows, nextNote));
|
|
507
|
+
else judgements.push(judgeHold(note, cursor, windows, tailWindows, nextNote));
|
|
508
|
+
}
|
|
509
|
+
return judgements;
|
|
510
|
+
}
|
|
511
|
+
function play(noteColumns, actionColumns, windows, tailWindows) {
|
|
512
|
+
const judgements = [];
|
|
513
|
+
for (let i = 0; i < noteColumns.length; i++) judgements.push(playColumn(noteColumns[i], actionColumns[i], windows, tailWindows));
|
|
514
|
+
return judgements;
|
|
515
|
+
}
|
|
516
|
+
function playOsu(data) {
|
|
517
|
+
const windows = truncWindows(baseWindows(data.od), data.speedRate * data.windowScale);
|
|
518
|
+
const tailW = tailWindows(windows);
|
|
519
|
+
return play(data.noteColumns, data.actionColumns, windows, tailW);
|
|
520
|
+
}
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/osu-lazer/timeline.ts
|
|
523
|
+
function createEvents(judgement) {
|
|
524
|
+
if (!("headResult" in judgement)) return [{
|
|
525
|
+
time: judgement.exit,
|
|
526
|
+
judgement,
|
|
527
|
+
result: judgement.result,
|
|
528
|
+
affectsResultCounts: true
|
|
529
|
+
}];
|
|
530
|
+
const events = [];
|
|
531
|
+
events.push({
|
|
532
|
+
time: judgement.headExit,
|
|
533
|
+
judgement,
|
|
534
|
+
result: judgement.headResult,
|
|
535
|
+
affectsResultCounts: true
|
|
536
|
+
});
|
|
537
|
+
if (judgement.tailEnter !== judgement.headExit || judgement.tailResult === HIT_RESULTS.Miss) events.push({
|
|
538
|
+
time: judgement.tailEnter,
|
|
539
|
+
judgement,
|
|
540
|
+
result: judgement.tailResult,
|
|
541
|
+
affectsResultCounts: true
|
|
542
|
+
});
|
|
543
|
+
return events;
|
|
544
|
+
}
|
|
545
|
+
function compareEvents(left, right) {
|
|
546
|
+
if (left.time !== right.time) return left.time - right.time;
|
|
547
|
+
if (left.judgement.note.column !== right.judgement.note.column) return left.judgement.note.column - right.judgement.note.column;
|
|
548
|
+
return left.judgement.note.start - right.judgement.note.start;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Generate timeline frames from judgement columns.
|
|
552
|
+
*
|
|
553
|
+
* Tracks combo, max combo, and result counts over time.
|
|
554
|
+
* Health/life simulation is not included (use the osu-v1 variant for that).
|
|
555
|
+
*/
|
|
556
|
+
function generateFrames(judgementColumns) {
|
|
557
|
+
const sorted = judgementColumns.flat().flatMap(createEvents).sort(compareEvents);
|
|
558
|
+
const frames = [];
|
|
559
|
+
const last = {
|
|
560
|
+
time: 0,
|
|
561
|
+
combo: 0,
|
|
562
|
+
maxCombo: 0,
|
|
563
|
+
resultCounts: [
|
|
564
|
+
0,
|
|
565
|
+
0,
|
|
566
|
+
0,
|
|
567
|
+
0,
|
|
568
|
+
0,
|
|
569
|
+
0
|
|
570
|
+
],
|
|
571
|
+
life: 1
|
|
572
|
+
};
|
|
573
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
574
|
+
const event = sorted[i];
|
|
575
|
+
last.time = event.time;
|
|
576
|
+
if (event.result < HIT_RESULTS.Miss) {
|
|
577
|
+
last.combo++;
|
|
578
|
+
if (last.combo > last.maxCombo) last.maxCombo = last.combo;
|
|
579
|
+
} else last.combo = 0;
|
|
580
|
+
if (event.affectsResultCounts) last.resultCounts[event.result]++;
|
|
581
|
+
if (sorted[i + 1]?.time === event.time) continue;
|
|
582
|
+
frames.push({
|
|
583
|
+
time: last.time,
|
|
584
|
+
combo: last.combo,
|
|
585
|
+
maxCombo: last.maxCombo,
|
|
586
|
+
resultCounts: [...last.resultCounts],
|
|
587
|
+
life: last.life
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
return frames;
|
|
591
|
+
}
|
|
592
|
+
//#endregion
|
|
593
|
+
//#region src/osu-lazer/index.ts
|
|
594
|
+
var osu_lazer_exports = /* @__PURE__ */ __exportAll({
|
|
364
595
|
accTable: () => accTable,
|
|
365
596
|
baseWindows: () => baseWindows,
|
|
366
|
-
createLifeTable: () => createLifeTable,
|
|
367
597
|
generateFrames: () => generateFrames,
|
|
368
|
-
|
|
598
|
+
getResult: () => getResult,
|
|
599
|
+
isHoldV2: () => isHoldV2,
|
|
369
600
|
play: () => play,
|
|
370
601
|
playColumn: () => playColumn,
|
|
371
|
-
playOsu: () => playOsu
|
|
602
|
+
playOsu: () => playOsu,
|
|
603
|
+
tailWindows: () => tailWindows
|
|
372
604
|
});
|
|
373
605
|
//#endregion
|
|
374
|
-
export { HIT_RESULTS, beatmapToNoteColumns, calcAccuracy,
|
|
606
|
+
export { HIT_RESULTS, beatmapToNoteColumns, calcAccuracy, clamp, createActionCursor, difficultyRange, osu_lazer_exports as lazer, replayToActionColumns, truncWindows, osu_v1_exports as v1 };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mania-judge",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "Simulate osu!
|
|
4
|
+
"version": "0.3.1",
|
|
5
|
+
"description": "Simulate osu!mania judgements.",
|
|
6
6
|
"author": "zzzzv",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/zzzzv/mania-judge#readme",
|
|
@@ -32,6 +32,10 @@
|
|
|
32
32
|
"gen:stable-json:hold": "node --env-file=.env --import tsx tests/gen-stable-json.ts hold",
|
|
33
33
|
"gen:stable-json:mods": "node --env-file=.env --import tsx tests/gen-stable-json.ts mods",
|
|
34
34
|
"gen:stable-json": "pnpm gen:stable-json:tap-only && pnpm gen:stable-json:hold && pnpm gen:stable-json:mods",
|
|
35
|
+
"gen:lazer-json:tap-only": "node --import tsx tests/gen-lazer-json.ts tap-only",
|
|
36
|
+
"gen:lazer-json:hold": "node --import tsx tests/gen-lazer-json.ts hold",
|
|
37
|
+
"gen:lazer-json:mods": "node --import tsx tests/gen-lazer-json.ts mods",
|
|
38
|
+
"gen:lazer-json": "pnpm gen:lazer-json:tap-only && pnpm gen:lazer-json:hold && pnpm gen:lazer-json:mods",
|
|
35
39
|
"gen:osu-files": "node --import tsx tests/gen-osu-files.ts",
|
|
36
40
|
"test": "vitest",
|
|
37
41
|
"typecheck": "tsc --noEmit",
|