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.
 
 
 

73 lines
1.2 KiB

  1. module.exports = {
  2. type: 'prophecies',
  3. list: [],
  4. init: function (blueprint) {
  5. (blueprint.list || []).forEach(function (p) {
  6. let template = null;
  7. try {
  8. let template = require('config/prophecies/' + p);
  9. } catch (e) {
  10. console.log(e);
  11. }
  12. if (template === null)
  13. return;
  14. else if (this.list.some(l => (l.type === p)))
  15. return;
  16. let prophecy = extend(true, {}, template);
  17. prophecy.obj = this.obj;
  18. prophecy.init();
  19. this.list.push(prophecy);
  20. }, this);
  21. delete blueprint.list;
  22. },
  23. hasProphecy: function (type) {
  24. return this.list.some(l => (l.type === type));
  25. },
  26. transfer: function () {
  27. let transferList = this.list;
  28. this.list = [];
  29. this.init({
  30. list: transferList
  31. });
  32. },
  33. fireEvent: function (event, args) {
  34. let list = this.list;
  35. let lLen = list.length;
  36. for (let i = 0; i < lLen; i++) {
  37. let l = list[i];
  38. let events = l.events;
  39. if (!events)
  40. continue;
  41. let callback = events[event];
  42. if (!callback)
  43. continue;
  44. callback.apply(l, args);
  45. }
  46. },
  47. simplify: function (self) {
  48. let e = {
  49. type: 'prophecies'
  50. };
  51. if ((this.list.length > 0) && (this.list[0].simplify))
  52. e.list = this.list.map(p => p.simplify());
  53. else
  54. e.list = this.list;
  55. return e;
  56. }
  57. };