class Gametimer extends Phaser.Scene{constructor(){super("Gametimer")}init(){log("=> launching Gametimer manager"),this.gTimer,this.runTime,this.timeRunning=!1}newTimer(e,{posX:t=100,posY:i=100,callback:s="",gameTime:a=15,delay:h=500,countdown:r=!1}){if(this.timeRunning)log("WARNING : a game timer is already running!");else{this.timerGroup=e.add.group(),this.blackLayer=this.add.sprite(t-8,i-10,"black-layer"),this.redLayer=this.add.sprite(t-8,i-10,"red-layer"),this.shape=this.make.graphics(),this.shape.fillStyle(16777215),this.shape.slice(this.redLayer.x,this.redLayer.y,this.redLayer.displayWidth/2,Phaser.Math.DegToRad(270),Phaser.Math.DegToRad(0),!0),this.shape.fillPath(),this.mask=this.shape.createGeometryMask(),this.redLayer.setMask(this.mask),this.redLayer.setScale(1.4),this.redLayer.setDepth(10),this.blackLayer.setDepth(10),this.blackLayer.setScale(1.4),log("new timer: ",a);this.callback=s,this.scene=e,this.countdown=r,this.gameTime=this.countdown?a:0,this.centerX=t,this.runTime=a,this.timerBg=this.add.sprite(t,i,"timerBg"),this.timerBg.setScale(1.2),this.timerBg.setDepth(9),this.timerDisplay=this.add.text(t-8,i-20,this.countdown?this.gameTime:0,{fontFamily:"digital-7",color:"#FE0101",fontSize:"130px",align:"left"}),this.timerDisplay.setShadow(4,4,"#000000",4,!1,!0),this.timerDisplay.setOrigin(.5),this.timerDisplay.setDepth(10),this.timerGroup.addMultiple([this.timerBg,this.blackLayer,this.redLayer,this.timerDisplay]),this.timerDisplay.alpha=0;e.tweens.add({targets:[this.timerDisplay],alpha:1,ease:"Back.Out",duration:h/2,delay:h/2,onComplete:()=>{this.setIntervalX((()=>{this.hideAndDestroy(this)}),1e3,a)}})}}update(){}resetTimer(){log("reset game timer to -> ",this.gameTime),null!=this.gTimer&&window.clearInterval(this.gTimer),this.setIntervalX((()=>{this.hideAndDestroy(this)}),1e3,this.gameTime)}stopTimer(e=!0){null!=this.gTimer&&(log("STOP TIMER!"),window.clearInterval(this.gTimer),this.gTimer=null,this.hideAndDestroy(this,e))}setIntervalX(e,t,i){var s=0;this.timeRunning=!0,log("NEW TIMER: ",e,t,i),this.gTimer=window.setInterval(function(){++s>i&&this.countdown&&(this.stopTimer(!1),e()),null!=this.timerDisplay&&this.timerDisplay.visible&&(this.countdown&&i-s>=0?(this.timerDisplay.text=i-s,this.runTime=i-s):(this.timerDisplay.text=0,this.runTime=0))}.bind(this),t)}startAnim(e){this.seconds=e,this.counter=this.scene.tweens.addCounter({from:0,to:359,duration:1e3*this.seconds,onUpdate:e=>{let t=e.getValue();this.shape.clear(),this.shape.slice(this.redLayer.x,this.redLayer.y,this.redLayer.displayWidth/2,Phaser.Math.DegToRad(270),Phaser.Math.DegToRad(270+t),!0),this.shape.fillPath()}})}hideAndDestroy(e,t=!0){var i=e;if(this.timeRunning=!1,this.scene.tweens)this.scene.tweens.add({targets:[this.timerDisplay,this.timerBg,this.blackLayer,this.redLayer],alpha:0,ease:"Back.In",duration:250,delay:10,onComplete:()=>{""!=i.callback&&t&&(log("Timer callback: ",i.callback),this.shape.clear(),this.blackLayer.setVisible(!1),i.callback()),i.destroyMe()}})}reportRuntime(){let e=null;return log("this.runTime: ",this.runTime),this.runTime&&(e=this.runTime),e}destroyMe(){this.timerDisplay.destroy()}}
//# sourceMappingURL=index.5188266a.js.map
