This repository has been archived by the owner on May 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings_migrator.js
63 lines (55 loc) · 2.25 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
const DefaultSettings = {
"enabled": true,
"notice": false,
"spawnObject": true,
"tts": true,
"rate": 2,
"gender": "male",
"dungeons": {}
};
module.exports = function MigrateSettings(oldVersion, targetVersion, oldSettings){
let updatedSettings = oldSettings;
if(!oldVersion){ // We have no config file, and legeacy config file checking is pointless for this module, so just give a default settings file if the old version doesn't exist
return DefaultSettings;
} else {
oldVersion = parseFloat(oldVersion);
targetVersion = parseFloat(targetVersion);
if(oldVersion < targetVersion){ // If the old version is smaller than the target version
oldVersion += 0.1; // Add 0.1 to the old version so we know which version we're upgrading to
updatedSettings = Object.assign(DefaultSettings, {}); // This is our new settings
/* Seeing as there has been no major settings upgrades, this part is commented out for now, but remains as an example
switch(oldVersion){
// We can simply make use of case fallthroughs for instant upgrades without need for repetition by removing breaks,
// simply setting oldVersion to the current highest version at the end... I swear most js module devs don't know about this
case 1.1:
console.log("Example Config version 1.2");
// Upgrade config from 1.1 to 1.2 here
oldVersion = 1.1;
// falls through
case 1.2:
console.log("Example Config version 1.3");
// Upgrade config from 1.2 to 1.3 here
oldVersion = 1.2;
// falls through
case 1.3:
console.log("Example Config version 1.4");
// Upgrade config from 1.3 to 1.4 here
oldVersion = 1.3;
// falls through
case 1.4:
console.log("Example Config version 1.5");
// Upgrade config from 1.4 to 1.5 here
oldVersion = 1.4;
break;
default: break;
}
*/
for(const item of oldSettings){ // If any of the keys in the old settings are the same as the keys in the new settings, apply them to the new settings
if(updatedSettings[item]){
updatedSettings[item] = oldSettings[item];
}
}
}
}
return updatedSettings; // Once we reach here, we know that oldVersion >= targetVersion and should now be ready for use!
};