XverseEffect.js 2.8 KB

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