settings_migrator.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. "hpCutoff": 97, // (healing only) ignore members that have more HP% than this
  17. "maxDistance": 27, // in-game meters. can work up to 35m
  18. "lockSpeed": 45, // delay for locking on targets.
  19. "castSpeed": 150 // delay for casting skills. castSpeed needs to be greater than lockSpeed.
  20. }
  21. module.exports = function MigrateSettings(from_ver, to_ver, settings) {
  22. if (from_ver === undefined) {
  23. // Migrate legacy config file
  24. return Object.assign(Object.assign({}, DefaultSettings), settings);
  25. } else if (from_ver === null) {
  26. // No config file exists, use default settings
  27. return DefaultSettings;
  28. } else {
  29. // Migrate from older version (using the new system) to latest one
  30. if (from_ver + 1 < to_ver) {
  31. // Recursively upgrade in one-version steps
  32. settings = MigrateSettings(from_ver, from_ver + 1, settings);
  33. return MigrateSettings(from_ver + 1, to_ver, settings);
  34. }
  35. // If we reach this point it's guaranteed that from_ver === to_ver - 1, so we can implement
  36. // a switch for each version step that upgrades to the next version. This enables us to
  37. // upgrade from any version to the latest version without additional effort!
  38. switch(to_ver)
  39. {
  40. // keep old settings, add new ones
  41. default:
  42. let oldsettings = settings
  43. settings = Object.assign(DefaultSettings, {});
  44. for(let 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. }