XverseEffect.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. const log$8 = new Logger("effectManager");
  2. class XverseEffect extends EventEmitter {
  3. constructor({id: e, jsonPath: t, type: r, room: n, scale: o=1}) {
  4. super();
  5. E(this, "_id");
  6. E(this, "type");
  7. E(this, "effect");
  8. E(this, "avatarEffect");
  9. E(this, "_room");
  10. E(this, "_isLoading", !0);
  11. E(this, "_failed", !1);
  12. E(this, "_scale", 1);
  13. this._room = n,
  14. this._id = e,
  15. this.type = r,
  16. this._scale = o,
  17. this.effect = e === "Rain" || e === "Boom" ? new XRain(this._room.scene,t,urlTransformer) : r === IEffectType.Sequence ? new XSequence(this._room.scene,t,"",urlTransformer) : new XSubSequence(this._room.scene,t,urlTransformer),
  18. this.avatarEffect = new XSubSequence(this._room.scene,t,urlTransformer)
  19. }
  20. get failed() {
  21. return this._failed
  22. }
  23. get position() {
  24. if (this.type !== IEffectType.Sequence)
  25. return this.effect.position
  26. }
  27. get rotation() {
  28. if (this.type !== IEffectType.Sequence)
  29. return this.effect.rotation
  30. }
  31. get isLoading() {
  32. return this._isLoading
  33. }
  34. get id() {
  35. return this._id
  36. }
  37. get name() {
  38. return this.effect.name
  39. }
  40. get isPlaying() {
  41. var e;
  42. return !!((e = this.effect) != null && e.isPlaying)
  43. }
  44. async init() {
  45. try {
  46. await this.effect.init()._timeout(1e4, new TimeoutError("effect init timeout(10s)")),
  47. this._isLoading = !1,
  48. this._failed = !1
  49. } catch (e) {
  50. throw this._isLoading = !1,
  51. this._failed = !0,
  52. log$8.error(`effect: ${this.id} init error`, e),
  53. e
  54. }
  55. }
  56. play(e=!1) {
  57. return new Promise((t,r)=>{
  58. this.effect.play(e),
  59. this.isPlaying ? t() : r(`play effect: ${this.name} failed`)
  60. }
  61. )
  62. }
  63. hide() {
  64. return this.effect.hide()
  65. }
  66. show() {
  67. return this.effect.show()
  68. }
  69. setRotation(e) {
  70. var t;
  71. return this.type === IEffectType.Sequence ? Promise.reject("setRotation failed, sequence unSuported") : (t = this.effect) == null ? void 0 : t.setRotation(e)
  72. }
  73. setPosition(e) {
  74. var t;
  75. return this.type === IEffectType.Sequence ? Promise.reject("setPosition failed, sequence unSuported") : (t = this.effect) == null ? void 0 : t.setPosition(e)
  76. }
  77. setScaling(e) {
  78. var t;
  79. return this.type === IEffectType.Sequence ? Promise.reject("setScaling failed, sequence unSuported") : (this._scale = e,
  80. (t = this.effect) == null ? void 0 : t.setScaling({
  81. x: e,
  82. y: e,
  83. z: e
  84. }))
  85. }
  86. dispose() {
  87. this.effect.dispose()
  88. }
  89. }