You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

89 lines
1.4 KiB

  1. let components = [
  2. 'keyboardMover',
  3. 'mouseMover',
  4. 'touchMover',
  5. 'player',
  6. 'pather',
  7. 'attackAnimation',
  8. 'lightningEffect',
  9. 'moveAnimation',
  10. 'bumpAnimation',
  11. 'animation',
  12. 'light',
  13. 'lightPatch',
  14. 'projectile',
  15. 'particles',
  16. 'explosion',
  17. 'spellbook',
  18. 'inventory',
  19. 'stats',
  20. 'chest',
  21. 'effects',
  22. 'quests',
  23. 'events',
  24. 'resourceNode',
  25. 'gatherer',
  26. 'stash',
  27. 'flash',
  28. 'chatter',
  29. 'dialogue',
  30. 'trade',
  31. 'reputation',
  32. 'serverActions',
  33. 'social',
  34. 'passives',
  35. 'sound',
  36. 'whirlwind',
  37. 'fadeInOut'
  38. ].map(function (c) {
  39. return 'js/components/' + c;
  40. });
  41. define([
  42. ...components,
  43. '../system/events'
  44. ], function () {
  45. const events = arguments[arguments.length - 1];
  46. const hookEvent = function (e, cb) {
  47. if (!this.eventList[e])
  48. this.eventList[e] = [];
  49. this.eventList[e].push(cb);
  50. events.on(e, cb);
  51. };
  52. const unhookEvents = function () {
  53. Object.entries(this.eventList).forEach(([eventName, callbacks]) => {
  54. callbacks.forEach(c => events.off(eventName, c));
  55. });
  56. };
  57. let templates = {};
  58. [].forEach.call(arguments, function (t, i) {
  59. //Don't do this for the events module
  60. if (i === arguments[2].length - 1)
  61. return;
  62. t.eventList = {};
  63. t.hookEvent = hookEvent;
  64. t.unhookEvents = unhookEvents;
  65. templates[t.type] = t;
  66. });
  67. return {
  68. getTemplate: function (type) {
  69. if (type === 'lightpatch')
  70. type = 'lightPatch';
  71. let template = templates[type] || {
  72. type: type
  73. };
  74. return template;
  75. }
  76. };
  77. });