Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

118 rader
2.0 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. events.on('onUiHover', this.onUiHover.bind(this, true));
  27. events.on('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. clearPath: function () {
  37. this.path.forEach(function (p) {
  38. if (p.sprite) {
  39. renderer.destroyObject({
  40. sprite: p.sprite,
  41. layerName: 'effects'
  42. });
  43. }
  44. });
  45. this.path = [];
  46. },
  47. onUiHover: function (dunno, onUiHover) {
  48. if (!this.sprite)
  49. return;
  50. this.sprite.visible = !onUiHover;
  51. },
  52. showPath: function (e) {
  53. if ((e.button !== null) && (e.button !== 0))
  54. return;
  55. let tileX = ~~(e.x / scale);
  56. let tileY = ~~(e.y / scale);
  57. if ((tileX === this.hoverTile.x) && (tileY === this.hoverTile.y))
  58. return;
  59. events.emit('onChangeHoverTile', tileX, tileY);
  60. this.hoverTile.x = ~~(e.x / scale);
  61. this.hoverTile.y = ~~(e.y / scale);
  62. this.sprite.x = (this.hoverTile.x * scale);
  63. this.sprite.y = (this.hoverTile.y * scale);
  64. },
  65. queuePath: function (e) {
  66. this.mouseDown = false;
  67. if ((this.path.length === 0) || (e.down))
  68. return;
  69. client.request({
  70. cpn: 'player',
  71. method: 'moveList',
  72. data: this.path.map(function (p) {
  73. return {
  74. x: p.x,
  75. y: p.y
  76. };
  77. })
  78. });
  79. this.obj.pather.setPath(this.path);
  80. this.path = [];
  81. },
  82. update: function () {
  83. this.opacityCounter++;
  84. if (this.sprite)
  85. this.sprite.alpha = 0.35 + Math.abs(Math.sin(this.opacityCounter / 20) * 0.35);
  86. this.showPath(input.mouse);
  87. },
  88. destroy: function () {
  89. renderer.destroyObject({
  90. sprite: this.sprite,
  91. layerName: 'effects'
  92. });
  93. }
  94. };
  95. });