directAudioActions.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Action } from "./action.js";
  2. import { RegisterClass } from "../Misc/typeStore.js";
  3. /**
  4. * This defines an action helpful to play a defined sound on a triggered action.
  5. */
  6. export class PlaySoundAction extends Action {
  7. /**
  8. * Instantiate the action
  9. * @param triggerOptions defines the trigger options
  10. * @param sound defines the sound to play
  11. * @param condition defines the trigger related conditions
  12. */
  13. constructor(triggerOptions, sound, condition) {
  14. super(triggerOptions, condition);
  15. this._sound = sound;
  16. }
  17. /** @internal */
  18. _prepare() { }
  19. /**
  20. * Execute the action and play the sound.
  21. */
  22. execute() {
  23. if (this._sound !== undefined) {
  24. this._sound.play();
  25. }
  26. }
  27. /**
  28. * Serializes the actions and its related information.
  29. * @param parent defines the object to serialize in
  30. * @returns the serialized object
  31. */
  32. serialize(parent) {
  33. return super._serialize({
  34. name: "PlaySoundAction",
  35. properties: [{ name: "sound", value: this._sound.name }],
  36. }, parent);
  37. }
  38. }
  39. /**
  40. * This defines an action helpful to stop a defined sound on a triggered action.
  41. */
  42. export class StopSoundAction extends Action {
  43. /**
  44. * Instantiate the action
  45. * @param triggerOptions defines the trigger options
  46. * @param sound defines the sound to stop
  47. * @param condition defines the trigger related conditions
  48. */
  49. constructor(triggerOptions, sound, condition) {
  50. super(triggerOptions, condition);
  51. this._sound = sound;
  52. }
  53. /** @internal */
  54. _prepare() { }
  55. /**
  56. * Execute the action and stop the sound.
  57. */
  58. execute() {
  59. if (this._sound !== undefined) {
  60. this._sound.stop();
  61. }
  62. }
  63. /**
  64. * Serializes the actions and its related information.
  65. * @param parent defines the object to serialize in
  66. * @returns the serialized object
  67. */
  68. serialize(parent) {
  69. return super._serialize({
  70. name: "StopSoundAction",
  71. properties: [{ name: "sound", value: this._sound.name }],
  72. }, parent);
  73. }
  74. }
  75. RegisterClass("BABYLON.PlaySoundAction", PlaySoundAction);
  76. RegisterClass("BABYLON.StopSoundAction", StopSoundAction);
  77. //# sourceMappingURL=directAudioActions.js.map