settings_migrator.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. const DefaultSettings = {
  3. "skills": {
  4. "6": [ // Priest
  5. 19, // Focus Heal
  6. 37 // Immersion
  7. ],
  8. "7": [ // Mystic
  9. 5, // Titanic Favor
  10. 9 // Arun's Cleansing Touch
  11. ]
  12. },
  13. "autoCast": true, // true = skills auto lockon and cast. false = pre-lockon onto targets and casting is done manually
  14. "autoHeal": true, // enable healing skills
  15. "autoCleanse": true, // enable mystic cleanse
  16. "onlyDebuff": true, // cleanse only players with debuffs (uses debuffData.json file)
  17. "hpCutoff": 97, // (healing only) ignore members that have more HP% than this
  18. "maxDistance": 35, // in-game meters. can work up to 35m
  19. "lockSpeed": 5, // delay for locking on targets. Possible to specify two values as array to select at random.
  20. "castSpeed": 10 // delay for casting skills. castSpeed needs to be greater than lockSpeed. Possible to specify two values as array to select at random.
  21. };
  22. module.exports = function MigrateSettings(from_ver, to_ver, settings) {
  23. if (from_ver === undefined) {
  24. // Migrate legacy config file
  25. return { ...DefaultSettings, ...settings };
  26. } else if (from_ver === null) {
  27. // No config file exists, use default settings
  28. return DefaultSettings;
  29. } else {
  30. // Migrate from older version (using the new system) to latest one
  31. if (from_ver + 1 < to_ver) {
  32. // Recursively upgrade in one-version steps
  33. settings = MigrateSettings(from_ver, from_ver + 1, settings);
  34. return MigrateSettings(from_ver + 1, to_ver, settings);
  35. }
  36. const oldsettings = settings;
  37. settings = Object.assign(DefaultSettings, {});
  38. // If we reach this point it's guaranteed that from_ver === to_ver - 1, so we can implement
  39. // a switch for each version step that upgrades to the next version. This enables us to
  40. // upgrade from any version to the latest version without additional effort!
  41. switch (to_ver) {
  42. // keep old settings, add new ones
  43. default:
  44. for (const option in oldsettings) {
  45. if (settings[option]) {
  46. settings[option] = oldsettings[option];
  47. }
  48. }
  49. if (from_ver < to_ver) console.log(`[Auto Heal] Your settings have been updated to version ${ to_ver }. You can edit the new config file after the next relog.`);
  50. break;
  51. }
  52. return settings;
  53. }
  54. };