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.
 
 
 

84 lines
1.5 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. return {
  15. type: 'mouseMover',
  16. hoverTile: {
  17. x: 0,
  18. y: 0
  19. },
  20. path: [],
  21. pathColor: 'rgba(255, 255, 255, 0.5)',
  22. mouseDown: false,
  23. opacityCounter: 0,
  24. sprite: null,
  25. init: function () {
  26. this.hookEvent('onUiHover', this.onUiHover.bind(this, true));
  27. this.hookEvent('onUiLeave', this.onUiHover.bind(this, false));
  28. this.sprite = renderer.buildObject({
  29. layerName: 'effects',
  30. x: 0,
  31. y: 0,
  32. sheetName: 'ui',
  33. cell: 7
  34. });
  35. },
  36. onUiHover: function (dunno, onUiHover) {
  37. if (this.sprite)
  38. this.sprite.visible = !onUiHover;
  39. },
  40. showPath: function (e) {
  41. if ((e.button !== null) && (e.button !== 0))
  42. return;
  43. let tileX = ~~(e.x / scale);
  44. let tileY = ~~(e.y / scale);
  45. if ((tileX === this.hoverTile.x) && (tileY === this.hoverTile.y))
  46. return;
  47. events.emit('onChangeHoverTile', tileX, tileY);
  48. this.hoverTile.x = ~~(e.x / scale);
  49. this.hoverTile.y = ~~(e.y / scale);
  50. this.sprite.x = (this.hoverTile.x * scale);
  51. this.sprite.y = (this.hoverTile.y * scale);
  52. },
  53. update: function () {
  54. this.opacityCounter++;
  55. if (this.sprite)
  56. this.sprite.alpha = 0.35 + Math.abs(Math.sin(this.opacityCounter / 20) * 0.35);
  57. this.showPath(input.mouse);
  58. },
  59. destroy: function () {
  60. renderer.destroyObject({
  61. sprite: this.sprite
  62. });
  63. this.unhookEvents();
  64. }
  65. };
  66. });