mania-judge 0.4.0 → 0.4.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/README.md CHANGED
@@ -11,6 +11,18 @@ resulting judgement list.
11
11
  - [osu!v1 判定逻辑](./doc/osu-v1-mania-judgement.md)(中文)
12
12
  - [osu!v1 时间轴逻辑](./doc/osu-v1-timeline.md)(中文)
13
13
 
14
+ ## Install
15
+
16
+ ```sh
17
+ npm install mania-judge
18
+ # or
19
+ pnpm add mania-judge
20
+ # or
21
+ yarn add mania-judge
22
+ ```
23
+
24
+ ESM only, with bundled type declarations and no runtime dependencies.
25
+
14
26
  ## Status
15
27
 
16
28
  Work in progress. Numbers below come from 97 replay fixtures (7K–18K mania maps) that are
@@ -22,10 +34,11 @@ compared against the counts / score / combo stored in the `.osr` header.
22
34
 
23
35
  - 90 / 97 fixtures match the header's six-tier counts exactly.
24
36
  - The remaining 7 fixtures differ by 1–5 events out of 1.5k–14k objects (all 7K maps).
25
- The same rule set is implemented by
26
- [osumania4k_replay_analyser](https://github.com/SWt0619/osumania4k_replay_analyser),
27
- which agrees with this library on 0 / 181,577 objects — so the residual is shared rule
28
- deviation, not an implementation gap between the two.
37
+ This residual is **not** a deviation of this library from stable: the header stores the
38
+ counts of the original play, while stable re-judges when replaying. On a full-map test
39
+ (Life is Piano 7K, 1473 objects) the game's replay re-judgement gives
40
+ 783/508/138/**26**/8/**10** versus the header's 25/11, and matches this library exactly
41
+ (max combo included). See [doc/osu-v1-mania-judgement.md](doc/osu-v1-mania-judgement.md).
29
42
 
30
43
  **Timeline** — combo / life / ScoreV1 derived from the judgement list.
31
44
 
@@ -33,7 +46,6 @@ compared against the counts / score / combo stored in the `.osr` header.
33
46
  | --- | --- | --- |
34
47
  | max combo | 73 / 97 | the rest are off by ±1 |
35
48
  | ScoreV1 | 43 / 97 | the rest are off by a median of ±50 (≈0.01%), worst 1136 (0.15%) |
36
- | life | — | `.osr` does not store the process HP bar, so there is no ground truth |
37
49
 
38
50
  Judgement and timeline are tested separately (`tests/osu-v1-judgement.test.ts`,
39
51
  `tests/osu-v1-timeline.test.ts`), with exact assertions and no tolerance.
@@ -104,7 +116,10 @@ engine.
104
116
 
105
117
  ## Development
106
118
 
107
- - Fixtures are generated from a local osu! install: `node --env-file=.env --import tsx tests/gen-stable-json.ts <tap-only|hold|mods>`.
119
+ - Copy `.env.example` to `.env` and point `OSU_STABLE_DIR` at your osu! install.
120
+ - Fixtures are generated from that install and are **not** committed:
121
+ `node --env-file=.env --import tsx tests/gen-stable-json.ts <tap-only|hold|mods>`
122
+ (same for `gen-lazer-json.ts`). A fresh clone has to generate them before `pnpm test`.
108
123
  - `pnpm test` runs the whole suite. Judgement and timeline tests assert exact equality, so
109
124
  the failing cases are the current known gaps and are meant to be read as a to-do list.
110
125
 
package/README.zh-CN.md CHANGED
@@ -9,6 +9,18 @@
9
9
  - [osu!v1 判定逻辑](./doc/osu-v1-mania-judgement.md)
10
10
  - [osu!v1 时间轴逻辑](./doc/osu-v1-timeline.md)
11
11
 
12
+ ## 安装
13
+
14
+ ```sh
15
+ npm install mania-judge
16
+ # 或
17
+ pnpm add mania-judge
18
+ # 或
19
+ yarn add mania-judge
20
+ ```
21
+
22
+ 只有 ESM 产物,自带类型声明,无运行时依赖。
23
+
12
24
  ## 现状
13
25
 
14
26
  仍在开发中。下面的数字来自 97 张回放样本(7K–18K 的 mania 谱面),对照的是 `.osr`
@@ -19,10 +31,11 @@
19
31
  **判定** —— 按列推进的状态机,驱动时钟来自回放的原始帧时间。
20
32
 
21
33
  - **90 / 97** 张谱的六档判定计数与回放头完全一致。
22
- - 剩下 7 张各差 1–5 个事件(物件总数 1.5k–14k,全部是 7K 谱)。同一套规则在
23
- [osumania4k_replay_analyser](https://github.com/SWt0619/osumania4k_replay_analyser) 里
24
- 与本库逐物件比对是 **0 / 181,577** 差异,所以这部分残差是「两边共用的规则与 stable
25
- 的偏差」,不是两个实现之间的差异。
34
+ - 剩下 7 张各差 1–5 个事件(物件总数 1.5k–14k,全部是 7K 谱)。这批残差**不是本实现对
35
+ stable 的偏差**:回放头记的是当初游玩的判定,而 stable 播放回放时会按当前帧重新判定,
36
+ 两者本来就可能不同。整图实测(Life is Piano 7K,1473 物件)里,游戏回放重判为
37
+ 783/508/138/**26**/8/**10**,与回放头的 25/11 不同,而与本库完全一致(连 maxCombo 都一致)。
38
+ 详见 [doc/osu-v1-mania-judgement.md](doc/osu-v1-mania-judgement.md#已知偏差)。
26
39
 
27
40
  **时间轴** —— 由判定结果派生连击 / 血量 / ScoreV1。
28
41
 
@@ -30,7 +43,6 @@
30
43
  | --- | --- | --- |
31
44
  | 最大连击 | 73 / 97 | 其余差 ±1 |
32
45
  | ScoreV1 | 43 / 97 | 其余中位偏差 ±50(约 0.01%),最大 1136(0.15%) |
33
- | 血量 | — | `.osr` 不记录过程血条,没有真值可用 |
34
46
 
35
47
  判定层与时间轴层的测试是分开的(`tests/osu-v1-judgement.test.ts`、
36
48
  `tests/osu-v1-timeline.test.ts`),都使用精确断言、不留容差。
@@ -97,7 +109,9 @@ mod 计算刻意留在库外:它需要的是 mod 表,不是判定引擎。
97
109
 
98
110
  ## 开发
99
111
 
100
- - 样本生成:`node --env-file=.env --import tsx tests/gen-stable-json.ts <tap-only|hold|mods>`(需要本机 osu! 安装目录)。
112
+ - 把 `.env.example` 复制成 `.env`,把 `OSU_STABLE_DIR` 指向本机 osu! 安装目录。
113
+ - 样本由脚本从该目录生成,**不入库**:`node --env-file=.env --import tsx tests/gen-stable-json.ts <tap-only|hold|mods>`
114
+ (lazer 用 `gen-lazer-json.ts`)。新克隆的仓库要先生成样本,`pnpm test` 才有数据。
101
115
  - `pnpm test` 跑全量。判定层与时间轴层都是精确断言,**失败用例就是当前的已知差异清单**,
102
116
  应当当作待办来读,而不是把断言放宽。
103
117
 
package/dist/index.d.mts CHANGED
@@ -66,7 +66,10 @@ interface HoldJudgementV1 {
66
66
  exit: number;
67
67
  actions: Action[];
68
68
  result: HitResult;
69
+ /** 首次提前松手的时刻(兼容旧字段) */
69
70
  breakTime?: number;
71
+ /** 每次提前松手的时刻:重新按下后再次提前松手会再记一次,每次都会重置连击 */
72
+ breakTimes?: number[];
70
73
  ticks: number[];
71
74
  }
72
75
  type JudgementV1 = TapJudgement | HoldJudgementV1;
package/dist/index.mjs CHANGED
@@ -108,7 +108,7 @@ function collectKeyFrames(notes, actions, windows, frameTimes) {
108
108
  if (action.press >= note.end) break;
109
109
  const stop = Math.min(action.release, note.end);
110
110
  for (let time = action.press + LN_TICK_MS; time <= stop; time += LN_TICK_MS) {
111
- const frame = resolveBoundary(time, frameTimes);
111
+ const frame = resolveBoundary(Math.max(time, note.start), frameTimes);
112
112
  if (Number.isFinite(frame)) frames.add(frame);
113
113
  }
114
114
  }
@@ -187,7 +187,11 @@ function judgeHoldState(state, now, runtime) {
187
187
  if (now < state.end - runtime.w50) {
188
188
  if (state.isHeld) return "wait";
189
189
  state.wasBroken = true;
190
- if (state.breakTime === void 0) state.breakTime = now;
190
+ if (!state.breakRecorded) {
191
+ state.breakRecorded = true;
192
+ state.breakTimes.push(now);
193
+ if (state.breakTime === void 0) state.breakTime = now;
194
+ }
191
195
  return "break";
192
196
  }
193
197
  if (now < state.end + runtime.w50 && state.isHeld) return "wait";
@@ -239,6 +243,7 @@ function tickNote(state, now, runtime) {
239
243
  state.isHeld = true;
240
244
  state.headJudged = true;
241
245
  state.lastTick = state.pressTime;
246
+ state.breakRecorded = false;
242
247
  return;
243
248
  }
244
249
  if (held && wasHeld) {
@@ -327,6 +332,8 @@ function createState(note, originalIndex, runtime) {
327
332
  enter: note.start - runtime.early,
328
333
  exit: (note.end ?? note.start) + runtime.w100,
329
334
  breakTime: void 0,
335
+ breakTimes: [],
336
+ breakRecorded: false,
330
337
  dimTime: void 0,
331
338
  current: void 0,
332
339
  originalIndex
@@ -375,6 +382,7 @@ function playColumnFrames(notes, actions, windows, frameTimes) {
375
382
  actions: state.actions,
376
383
  result: state.judgement,
377
384
  breakTime: state.breakTime,
385
+ breakTimes: state.breakTimes,
378
386
  ticks: state.ticks
379
387
  };
380
388
  judgements[state.originalIndex] = hold;
@@ -514,9 +522,9 @@ function buildEvents(judgements) {
514
522
  kind: "tick",
515
523
  result: HIT_RESULTS.Great
516
524
  });
517
- if (judgement.breakTime !== void 0) events.push({
525
+ for (const breakTime of judgement.breakTimes ?? (judgement.breakTime !== void 0 ? [judgement.breakTime] : [])) events.push({
518
526
  ...base,
519
- time: judgement.breakTime,
527
+ time: breakTime,
520
528
  kind: "break",
521
529
  result: HIT_RESULTS.Miss
522
530
  });
@@ -626,8 +634,8 @@ function createEvents$1(judgement) {
626
634
  judgement,
627
635
  result: HIT_RESULTS.Great
628
636
  });
629
- if (judgement.breakTime !== void 0) events.push({
630
- time: judgement.breakTime,
637
+ for (const breakTime of judgement.breakTimes ?? (judgement.breakTime !== void 0 ? [judgement.breakTime] : [])) events.push({
638
+ time: breakTime,
631
639
  kind: "break",
632
640
  judgement,
633
641
  result: HIT_RESULTS.Miss
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mania-judge",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "description": "Simulate osu!mania judgements.",
6
6
  "author": "zzzzv",
7
7
  "license": "MIT",
@@ -38,6 +38,7 @@
38
38
  "gen:lazer-json": "pnpm gen:lazer-json:tap-only && pnpm gen:lazer-json:hold && pnpm gen:lazer-json:mods",
39
39
  "gen:osu-files": "node --import tsx tests/gen-osu-files.ts",
40
40
  "test": "vitest",
41
+ "test:unit": "vitest run tests/osu-data.test.ts tests/timeline.test.ts",
41
42
  "typecheck": "tsc --noEmit",
42
43
  "prepublishOnly": "pnpm run build"
43
44
  },