fpsManager.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* eslint-disable global-require */
  2. "use strict";
  3. /*
  4. * Fps Manager loader. Managing units start and prerequisites
  5. * Author: SaltyMonkey
  6. * Contributors:
  7. */
  8. /**
  9. * Dependencies
  10. * @typedef {Object} deps
  11. * @property {import('./lib/unitProto')} proto
  12. * @property {import('./lib/unitState')} data
  13. * @property {import('./lib/unitTracker')} tracker
  14. * @property {import('./lib/unitFps')} fps
  15. * @property {import('./lib/unitControl')} cmd
  16. * @property {*} mod
  17. */
  18. const msg = {
  19. "proxyWarning": "Proxy runtime detected. Proper work not guaranteed.",
  20. "runtimeWarning": "Outdated runtime detected. Proper work not guaranteed."
  21. "runtimeOld": "Runtime is so old"
  22. };
  23. const units = [
  24. ["proto", require("./lib/unitProto")],
  25. ["data", require("./lib/unitState")],
  26. ["tracker", require("./lib/unitTracker")],
  27. ["fps", require("./lib/unitFps")],
  28. ["cmd", require("./lib/unitControl")]
  29. ];
  30. class FpsManager {
  31. constructor(mod) {
  32. /**
  33. * @type {deps}
  34. */
  35. let deps = {};
  36. console.log("DEBUG: FpsManager -> constructor");
  37. //check compatibility (only warning atm)
  38. if (mod.proxyAuthor !== "caali")
  39. mod.error(msg.runtimeWarning);
  40. else if(mod.proxyAuthor === "caali" && !mod.clientInterface)
  41. mod.error(msg.proxyWarning);
  42. // eslint-disable-next-line node/no-missing-require
  43. else if(!require("tera-data-parser").types)
  44. mod.error(msg.runtimeOld);
  45. mod.game.initialize("me");
  46. units.forEach(unit => {
  47. // eslint-disable-next-line no-magic-numbers
  48. deps[unit[0]] = new unit[1](deps);
  49. });
  50. //just in case units will need custom destructors, register them
  51. this.destructor = () => {
  52. Object.keys(deps).forEach(key => {
  53. if (typeof deps[key].destructor === "function") { deps[key].destructor(); }
  54. });
  55. };
  56. }
  57. }
  58. module.exports = FpsManager;