custom-pixi-particles 8.1.1 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/dist/index.d.ts +15 -0
  2. package/dist/index.js +45 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/lib/Model.d.ts +32 -0
  5. package/dist/lib/Model.js +44 -0
  6. package/dist/lib/Model.js.map +1 -0
  7. package/dist/lib/Particle.d.ts +234 -0
  8. package/dist/lib/Particle.js +201 -0
  9. package/dist/lib/Particle.js.map +1 -0
  10. package/dist/lib/ParticlePool.d.ts +37 -0
  11. package/dist/lib/ParticlePool.js +56 -0
  12. package/dist/lib/ParticlePool.js.map +1 -0
  13. package/dist/lib/behaviour/AngularVelocityBehaviour.d.ts +61 -0
  14. package/dist/lib/behaviour/AngularVelocityBehaviour.js +118 -0
  15. package/dist/lib/behaviour/AngularVelocityBehaviour.js.map +1 -0
  16. package/dist/lib/behaviour/AttractionRepulsionBehaviour.d.ts +42 -0
  17. package/dist/lib/behaviour/AttractionRepulsionBehaviour.js +78 -0
  18. package/dist/lib/behaviour/AttractionRepulsionBehaviour.js.map +1 -0
  19. package/dist/lib/behaviour/Behaviour.d.ts +33 -0
  20. package/dist/lib/behaviour/Behaviour.js +45 -0
  21. package/dist/lib/behaviour/Behaviour.js.map +1 -0
  22. package/dist/lib/behaviour/BehaviourNames.d.ts +22 -0
  23. package/dist/lib/behaviour/BehaviourNames.js +23 -0
  24. package/dist/lib/behaviour/BehaviourNames.js.map +1 -0
  25. package/dist/lib/behaviour/CollisionBehaviour.d.ts +81 -0
  26. package/dist/lib/behaviour/CollisionBehaviour.js +136 -0
  27. package/dist/lib/behaviour/CollisionBehaviour.js.map +1 -0
  28. package/dist/lib/behaviour/ColorBehaviour.d.ts +67 -0
  29. package/dist/lib/behaviour/ColorBehaviour.js +209 -0
  30. package/dist/lib/behaviour/ColorBehaviour.js.map +1 -0
  31. package/dist/lib/behaviour/EmitDirectionBehaviour.d.ts +52 -0
  32. package/dist/lib/behaviour/EmitDirectionBehaviour.js +105 -0
  33. package/dist/lib/behaviour/EmitDirectionBehaviour.js.map +1 -0
  34. package/dist/lib/behaviour/EmitterBehaviours.d.ts +69 -0
  35. package/dist/lib/behaviour/EmitterBehaviours.js +116 -0
  36. package/dist/lib/behaviour/EmitterBehaviours.js.map +1 -0
  37. package/dist/lib/behaviour/ForceFieldsBehaviour.d.ts +53 -0
  38. package/dist/lib/behaviour/ForceFieldsBehaviour.js +80 -0
  39. package/dist/lib/behaviour/ForceFieldsBehaviour.js.map +1 -0
  40. package/dist/lib/behaviour/GroupingBehaviour.d.ts +57 -0
  41. package/dist/lib/behaviour/GroupingBehaviour.js +143 -0
  42. package/dist/lib/behaviour/GroupingBehaviour.js.map +1 -0
  43. package/dist/lib/behaviour/LifeBehaviour.d.ts +47 -0
  44. package/dist/lib/behaviour/LifeBehaviour.js +65 -0
  45. package/dist/lib/behaviour/LifeBehaviour.js.map +1 -0
  46. package/dist/lib/behaviour/LightEffectBehaviour.d.ts +59 -0
  47. package/dist/lib/behaviour/LightEffectBehaviour.js +94 -0
  48. package/dist/lib/behaviour/LightEffectBehaviour.js.map +1 -0
  49. package/dist/lib/behaviour/NoiseBasedMotionBehaviour.d.ts +28 -0
  50. package/dist/lib/behaviour/NoiseBasedMotionBehaviour.js +50 -0
  51. package/dist/lib/behaviour/NoiseBasedMotionBehaviour.js.map +1 -0
  52. package/dist/lib/behaviour/PositionBehaviour.d.ts +164 -0
  53. package/dist/lib/behaviour/PositionBehaviour.js +484 -0
  54. package/dist/lib/behaviour/PositionBehaviour.js.map +1 -0
  55. package/dist/lib/behaviour/RotationBehaviour.d.ts +59 -0
  56. package/dist/lib/behaviour/RotationBehaviour.js +100 -0
  57. package/dist/lib/behaviour/RotationBehaviour.js.map +1 -0
  58. package/dist/lib/behaviour/SizeBehaviour.d.ts +61 -0
  59. package/dist/lib/behaviour/SizeBehaviour.js +156 -0
  60. package/dist/lib/behaviour/SizeBehaviour.js.map +1 -0
  61. package/dist/lib/behaviour/SoundReactiveBehaviour.d.ts +58 -0
  62. package/dist/lib/behaviour/SoundReactiveBehaviour.js +132 -0
  63. package/dist/lib/behaviour/SoundReactiveBehaviour.js.map +1 -0
  64. package/dist/lib/behaviour/SpawnBehaviour.d.ts +89 -0
  65. package/dist/lib/behaviour/SpawnBehaviour.js +705 -0
  66. package/dist/lib/behaviour/SpawnBehaviour.js.map +1 -0
  67. package/dist/lib/behaviour/StretchBehaviour.d.ts +30 -0
  68. package/dist/lib/behaviour/StretchBehaviour.js +59 -0
  69. package/dist/lib/behaviour/StretchBehaviour.js.map +1 -0
  70. package/dist/lib/behaviour/TemperatureBehaviour.d.ts +47 -0
  71. package/dist/lib/behaviour/TemperatureBehaviour.js +64 -0
  72. package/dist/lib/behaviour/TemperatureBehaviour.js.map +1 -0
  73. package/dist/lib/behaviour/TimelineBehaviour.d.ts +73 -0
  74. package/dist/lib/behaviour/TimelineBehaviour.js +100 -0
  75. package/dist/lib/behaviour/TimelineBehaviour.js.map +1 -0
  76. package/dist/lib/behaviour/TurbulenceBehaviour.d.ts +73 -0
  77. package/dist/lib/behaviour/TurbulenceBehaviour.js +133 -0
  78. package/dist/lib/behaviour/TurbulenceBehaviour.js.map +1 -0
  79. package/dist/lib/behaviour/index.d.ts +23 -0
  80. package/dist/lib/behaviour/index.js +24 -0
  81. package/dist/lib/behaviour/index.js.map +1 -0
  82. package/dist/lib/customPixiParticlesSettingsInterface.d.ts +19 -0
  83. package/dist/lib/customPixiParticlesSettingsInterface.js +2 -0
  84. package/dist/lib/customPixiParticlesSettingsInterface.js.map +1 -0
  85. package/dist/lib/emission/AbstractEmission.d.ts +30 -0
  86. package/dist/lib/emission/AbstractEmission.js +39 -0
  87. package/dist/lib/emission/AbstractEmission.js.map +1 -0
  88. package/dist/lib/emission/EmissionTypes.d.ts +6 -0
  89. package/dist/lib/emission/EmissionTypes.js +6 -0
  90. package/dist/lib/emission/EmissionTypes.js.map +1 -0
  91. package/dist/lib/emission/RandomEmission.d.ts +44 -0
  92. package/dist/lib/emission/RandomEmission.js +66 -0
  93. package/dist/lib/emission/RandomEmission.js.map +1 -0
  94. package/dist/lib/emission/StandardEmission.d.ts +62 -0
  95. package/dist/lib/emission/StandardEmission.js +87 -0
  96. package/dist/lib/emission/StandardEmission.js.map +1 -0
  97. package/dist/lib/emission/UniformEmission.d.ts +56 -0
  98. package/dist/lib/emission/UniformEmission.js +83 -0
  99. package/dist/lib/emission/UniformEmission.js.map +1 -0
  100. package/dist/lib/emission/index.d.ts +6 -0
  101. package/dist/lib/emission/index.js +7 -0
  102. package/dist/lib/emission/index.js.map +1 -0
  103. package/dist/lib/emitter/Duration.d.ts +27 -0
  104. package/dist/lib/emitter/Duration.js +41 -0
  105. package/dist/lib/emitter/Duration.js.map +1 -0
  106. package/dist/lib/emitter/Emitter.d.ts +116 -0
  107. package/dist/lib/emitter/Emitter.js +240 -0
  108. package/dist/lib/emitter/Emitter.js.map +1 -0
  109. package/dist/lib/emitter/index.d.ts +3 -0
  110. package/dist/lib/emitter/index.js +4 -0
  111. package/dist/lib/emitter/index.js.map +1 -0
  112. package/dist/lib/index.d.ts +20 -0
  113. package/dist/lib/index.js +21 -0
  114. package/dist/lib/index.js.map +1 -0
  115. package/dist/lib/parser/BehaviourParser.d.ts +21 -0
  116. package/dist/lib/parser/BehaviourParser.js +72 -0
  117. package/dist/lib/parser/BehaviourParser.js.map +1 -0
  118. package/dist/lib/parser/CompatibilityHelper.d.ts +12 -0
  119. package/dist/lib/parser/CompatibilityHelper.js +19 -0
  120. package/dist/lib/parser/CompatibilityHelper.js.map +1 -0
  121. package/dist/lib/parser/EmitControllerParser.d.ts +27 -0
  122. package/dist/lib/parser/EmitControllerParser.js +39 -0
  123. package/dist/lib/parser/EmitControllerParser.js.map +1 -0
  124. package/dist/lib/parser/EmitterParser.d.ts +67 -0
  125. package/dist/lib/parser/EmitterParser.js +168 -0
  126. package/dist/lib/parser/EmitterParser.js.map +1 -0
  127. package/dist/lib/parser/index.d.ts +5 -0
  128. package/dist/lib/parser/index.js +6 -0
  129. package/dist/lib/parser/index.js.map +1 -0
  130. package/dist/lib/pixi/Renderer.d.ts +125 -0
  131. package/dist/lib/pixi/Renderer.js +566 -0
  132. package/dist/lib/pixi/Renderer.js.map +1 -0
  133. package/dist/lib/pixi/TestRenderer.d.ts +125 -0
  134. package/dist/lib/pixi/TestRenderer.js +560 -0
  135. package/dist/lib/pixi/TestRenderer.js.map +1 -0
  136. package/dist/lib/util/Color.d.ts +133 -0
  137. package/dist/lib/util/Color.js +173 -0
  138. package/dist/lib/util/Color.js.map +1 -0
  139. package/dist/lib/util/List.d.ts +49 -0
  140. package/dist/lib/util/List.js +87 -0
  141. package/dist/lib/util/List.js.map +1 -0
  142. package/dist/lib/util/MinMax.d.ts +34 -0
  143. package/dist/lib/util/MinMax.js +46 -0
  144. package/dist/lib/util/MinMax.js.map +1 -0
  145. package/dist/lib/util/Point.d.ts +34 -0
  146. package/dist/lib/util/Point.js +46 -0
  147. package/dist/lib/util/Point.js.map +1 -0
  148. package/dist/lib/util/Random.d.ts +24 -0
  149. package/dist/lib/util/Random.js +30 -0
  150. package/dist/lib/util/Random.js.map +1 -0
  151. package/dist/lib/util/ThereBack.d.ts +14 -0
  152. package/dist/lib/util/ThereBack.js +23 -0
  153. package/dist/lib/util/ThereBack.js.map +1 -0
  154. package/dist/lib/util/index.d.ts +5 -0
  155. package/dist/lib/util/index.js +6 -0
  156. package/dist/lib/util/index.js.map +1 -0
  157. package/dist/lib/util/maths.d.ts +10 -0
  158. package/dist/lib/util/maths.js +13 -0
  159. package/dist/lib/util/maths.js.map +1 -0
  160. package/dist/lib/util/turbulencePool.d.ts +4 -0
  161. package/dist/lib/util/turbulencePool.js +7 -0
  162. package/dist/lib/util/turbulencePool.js.map +1 -0
  163. package/package.json +1 -1
@@ -0,0 +1,125 @@
1
+ import { Emitter } from '../emitter';
2
+ import { ICustomPixiParticlesSettings } from '../customPixiParticlesSettingsInterface';
3
+ import { Container } from 'pixi.js';
4
+ /**
5
+ * Renderer is a class used to render particles in the Pixi library.
6
+ *
7
+ * @class Renderer
8
+ */
9
+ export default class TestRenderer extends Container {
10
+ blendMode: any;
11
+ emitter: Emitter;
12
+ turbulenceEmitter: Emitter;
13
+ private _paused;
14
+ private _internalPaused;
15
+ private textures;
16
+ private zeroPad;
17
+ private indexToStart;
18
+ private finishingTextureNames;
19
+ private unusedSprites;
20
+ private emitterParser;
21
+ private turbulenceParser;
22
+ private config;
23
+ private anchor;
24
+ private _model;
25
+ private _ticker;
26
+ private _visibilitychangeBinding;
27
+ /**
28
+ * Creates an instance of Renderer.
29
+ *
30
+ * @memberof Renderer
31
+ */
32
+ constructor(settings: ICustomPixiParticlesSettings);
33
+ onComplete: any;
34
+ onCompleteFN: any;
35
+ /**
36
+ * Sets the paused state of the object.
37
+ *
38
+ * @param {boolean} [isPaused=true] - The new paused state of the object. Defaults to `true`.
39
+ * @returns {void}
40
+ */
41
+ pause(isPaused?: boolean): void;
42
+ /**
43
+ * Resumes the object's operation by setting its paused state to false.
44
+ *
45
+ * @returns {void}
46
+ */
47
+ resume(): void;
48
+ /**
49
+ * Updates the transform of the ParticleContainer and updates the emitters.
50
+ */
51
+ _updateTransform(deltaTime: number): void;
52
+ /**
53
+ *
54
+ * @method updateTexture
55
+ * @description This method updates the texture of the unused sprites and children to a randomly generated texture.
56
+ */
57
+ updateTexture(): void;
58
+ /**
59
+ * This method is used to start the emitter and turbulenceEmitter if available.
60
+ * @function start
61
+ */
62
+ start(): void;
63
+ /**
64
+ * Resets the particle emitters in this class without removing existing particles and plays them.
65
+ * @function play
66
+ */
67
+ play(): void;
68
+ /**
69
+ * Immediately stops emitting particles
70
+ */
71
+ stopImmediately(): void;
72
+ /**
73
+ * Destroy particles
74
+ */
75
+ destroy(): void;
76
+ /**
77
+ * Terminates the emitter and any turbulence emitter it is associated with
78
+ */
79
+ stop(): void;
80
+ /**
81
+ * Resets the emitters to their initial state
82
+ */
83
+ resetEmitter(): void;
84
+ /**
85
+ * Sets the textures used by the emitter
86
+ * @param {string[]} textures - Array of strings containing the textures to be used by the emitter
87
+ */
88
+ setTextures(textures: string[]): void;
89
+ /**
90
+ * Updates the configuration of the emitter
91
+ * @param {any} config - Configuration object to be used to update the emitter
92
+ * @param {boolean} resetDuration - should duration be reset
93
+ */
94
+ updateConfig(config: any, resetDuration?: boolean): void;
95
+ /**
96
+ * Updates the position of the emitter
97
+ * @param {Object} position - Object containing the x and y coordinates of the new position
98
+ * @param {boolean} resetDuration - should duration be reset
99
+ */
100
+ updatePosition(position: {
101
+ x: number;
102
+ y: number;
103
+ }, resetDuration?: boolean): void;
104
+ /**
105
+ * Clears the sprite pool, the unused sprites list and the turbulence and particle pools.
106
+ */
107
+ clearPool(): void;
108
+ private getByName;
109
+ private getOrCreateSprite;
110
+ private createFrameAnimationByName;
111
+ private onCreate;
112
+ private onCreateTurbulence;
113
+ private onUpdate;
114
+ private onUpdateTurbulence;
115
+ private onFinishing;
116
+ private onRemove;
117
+ private onRemoveTurbulence;
118
+ private getRandomTexture;
119
+ private getRandomFinishingTexture;
120
+ private getRandomFrameNumber;
121
+ private paused;
122
+ private internalPause;
123
+ private getConfigIndexByName;
124
+ private buildTurbulenceConfig;
125
+ }
@@ -0,0 +1,560 @@
1
+ // tslint:disable:prefer-for-of
2
+ import engine from '../index';
3
+ import { Emitter } from '../emitter';
4
+ import BehaviourNames from '../behaviour/BehaviourNames';
5
+ import List from '../util/List';
6
+ import ParticlePool from '../ParticlePool';
7
+ import { AnimatedSprite, Assets, Container, Sprite, Texture, Ticker, utils } from 'pixi.js';
8
+ import Model from '../Model';
9
+ /**
10
+ * Renderer is a class used to render particles in the Pixi library.
11
+ *
12
+ * @class Renderer
13
+ */
14
+ export default class TestRenderer extends Container {
15
+ /**
16
+ * Creates an instance of Renderer.
17
+ *
18
+ * @memberof Renderer
19
+ */
20
+ constructor(settings) {
21
+ const { textures, emitterConfig, finishingTextures, animatedSpriteZeroPad, animatedSpriteIndexToStart, maxFPS, minFPS, tickerSpeed, } = settings;
22
+ super();
23
+ this._paused = false;
24
+ this._internalPaused = false;
25
+ this.zeroPad = 2;
26
+ this.indexToStart = 0;
27
+ this.unusedSprites = [];
28
+ this.anchor = { x: 0.5, y: 0.5 };
29
+ this._model = new Model();
30
+ this.onComplete = () => {
31
+ /**/
32
+ };
33
+ this.onCompleteFN = () => {
34
+ /**/
35
+ };
36
+ this.getByName = (name) => {
37
+ for (let i = 0; i < this.config.behaviours.length; ++i) {
38
+ if (this.config.behaviours[i].name === name) {
39
+ return this.config.behaviours[i];
40
+ }
41
+ }
42
+ return null;
43
+ };
44
+ this.config = emitterConfig;
45
+ this.textures = textures;
46
+ this.finishingTextureNames = finishingTextures;
47
+ this.zeroPad = animatedSpriteZeroPad;
48
+ this.indexToStart = animatedSpriteIndexToStart;
49
+ const turbulenceConfigIndex = this.getConfigIndexByName(BehaviourNames.TURBULENCE_BEHAVIOUR, emitterConfig);
50
+ if (turbulenceConfigIndex !== -1) {
51
+ const turbulenceConfig = emitterConfig.behaviours[turbulenceConfigIndex];
52
+ if (turbulenceConfig.enabled === true) {
53
+ this.turbulenceEmitter = new engine.Emitter(this._model);
54
+ this.turbulenceParser = this.turbulenceEmitter.getParser();
55
+ this.turbulenceParser.read(this.buildTurbulenceConfig(turbulenceConfig), this._model);
56
+ this.turbulenceEmitter.on(Emitter.CREATE, this.onCreateTurbulence, this);
57
+ this.turbulenceEmitter.on(Emitter.UPDATE, this.onUpdateTurbulence, this);
58
+ this.turbulenceEmitter.on(Emitter.REMOVE, this.onRemoveTurbulence, this);
59
+ }
60
+ }
61
+ if (typeof emitterConfig.alpha !== 'undefined') {
62
+ this.alpha = emitterConfig.alpha;
63
+ }
64
+ if (typeof emitterConfig.blendMode !== 'undefined') {
65
+ this.blendMode = emitterConfig.blendMode;
66
+ }
67
+ if (typeof emitterConfig.anchor !== 'undefined') {
68
+ this.anchor = emitterConfig.anchor;
69
+ }
70
+ this.emitter = new engine.Emitter(this._model);
71
+ this.emitterParser = this.emitter.getParser();
72
+ this.emitterParser.read(emitterConfig, this._model);
73
+ this.emitter.on(Emitter.CREATE, this.onCreate, this);
74
+ this.emitter.on(Emitter.UPDATE, this.onUpdate, this);
75
+ this.emitter.on(Emitter.FINISHING, this.onFinishing, this);
76
+ this.emitter.on(Emitter.REMOVE, this.onRemove, this);
77
+ this.onCompleteFN = () => this.onComplete();
78
+ this.emitter.on(Emitter.COMPLETE, this.onCompleteFN, this);
79
+ if (this.turbulenceEmitter && this.turbulenceEmitter.list) {
80
+ this.emitter.turbulencePool.list = this.turbulenceEmitter.list;
81
+ }
82
+ this._visibilitychangeBinding = () => this.internalPause(document.hidden);
83
+ document.addEventListener('visibilitychange', this._visibilitychangeBinding);
84
+ const ticker = new Ticker();
85
+ ticker.maxFPS = maxFPS || 60;
86
+ ticker.minFPS = minFPS || 60;
87
+ ticker.speed = tickerSpeed || 0.02;
88
+ ticker.stop();
89
+ // @ts-ignore
90
+ ticker.add(this._updateTransform, this);
91
+ ticker.start();
92
+ this._ticker = ticker;
93
+ }
94
+ /**
95
+ * Sets the paused state of the object.
96
+ *
97
+ * @param {boolean} [isPaused=true] - The new paused state of the object. Defaults to `true`.
98
+ * @returns {void}
99
+ */
100
+ pause(isPaused = true) {
101
+ this.paused(isPaused);
102
+ }
103
+ /**
104
+ * Resumes the object's operation by setting its paused state to false.
105
+ *
106
+ * @returns {void}
107
+ */
108
+ resume() {
109
+ this.paused(false);
110
+ }
111
+ /**
112
+ * Updates the transform of the ParticleContainer and updates the emitters.
113
+ */
114
+ _updateTransform(deltaTime) {
115
+ var _a;
116
+ if (this._paused)
117
+ return;
118
+ (_a = this.emitter) === null || _a === void 0 ? void 0 : _a.update(deltaTime);
119
+ if (this.turbulenceEmitter) {
120
+ this.turbulenceEmitter.update(deltaTime);
121
+ }
122
+ }
123
+ /**
124
+ *
125
+ * @method updateTexture
126
+ * @description This method updates the texture of the unused sprites and children to a randomly generated texture.
127
+ */
128
+ updateTexture() {
129
+ var _a;
130
+ for (let i = 0; i < this.unusedSprites.length; ++i) {
131
+ this.unusedSprites[i].texture = Assets.get(this.getRandomTexture());
132
+ }
133
+ for (let i = 0; i < ((_a = this.children) === null || _a === void 0 ? void 0 : _a.length); ++i) {
134
+ // @ts-ignore
135
+ this.children[i].texture = Texture.from(this.getRandomTexture());
136
+ }
137
+ }
138
+ /**
139
+ * This method is used to start the emitter and turbulenceEmitter if available.
140
+ * @function start
141
+ */
142
+ start() {
143
+ var _a;
144
+ (_a = this.emitter) === null || _a === void 0 ? void 0 : _a.resetAndPlay();
145
+ if (this.turbulenceEmitter) {
146
+ this.turbulenceEmitter.resetAndPlay();
147
+ }
148
+ }
149
+ /**
150
+ * Resets the particle emitters in this class without removing existing particles and plays them.
151
+ * @function play
152
+ */
153
+ play() {
154
+ var _a;
155
+ (_a = this.emitter) === null || _a === void 0 ? void 0 : _a.resetWithoutRemovingAndPlay();
156
+ if (this.turbulenceEmitter) {
157
+ this.turbulenceEmitter.resetWithoutRemovingAndPlay();
158
+ }
159
+ }
160
+ /**
161
+ * Immediately stops emitting particles
162
+ */
163
+ stopImmediately() {
164
+ var _a, _b, _c;
165
+ (_a = this._ticker) === null || _a === void 0 ? void 0 : _a.destroy();
166
+ this._ticker = undefined;
167
+ (_b = this.emitter) === null || _b === void 0 ? void 0 : _b.stop();
168
+ if (this.turbulenceEmitter) {
169
+ this.turbulenceEmitter.stop();
170
+ }
171
+ (_c = this.emitter) === null || _c === void 0 ? void 0 : _c.emit(Emitter.COMPLETE);
172
+ }
173
+ /**
174
+ * Destroy particles
175
+ */
176
+ destroy() {
177
+ this.stopImmediately();
178
+ super.destroy();
179
+ if (this.emitter) {
180
+ this.emitter.destroy();
181
+ this.emitter.off(Emitter.CREATE, this.onCreate, this);
182
+ this.emitter.off(Emitter.UPDATE, this.onUpdate, this);
183
+ this.emitter.off(Emitter.FINISHING, this.onFinishing, this);
184
+ this.emitter.off(Emitter.REMOVE, this.onRemove, this);
185
+ this.emitter.off(Emitter.COMPLETE, this.onCompleteFN, this);
186
+ // @ts-ignore
187
+ this.emitter = undefined;
188
+ }
189
+ // @ts-ignore
190
+ this.turbulenceEmitter = undefined;
191
+ // @ts-ignore
192
+ this.turbulenceParser = undefined;
193
+ // @ts-ignore
194
+ this.unusedSprites = undefined;
195
+ // @ts-ignore
196
+ this._model = undefined;
197
+ this.onComplete = undefined;
198
+ this.onCompleteFN = undefined;
199
+ this.config = undefined;
200
+ // @ts-ignore
201
+ this.textures = undefined;
202
+ // @ts-ignore
203
+ this.finishingTextureNames = undefined;
204
+ // @ts-ignore
205
+ this.emitterParser = undefined;
206
+ // @ts-ignore
207
+ this.textures = undefined;
208
+ document.removeEventListener('visibilitychange', this._visibilitychangeBinding);
209
+ }
210
+ /**
211
+ * Terminates the emitter and any turbulence emitter it is associated with
212
+ */
213
+ stop() {
214
+ var _a;
215
+ (_a = this.emitter) === null || _a === void 0 ? void 0 : _a.stopWithoutKilling();
216
+ if (this.turbulenceEmitter) {
217
+ this.turbulenceEmitter.stop();
218
+ }
219
+ }
220
+ /**
221
+ * Resets the emitters to their initial state
222
+ */
223
+ resetEmitter() {
224
+ var _a;
225
+ (_a = this.emitter) === null || _a === void 0 ? void 0 : _a.reset();
226
+ if (this.turbulenceEmitter) {
227
+ this.turbulenceEmitter.reset();
228
+ }
229
+ }
230
+ /**
231
+ * Sets the textures used by the emitter
232
+ * @param {string[]} textures - Array of strings containing the textures to be used by the emitter
233
+ */
234
+ setTextures(textures) {
235
+ this.textures = textures;
236
+ this.updateTexture();
237
+ }
238
+ /**
239
+ * Updates the configuration of the emitter
240
+ * @param {any} config - Configuration object to be used to update the emitter
241
+ * @param {boolean} resetDuration - should duration be reset
242
+ */
243
+ updateConfig(config, resetDuration = false) {
244
+ var _a;
245
+ (_a = this.emitterParser) === null || _a === void 0 ? void 0 : _a.update(config, this._model, resetDuration);
246
+ if (this.turbulenceEmitter) {
247
+ const turbulenceConfigIndex = this.getConfigIndexByName(BehaviourNames.TURBULENCE_BEHAVIOUR, config);
248
+ if (turbulenceConfigIndex !== -1) {
249
+ const turbulenceConfig = config.behaviours[turbulenceConfigIndex];
250
+ if (turbulenceConfig.enabled === true) {
251
+ this.turbulenceParser.update(this.buildTurbulenceConfig(turbulenceConfig), this._model, resetDuration);
252
+ }
253
+ }
254
+ }
255
+ }
256
+ /**
257
+ * Updates the position of the emitter
258
+ * @param {Object} position - Object containing the x and y coordinates of the new position
259
+ * @param {boolean} resetDuration - should duration be reset
260
+ */
261
+ updatePosition(position, resetDuration = true) {
262
+ var _a;
263
+ const behaviour = this.getByName(BehaviourNames.SPAWN_BEHAVIOUR);
264
+ behaviour.customPoints[0].position.x = position.x;
265
+ behaviour.customPoints[0].position.y = position.y;
266
+ (_a = this.emitterParser) === null || _a === void 0 ? void 0 : _a.update(this.config, this._model, resetDuration);
267
+ }
268
+ /**
269
+ * Clears the sprite pool, the unused sprites list and the turbulence and particle pools.
270
+ */
271
+ clearPool() {
272
+ this.removeChildren();
273
+ this.unusedSprites = [];
274
+ if (this.turbulenceEmitter && this.turbulenceEmitter.list) {
275
+ if (this.emitter) {
276
+ this.emitter.turbulencePool.list.reset();
277
+ this.emitter.turbulencePool.list = new List();
278
+ }
279
+ }
280
+ if (this.emitter) {
281
+ this.emitter.list.reset();
282
+ this.emitter.list = new List();
283
+ }
284
+ ParticlePool.global.reset();
285
+ }
286
+ getOrCreateSprite() {
287
+ var _a, _b, _c;
288
+ if (this.unusedSprites.length > 0) {
289
+ const sprite = this.unusedSprites.pop();
290
+ if (this.finishingTextureNames && this.finishingTextureNames.length) {
291
+ sprite.texture = Assets.get(this.getRandomTexture());
292
+ }
293
+ return sprite;
294
+ }
295
+ if ((_a = this.emitter) === null || _a === void 0 ? void 0 : _a.animatedSprite) {
296
+ const textures = this.createFrameAnimationByName(this.getRandomTexture());
297
+ if (textures.length) {
298
+ const animation = new AnimatedSprite(textures);
299
+ animation.anchor.set(this.anchor.x, this.anchor.y);
300
+ // @ts-ignore
301
+ animation.loop = (_b = this.emitter) === null || _b === void 0 ? void 0 : _b.animatedSprite.loop;
302
+ // @ts-ignore
303
+ animation.animationSpeed = (_c = this.emitter) === null || _c === void 0 ? void 0 : _c.animatedSprite.frameRate;
304
+ return this.addChild(animation);
305
+ }
306
+ }
307
+ const sprite = new Sprite(Texture.from(this.getRandomTexture()));
308
+ sprite.anchor.set(this.anchor.x, this.anchor.y);
309
+ return this.addChild(sprite);
310
+ }
311
+ createFrameAnimationByName(prefix, imageFileExtension = 'png') {
312
+ const zeroPad = this.zeroPad;
313
+ const textures = [];
314
+ let frame = '';
315
+ let indexFrame = this.indexToStart;
316
+ let padding = 0;
317
+ let texture;
318
+ do {
319
+ frame = indexFrame.toString();
320
+ padding = zeroPad - frame.length;
321
+ if (padding > 0) {
322
+ frame = '0'.repeat(padding) + frame;
323
+ }
324
+ try {
325
+ const fileName = `${prefix}${frame}.${imageFileExtension}`;
326
+ const file = utils.TextureCache[fileName];
327
+ if (file) {
328
+ texture = Assets.get(fileName);
329
+ textures.push(texture);
330
+ indexFrame += 1;
331
+ }
332
+ else {
333
+ texture = null;
334
+ }
335
+ }
336
+ catch (e) {
337
+ texture = null;
338
+ }
339
+ } while (texture);
340
+ return textures;
341
+ }
342
+ onCreate(particle) {
343
+ var _a;
344
+ const sprite = this.getOrCreateSprite();
345
+ sprite.visible = true;
346
+ sprite.alpha = 1;
347
+ if (this.blendMode) {
348
+ sprite.blendMode = this.blendMode;
349
+ }
350
+ if (sprite instanceof AnimatedSprite) {
351
+ if ((_a = this.emitter) === null || _a === void 0 ? void 0 : _a.animatedSprite.randomFrameStart) {
352
+ const textures = this.createFrameAnimationByName(this.getRandomTexture());
353
+ sprite.gotoAndPlay(this.getRandomFrameNumber(textures.length));
354
+ }
355
+ else {
356
+ sprite.play();
357
+ }
358
+ }
359
+ particle.sprite = sprite;
360
+ }
361
+ onCreateTurbulence(particle) {
362
+ let sprite;
363
+ if (particle.showVortices) {
364
+ sprite = new Sprite(Texture.from('vortex.png'));
365
+ }
366
+ else {
367
+ sprite = new Sprite();
368
+ }
369
+ sprite.anchor.set(this.anchor.x, this.anchor.y);
370
+ this.addChild(sprite);
371
+ sprite.visible = false;
372
+ sprite.alpha = 0;
373
+ particle.sprite = sprite;
374
+ if (particle.showVortices && sprite) {
375
+ sprite.visible = true;
376
+ sprite.alpha = 1;
377
+ }
378
+ }
379
+ onUpdate(particle) {
380
+ const sprite = particle.sprite;
381
+ sprite.x = particle.x;
382
+ sprite.y = particle.y;
383
+ sprite.scale.x = particle.size.x;
384
+ sprite.scale.y = particle.size.y;
385
+ sprite.tint = particle.color.hex;
386
+ sprite.alpha = particle.color.alpha;
387
+ sprite.rotation = particle.rotation;
388
+ }
389
+ onUpdateTurbulence(particle) {
390
+ const sprite = particle.sprite;
391
+ sprite.x = particle.x;
392
+ sprite.y = particle.y;
393
+ if (particle.showVortices && sprite) {
394
+ sprite.scale.x = particle.size.x;
395
+ sprite.scale.y = particle.size.y;
396
+ sprite.tint = particle.color.hex;
397
+ sprite.alpha = particle.color.alpha;
398
+ sprite.rotation = particle.rotation;
399
+ }
400
+ }
401
+ onFinishing(particle) {
402
+ if (!this.finishingTextureNames || !this.finishingTextureNames.length)
403
+ return;
404
+ const sprite = particle.sprite;
405
+ if (particle.finishingTexture <= this.finishingTextureNames.length - 1) {
406
+ sprite.texture = Texture.from(this.getRandomFinishingTexture());
407
+ particle.finishingTexture++;
408
+ }
409
+ }
410
+ onRemove(particle) {
411
+ const sprite = particle.sprite;
412
+ if (!particle.showVortices && sprite) {
413
+ sprite.visible = false;
414
+ sprite.alpha = 0;
415
+ }
416
+ particle.finishingTexture = 0;
417
+ this.unusedSprites.push(sprite);
418
+ if (sprite instanceof AnimatedSprite) {
419
+ sprite.stop();
420
+ }
421
+ }
422
+ onRemoveTurbulence(particle) {
423
+ const sprite = particle.sprite;
424
+ if (!particle.showVortices && sprite) {
425
+ sprite.visible = false;
426
+ sprite.alpha = 0;
427
+ }
428
+ this.removeChild(sprite);
429
+ delete particle.sprite;
430
+ }
431
+ getRandomTexture() {
432
+ return this.textures[Math.floor(Math.random() * this.textures.length)];
433
+ }
434
+ getRandomFinishingTexture() {
435
+ return this.finishingTextureNames[Math.floor(Math.random() * this.finishingTextureNames.length)];
436
+ }
437
+ getRandomFrameNumber(textures) {
438
+ return Math.floor(Math.random() * textures);
439
+ }
440
+ paused(paused) {
441
+ var _a, _b, _c, _d;
442
+ if (paused === this._paused)
443
+ return;
444
+ this._paused = paused;
445
+ if (paused) {
446
+ (_a = this._ticker) === null || _a === void 0 ? void 0 : _a.stop();
447
+ (_b = this.emitter) === null || _b === void 0 ? void 0 : _b.pause();
448
+ }
449
+ else {
450
+ (_c = this._ticker) === null || _c === void 0 ? void 0 : _c.start();
451
+ (_d = this.emitter) === null || _d === void 0 ? void 0 : _d.resume();
452
+ }
453
+ }
454
+ internalPause(paused) {
455
+ if (this._paused)
456
+ return;
457
+ if (paused === this._internalPaused)
458
+ return;
459
+ this._internalPaused = paused;
460
+ }
461
+ getConfigIndexByName(name, config) {
462
+ let index = -1;
463
+ config.behaviours.forEach((behaviour, i) => {
464
+ if (behaviour.name === name) {
465
+ index = i;
466
+ }
467
+ });
468
+ return index;
469
+ }
470
+ buildTurbulenceConfig(turbulenceConfig) {
471
+ return {
472
+ behaviours: [
473
+ {
474
+ enabled: true,
475
+ priority: 10000,
476
+ maxLifeTime: turbulenceConfig.maxLifeTime || 2,
477
+ timeVariance: turbulenceConfig.maxLifeTimeVariance || 0,
478
+ name: 'LifeBehaviour',
479
+ },
480
+ {
481
+ priority: 100,
482
+ customPoints: [
483
+ {
484
+ spawnType: 'Ring',
485
+ radius: 0,
486
+ position: {
487
+ x: turbulenceConfig.position.x || 0,
488
+ y: turbulenceConfig.position.y || 0,
489
+ },
490
+ positionVariance: {
491
+ x: turbulenceConfig.positionVariance.x || 0,
492
+ y: turbulenceConfig.positionVariance.y || 0,
493
+ },
494
+ },
495
+ ],
496
+ name: 'SpawnBehaviour',
497
+ },
498
+ {
499
+ enabled: true,
500
+ priority: 100,
501
+ velocity: {
502
+ x: turbulenceConfig.velocity.x || 0,
503
+ y: turbulenceConfig.velocity.y || 0,
504
+ },
505
+ velocityVariance: {
506
+ x: turbulenceConfig.velocityVariance.x || 0,
507
+ y: turbulenceConfig.velocityVariance.y || 0,
508
+ },
509
+ acceleration: {
510
+ x: turbulenceConfig.acceleration.x || 0,
511
+ y: turbulenceConfig.acceleration.y || 0,
512
+ },
513
+ accelerationVariance: {
514
+ x: turbulenceConfig.accelerationVariance.x || 0,
515
+ y: turbulenceConfig.accelerationVariance.y || 0,
516
+ },
517
+ name: 'PositionBehaviour',
518
+ },
519
+ {
520
+ enabled: true,
521
+ priority: 0,
522
+ sizeStart: {
523
+ x: turbulenceConfig.sizeStart.x || 1,
524
+ y: turbulenceConfig.sizeStart.y || 1,
525
+ },
526
+ sizeEnd: {
527
+ x: turbulenceConfig.sizeEnd.x || 1,
528
+ y: turbulenceConfig.sizeEnd.y || 1,
529
+ },
530
+ startVariance: turbulenceConfig.startVariance || 0,
531
+ endVariance: turbulenceConfig.endVariance || 0,
532
+ name: 'SizeBehaviour',
533
+ },
534
+ {
535
+ enabled: true,
536
+ priority: 0,
537
+ rotation: 12,
538
+ variance: 0,
539
+ name: 'RotationBehaviour',
540
+ },
541
+ {
542
+ enabled: true,
543
+ priority: 0,
544
+ showVortices: turbulenceConfig.showVortices || false,
545
+ turbulence: true,
546
+ name: 'TurbulenceBehaviour',
547
+ },
548
+ ],
549
+ emitController: {
550
+ _maxParticles: 0,
551
+ _maxLife: 1,
552
+ _emitPerSecond: turbulenceConfig.emitPerSecond || 2,
553
+ _frames: 0,
554
+ name: 'UniformEmission',
555
+ },
556
+ duration: turbulenceConfig.duration || -1,
557
+ };
558
+ }
559
+ }
560
+ //# sourceMappingURL=TestRenderer.js.map