forked from hsdn/tera-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings_migrator.js
167 lines (152 loc) · 3.49 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
"use strict";
const DefaultSettings = {
"enabled": true,
"stream": false,
"lNotice": false,
"gNotice": false,
"spawnObject": true,
"speech": {
"enabled": false,
"rate": 2,
"volume": 100,
"gender": "female"
},
"cc": [
"</font><font color=\"#ffff00\">"
],
"language": "auto",
"dungeons": {},
"debug": {
"chat": true,
"all": false,
"s": false,
"e": false,
"am": false,
"ae": false,
"ab": false,
"ar": false,
"ad": false,
"h": false,
"ns": false,
"nd": false,
"rb": false,
"re": 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.16: // p102
remove([
"guides/3027.js",
"guides/3034.js",
"guides/3036.js",
"guides/3201.js",
"guides/3202.js",
"guides/3203.js",
"guides/9053.js",
"guides/9056.js",
"guides/9735.js",
"guides/9739.js",
"guides/9781.js",
"guides/9920.js",
"guides/9982.js"
]);
break;
case 1.17: // p108
remove([
"guides/3020.js",
"guides/3026.js",
"guides/3034.js",
"guides/3101.js",
"guides/3103.js",
"guides/3104.js",
"guides/3106.js",
"guides/3126.js",
"guides/3204.js",
"guides/9070.js",
"guides/9770.js",
"guides/9970.js"
]);
break;
case 1.18: // p114
case 1.19:
remove([
"guides/3023.js",
"guides/3030.js",
"guides/3041.js",
"guides/3044.js",
"guides/3102.js",
"guides/3104.js",
"guides/3107.js",
"guides/3205.js",
"guides/9044.js",
"guides/9780.js",
"guides/9982.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) {}
}
};