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.
 
 
 

74 lines
1.4 KiB

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