fpsManager.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. //check compatibility (only warning atm)
  36. if (mod.proxyAuthor !== "caali")
  37. mod.error(msg.runtimeWarning);
  38. else if(mod.proxyAuthor === "caali" && !mod.clientInterface)
  39. mod.error(msg.proxyWarning);
  40. mod.game.initialize("me");
  41. units.forEach(unit => {
  42. // eslint-disable-next-line no-magic-numbers
  43. deps[unit[0]] = new unit[1](deps);
  44. });
  45. //just in case units will need custom destructors, register them
  46. this.destructor = () => {
  47. Object.keys(deps).forEach(key => {
  48. if (typeof deps[key].destructor === "function") { deps[key].destructor(); }
  49. });
  50. };
  51. }
  52. }
  53. module.exports = FpsManager;