actionEvent.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * ActionEvent is the event being sent when an action is triggered.
  3. */
  4. export class ActionEvent {
  5. /**
  6. * Creates a new ActionEvent
  7. * @param source The mesh or sprite that triggered the action
  8. * @param pointerX The X mouse cursor position at the time of the event
  9. * @param pointerY The Y mouse cursor position at the time of the event
  10. * @param meshUnderPointer The mesh that is currently pointed at (can be null)
  11. * @param sourceEvent the original (browser) event that triggered the ActionEvent
  12. * @param additionalData additional data for the event
  13. */
  14. constructor(
  15. /** The mesh or sprite that triggered the action */
  16. source,
  17. /** The X mouse cursor position at the time of the event */
  18. pointerX,
  19. /** The Y mouse cursor position at the time of the event */
  20. pointerY,
  21. /** The mesh that is currently pointed at (can be null) */
  22. meshUnderPointer,
  23. /** the original (browser) event that triggered the ActionEvent */
  24. sourceEvent,
  25. /** additional data for the event */
  26. additionalData) {
  27. this.source = source;
  28. this.pointerX = pointerX;
  29. this.pointerY = pointerY;
  30. this.meshUnderPointer = meshUnderPointer;
  31. this.sourceEvent = sourceEvent;
  32. this.additionalData = additionalData;
  33. }
  34. /**
  35. * Helper function to auto-create an ActionEvent from a source mesh.
  36. * @param source The source mesh that triggered the event
  37. * @param evt The original (browser) event
  38. * @param additionalData additional data for the event
  39. * @returns the new ActionEvent
  40. */
  41. static CreateNew(source, evt, additionalData) {
  42. const scene = source.getScene();
  43. return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer || source, evt, additionalData);
  44. }
  45. /**
  46. * Helper function to auto-create an ActionEvent from a source sprite
  47. * @param source The source sprite that triggered the event
  48. * @param scene Scene associated with the sprite
  49. * @param evt The original (browser) event
  50. * @param additionalData additional data for the event
  51. * @returns the new ActionEvent
  52. */
  53. static CreateNewFromSprite(source, scene, evt, additionalData) {
  54. return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt, additionalData);
  55. }
  56. /**
  57. * Helper function to auto-create an ActionEvent from a scene. If triggered by a mesh use ActionEvent.CreateNew
  58. * @param scene the scene where the event occurred
  59. * @param evt The original (browser) event
  60. * @returns the new ActionEvent
  61. */
  62. static CreateNewFromScene(scene, evt) {
  63. return new ActionEvent(null, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt);
  64. }
  65. /**
  66. * Helper function to auto-create an ActionEvent from a primitive
  67. * @param prim defines the target primitive
  68. * @param pointerPos defines the pointer position
  69. * @param evt The original (browser) event
  70. * @param additionalData additional data for the event
  71. * @returns the new ActionEvent
  72. */
  73. static CreateNewFromPrimitive(prim, pointerPos, evt, additionalData) {
  74. return new ActionEvent(prim, pointerPos.x, pointerPos.y, null, evt, additionalData);
  75. }
  76. }
  77. //# sourceMappingURL=actionEvent.js.map