fpsManager.js 1.8 KB

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