-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsettings_migrator.js
148 lines (131 loc) · 3.05 KB
/
settings_migrator.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"use strict";
const DefaultSettings = {
"enabled": true,
"stream": false,
"lNotice": false,
"gNotice": false,
"spawnObject": true,
"speech": {
"enabled": false,
"rate": 3,
"volume": 100,
"gender": "female"
},
"cc": [
"</font><font color=\"#b8ff05\">"
],
"language": "auto",
"dungeons": {},
"debug": {
"chat": true,
"all": false,
"s": false,
"am": false,
"ae": false,
"ab": false,
"ar": false,
"ad": false,
"h": false,
"ns": false,
"nd": false,
"dm": false,
"qb": false
}
};
module.exports = function MigrateSettings(from_ver, to_ver, settings) {
if (from_ver === undefined) return { ...DefaultSettings, ...settings };
else if (from_ver === null) return DefaultSettings;
else {
from_ver = Number(from_ver);
to_ver = Number(to_ver);
if (from_ver + 0.01 < to_ver) {
settings = MigrateSettings(from_ver, from_ver + 0.01, settings);
return MigrateSettings(from_ver + 0.01, to_ver, settings);
}
const oldsettings = settings;
settings = Object.assign(DefaultSettings, {});
to_ver = Math.round(to_ver * 100) / 100;
switch (to_ver) {
case 1.12:
for (const option in oldsettings) {
if (option === "dungeons" && Array.isArray(oldsettings[option])) {
settings[option] = {};
for (const element of oldsettings[option]) {
const id = element.id;
delete element.id;
settings[option][id] = element;
}
continue;
} else
settings[option] = oldsettings[option];
}
return settings;
case 1.13:
remove(["dbg.json", "lib.js", "dispatch.js", "voice/index.js", "voice"]);
break;
case 1.14:
oldsettings["debug"] = settings["debug"];
break;
case 1.15:
for (const option in oldsettings) {
if (option === "speaks")
settings["speech"]["enabled"] = oldsettings["speaks"];
else if (option === "rate")
settings["speech"]["rate"] = parseInt(oldsettings["rate"]);
else
settings[option] = oldsettings[option];
}
return settings;
case 1.22:
remove([
"guides/3034.js",
"guides/3034.js",
"guides/3106.js",
"guides/3204.js"
]);
break;
case 1.18: // p114
case 1.23:
remove([
"guides/3041.js",
"guides/3044.js",
"guides/3104.js",
"guides/3107.js",
"guides/3205.js"
]);
break;
case 1.24: // p115
remove([
"guides/3042.js",
"guides/3047.js",
"guides/3043.js",
"guides/3040.js",
"guides/3046.js",
"guides/3105.js",
"guides/3108.js",
"guides/3109.js",
"guides/3209.js"
]);
break;
}
for (const option in oldsettings) {
if (settings[option] !== undefined)
settings[option] = oldsettings[option];
}
return settings;
}
function remove(files) {
const fs = require("fs"), path = require("path");
try {
for (const file of files) {
const filePath = path.join(__dirname, file);
if (fs.existsSync(filePath)) {
if (fs.lstatSync(filePath).isDirectory())
fs.rmdirSync(filePath);
else
fs.unlinkSync(filePath);
}
}
} catch (e) {}
}
};