@@ -16,10 +16,6 @@ interface MovePlayerMessage {
1616 direction ?: string ;
1717}
1818
19- interface CustomAnimation extends Phaser . Animations . Animation {
20- frameCallbacks ?: number [ ] ;
21- }
22-
2319interface GenerateAttackHitboxMessage {
2420 attackType : string ;
2521 attackerWidth : number ;
@@ -144,11 +140,11 @@ export default class ClientMatch extends Phaser.Scene {
144140 frames : this . anims . generateFrameNumbers ( animKey , { start : key . startFrame , end : key . endFrame } ) ,
145141 frameRate : key . frameRate ,
146142 repeat : key . repeat ,
147- frameCallbacks : key . frameCallbacks ,
148- } as CustomAnimationy ) ;
143+ } ) ;
149144 } ) ;
150145 } ) ;
151146
147+ console . log ( this . spriteSheetsLoader ) ;
152148 // CREATION DU BACKGROUND ET DU TUILAGE
153149 // Background
154150 this . background = this . add . image ( 0 , 0 , 'background' ) . setOrigin ( 0 , 0 ) ;
@@ -218,6 +214,13 @@ export default class ClientMatch extends Phaser.Scene {
218214 entity . jumpCount = 0 ;
219215 entity . airborneCount = 0 ;
220216 entity . maxJump = maxJumpHandler [ message . gameEntityType ] ;
217+ entity . frameEvents = { } ;
218+ this . spriteSheetsLoader
219+ . find ( ( spritePaths ) => spritePaths . heroName === message . gameEntityType )
220+ ?. spriteSheets . forEach ( ( spritesheet ) => {
221+ entity . frameEvents [ spritesheet . key ] = spritesheet . frameEvents ;
222+ } ) ;
223+ console . log ( entity . frameEvents ) ;
221224 }
222225
223226 //console.log(this.gameEntities);
@@ -342,41 +345,32 @@ export default class ClientMatch extends Phaser.Scene {
342345 entity . setFlipX ( flipX ) ;
343346
344347 entity . anims . play ( gem . anim , true ) ;
348+
345349 // wait for fixed animations do be finished before playing other animations
346350 if ( fixedAnimations . includes ( animKey ! ) ) {
347351 if ( animKey == 'Attack1' || animKey == 'Attack2' || animKey == 'Attack3' ) {
348- // Add a callback to the third frame of the animation
349352 entity . on ( 'animationupdate' , ( anim : any , frame : any , sprite : any , frameKey : any ) => {
350- const cAnim = anim ;
351- const cFrame = frame ;
352- const cSprite = sprite ;
353- const cFrameKey = frameKey ;
354-
355- if ( frame . index === 2 ) {
356- console . log ( 'on frame 2' ) ;
353+ if ( anim . key . split ( gem . gameEntityType ) [ 1 ] === animKey && entity . frameEvents [ animKey . toLowerCase ( ) ] ?. includes ( frame . index ) ) {
354+ this . generateAttackHitboxMessage = {
355+ attackType : entity . name + animKey ,
356+ attackerWidth : entity . width ,
357+ attackerHeight : entity . height ,
358+ direction : entity . direction ,
359+ x : entity . x ,
360+ y : entity . y ,
361+ } ;
362+
363+ console . log ( 'generate_attack_hitbox' , frame . index + this . generateAttackHitboxMessage ) ;
364+
365+ this . mo ! . send ( 'generate_attack_hitbox' , this . generateAttackHitboxMessage ) ;
357366 }
358367 } ) ;
359368 }
369+
360370 entity . once ( 'animationcomplete' , ( ) => {
361- //console.log("I'm done!");
362371 if ( animKey == 'Attack1' || animKey == 'Attack2' || animKey == 'Attack3' ) {
363- //entity.anim = `${gem.gameEntityType}Idle`;
364- //entity.anims.play(`${gem.gameEntityType}Idle`, true);
365-
366- this . generateAttackHitboxMessage = {
367- attackType : entity . name + animKey ,
368- attackerWidth : entity . width ,
369- attackerHeight : entity . height ,
370- direction : entity . direction ,
371- x : entity . x ,
372- y : entity . y ,
373- } ;
374-
375- this . mo ! . send ( 'generate_attack_hitbox' , this . generateAttackHitboxMessage ) ;
376-
377- //console.log(`Generate ${entity.name}${animKey} from ${this.playerId} at ${entity.x}, ${entity.y}`);
372+ entity . anim = `${ gem . gameEntityType } Idle` ;
378373 } else {
379- //entity.anims.play(`${gem.gameEntityType}Fall`, true);
380374 entity . anim = `${ gem . gameEntityType } Fall` ;
381375 }
382376 } ) ;
0 commit comments