forked from mkzi-nya/milthm-calculator-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefedit.html
More file actions
845 lines (751 loc) · 30.9 KB
/
prefedit.html
File metadata and controls
845 lines (751 loc) · 30.9 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Milthm存档解析</title>
<style>
/* 禁用左右滑动 */
html,
body {
overflow-x: hidden;
margin: 0;
padding: 0;
}
body {
background-color: #000;
color: #f0f0f0;
font-family: Arial, sans-serif;
padding: 20px;
line-height: 1.6;
}
.container {
max-width: 600px;
margin: 0 auto;
}
@media (min-width: 768px) {
.container {
max-width: 800px;
}
}
h1 {
text-align: center;
color: #fff;
}
/* 警示文本框 */
#warningBox {
background-color: #330000;
border: 1px solid #660000;
padding: 10px;
margin: 10px auto;
white-space: pre-wrap;
font-size: 14px;
line-height: 1.4;
color: #ffcccc;
border-radius: 4px;
}
textarea {
width: 100%;
height: 200px;
background-color: #1a1a1a;
color: #f0f0f0;
border: 1px solid #555;
padding: 10px;
font-size: 14px;
box-sizing: border-box;
resize: vertical;
white-space: pre-wrap;
word-wrap: break-word;
}
.btn-group {
margin-top: 10px;
text-align: center;
}
button {
background-color: #333;
color: #f0f0f0;
border: none;
padding: 8px 16px;
margin: 5px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
button:hover {
background-color: #444;
}
/* 上传按钮:隐藏 input 用 label 显示 */
#uploadInput {
display: none;
}
.upload-btn {
background-color: #333;
color: #f0f0f0;
border: none;
padding: 8px 16px;
margin: 5px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
display: inline-block;
}
/* 排序下拉菜单 */
.sort-menu {
text-align: center;
margin-top: 10px;
}
.sort-menu select {
background-color: #333;
color: #f0f0f0;
border: 1px solid #555;
padding: 6px;
border-radius: 4px;
font-size: 14px;
}
/* 卡片展示区域:两列网格 */
#cardsContainer {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 10px;
margin-top: 20px;
}
.song-card {
background-color: #1a1a1a;
border: 1px solid #444;
border-radius: 4px;
padding: 10px;
font-size: 13px;
position: relative;
}
.song-title {
font-weight: bold;
margin-bottom: 5px;
}
.song-detail {
margin-bottom: 5px;
}
.edit-btn {
background-color: transparent;
border: none;
color: #f0f0f0;
font-size: 18px;
cursor: pointer;
position: absolute;
top: 5px;
right: 5px;
}
.edit-btn:hover {
color: #ddd;
}
/* 模态框样式 */
#editModal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: none;
background: rgba(0, 0, 0, 0.8);
z-index: 1000;
}
#editModalContent {
background-color: #1a1a1a;
padding: 20px;
border-radius: 4px;
max-width: 300px;
margin: 100px auto;
color: #f0f0f0;
}
#editModalContent input {
width: 100%;
padding: 8px;
margin: 5px 0 10px;
border: 1px solid #555;
border-radius: 4px;
background-color: #333;
color: #f0f0f0;
}
#editModalContent button {
margin: 5px;
font-size: 14px;
}
</style>
</head>
<body>
<div class="container">
<h1>Milthm存档解析</h1>
<div id="warningBox">
警告:
如果您不需要恢复或修改存档,请使用查分器
<a href="http://k9.lv/c" target="_blank" style="color: lightblue; text-decoration: underline;">Milthm calc</a>或<a
href="https://mkzi-nya.github.io/milthm-calculator-web/" target="_blank"
style="color: lightblue; text-decoration: underline;">Milthm calc(Github)</a>
不保证修改或转换后的存档能正常使用
修改后的存档可能包含但不限于解锁进度与故事进度丢失等问题
修改后引发的任何问题概不负责
可以上传db格式,json格式与查分图
</div>
<textarea id="inputArea" placeholder="在此粘贴json或查分器数据"></textarea>
<div class="btn-group">
<button id="importBtn">粘贴</button>
<button id="copyBtn">复制</button>
<button id="clearBtn">清空</button>
<label for="uploadInput" class="upload-btn">上传</label>
<input type="file" id="uploadInput">
<button id="downloadBtn">下载</button>
<button id="clearV2Btn">清除v2成绩</button>
</div>
<!-- 排序下拉菜单 -->
<div class="sort-menu">
<label for="sortMenu">排序方式: </label>
<select id="sortMenu">
<option value="default">默认排序</option>
<option value="defaultReverse">默认逆序排序</option>
<option value="reality">Reality排序</option>
<option value="name">曲名排序</option>
<option value="difficulty">难度排序</option>
</select>
</div>
<!-- 卡片展示区域 -->
<div id="cardsContainer"></div>
</div>
<!-- 编辑模态框 -->
<div id="editModal">
<div id="editModalContent">
<h3>编辑曲目信息</h3>
<!-- 直接显示 id -->
<div>
<span id="editBeatmapID" style="font-size:12px;color:#ccc;"></span>
</div>
<label for="editScore">Best Score:</label>
<input type="number" id="editScore">
<label for="editAccuracy">Best Accuracy:</label>
<input type="number" step="0.01" id="editAccuracy">
<label for="editLevel">BestLevel:<br>(0=R,1=M,2=S,3=A,4=B,5=C,6=F)</label>
<input type="number" id="editLevel">
<label for="editAchievedStatus">AchievedStatus:<br>(0=通关,3,4=FC,5=AP,6=False)</label>
<input type="text" id="editAchievedStatus">
<div style="text-align: right;">
<button id="cancelEditBtn">取消</button>
<button id="saveEditBtn">保存</button>
</div>
</div>
</div>
<!-- 引入外部常量数据 -->
<script src="./js/constant.js"></script>
<!-- 引入 SQL.js,用于解析 .db 文件 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.8.0/sql-wasm.js"></script>
<script>
// 修改后的完整 JavaScript 代码
let currentData = null;
let sortMode = 'default';
// level 映射:数字到评级字母
const levelMapping = ["R", "M", "S", "A", "B", "C", "F"];
// 构造映射:键为 "name|category",值为 BeatmapID(用于非 JSON 转换时查找)
let beatmapDict = {};
if (typeof constants !== 'undefined') {
for (let id in constants) {
let info = constants[id];
beatmapDict[info.name + "|" + info.category] = id;
}
} else {
console.error("无法加载常量数据,请检查cha_newui.js是否正确引入");
}
// 附加内容(可根据需要修改)
const additionalContent = { "MarkRecords": [{ "MarkName": "tip_welcome_read", "Mark": true }, { "MarkName": "episode_story.main.0.1_read", "Mark": true }, { "MarkName": "tip_judgement_read", "Mark": true }, { "MarkName": "tip_bluetooth_read", "Mark": true }, { "MarkName": "tip_rain_read", "Mark": true }, { "MarkName": "tip_checkstate_read", "Mark": true }, { "MarkName": "tip_about-us_read", "Mark": true }, { "MarkName": "tip_susan_read", "Mark": true }, { "MarkName": "tip_hold-tricks_read", "Mark": true }, { "MarkName": "tip_level-rule_read", "Mark": true }, { "MarkName": "tip_reality_read", "Mark": true }, { "MarkName": "tip_star_read", "Mark": true }, { "MarkName": "tip_who-are-you_read", "Mark": true }, { "MarkName": "tip_what-is-downpour_read", "Mark": true }, { "MarkName": "tip_what-is-heart_read", "Mark": true }, { "MarkName": "tip_coffee_read", "Mark": true }, { "MarkName": "tip_sleep_read", "Mark": true }, { "MarkName": "tip_do-you-know_read", "Mark": true }, { "MarkName": "tip_or-scene-illustration_read", "Mark": true }, { "MarkName": "episode_story.main.0.2_read", "Mark": true }, { "MarkName": "episode_story.main.0.3_read", "Mark": true }, { "MarkName": "episode_story.main.0.4_read", "Mark": true }, { "MarkName": "episode_story.main.0.5_read", "Mark": true }, { "MarkName": "episode_story.main.0.6_read", "Mark": true }, { "MarkName": "RainCity-Cloudburst", "Mark": true }, { "MarkName": "DestinyDay-Cloudburst", "Mark": true }, { "MarkName": "episode_main_story_1_1_read", "Mark": true }, { "MarkName": "episode_main_story_1_2_read", "Mark": true }, { "MarkName": "episode_main_story_1_3_read", "Mark": true }, { "MarkName": "episode_main_story_1_4_read", "Mark": true }, { "MarkName": "episode_main_story_1_5_read", "Mark": true }, { "MarkName": "hyper_memories", "Mark": true }, { "MarkName": "episode_main_story_1_6_read", "Mark": true }, { "MarkName": "regnaissance-Cloudburst", "Mark": true }, { "MarkName": "contrasty_angels-Cloudburst", "Mark": true }, { "MarkName": "episode_main_story_1_7_read", "Mark": true }, { "MarkName": "RainWorld", "Mark": true }, { "MarkName": "episode_story.rainworld.0.2_read", "Mark": true }, { "MarkName": "episode_story.rainworld.0.1_read", "Mark": true }, { "MarkName": "episode_story.notanote.1_read", "Mark": true }, { "MarkName": "episode_story.notanote.2_read", "Mark": true }, { "MarkName": "episode_story.notanote.3_read", "Mark": true }, { "MarkName": "episode_story.notanote.4_read", "Mark": true }, { "MarkName": "episode_story.rainworld.0.3_read", "Mark": true }, { "MarkName": "episode_story.rainworld.1.1_read", "Mark": true }, { "MarkName": "episode_story.rainworld.1.2_read", "Mark": true }, { "MarkName": "episode_story.rainworld.1.3_read", "Mark": true }, { "MarkName": "episode_story.rainworld.2.1_read", "Mark": true }, { "MarkName": "episode_story.rainworld.2.2_read", "Mark": true }, { "MarkName": "episode_story.rainworld.2.3_read", "Mark": true }, { "MarkName": "episode_story.rainworld.3.1_read", "Mark": true }, { "MarkName": "episode_story.notanote.5_read", "Mark": true }, { "MarkName": "DogbiteSP", "Mark": true }, { "MarkName": "3d4fcad4-364a-43a1-8eb6-884b53961092-Reveal", "Mark": true }, { "MarkName": "episode_story.rainworld2.journey_bridge_read", "Mark": true }, { "MarkName": "episode_story.rainworld2.superstructure_x_read", "Mark": true }, { "MarkName": "rain_world2", "Mark": true }, { "MarkName": "episode_story.rainworld2.journey_shoreline_read", "Mark": true }, { "MarkName": "industrial_complex", "Mark": true }, { "MarkName": "episode_story.rainworld2.journey_industrial_complex_read", "Mark": true }, { "MarkName": "episode_story.rainworld2.journey_downpour_read", "Mark": true }, { "MarkName": "episode_story.rainworld2.journey_sky_islands_read", "Mark": true }, { "MarkName": "episode_story.rainworld2.journey_seven_red_suns_read", "Mark": true }, { "MarkName": "sheer_ice_torrent", "Mark": true }, { "MarkName": "moonfall", "Mark": true }, { "MarkName": "episode_story.rainworld2.archived_file_read", "Mark": true }, { "MarkName": "episode_story.rainworld2.journey_deactivated_monsoon_read", "Mark": true }, { "MarkName": "fool2025_startup", "Mark": true }], "ImmerseProgresses": [{ "Tag": "0", "Value": 1.0 }, { "Tag": "chapter1", "Value": 1.0 }, { "Tag": "RainWorld", "Value": 1.0 }, { "Tag": "notanote", "Value": 1.0 }], "Agreements": [{ "ID": "eula", "AcceptTime": "2024/9/13 0:47:46", "AgreementUpdateTime": "2023/10/21 0:00:00", "AgreementVersion": 2023102104 }, { "ID": "privacy_policy-zh", "AcceptTime": "2024/9/13 0:47:49", "AgreementUpdateTime": "2023/10/27 0:00:00", "AgreementVersion": 2023102704 }], "SongListSorting": 0, "ReverseSongListSorting": false, "LastSelectChapterID": "All", "LastReadChapterID": "RainWorld", "ChapterSelectPreferences": [{ "ChapterID": "All", "LastSelectSongID": "7f54e367-428a-44e1-9abb-5d074092aacb", "LastSelectDifficulty": "Cloudburst" }, { "ChapterID": "Chapter0", "LastSelectSongID": "5f94aacc-fba5-46a9-8bd4-cbe341ef511d", "LastSelectDifficulty": "Cloudburst" }, { "ChapterID": "Chapter1", "LastSelectSongID": "8e5c851e-458d-4524-a1b7-3dd5eee95d29", "LastSelectDifficulty": "Cloudburst" }, { "ChapterID": "Introduction", "LastSelectSongID": "e09f6870-7cec-4381-a500-dc2360c9a488", "LastSelectDifficulty": "Drizzle" }, { "ChapterID": "Notanote", "LastSelectSongID": "c41460e1-0352-4b89-bcd7-b49c90a20e82", "LastSelectDifficulty": "Cloudburst" }, { "ChapterID": "RainWorld", "LastSelectSongID": "a604ef85-d9fc-48a3-9c08-23d422cb1a77", "LastSelectDifficulty": "Cloudburst" }, { "ChapterID": "Single", "LastSelectSongID": "3d466b94-8503-4b93-b39c-cd149c4fb760", "LastSelectDifficulty": "Cloudburst" }, { "ChapterID": "Garden", "LastSelectSongID": "6ab26e68-c366-497b-bdf3-cc00a0af8ec3", "LastSelectDifficulty": "Drizzle" }] };
// 定义 reality 计算函数
function reality(score, constant) {
if (constant < 1e-3) return 0;
if (score >= 1005000)
return Math.max(1.5 + constant, 0);
if (score >= 995000)
return Math.max(1.4 / (Math.exp(-3.65 * (score / 10000 - 99.5)) + 1) - 0.4 + constant, 0);
if (score >= 980000)
return Math.max(((Math.exp(3.1 * (score - 980000) / 15000) - 1) / (Math.exp(3.1) - 1)) * 0.8 - 0.5 + constant, 0);
if (score >= 700000)
return Math.max(score / 280000 - 4 + constant, 0);
return 0;
}
function realityV3(score, c) {
if (c < 1e-3) return 0;
if (score >= 1000000) return c + 1.5;
if (score >= 850000) return c + (score - 850000) / 100000.0;
if (score >= 700000) return Math.max(0, c * (0.5 + (score - 700000) / 300000.0) + (score - 850000) / 100000.0);
if (score >= 600000) return Math.max(0, (c - 3) * (score - 600000) / 200000.0);
return 0;
}
// 辅助函数:获取曲名排序键(分组顺序:大写=0,小写=1,中文=2,日文=3,其他=4,未解析=5)
function getNameSortKey(song) {
if (song.BeatmapID && constants[song.BeatmapID] && constants[song.BeatmapID].name) {
let name = constants[song.BeatmapID].name;
let ch = name.charAt(0);
let group;
if (ch >= 'A' && ch <= 'Z') {
group = 0;
} else if (ch >= 'a' && ch <= 'z') {
group = 1;
} else if (/[\u4e00-\u9fff]/.test(ch)) {
group = 2;
} else if (/[\u3040-\u30ff]/.test(ch)) {
group = 3;
} else {
group = 4;
}
return [group, name.toLowerCase()];
} else {
return [5, ""]; // 未解析
}
}
// 转换函数:只处理 JSON 格式,同时检查 SongRecordsV3
function convertData() {
const textarea = document.getElementById('inputArea');
let text = textarea.value.trim();
if (!text) return;
// 尝试解析为 JSON
try {
currentData = JSON.parse(text);
// 处理 SongRecords
if (currentData.SongRecords) {
currentData.SongRecords.forEach((song, i) => {
if (song.origIndex === undefined) song.origIndex = i;
});
}
// 处理 SongRecordsV3
if (currentData.SongRecordsV3) {
currentData.SongRecordsV3.forEach((song, i) => {
if (song.origIndex === undefined) song.origIndex = i;
});
}
renderCards();
return;
} catch (e) {
// 如果不是有效的 JSON,显示错误
alert("输入的内容不是有效的 JSON 格式");
return;
}
}
// 更新文本框内 JSON 输出(单行)
function updateOutput() {
const textarea = document.getElementById('inputArea');
textarea.value = JSON.stringify(currentData);
}
// 设置全局排序模式并刷新卡片显示
function setSortMode(mode) {
sortMode = mode;
renderCards();
}
document.getElementById('sortMenu').addEventListener('change', function () {
setSortMode(this.value);
});
// 渲染曲目卡片
function renderCards() {
const container = document.getElementById('cardsContainer');
container.innerHTML = "";
if (!currentData) return;
let allRecords = [];
// 处理 SongRecords
if (currentData.SongRecords) {
currentData.SongRecords.forEach((song, i) => {
if (song.origIndex === undefined) song.origIndex = i;
song.recordType = 'v2'; // 标记为 v2 记录
allRecords.push(song);
});
}
// 处理 SongRecordsV3
if (currentData.SongRecordsV3) {
currentData.SongRecordsV3.forEach((song, i) => {
if (song.origIndex === undefined) song.origIndex = i;
song.recordType = 'V3'; // 标记为 V3 记录
allRecords.push(song);
});
}
if (allRecords.length === 0) return;
// 排序
if (sortMode === "default") {
allRecords.sort((a, b) => a.origIndex - b.origIndex);
} else if (sortMode === "defaultReverse") {
allRecords.sort((a, b) => b.origIndex - a.origIndex);
} else if (sortMode === "reality") {
allRecords.sort((a, b) => {
const constA = (constants[a.BeatmapID] && constants[a.BeatmapID].constant);
const constB = (constants[b.BeatmapID] && constants[b.BeatmapID].constant);
let realityA = -Infinity;
let realityB = -Infinity;
if (constants[a.BeatmapID]) {
realityA = a.recordType === 'V3' ?
realityV3(a.BestScore, constA) :
reality(a.BestScore, constA);
}
if (constants[b.BeatmapID]) {
realityB = b.recordType === 'V3' ?
realityV3(b.BestScore, constB) :
reality(b.BestScore, constB);
}
return realityB - realityA;
});
} else if (sortMode === "name") {
allRecords.sort((a, b) => {
let keyA = getNameSortKey(a);
let keyB = getNameSortKey(b);
if (keyA[0] !== keyB[0]) return keyA[0] - keyB[0];
return keyA[1].localeCompare(keyB[1]);
});
} else if (sortMode === "difficulty") {
allRecords.sort((a, b) => {
const diffA = (constants[a.BeatmapID] && constants[a.BeatmapID].constant);
const diffB = (constants[b.BeatmapID] && constants[b.BeatmapID].constant);
if (diffA === undefined) return 1;
if (diffB === undefined) return -1;
return diffA - diffB;
});
}
// 为每个记录生成卡片
allRecords.forEach((song) => {
let songName = "";
let difficulty = "";
let constantValue = "";
let computedReality = "";
let recordType = song.recordType || 'v2';
if (song.BeatmapID && constants[song.BeatmapID]) {
const info = constants[song.BeatmapID];
songName = info.name;
difficulty = info.category;
constantValue = info.constant;
// 根据记录类型使用不同的 reality 计算函数
computedReality = recordType === 'V3' ?
realityV3(song.BestScore, constantValue).toFixed(2) :
reality(song.BestScore, constantValue).toFixed(2);
} else {
songName = song.BeatmapID || "";
difficulty = "";
constantValue = "";
computedReality = "";
}
// 格式化 Accuracy 为百分比,向下取整后保留两位小数
const accFloor = Math.floor(song.BestAccuracy * 100) / 100;
const formattedAcc = accFloor.toFixed(2) + "%";
const card = document.createElement('div');
card.className = "song-card";
card.innerHTML = `
<div class="song-title">${songName} (${difficulty}) ${recordType === 'V3' ? '[V3]' : ''}</div>
<div class="song-detail">Score: ${song.BestScore}</div>
<div class="song-detail">Accuracy: ${formattedAcc}</div>
<div class="song-detail">BestLevel: ${song.BestLevel} (${levelMapping[song.BestLevel] || "?"})</div>
<div class="song-detail">Reality: ${computedReality}</div>
<div class="song-detail">Constant: ${constantValue}</div>
<button class="edit-btn" onclick="showEditModal('${recordType}', ${song.origIndex})">✎</button>
`;
container.appendChild(card);
});
}
// 剪贴板导入(按钮文字为"粘贴")
document.getElementById('importBtn').addEventListener('click', async () => {
if (navigator.clipboard && navigator.clipboard.readText) {
try {
const text = await navigator.clipboard.readText();
document.getElementById('inputArea').value = text;
convertData();
} catch (err) {
console.error('读取剪贴板失败:', err);
alert('未能成功访问剪贴板,请手动粘贴');
}
} else {
const text = prompt('请粘贴剪贴板内容:');
if (text) {
document.getElementById('inputArea').value = text;
convertData();
}
}
});
// 复制功能(支持 execCommand 备用方案)
document.getElementById('copyBtn').addEventListener('click', async () => {
const text = document.getElementById('inputArea').value;
if (navigator.clipboard && navigator.clipboard.writeText) {
try {
await navigator.clipboard.writeText(text);
alert('已复制到剪贴板');
} catch (err) {
console.error('复制失败:', err);
fallbackCopyText(text);
}
} else {
fallbackCopyText(text);
}
});
function fallbackCopyText(text) {
const textarea = document.createElement('textarea');
textarea.value = text;
document.body.appendChild(textarea);
textarea.select();
try {
document.execCommand('copy');
alert('已复制到剪贴板');
} catch (err) {
alert('复制失败,请手动复制');
}
document.body.removeChild(textarea);
}
document.getElementById('clearBtn').addEventListener('click', () => {
document.getElementById('inputArea').value = '';
document.getElementById('cardsContainer').innerHTML = '';
currentData = null;
});
// 文件上传处理
document.getElementById('uploadInput').addEventListener('change', function (event) {
const file = event.target.files[0];
if (!file) return;
const filename = file.name.toLowerCase();
const reader = new FileReader();
if (filename.endsWith('.db')) {
// 如果是 .db 文件,读取为 ArrayBuffer 并用 SQL.js 解析
reader.onload = async function (e) {
const buffer = e.target.result;
try {
// 初始化 SQL.js
const SQL = await initSqlJs({
locateFile: file => `https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.8.0/${file}`
});
const db = new SQL.Database(new Uint8Array(buffer));
// 查询 kv 表中的 value 字段
const res = db.exec("SELECT value FROM kv");
if (res.length > 0 && res[0].values.length > 0) {
const values = res[0].values;
// 判断是否存在第二行,优先使用第二行的 value
const jsonText = values.length > 1 ? values[1][0] : values[0][0];
document.getElementById('inputArea').value = jsonText;
convertData();
} else {
alert("无法在.db文件中找到kv表的value项");
}
} catch (err) {
console.error(err);
alert("解析.db文件时出错");
}
};
reader.readAsArrayBuffer(file);
} else if (filename.endsWith('.png')) {
// 如果是 .png 文件,读取为 ArrayBuffer 并解析 userdata 部分
reader.onload = function (e) {
const arrayBuffer = e.target.result;
const text = parsePNGFile(arrayBuffer);
document.getElementById('inputArea').value = text;
convertData();
};
reader.readAsArrayBuffer(file);
} else {
// 如果是文本文件,直接读取为文本
reader.onload = function (e) {
const text = e.target.result;
document.getElementById('inputArea').value = text;
convertData();
};
reader.readAsText(file);
}
});
// PNG 文件解析函数
function parsePNGFile(arrayBuffer) {
// 将 ArrayBuffer 转为字节数组
const data = new Uint8Array(arrayBuffer);
// 查找 userdata: 部分的位置
const startIndex = findUserDataStart(data);
if (startIndex !== -1) {
// 提取 userdata 后的文本内容
const userdataText = extractUserDataText(data, startIndex);
return userdataText;
} else {
alert("未找到 userdata 数据!");
return '';
}
}
// 查找 userdata: 的起始位置
function findUserDataStart(data) {
const searchString = 'userdata:';
for (let i = 0; i < data.length - searchString.length; i++) {
let match = true;
for (let j = 0; j < searchString.length; j++) {
if (data[i + j] !== searchString.charCodeAt(j)) {
match = false;
break;
}
}
if (match) {
return i + searchString.length; // 返回 userdata: 后的第一个字节位置
}
}
return -1; // 如果没有找到 userdata: 返回 -1
}
// 提取 userdata 后的文本内容,并解码为 UTF-8
function extractUserDataText(data, startIndex) {
// 创建一个 TextDecoder 来解码 UTF-8 字符串
const textDecoder = new TextDecoder('utf-8');
// 提取 userdata 后的二进制数据
const textData = data.slice(startIndex);
// 使用 TextDecoder 解码为文本
const decodedText = textDecoder.decode(textData);
return decodedText.trim(); // 返回解码后的文本内容
}
// 编辑模态框相关 - 修改为支持两种记录类型
function showEditModal(recordType, origIndex) {
let song;
if (recordType === 'V3') {
song = currentData.SongRecordsV3[origIndex];
} else {
song = currentData.SongRecords[origIndex];
}
document.getElementById('editScore').value = song.BestScore;
document.getElementById('editAccuracy').value = song.BestAccuracy;
document.getElementById('editLevel').value = song.BestLevel;
document.getElementById('editBeatmapID').textContent = song.BeatmapID || "未解析";
document.getElementById('editAchievedStatus').value =
(song.AchievedStatus || []).join(",");
window.currentEditIndex = origIndex;
window.currentEditType = recordType;
document.getElementById('editModal').style.display = "block";
}
document.getElementById('cancelEditBtn').addEventListener('click', () => {
document.getElementById('editModal').style.display = "none";
});
document.getElementById('saveEditBtn').addEventListener('click', () => {
const scoreInput = parseInt(document.getElementById('editScore').value);
const accuracyInput = parseFloat(document.getElementById('editAccuracy').value);
let levelInput = parseFloat(document.getElementById('editLevel').value);
if (isNaN(levelInput)) {
levelInput = 7;
} else {
levelInput = Math.floor(levelInput);
if (levelInput < 0) levelInput = 0;
if (levelInput > 7) levelInput = 7;
}
let targetArray;
if (window.currentEditType === 'V3') {
targetArray = currentData.SongRecordsV3;
} else {
targetArray = currentData.SongRecords;
}
targetArray[window.currentEditIndex].BestScore = scoreInput;
targetArray[window.currentEditIndex].BestAccuracy = accuracyInput;
targetArray[window.currentEditIndex].BestLevel = levelInput;
const statusInput = document.getElementById('editAchievedStatus').value;
const statusArray = statusInput.split(',').map(s => parseInt(s.trim())).filter(n => !isNaN(n));
targetArray[window.currentEditIndex].AchievedStatus = statusArray;
updateOutput();
renderCards();
document.getElementById('editModal').style.display = "none";
});
// 输入框失去焦点时自动检测转换
document.getElementById('inputArea').addEventListener('blur', convertData);
// 下载按钮点击事件处理
document.getElementById('downloadBtn').addEventListener('click', async () => {
const inputText = document.getElementById('inputArea').value.trim();
if (!inputText) {
alert('输入框为空,无法生成新的存档!');
return;
}
const file = await fetch('./files/saves.db'); // 从指定路径获取 saves.db
const buffer = await file.arrayBuffer();
const SQL = await initSqlJs({
locateFile: file => `https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.8.0/${file}`
});
const db = new SQL.Database(new Uint8Array(buffer));
// 查询 kv 表中的 value 字段
const res = db.exec("SELECT rowid, value FROM kv");
if (res.length > 0 && res[0].values.length > 0) {
// 替换 kv 表中的 value 值
const rowId = res[0].values[1][0]; // 获取 rowid
db.run("UPDATE kv SET value = ? WHERE rowid = ?", [inputText, rowId]);
// 下载更新后的 db 文件
const updatedDbBuffer = db.export();
const updatedBlob = new Blob([updatedDbBuffer], { type: 'application/octet-stream' });
const url = URL.createObjectURL(updatedBlob);
const a = document.createElement('a');
a.href = url;
a.download = 'saves.db'; // 设定下载文件的名称
a.click();
// 清理 URL 对象
URL.revokeObjectURL(url);
} else {
alert("无法找到kv表中的value项");
}
});
// 添加清除v2成绩按钮的事件监听
document.getElementById('clearV2Btn').addEventListener('click', clearV2Scores);
// 清除v2成绩函数
function clearV2Scores() {
if (!currentData) {
alert('没有数据可处理');
return;
}
if (!currentData.SongRecords || currentData.SongRecords.length === 0) {
alert('没有v2成绩数据');
return;
}
// 确认框
if (!confirm('确定要清除v2成绩并合并到v3吗?此操作将会将v2成绩转为0分,v2已ap成绩转为最低100,0000分,此操作不可逆。')) {
return;
}
// 确保有v3数组
if (!currentData.SongRecordsV3) {
currentData.SongRecordsV3 = [];
}
// 处理每个v2成绩
currentData.SongRecords.forEach(v2Song => {
const existingV3Index = currentData.SongRecordsV3.findIndex(
v3Song => v3Song.BeatmapID === v2Song.BeatmapID
);
if (existingV3Index === -1) {
// v3中没有这个成绩,创建新记录
const newV3Record = {
BeatmapID: v2Song.BeatmapID,
BestScore: 0, // 不存在v3就是0分
BestAccuracy: v2Song.BestAccuracy,
BestLevel: v2Song.BestLevel,
AchievedStatus: [...(v2Song.AchievedStatus || [])] // 直接复制,包含6
};
// 如果achievedStatus存在2或5,最低取1000000分
const v2Status = v2Song.AchievedStatus || [];
if (v2Status.includes(2) || v2Status.includes(5)) {
newV3Record.BestScore = Math.max(newV3Record.BestScore, 1000000);
}
currentData.SongRecordsV3.push(newV3Record);
} else {
// v3中已有成绩,进行合并
const existingV3 = currentData.SongRecordsV3[existingV3Index];
// Best Accuracy取较高值
existingV3.BestAccuracy = Math.max(existingV3.BestAccuracy, v2Song.BestAccuracy);
// BestLevel取较小值
existingV3.BestLevel = Math.min(existingV3.BestLevel, v2Song.BestLevel);
// AchievedStatus做并集
const statusSet = new Set(existingV3.AchievedStatus);
// 只有在v3本身没有6的情况下才清除6
if (!statusSet.has(6)) {
// v3没有6,添加v2状态时排除6
(v2Song.AchievedStatus || []).forEach(status => {
if (status !== 6) {
statusSet.add(status);
}
});
} else {
// v3本身有6,直接并集(包含6)
(v2Song.AchievedStatus || []).forEach(status => {
statusSet.add(status);
});
}
existingV3.AchievedStatus = Array.from(statusSet);
// 如果v2的achievedStatus存在2或5,且v3的分数低于1000000,则设置最低1000000分
const v2Status = v2Song.AchievedStatus || [];
if ((v2Status.includes(2) || v2Status.includes(5)) && existingV3.BestScore < 1000000) {
existingV3.BestScore = 1000000;
}
// 否则保持v3的原有值
}
});
// 清空v2成绩
currentData.SongRecords = [];
// 更新显示
updateOutput();
renderCards();
alert('v2成绩已清除并合并到v3中');
}
</script>
</body>
</html>