fpsManager.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/management/cmd')} 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. ["log", require("./lib/unitLog")],
  25. ["proto", require("./lib/unitProto")],
  26. ["data", require("./lib/unitState")],
  27. ["tracker", require("./lib/unitTracker")],
  28. ["fps", require("./lib/unitFps")],
  29. ["cmd", require("./lib/management/cmd")]
  30. ];
  31. class FpsManager {
  32. constructor(mod) {
  33. /**
  34. * @type {deps}
  35. */
  36. let deps = { "mod": mod };
  37. //check compatibility (only warning atm)
  38. if (mod.isProxyCompat)
  39. mod.error(msg.proxyWarning);
  40. // eslint-disable-next-line node/no-missing-require
  41. else if (!require("tera-data-parser").types)
  42. mod.error(msg.runtimeOld);
  43. mod.game.initialize("me");
  44. units.forEach(unit => {
  45. // eslint-disable-next-line no-magic-numbers
  46. deps[unit[0]] = new unit[1](deps);
  47. });
  48. //just in case units will need custom destructors, register them
  49. this.destructor = () => {
  50. Object.keys(deps).forEach(key => {
  51. if (key !== "mod" && typeof deps[key].destructor === "function") { deps[key].destructor(); }
  52. });
  53. };
  54. }
  55. }
  56. module.exports = FpsManager;