-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
EmitterOp.js
921 lines (814 loc) · 27.6 KB
/
EmitterOp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2024 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Between = require('../../math/Between');
var Clamp = require('../../math/Clamp');
var Class = require('../../utils/Class');
var FloatBetween = require('../../math/FloatBetween');
var GetEaseFunction = require('../../tweens/builders/GetEaseFunction');
var GetFastValue = require('../../utils/object/GetFastValue');
var GetInterpolationFunction = require('../../tweens/builders/GetInterpolationFunction');
var SnapTo = require('../../math/snap/SnapTo');
var Wrap = require('../../math/Wrap');
/**
* @classdesc
* This class is responsible for taking control over a single property
* in the Particle class and managing its emission and updating functions.
*
* Particles properties such as `x`, `y`, `scaleX`, `lifespan` and others all use
* EmitterOp instances to manage them, as they can be given in a variety of
* formats: from simple values, to functions, to dynamic callbacks.
*
* See the `ParticleEmitter` class for more details on emitter op configuration.
*
* @class EmitterOp
* @memberof Phaser.GameObjects.Particles
* @constructor
* @since 3.0.0
*
* @param {string} key - The name of the property.
* @param {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType|Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType} defaultValue - The default value of the property.
* @param {boolean} [emitOnly=false] - Whether the property can only be modified when a Particle is emitted.
*/
var EmitterOp = new Class({
initialize:
function EmitterOp (key, defaultValue, emitOnly)
{
if (emitOnly === undefined) { emitOnly = false; }
/**
* The name of this property.
*
* @name Phaser.GameObjects.Particles.EmitterOp#propertyKey
* @type {string}
* @since 3.0.0
*/
this.propertyKey = key;
/**
* The current value of this property.
*
* This can be a simple value, an array, a function or an onEmit
* configuration object.
*
* @name Phaser.GameObjects.Particles.EmitterOp#propertyValue
* @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType|Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType}
* @since 3.0.0
*/
this.propertyValue = defaultValue;
/**
* The default value of this property.
*
* This can be a simple value, an array, a function or an onEmit
* configuration object.
*
* @name Phaser.GameObjects.Particles.EmitterOp#defaultValue
* @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType|Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType}
* @since 3.0.0
*/
this.defaultValue = defaultValue;
/**
* The number of steps for stepped easing between {@link Phaser.GameObjects.Particles.EmitterOp#start} and
* {@link Phaser.GameObjects.Particles.EmitterOp#end} values, per emit.
*
* @name Phaser.GameObjects.Particles.EmitterOp#steps
* @type {number}
* @default 0
* @since 3.0.0
*/
this.steps = 0;
/**
* The step counter for stepped easing, per emit.
*
* @name Phaser.GameObjects.Particles.EmitterOp#counter
* @type {number}
* @default 0
* @since 3.0.0
*/
this.counter = 0;
/**
* When the step counter reaches it's maximum, should it then
* yoyo back to the start again, or flip over to it?
*
* @name Phaser.GameObjects.Particles.EmitterOp#yoyo
* @type {boolean}
* @default false
* @since 3.60.0
*/
this.yoyo = false;
/**
* The counter direction. 0 for up and 1 for down.
*
* @name Phaser.GameObjects.Particles.EmitterOp#direction
* @type {number}
* @default 0
* @since 3.60.0
*/
this.direction = 0;
/**
* The start value for this property to ease between.
*
* If an interpolation this holds a reference to the number data array.
*
* @name Phaser.GameObjects.Particles.EmitterOp#start
* @type {number|number[]}
* @default 0
* @since 3.0.0
*/
this.start = 0;
/**
* The most recently calculated value. Updated every time an
* emission or update method is called. Treat as read-only.
*
* @name Phaser.GameObjects.Particles.EmitterOp#current
* @type {number}
* @since 3.60.0
*/
this.current = 0;
/**
* The end value for this property to ease between.
*
* @name Phaser.GameObjects.Particles.EmitterOp#end
* @type {number}
* @default 0
* @since 3.0.0
*/
this.end = 0;
/**
* The easing function to use for updating this property, if any.
*
* @name Phaser.GameObjects.Particles.EmitterOp#ease
* @type {?function}
* @since 3.0.0
*/
this.ease = null;
/**
* The interpolation function to use for updating this property, if any.
*
* @name Phaser.GameObjects.Particles.EmitterOp#interpolation
* @type {?function}
* @since 3.60.0
*/
this.interpolation = null;
/**
* Whether this property can only be modified when a Particle is emitted.
*
* Set to `true` to allow only {@link Phaser.GameObjects.Particles.EmitterOp#onEmit} callbacks to be set and
* affect this property.
*
* Set to `false` to allow both {@link Phaser.GameObjects.Particles.EmitterOp#onEmit} and
* {@link Phaser.GameObjects.Particles.EmitterOp#onUpdate} callbacks to be set and affect this property.
*
* @name Phaser.GameObjects.Particles.EmitterOp#emitOnly
* @type {boolean}
* @since 3.0.0
*/
this.emitOnly = emitOnly;
/**
* The callback to run for Particles when they are emitted from the Particle Emitter.
*
* @name Phaser.GameObjects.Particles.EmitterOp#onEmit
* @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitCallback}
* @since 3.0.0
*/
this.onEmit = this.defaultEmit;
/**
* The callback to run for Particles when they are updated.
*
* @name Phaser.GameObjects.Particles.EmitterOp#onUpdate
* @type {Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateCallback}
* @since 3.0.0
*/
this.onUpdate = this.defaultUpdate;
/**
* Set to `false` to disable this EmitterOp.
*
* @name Phaser.GameObjects.Particles.EmitterOp#active
* @type {boolean}
* @since 3.60.0
*/
this.active = true;
/**
* The onEmit method type of this EmitterOp.
*
* Set as part of `setMethod` and cached here to avoid
* re-setting when only the value changes.
*
* @name Phaser.GameObjects.Particles.EmitterOp#method
* @type {number}
* @since 3.60.0
*/
this.method = 0;
/**
* The callback to run for Particles when they are emitted from the Particle Emitter.
* This is set during `setMethods` and used by `proxyEmit`.
*
* @name Phaser.GameObjects.Particles.EmitterOp#_onEmit
* @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitCallback}
* @private
* @since 3.60.0
*/
this._onEmit;
/**
* The callback to run for Particles when they are updated.
* This is set during `setMethods` and used by `proxyUpdate`.
*
* @name Phaser.GameObjects.Particles.EmitterOp#_onUpdate
* @type {Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateCallback}
* @private
* @since 3.60.0
*/
this._onUpdate;
},
/**
* Load the property from a Particle Emitter configuration object.
*
* Optionally accepts a new property key to use, replacing the current one.
*
* @method Phaser.GameObjects.Particles.EmitterOp#loadConfig
* @since 3.0.0
*
* @param {Phaser.Types.GameObjects.Particles.ParticleEmitterConfig} [config] - Settings for the Particle Emitter that owns this property.
* @param {string} [newKey] - The new key to use for this property, if any.
*/
loadConfig: function (config, newKey)
{
if (config === undefined)
{
config = {};
}
if (newKey)
{
this.propertyKey = newKey;
}
this.propertyValue = GetFastValue(
config,
this.propertyKey,
this.defaultValue
);
this.method = this.getMethod();
this.setMethods();
if (this.emitOnly)
{
// Reset it back again
this.onUpdate = this.defaultUpdate;
}
},
/**
* Build a JSON representation of this Particle Emitter property.
*
* @method Phaser.GameObjects.Particles.EmitterOp#toJSON
* @since 3.0.0
*
* @return {object} A JSON representation of this Particle Emitter property.
*/
toJSON: function ()
{
return JSON.stringify(this.propertyValue);
},
/**
* Change the current value of the property and update its callback methods.
*
* @method Phaser.GameObjects.Particles.EmitterOp#onChange
* @since 3.0.0
*
* @param {number} value - The new numeric value of this property.
*
* @return {this} This Emitter Op object.
*/
onChange: function (value)
{
var current;
switch (this.method)
{
// Number
// Custom Callback (onEmit only)
// Custom onEmit and/or onUpdate callbacks
case 1:
case 3:
case 8:
current = value;
break;
// Random Array
case 2:
if (this.propertyValue.indexOf(value) >= 0)
{
current = value;
}
break;
// Stepped start/end
case 4:
var step = (this.end - this.start) / this.steps;
current = SnapTo(value, step);
this.counter = current;
break;
// Eased start/end
// min/max (random float or int)
// Random object (random integer)
case 5:
case 6:
case 7:
current = Clamp(value, this.start, this.end);
break;
// Interpolation
case 9:
current = this.start[0];
break;
}
this.current = current;
return this;
},
/**
* Checks the type of `EmitterOp.propertyValue` to determine which
* method is required in order to return values from this op function.
*
* @method Phaser.GameObjects.Particles.EmitterOp#getMethod
* @since 3.60.0
*
* @return {number} A number between 0 and 9 which should be passed to `setMethods`.
*/
getMethod: function ()
{
var value = this.propertyValue;
// `moveToX` and `moveToY` are null by default
if (value === null)
{
return 0;
}
var t = typeof value;
if (t === 'number')
{
// Number
return 1;
}
else if (Array.isArray(value))
{
// Random Array
return 2;
}
else if (t === 'function')
{
// Custom Callback
return 3;
}
else if (t === 'object')
{
if (this.hasBoth(value, 'start', 'end'))
{
if (this.has(value, 'steps'))
{
// Stepped start/end
return 4;
}
else
{
// Eased start/end
return 5;
}
}
else if (this.hasBoth(value, 'min', 'max'))
{
// min/max
return 6;
}
else if (this.has(value, 'random'))
{
// Random object
return 7;
}
else if (this.hasEither(value, 'onEmit', 'onUpdate'))
{
// Custom onEmit onUpdate
return 8;
}
else if (this.hasEither(value, 'values', 'interpolation'))
{
// Interpolation
return 9;
}
}
return 0;
},
/**
* Update the {@link Phaser.GameObjects.Particles.EmitterOp#onEmit} and
* {@link Phaser.GameObjects.Particles.EmitterOp#onUpdate} callbacks based on the method returned
* from `getMethod`. The method is stored in the `EmitterOp.method` property
* and is a number between 0 and 9 inclusively.
*
* @method Phaser.GameObjects.Particles.EmitterOp#setMethods
* @since 3.0.0
*
* @return {this} This Emitter Op object.
*/
setMethods: function ()
{
var value = this.propertyValue;
var current = value;
var onEmit = this.defaultEmit;
var onUpdate = this.defaultUpdate;
switch (this.method)
{
// Number
case 1:
onEmit = this.staticValueEmit;
break;
// Random Array
case 2:
onEmit = this.randomStaticValueEmit;
current = value[0];
break;
// Custom Callback (onEmit only)
case 3:
this._onEmit = value;
onEmit = this.proxyEmit;
break;
// Stepped start/end
case 4:
this.start = value.start;
this.end = value.end;
this.steps = value.steps;
this.counter = this.start;
this.yoyo = this.has(value, 'yoyo') ? value.yoyo : false;
this.direction = 0;
onEmit = this.steppedEmit;
current = this.start;
break;
// Eased start/end
case 5:
this.start = value.start;
this.end = value.end;
var easeType = this.has(value, 'ease') ? value.ease : 'Linear';
this.ease = GetEaseFunction(easeType, value.easeParams);
onEmit = (this.has(value, 'random') && value.random) ? this.randomRangedValueEmit : this.easedValueEmit;
onUpdate = this.easeValueUpdate;
current = this.start;
break;
// min/max (random float or int)
case 6:
this.start = value.min;
this.end = value.max;
onEmit = (this.has(value, 'int') && value.int) ? this.randomRangedIntEmit : this.randomRangedValueEmit;
current = this.start;
break;
// Random object (random integer)
case 7:
var rnd = value.random;
if (Array.isArray(rnd))
{
this.start = rnd[0];
this.end = rnd[1];
}
onEmit = this.randomRangedIntEmit;
current = this.start;
break;
// Custom onEmit and/or onUpdate callbacks
case 8:
this._onEmit = (this.has(value, 'onEmit')) ? value.onEmit : this.defaultEmit;
this._onUpdate = (this.has(value, 'onUpdate')) ? value.onUpdate : this.defaultUpdate;
onEmit = this.proxyEmit;
onUpdate = this.proxyUpdate;
break;
// Interpolation
case 9:
this.start = value.values;
var easeTypeI = this.has(value, 'ease') ? value.ease : 'Linear';
this.ease = GetEaseFunction(easeTypeI, value.easeParams);
this.interpolation = GetInterpolationFunction(value.interpolation);
onEmit = this.easedValueEmit;
onUpdate = this.easeValueUpdate;
current = this.start[0];
break;
}
this.onEmit = onEmit;
this.onUpdate = onUpdate;
this.current = current;
return this;
},
/**
* Check whether an object has the given property.
*
* @method Phaser.GameObjects.Particles.EmitterOp#has
* @since 3.0.0
*
* @param {object} object - The object to check.
* @param {string} key - The key of the property to look for in the object.
*
* @return {boolean} `true` if the property exists in the object, `false` otherwise.
*/
has: function (object, key)
{
return object.hasOwnProperty(key);
},
/**
* Check whether an object has both of the given properties.
*
* @method Phaser.GameObjects.Particles.EmitterOp#hasBoth
* @since 3.0.0
*
* @param {object} object - The object to check.
* @param {string} key1 - The key of the first property to check the object for.
* @param {string} key2 - The key of the second property to check the object for.
*
* @return {boolean} `true` if both properties exist in the object, `false` otherwise.
*/
hasBoth: function (object, key1, key2)
{
return object.hasOwnProperty(key1) && object.hasOwnProperty(key2);
},
/**
* Check whether an object has at least one of the given properties.
*
* @method Phaser.GameObjects.Particles.EmitterOp#hasEither
* @since 3.0.0
*
* @param {object} object - The object to check.
* @param {string} key1 - The key of the first property to check the object for.
* @param {string} key2 - The key of the second property to check the object for.
*
* @return {boolean} `true` if at least one of the properties exists in the object, `false` if neither exist.
*/
hasEither: function (object, key1, key2)
{
return object.hasOwnProperty(key1) || object.hasOwnProperty(key2);
},
/**
* The returned value sets what the property will be at the START of the particles life, on emit.
*
* @method Phaser.GameObjects.Particles.EmitterOp#defaultEmit
* @since 3.0.0
*
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
* @param {string} key - The name of the property.
* @param {number} [value] - The current value of the property.
*
* @return {number} The new value of the property.
*/
defaultEmit: function (particle, key, value)
{
return value;
},
/**
* The returned value updates the property for the duration of the particles life.
*
* @method Phaser.GameObjects.Particles.EmitterOp#defaultUpdate
* @since 3.0.0
*
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
* @param {string} key - The name of the property.
* @param {number} t - The current normalized lifetime of the particle, between 0 (birth) and 1 (death).
* @param {number} value - The current value of the property.
*
* @return {number} The new value of the property.
*/
defaultUpdate: function (particle, key, t, value)
{
return value;
},
/**
* The returned value sets what the property will be at the START of the particles life, on emit.
*
* This method is only used when you have provided a custom emit callback.
*
* @method Phaser.GameObjects.Particles.EmitterOp#proxyEmit
* @since 3.60.0
*
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
* @param {string} key - The name of the property.
* @param {number} [value] - The current value of the property.
*
* @return {number} The new value of the property.
*/
proxyEmit: function (particle, key, value)
{
var result = this._onEmit(particle, key, value);
this.current = result;
return result;
},
/**
* The returned value updates the property for the duration of the particles life.
*
* This method is only used when you have provided a custom update callback.
*
* @method Phaser.GameObjects.Particles.EmitterOp#proxyUpdate
* @since 3.60.0
*
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
* @param {string} key - The name of the property.
* @param {number} t - The current normalized lifetime of the particle, between 0 (birth) and 1 (death).
* @param {number} value - The current value of the property.
*
* @return {number} The new value of the property.
*/
proxyUpdate: function (particle, key, t, value)
{
var result = this._onUpdate(particle, key, t, value);
this.current = result;
return result;
},
/**
* An `onEmit` callback that returns the current value of the property.
*
* @method Phaser.GameObjects.Particles.EmitterOp#staticValueEmit
* @since 3.0.0
*
* @return {number} The current value of the property.
*/
staticValueEmit: function ()
{
return this.current;
},
/**
* An `onUpdate` callback that returns the current value of the property.
*
* @method Phaser.GameObjects.Particles.EmitterOp#staticValueUpdate
* @since 3.0.0
*
* @return {number} The current value of the property.
*/
staticValueUpdate: function ()
{
return this.current;
},
/**
* An `onEmit` callback that returns a random value from the current value array.
*
* @method Phaser.GameObjects.Particles.EmitterOp#randomStaticValueEmit
* @since 3.0.0
*
* @return {number} The new value of the property.
*/
randomStaticValueEmit: function ()
{
var randomIndex = Math.floor(Math.random() * this.propertyValue.length);
this.current = this.propertyValue[randomIndex];
return this.current;
},
/**
* An `onEmit` callback that returns a value between the {@link Phaser.GameObjects.Particles.EmitterOp#start} and
* {@link Phaser.GameObjects.Particles.EmitterOp#end} range.
*
* @method Phaser.GameObjects.Particles.EmitterOp#randomRangedValueEmit
* @since 3.0.0
*
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
* @param {string} key - The key of the property.
*
* @return {number} The new value of the property.
*/
randomRangedValueEmit: function (particle, key)
{
var value = FloatBetween(this.start, this.end);
if (particle && particle.data[key])
{
particle.data[key].min = value;
particle.data[key].max = this.end;
}
this.current = value;
return value;
},
/**
* An `onEmit` callback that returns a value between the {@link Phaser.GameObjects.Particles.EmitterOp#start} and
* {@link Phaser.GameObjects.Particles.EmitterOp#end} range.
*
* @method Phaser.GameObjects.Particles.EmitterOp#randomRangedIntEmit
* @since 3.60.0
*
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
* @param {string} key - The key of the property.
*
* @return {number} The new value of the property.
*/
randomRangedIntEmit: function (particle, key)
{
var value = Between(this.start, this.end);
if (particle && particle.data[key])
{
particle.data[key].min = value;
particle.data[key].max = this.end;
}
this.current = value;
return value;
},
/**
* An `onEmit` callback that returns a stepped value between the
* {@link Phaser.GameObjects.Particles.EmitterOp#start} and {@link Phaser.GameObjects.Particles.EmitterOp#end}
* range.
*
* @method Phaser.GameObjects.Particles.EmitterOp#steppedEmit
* @since 3.0.0
*
* @return {number} The new value of the property.
*/
steppedEmit: function ()
{
var current = this.counter;
var next = current;
var step = (this.end - this.start) / this.steps;
if (this.yoyo)
{
var over;
if (this.direction === 0)
{
// Add step to the current value
next += step;
if (next >= this.end)
{
over = next - this.end;
next = this.end - over;
this.direction = 1;
}
}
else
{
// Down
next -= step;
if (next <= this.start)
{
over = this.start - next;
next = this.start + over;
this.direction = 0;
}
}
this.counter = next;
}
else
{
this.counter = Wrap(next + step, this.start, this.end);
}
this.current = current;
return current;
},
/**
* An `onEmit` callback for an eased property.
*
* It prepares the particle for easing by {@link Phaser.GameObjects.Particles.EmitterOp#easeValueUpdate}.
*
* @method Phaser.GameObjects.Particles.EmitterOp#easedValueEmit
* @since 3.0.0
*
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
* @param {string} key - The name of the property.
*
* @return {number} {@link Phaser.GameObjects.Particles.EmitterOp#start}, as the new value of the property.
*/
easedValueEmit: function (particle, key)
{
if (particle && particle.data[key])
{
var data = particle.data[key];
data.min = this.start;
data.max = this.end;
}
this.current = this.start;
return this.start;
},
/**
* An `onUpdate` callback that returns an eased value between the
* {@link Phaser.GameObjects.Particles.EmitterOp#start} and {@link Phaser.GameObjects.Particles.EmitterOp#end}
* range.
*
* @method Phaser.GameObjects.Particles.EmitterOp#easeValueUpdate
* @since 3.0.0
*
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
* @param {string} key - The name of the property.
* @param {number} t - The current normalized lifetime of the particle, between 0 (birth) and 1 (death).
*
* @return {number} The new value of the property.
*/
easeValueUpdate: function (particle, key, t)
{
var data = particle.data[key];
var current;
var v = this.ease(t);
if (this.interpolation)
{
current = this.interpolation(this.start, v);
}
else
{
current = (data.max - data.min) * v + data.min;
}
this.current = current;
return current;
},
/**
* Destroys this EmitterOp instance and all of its references.
*
* Called automatically when the ParticleEmitter that owns this
* EmitterOp is destroyed.
*
* @method Phaser.GameObjects.Particles.EmitterOp#destroy
* @since 3.60.0
*/
destroy: function ()
{
this.propertyValue = null;
this.defaultValue = null;
this.ease = null;
this.interpolation = null;
this._onEmit = null;
this._onUpdate = null;
}
});
module.exports = EmitterOp;