XParticleManager.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. class XParticleManager{
  2. constructor(e) {
  3. E(this, "_scene");
  4. E(this, "_particles");
  5. E(this, "_light");
  6. E(this, "load", (e,t,r)=>new Promise(n=>{
  7. ParticleSystemSet.BaseAssetsUrl = e;
  8. const o = new XMLHttpRequest;
  9. o.open("get", e + "/" + t),
  10. o.send(null),
  11. o.onload = ()=>{
  12. if (o.status == 200) {
  13. const a = JSON.parse(o.responseText);
  14. let s = null;
  15. if (Object.keys(a).find(l=>l == "systems") == null) {
  16. const l = ParticleSystem.Parse(a, this._scene, e);
  17. s = new ParticleSystemSet,
  18. s.systems.push(l)
  19. } else
  20. s = ParticleSystemSet.Parse(a, this._scene, !1);
  21. n(s)
  22. }
  23. }
  24. }
  25. ));
  26. E(this, "get", e=>this._particles.get(e));
  27. E(this, "start", e=>{
  28. const t = this._particles.get(e);
  29. t && t.start()
  30. }
  31. );
  32. E(this, "stop", e=>{
  33. var r;
  34. const t = ((r = this._particles.get(e)) == null ? void 0 : r.systems) || [];
  35. for (let n = 0; n < t.length; n++)
  36. t[n].stop()
  37. }
  38. );
  39. E(this, "remove", e=>{
  40. const t = this._particles.get(e);
  41. t && t.dispose()
  42. }
  43. );
  44. E(this, "setParticlePosition", (e,t)=>{
  45. const r = this._particles.get(e);
  46. r && (r.emitterNode = t)
  47. }
  48. );
  49. E(this, "setParticleScalingInPlace", (e,t)=>{
  50. const r = this._particles.get(e);
  51. r == null || r.systems.forEach(n=>{
  52. de.scalingInPlace(n, t)
  53. }
  54. )
  55. }
  56. );
  57. if (this._scene = e,
  58. this._particles = new Map,
  59. this._light = null,
  60. this._scene.getLightByName("fireworkLight"))
  61. this._light = this._scene.getLightByName("fireworkLight");
  62. else {
  63. const t = new PointLight("fireworkLight",new Vector3(0,0,0),e);
  64. t.intensity = 0,
  65. this._light = t
  66. }
  67. }
  68. _flashBang(e=200) {
  69. const t = this._scene.getLightByName("fireworkLight");
  70. t.intensity = 1,
  71. setTimeout(()=>{
  72. t.intensity = 0
  73. }
  74. , e)
  75. }
  76. }
  77. ;
  78. E(XParticleManager, "disposeParticleSysSet", e=>{
  79. !e.systems || (e.systems.forEach(t=>{
  80. de.disposeParticleSystem(t)
  81. }
  82. ),
  83. e.dispose())
  84. }
  85. ),
  86. E(XParticleManager, "disposeParticleSystem", e=>{
  87. e.particleSystem && (e = e.particleSystem),
  88. e.subEmitters && e.subEmitters.forEach(t=>{
  89. t instanceof Array ? t.forEach(r=>{
  90. de.disposeParticleSystem(r)
  91. }
  92. ) : de.disposeParticleSystem(t)
  93. }
  94. ),
  95. e.dispose()
  96. }
  97. ),
  98. E(XParticleManager, "scalingInPlace", (e,t)=>{
  99. e.getClassName() === "ParticleSystem" && (e.minSize *= t,
  100. e.maxSize *= t,
  101. e.subEmitters != null && e.subEmitters.forEach(r=>{
  102. r instanceof SubEmitter && de.scalingInPlace(r.particleSystem, t),
  103. r instanceof ParticleSystem && de.scalingInPlace(r, t),
  104. r instanceof Array && r.forEach(n=>{
  105. de.scalingInPlace(n.particleSystem, t)
  106. }
  107. )
  108. }
  109. ))
  110. }
  111. );