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.
 
 
 

57 lines
1.1 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. events.on('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. let exists = this.actions.some(function (ta) {
  29. return ((ta.targetId == a.targetId) && (ta.cpn == a.cpn) && (ta.method == a.method));
  30. });
  31. if (exists)
  32. return;
  33. this.actions.push(a);
  34. }, this);
  35. delete blueprint.addActions;
  36. }
  37. if (blueprint.removeActions) {
  38. blueprint.removeActions.forEach(function (a) {
  39. this.actions.spliceWhere(function (ta) {
  40. return ((ta.targetId == a.targetId) && (ta.cpn == a.cpn) && (ta.method == a.method));
  41. });
  42. }, this);
  43. delete blueprint.removeActions;
  44. }
  45. }
  46. };
  47. });