No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

69 líneas
1.4 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. hasAction: function (actionId) {
  15. return this.actions.some(a => a.id === actionId);
  16. },
  17. onKeyUp: function (key) {
  18. this.actions.forEach(function (a) {
  19. if (a.key !== key)
  20. return;
  21. client.request({
  22. cpn: 'player',
  23. method: 'performAction',
  24. data: a.action
  25. });
  26. }, this);
  27. },
  28. extend: function (blueprint) {
  29. if (blueprint.addActions) {
  30. blueprint.addActions.forEach(function (a) {
  31. this.actions.spliceWhere(f => f.key === a.key);
  32. let exists = this.actions.some(function (ta) {
  33. return ((ta.targetId === a.targetId) && (ta.cpn === a.cpn) && (ta.method === a.method));
  34. });
  35. if (exists)
  36. return;
  37. this.actions.push(a);
  38. }, this);
  39. delete blueprint.addActions;
  40. }
  41. if (blueprint.removeActions) {
  42. blueprint.removeActions.forEach(function (a) {
  43. this.actions.spliceWhere(function (ta) {
  44. return ((ta.targetId === a.targetId) && (ta.cpn === a.cpn) && (ta.method === a.method));
  45. });
  46. }, this);
  47. delete blueprint.removeActions;
  48. }
  49. events.emit('onGetServerActions', this.actions);
  50. },
  51. destroy: function () {
  52. this.unhookEvents();
  53. }
  54. };
  55. });