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.
 
 
 

65 lines
1.3 KiB

  1. define([
  2. 'js/system/events',
  3. 'js/system/client'
  4. ], function (
  5. events,
  6. client
  7. ) {
  8. return {
  9. type: 'serverActions',
  10. actions: [],
  11. init: function (blueprint) {
  12. this.hookEvent('onKeyUp', this.onKeyUp.bind(this));
  13. },
  14. onKeyUp: function (key) {
  15. this.actions.forEach(function (a) {
  16. if (a.key !== key)
  17. return;
  18. client.request({
  19. cpn: 'player',
  20. method: 'performAction',
  21. data: a.action
  22. });
  23. }, this);
  24. },
  25. extend: function (blueprint) {
  26. if (blueprint.addActions) {
  27. blueprint.addActions.forEach(function (a) {
  28. this.actions.spliceWhere(f => f.key === a.key);
  29. let exists = this.actions.some(function (ta) {
  30. return ((ta.targetId === a.targetId) && (ta.cpn === a.cpn) && (ta.method === a.method));
  31. });
  32. if (exists)
  33. return;
  34. this.actions.push(a);
  35. }, this);
  36. delete blueprint.addActions;
  37. }
  38. if (blueprint.removeActions) {
  39. blueprint.removeActions.forEach(function (a) {
  40. this.actions.spliceWhere(function (ta) {
  41. return ((ta.targetId === a.targetId) && (ta.cpn === a.cpn) && (ta.method === a.method));
  42. });
  43. }, this);
  44. delete blueprint.removeActions;
  45. }
  46. events.emit('onGetServerActions', this.actions);
  47. },
  48. destroy: function () {
  49. this.unhookEvents();
  50. }
  51. };
  52. });