forked from FukutoTojido/beatmap-viewer-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
124 lines (111 loc) · 3.8 KB
/
index.js
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
import { Game } from "./scripts/Game.js";
import { loadLocalStorage } from "./scripts/Utils.js";
import { Texture } from "./scripts/Texture.js";
import { BeatmapFile } from "./scripts/BeatmapFile.js";
import { urlParams } from "./scripts/GlobalVariables.js";
import { toggleSidePanel } from "./scripts/SidePanel.js";
import { openMenu } from "./scripts/Settings.js";
document.querySelector(".loading").style.opacity = 1;
document.querySelector("#loadingText").textContent = `Initializing`;
function setupDefaultStorage() {
const settingsTemplate = {
mirror: {
val: "mino",
custom: "",
},
mapping: {
beatsnap: 4,
offset: 0,
showGreenLine: false,
},
background: {
dim: 0.8,
blur: 0,
},
volume: {
master: 1,
music: 0.5,
hs: 0.2,
},
skinning: {
type: "0",
val: "-1",
},
sliderAppearance: {
snaking: true,
hitAnim: true,
ignoreSkin: false,
},
timeline: {
zoomRate: 200,
},
};
if (!localStorage.getItem("settings")) {
localStorage.setItem("settings", JSON.stringify(settingsTemplate));
} else {
const currentLocalStorage = JSON.parse(localStorage.getItem("settings"));
Object.keys(settingsTemplate).forEach((k) => {
if (currentLocalStorage[k] === undefined) currentLocalStorage[k] = settingsTemplate[k];
Object.keys(settingsTemplate[k]).forEach((k2) => {
if (currentLocalStorage[k][k2] === undefined) currentLocalStorage[k][k2] = settingsTemplate[k][k2];
});
});
localStorage.setItem("settings", JSON.stringify(currentLocalStorage));
}
}
(async () => {
setupDefaultStorage();
Game.MASTER_VOL = JSON.parse(localStorage.getItem("settings")).volume.master;
Game.MUSIC_VOL = JSON.parse(localStorage.getItem("settings")).volume.music;
Game.HS_VOL = JSON.parse(localStorage.getItem("settings")).volume.hs;
Game.SLIDER_APPEARANCE = JSON.parse(localStorage.getItem("settings")).sliderAppearance;
Game.SKINNING = JSON.parse(localStorage.getItem("settings")).skinning;
Game.MAPPING = JSON.parse(localStorage.getItem("settings")).mapping;
await loadLocalStorage();
document.querySelector(".loading").style.opacity = 0;
document.querySelector(".loading").style.display = "none";
// Init
Game.init();
Texture.generateDefaultTextures();
document.body.addEventListener("keydown", (e) => {
switch (e.key) {
case "F6": {
e.preventDefault();
break;
}
case "F4": {
e.preventDefault();
break;
}
case "o": {
e.preventDefault();
break;
}
}
});
document.body.addEventListener("keyup", (e) => {
switch (e.key) {
case "F6": {
e.preventDefault();
toggleSidePanel("timing");
break;
}
case "F4": {
e.preventDefault();
toggleSidePanel("metadata");
break;
}
case "o": {
if (e.ctrlKey) {
e.preventDefault();
openMenu();
}
break;
}
}
});
if (urlParams.get("b") && /[0-9]+/g.test(urlParams.get("b"))) {
Game.BEATMAP_FILE = new BeatmapFile(urlParams.get("b"));
document.querySelector("#mapInput").value = urlParams.get("b");
}
})();