@@ -3,6 +3,7 @@ import {GoldenSun} from "GoldenSun";
3
3
import { GAME_HEIGHT , GAME_WIDTH } from "./magic_numbers" ;
4
4
import { elements , element_colors_in_battle , hex2rgb } from "./utils" ;
5
5
import * as _ from "lodash" ;
6
+ import { EventValue } from "game_events/GameEvent" ;
6
7
7
8
export type AdvParticleValue =
8
9
| number
@@ -87,6 +88,8 @@ export type Emitter = {
87
88
step : number ;
88
89
visible : boolean ;
89
90
} ;
91
+ hue_angle ?: number ;
92
+ random_animation_start ?: boolean ;
90
93
particles_display_blend_mode ?: string ;
91
94
render_white_core ?: boolean ;
92
95
core_custom_color ?: string ;
@@ -123,6 +126,13 @@ export type Emitter = {
123
126
frame_rate : number ;
124
127
loop : boolean ;
125
128
} ;
129
+ tween_emitter ?: {
130
+ duration : number ;
131
+ x ?: number | EventValue ;
132
+ y ?: number | EventValue ;
133
+ easing ?: string ;
134
+ incremental ?: boolean ;
135
+ } ;
126
136
} ;
127
137
128
138
export type ParticlesInfo = {
@@ -154,10 +164,10 @@ export class ParticlesWrapper {
154
164
} ,
155
165
element ?: elements ,
156
166
xy_pos_getter ?: (
157
- x : number | string ,
158
- y : number | string ,
159
- shift_x : number ,
160
- shift_y : number
167
+ x : number | string | EventValue ,
168
+ y : number | string | EventValue ,
169
+ shift_x : number | EventValue ,
170
+ shift_y : number | EventValue
161
171
) => { x : number ; y : number }
162
172
) {
163
173
const promises : Promise < void > [ ] = [ ] ;
@@ -317,7 +327,59 @@ export class ParticlesWrapper {
317
327
emitter_info . shift_x ,
318
328
emitter_info . shift_y
319
329
) ;
320
- emitter . emit ( emitter_info . emitter_data_key , x , y , {
330
+ if (
331
+ emitter_info . hue_angle !== undefined ||
332
+ emitter_info . random_animation_start ||
333
+ adv_particles_seq . particles_callback ||
334
+ emitter_info . animation !== undefined
335
+ ) {
336
+ emitter . onEmit = new Phaser . Signal ( ) ;
337
+ emitter . onEmit . add (
338
+ ( emitter : Phaser . ParticleStorm . Emitter , particle : Phaser . ParticleStorm . Particle ) => {
339
+ if ( emitter_info . hue_angle !== undefined ) {
340
+ if ( ! particle . sprite . filters ) {
341
+ const hue_filter = this . game . add . filter ( "Hue" ) as Phaser . Filter . Hue ;
342
+ particle . sprite . filters = [ hue_filter ] ;
343
+ hue_filter . angle = emitter_info . hue_angle ;
344
+ }
345
+ }
346
+ if ( emitter_info . random_animation_start ) {
347
+ if ( particle . sprite . animations . currentAnim ) {
348
+ particle . sprite . frameName = _ . sample (
349
+ Object . keys ( particle . sprite . animations . currentAnim . _frameData . _frameNames )
350
+ ) ;
351
+ }
352
+ }
353
+ if ( adv_particles_seq . particles_callback ) {
354
+ adv_particles_seq . particles_callback ( particle ) ;
355
+ }
356
+ if ( emitter_info . animation !== undefined ) {
357
+ if (
358
+ ! particle . sprite . animations . currentAnim ||
359
+ ! particle . sprite . animations . currentAnim . isPlaying
360
+ ) {
361
+ const particle_key = adv_particles_seq . data [ emitter_info . emitter_data_key ]
362
+ . image as string ;
363
+ const particle_sprite_base = this . data . info . misc_sprite_base_list [ particle_key ] ;
364
+ const anim_key = particle_sprite_base . getAnimationKey (
365
+ particle_key ,
366
+ emitter_info . animation . animation_key
367
+ ) ;
368
+ particle_sprite_base . setAnimation ( particle . sprite , particle_key ) ;
369
+ particle . sprite . animations . play (
370
+ anim_key ,
371
+ emitter_info . animation . frame_rate ,
372
+ emitter_info . animation . loop
373
+ ) ;
374
+ }
375
+ }
376
+ }
377
+ ) ;
378
+ }
379
+ const pos = { x : x , y : y } ;
380
+ const get_x = ( ) => pos . x ;
381
+ const get_y = ( ) => pos . y ;
382
+ emitter . emit ( emitter_info . emitter_data_key , get_x , get_y , {
321
383
...( emitter_info . total !== undefined && { total : emitter_info . total } ) ,
322
384
...( emitter_info . repeat !== undefined && { repeat : emitter_info . repeat } ) ,
323
385
...( emitter_info . frequency !== undefined && { frequency : emitter_info . frequency } ) ,
@@ -330,31 +392,32 @@ export class ParticlesWrapper {
330
392
...( emitter_info . radiate !== undefined && { radiate : emitter_info . radiate } ) ,
331
393
...( emitter_info . radiateFrom !== undefined && { radiateFrom : emitter_info . radiateFrom } ) ,
332
394
} ) ;
333
- if ( adv_particles_seq . particles_callback ) {
334
- emitter . forEach ( ( particle : Phaser . ParticleStorm . Particle ) => {
335
- adv_particles_seq . particles_callback ( particle ) ;
336
- } , this ) ;
337
- }
338
- if ( emitter_info . animation !== undefined ) {
339
- const particle_key = adv_particles_seq . data [ emitter_info . emitter_data_key ] . image as string ;
340
- const particle_sprite_base = this . data . info . misc_sprite_base_list [ particle_key ] ;
341
- const anim_key = particle_sprite_base . getAnimationKey (
342
- particle_key ,
343
- emitter_info . animation . animation_key
344
- ) ;
345
- emitter . forEach ( ( particle : Phaser . ParticleStorm . Particle ) => {
346
- particle_sprite_base . setAnimation ( particle . sprite , particle_key ) ;
347
- } , this ) ;
348
- emitter . onEmit = new Phaser . Signal ( ) ;
349
- emitter . onEmit . add (
350
- ( emitter : Phaser . ParticleStorm . Emitter , particle : Phaser . ParticleStorm . Particle ) => {
351
- particle . sprite . animations . play (
352
- anim_key ,
353
- emitter_info . animation . frame_rate ,
354
- emitter_info . animation . loop
355
- ) ;
395
+ if ( emitter_info . tween_emitter ) {
396
+ const dest : { x ?: number ; y ?: number } = { } ;
397
+ if ( emitter_info . tween_emitter . x ) {
398
+ if ( typeof emitter_info . tween_emitter . x !== "number" ) {
399
+ dest . x = this . data . game_event_manager . get_value ( emitter_info . tween_emitter . x ) ;
400
+ } else {
401
+ dest . x = emitter_info . tween_emitter . x ;
356
402
}
357
- ) ;
403
+ dest . x = ( emitter_info . tween_emitter . incremental ? pos . x : 0 ) + dest . x ;
404
+ }
405
+ if ( emitter_info . tween_emitter . y ) {
406
+ if ( typeof emitter_info . tween_emitter . y !== "number" ) {
407
+ dest . y = this . data . game_event_manager . get_value ( emitter_info . tween_emitter . y ) ;
408
+ } else {
409
+ dest . y = emitter_info . tween_emitter . y ;
410
+ }
411
+ dest . y = ( emitter_info . tween_emitter . incremental ? pos . y : 0 ) + dest . y ;
412
+ }
413
+ this . game . add
414
+ . tween ( pos )
415
+ . to (
416
+ dest ,
417
+ emitter_info . tween_emitter . duration ,
418
+ _ . get ( Phaser . Easing , emitter_info . tween_emitter . easing ?? "Linear.None" ) ,
419
+ true
420
+ ) ;
358
421
}
359
422
emitters . push ( emitter ) ;
360
423
} ) ;
0 commit comments