diff --git a/public/assets/glApp.js b/public/assets/glApp.js index c5772ee72..663542fae 100644 --- a/public/assets/glApp.js +++ b/public/assets/glApp.js @@ -3842,7 +3842,7 @@ uniform vec2 u_blueNoiseCoordOffset; vec3 getBlueNoise (vec2 coord) { return texture2D(u_blueNoiseTexture, coord * u_blueNoiseTexelSize + u_blueNoiseCoordOffset).rgb; -}`;class gm{constructor(){N(this,"sharedUniforms",{u_blueNoiseTexture:{value:null},u_blueNoiseTexelSize:{value:null},u_blueNoiseCoordOffset:{value:new De}});N(this,"TEXTURE_SIZE",128)}preInit(){Sn.loadTexture(at.ASSETS_PATH+"textures/LDR_RGB1_0.png",e=>{e.generateMipmaps=!1,e.minFilter=e.magFilter=Rt,e.wrapS=e.wrapT=Or,e.needsUpdate=!0,this.sharedUniforms.u_blueNoiseTexture.value=e,this.sharedUniforms.u_blueNoiseTexelSize.value=new De(1/this.TEXTURE_SIZE,1/this.TEXTURE_SIZE)}),Fe.getBlueNoise=_m}update(e){this.sharedUniforms.u_blueNoiseCoordOffset.value.set(Math.random(),Math.random())}}const Pi=new gm;class vm{constructor(){N(this,"PI",Math.PI)}clamp(e,t,n){return en?n:e}mix(e,t,n){return e+(t-e)*n}cUnMix(e,t,n){return this.clamp((n-e)/(t-e),0,1)}saturate(e){return this.clamp(e,0,1)}fit(e,t,n,r,s,o){return e=this.cUnMix(t,n,e),o&&(e=o(e)),r+e*(s-r)}}const Ie=new vm;class xm{quartInOut(e){return(e*=2)<1?.5*e*e*e*e:-.5*((e-=2)*e*e*e-2)}sineOut(e){return Math.sin(e*Math.PI/2)}backIn(e){let t=1.70158;return e*e*((t+1)*e-t)}backOut(e,t=1.70158){return--e*e*((t+1)*e+t)+1}backInOut(e){let t=2.5949095;return(e*=2)<1?.5*e*e*((t+1)*e-t):.5*((e-=2)*e*((t+1)*e+t)+2)}}function Sm(i,e,t,n,r){if(i===0)return 0;if(i===1)return 1;function s(l,c,u,f,p){const m=3*(u-c),_=3*(f-u)-m;return(((p-c-m-_)*l+_)*l+m)*l+c}function o(l,c,u,f=1e-6){let p=0,m=1,_=l;for(;p{var l;return(a==null?void 0:a.id)===((l=O.errorBlock)==null?void 0:l.id)});o&&(o.isErrorBlock=!1,Dn.resetBlockFromLogicBlock(o)),O.errorBlock=null}this.statusUpdateQueue.push(()=>t?this._updateStatusAndResult(e,t,n):this._updateStatus(e))}reset(){this._queueStatusUpdate(nt.NOT_STARTED,ot.NONE)}setStart(){this._queueStatusUpdate(nt.STARTED)}setFree(){this._queueStatusUpdate(nt.FREE)}setPause(){O.isPaused=!0}setResume(){O.isPaused=!1}setStop(){this._queueStatusUpdate(nt.RESULT,ot.STOP)}setComplete(){this._queueStatusUpdate(nt.RESULT,ot.COMPLETED,Kn.LEVEL_1)}setComplete2(){this._queueStatusUpdate(nt.RESULT,ot.COMPLETED,Kn.LEVEL_2)}setComplete3(){this._queueStatusUpdate(nt.RESULT,ot.COMPLETED,Kn.LEVEL_3)}setFail(){this._queueStatusUpdate(nt.RESULT,ot.FAILED)}setResultAnimation(){this._queueStatusUpdate(nt.RESULT_ANIMATION)}setRestartAnimation(){this._queueStatusUpdate(nt.RESTART_ANIMATION)}setRestart(){this.statusUpdateQueue.push(()=>{this._updateStatus(nt.RESTART)&&this.gameEndedSignal.dispatch()})}}const Le=new Mm;class el{constructor(e,t=!1){N(this,"id",-1);N(this,"isMoving",!1);N(this,"hasBeenSpawned",!1);N(this,"hasAnimationEnded",!1);N(this,"hasBeenEvaluated",!1);N(this,"currentTile",null);N(this,"targetTile",null);N(this,"moveAnimationRatio",0);N(this,"spawnAnimationRatio",0);N(this,"spawnAnimationRatioUnclamped",-Math.random());N(this,"easedAnimationRatio",0);N(this,"randomVector",{x:Math.random()-.5,y:Math.random()-.5});N(this,"lifeCycle",0);N(this,"easingFunction",null);N(this,"errorLifeCycle",0);N(this,"isErrorBlock",!1);N(this,"errorPreFallAnimationTime",0);N(this,"errorPreFallAnimationTimeScale",0);N(this,"errorFallAnimationTime",0);this.id=e,this.init(),t&&(this.isErrorBlock=!1,O.errorBlock=null)}init(){this._setNewEasingFunction()}_setNewEasingFunction(){const e=Math.random(),t=.25;this.easingFunction=n=>vi(Ie.fit(n,e*t,e*t+(1-t),0,1))}updateTile(){this.currentTile&&(this.currentTile.isOccupied=!0,this.currentTile.willBeOccupied=!1)}_findBestTile(e,t){return e.find(n=>n.isOccupied||n.willBeOccupied||n.isMain?!1:t||this.currentTile.priority>=n.priority)}moveToNextTile(e=!1,t=0){if(this.hasBeenEvaluated=!0,this.moveAnimationRatio=-t*(this.isErrorBlock?0:1),!this.currentTile)return;if(this.isErrorBlock){this.isMoving=!0,this.targetTile=this.currentTile;return}this.currentTile.shuffleReachableNeighbours();const n=e?this.currentTile.reachableNeighbours:this.currentTile.prioritySortedReachableNeighbours,r=this._findBestTile(n,e);r&&(!this.currentTile.isMain||Math.random()<=.8)?(this.targetTile=r,this.targetTile.willBeOccupied=!0,this.isMoving=!0):this.hasAnimationEnded=!0}resetAfterCycle(){var o;this.hasBeenEvaluated=!1,this.hasAnimationEnded=!1,this.moveAnimationRatio=0,this.easedAnimationRatio=0,this.isMoving=!1,this.lifeCycle++,this.isErrorBlock&&this.errorLifeCycle++;const e=(o=this.currentTile)==null?void 0:o.isBorder,t=!O.errorBlock,n=O.activeBlocksCount>=O.minSpawnedBlocksForTheErrorBlock,r=Math.random()<.5;Le.isFree&&r&&n&&e&&t&&(this.isErrorBlock=!0,O.errorBlock=this),this._setNewEasingFunction(),this.updateTile()}reset(e=!1){var t;this.isErrorBlock&&(this.errorLifeCycle=0,this.isErrorBlock=!1,this.currentTile.reset(),(t=this.targetTile)==null||t.reset(),this.errorFallAnimationTime=0),this.id=e?this.id:-1,this.isMoving=!1,this.hasBeenSpawned=!1,this.hasAnimationEnded=!1,this.hasBeenEvaluated=!1,this.currentTile=null,this.targetTile=null,this.moveAnimationRatio=0,this.spawnAnimationRatio=0,this.spawnAnimationRatioUnclamped=-Math.random(),this.easedAnimationRatio=0,this.lifeCycle=0,this.errorPreFallAnimationTime=0,this.errorPreFallAnimationTimeScale=0,this.errorFallAnimationTime=0}_onMovementEnd(){this.moveAnimationRatio=1,this.currentTile&&(this.currentTile.isOccupied=!1),this.currentTile=this.targetTile,this.targetTile=null,this.hasAnimationEnded=!0,this.updateTile()}_updateSpawnAnimation(e){this.spawnAnimationRatioUnclamped+=.75*O.animationSpeed*e,this.spawnAnimationRatio=Math.max(0,Math.min(1,this.spawnAnimationRatioUnclamped)),this.spawnAnimationRatio===1&&(this.hasBeenSpawned=!0)}_updateMovement(e){(this.isMoving&&!this.hasAnimationEnded||Le.isResultAnimation)&&(this.moveAnimationRatio=Math.min(1,this.moveAnimationRatio+O.animationSpeed*e*(this.isErrorBlock?.7:1)),this.easedAnimationRatio=this.easingFunction(Math.max(0,this.moveAnimationRatio)),this.easedAnimationRatio===1&&(Le.isFree||Le.isResult)&&this._onMovementEnd())}_updateTileRatios(){const e=Math.max(0,Math.min(1,this.hasBeenSpawned?this.easedAnimationRatio:this.spawnAnimationRatio));this.currentTile&&(this.currentTile.activeRatio=this.hasBeenSpawned?this.targetTile?1-e:1:this.spawnAnimationRatio),this.targetTile&&(this.targetTile.activeRatio=e),this.isErrorBlock&&this.errorLifeCycle>=O.errorBlockMaxLifeCycle-1&&(this.currentTile.activeRatio=0,this.targetTile&&(this.targetTile.activeRatio=0))}update(e){this.hasBeenSpawned?this._updateMovement(e):this._updateSpawnAnimation(e),this.errorLifeCycle>=O.errorBlockMaxLifeCycle-1&&(this.errorFallAnimationTime=this.errorFallAnimationTime+3*O.animationSpeed*e),this.isErrorBlock&&(this.errorPreFallAnimationTimeScale=this.errorPreFallAnimationTimeScale+3*e,this.errorPreFallAnimationTimeScale=Math.min(20,this.errorPreFallAnimationTimeScale),this.errorPreFallAnimationTime=this.errorPreFallAnimationTime+this.errorPreFallAnimationTimeScale*e),this._updateTileRatios()}}class Em{constructor(){N(this,"currentAnimationStyle",null);N(this,"ratio",0);N(this,"duration",8);N(this,"towerRotationRatio",0);N(this,"floatingCoinsRatio",0);N(this,"floatingCubesRatio",0);N(this,"vortexCoinsRatio",0);N(this,"pushDownRatio",0);N(this,"successColorTowerRatio",0);N(this,"floatingCubesDisplacement",1);N(this,"completeAnimationEndedSignal",new xn)}init(){Le.stateSignal.add((e,t,n)=>{e===nt.RESULT&&t===ot.COMPLETED&&this.triggerNewAnimation(n)})}triggerNewAnimation(e){this.currentAnimationStyle=e}resetRatios(){this.ratio=0,this.towerRotationRatio=0,this.floatingCoinsRatio=0,this.floatingCubesRatio=0,this.vortexCoinsRatio=0,this.pushDownRatio=0,this.successColorTowerRatio=0,this.floatingCubesDisplacement=1,this.currentAnimationStyle=null}updateRatios1(){this.floatingCubesDisplacement=1,this.towerRotationRatio=0,this.floatingCoinsRatio=0,this.floatingCubesRatio=Ie.fit(this.ratio,.2,.49,0,1.2),this.pushDownRatio=Ie.fit(this.ratio,.45,.55,0,1),this.successColorTowerRatio=Ie.fit(this.ratio,.45,.7,0,1),this.vortexCoinsRatio=Ie.fit(this.ratio,.55,1,0,1)}updateRatios2(){this.floatingCubesDisplacement=1.5,this.floatingCoinsRatio=0,this.towerRotationRatio=Ie.fit(this.ratio,.1,.45,0,1),this.floatingCubesRatio=Ie.fit(this.ratio,.15,.49,0,1.2),this.pushDownRatio=Ie.fit(this.ratio,.45,.55,0,1),this.successColorTowerRatio=Ie.fit(this.ratio,.45,.7,0,1),this.vortexCoinsRatio=Ie.fit(this.ratio,.55,1,0,1)}updateRatios3(){this.floatingCubesDisplacement=2,this.towerRotationRatio=Ie.fit(this.ratio,.1,.5,0,1),this.floatingCoinsRatio=Ie.fit(this.ratio,.2,.51,0,1),this.floatingCubesRatio=Ie.fit(this.ratio,.2,.49,0,1.2),this.pushDownRatio=Ie.fit(this.ratio,.45,.55,0,1),this.successColorTowerRatio=Ie.fit(this.ratio,.45,.7,0,1),this.vortexCoinsRatio=Ie.fit(this.ratio,.6,1,0,1)}update(e){switch(this.ratio+=(this.currentAnimationStyle?1:0)*e/this.duration,this.ratio=Ie.clamp(this.ratio,0,1),this.currentAnimationStyle){case Kn.LEVEL_1:this.updateRatios1();break;case Kn.LEVEL_2:this.updateRatios2();break;case Kn.LEVEL_3:this.updateRatios3();break}this.ratio===1&&(this.completeAnimationEndedSignal.dispatch(),this.resetRatios())}}const Dt=new Em;class ym{constructor(){N(this,"isActive",!1);N(this,"ratio",0);N(this,"duration",4);N(this,"spawnRatio",0);N(this,"pushDownRatio",0);N(this,"stopAnimationEndedSignal",new xn)}init(){Le.stateSignal.add((e,t,n)=>{e===nt.RESULT&&t===ot.STOP&&(this.isActive=!0)})}resetRatios(){this.ratio=0,this.pushDownRatio=0,this.spawnRatio=0,this.isActive=!1}update(e){this.ratio+=(this.isActive?1:0)*e/this.duration,this.ratio=Ie.clamp(this.ratio,0,1),this.spawnRatio=Ie.fit(this.ratio,0,.25,0,2.5),this.pushDownRatio=Ie.fit(this.ratio,.45,.55,0,1),this.ratio===1&&(this.stopAnimationEndedSignal.dispatch(),this.resetRatios())}}const mn=new ym;class Tm{constructor(){N(this,"isActive",!1);N(this,"ratio",0);N(this,"duration",4);N(this,"shakeRatio",0);N(this,"floatingCubesRatio",0);N(this,"spawnRatio",0);N(this,"pushDownRatio",0);N(this,"errorAnimationEndedSignal",new xn)}init(){Le.stateSignal.add((e,t,n)=>{e===nt.RESULT&&t===ot.FAILED&&(this.isActive=!0)})}resetRatios(){this.ratio=0,this.shakeRatio=0,this.floatingCubesRatio=0,this.pushDownRatio=0,this.spawnRatio=0,this.isActive=!1}update(e){this.ratio+=(this.isActive?1:0)*e/this.duration,this.ratio=Ie.clamp(this.ratio,0,1),this.shakeRatio=Ie.fit(this.ratio,0,.3,0,1),this.floatingCubesRatio=Ie.fit(this.ratio,.35,.65,0,1),this.spawnRatio=Ie.fit(this.ratio,.3,.55,0,2.5),this.pushDownRatio=Ie.fit(this.ratio,.6,.8,0,1),this.ratio===1&&(this.errorAnimationEndedSignal.dispatch(),this.resetRatios())}}const St=new Tm;class Am{constructor(){N(this,"blocks",[]);N(this,"lastSpawnedBlock",null);N(this,"cycleIndex",0);N(this,"animationSpeedRatio",0);N(this,"firstStartAnimationRatio",0);N(this,"previousSuccessBlocksAnimationRatio",0);N(this,"isEndAnimationActive",!1);N(this,"wasSuccess",!1)}init(){Le.init(),Dt.init(),mn.init(),St.init(),Jt.init(),Dt.completeAnimationEndedSignal.add(()=>{Le.setRestart(),this._startNewCycle()}),mn.stopAnimationEndedSignal.add(()=>{Le.setRestart(),this._startNewCycle()}),St.errorAnimationEndedSignal.add(()=>{Le.setRestart(),this._startNewCycle()})}_spawnBlock(){this._shouldPreventSpawn()||(Le.isSuccessResult?this._spawnMultipleBlocks():this._spawnSingleBlock(),!(this.blocks.length===O.maxFreeBlocksCount&&Le.isFree)&&Le.spawnSignal.dispatch())}_shouldPreventSpawn(){return Le.isFailResult||Le.isStopped||this.blocks.length>=$t||Jt.mainTile.isOccupied&&!Le.isSuccessResult}_spawnMultipleBlocks(){let e=$t-O.activeBlocksCount;O.errorBlock&&(O.errorBlock.currentTile.isOccupied=!1,e+=1);for(let t=0;t=O.errorBlockMaxLifeCycle),n=!!(this.blocks.lengthe.resetAfterCycle()),Le.endCycleSignal.dispatch(),this.cycleIndex++,this._spawnBlock(),this._calculatePaths()))}_calculatePaths(){var t;(t=this.lastSpawnedBlock)!=null&&t.hasBeenSpawned&&this.lastSpawnedBlock.moveToNextTile(Le.isFree,0);const e=this.cycleIndex%2===0?!0:O.activeBlocksCount{!n.hasBeenEvaluated&&n.hasBeenSpawned&&n.moveToNextTile(e,r*.2)})}reset(){this.blocks.forEach(t=>t.reset()),Dn.reset(),Jt.reset(),this.blocks=[],this.lastSpawnedBlock=null,this.cycleIndex=0,this.animationSpeedRatio=0,this.previousSuccessBlocksAnimationRatio=this.wasSuccess?1:0,this.isEndAnimationActive=!1;const e=at.AUTO_RESTART&&[ot.FAILED,ot.COMPLETED].includes(Le.result);Le.reset(),this._startNewCycle(),e&&(Le.setStart(),Le.updateFlags())}_updateAnimationRatios(e){const{isResult:t}=Le;this.firstStartAnimationRatio=Ie.saturate(this.firstStartAnimationRatio+e*(O.showVisual?1:0)),this.animationSpeedRatio=Math.min(1,this.animationSpeedRatio+e*(t?1:0)),this.previousSuccessBlocksAnimationRatio=Ie.saturate(this.previousSuccessBlocksAnimationRatio-.25*e)}_checkCycleCompletion(){let e=!0;return this.lastSpawnedBlock&&(e=e&&this.lastSpawnedBlock.hasBeenSpawned),this.blocks.forEach(t=>{t.lifeCycle>0?e=e&&t.hasBeenEvaluated&&t.hasAnimationEnded:e=e&&t.spawnAnimationRatio===1}),e||Le.isResultAnimation||Le.isFailResult||Le.isStopped}update(e){if(this._updateAnimationRatios(e),Dt.update(e),mn.update(e),St.update(e),Le.hasNotStarted){this._startNewCycle();return}if(Le.isRestart){this.wasSuccess=Le.result===ot.COMPLETED,this.reset();return}Le.isResultAnimation&&Le.setRestartAnimation(),Jt.preUpdate(e),this.lastSpawnedBlock&&this.lastSpawnedBlock.update(e),this.blocks.forEach(n=>n.update(e)),Jt.update(e),this._checkCycleCompletion()&&this._startNewCycle()}}const Mt=new Am,bm=Math.PI/2,_i=new U;class wm{constructor(){this.animation=0,this.boardDir=new De,this.boardPos=new De,this.pos=new U,this.orient=new Yt,this.showRatio=0,this.spinPivot=new U,this.spinOrient=new Yt,this.spinOrient2=new Yt}reset(){this.animation=0,this.boardDir.set(0,0),this.boardPos.set(0,0),this.pos.set(0,0,0),this.orient.identity(),this.showRatio=0,this.spinPivot.set(0,0,0),this.spinOrient.identity()}update(e){this.pos.set(this.boardPos.x,0,-this.boardPos.y),this.spinPivot.set(this.boardDir.x*.5,-.5,-this.boardDir.y*.5),_i.set(-this.boardDir.y,0,-this.boardDir.x),this.spinOrient.setFromAxisAngle(_i,this.animation*bm)}addsFallAnimation(e){_i.set(this.boardDir.x,-e,-this.boardDir.y),this.pos.addScaledVector(_i,e),_i.set(this.boardDir.x*.5,0,-this.boardDir.y*.5),this.spinPivot.lerp(_i,Ie.saturate(e))}}var Tr=`#ifndef IS_BASE +}`;class gm{constructor(){N(this,"sharedUniforms",{u_blueNoiseTexture:{value:null},u_blueNoiseTexelSize:{value:null},u_blueNoiseCoordOffset:{value:new De}});N(this,"TEXTURE_SIZE",128)}preInit(){Sn.loadTexture(at.ASSETS_PATH+"textures/LDR_RGB1_0.png",e=>{e.generateMipmaps=!1,e.minFilter=e.magFilter=Rt,e.wrapS=e.wrapT=Or,e.needsUpdate=!0,this.sharedUniforms.u_blueNoiseTexture.value=e,this.sharedUniforms.u_blueNoiseTexelSize.value=new De(1/this.TEXTURE_SIZE,1/this.TEXTURE_SIZE)}),Fe.getBlueNoise=_m}update(e){this.sharedUniforms.u_blueNoiseCoordOffset.value.set(Math.random(),Math.random())}}const Pi=new gm;class vm{constructor(){N(this,"PI",Math.PI)}clamp(e,t,n){return en?n:e}mix(e,t,n){return e+(t-e)*n}cUnMix(e,t,n){return this.clamp((n-e)/(t-e),0,1)}saturate(e){return this.clamp(e,0,1)}fit(e,t,n,r,s,o){return e=this.cUnMix(t,n,e),o&&(e=o(e)),r+e*(s-r)}}const Ie=new vm;class xm{quartInOut(e){return(e*=2)<1?.5*e*e*e*e:-.5*((e-=2)*e*e*e-2)}sineOut(e){return Math.sin(e*Math.PI/2)}backIn(e){let t=1.70158;return e*e*((t+1)*e-t)}backOut(e,t=1.70158){return--e*e*((t+1)*e+t)+1}backInOut(e){let t=2.5949095;return(e*=2)<1?.5*e*e*((t+1)*e-t):.5*((e-=2)*e*((t+1)*e+t)+2)}}function Sm(i,e,t,n,r){if(i===0)return 0;if(i===1)return 1;function s(l,c,u,f,p){const m=3*(u-c),_=3*(f-u)-m;return(((p-c-m-_)*l+_)*l+m)*l+c}function o(l,c,u,f=1e-6){let p=0,m=1,_=l;for(;p{var l;return(a==null?void 0:a.id)===((l=O.errorBlock)==null?void 0:l.id)});o&&(o.isErrorBlock=!1,Dn.resetBlockFromLogicBlock(o)),O.errorBlock=null}this.statusUpdateQueue.push(()=>t?this._updateStatusAndResult(e,t,n):this._updateStatus(e))}reset(){this._queueStatusUpdate(nt.NOT_STARTED,ot.NONE)}setStart(){this._queueStatusUpdate(nt.STARTED)}setFree(){this._queueStatusUpdate(nt.FREE)}setPause(){O.isPaused=!0}setResume(){O.isPaused=!1}setStop(){this._queueStatusUpdate(nt.RESULT,ot.STOP)}setComplete(){this._queueStatusUpdate(nt.RESULT,ot.COMPLETED,Kn.LEVEL_1)}setComplete2(){this._queueStatusUpdate(nt.RESULT,ot.COMPLETED,Kn.LEVEL_2)}setComplete3(){this._queueStatusUpdate(nt.RESULT,ot.COMPLETED,Kn.LEVEL_3)}setFail(){this._queueStatusUpdate(nt.RESULT,ot.FAILED)}setResultAnimation(){this._queueStatusUpdate(nt.RESULT_ANIMATION)}setRestartAnimation(){this._queueStatusUpdate(nt.RESTART_ANIMATION)}setRestart(){this.statusUpdateQueue.push(()=>{this._updateStatus(nt.RESTART)&&this.gameEndedSignal.dispatch()})}}const Le=new Mm;class el{constructor(e,t=!1){N(this,"id",-1);N(this,"isMoving",!1);N(this,"hasBeenSpawned",!1);N(this,"hasAnimationEnded",!1);N(this,"hasBeenEvaluated",!1);N(this,"currentTile",null);N(this,"targetTile",null);N(this,"moveAnimationRatio",0);N(this,"spawnAnimationRatio",0);N(this,"spawnAnimationRatioUnclamped",-Math.random());N(this,"easedAnimationRatio",0);N(this,"randomVector",{x:Math.random()-.5,y:Math.random()-.5});N(this,"lifeCycle",0);N(this,"easingFunction",null);N(this,"errorLifeCycle",0);N(this,"isErrorBlock",!1);N(this,"errorPreFallAnimationTime",0);N(this,"errorPreFallAnimationTimeScale",0);N(this,"errorFallAnimationTime",0);this.id=e,this.init(),t&&(this.isErrorBlock=!1,O.errorBlock=null)}init(){this._setNewEasingFunction()}_setNewEasingFunction(){const e=Math.random(),t=.25;this.easingFunction=n=>vi(Ie.fit(n,e*t,e*t+(1-t),0,1))}updateTile(){this.currentTile&&(this.currentTile.isOccupied=!0,this.currentTile.willBeOccupied=!1)}_findBestTile(e,t){return e.find(n=>n.isOccupied||n.willBeOccupied||n.isMain?!1:t||this.currentTile.priority>=n.priority)}moveToNextTile(e=!1,t=0){if(this.hasBeenEvaluated=!0,this.moveAnimationRatio=-t*(this.isErrorBlock?0:1),!this.currentTile)return;if(this.isErrorBlock){this.isMoving=!0,this.targetTile=this.currentTile;return}this.currentTile.shuffleReachableNeighbours();const n=e?this.currentTile.reachableNeighbours:this.currentTile.prioritySortedReachableNeighbours,r=this._findBestTile(n,e);r&&(!this.currentTile.isMain||Math.random()<=.8)?(this.targetTile=r,this.targetTile.willBeOccupied=!0,this.isMoving=!0):this.hasAnimationEnded=!0}resetAfterCycle(){var a;this.hasBeenEvaluated=!1,this.hasAnimationEnded=!1,this.moveAnimationRatio=0,this.easedAnimationRatio=0,this.isMoving=!1,this.lifeCycle++,this.isErrorBlock&&this.errorLifeCycle++;const e=(a=this.currentTile)==null?void 0:a.isBorder,t=!O.errorBlock,n=O.activeBlocksCount>=O.minSpawnedBlocksForTheErrorBlock,s=window.crypto.getRandomValues(new Uint32Array(1))[0]*Math.pow(2,-32)<.5;Le.isFree&&s&&n&&e&&t&&(this.isErrorBlock=!0,O.errorBlock=this),this._setNewEasingFunction(),this.updateTile()}reset(e=!1){var t;this.isErrorBlock&&(this.errorLifeCycle=0,this.isErrorBlock=!1,this.currentTile.reset(),(t=this.targetTile)==null||t.reset(),this.errorFallAnimationTime=0),this.id=e?this.id:-1,this.isMoving=!1,this.hasBeenSpawned=!1,this.hasAnimationEnded=!1,this.hasBeenEvaluated=!1,this.currentTile=null,this.targetTile=null,this.moveAnimationRatio=0,this.spawnAnimationRatio=0,this.spawnAnimationRatioUnclamped=-Math.random(),this.easedAnimationRatio=0,this.lifeCycle=0,this.errorPreFallAnimationTime=0,this.errorPreFallAnimationTimeScale=0,this.errorFallAnimationTime=0}_onMovementEnd(){this.moveAnimationRatio=1,this.currentTile&&(this.currentTile.isOccupied=!1),this.currentTile=this.targetTile,this.targetTile=null,this.hasAnimationEnded=!0,this.updateTile()}_updateSpawnAnimation(e){this.spawnAnimationRatioUnclamped+=.75*O.animationSpeed*e,this.spawnAnimationRatio=Math.max(0,Math.min(1,this.spawnAnimationRatioUnclamped)),this.spawnAnimationRatio===1&&(this.hasBeenSpawned=!0)}_updateMovement(e){(this.isMoving&&!this.hasAnimationEnded||Le.isResultAnimation)&&(this.moveAnimationRatio=Math.min(1,this.moveAnimationRatio+O.animationSpeed*e*(this.isErrorBlock?.7:1)),this.easedAnimationRatio=this.easingFunction(Math.max(0,this.moveAnimationRatio)),this.easedAnimationRatio===1&&(Le.isFree||Le.isResult)&&this._onMovementEnd())}_updateTileRatios(){const e=Math.max(0,Math.min(1,this.hasBeenSpawned?this.easedAnimationRatio:this.spawnAnimationRatio));this.currentTile&&(this.currentTile.activeRatio=this.hasBeenSpawned?this.targetTile?1-e:1:this.spawnAnimationRatio),this.targetTile&&(this.targetTile.activeRatio=e),this.isErrorBlock&&this.errorLifeCycle>=O.errorBlockMaxLifeCycle-1&&(this.currentTile.activeRatio=0,this.targetTile&&(this.targetTile.activeRatio=0))}update(e){this.hasBeenSpawned?this._updateMovement(e):this._updateSpawnAnimation(e),this.errorLifeCycle>=O.errorBlockMaxLifeCycle-1&&(this.errorFallAnimationTime=this.errorFallAnimationTime+3*O.animationSpeed*e),this.isErrorBlock&&(this.errorPreFallAnimationTimeScale=this.errorPreFallAnimationTimeScale+3*e,this.errorPreFallAnimationTimeScale=Math.min(20,this.errorPreFallAnimationTimeScale),this.errorPreFallAnimationTime=this.errorPreFallAnimationTime+this.errorPreFallAnimationTimeScale*e),this._updateTileRatios()}}class Em{constructor(){N(this,"currentAnimationStyle",null);N(this,"ratio",0);N(this,"duration",8);N(this,"towerRotationRatio",0);N(this,"floatingCoinsRatio",0);N(this,"floatingCubesRatio",0);N(this,"vortexCoinsRatio",0);N(this,"pushDownRatio",0);N(this,"successColorTowerRatio",0);N(this,"floatingCubesDisplacement",1);N(this,"completeAnimationEndedSignal",new xn)}init(){Le.stateSignal.add((e,t,n)=>{e===nt.RESULT&&t===ot.COMPLETED&&this.triggerNewAnimation(n)})}triggerNewAnimation(e){this.currentAnimationStyle=e}resetRatios(){this.ratio=0,this.towerRotationRatio=0,this.floatingCoinsRatio=0,this.floatingCubesRatio=0,this.vortexCoinsRatio=0,this.pushDownRatio=0,this.successColorTowerRatio=0,this.floatingCubesDisplacement=1,this.currentAnimationStyle=null}updateRatios1(){this.floatingCubesDisplacement=1,this.towerRotationRatio=0,this.floatingCoinsRatio=0,this.floatingCubesRatio=Ie.fit(this.ratio,.2,.49,0,1.2),this.pushDownRatio=Ie.fit(this.ratio,.45,.55,0,1),this.successColorTowerRatio=Ie.fit(this.ratio,.45,.7,0,1),this.vortexCoinsRatio=Ie.fit(this.ratio,.55,1,0,1)}updateRatios2(){this.floatingCubesDisplacement=1.5,this.floatingCoinsRatio=0,this.towerRotationRatio=Ie.fit(this.ratio,.1,.45,0,1),this.floatingCubesRatio=Ie.fit(this.ratio,.15,.49,0,1.2),this.pushDownRatio=Ie.fit(this.ratio,.45,.55,0,1),this.successColorTowerRatio=Ie.fit(this.ratio,.45,.7,0,1),this.vortexCoinsRatio=Ie.fit(this.ratio,.55,1,0,1)}updateRatios3(){this.floatingCubesDisplacement=2,this.towerRotationRatio=Ie.fit(this.ratio,.1,.5,0,1),this.floatingCoinsRatio=Ie.fit(this.ratio,.2,.51,0,1),this.floatingCubesRatio=Ie.fit(this.ratio,.2,.49,0,1.2),this.pushDownRatio=Ie.fit(this.ratio,.45,.55,0,1),this.successColorTowerRatio=Ie.fit(this.ratio,.45,.7,0,1),this.vortexCoinsRatio=Ie.fit(this.ratio,.6,1,0,1)}update(e){switch(this.ratio+=(this.currentAnimationStyle?1:0)*e/this.duration,this.ratio=Ie.clamp(this.ratio,0,1),this.currentAnimationStyle){case Kn.LEVEL_1:this.updateRatios1();break;case Kn.LEVEL_2:this.updateRatios2();break;case Kn.LEVEL_3:this.updateRatios3();break}this.ratio===1&&(this.completeAnimationEndedSignal.dispatch(),this.resetRatios())}}const Dt=new Em;class ym{constructor(){N(this,"isActive",!1);N(this,"ratio",0);N(this,"duration",4);N(this,"spawnRatio",0);N(this,"pushDownRatio",0);N(this,"stopAnimationEndedSignal",new xn)}init(){Le.stateSignal.add((e,t,n)=>{e===nt.RESULT&&t===ot.STOP&&(this.isActive=!0)})}resetRatios(){this.ratio=0,this.pushDownRatio=0,this.spawnRatio=0,this.isActive=!1}update(e){this.ratio+=(this.isActive?1:0)*e/this.duration,this.ratio=Ie.clamp(this.ratio,0,1),this.spawnRatio=Ie.fit(this.ratio,0,.25,0,2.5),this.pushDownRatio=Ie.fit(this.ratio,.45,.55,0,1),this.ratio===1&&(this.stopAnimationEndedSignal.dispatch(),this.resetRatios())}}const mn=new ym;class Tm{constructor(){N(this,"isActive",!1);N(this,"ratio",0);N(this,"duration",4);N(this,"shakeRatio",0);N(this,"floatingCubesRatio",0);N(this,"spawnRatio",0);N(this,"pushDownRatio",0);N(this,"errorAnimationEndedSignal",new xn)}init(){Le.stateSignal.add((e,t,n)=>{e===nt.RESULT&&t===ot.FAILED&&(this.isActive=!0)})}resetRatios(){this.ratio=0,this.shakeRatio=0,this.floatingCubesRatio=0,this.pushDownRatio=0,this.spawnRatio=0,this.isActive=!1}update(e){this.ratio+=(this.isActive?1:0)*e/this.duration,this.ratio=Ie.clamp(this.ratio,0,1),this.shakeRatio=Ie.fit(this.ratio,0,.3,0,1),this.floatingCubesRatio=Ie.fit(this.ratio,.35,.65,0,1),this.spawnRatio=Ie.fit(this.ratio,.3,.55,0,2.5),this.pushDownRatio=Ie.fit(this.ratio,.6,.8,0,1),this.ratio===1&&(this.errorAnimationEndedSignal.dispatch(),this.resetRatios())}}const St=new Tm;class Am{constructor(){N(this,"blocks",[]);N(this,"lastSpawnedBlock",null);N(this,"cycleIndex",0);N(this,"animationSpeedRatio",0);N(this,"firstStartAnimationRatio",0);N(this,"previousSuccessBlocksAnimationRatio",0);N(this,"isEndAnimationActive",!1);N(this,"wasSuccess",!1)}init(){Le.init(),Dt.init(),mn.init(),St.init(),Jt.init(),Dt.completeAnimationEndedSignal.add(()=>{Le.setRestart(),this._startNewCycle()}),mn.stopAnimationEndedSignal.add(()=>{Le.setRestart(),this._startNewCycle()}),St.errorAnimationEndedSignal.add(()=>{Le.setRestart(),this._startNewCycle()})}_spawnBlock(){this._shouldPreventSpawn()||(Le.isSuccessResult?this._spawnMultipleBlocks():this._spawnSingleBlock(),!(this.blocks.length===O.maxFreeBlocksCount&&Le.isFree)&&Le.spawnSignal.dispatch())}_shouldPreventSpawn(){return Le.isFailResult||Le.isStopped||this.blocks.length>=$t||Jt.mainTile.isOccupied&&!Le.isSuccessResult}_spawnMultipleBlocks(){let e=$t-O.activeBlocksCount;O.errorBlock&&(O.errorBlock.currentTile.isOccupied=!1,e+=1);for(let t=0;t=O.errorBlockMaxLifeCycle),n=!!(this.blocks.lengthe.resetAfterCycle()),Le.endCycleSignal.dispatch(),this.cycleIndex++,this._spawnBlock(),this._calculatePaths()))}_calculatePaths(){var t;(t=this.lastSpawnedBlock)!=null&&t.hasBeenSpawned&&this.lastSpawnedBlock.moveToNextTile(Le.isFree,0);const e=this.cycleIndex%2===0?!0:O.activeBlocksCount{!n.hasBeenEvaluated&&n.hasBeenSpawned&&n.moveToNextTile(e,r*.2)})}reset(){this.blocks.forEach(t=>t.reset()),Dn.reset(),Jt.reset(),this.blocks=[],this.lastSpawnedBlock=null,this.cycleIndex=0,this.animationSpeedRatio=0,this.previousSuccessBlocksAnimationRatio=this.wasSuccess?1:0,this.isEndAnimationActive=!1;const e=at.AUTO_RESTART&&[ot.FAILED,ot.COMPLETED].includes(Le.result);Le.reset(),this._startNewCycle(),e&&(Le.setStart(),Le.updateFlags())}_updateAnimationRatios(e){const{isResult:t}=Le;this.firstStartAnimationRatio=Ie.saturate(this.firstStartAnimationRatio+e*(O.showVisual?1:0)),this.animationSpeedRatio=Math.min(1,this.animationSpeedRatio+e*(t?1:0)),this.previousSuccessBlocksAnimationRatio=Ie.saturate(this.previousSuccessBlocksAnimationRatio-.25*e)}_checkCycleCompletion(){let e=!0;return this.lastSpawnedBlock&&(e=e&&this.lastSpawnedBlock.hasBeenSpawned),this.blocks.forEach(t=>{t.lifeCycle>0?e=e&&t.hasBeenEvaluated&&t.hasAnimationEnded:e=e&&t.spawnAnimationRatio===1}),e||Le.isResultAnimation||Le.isFailResult||Le.isStopped}update(e){if(this._updateAnimationRatios(e),Dt.update(e),mn.update(e),St.update(e),Le.hasNotStarted){this._startNewCycle();return}if(Le.isRestart){this.wasSuccess=Le.result===ot.COMPLETED,this.reset();return}Le.isResultAnimation&&Le.setRestartAnimation(),Jt.preUpdate(e),this.lastSpawnedBlock&&this.lastSpawnedBlock.update(e),this.blocks.forEach(n=>n.update(e)),Jt.update(e),this._checkCycleCompletion()&&this._startNewCycle()}}const Mt=new Am,bm=Math.PI/2,_i=new U;class wm{constructor(){this.animation=0,this.boardDir=new De,this.boardPos=new De,this.pos=new U,this.orient=new Yt,this.showRatio=0,this.spinPivot=new U,this.spinOrient=new Yt,this.spinOrient2=new Yt}reset(){this.animation=0,this.boardDir.set(0,0),this.boardPos.set(0,0),this.pos.set(0,0,0),this.orient.identity(),this.showRatio=0,this.spinPivot.set(0,0,0),this.spinOrient.identity()}update(e){this.pos.set(this.boardPos.x,0,-this.boardPos.y),this.spinPivot.set(this.boardDir.x*.5,-.5,-this.boardDir.y*.5),_i.set(-this.boardDir.y,0,-this.boardDir.x),this.spinOrient.setFromAxisAngle(_i,this.animation*bm)}addsFallAnimation(e){_i.set(this.boardDir.x,-e,-this.boardDir.y),this.pos.addScaledVector(_i,e),_i.set(this.boardDir.x*.5,0,-this.boardDir.y*.5),this.spinPivot.lerp(_i,Ie.saturate(e))}}var Tr=`#ifndef IS_BASE attribute vec3 instancePos; attribute vec4 instanceOrient; attribute float instanceShowRatio;