forked from GrafNikola/tera-guide
-
Notifications
You must be signed in to change notification settings - Fork 17
/
settings_migrator.js
115 lines (103 loc) · 2.51 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
"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;
}
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) {}
}
};