forked from xVinnie/tera-long-dmg-numbers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings_migrator.js
35 lines (31 loc) · 1.03 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
const DefaultSettings = {
"enabled": true,
"pve_divisor": 1000,
"pvp_divisor": 1
}
function MigrateSettings(from_ver, to_ver, settings) {
if (from_ver === undefined) {
// Migrate legacy config file
return Object.assign(Object.assign({}, DefaultSettings), settings);
} else if (from_ver === null) {
// No config file exists, use default settings
return DefaultSettings;
} else {
// Migrate from older version (using the new system) to latest one
if (from_ver + 1 < to_ver) {
// Recursively upgrade in one-version steps
settings = MigrateSettings(from_ver, from_ver + 1, settings);
return MigrateSettings(from_ver + 1, to_ver, settings);
}
switch(to_ver)
{
case 2:
settings.pve_divisor = settings.divisor;
settings.pvp_divisor = DefaultSettings.pvp_divisor;
delete settings.divisor;
break;
}
return settings;
}
}
module.exports = MigrateSettings;