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.
 
 
 

120 lines
2.1 KiB

  1. define([
  2. 'js/system/events',
  3. 'js/rendering/renderer',
  4. 'js/system/client',
  5. 'js/input',
  6. 'js/objects/objects'
  7. ], function (
  8. events,
  9. renderer,
  10. client,
  11. input,
  12. objects
  13. ) {
  14. let scale = 40;
  15. return {
  16. type: 'mouseMover',
  17. hoverTile: {
  18. x: 0,
  19. y: 0
  20. },
  21. path: [],
  22. pathColor: 'rgba(255, 255, 255, 0.5)',
  23. mouseDown: false,
  24. opacityCounter: 0,
  25. sprite: null,
  26. init: function () {
  27. events.on('onUiHover', this.onUiHover.bind(this, true));
  28. events.on('onUiLeave', this.onUiHover.bind(this, false));
  29. this.sprite = renderer.buildObject({
  30. layerName: 'effects',
  31. x: 0,
  32. y: 0,
  33. sheetName: 'ui',
  34. cell: 7
  35. });
  36. },
  37. clearPath: function () {
  38. this.path.forEach(function (p) {
  39. if (p.sprite) {
  40. renderer.destroyObject({
  41. sprite: p.sprite,
  42. layerName: 'effects'
  43. });
  44. }
  45. });
  46. this.path = [];
  47. },
  48. onUiHover: function (dunno, onUiHover) {
  49. if (!this.sprite)
  50. return;
  51. this.sprite.visible = !onUiHover;
  52. },
  53. showPath: function (e) {
  54. if ((e.button != null) && (e.button != 0))
  55. return;
  56. let tileX = ~~(e.x / scale);
  57. let tileY = ~~(e.y / scale);
  58. if ((tileX == this.hoverTile.x) && (tileY == this.hoverTile.y))
  59. return;
  60. events.emit('onChangeHoverTile', tileX, tileY);
  61. this.hoverTile.x = ~~(e.x / scale);
  62. this.hoverTile.y = ~~(e.y / scale);
  63. this.sprite.x = (this.hoverTile.x * scale);
  64. this.sprite.y = (this.hoverTile.y * scale);
  65. },
  66. queuePath: function (e) {
  67. this.mouseDown = false;
  68. if ((this.path.length == 0) || (e.down))
  69. return;
  70. client.request({
  71. cpn: 'player',
  72. method: 'moveList',
  73. data: this.path.map(function (p) {
  74. return {
  75. x: p.x,
  76. y: p.y
  77. };
  78. })
  79. });
  80. this.obj.pather.setPath(this.path);
  81. this.path = [];
  82. },
  83. update: function () {
  84. this.opacityCounter++;
  85. if (this.sprite)
  86. this.sprite.alpha = 0.35 + Math.abs(Math.sin(this.opacityCounter / 20) * 0.35);
  87. this.showPath(input.mouse);
  88. },
  89. destroy: function () {
  90. renderer.destroyObject({
  91. sprite: this.sprite,
  92. layerName: 'effects'
  93. });
  94. }
  95. };
  96. });