fpsManager.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 units = [
  19. ["proto", require("./lib/unitProto")],
  20. ["data", require("./lib/unitState")],
  21. ["tracker", require("./lib/unitTracker")],
  22. ["fps", require("./lib/unitFps")],
  23. ["cmd", require("./lib/unitControl")]
  24. ];
  25. class FpsManager {
  26. constructor(mod) {
  27. //check compatibility (only warning atm)
  28. if (mod.proxyAuthor !== "caali")
  29. mod.error("This mod using possibly will be broken with this runtime.");
  30. else if(mod.proxyAuthor === "caali" && !mod.clientInterface)
  31. mod.error("Proxy runtime detected. Proper work not guaranteed.");
  32. mod.game.initialize("me");
  33. /**
  34. * @type {deps}
  35. */
  36. let deps = {};
  37. units.forEach(unit => {
  38. // eslint-disable-next-line no-magic-numbers
  39. deps[unit[0]] = new unit[1](deps);
  40. });
  41. //just in case units will need custom destructors, register them
  42. this.destructor = () => {
  43. Object.keys(deps).forEach(key => {
  44. if (typeof deps[key].destructor === "function") { deps[key].destructor(); }
  45. });
  46. };
  47. }
  48. }
  49. module.exports = FpsManager;