@vimp-games/tanks 0.22.11 → 0.22.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client-7hAYQZhm.js +210 -0
- package/dist/client-7hAYQZhm.js.map +1 -0
- package/dist/host-DlCqKb7D.js.map +1 -1
- package/dist/manifest.json +3 -3
- package/dist/maps/garden.json +1 -1
- package/dist/sounds/bomb-has-been-planted.webm +0 -0
- package/dist/sounds/bomb-has-been-planted2.webm +0 -0
- package/dist/sounds/defeat.webm +0 -0
- package/dist/sounds/empty-bullet.webm +0 -0
- package/dist/sounds/explosion.webm +0 -0
- package/dist/sounds/frag.webm +0 -0
- package/dist/sounds/game-over.webm +0 -0
- package/dist/sounds/hit.webm +0 -0
- package/dist/sounds/round-start.webm +0 -0
- package/dist/sounds/shot.webm +0 -0
- package/dist/sounds/tank-engine.webm +0 -0
- package/dist/sounds/tank-landing.webm +0 -0
- package/dist/sounds/tank-water.webm +0 -0
- package/dist/sounds/victory.webm +0 -0
- package/package.json +1 -1
- package/dist/client-ByYEfcjw.js +0 -210
- package/dist/client-ByYEfcjw.js.map +0 -1
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import{UniformGroup as Ne,Filter as Ln,GpuProgram as Pn,GlProgram as xs,defaultFilterVert as zn,Ticker as Q,Container as $,Sprite as J,Rectangle as rt,Spritesheet as Cn,MeshSimple as En,Text as Ci,BlurFilter as ys,Assets as as,Texture as Ue,Graphics as U,Shader as Ei,Geometry as In,Mesh as Ii,AlphaFilter as Ri,PerspectiveMesh as Rn,Particle as Fn,ParticleContainer as Ke,MeshGeometry as Xn}from"pixi.js";const Yn=4;class ls{__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,Is.unregister(this),t}free(){const t=this.__destroy_into_raw();C.__wbg_clientcore_free(t,0)}abi_describe(){let t,e;try{const s=C.clientcore_abi_describe(this.__wbg_ptr);return t=s[0],e=s[1],Lt(s[0],s[1])}finally{C.__wbindgen_free(t,e,1)}}apply_aim(t,e,s,n){C.clientcore_apply_aim(this.__wbg_ptr,t,e,s,n)}apply_input(t,e,s){const n=Vt(t,C.__wbindgen_malloc,C.__wbindgen_realloc),o=_t,r=Vt(e,C.__wbindgen_malloc,C.__wbindgen_realloc),a=_t;C.clientcore_apply_input(this.__wbg_ptr,n,o,r,a,s)}cycle_weapon(t){C.clientcore_cycle_weapon(this.__wbg_ptr,t)}debug_json(){let t,e;try{const s=C.clientcore_debug_json(this.__wbg_ptr);return t=s[0],e=s[1],Lt(s[0],s[1])}finally{C.__wbindgen_free(t,e,1)}}decode_frame(t){let e,s;try{const n=je(t,C.__wbindgen_malloc),o=_t,r=C.clientcore_decode_frame(this.__wbg_ptr,n,o);return e=r[0],s=r[1],Lt(r[0],r[1])}finally{C.__wbindgen_free(e,s,1)}}dispatch(t,e){const s=Vt(t,C.__wbindgen_malloc,C.__wbindgen_realloc),n=_t,o=je(e,C.__wbindgen_malloc),r=_t,a=C.clientcore_dispatch(this.__wbg_ptr,s,n,o,r);var l=Vn(a[0],a[1]).slice();return C.__wbindgen_free(a[0],a[1]*1,1),l}floor_level(t,e,s){return C.clientcore_floor_level(this.__wbg_ptr,t,e,s)}hot_ptr(){return C.clientcore_hot_ptr(this.__wbg_ptr)>>>0}hot_values(){const t=C.clientcore_hot_values(this.__wbg_ptr);var e=Ze(t[0],t[1]).slice();return C.__wbindgen_free(t[0],t[1]*4,4),e}map_dynamics_to_world(t,e,s){const n=Vt(t,C.__wbindgen_malloc,C.__wbindgen_realloc),o=_t,r=C.clientcore_map_dynamics_to_world(this.__wbg_ptr,n,o,e,s);var a=Ze(r[0],r[1]).slice();return C.__wbindgen_free(r[0],r[1]*4,4),a}map_generation(){return C.clientcore_map_generation(this.__wbg_ptr)>>>0}my_game_id(){return C.clientcore_my_game_id(this.__wbg_ptr)}constructor(t){const e=Vt(t,C.__wbindgen_malloc,C.__wbindgen_realloc),s=_t,n=C.clientcore_new(e,s);if(n[2])throw Rs(n[1]);return this.__wbg_ptr=n[0],Is.register(this,this.__wbg_ptr,this),this}offset(){return C.clientcore_offset(this.__wbg_ptr)}push_frame(t,e){const s=je(t,C.__wbindgen_malloc),n=_t;return C.clientcore_push_frame(this.__wbg_ptr,s,n,e)!==0}ramp_runs(){let t,e;try{const s=C.clientcore_ramp_runs(this.__wbg_ptr);return t=s[0],e=s[1],Lt(s[0],s[1])}finally{C.__wbindgen_free(t,e,1)}}reset(){C.clientcore_reset(this.__wbg_ptr)}resync(){C.clientcore_resync(this.__wbg_ptr)}sample(t){return C.clientcore_sample(this.__wbg_ptr,t)>>>0}set_active(t){C.clientcore_set_active(this.__wbg_ptr,t)}set_map(t){const e=Vt(t,C.__wbindgen_malloc,C.__wbindgen_realloc),s=_t,n=C.clientcore_set_map(this.__wbg_ptr,e,s);if(n[1])throw Rs(n[0])}set_model(t){const e=Vt(t,C.__wbindgen_malloc,C.__wbindgen_realloc),s=_t;C.clientcore_set_model(this.__wbg_ptr,e,s)}shot_segments(t,e,s,n,o,r){const a=C.clientcore_shot_segments(this.__wbg_ptr,t,e,s,n,o,r);var l=Ze(a[0],a[1]).slice();return C.__wbindgen_free(a[0],a[1]*4,4),l}surface_at(t,e,s){return C.clientcore_surface_at(this.__wbg_ptr,t,e,s)}surface_dir_at(t,e,s){return C.clientcore_surface_dir_at(this.__wbg_ptr,t,e,s)}surface_types(){let t,e;try{const s=C.clientcore_surface_types(this.__wbg_ptr);return t=s[0],e=s[1],Lt(s[0],s[1])}finally{C.__wbindgen_free(t,e,1)}}sync_panel(t){const e=Vt(t,C.__wbindgen_malloc,C.__wbindgen_realloc),s=_t;C.clientcore_sync_panel(this.__wbg_ptr,e,s)}take_divergence(){let t,e;try{const s=C.clientcore_take_divergence(this.__wbg_ptr);return t=s[0],e=s[1],Lt(s[0],s[1])}finally{C.__wbindgen_free(t,e,1)}}take_frames(){let t,e;try{const s=C.clientcore_take_frames(this.__wbg_ptr);return t=s[0],e=s[1],Lt(s[0],s[1])}finally{C.__wbindgen_free(t,e,1)}}try_fire(t){const e=C.clientcore_try_fire(this.__wbg_ptr,t);let s;return e[0]!==0&&(s=Lt(e[0],e[1]).slice(),C.__wbindgen_free(e[0],e[1]*1,1)),s}}Symbol.dispose&&(ls.prototype[Symbol.dispose]=ls.prototype.free);function Dn(){return{__proto__:null,"./vimp_tanks_core_bg.js":{__proto__:null,__wbg_Error_92b29b0548f8b746:function(t,e){return Error(Lt(t,e))},__wbg___wbindgen_throw_344f42d3211c4765:function(t,e){throw new Error(Lt(t,e))},__wbindgen_init_externref_table:function(){const t=C.__wbindgen_externrefs,e=t.grow(4);t.set(0,void 0),t.set(e+0,void 0),t.set(e+1,null),t.set(e+2,!0),t.set(e+3,!1)}}}}const Is=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(i=>C.__wbg_clientcore_free(i,1));typeof FinalizationRegistry>"u"||new FinalizationRegistry(i=>C.__wbg_gamecore_free(i,1));function Ze(i,t){return i=i>>>0,On().subarray(i/4,i/4+t)}function Vn(i,t){return i=i>>>0,le().subarray(i/1,i/1+t)}let we=null;function On(){return(we===null||we.byteLength===0)&&(we=new Float32Array(C.memory.buffer)),we}function Lt(i,t){return Nn(i>>>0,t)}let ve=null;function le(){return(ve===null||ve.byteLength===0)&&(ve=new Uint8Array(C.memory.buffer)),ve}function je(i,t){const e=t(i.length*1,1)>>>0;return le().set(i,e/1),_t=i.length,e}function Vt(i,t,e){if(e===void 0){const a=be.encode(i),l=t(a.length,1)>>>0;return le().subarray(l,l+a.length).set(a),_t=a.length,l}let s=i.length,n=t(s,1)>>>0;const o=le();let r=0;for(;r<s;r++){const a=i.charCodeAt(r);if(a>127)break;o[n+r]=a}if(r!==s){r!==0&&(i=i.slice(r)),n=e(n,s,s=r+i.length*3,1)>>>0;const a=le().subarray(n+r,n+s),l=be.encodeInto(i,a);r+=l.written,n=e(n,s,r,1)>>>0}return _t=r,n}function Rs(i){const t=C.__wbindgen_externrefs.get(i);return C.__externref_table_dealloc(i),t}let Ye=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});Ye.decode();const Bn=2146435072;let qe=0;function Nn(i,t){return qe+=t,qe>=Bn&&(Ye=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),Ye.decode(),qe=t),Ye.decode(le().subarray(i,i+t))}const be=new TextEncoder;"encodeInto"in be||(be.encodeInto=function(i,t){const e=be.encode(i);return t.set(e),{read:i.length,written:e.length}});let _t=0,C;function Un(i,t){return C=i.exports,we=null,ve=null,C.__wbindgen_start(),C}async function Wn(i,t){if(typeof Response=="function"&&i instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(i,t)}catch(n){if(i.ok&&e(i.type)&&i.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",n);else throw n}const s=await i.arrayBuffer();return await WebAssembly.instantiate(s,t)}else{const s=await WebAssembly.instantiate(i,t);return s instanceof WebAssembly.Instance?{instance:s,module:i}:s}function e(s){switch(s){case"basic":case"cors":case"default":return!0}return!1}}async function Hn(i){if(C!==void 0)return C;i!==void 0&&(Object.getPrototypeOf(i)===Object.prototype?{module_or_path:i}=i:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),i===void 0&&(i=new URL("/assets/vimp_tanks_core_bg-GriiC3GE.wasm",import.meta.url));const t=Dn();(typeof i=="string"||typeof Request=="function"&&i instanceof Request||typeof URL=="function"&&i instanceof URL)&&(i=fetch(i));const{instance:e,module:s}=await Wn(await i,t);return Un(e)}const Gn='@charset "UTF-8";#panel table td#panel-bullet:before{content:"bullet: "}#panel table td#panel-bomb:before{content:"bomb: "}#panel table td#panel-time:before{content:"time: "}#vimp{background:#222;position:absolute;inset:0;margin:auto;z-index:1}#radar{position:absolute;right:1%;top:35px;z-index:2;border-radius:50%;background-color:#00be5acc;box-shadow:inset 0 0 47px #ee6,0 0 0 3px #054}#team1{color:#f56}#team2{color:#7ed}#spectators{color:#fe5}#team1 tHead tr,#team2 tHead tr,#spectators tHead tr{border-bottom:1px solid #888;text-transform:capitalize;font-weight:700}#team1 tBody tr,#team2 tBody tr{border-bottom:1px solid #444}#team1 tHead td:first-child:before{content:"team1 ("}#team1 tHead td:first-child:after{content:")"}#team2 tHead td:first-child:before{content:"team2 ("}#team2 tHead td:first-child:after{content:")"}#spectators tHead td:first-child:before{content:"spectators"}#spectators tBody td:nth-child(1){padding:0 1%;line-height:1.4em}#spectators tBody td:nth-child(2),#spectators tBody td:nth-child(3),#spectators tBody td:nth-child(4),#spectators tBody td:nth-child(5){display:none}',$n={mode:"hole",radius:260,softness:.45,minAlpha:.12,layerAlpha:.4,fadeRate:6,roofMargin:0,lowerTint:11579584},B={shear:.22,levelZStride:100},Rt={faceTilesPerLevel:3,faceSegments:4,faceBleedPx:2,rampSegments:4,sideTint:10133674},At={scaleGain:.1,baseAlpha:.4,alphaFalloff:.12,sizeFactor:1.05,groundOffset:3,groundAlpha:.3},It={lift:.35,vertices:6,shading:.28,lightDir:[-.7,-.7]},jt={ambient:.55,diffuse:.6,lightZ:1},Kt={duration:150,attack:.15,gunKick:1,bodyKick:0,rock:.1},Mt={enabled:!0,trackHeight:5,hullBase:2,hullTop:6,turretBase:6,turretTop:10,barrelHeight:8,barrelRadius:1.5,brakeRadius:2,levelHeight:12.8,leanGain:.3,maxLean:.6,shadowBlur:1},de={rock:.22,wobbleHz:5,decay:180,duration:700,hop:.3,hopDuration:420,underShare:.5,shake:1.2,shakeDuration:220},K={referenceSize:3,maxFire:64,maxSmoke:80,wind:{x:5,y:-3},joltRadius:18,sound:"tankExplosion",flash:{duration:180,startSize:12,endSize:40,alpha:1,color:16773576},fireball:{count:14,speed:{min:15,max:50},drag:4,size:{min:4,max:7},grow:2.2,lifetime:{min:450,max:850},rise:.5,alpha:.95},sparks:{count:12,speed:{min:70,max:160},drag:3,length:2.4,width:.5,lifetime:{min:300,max:700},colors:[16770728,16738842]},fire:{duration:9e3,fadeOut:5e3,rate:36,points:[[-.3,0],[.05,0]],spread:.4,size:{min:2.5,max:4.5},grow:1.6,lifetime:{min:300,max:650},jitter:4,rise:.35,alpha:.85,ramp:[[0,16774344],[.2,16761418],[.5,15885850],[.8,9184266],[1,2361348]]},glow:{size:28,alpha:.3,color:16747056,flicker:.35},smoke:{rate:12,tailRate:7,tail:15e3,burst:{count:12,speed:{min:12,max:30},alpha:.55},size:{min:3,max:5},grow:3.8,lifetime:{min:2600,max:4200},speed:6,drag:1.5,rise:1.4,alpha:.42,tailAlpha:.2,burning:[1315344,2762274],cooling:[4867908,6446682]},scorch:{size:26,alpha:.55,fadeIn:400}},De={speed:19e3,minDuration:45,maxDuration:80,trailLength:55,trailShare:.4,color:16751178,coreColor:16774368,coreWidth:.3,glowWidth:1.2,glowAlpha:.2,alphaStart:1,alphaEnd:.6,height:.19,fadeSteps:8},Kn={duration:35,spikes:5,length:6,width:1.6,spread:.35,jitter:.5,sideLength:2.2,sideWidth:.9,layers:[{scale:1.35,alpha:.18},{scale:1,alpha:.45},{scale:.55,alpha:.95,core:!0}],shrink:.4,color:16751178,coreColor:16774368},Pt={sand:{color:14205834,rate:24,fullSpeed:60,minSpeed:4,lifetime:{min:350,max:750},sizeFactor:1,alpha:.35},mud:{color:3878430,rate:14,fullSpeed:60,minSpeed:4,lifetime:{min:180,max:380},sizeFactor:1.8,alpha:.6},water:{color:10474751,rate:20,fullSpeed:60,minSpeed:4,lifetime:{min:250,max:550},sizeFactor:1.1,alpha:.5,sideSpeed:{min:25,max:60},entryBurst:10,entryMinSpeed:20,sound:{minVolume:.25,fullSpeed:120,rate:{min:.9,max:1.1}}},boost:{color:16765024,burst:16,lifetime:{min:200,max:420},sizeFactor:1.4,alpha:.8,tailSpeed:{min:60,max:140},boostMinSpeed:20,resetDistance:40},tracks:{oil:{alpha:2,lifetime:3,tint:2105384,trail:1.5},mud:{alpha:1.5,lifetime:1,tint:5917242},noMarks:["water"]}},Zt={fullImpact:6,squash:.14,duration:260,minImpact:1.5},Zn={maxFps:30},St={enabled:!0,resolution:.5,maxLights:96,headlights:{length:90,spread:.55,intensity:.9,color:16773572,offset:.5,occlusion:{enabled:!0,rays:64},bounce:{intensity:.35,radius:30,maxDistance:80},wash:{height:.6,intensity:1}},rampSpill:1,tankGlow:{radius:26,intensity:.35,color:12570879},flash:{explosion:{radius:140,intensity:1,duration:260,color:16756832},shot:{radius:40,intensity:.6,duration:70,color:16773280},wreck:{radius:150,intensity:1.1,duration:320,color:16752720}},wreckFire:{radius:70,intensity:.75,color:16748608,flicker:.45},glints:{enabled:!0,intensity:.8,size:1.2},shafts:{enabled:!0,rays:14,length:1.3,intensity:.35,shadows:!0,maxShadowCasters:4}},jn=B.levelZStride,W=(i,t)=>i+jn*(t||0),Fi=5,Te=(i,t)=>Math.min(i||0,Math.round(t));function ut(i,t){const e=t?.screen;return!i||i.destroyed||!e||!i.scale.x||!i.scale.y?null:{x:(e.width/2-i.position.x)/i.scale.x,y:(e.height/2-i.position.y)/i.scale.y,scaleX:i.scale.x,scaleY:i.scale.y}}function mt(i,t,e,s){return!e||!s?{x:i,y:t}:{x:i+(i-e.x)*s,y:t+(t-e.y)*s}}function gt(i,t,e,s=1){const n=typeof s=="number"?s:s.x,o=typeof s=="number"?s:s.y;if(!t||!e){i.scale.set(n,o),i.position.set(0,0);return}i.scale.set(n*(1+e),o*(1+e)),i.position.set(-t.x*e,-t.y*e)}function ke(i,t,e,s,n){if(!e)return{x:i,y:t,scale:1};const o=(1+(n||0))/(1+(s||0));return{x:e.x+(i-e.x)*o,y:e.y+(t-e.y)*o,scale:o}}function Le(i){const t=typeof i=="number"?i:i.x,e=typeof i=="number"?i:i.y;return{x:t,y:e}}function he(i,t,e){return Math.floor(i/t/e)}function qn(i,t,e){return Math.round(i/t/e)}function Jn(i,t,e){return{map:i,scale:t,step:e}}function Xi(i,t,e,s){const n=he(t,i.scale.x,i.step),o=he(e,i.scale.y,i.step),r=i.map?.[o]?.[n];return r!==void 0&&s.has(r)}function Yi(i,t,e,s,n){if(!e||!t)return!1;const o=n>0?[[0,0],[n,0],[-n,0],[0,n],[0,-n]]:[[0,0]];for(const r of s){const a=1+r;for(const[l,h]of o)if(i((t.x+l+e.x*r)/a,(t.y+h+e.y*r)/a))return!0}return!1}function Qn(i,t,e,s,n,o){return i?.map?Yi((r,a)=>Xi(i,r,a,t),e,s,n,o):!1}function to(i,t,e,s,n,o,r){return!i||i.size===0?!1:Yi((a,l)=>i.has(`${he(a,e.x,t)},${he(l,e.y,t)}`),s,n,o,r)}const Di=i=>i.radius*(1-i.softness),eo=(i,t,e)=>{if(t<=i)return e<t?0:1;const s=Math.min(1,Math.max(0,(e-i)/(t-i)));return s*s*(3-2*s)};function so({viewLevel:i,viewX:t,viewY:e,level:s,x:n,y:o,cfg:r}){if((s||0)<=(i||0))return 1;if(r.mode==="layer")return r.layerAlpha;const a=n-t,l=o-e,h=Math.sqrt(a*a+l*l),u=eo(Di(r),r.radius,h);return r.minAlpha+(1-r.minAlpha)*u}function io(i,t,e){return(t||0)<(i||0)?e.lowerTint:16777215}const no=`
|
|
2
|
+
precision highp float;
|
|
3
|
+
|
|
4
|
+
in vec2 vTextureCoord;
|
|
5
|
+
|
|
6
|
+
out vec4 finalColor;
|
|
7
|
+
|
|
8
|
+
uniform sampler2D uTexture;
|
|
9
|
+
uniform vec4 uInputSize;
|
|
10
|
+
uniform vec4 uOutputFrame;
|
|
11
|
+
|
|
12
|
+
uniform vec2 uHoleCenter;
|
|
13
|
+
// x - внешний радиус, y - внутренний, z - alpha в центре дыры
|
|
14
|
+
uniform vec3 uHoleParams;
|
|
15
|
+
|
|
16
|
+
void main(void)
|
|
17
|
+
{
|
|
18
|
+
vec4 color = texture(uTexture, vTextureCoord);
|
|
19
|
+
vec2 pixel = uOutputFrame.xy + vTextureCoord * uInputSize.xy;
|
|
20
|
+
float d = distance(pixel, uHoleCenter);
|
|
21
|
+
float t = smoothstep(uHoleParams.y, uHoleParams.x, d);
|
|
22
|
+
|
|
23
|
+
finalColor = color * mix(uHoleParams.z, 1.0, t);
|
|
24
|
+
}
|
|
25
|
+
`,Fs=`
|
|
26
|
+
struct GlobalFilterUniforms {
|
|
27
|
+
uInputSize:vec4<f32>,
|
|
28
|
+
uInputPixel:vec4<f32>,
|
|
29
|
+
uInputClamp:vec4<f32>,
|
|
30
|
+
uOutputFrame:vec4<f32>,
|
|
31
|
+
uGlobalFrame:vec4<f32>,
|
|
32
|
+
uOutputTexture:vec4<f32>,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
struct HoleUniforms {
|
|
36
|
+
uHoleCenter:vec2<f32>,
|
|
37
|
+
uHoleParams:vec3<f32>,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
|
|
41
|
+
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
|
42
|
+
@group(0) @binding(2) var uSampler : sampler;
|
|
43
|
+
|
|
44
|
+
@group(1) @binding(0) var<uniform> holeUniforms : HoleUniforms;
|
|
45
|
+
|
|
46
|
+
struct VSOutput {
|
|
47
|
+
@builtin(position) position: vec4<f32>,
|
|
48
|
+
@location(0) uv : vec2<f32>
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
|
|
52
|
+
{
|
|
53
|
+
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
|
54
|
+
|
|
55
|
+
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
|
56
|
+
position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y)
|
|
57
|
+
- gfu.uOutputTexture.z;
|
|
58
|
+
|
|
59
|
+
return vec4(position, 0.0, 1.0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
|
63
|
+
{
|
|
64
|
+
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@vertex
|
|
68
|
+
fn mainVertex(@location(0) aPosition : vec2<f32>) -> VSOutput {
|
|
69
|
+
return VSOutput(
|
|
70
|
+
filterVertexPosition(aPosition),
|
|
71
|
+
filterTextureCoord(aPosition)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@fragment
|
|
76
|
+
fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
|
|
77
|
+
var color = textureSample(uTexture, uSampler, uv);
|
|
78
|
+
var pixel = gfu.uOutputFrame.xy + uv * gfu.uInputSize.xy;
|
|
79
|
+
var d = distance(pixel, holeUniforms.uHoleCenter);
|
|
80
|
+
var t = smoothstep(holeUniforms.uHoleParams.y, holeUniforms.uHoleParams.x, d);
|
|
81
|
+
|
|
82
|
+
return color * mix(holeUniforms.uHoleParams.z, 1.0, t);
|
|
83
|
+
}
|
|
84
|
+
`;function oo(i){const t=new Ne({uHoleCenter:{value:new Float32Array([0,0]),type:"vec2<f32>"},uHoleParams:{value:new Float32Array([i.radius,Di(i),i.minAlpha]),type:"vec3<f32>"}});return new Ln({glProgram:xs.from({vertex:zn,fragment:no,name:"see-through-hole-filter"}),gpuProgram:Pn.from({vertex:{source:Fs,entryPoint:"mainVertex"},fragment:{source:Fs,entryPoint:"mainFragment"}}),resources:{holeUniforms:t}})}function ro(i,{centerX:t,centerY:e,radius:s,softness:n,minAlpha:o}){const r=i.resources.holeUniforms.uniforms;r.uHoleCenter[0]=t,r.uHoleCenter[1]=e,r.uHoleParams[0]=s,r.uHoleParams[1]=s*(1-n),r.uHoleParams[2]=o}const ao=.01;function hs(){return{strength:0,filter:null,attached:!1,tick:null}}function Vi(i,t){const e=Q.shared.lastTime;return i.tick===e?0:(i.tick=e,Math.min(1,t*(Q.shared.deltaMS/1e3)))}function ws(i,t,e){return i.strength+=((t?1:0)-i.strength)*e,i.strength}function Oi(i,t){return 1+(t.minAlpha-1)*i.strength}function vs(i,t,e,s,n,o){if(t.strength<ao||!n){t.attached&&(i.filters=[],t.attached=!1);return}t.filter||(t.filter=oo(e)),t.attached||(i.filters=[t.filter],t.attached=!0);const r=mt(s.x,s.y,o,s.z*B.shear);ro(t.filter,{centerX:r.x*n.scale.x+n.position.x,centerY:r.y*n.scale.y+n.position.y,radius:e.radius*n.scale.x,softness:e.softness,minAlpha:Oi(t,e)})}function cs(i,t){if(!i.filter){i.attached=!1;return}t.filters=[],i.attached=!1,i.filter.destroy(),i.filter=null}async function Bi(i,t){const e={};t.frames.forEach((o,r)=>{const[a,l,h,u]=o;e[`frame${r}`]={frame:{x:a,y:l,w:h,h:u}}});const s={frames:e,meta:{scale:"1"}},n=new Cn(i,s);return await n.parse(),n}async function Ms({baseTexture:i,spriteSheetData:t,map:e,tiles:s,step:n,renderer:o,exclude:r=[]}){const a=await Bi(i,t),l=new Set(r),h=s.filter(p=>!l.has(p)),u=e[0].length*n,c=e.length*n,_=new $;for(let p=0,d=e.length;p<d;p+=1)for(let g=0,m=e[p].length;g<m;g+=1){const w=e[p][g];if(h.includes(w)){const M=`frame${w}`,b=a.textures[M];if(b){const v=new J(b);v.x=g*n,v.y=p*n,_.addChild(v)}else console.warn(`Texture not found. Tile: ${w}, sprite: ${M}`)}}const f=o.generateTexture({target:_,frame:new rt(0,0,u,c)});return _.destroy({children:!0}),a.destroy(),f}function lo(i,t){const e=[];if(!Array.isArray(i))return e;for(const s of i){const n=s.axis===0?0:1,o=n===0?1:0,r=t(s.min,n),a=t(s.max,n),l=t(s.crossMin,o),h=t(s.crossMax,o),u=typeof s.railMin=="number"&&typeof s.railMax=="number";e.push({axis:s.axis,sign:s.sign,from:s.from,to:s.to,block:s.block,rail0:u?t(s.railMin,n):null,rail1:u?t(s.railMax,n):null,col0:n===0?r:l,col1:n===0?a:h,row0:n===0?l:r,row1:n===0?h:a})}return ho(e)}function ho(i){const t=new Map;for(const s of i){const n=t.get(s.block);n?n.push(s):t.set(s.block,[s])}const e=[];for(const s of t.values()){const n=a=>a.axis===1?a.col0:a.row0,o=a=>a.axis===1?a.col1:a.row1;s.sort((a,l)=>n(a)-n(l));let r=null;for(const a of s){if(r&&n(a)===o(r)){r.axis===1?r.col1=a.col1:r.row1=a.row1;continue}r={...a},e.push(r)}}return e}function Ss(i){const t=new En(i);return t.geometry.batchMode="batch",t}const co=1e-6,uo=1e3,Ni=[0,1,3,0,3,2];function fo(i,t){const e=[],s=i.length,n=i.reduce((r,a)=>Math.max(r,a.length),0),o=(r,a)=>{const l=i[a]?.[r];return l!==void 0&&t.has(l)};for(let r=0;r<s;r+=1)for(let a=0;a<n;a+=1)if(o(a,r)){for(const l of[-1,1]){if(o(a,r+l))continue;const h=l<0?r:r+1;e.push({tile:i[r][a],col:a,row:r,nx:0,ny:l,x0:a,y0:h,x1:a+1,y1:h})}for(const l of[-1,1]){if(o(a+l,r))continue;const h=l<0?a:a+1;e.push({tile:i[r][a],col:a,row:r,nx:l,ny:0,x0:h,y0:r,x1:h,y1:r+1})}}return e}function Ui(i,t){return Math.max(1,Math.ceil(i*t-1e-9))}function _o({map:i,tiles:t,step:e,baseScale:s,level:n,volume:o,shear:r,sideTint:a,textures:l,tilesPerLevel:h=1,segments:u=1}){const c=fo(i,new Set(t)),_=n*r,f=(n+o)*r,p=f-co,d=Math.max(1,Math.ceil(o*u-1e-9)),g=Ui(o,h),m=o*h/g,w=(d+1)*2,M=Math.max(1,Math.floor(uo/d)),b=[],v=new Map;for(const S of c)v.has(S.tile)||v.set(S.tile,[]),v.get(S.tile).push(S);for(const[S,y]of v){const z=l?.get(S);if(!z){console.warn(`buildVolumeWalls: no side texture for tile ${S}`);continue}for(let T=0;T<y.length;T+=M){const L=y.slice(T,T+M),R=L.length,D=R*w,I=new Float32Array(D*2),X=new Float32Array(D),Y=new Float32Array(D*2),N=new Uint32Array(R*d*6),V=new Float32Array(R*2),G=new Float32Array(R*2);for(let H=0;H<R;H+=1){const{nx:xt,ny:Ct,x0:Bt,y0:Nt,x1:Ut,y1:Wt}=L[H],nt=Bt*e,Ht=Nt*e,Gt=Ut*e,ft=Wt*e,x=H*w;for(let k=0;k<=d;k+=1)for(let P=0;P<2;P+=1){const A=x+k*2+P;I[A*2]=(P===1?Gt:nt)*s.x,I[A*2+1]=(P===1?ft:Ht)*s.y,X[A]=f-(f-_)*k/d,Y[A*2]=P,Y[A*2+1]=m*k/d}for(let k=0;k<d;k+=1){const P=x+k*2,A=(H*d+k)*6;for(let E=0;E<6;E+=1)N[A+E]=P+Ni[E]}V[H*2]=xt,V[H*2+1]=Ct,G[H*2]=(nt+Gt)/2*s.x,G[H*2+1]=(Ht+ft)/2*s.y}const j=Ss({texture:z,vertices:I.slice(),uvs:Y,indices:N});j.tint=a,b.push({target:j,k:p,base:I,heights:X,rows:d,k0:_,k1:f,occluder:!0,walls:!0,normals:V,centers:G,facing:new Uint8Array(R).fill(2)})}}return b}function Wi(i,t,e){return i.cameraX===t.x&&i.cameraY===t.y&&i.cameraScale===t.scaleX&&i.cameraBleed===e?!0:(i.cameraX=t.x,i.cameraY=t.y,i.cameraScale=t.scaleX,i.cameraBleed=e,!1)}function po(i,t,e=0){if(Wi(i,t,e))return;const{target:s,base:n,heights:o,rows:r}=i,a=s.vertices,l=(r+1)*2,h=e&&t.scaleX?e/t.scaleX:0;for(let u=0,c=o.length;u<c;u+=1){const _=n[u*2],f=n[u*2+1],p=_-t.x,d=f-t.y,g=u%l<2,m=Math.sqrt(p*p+d*d)||1e-6,w=o[u]+(g?h/m:0);a[u*2]=_+p*w,a[u*2+1]=f+d*w}s.vertices=a}function mo(i,t){if(i.orderX===t.x&&i.orderY===t.y)return!1;i.orderX=t.x,i.orderY=t.y;const{target:e,normals:s,centers:n,facing:o,rows:r}=i,a=o.length,l=(r+1)*2;let h=!1;for(let _=0;_<a;_+=1){const p=s[_*2]*(t.x-n[_*2])+s[_*2+1]*(t.y-n[_*2+1])>0?1:0;o[_]!==p&&(o[_]=p,h=!0)}if(!h)return!1;const u=e.geometry.indices;let c=0;for(let _=0;_<2;_+=1)for(let f=0;f<a;f+=1)if(o[f]===_)for(let p=0;p<r;p+=1){const d=f*l+p*2;for(let g=0;g<6;g+=1)u[c]=d+Ni[g],c+=1}return e.geometry.indices=u,!0}function go({runs:i,texture:t,step:e,shear:s,baseScale:n,segments:o,sideTint:r}){const a=[],l=t.width||1,h=t.height||1,u=Math.max(1,Math.round(o)||1);for(const c of i){const _=c.axis===0,f=_?c.col1-c.col0:c.row1-c.row0,p=Math.max(1,f*u),d=_?c.col0:c.row0,g=typeof c.rail0=="number"&&typeof c.rail1=="number"?{first:(c.rail0-d)*u,last:(c.rail1-d)*u}:null,m=c.col0*e,w=c.col1*e,M=c.row0*e,b=c.row1*e,v=p+1,S=Math.min(c.from,c.to),y=Math.max(c.from,c.to),z=S*s,T=new Float32Array(v*4),L=new Float32Array(v*4),R=new Float32Array(v*4),D=new Float32Array(v*2),I=new Uint32Array(p*6),X=1;for(let N=0;N<v;N+=1){const V=N/p,G=c.sign>0?V:1-V,j=(c.from+(c.to-c.from)*G)*s,H=_?m:M,Ct=H+((_?w:b)-H)*V,Bt=_?Ct:m,Nt=_?M:Ct,Ut=_?Ct:w,Wt=_?b:Ct,nt=N*4;T[nt]=Bt*n.x,T[nt+1]=Nt*n.y,T[nt+2]=Ut*n.x,T[nt+3]=Wt*n.y,L[nt]=Bt/l,L[nt+1]=Nt/h,L[nt+2]=Ut/l,L[nt+3]=Wt/h;const Ht=_?Nt+X:Bt+X,Gt=_?Wt-X:Ut-X,ft=Math.min(Math.max(Ct,(_?m:M)+X),(_?w:b)-X);R[nt]=(_?ft:Ht)/l,R[nt+1]=(_?Ht:ft)/h,R[nt+2]=(_?ft:Gt)/l,R[nt+3]=(_?Gt:ft)/h,D[N*2]=j,D[N*2+1]=j}for(let N=0;N<p;N+=1){const V=N*2,G=N*6;I[G]=V,I[G+1]=V+1,I[G+2]=V+3,I[G+3]=V,I[G+4]=V+3,I[G+5]=V+2}const Y=Ss({texture:t,vertices:T.slice(),uvs:L,indices:I});a.push(xo({base:T,uvs:R,heights:D,points:v,texture:t,kBase:z,sideTint:r,endIndex:c.sign>0?v-1:0,rails:g})),a.push({target:Y,k:y*s,base:T,heights:D})}return a}function xo(i){const{base:t,uvs:e,heights:s,points:n,texture:o,kBase:r,endIndex:a,sideTint:l,rails:h}=i,u=h?Math.max(0,Math.min(h.first,n-1)):0,c=h?Math.max(u,Math.min(h.last,n-1)):-1,_=h?c-u+1:0,f=_*2+2,p=new Float32Array(f*4),d=new Float32Array(f*4),g=new Float32Array(f*2),m=Math.max(0,_-1)*2+1,w=new Uint32Array(m*6),M=S=>S<_?(u+S)*2:S<_*2?(u+S-_)*2+1:a*2+(S-_*2);for(let S=0;S<f;S+=1){const y=M(S),z=S*4,T=t[y*2],L=t[y*2+1];p[z]=T,p[z+1]=L,p[z+2]=T,p[z+3]=L,d[z]=e[y*2],d[z+1]=e[y*2+1],d[z+2]=e[y*2],d[z+3]=e[y*2+1],g[S*2]=s[y],g[S*2+1]=r}let b=0;for(let S=0;S<3;S+=1){const y=S===2?_*2:S*_,z=S===2?_*2+1:y+_-1;for(let T=y;T<z;T+=1){const L=T*2,R=b*6;w[R]=L,w[R+1]=L+1,w[R+2]=L+3,w[R+3]=L,w[R+4]=L+3,w[R+5]=L+2,b+=1}}const v=Ss({texture:o,vertices:p.slice(),uvs:d,indices:w});return v.tint=l,{target:v,k:r,base:p,heights:g}}function yo(i,t){if(Wi(i,t,0))return;const{target:e,base:s,heights:n}=i,o=e.vertices;for(let r=0,a=n.length;r<a;r+=1){const l=s[r*2],h=s[r*2+1],u=n[r];o[r*2]=l+(l-t.x)*u,o[r*2+1]=h+(h-t.y)*u}e.vertices=o}const _e={mapSprite:null,occluder:null,slices:[],rampTexture:null,wallTextures:[]};function wo({mapSprite:i,bakedTexture:t,occluder:e,slices:s,rampTexture:n,wallTextures:o}){for(const r of s)r.target.parent?.removeChild(r.target),r.target.destroy({texture:!1,textureSource:!1});e?.destroy({children:!0,texture:!1,textureSource:!1}),n&&n.destroy(!0);for(const r of o??[])r.destroy(!0);i&&(i.parent?.removeChild(i),i.destroy({texture:!1,textureSource:!1})),t?.destroy(!0)}async function vo(i){try{const t=await i.baseTexture;if(i.isAborted())return _e;const e=await Ms({baseTexture:t,spriteSheetData:i.spriteSheetData,map:i.map,tiles:i.tiles,step:i.step,renderer:i.renderer,exclude:i.exclude});if(i.isAborted())return e.destroy(!0),_e;const s=new J(e);if(i.layerRoot.addChildAt(s,0),!i.extruding)return{..._e,mapSprite:s};const n=await Mo(i,t,e),o={mapSprite:s,...n};return i.isAborted()?(wo({...o,bakedTexture:e}),_e):o}catch(t){return console.error(`Failed to create static map with asset ${i.assetUrl}:`,t),_e}}async function Mo(i,t,e){const s=B.shear,n=[],o=[];let r=null,a=null;if(i.volume>0){r=new $,r.zIndex=W(Math.max(i.layer,Fi),i.level);{const h=await So(i,t,o);if(i.isAborted())return{occluder:r,slices:n,rampTexture:a,wallTextures:o};n.push(..._o({map:i.map,tiles:i.tiles,step:i.step,baseScale:i.baseScale,level:i.level,volume:i.volume,shear:s,sideTint:Rt.sideTint,textures:h,tilesPerLevel:Rt.faceTilesPerLevel,segments:Rt.faceSegments}));const u=new J(e);u.tint=16777215,n.push({target:u,k:(i.level+i.volume)*s,occluder:!0})}}const l=Hi(i);if(l.length){if(a=await Ms({baseTexture:t,spriteSheetData:i.spriteSheetData,map:i.map,tiles:i.ramps.map(h=>h.tile),step:i.step,renderer:i.renderer}),i.isAborted())return{occluder:r,slices:n,rampTexture:a,wallTextures:o};n.push(...go({runs:l,texture:a,step:i.step,shear:s,baseScale:i.baseScale,segments:Rt.rampSegments,sideTint:Rt.sideTint}))}if(i.isAborted())return{occluder:r,slices:n,rampTexture:a,wallTextures:o};n.sort((h,u)=>h.k-u.k);for(const h of n)h.base||gt(h.target,null,h.k,i.baseScale),(h.occluder?r:i.container).addChild(h.target);return{occluder:r,slices:n,rampTexture:a,wallTextures:o}}async function So(i,t,e){const s=new Map,n=Ui(i.volume,Rt.faceTilesPerLevel);for(const o of i.tiles){const r=await Ms({baseTexture:t,spriteSheetData:i.spriteSheetData,map:Array.from({length:n},()=>[o]),tiles:[o],step:i.step,renderer:i.renderer});e.push(r),s.set(o,r)}return s}function Hi(i){if(!i.ramps?.length||!i.rampRuns)return[];const t=new Set(i.ramps.map(n=>`${n.from}:${n.to}`)),e=i.rampRuns.forLevel(i.level).filter(n=>t.has(`${n.from}:${n.to}`));return lo(e,(n,o)=>qn(n,o===0?i.baseScale.x:i.baseScale.y,i.step))}function bo(i,t){if(!i.levelView)return;const e=i.levelView.cfg,s=Vi(i.hole,e.fadeRate);i.hasSprite&&ko(i,e,s,t),i.occluder&&To(i,e,s,t)}function ko(i,t,e,s){const{levelView:n,container:o}=i,r=i.roof?n.level<i.level&&Lo(i,t,s):null;if(n.mode==="layer"){const h=(i.roof?r:n.level<i.level&&Xi(i.grid,n.x,n.y,i.floorSet))?t.layerAlpha:1;o.alpha+=(h-o.alpha)*e;return}const a=i.roof?r:n.level<i.level;ws(i.hole,a,e),vs(o,i.hole,t,n,i.stage,s)}function To(i,t,e,s){const{levelView:n,occluder:o}=i,r=i.level>n.level;if(n.mode==="layer"){const a=r?t.layerAlpha:1;o.alpha+=(a-o.alpha)*e;return}ws(i.occluderHole,r,e),vs(o,i.occluderHole,t,n,i.stage,s)}function Ao(i,t){const e=i.levelView;return mt(e.x,e.y,t,e.z*B.shear)}function Lo(i,t,e){return e?Qn(i.grid,i.tileSet,Ao(i,e),e,[i.level*B.shear],t.roofMargin??0):!1}const Po=40,Gi=45,zo=1.5;function Co(i){let t=2166136261;for(let e=0;e<i.length;e+=1)t^=i.charCodeAt(e),t=Math.imul(t,16777619)>>>0;return t>>>0}function Eo(i){const t=i?.map?.length||0,e=i?.map?.[0]?.length||0,s=Co(JSON.stringify(i?.game?.lighting??null));return`${e}x${t}:${s.toString(16)}`}function Io(i,t,e,s){const{x:n,y:o}=Le(s);return{x:(i+.5)*e*n,y:(t+.5)*e*o}}function Xs(i,t){const e=new Set(t||[]),s=[];if(!i||e.size===0)return s;for(let n=0;n<i.length;n+=1){const o=i[n]||[];for(let r=0;r<o.length;r+=1)e.has(o[r])&&s.push([r,n])}return s}function Ys(i){const t=new Map;for(const[s,n]of i)t.has(n)||t.set(n,new Set),t.get(n).add(s);const e=[];for(const s of[...t.keys()].sort((n,o)=>n-o)){const n=[...t.get(s)].sort((a,l)=>a-l);let o=n[0],r=n[0];for(let a=1;a<=n.length;a+=1){const l=n[a];l===r+1||(e.push({col:o,row:s,length:r-o+1}),o=l),r=l}}return e}function Ve(i,t,e,s,n,o){const r=e*o,a=mt(i,t,s,r);return{x:a.x,y:a.y,scale:1+r,screenX:a.x*n.scale.x+n.position.x,screenY:a.y*n.scale.y+n.position.y}}function $i(i,t,e){return!e&&Math.abs(t-Math.round(t))>.001?[Math.floor(t),Math.ceil(t)]:[Te(i,t)]}function us(i,t,e,s,n){return i+e>=0&&i-e<=s&&t+e>=0&&t-e<=n}function ce(i,t,e){if(!e)return 1;const s=t/1e3,n=Math.sin(s*7.3+i*12.9898)*.5+Math.sin(s*13.1+i*78.233)*.3+Math.sin(s*23.7+i*3.7)*.2;return 1-e*((n+1)/2)}function Ki(i,t){if(!(t>0)||i>=t)return 0;const e=1-Math.max(0,i)/t;return e*e}function Zi(i){return(1-i)*(1-i)}const Ro=.35;function ji(i){return(1-i)*(1-i*Ro)}function Fo(i,t){return!(t>0)||i>=t?0:Zi(Math.max(0,i)/t)}function qi(i,t,e){const s=t-i.x,n=e-i.y,o=i.intensity??1;if(i.kind!=="cone")return o*Fo(Math.hypot(s,n),i.radius);const r=Math.cos(i.rotation||0),a=Math.sin(i.rotation||0),l=s*r+n*a,h=Math.abs(n*r-s*a);if(!(i.radius>0)||l<=0||l>=i.radius)return 0;const u=l*(i.spread??.5);if(h>=u)return 0;const c=l/i.radius;return o*ji(c)*(1-h/u)}function Xo(i,t,e,s){const n=[];for(const{light:o,factor:r}of i){const a=qi(o,t,e)*r;a>0&&n.push({light:o,strength:a,angle:Math.atan2(o.y-e,o.x-t),color:o.color??16777215})}return n.sort((o,r)=>r.strength-o.strength),n.slice(0,Math.max(0,s))}const Ji=(i,t)=>`${i},${t}`;function Yo(i,t){const e=t>0?t:1,s=new Map;for(const n of i){const o=n.radius||0,r=Math.floor((n.x-o)/e),a=Math.floor((n.x+o)/e),l=Math.floor((n.y-o)/e),h=Math.floor((n.y+o)/e);for(let u=l;u<=h;u+=1)for(let c=r;c<=a;c+=1){const _=Ji(c,u);s.has(_)||s.set(_,[]),s.get(_).push(n)}}return{cellSize:e,cells:s}}function Do(i,t,e){if(!i)return[];const s=Math.floor(t/i.cellSize),n=Math.floor(e/i.cellSize);return i.cells.get(Ji(s,n))||[]}function Vo(i,t,e,s,n,o){const r=Math.hypot(e-i,s-t);if(!(n>0)||r<=n)return null;const a=Math.sqrt(r*r-n*n);if(a>=o)return null;const l=Math.atan2(s-t,e-i),h=Math.asin(n/r),u=l-h,c=l+h;return[i+Math.cos(u)*a,t+Math.sin(u)*a,i+Math.cos(u)*o,t+Math.sin(u)*o,i+Math.cos(c)*o,t+Math.sin(c)*o,i+Math.cos(c)*a,t+Math.sin(c)*a]}function Oo(i,t,e){const s=t/1e3;return e*(Math.sin(s*.37+i*1.7)*.6+Math.sin(s*.61+i*4.1)*.4)}function Bo(i=Q.shared){let t=null,e=0;return{now(){const s=i.lastTime;return s!==t&&(t!==null&&(e+=Math.max(0,s-t)/1e3),t=s),e}}}const No=Bo();function Uo(i,t){return Math.floor(i*t)/t}function Wo(i){return new Set(Object.keys(i||{}).map(Number))}function Ho(i,t,e=1){if(i.speed!==void 0){const s=i.frames?.length||0,n=t*(typeof e=="number"?e:e.x);return n>0?i.speed*s/n:0}return i.fps||0}function Qi(i,t,e){return!(e>0)||!(t>0)?0:Math.floor(i*t)%e}function Go(i,t,e){const s=new $,n=[];if(s.label="animatedTiles",!e)return{container:s,groups:n};const o=new Set(i.tiles);for(const[r,a]of Object.entries(e)){const l=Number(r);if(!o.has(l))continue;const h=(a.frames||[]).map(c=>t.textures[`frame${c}`]).filter(Boolean);if(h.length===0){console.warn(`Animated tile ${l}: no frames found in the sprite sheet`);continue}const u={id:l,fps:Ho(a,i.step,i.scale),textures:h,sprites:[],container:new $,frame:0};u.container.label=`animatedTile-${l}`;for(let c=0;c<i.map.length;c+=1){const _=i.map[c];for(let f=0;f<_.length;f+=1){if(_[f]!==l)continue;const p=new J(h[0]);p.x=f*i.step,p.y=c*i.step,p.cullable=!0,u.sprites.push(p),u.container.addChild(p)}}if(u.sprites.length===0){u.container.destroy();continue}s.addChild(u.container),n.push(u)}return{container:s,groups:n}}function $o(i,t,e=()=>!0){for(let s=0;s<i.length;s+=1){const n=i[s];if(!e(n.container))continue;const o=Qi(t,n.fps,n.textures.length);if(o===n.frame)continue;n.frame=o;const r=n.textures[o];for(let a=0;a<n.sprites.length;a+=1)n.sprites[a].texture=r}}function Ko(i){i.container.parent?.removeChild(i.container),i.container.destroy({children:!0,texture:!1,textureSource:!1}),i.groups.length=0}function Ds(i,t,e){return(i||[]).filter(s=>(s.level||0)===t&&Number(s.layer)===e)}function Zo(i,t,e,s){const n=[];for(const o of i){const[r,a]=o.cell||[0,0],h=(o.kind==="frames"?o.frames||[o.frame]:[o.frame]).map(c=>t.textures[`frame${c}`]).filter(Boolean);if(h.length===0){console.warn(`Decal at [${r}, ${a}]: frame not found in the sprite sheet`);continue}const u=new J(h[0]);u.anchor.set(.5),u.position.set((r+.5)*e,(a+.5)*e),s.addChild(u),n.push({item:o,sprite:u,textures:h,frame:0})}return n}function jo(i,t){for(let e=0;e<i.length;e+=1){const s=i[e];if(s.item.kind==="rotate"){s.sprite.rotation=(s.item.rps||0)*2*Math.PI*t;continue}if(s.item.kind==="frames"){const n=Qi(t,s.item.fps,s.textures.length);n!==s.frame&&(s.frame=n,s.sprite.texture=s.textures[n])}}}function qo(i){for(const t of i)t.sprite.parent?.removeChild(t.sprite),t.sprite.destroy({texture:!1,textureSource:!1});i.length=0}const Jo=.8,Je=.6,Vs=.09,Qo=.12,tr=.55;function tn(i){let t=i+2654435769>>>0;return t=Math.imul(t^t>>>16,2246822507)>>>0,t=Math.imul(t^t>>>13,3266489909)>>>0,(t^t>>>16)>>>0}function er(i,t,e=0){return tn((Math.imul(i,73856093)^Math.imul(t,19349663)^Math.imul(e,83492791))>>>0)}function Os(i,t,e){return tn((i^Math.imul(t+e,668265261))>>>0)/4294967296}const pe=i=>Math.min(1,Math.max(0,i));function sr(i,t,e){if(!(e>0))return!1;const s=Math.floor(i/Je);if(Os(t,s,0)>=e)return!1;const n=s*Je+Os(t,s,1)*(Je-Vs);return i>=n&&i<n+Vs}function ir(i,t,e){const s=pe(e?.pulse||0),n=t%1e3/1e3,o=1-s*(.5+.5*Math.sin(2*Math.PI*(Jo*i+n)));return sr(i,t,e?.dropouts||0)?{core:pe(o*Qo),glow:pe(o*tr)}:{core:pe(o),glow:pe(o)}}const nr=4;function Tt(i){return Math.ceil(i*nr)}function en(i){return Tt(i)*2}const fs=new WeakMap;function sn({text:i,size:t}){return`${t}|${i}`}function or(i){return Math.max(2,Math.round(i/4))}function rr(i,{text:t,size:e}){const s=or(e),n=Tt(s),o=new $,r=new Ci({text:String(t),style:{fontFamily:"monospace",fontWeight:"bold",fontSize:e,fill:16777215}});r.position.set(n,n),o.addChild(r);const a=new rt(0,0,Math.ceil(r.width)+n*2,Math.ceil(r.height)+n*2),l=i.generateTexture({target:o,frame:a}),h=new ys({strength:s,quality:6});h.padding=en(s),r.filters=[h];const u=i.generateTexture({target:o,frame:a});return r.filters=[],h.destroy(),o.destroy({children:!0}),{core:l,glow:u}}function ar(i,t){let e=fs.get(i);e||(e=new Map,fs.set(i,e));const s=sn(t);let n=e.get(s);return n||(n={...rr(i,t),count:0},e.set(s,n)),n.count+=1,{core:n.core,glow:n.glow}}function lr(i,t){const e=fs.get(i),s=sn(t),n=e?.get(s);n&&(n.count-=1,!(n.count>0)&&(e.delete(s),n.core.destroy(!0),n.glow.destroy(!0)))}class hr{constructor({sign:t,renderer:e,lighting:s,animated:n,step:o,scale:r,level:a}){const[l,h]=t.cell||[0,0];this._sign=t,this._renderer=e,this._lighting=s||null,this._level=a,this._seed=er(l,h,a),this._scale=r,this._light=null,this._gridX=(l+.5)*o,this._gridY=(h+.5)*o,this._worldX=this._gridX*r.x,this._worldY=this._gridY*r.y;const u=ar(e,t);this.glow=this._sprite(u.glow),this.core=this._sprite(u.core),this.emissive=!!this._lighting?.addEmissive(this.glow,a)&&this._lighting.addEmissive(this.core,a),this.emissive?t.light&&(this._light=this._lighting.addLight({kind:"radial",level:a,x:this._worldX,y:this._worldY,z:a,radius:t.light.radius??0,color:t.color??16777215,intensity:t.light.intensity??1})):(this._lighting?.removeEmissive(this.glow),this.glow.position.set(this._gridX,this._gridY),this.core.position.set(this._gridX,this._gridY),n.addChild(this.glow,this.core))}_sprite(t){const e=new J(t);return e.anchor.set(.5),e.blendMode="add",e.tint=this._sign.color??16777215,e.angle=this._sign.angle||0,e}update(t,e,s,n=null){const o=t===null?{core:1,glow:1}:ir(t,this._seed,this._sign.flicker);if(!this.emissive){this.glow.alpha=o.glow,this.core.alpha=o.core;return}const r=this._level*B.shear,a=mt(this._worldX,this._worldY,e,r);let l=1;n!==null?l=n:s&&(l=s.alphaFor(this._level,a.x,a.y,0));for(const h of[this.glow,this.core])h.position.set(a.x,a.y),h.scale.set(this._scale.x*(1+r),this._scale.y*(1+r));this.glow.alpha=l*o.glow,this.core.alpha=l*o.core,this._light&&this._lighting.updateLight(this._light,{intensity:(this._sign.light.intensity??1)*o.glow})}destroy(){this._lighting&&(this._light&&(this._lighting.removeLight(this._light),this._light=null),this._lighting.removeEmissive(this.glow),this._lighting.removeEmissive(this.core));for(const s of[this.glow,this.core])s.parent?.removeChild(s),s.destroy({texture:!1,textureSource:!1});const t=this._renderer,e=this._sign;return this._lighting=null,this._renderer=null,()=>lr(t,e)}}function cr(i,t,e,s){const n=Wo(i?.animatedTiles),o=new Set(t);return{exclude:[...n],hasTiles:[...n].some(r=>o.has(r)),signs:Ds(i?.signs,e,s),decals:Ds(i?.decals,e,s)}}function Bs(i){return i.hasTiles||i.signs.length>0||i.decals.length>0}async function ur({spec:i,game:t,baseTexture:e,spriteSheetData:s,map:n,tiles:o,step:r,scale:a,level:l,animated:h,renderer:u,lighting:c,isAborted:_}){let f=null;if((i.hasTiles||i.decals.length>0)&&(f=await Bi(e,s),_()))return f.destroy(),null;const p={sheet:f,tiles:null,decals:[],signs:[],tick:null};return i.hasTiles&&(p.tiles=Go({map:n,tiles:o,step:r,scale:a},f,t.animatedTiles),h.addChild(p.tiles.container)),f&&(p.decals=Zo(i.decals,f,r,h)),p.signs=i.signs.map(d=>new hr({sign:d,renderer:u,lighting:c,animated:h,step:r,scale:a,level:l})),p}function fr(i){return i?t=>{const e=t.getBounds();return e.maxX>=0&&e.minX<=i.width&&e.maxY>=0&&e.minY<=i.height}:()=>!0}function dr(i,{camera:t,levelView:e,screen:s,roofAlpha:n=null}){const o=Uo(No.now(),Zn.maxFps),r=Q.shared.lastTime;i.tick!==r&&(i.tick=r,i.tiles&&$o(i.tiles.groups,o,fr(s)),jo(i.decals,o));for(let a=0;a<i.signs.length;a+=1)i.signs[a].update(o,t,e,n)}function _r(i){if(!i)return()=>{};i.tiles&&(Ko(i.tiles),i.tiles=null),qo(i.decals);const t=i.signs.map(s=>s.destroy()),e=i.sheet;return i.signs=[],i.sheet=null,()=>{t.forEach(s=>s()),e?.destroy()}}class pr{constructor(t,e,s,n,o={}){this._container=t,this._renderer=s.renderer,this._levelView=s.levelView||null,this._levelView?.setDiagnostics(s.diagnostics??null),this._rampRuns=s.rampRuns||null,this._hole=hs(),this._occluderHole=hs(),this._occluder=null,this._baseScale=Le(e.scale),this._slices=[],this._rampTexture=null,this._wallTextures=[],this.mapSprite=null,this._assetUrl=`${n}${e.spriteSheet.img}`,this._baseTexturePromise=as.load(this._assetUrl),this._map=e.map,this._tiles=e.tiles,this._level=e.level||0,this._floor=e.floor||[],this._tileSet=new Set(this._tiles),this._floorSet=new Set(this._floor),this._roof=mr(e.game,this._level,this._tiles),this._spriteSheetData=e.spriteSheet,this._step=e.step,this._layer=Number(e.layer)||1,t.zIndex=W(this._layer,this._level),this._parallaxK=this._level*B.shear,this._layerRoot=new $,this._layerRoot.label="layerRoot",this._animated=new $,this._animated.label="animated",this._layerRoot.addChild(this._animated),gt(this._layerRoot,null,this._parallaxK,this._baseScale),t.addChild(this._layerRoot),this._animationSpec=cr(e.game,this._tiles,this._level,this._layer),this._animations=null,this._game=e.game,this._volume=Number(e.volume)||0,this._ramps=(e.ramps||[]).filter(r=>this._tiles.includes(r.tile)),this._extruding=this._volume>0||this._ramps.length>0,this._grid=Jn(this._map,this._baseScale,this._step),this._lighting=s.lighting?.enabled?s.lighting:null,this._mapKey=null,this._lighting&&(this._lighting.registerTextures({radial:o.lightRadialTexture,head:o.lampHeadTexture,glint:o.glintTexture,shaft:o.lightShaftTexture}),this._mapKey=Eo(e),this._lighting.acquireMap(this._mapKey,e.game?.lighting,this._step,e.scale,{cols:Math.max(0,...this._map.map(r=>r.length)),rows:this._map.length}),this._level>=1&&this._lighting.setLevelMask(this._level,Xs(this._map,this._roof?this._tiles:this._floor),this,{roof:this._roof}),this._ramps.length&&this._lighting.setRampWedges(this._level,Hi({ramps:this._ramps,rampRuns:this._rampRuns,level:this._level,baseScale:this._baseScale,step:this._step}),this)),this._volumes=s.volumes||null,this._volume>0&&this._volumes?.setLayerVolume(this._level,Xs(this._map,this._tiles),this._volume,this,{step:this._step,scale:e.scale}),this.needsRender=this._level>=1||this._extruding||!!this._lighting?.isNight()||Bs(this._animationSpec),this._build(e)}async _build(t){const e=await vo({container:this._container,layerRoot:this._layerRoot,exclude:this._animationSpec.exclude,baseTexture:this._baseTexturePromise,spriteSheetData:t.spriteSheet,map:this._map,tiles:this._tiles,step:this._step,renderer:this._renderer,level:this._level,layer:this._layer,volume:this._volume,ramps:this._ramps,rampRuns:this._rampRuns,baseScale:this._baseScale,parallaxK:this._parallaxK,extruding:this._extruding,assetUrl:this._assetUrl,isAborted:()=>this._container.destroyed});this.mapSprite=e.mapSprite,this._occluder=e.occluder,this._slices=e.slices,this._rampTexture=e.rampTexture,this._wallTextures=e.wallTextures??[],!(!this.mapSprite||this._container.destroyed||!Bs(this._animationSpec))&&(this._animations=await ur({spec:this._animationSpec,game:this._game,baseTexture:await this._baseTexturePromise,spriteSheetData:t.spriteSheet,map:this._map,tiles:this._tiles,step:this._step,scale:this._baseScale,level:this._level,animated:this._animated,renderer:this._renderer,lighting:this._lighting,isAborted:()=>this._container.destroyed}))}_seeThroughView(){return{levelView:this._levelView,container:this._container,stage:this._container.parent,occluder:this._occluder,hasSprite:!!this.mapSprite,hole:this._hole,occluderHole:this._occluderHole,level:this._level,grid:this._grid,tileSet:this._tileSet,floorSet:this._floorSet,roof:this._roof}}_roofAlpha(){return!this._roof||!this._levelView?null:this._levelView.mode==="layer"?this._container.alpha:Oi(this._hole,this._levelView.cfg)}render(){this._attachOccluder(),this._levelView&&this._levelView.attachStage(this._container.parent,this._renderer);const t=this._levelView?this._levelView.camera():ut(this._container.parent,this._renderer);if(this._lighting&&(this._lighting.attachStage(this._container.parent,this._renderer),this._lighting.render()),(this._level>=1||this._occluder)&&bo(this._seeThroughView(),t),this._animations&&dr(this._animations,{camera:t,levelView:this._levelView,screen:this._renderer?.screen,roofAlpha:this._roofAlpha()}),!(!this._parallaxK&&!this._slices.length)&&t){gt(this._layerRoot,t,this._parallaxK,this._baseScale);for(let e=0;e<this._slices.length;e+=1){const s=this._slices[e];s.walls?(po(s,t,Rt.faceBleedPx),mo(s,t)):s.base?yo(s,t):gt(s.target,t,s.k,this._baseScale)}}}_attachOccluder(){const t=this._container.parent;!this._occluder||!t||this._occluder.parent===t||t.addChild(this._occluder)}destroy(){const t=this._container,e=_r(this._animations);if(this._animations=null,this._lighting&&(this._lighting.releaseMap(this._mapKey,this),this._lighting=null),this._volumes?.release(this),this._volumes=null,cs(this._hole,t),this._occluder){const a=this._occluder;this._occluder=null,a.filters=[],cs(this._occluderHole,a),a.parent?.removeChild(a),a.destroy({children:!0,texture:!1,textureSource:!1})}const s=this.mapSprite,n=this._rampTexture,o=this._wallTextures,r=this._slices;this.mapSprite=null,this._rampTexture=null,this._wallTextures=[],this._slices=[];for(const a of r)a.target.destroyed||(a.target.texture=Ue.EMPTY);return s&&s.parent?.removeChild(s),this._baseTexturePromise=null,this._assetUrl=null,this._map=null,this._tiles=null,this._floor=null,this._tileSet=null,this._floorSet=null,this._grid=null,this._ramps=null,this._spriteSheetData=null,this._renderer=null,this._levelView=null,this._game=null,()=>{e(),n&&n.destroy(!0);for(const a of o)a.destroy(!0);s&&s.destroy({children:!0,texture:!0,textureSource:!0})}}}function mr(i,t,e){const s=i?.roofs?.[t]??i?.roofs?.[String(t)];if(!Array.isArray(s)||s.length===0||!e?.length)return!1;const n=new Set(s),o=e.filter(r=>n.has(r)).length;return o>0&&o<e.length?(console.warn(`MapLayer: level ${t} layer mixes roof tiles with others; a roof needs its own layer`),!1):o===e.length}const ct=(i,t,e)=>i+(t-i)*e,zt=(i,t,e)=>Math.min(e,Math.max(t,i)),gr=i=>i*(Math.PI/180),xr=i=>{for(;i>Math.PI;)i-=Math.PI*2;for(;i<-Math.PI;)i+=Math.PI*2;return i},F=(i,t)=>Math.random()*(t-i)+i;class Qt extends ${constructor(t){super(),this._tickListener=null,this._isStarted=!1,this.isComplete=!1,this.onComplete=t}run(){this.isComplete||this._isStarted||(this._isStarted=!0,this._tickListener=t=>this._update(t.deltaMS),Q.shared.add(this._tickListener),this._onEffectStart(),this.isComplete||this._update(0))}_onEffectStart(){}_update(){}_completeEffect(){this.isComplete||(this.isComplete=!0,this._tickListener&&(Q.shared.remove(this._tickListener),this._tickListener=null),typeof this.onComplete=="function"&&this.onComplete())}destroy(t){this.isComplete=!0,this._tickListener&&(Q.shared.remove(this._tickListener),this._tickListener=null),this.parent&&this.parent.removeChild(this),super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}class yr extends Qt{constructor(t,e,s,n,o){super(n),this.x=t,this.y=e,this._textures=o.textures,this._contentSize=o.contentSize,this.config={particleCount:Math.round(F(6,10)),particleMinSize:1.5,particleMaxSize:4,minInitialSpeed:30,maxInitialSpeed:140,maxSpin:12,dragCoefficient:5,minLifetime:1200,maxLifetime:2200,fadeOutStart:.6,color:[7035460,5917240,8022613,4143667]},this.particlesData=[],this._createParticles(s/2)}_createParticles(t){const{config:e}=this;for(let s=0;s<e.particleCount;s+=1){const n=Math.random()*Math.PI*2,o=F(e.minInitialSpeed,e.maxInitialSpeed),r=this._textures[Math.floor(Math.random()*this._textures.length)],a=new J(r),l=F(0,t);a.anchor.set(.5),a.tint=e.color[Math.floor(Math.random()*e.color.length)],a.scale.set(F(e.particleMinSize,e.particleMaxSize)/this._contentSize),this.particlesData.push({sprite:a,x:Math.cos(n)*l,y:Math.sin(n)*l,vx:Math.cos(n)*o,vy:Math.sin(n)*o,rotation:Math.random()*Math.PI*2,spin:F(-e.maxSpin,e.maxSpin),lifetime:F(e.minLifetime,e.maxLifetime),age:0}),this.addChild(a)}}_update(t){if(this.isComplete)return;const{config:e}=this,s=t/1e3,n=Math.max(0,1-e.dragCoefficient*s);let o=0;for(const r of this.particlesData){if(r.age>=r.lifetime)continue;r.age+=t,r.vx*=n,r.vy*=n,r.spin*=n,r.x+=r.vx*s,r.y+=r.vy*s,r.rotation+=r.spin*s;const a=r.age/r.lifetime,{sprite:l}=r;l.position.set(r.x,r.y),l.rotation=r.rotation,l.alpha=a<e.fadeOutStart?1:ct(1,0,Math.min((a-e.fadeOutStart)/(1-e.fadeOutStart),1)),r.age>=r.lifetime?l.visible=!1:o+=1}o===0&&this._isStarted&&this._completeEffect()}destroy(t){this.particlesData=[],super.destroy(t)}}function nn(i,{x:t,y:e,z:s,level:n,reach:o,exclude:r=null}){const a=i?.texture("glint");return!St.glints?.enabled||!a||!i.isNight()||!i.onScreen(t,e,s,o)?null:i.lightsAt(t,e,n,1,r)[0]||null}function on(i,t,e){if(i)return i;const s=new J(e),n=new J;return s.anchor.set(.5),s.blendMode="add",s.mask=n,t.addChild(n,s),{sprite:s,mask:n}}function rn(i){i&&(i.sprite.visible=!1)}function an(i,{hit:t,asset:e,x:s,y:n,rotation:o,size:r}){const{sprite:a}=i,l=St.glints;a.texture=e.texture,a.visible=!0,a.position.set(s,n),a.rotation=o,a.scale.set(r*l.size/e.contentSize),a.tint=t.color,a.alpha=Math.min(1,l.intensity*t.strength)}const bt=0,kt=1,Ft=2,Ns=3,ue=4,fe=5,Ot=6,vt=7,Pe=8,We=9,Jt=11,pt=12,Ae=13,Us=14,Ws=15,wr=0,vr=1,Mr=2,Sr=3,br=4,kr=5,Tr=6,Qe=7,Ar=8,Lr=9,Hs=10,Gs=2,Pr=3,$s=0,Ks=1,Zs=2,zr=3,Cr=4,Er=6,Ir=0,Rr=1,Fr=2,Xr=3,js=0,qs=1,Js=2,Yr=3,Dr=4,Vr=5,Qs=0,Or=1,me=2,Br=1,Nr=2,Ur=1.4;class Wr{constructor(t,e,s,n,o={}){this._container=t,this._renderer=s.renderer,this._soundManager=s.soundManager||null,this._assets=o||{},this._levelView=s.levelView||null,this._lighting=s.lighting?.enabled?s.lighting:null,this._glint=null,this._caster=null,this._baseScale=Le(e.scale),t.scale=e.scale,this._assetUrl=`${n}${e.img}`,this._baseTexturePromise=as.load(this._assetUrl),this._damagedUrl=e.game?.imgDamaged?`${n}${e.game.imgDamaged}`:null,this._destroyedUrl=e.game?.imgDestroyed?`${n}${e.game.imgDestroyed}`:null,this._z=e.level||0,this._level=e.level||0,this._layer=Number(e.layer)||2,t.zIndex=W(this._layer,this._level),this._rotation=gr(e.angle),this._width=e.width,this._height=e.height,this._x=e.position[0],this._y=e.position[1],this._worldX=this._x*this._baseScale.x,this._worldY=this._y*this._baseScale.y,this._state=null,this.sprite=null,this._scorch=null,this._effects=new Set,this.needsRender=!!this._levelView,this._create()}async _create(){try{const t=await this._baseTexturePromise;if(this._container.destroyed)return;this.sprite=new J(t),this.sprite.x=this._x,this.sprite.y=this._y,this.sprite.width=this._width,this.sprite.height=this._height,this.sprite.rotation=this._rotation,this._container.addChild(this.sprite),this._state!==null&&this._state!==Qs&&this._showState(this._state)}catch(t){console.error(`Failed to create dynamic map with asset ${this._assetUrl}:`,t)}}render(){if(!this._levelView||!this.sprite)return;this._updateGlint(),this._updateCaster();const t=this._container;t.alpha=this._levelView.alphaFor(this._level,this._worldX,this._worldY,this._z),t.tint=this._levelView.tintFor(this._level),!(!this._level&&!this._z)&>(t,this._levelView.camera()??ut(t.parent,this._renderer),this._z*B.shear,this._baseScale)}update(t){this.sprite&&(this.sprite.x=t[js]/this._baseScale.x,this.sprite.y=t[qs]/this._baseScale.y,this.sprite.rotation=t[Js]),this._worldX=t[js],this._worldY=t[qs],this._rotation=t[Js],this._z=t[Yr]||0;const e=Te(t[Dr],this._z);e!==this._level&&(this._level=e,this._container.zIndex=W(this._drawLayer(),e),!e&&!this._z&>(this._container,null,0,this._baseScale));const s=t[Vr]||Qs;if(s!==this._state){const n=this._state===null;this._state=s,this._showState(s),s===me&&!n&&this._burst()}this._placeScorch()}_drawLayer(){return this._state===me?Br:this._layer}_standing(){return this._state!==me||!!this._destroyedUrl}_updateGlint(){const t=this._localCenter(),e=this.sprite.visible&&this._standing()?nn(this._lighting,{x:t.x*this._baseScale.x,y:t.y*this._baseScale.y,z:this._z,level:this._level,reach:Math.max(this._width*this._baseScale.x,this._height*this._baseScale.y)}):null;if(!e){rn(this._glint);return}const s=this._lighting.texture("glint");this._glint=on(this._glint,this._container,s.texture);const{mask:n}=this._glint,o=this.sprite;n.texture=o.texture,n.position.copyFrom(o.position),n.scale.copyFrom(o.scale),n.rotation=o.rotation,an(this._glint,{hit:e,asset:s,x:t.x,y:t.y,rotation:e.angle,size:Math.max(this._width,this._height)})}_updateCaster(){if(!this._lighting)return;if(!this._lighting.castsShadows()||!this._standing()){this._caster&&(this._lighting.setCaster(this,null),this._caster=null);return}this._caster||(this._caster={},this._lighting.setCaster(this,this._caster));const t=this._localCenter();this._caster.x=t.x*this._baseScale.x,this._caster.y=t.y*this._baseScale.y,this._caster.z=this._z,this._caster.level=this._level,this._caster.radius=Math.hypot(this._width*this._baseScale.x,this._height*this._baseScale.y)/2}_showState(t){if(this._container.zIndex=W(this._drawLayer(),this._level),!this.sprite)return;if(t===me&&!this._destroyedUrl){this.sprite.visible=!1,this._showScorch();return}this._scorch&&(this._scorch.visible=!1),this.sprite.visible=!0;let e=null;t===Or?e=this._damagedUrl:t===me&&(e=this._destroyedUrl),this._setTexture(e?as.load(e):this._baseTexturePromise,t,e??this._assetUrl)}async _setTexture(t,e,s){try{const n=await t;if(this._container.destroyed||!this.sprite||this._state!==e)return;this.sprite.texture=n,this.sprite.width=this._width,this.sprite.height=this._height}catch(n){console.error(`Failed to load map object state asset ${s}:`,n)}}_showScorch(){const t=this._assets.scorchTexture;if(t){if(!this._scorch){const{textures:e,contentSize:s}=t,n=new J(e[Math.floor(Math.random()*e.length)]);n.anchor.set(.5),n.rotation=Math.random()*Math.PI*2,n.scale.set(Math.max(this._width,this._height)*Ur/s),this._scorch=n,this._container.addChild(n)}this._scorch.visible=!0,this._placeScorch()}}_placeScorch(){if(!this._scorch?.visible)return;const t=this._localCenter();this._scorch.position.set(t.x,t.y)}_localCenter(){const t=Math.cos(this._rotation),e=Math.sin(this._rotation),s=this._width/2,n=this._height/2;return{x:this._worldX/this._baseScale.x+t*s-e*n,y:this._worldY/this._baseScale.y+e*s+t*n}}_burst(){const t=this._localCenter(),e=t.x*this._baseScale.x,s=t.y*this._baseScale.y;this._soundManager?.registerSound("propBreak",{position:{x:e,y:s}});const n=this._container.parent,o=this._assets.debrisTexture;if(!n||!o)return;const r=Math.max(this._width*this._baseScale.x,this._height*this._baseScale.y),a=new yr(e,s,r,()=>{this._effects.delete(a),a.destroy()},o);a.zIndex=W(Nr,this._level),n.addChild(a),this._effects.add(a),a.run()}destroy(){for(const t of this._effects)t.destroy();this._effects.clear(),this._lighting?.setCaster(this,null),this._lighting=null,this._glint=null,this.sprite=null,this._scorch=null,this._baseTexturePromise=null,this._assetUrl=null,this._renderer=null,this._levelView=null,this._soundManager=null}}let Hr=class extends ${constructor(t,e,s){if(super(),this._mode=null,typeof s.assetsBase!="string"){console.error("Map: сервис assetsBase недоступен — карта останется пустой. Объявите assetsBase в componentDependencies и запустите игру на vimp-engine >= 0.9.0");return}const n=`${s.assetsBase}img/`;this._mode=t.type==="dynamic"?new Wr(this,t,s,n,e):new pr(this,t,s,n,e),this._mode.needsRender&&(this.onRender=()=>this._mode.render())}update(t){this._mode?.update?.(t)}destroy(t){const e=this._mode?.destroy();this._mode=null,super.destroy({children:!0,texture:!1,textureSource:!1,...t}),e?.()}};const ti=[16777215,9418751,10477760,15783820,14721232,10541296,15773836,12632280],ln=i=>ti[i]??ti[0],Gr=2,$r=.35;class Kr extends ${constructor(t,e,s={}){super(),this._map=t.map,this._level=t.level||0,this._solid=t.solid||t.physicsStatic||[],this._tiles=t.tiles||[],this._step=t.step,this.zIndex=W(Gr,this._level),this.scale=t.scale,this._draws=this._tiles.some(n=>this._solid.includes(n)),this.radarGraphics=new U,this.addChild(this.radarGraphics),this._levelView=s.levelView||null,this._levelView&&this._draws&&(this.onRender=()=>{this.alpha=this._levelView.level===this._level?1:$r}),this.createRadarMap()}createRadarMap(){if(!this._draws)return;const t=this.radarGraphics;if(t.clear(),Array.isArray(this._map))for(let e=0;e<this._map.length;e+=1){const s=this._map[e];if(Array.isArray(s))for(let n=0;n<s.length;n+=1){const o=s[n];this._solid.includes(o)&&t.rect(n*this._step,e*this._step,this._step/2,this._step/2)}}t.fill(ln(this._level))}update(){}destroy(t){super.destroy({children:!0,texture:!1,textureSource:!1,...t}),this.radarGraphics=null,this._map=null,this._solid=null,this._tiles=null}}const ei=2,Zr=9,jr=1.5;class qr extends ${constructor(t,e){super(),this._level=t[pt]||0,this.zIndex=W(ei,this._level),this._textures=e.tankRadarTexture,this.body=new J,this.body.anchor.set(.5),this.levelRing=new U,this.addChild(this.levelRing,this.body),this._drawLevelRing(),this.x=t[bt]||0,this.y=t[kt]||0,this._condition=t[vt],this._teamId=t[We],this.scale.set(5,5),this.create()}_drawLevelRing(){this.levelRing.clear(),this._level>0&&this.levelRing.circle(0,0,Zr).stroke({width:jr,color:ln(this._level)})}create(){this._condition===0?this.body.texture=this._textures.destroyed:this._teamId===1?this.body.texture=this._textures.liveTeamId1:this._teamId===2&&(this.body.texture=this._textures.liveTeamId2)}update(t){this.x=t[bt],this.y=t[kt];const e=t[pt]||0;e!==this._level&&(this._level=e,this.zIndex=W(ei,e),this._drawLevelRing());const s=t[vt],n=t[We];let o=!1;s!==void 0&&s!==this._condition&&(this._condition=s,o=!0),n!==void 0&&n!==this._teamId&&(this._teamId=n,o=!0),o&&this.create()}destroy(t){super.destroy({children:!0,texture:!1,textureSource:!1,...t}),this.body=null,this.levelRing=null,this._textures=null}}function Jr({width:i,height:t,anchorX:e,anchorY:s,rotation:n,heading:o=0,pitch:r,roll:a,shear:l,lift:h}){const u=-e*i,c=(1-e)*i,_=-s*t,f=(1-s)*t,p=[[u,_],[c,_],[c,f],[u,f]],d=Math.cos(n),g=Math.sin(n),m=Math.cos(r),w=Math.sin(r),M=Math.cos(a),b=Math.sin(a),v=-Math.sin(o),S=-Math.cos(o),y=[];for(const[z,T]of p){const L=z*d-T*g,R=z*g+T*d,D=L*m,I=L*w,X=R*M,Y=R*b,N=I+Y,V=t?N/t*l:0,G=N*h;y.push(D*(1+V)+v*G,X*(1+V)+S*G)}return y}function Qr({angle:i,pitch:t,roll:e,lightDir:s,shading:n}){if(!s)return 1;const o=Math.cos(i),r=Math.sin(i),a=-Math.sin(t)*o+Math.sin(e)*r,l=-Math.sin(t)*r-Math.sin(e)*o,h=Math.hypot(s[0],s[1])||1,u=(a*s[0]+l*s[1])/h;return 1-Math.max(0,-u)*n}function qt(i,t){const e=s=>{const n=Math.round((i>>s&255)*t);return Math.min(255,Math.max(0,n))};return e(16)<<16|e(8)<<8|e(0)}function hn(i,t,{minImpact:e,fullImpact:s}){return!(i<-e)||t!==0?0:Math.min(1,-i/s)}function ta(i,t,e){if(i<0||i>=t)return 0;const s=i/t;if(s<e)return s/e;const n=(s-e)/(1-e);return(1-n)*(1-n)}function ea({amount:i,gunRotation:t,config:e}){const s=Math.cos(t),n=Math.sin(t),o=e.gunKick*i,r=e.bodyKick*i,a=e.rock*i;return{gun:{x:-s*o,y:-n*o},body:{x:-s*r,y:-n*r},pitch:a*s,roll:a*n}}const Oe=Math.PI*2,sa=.09,ia=.113;function na(i,t){return!(t>0)||i>=t?0:1-i/t}function oa({x:i,y:t,level:e,heading:s,hullLength:n,blast:o,config:r,rng:a=Math.random}){if((o.level||0)!==(e||0))return null;const l=o.x-i,h=o.y-t,u=Math.hypot(l,h),c=na(u,o.radius);if(!c)return null;const _=u<r.underShare*n,f=_?a()*Oe:Math.atan2(h,l)-s;return{strength:c,dirU:Math.cos(f),dirV:Math.sin(f),hop:_,phaseX:a()*Oe,phaseY:a()*Oe}}function si({elapsed:i,kick:t,config:e}){const s=t.strength,n=e.decay>0?Math.exp(-i/e.decay):0,o=n*Math.cos(Oe*e.wobbleHz*(i/1e3)),r=e.rock*s*o,a=t.hop&&i<e.hopDuration,l=a?e.hop*s*Math.sin(Math.PI*i/e.hopDuration):0,u=i<e.shakeDuration?e.shake*s*(1-i/e.shakeDuration):0;return{pitch:r*t.dirU,roll:r*t.dirV,lift:l,shakeX:u*Math.sin(i*sa+t.phaseX),shakeY:u*Math.sin(i*ia+t.phaseY),envelope:s*n,done:i>=e.duration&&!a}}const ii=[[1.33,-.42],[.42,-1],[-.42,-1],[-1.33,-.42],[-1.33,.42],[-.42,1],[.42,1],[1.33,.42]].map(([i,t])=>[i*10,t*10]),ni={track:0,hull:1,turret:2,barrel:3};function cn(i){let t=0;for(let e=0;e<i.length;e+=1){const[s,n]=i[e],[o,r]=i[(e+1)%i.length];t+=s*r-o*n}return t}function ra(i){let t=0,e=0,s=0;for(let o=0;o<i.length;o+=1){const[r,a,l]=i[o],[h,u,c]=i[(o+1)%i.length];t+=(a-u)*(l+c),e+=(l-c)*(r+h),s+=(r-h)*(a+u)}const n=Math.hypot(t,e,s)||1;return[t/n,e/n,s/n]}const ge=(i,t,e,s)=>[[i,e],[t,e],[t,s],[i,s]],aa=(i,t)=>i.map(([e,s])=>[e*t,s*t]);function la(i=Mt){const t=[],e=[],s=({bottom:r,top:a,w0:l,w1:h,part:u,topMaterial:c,sideMaterial:_})=>{let f=r,p=a;cn(f)<0&&(f=[...f].reverse(),p=[...p].reverse());const d=t.length,g=f.length;for(const[M,b]of f)t.push([M,b,l]);for(const[M,b]of p)t.push([M,b,h]);const m=M=>d+M,w=M=>d+g+M;e.push({indices:p.map((M,b)=>w(b)),part:u,material:c,kind:"top"}),e.push({indices:f.map((M,b)=>m(g-1-b)),part:u,material:"bottom",kind:"bottom"});for(let M=0;M<g;M+=1){const b=(M+1)%g;e.push({indices:[m(M),m(b),w(b),w(M)],part:u,material:_,kind:"side"})}};for(const[r,a]of[[-15,-9],[9,15]]){const l=ge(-20,20,r,a);s({bottom:l,top:l,w0:0,w1:i.trackHeight,part:"track",topMaterial:"trackTop",sideMaterial:"trackSide"})}s({bottom:ge(-18,18,-9,9),top:ge(-16,14,-7,7),w0:i.hullBase,w1:i.hullTop,part:"hull",topMaterial:"hullTop",sideMaterial:"hullSide"}),s({bottom:ii,top:aa(ii,.6),w0:i.turretBase,w1:i.turretTop,part:"turret",topMaterial:"turretTop",sideMaterial:"turretSide"});const n=ge(2.5,21,-2.5,2.5);s({bottom:n,top:n,w0:i.barrelHeight-i.barrelRadius,w1:i.barrelHeight+i.barrelRadius,part:"barrel",topMaterial:"barrel",sideMaterial:"barrel"});const o=ge(21,24.5,-3.6,3.6);return s({bottom:o,top:o,w0:i.barrelHeight-i.brakeRadius,w1:i.barrelHeight+i.brakeRadius,part:"barrel",topMaterial:"brake",sideMaterial:"brake"}),{vertices:t,faces:e}}const oi=new Set(["turret","barrel"]);function ha({model:i,size:t,gunRotation:e=0,pitch:s=0,roll:n=0,gunKick:o={x:0,y:0},shift:r={x:0,y:0},squash:a=0}){const l=t/10,h=Math.cos(e),u=Math.sin(e),c=Math.cos(s),_=Math.sin(s),f=Math.cos(n),p=Math.sin(n),d=1-a,g=new Array(i.vertices.length);for(const v of i.faces)for(const S of v.indices)g[S]=v.part;const m=([v,S,y])=>{const z=S*f-y*p,T=S*p+y*f;return[v*c-T*_,z,v*_+T*c]},w=([v,S,y])=>[v*h-S*u,v*u+S*h,y],M=i.vertices.map(([v,S,y],z)=>{let T=[v*l,S*l,y*l*d];const L=g[z];return oi.has(L)&&(T=w(T)),L==="barrel"&&(T=[T[0]+o.x,T[1]+o.y,T[2]]),T=m(T),[T[0]+r.x,T[1]+r.y,T[2]]}),b=i.faces.map(v=>{let S=ca(i,v,d);return oi.has(v.part)&&(S=w(S)),m(S)});return{points:M,normals:b}}function ca(i,t,e){return ra(t.indices.map(s=>{const[n,o,r]=i.vertices[s];return[n,o,r*e]}))}function ua({x:i,y:t,camera:e,heading:s,shear:n,levelHeight:o,maxLean:r,topHeight:a,gain:l=1}){if(!e)return{x:0,y:0};let h=(i-e.x)*n*l/o,u=(t-e.y)*n*l/o;const c=Math.hypot(h,u)*a;if(c>0&&r>0){const p=r*Math.tanh(c/r)/c;h*=p,u*=p}const _=Math.cos(s),f=Math.sin(s);return{x:h*_+u*f,y:-h*f+u*_}}function fa({points:i,lean:t,zScale:e=1}){return i.map(([s,n,o])=>[(s+t.x*o)*e,(n+t.y*o)*e])}function da({model:i,points:t,projected:e}){const s=[];return i.faces.forEach((n,o)=>{const r=n.indices.map(a=>e[a]);if(cn(r)>1e-9){let a=0;for(const l of n.indices)a+=t[l][2];s.push({index:o,height:a/n.indices.length,face:n})}}),s.sort((n,o)=>ni[n.face.part]-ni[o.face.part]||n.height-o.height||n.index-o.index),s.map(n=>n.index)}function _a(i,t,e){const s=Math.cos(t),n=Math.sin(t),o=i[0]*s-i[1]*n,r=i[0]*n+i[1]*s,a=o*e.uLight[0]+r*e.uLight[1]+i[2]*e.uLight[2];return(e.uAmbient+e.uDiffuse*Math.max(a,0))*e.uNorm}const pa={track:"body",hull:"body",turret:"gun",barrel:"gun"},ma={trackSide:"trackSide",barrel:"barrelSide",brake:"brakeSide"};function ga(i,t){const[e,s,n,o]=t.indices.map(r=>i.vertices[r]);return t.indices.length===4&&e[0]===o[0]&&e[1]===o[1]&&s[0]===n[0]&&s[1]===n[1]}function xa(i,t){const{width:e,height:s,regions:n}=t,o=([r,a])=>[r/e,a/s];return i.faces.map(r=>{if(r.kind==="bottom"){const{x:h,y:u,w:c,h:_}=n.bottom;return r.indices.map(()=>o([h+c/2,u+_/2]))}const a=ma[r.material];if(r.kind==="side"&&a&&ga(i,r)){const h=n[a],[u,c]=r.indices.map(d=>i.vertices[d]),_=Math.min(Math.hypot(c[0]-u[0],c[1]-u[1]),h.w),f=h.y,p=h.y+h.h;return[o([h.x,p]),o([h.x+_,p]),o([h.x+_,f]),o([h.x,f])]}const l=n[pa[r.part]];return r.indices.map(h=>{const[u,c]=i.vertices[h];return o([l.originX+u,l.originY+c])})})}const ya=`#version 300 es
|
|
85
|
+
in vec2 aPosition;
|
|
86
|
+
in vec2 aUv;
|
|
87
|
+
in float aShade;
|
|
88
|
+
|
|
89
|
+
out vec2 vUV;
|
|
90
|
+
out float vShade;
|
|
91
|
+
out vec4 vColor;
|
|
92
|
+
|
|
93
|
+
uniform mat3 uProjectionMatrix;
|
|
94
|
+
uniform mat3 uWorldTransformMatrix;
|
|
95
|
+
uniform vec4 uWorldColorAlpha;
|
|
96
|
+
uniform vec2 uResolution;
|
|
97
|
+
|
|
98
|
+
uniform mat3 uTransformMatrix;
|
|
99
|
+
uniform vec4 uColor;
|
|
100
|
+
uniform float uRound;
|
|
101
|
+
|
|
102
|
+
uniform mat3 uTextureMatrix;
|
|
103
|
+
|
|
104
|
+
void main(void) {
|
|
105
|
+
mat3 mvp = uProjectionMatrix * uWorldTransformMatrix * uTransformMatrix;
|
|
106
|
+
|
|
107
|
+
gl_Position = vec4((mvp * vec3(aPosition, 1.0)).xy, 0.0, 1.0);
|
|
108
|
+
|
|
109
|
+
if (uRound == 1.0) {
|
|
110
|
+
gl_Position.xy =
|
|
111
|
+
(floor(((gl_Position.xy * 0.5 + 0.5) * uResolution) + 0.5) /
|
|
112
|
+
uResolution) * 2.0 - 1.0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
vUV = (uTextureMatrix * vec3(aUv, 1.0)).xy;
|
|
116
|
+
vShade = aShade;
|
|
117
|
+
vColor = uColor * uWorldColorAlpha;
|
|
118
|
+
}
|
|
119
|
+
`,wa=`#version 300 es
|
|
120
|
+
in vec2 vUV;
|
|
121
|
+
in float vShade;
|
|
122
|
+
in vec4 vColor;
|
|
123
|
+
|
|
124
|
+
out vec4 finalColor;
|
|
125
|
+
|
|
126
|
+
uniform sampler2D uTexture;
|
|
127
|
+
|
|
128
|
+
void main(void) {
|
|
129
|
+
vec4 color = texture(uTexture, vUV);
|
|
130
|
+
|
|
131
|
+
finalColor = vec4(color.rgb * vShade, color.a) * vColor;
|
|
132
|
+
}
|
|
133
|
+
`;let ri=null;function va(i){return ri||=xs.from({vertex:ya,fragment:wa,name:"tank-model"}),new Ei({glProgram:ri,resources:{uTexture:i.source,textureUniforms:new Ne({uTextureMatrix:{value:i.textureMatrix.mapCoord,type:"mat3x3<f32>"}})}})}function Ma(i,t){i.resources.uTexture=t.source,i.resources.textureUniforms.uniforms.uTextureMatrix=t.textureMatrix.mapCoord}function Sa(i,t){const e=[];let s=0,n=0;for(const f of i.faces)e.push(s),s+=f.indices.length,n+=f.indices.length-2;const o=new Float32Array(s*2),r=new Float32Array(s*2),a=new Float32Array(s).fill(1),l=new Uint32Array(n*3),h=f=>{xa(i,f).forEach((p,d)=>{p.forEach(([g,m],w)=>{r[(e[d]+w)*2]=g,r[(e[d]+w)*2+1]=m})})};h(t);const u=new In({attributes:{aPosition:{buffer:o,format:"float32x2"},aUv:{buffer:r,format:"float32x2"},aShade:{buffer:a,format:"float32"}},indexBuffer:l}),c=va(t.texture),_=new Ii({geometry:u,shader:c,texture:t.texture});return{mesh:_,setAtlas(f){h(f),u.getBuffer("aUv").update(),Ma(c,f.texture),_.texture=f.texture},update(f,p,d){i.faces.forEach((m,w)=>{const M=e[w];m.indices.forEach((b,v)=>{o[(M+v)*2]=f[b][0],o[(M+v)*2+1]=f[b][1],a[M+v]=p[w]})});let g=0;for(const m of d){const w=e[m],M=i.faces[m].indices.length;for(let b=1;b<M-1;b+=1)l[g]=w,l[g+1]=w+b,l[g+2]=w+b+1,g+=3}l.fill(0,g),u.getBuffer("aPosition").update(),u.getBuffer("aShade").update(),u.indexBuffer.update()},destroy(){_.destroy(),c.destroy(),u.destroy()}}}function ba(i){const t=[...i].sort((o,r)=>o[0]-r[0]||o[1]-r[1]);if(t.length<3)return t;const e=(o,r,a)=>(r[0]-o[0])*(a[1]-o[1])-(r[1]-o[1])*(a[0]-o[0]),s=[],n=[];for(const o of t){for(;s.length>=2&&e(s[s.length-2],s[s.length-1],o)<=0;)s.pop();s.push(o)}for(let o=t.length-1;o>=0;o-=1){const r=t[o];for(;n.length>=2&&e(n[n.length-2],n[n.length-1],r)<=0;)n.pop();n.push(r)}return s.pop(),n.pop(),s.concat(n)}function ka(i,t,e){if(!i)return{x:0,y:0};const s=Math.hypot(i[0],i[1])||1,n=-i[0]/s/t,o=-i[1]/s/t,r=Math.cos(e),a=Math.sin(e);return{x:n*r+o*a,y:-n*a+o*r}}function Ta({model:i,points:t,lift:e=0,drift:s}){const n=new Map;for(const r of i.faces){n.has(r.part)||n.set(r.part,new Set);for(const a of r.indices)n.get(r.part).add(a)}const o=[];for(const r of n.values()){const a=[...r].map(l=>{const[h,u,c]=t[l],_=Math.max(0,c+e);return[h+s.x*_,u+s.y*_]});o.push(ba(a))}return o}const Aa=`#version 300 es
|
|
134
|
+
in vec2 aPosition;
|
|
135
|
+
in vec2 aUV;
|
|
136
|
+
|
|
137
|
+
out vec2 vUV;
|
|
138
|
+
out vec4 vColor;
|
|
139
|
+
|
|
140
|
+
uniform mat3 uProjectionMatrix;
|
|
141
|
+
uniform mat3 uWorldTransformMatrix;
|
|
142
|
+
uniform vec4 uWorldColorAlpha;
|
|
143
|
+
uniform vec2 uResolution;
|
|
144
|
+
|
|
145
|
+
uniform mat3 uTransformMatrix;
|
|
146
|
+
uniform vec4 uColor;
|
|
147
|
+
uniform float uRound;
|
|
148
|
+
|
|
149
|
+
uniform mat3 uTextureMatrix;
|
|
150
|
+
|
|
151
|
+
void main(void) {
|
|
152
|
+
mat3 mvp = uProjectionMatrix * uWorldTransformMatrix * uTransformMatrix;
|
|
153
|
+
|
|
154
|
+
gl_Position = vec4((mvp * vec3(aPosition, 1.0)).xy, 0.0, 1.0);
|
|
155
|
+
|
|
156
|
+
if (uRound == 1.0) {
|
|
157
|
+
gl_Position.xy =
|
|
158
|
+
(floor(((gl_Position.xy * 0.5 + 0.5) * uResolution) + 0.5) /
|
|
159
|
+
uResolution) * 2.0 - 1.0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
vUV = (uTextureMatrix * vec3(aUV, 1.0)).xy;
|
|
163
|
+
// тинт уровня и прозрачность (премультиплицированы, как у меша PixiJS)
|
|
164
|
+
vColor = uColor * uWorldColorAlpha;
|
|
165
|
+
}
|
|
166
|
+
`,La=`#version 300 es
|
|
167
|
+
in vec2 vUV;
|
|
168
|
+
in vec4 vColor;
|
|
169
|
+
|
|
170
|
+
out vec4 finalColor;
|
|
171
|
+
|
|
172
|
+
uniform sampler2D uTexture;
|
|
173
|
+
uniform sampler2D uNormal;
|
|
174
|
+
|
|
175
|
+
uniform vec2 uSpin;
|
|
176
|
+
uniform vec2 uPitch;
|
|
177
|
+
uniform vec2 uRoll;
|
|
178
|
+
uniform vec2 uHeading;
|
|
179
|
+
uniform vec3 uLight;
|
|
180
|
+
uniform float uAmbient;
|
|
181
|
+
uniform float uDiffuse;
|
|
182
|
+
uniform float uNorm;
|
|
183
|
+
|
|
184
|
+
vec2 turn(vec2 v, vec2 cs) {
|
|
185
|
+
return vec2(v.x * cs.x - v.y * cs.y, v.x * cs.y + v.y * cs.x);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
void main(void) {
|
|
189
|
+
vec4 color = texture(uTexture, vUV);
|
|
190
|
+
vec4 encoded = texture(uNormal, vUV);
|
|
191
|
+
vec3 n = vec3(0.0, 0.0, 1.0);
|
|
192
|
+
|
|
193
|
+
// запечённая текстура премультиплицирована: на кромке антиалиасинга
|
|
194
|
+
// нормаль делится на свою альфу, а пустота считается плоской
|
|
195
|
+
if (encoded.a > 0.01) {
|
|
196
|
+
n = normalize(encoded.rgb / encoded.a * 2.0 - 1.0);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
n.xy = turn(n.xy, uSpin);
|
|
200
|
+
// тангаж: нос +u вверх — нормаль к корме
|
|
201
|
+
n = vec3(n.x * uPitch.x - n.z * uPitch.y, n.y, n.x * uPitch.y + n.z * uPitch.x);
|
|
202
|
+
// крен: борт +v вверх — нормаль к борту −v
|
|
203
|
+
n = vec3(n.x, n.y * uRoll.x - n.z * uRoll.y, n.y * uRoll.y + n.z * uRoll.x);
|
|
204
|
+
n.xy = turn(n.xy, uHeading);
|
|
205
|
+
|
|
206
|
+
float light = (uAmbient + uDiffuse * max(dot(n, uLight), 0.0)) * uNorm;
|
|
207
|
+
|
|
208
|
+
finalColor = vec4(color.rgb * light, color.a) * vColor;
|
|
209
|
+
}
|
|
210
|
+
`,Ce=i=>[Math.cos(i),Math.sin(i)];function un({heading:i,rotation:t,pitch:e,roll:s,lightDir:n,lightZ:o,ambient:r,diffuse:a}){const[l,h]=n||[0,0],u=Math.hypot(l,h,o)||1,c=[l/u,h/u,o/u],_=r+a*Math.max(c[2],0);return{uSpin:Ce(t),uPitch:Ce(e),uRoll:Ce(s),uHeading:Ce(i),uLight:c,uAmbient:r,uDiffuse:a,uNorm:_?1/_:1}}let ai=null;function Pa(i,t){return ai||=xs.from({vertex:Aa,fragment:La,name:"tank-light"}),new Ei({glProgram:ai,resources:{uTexture:i.source,uNormal:t.source,textureUniforms:new Ne({uTextureMatrix:{value:i.textureMatrix.mapCoord,type:"mat3x3<f32>"}}),tankLight:new Ne({uSpin:{value:new Float32Array([1,0]),type:"vec2<f32>"},uPitch:{value:new Float32Array([1,0]),type:"vec2<f32>"},uRoll:{value:new Float32Array([1,0]),type:"vec2<f32>"},uHeading:{value:new Float32Array([1,0]),type:"vec2<f32>"},uLight:{value:new Float32Array([0,0,1]),type:"vec3<f32>"},uAmbient:{value:1,type:"f32"},uDiffuse:{value:0,type:"f32"},uNorm:{value:1,type:"f32"}})}})}function za(i,t,e){i.resources.uTexture=t.source,i.resources.uNormal=e.source,i.resources.textureUniforms.uniforms.uTextureMatrix=t.textureMatrix.mapCoord}function Ca(i,t){const e=i.resources.tankLight.uniforms;for(const s of["uSpin","uPitch","uRoll","uHeading","uLight"])e[s].set(t[s]);e.uAmbient=t.uAmbient,e.uDiffuse=t.uDiffuse,e.uNorm=t.uNorm}const Ea=0,Ia=1,Ee=3;let li=null;const ts=()=>(li||=la(Mt),li),Ra=()=>un({heading:0,rotation:0,pitch:0,roll:0,lightDir:It.lightDir,lightZ:jt.lightZ,ambient:jt.ambient,diffuse:jt.diffuse}),Fa=.55,Xa=.6,hi=7,Ya=1,ci=1.15,Da=1.25,Va=.6,Oa=1,Ba=.015,Na=2.5;function Ua(i,t=0){const e=Number.isFinite(i)?i:0,s=zt(e,0,1),n=Math.max(0,e-1),o=ct(Ya,ci,s)+(Da-ci)*n,r=ct(Va,Oa,s),a=1+Ba*(1-s)*Math.sin(2*Math.PI*Na*(t/1e3));return{rate:o*a,volumeFactor:r}}function Wa(i=It.lightDir,t=At.groundOffset){const e=i?Math.hypot(i[0],i[1]):0;return!e||!t?{x:0,y:0}:{x:-i[0]/e*t,y:-i[1]/e*t}}class Ha extends ${constructor(t,e,s,n){super();const o=()=>{const c=new Rn({verticesX:It.vertices,verticesY:It.vertices});return c.geometry.batchMode="batch",c};this.body=o(),this.gun=o(),this.wreck=o(),this._bodyAnchor={x:.5,y:.5},this._wreckAnchor={x:.5,y:.5},this.addChild(this.body,this.gun,this.wreck),this._lightShaders=new Map,this._textures=e.tankTexture,this._modelAtlases=Mt.enabled&&e.tankModelTexture?e.tankModelTexture:null,this._model=null,this._modelShadow=null,this._wreckSkew=0,this._shadowAsset=e.tankShadowTexture||null,this._renderer=s.renderer||null,this._shadow=null,this._worldX=t[bt]||0,this._worldY=t[kt]||0,this.x=this._worldX,this.y=this._worldY,this.rotation=t[Ft]||0,this._gunRotation=t[Ns]||0,this._engineLoad=t[Ot]||0,this._condition=t[vt],this._size=t[Pe],this._teamId=t[We],this._z=t[Jt]||0,this._physLevel=t[pt]||0,this._vz=t[Ae]||0,this._prevVz=this._vz,this._pitch=t[Us]||0,this._roll=t[Ws]||0,this._landImpact=0,this._landTimer=0,this._squash=0,this._level=Te(t[pt],this._z),this.zIndex=W(Ee,this._level),this._isLocal=()=>s.localPlayer?.is(n?.id)===!0,this._recoilElapsed=1/0,this._recoilTilt={pitch:0,roll:0},this._recoilOffsets={body:{x:0,y:0},gun:{x:0,y:0}},this._blastKick=null,this._blastElapsed=0,this._blastTilt={pitch:0,roll:0},this._blastLift=0,this._blastShake={x:0,y:0},this._unsubscribeBlasts=s.blasts?s.blasts.subscribe(c=>this._onBlast(c)):null,this._unsubscribeShots=s.shots&&n?.id!==void 0?s.shots.subscribe(n.id,{fired:()=>this._onFired(),muzzle:()=>this._muzzleWorld()}):null,this._levelView=s.levelView||null,this._levelView?.setDiagnostics(s.diagnostics??null),this._lighting=s.lighting?.enabled?s.lighting:null,this._headlights=null,this._ownLights=null,this._glint=null,this._caster=null,this._lighting&&e.headlightConeTexture&&this._lighting.registerTextures({cone:e.headlightConeTexture}),this.onRender=()=>this._updateView();const r=this._teamId===1?this._textures.liveTeamId1:this._textures.liveTeamId2,a=r?r.gunAnchor:null;this._gunAnchor=a?{x:a.x,y:a.y}:{x:.5,y:.5};const l=10;this._scaleFactor=this._size/l,this._soundManager=s.soundManager,this._soundId=null;const h=this._soundManager.getSoundConfig("tankEngine");this._baseEngineVolume=h?.volume||0,this._hasEngineSound=!!h,this._surfaces=s.surfaces||null,this._waterSoundId=null,this._speed=Math.hypot(t[ue]||0,t[fe]||0);const u=this._soundManager.getSoundConfig("tankWater");this._baseWaterVolume=u?.volume||0,this._hasWaterSound=!!u,this.create()}_initSounds(){this._soundId||this._condition===0||!this._hasEngineSound||(this._soundId=this._soundManager.registerSound("tankEngine",this._getSoundData()))}_getSoundData(){const{rate:t,volumeFactor:e}=Ua(this._engineLoad,performance.now());return{position:{x:this._worldX,y:this._worldY},rate:t,volume:this._baseEngineVolume*e,spatial:!this._isLocal()}}create(){if(this._condition===0){this.body.visible=!1,this.gun.visible=!1,this._setTexture(this.wreck,this._textures.destroyed,this._textures.destroyedNormal);const t=this._modelAtlases?.destroyed;t?(this._wreckSkew=(Math.random()*2-1)*Xa,this._showModel(t),this.wreck.visible=!1):(this._model&&(this._model.mesh.visible=!1),this.wreck.visible=!0),this._gunRotation=0,this._resetRecoil(),this.destroySounds(),this._removeLights()}else{this.wreck.visible=!1;let t;this._teamId===1?t=this._textures.liveTeamId1:this._teamId===2&&(t=this._textures.liveTeamId2),this._setTexture(this.body,t.body,t.bodyNormal),this._setTexture(this.gun,t.gun,t.gunNormal);const e=this._modelAtlas();e?this._showModel(e):(this.body.visible=!0,this.gun.visible=!0),this._initSounds(),this._addLights()}this._applyTilt()}update(t){this._worldX=t[bt],this._worldY=t[kt],this.rotation=t[Ft],this._gunRotation=t[Ns],this._engineLoad=t[Ot]||0,this._speed=Math.hypot(t[ue]||0,t[fe]||0),this._z=t[Jt]||0,this._physLevel=t[pt]||0,this._vz=t[Ae]||0,this._pitch=t[Us]||0,this._roll=t[Ws]||0;const e=hn(this._prevVz,this._vz,Zt);e>0&&(this._landImpact=e,this._landTimer=Zt.duration),this._prevVz=this._vz;const s=Te(t[pt],this._z);s!==this._level&&(this._level=s,this.zIndex=W(Ee,s)),this._applyTilt(),this._levelView&&this._isLocal()&&this._levelView.set(s,this._worldX,this._worldY,this._z),this._condition>0&&(this._soundId===null?this._initSounds():this._soundManager.updateSoundData(this._soundId,this._getSoundData()));const n=t[vt],o=t[We];let r=!1;n!==void 0&&n!==this._condition&&(this._condition=n,r=!0),o!==void 0&&o!==this._teamId&&(this._teamId=o,r=!0),r&&this.create(),this._updateLights(),this._updateWaterSound()}_updateWaterSound(){if(!(this._hasWaterSound&&this._condition>0&&this._vz===0&&this._surfaces?.kindAt(this._worldX,this._worldY,this._physLevel)==="water")){this._removeWaterSound();return}this._waterSoundId===null?this._waterSoundId=this._soundManager.registerSound("tankWater",this._getWaterSoundData()):this._soundManager.updateSoundData(this._waterSoundId,this._getWaterSoundData())}_getWaterSoundData(){const{minVolume:t,fullSpeed:e,rate:s}=Pt.water.sound,n=zt(this._speed/e,0,1);return{position:{x:this._worldX,y:this._worldY},rate:ct(s.min,s.max,n),volume:this._baseWaterVolume*(t+(1-t)*n),spatial:!this._isLocal()}}_removeWaterSound(){this._waterSoundId&&(this._soundManager.unregisterSound(this._waterSoundId),this._waterSoundId=null)}_headlightPoints(){const t=Math.cos(this.rotation),e=Math.sin(this.rotation),s=this._size*2,n=this._size*1.5*St.headlights.offset,o=this._worldX+t*s,r=this._worldY+e*s;return[{x:o+e*n,y:r-t*n},{x:o-e*n,y:r+t*n}]}_addLights(){if(!this._lighting||this._headlights)return;const{headlights:t,tankGlow:e}=St,s=()=>this._lighting.addLight({kind:"cone",radius:t.length,spread:t.spread,color:t.color,intensity:t.intensity});this._headlights={cones:[s(),s()],glow:this._lighting.addLight({kind:"radial",radius:e.radius,color:e.color,intensity:e.intensity})},this._ownLights=[...this._headlights.cones,this._headlights.glow],this._updateLights()}_updateLights(){if(!this._headlights)return;const t=this._level,e=this._z,s=$i(this._physLevel,e,this._vz!==0),n=this._headlightPoints();for(let o=0;o<2;o+=1)this._lighting.updateLight(this._headlights.cones[o],{x:n[o].x,y:n[o].y,z:e,level:t,levels:s,rotation:this.rotation});this._lighting.updateLight(this._headlights.glow,{x:this._worldX,y:this._worldY,z:e,level:t,levels:s})}_removeLights(){this._headlights&&(this._lighting.removeLight(this._headlights.cones[0]),this._lighting.removeLight(this._headlights.cones[1]),this._lighting.removeLight(this._headlights.glow),this._headlights=null,this._ownLights=null)}_onFired(){if(this._condition===0)return;const t=Kt.attack*Kt.duration;this._recoilElapsed=this._recoilElapsed<Kt.duration?Math.min(this._recoilElapsed,t):0}_muzzleWorld(){if(this._condition===0||this.destroyed)return null;const t=this.rotation+this._gunRotation,e=this._size*4*Fa;return{x:this._worldX+Math.cos(t)*e,y:this._worldY+Math.sin(t)*e}}_resetRecoil(){this._recoilElapsed=1/0,this._recoilTilt.pitch=0,this._recoilTilt.roll=0,this._recoilOffsets.body.x=0,this._recoilOffsets.body.y=0,this._recoilOffsets.gun.x=0,this._recoilOffsets.gun.y=0}_stepRecoil(){if(this._recoilElapsed===1/0)return;this._recoilElapsed+=Q.shared.deltaMS;const t=ta(this._recoilElapsed,Kt.duration,Kt.attack);if(t===0&&this._recoilElapsed>=Kt.duration){this._resetRecoil();return}const e=ea({amount:t,gunRotation:this._gunRotation,config:Kt});this._recoilOffsets.body=e.body,this._recoilOffsets.gun=e.gun,this._recoilTilt.pitch=e.pitch,this._recoilTilt.roll=e.roll}_onBlast(t){if(this.destroyed)return;const e=oa({x:this._worldX,y:this._worldY,level:this._physLevel,heading:this.rotation,hullLength:this._size*4,blast:t,config:de});if(!e)return;const s=this._blastKick?si({elapsed:this._blastElapsed,kick:this._blastKick,config:de}).envelope:0;e.strength>=s&&(this._blastKick=e,this._blastElapsed=0)}_stepBlast(){if(!this._blastKick)return;const t=this._blastKick.hop&&this._blastElapsed<de.hopDuration;this._blastElapsed+=Q.shared.deltaMS;const e=si({elapsed:this._blastElapsed,kick:this._blastKick,config:de});if(t&&this._blastElapsed>=de.hopDuration&&Zt.duration>0&&(this._landImpact=this._blastKick.strength,this._landTimer=Zt.duration),e.done){this._resetBlast();return}this._blastTilt.pitch=e.pitch,this._blastTilt.roll=e.roll,this._blastLift=e.lift,this._blastShake.x=e.shakeX,this._blastShake.y=e.shakeY}_resetBlast(){this._blastKick=null,this._blastElapsed=0,this._blastTilt.pitch=0,this._blastTilt.roll=0,this._blastLift=0,this._blastShake.x=0,this._blastShake.y=0}_viewZ(){return this._z+this._blastLift}_applyMeshOffsets(){const t=1+this._viewZ()*B.shear,{body:e,gun:s}=this._recoilOffsets,n=e.x+this._blastShake.x,o=e.y+this._blastShake.y;this.body.position.set(n*t,o*t),this.wreck.position.set(this._blastShake.x*t,this._blastShake.y*t),this.gun.position.set((n+s.x)*t,(o+s.y)*t)}_setTexture(t,e,s){t.texture=e;const n=this._lightShaders.get(t);if(!s){n&&(t.shader=null,n.destroy(),this._lightShaders.delete(t));return}if(n)za(n,e,s);else{const o=Pa(e,s);t.shader=o,this._lightShaders.set(t,o)}}_applyLight(){for(const[t,e]of this._lightShaders)Ca(e,un({heading:this.rotation,rotation:t===this.gun?this._gunRotation:0,pitch:this._pitch+this._recoilTilt.pitch+this._blastTilt.pitch,roll:this._roll+this._recoilTilt.roll+this._blastTilt.roll,lightDir:It.lightDir,lightZ:jt.lightZ,ambient:jt.ambient,diffuse:jt.diffuse}))}_setCorners(t,e,s,n,o){const{texture:r}=t;t.setCorners(...Jr({width:r.width*n,height:r.height*n*o,anchorX:e.x,anchorY:e.y,rotation:s,heading:this.rotation,pitch:this._pitch+this._recoilTilt.pitch+this._blastTilt.pitch,roll:this._roll+this._recoilTilt.roll+this._blastTilt.roll,shear:B.shear,lift:It.lift}))}_groundZ(){return this._vz!==0?this._physLevel:this._z}_applyTilt(){const t=1+this._viewZ()*B.shear,e=this._scaleFactor*t,s=1-this._squash;this._setCorners(this.body,this._bodyAnchor,0,e,s),this._setCorners(this.gun,this._gunAnchor,this._gunRotation,e,s),this._setCorners(this.wreck,this._wreckAnchor,0,e,s)}_updateView(){this._levelView&&this._levelView.attachStage(this.parent,this._renderer);const t=this._levelView?this._levelView.camera():ut(this.parent,this._renderer);this._lighting&&(this._lighting.attachStage(this.parent,this._renderer),this._lighting.render());let e=16777215;this._levelView&&(this.alpha=this._levelView.alphaFor(this._level,this._worldX,this._worldY,this._z),e=this._levelView.tintFor(this._level),this.tint=e),this._stepBlast();const s=mt(this._worldX,this._worldY,t,this._viewZ()*B.shear);if(this.position.set(s.x,s.y),this._lightShaders.size===0&&!this._model?.mesh.visible){const n=zt(Qr({angle:this.rotation,pitch:this._pitch,roll:this._roll,lightDir:It.lightDir,shading:It.shading}),Ea,Ia);this.tint=qt(e,n)}if(this._landTimer>0){this._landTimer=Math.max(0,this._landTimer-Q.shared.deltaMS);const n=this._landTimer/Zt.duration;this._squash=Math.sin(n*Math.PI)*Zt.squash*this._landImpact}else this._squash=0;this._stepRecoil(),this._applyMeshOffsets(),this._applyTilt(),this._applyLight(),this._applyModel(t),this._updateShadow(t),this._updateGlint(),this._updateCaster()}_updateGlint(){const t=1+this._viewZ()*B.shear,e=nn(this._lighting,{x:this._worldX,y:this._worldY,z:this._viewZ(),level:this._level,reach:this._size*2*t,exclude:this._ownLights});if(!e){rn(this._glint);return}const s=this._lighting.texture("glint");this._glint=on(this._glint,this,s.texture);const{sprite:n,mask:o}=this._glint,r=this._condition===0,a=r?this.wreck:this.body,l=r?this._wreckAnchor:this._bodyAnchor,h=this._scaleFactor*t;this.children.at(-1)!==n&&this.addChild(n),o.texture=a.texture,o.anchor.set(l.x,l.y),o.position.copyFrom(a.position),o.scale.set(h,h*(1-this._squash)),an(this._glint,{hit:e,asset:s,x:a.position.x,y:a.position.y,rotation:e.angle-this.rotation,size:Math.max(a.texture.width,a.texture.height)*h})}_updateCaster(){if(this._lighting){if(!this._lighting.castsShadows()){this._caster&&(this._lighting.setCaster(this,null),this._caster=null);return}this._caster||(this._caster={},this._lighting.setCaster(this,this._caster)),this._caster.x=this._worldX,this._caster.y=this._worldY,this._caster.z=this._z,this._caster.level=this._level,this._caster.radius=this._size*2}}_modelAtlas(){return this._modelAtlases?this._teamId===2?this._modelAtlases.liveTeamId2:this._modelAtlases.liveTeamId1:null}_showModel(t){this._model?this._model.setAtlas(t):(this._model=Sa(ts(),t),this.addChild(this._model.mesh)),this._model.mesh.visible=!0,this.body.visible=!1,this.gun.visible=!1}_applyModel(t){if(!this._model||!this._model.mesh.visible)return;const e=ts(),s=ha({model:e,size:this._size,gunRotation:this._condition===0?this._wreckSkew:this._gunRotation,pitch:this._pitch+this._recoilTilt.pitch+this._blastTilt.pitch,roll:this._roll+this._recoilTilt.roll+this._blastTilt.roll,gunKick:this._recoilOffsets.gun,shift:{x:this._recoilOffsets.body.x+this._blastShake.x,y:this._recoilOffsets.body.y+this._blastShake.y},squash:this._squash}),n=ua({x:this._worldX,y:this._worldY,camera:t,heading:this.rotation,shear:B.shear,levelHeight:Mt.levelHeight,maxLean:Mt.maxLean,gain:Mt.leanGain,topHeight:Mt.turretTop*this._size/10}),o=fa({points:s.points,lean:n,zScale:1+this._viewZ()*B.shear});this._modelPose=s;const r=da({model:e,points:s.points,projected:o}),a=Ra(),l=s.normals.map(h=>_a(h,this.rotation,a));this._model.update(o,l,r)}_modelShadowActive(){return this._condition!==0&&this._model!==null&&this._model.mesh.visible&&this._modelPose!==void 0&&this.parent!==null}_updateModelShadow(t){if(!this._modelShadow){const h=new U;this._modelShadowAlpha=new Ri({alpha:1}),h.filters=Mt.shadowBlur?[new ys({strength:Mt.shadowBlur,quality:2}),this._modelShadowAlpha]:[this._modelShadowAlpha],this.parent.addChild(h),this._modelShadow=h}const e=this._modelShadow,s=this._groundZ(),n=mt(this._worldX,this._worldY,t,s*B.shear),o=Math.max(0,this._viewZ()-s);e.visible=!0,e.position.set(n.x,n.y),e.rotation=this.rotation,e.scale.set(1+s*B.shear),e.zIndex=W(Ee-1,Math.min(hi,Math.floor(s)));const r=Ta({model:ts(),points:this._modelPose.points,lift:o*Mt.levelHeight,drift:ka(It.lightDir,jt.lightZ,this.rotation)});e.clear();for(const h of r)e.poly(h.flat()).fill(0);const l=this._vz!==0||this._blastLift>0?Math.max(0,At.baseAlpha-o*At.alphaFalloff):At.groundAlpha;this._modelShadowAlpha.alpha=l*this.alpha}_updateShadow(t){if(this._modelShadowActive()){this._shadow&&(this._shadow.visible=!1),this._updateModelShadow(t);return}if(this._modelShadow&&(this._modelShadow.visible=!1),!this._shadowAsset||!this.parent)return;const e=this._vz!==0;if(!(this._condition!==0&&(e||At.groundOffset>0))){this._shadow&&(this._shadow.visible=!1);return}if(!this._shadow){const{texture:u,contentSize:c}=this._shadowAsset;this._shadow=new J(u),this._shadow.anchor.set(.5),this._shadowScale=this._size*4*At.sizeFactor/c,this.parent.addChild(this._shadow)}const n=this._shadow;n.visible=!0;const o=this._groundZ(),r=mt(this._worldX,this._worldY,t,o*B.shear),a=Wa();n.x=r.x+a.x,n.y=r.y+a.y,n.rotation=this.rotation;const l=Math.max(0,this._z-o);n.scale.set(this._shadowScale*(1+l*At.scaleGain));const h=e?Math.max(0,At.baseAlpha-l*At.alphaFalloff):At.groundAlpha;n.alpha=h*this.alpha,n.zIndex=W(Ee-1,Math.min(hi,Math.floor(o)))}destroySounds(){this._soundId&&(this._soundManager.unregisterSound(this._soundId),this._soundId=null),this._removeWaterSound()}destroy(t){this.destroySounds(),this._removeLights(),this._lighting?.setCaster(this,null),this._glint=null,this._shadow&&(this._shadow.destroy({texture:!1,textureSource:!1}),this._shadow=null),this._modelShadow&&(this._modelShadow.destroy(),this._modelShadow=null),this._unsubscribeShots&&(this._unsubscribeShots(),this._unsubscribeShots=null),this._unsubscribeBlasts&&(this._unsubscribeBlasts(),this._unsubscribeBlasts=null),this._model&&(this._model.destroy(),this._model=null);for(const e of this._lightShaders.values())e.destroy();this._lightShaders.clear(),super.destroy({children:!0,texture:!1,textureSource:!1,...t})}}const Ga=2;class $a extends ${constructor(t,e,s){super(),this._level=t[Er]||0,this.zIndex=W(Ga,this._level),this._levelView=s.levelView||null,this._renderer=s.renderer||null,(this._levelView||this._renderer)&&(this.onRender=()=>{this._levelView&&(this.alpha=this._levelView.alphaFor(this._level,this._worldX,this._worldY),this.tint=this._levelView.tintFor(this._level)),this._applyHeight()}),this.body=new J(e.bombTexture),this.body.anchor.set(.5),this._worldX=t[$s],this._worldY=t[Ks],this.x=this._worldX,this.y=this._worldY,this.rotation=t[Zs],this._size=t[zr],this._totalDurationMs=t[Cr],this._soundManager=s.soundManager,this._soundId=null;const n=e.bombTexture.width,o=this._size/n;this.body.scale.set(o);const r=64,a=this._size/1.2/r;this.text=new Ci({style:{fontFamily:"Arial",fontSize:r,fill:16777215,align:"center"}}),this.text.anchor.set(.5),this.text.scale.set(a),this.text.x=0,this.text.y=0,this._accumulatedTimeMs=0,this._secondsLeft="",this.addChild(this.body,this.text),this._updateTimerDisplay(this._totalDurationMs),this._tickListener=l=>this._updateTimer(l.deltaMS),Q.shared.add(this._tickListener),this._soundId=this._soundManager.registerSound("bombHasBeenPlanted",{position:{x:this.x,y:this.y}})}_updateTimer(t){this._accumulatedTimeMs+=t;const e=Math.max(0,this._totalDurationMs-this._accumulatedTimeMs);this._updateTimerDisplay(e),e<=0&&(this._stopTimer(),this._updateTimerDisplay(0))}_updateTimerDisplay(t){const e=Math.round(t/1e3);this._secondsLeft!==e&&(this._secondsLeft=e,this.text.text=`${this._secondsLeft}`)}update(t){this._worldX=t[$s],this._worldY=t[Ks],this.x=this._worldX,this.y=this._worldY,this.rotation=t[Zs],this._soundId&&(this._soundManager.updateSoundData(this._soundId,{position:{x:this._worldX,y:this._worldY}})||(this._soundId=null))}_applyHeight(){const t=this._level*B.shear,e=ut(this.parent,this._renderer),s=mt(this._worldX,this._worldY,e,t);this.position.set(s.x,s.y),this.scale.set(1+t)}_stopTimer(){this._tickListener&&(Q.shared.remove(this._tickListener),this._tickListener=null)}destroy(t){this._stopTimer(),this._soundId&&(this._soundManager.releaseSound(this._soundId),this._soundId=null),super.destroy({children:!0,texture:!1,textureSource:!1,...t}),this.body=null,this.text=null}}class Ka extends Qt{constructor(t,e,s,n,o){super(n);const{texture:r,contentSize:a}=o.explosionTexture;this.x=t,this.y=e,this._radius=s,this._durationMs=1500,this._elapsedMs=0,this._baseScale=this._radius*2/a,this._mainBody=new J(r),this._mainBody.anchor.set(.5),this._mainBody.tint=11393254,this._mainBody.scale.set(this._baseScale),this._core=new J(r),this._core.anchor.set(.5),this._core.tint=13882323,this._core.scale.set(this._baseScale),this.addChild(this._mainBody,this._core)}_update(t){if(!this.isComplete)if(this._elapsedMs+=t,this._elapsedMs<=this._durationMs){const e=this._elapsedMs/this._durationMs;this._draw(e)}else this._completeEffect()}_draw(t){const e=n=>n*n;this._mainBody.alpha=.6*(1-e(t));const s=Math.min(1,t*1.5);this._core.alpha=.7-s,this._core.scale.set(this._baseScale*(1-s))}destroy(t){super.destroy(t)}}const es=[],wt={get(i){if(es.length>0){const t=es.pop();return t.texture=i,t.alpha=1,t.scaleX=1,t.scaleY=1,t.rotation=0,t.tint=16777215,t.anchorX=.5,t.anchorY=.5,t}return new Fn({texture:i,anchorX:.5,anchorY:.5})},release(i){i&&es.push(i)}},ds=50,Za=400,ja=800;class qa extends Qt{constructor(t,e=ds){super();const s=e/ds;this._blastScale=s;const{texture:n,contentSize:o}=t.explosionTexture;this.explosionTexture=n,this._unitScale=1/o;const r=Za*s,a=ja*s;this._particleContainer=new Ke({texture:this.explosionTexture,boundsArea:new rt(-r/2,-a/2,r,a),dynamicProperties:{position:!0,vertex:!0,rotation:!0,color:!0}}),this.addChild(this._particleContainer),this._particles=[],this._isSpawning=!0,this._particleSpawnRateMs=50,this._particleMaxLifeMs=2e3,this._minStartSize=2.1*s,this._maxStartSize=5.2*s,this._minTargetSize=8.3*s,this._maxTargetSize=16.6*s,this._startAlpha=.1,this._initialOffsetX=15*s,this._initialOffsetY=15*s,this._lastSpawnTime=0;for(let l=0;l<30;l+=1)this._createParticle()}stopSpawning(){this._isSpawning=!1}_createParticle(){const t=wt.get(this.explosionTexture),e=.2+Math.random()*.4,s=Math.floor(e*255);t.tint=s<<16|s<<8|s;const n=(this._minStartSize+Math.random()*(this._maxStartSize-this._minStartSize))*this._unitScale,o=.6+Math.random()*.8,r=.6+Math.random()*.8;t.scaleX=n*o,t.scaleY=n*r,t.alpha=this._startAlpha+Math.random()*.1,t.rotation=Math.random()*Math.PI*2,t.x=(Math.random()-.5)*this._initialOffsetX,t.y=(Math.random()-.5)*this._initialOffsetY;const a={view:t,life:0,maxLife:this._particleMaxLifeMs*(.7+Math.random()*.6),aspectRatioX:o,aspectRatioY:r,vx:(Math.random()-.5)*.2*this._blastScale,vy:(-.3-Math.random()*.4)*this._blastScale,swaySpeed:.002+Math.random()*.003,swayAmp:(.025+Math.random()*.05)*this._blastScale,swayOffset:Math.random()*100,rotationSpeed:(Math.random()-.5)*.05,targetScale:(this._minTargetSize+Math.random()*(this._maxTargetSize-this._minTargetSize))*this._unitScale,startScale:n};this._particleContainer.addParticle(t),this._particles.push(a)}_update(t){if(!this.isComplete){if(t=Math.min(t,100),this._isSpawning)for(this._lastSpawnTime+=t;this._lastSpawnTime>this._particleSpawnRateMs;)this._createParticle(),this._lastSpawnTime-=this._particleSpawnRateMs;for(let e=this._particles.length-1;e>=0;e-=1){const s=this._particles[e],n=s.view;if(s.life+=t,s.life>=s.maxLife)this._particleContainer.removeParticle(n),wt.release(n),this._particles.splice(e,1);else{const o=s.life/s.maxLife;s.vy*=.98,s.vx*=.95;const r=Math.sin(s.life*s.swaySpeed+s.swayOffset)*s.swayAmp;n.x+=(s.vx+r)*(t/16),n.y+=s.vy*(t/16),n.rotation+=s.rotationSpeed*(t/16);const a=1-Math.pow(1-o,3),l=s.startScale+(s.targetScale-s.startScale)*a;if(n.scaleX=l*s.aspectRatioX,n.scaleY=l*s.aspectRatioY,o<.1)n.alpha=o/.1*this._startAlpha;else if(o>.4){const h=(o-.4)/.6;n.alpha=this._startAlpha*(1-h)}else n.alpha=this._startAlpha}}!this._isSpawning&&this._particles.length===0&&this._isStarted&&(this._completeEffect(),this.destroyed||this.destroy())}}destroy(t){for(let e=0;e<this._particles.length;e+=1)wt.release(this._particles[e].view);this._particles=[],super.destroy(t)}}const Ja=.168,Qa=.225,ui=.15,tl=2e4,el=50,sl=4e3,il=4e3;class nl extends Qt{constructor(t,e,s,n,o){super(n),this._assets=o,this._radius=s,this.x=t,this.y=e,this._funnelDurationMs=tl,this._funnelFadeInDurationMs=el,this._funnelFadeDurationMs=sl,this._elapsedMs=0,this._smokeDurationMs=il,this._smokeSpawningStopped=!1,this._funnel=this._createFunnelSprite(),this._smoke=new qa(this._assets,this._radius),this.addChild(this._funnel,this._smoke)}_createFunnelSprite(){const{textures:t,contentSize:e}=this._assets.funnelTexture,s=t[Math.floor(Math.random()*t.length)],n=new J(s);n.anchor.set(.5),n.alpha=0,n.rotation=Math.random()*Math.PI*2;const o=this._radius*Ja*F(1-ui,1+ui);return n.scale.set(o/e),n}_onEffectStart(){super._onEffectStart(),this._smoke&&this._smoke.run()}_update(t){if(this.isComplete)return;this._elapsedMs+=t,!this._smokeSpawningStopped&&this._elapsedMs>=this._smokeDurationMs&&(this._smoke.stopSpawning(),this._smokeSpawningStopped=!0);const e=this._funnelDurationMs-this._elapsedMs,s=this._funnelFadeInDurationMs>0?this._elapsedMs/this._funnelFadeInDurationMs:1,n=e/this._funnelFadeDurationMs;this._funnel.alpha=Qa*zt(Math.min(s,n),0,1),e<=0&&this._completeEffect()}destroy(t){this._smoke&&(this._smoke.destroy(),this._smoke=null),this._funnel=null,super.destroy(t)}}const ol=4,rl=2;class al extends ${constructor(t,e,s){super(),this.originX=t[Ir],this.originY=t[Rr],this.radius=t[Fr]??ds,this._level=t[Xr]||0,this._assets=e,this._soundManager=s.soundManager,this._levelView=s.levelView||null,this._renderer=s.renderer||null,this._lighting=s.lighting||null,s.blasts?.exploded({x:this.originX,y:this.originY,radius:this.radius,level:this._level}),(this._levelView||this._renderer)&&(this.onRender=()=>{this._levelView&&this._updateSeeThrough(),this._applyHeight()}),this.x=this.originX,this.y=this.originY,this.explosion=null,this.funnel=null,this._isStarted=!1,this._isDestroyed=!1,this._soundId=this._soundManager.registerSound("explosion",{position:{x:this.originX,y:this.originY}})}_updateSeeThrough(){const t=this._levelView.alphaFor(this._level,this.originX,this.originY),e=this._levelView.tintFor(this._level);this.explosion&&(this.explosion.alpha=t,this.explosion.tint=e),this.funnel&&(this.funnel.alpha=t,this.funnel.tint=e)}_applyHeight(){const t=this._level*B.shear,e=ut(this.parent,this._renderer),s=mt(this.originX,this.originY,e,t);for(const n of[this.explosion,this.funnel])n&&(n.position.set(s.x,s.y),n.scale.set(1+t))}run(){if(!(this._isDestroyed||this._isStarted)){if(this._isStarted=!0,!this.parent){this.destroy();return}this._lighting?.flash({...St.flash.explosion,level:this._level,x:this.originX,y:this.originY,z:this._level}),this.explosion=new Ka(this.originX,this.originY,this.radius,this._onExplosionComplete.bind(this),this._assets),this.explosion.zIndex=W(ol,this._level),this.funnel=new nl(this.originX,this.originY,this.radius,this._onFunnelComplete.bind(this),this._assets),this.funnel.zIndex=W(rl,this._level),this.parent.addChild(this.explosion,this.funnel),this.parent.sortChildren(),this.explosion.run(),this.funnel.run()}}_onExplosionComplete(){this._isDestroyed||this.explosion&&(this.explosion.destroy(),this.explosion=null)}_onFunnelComplete(){this._isDestroyed||this.destroy()}destroy(){this._isDestroyed||(this._isDestroyed=!0,this._soundId&&(this._soundManager.unregisterSound(this._soundId),this._soundId=null),this.explosion&&(this.explosion.destroy(),this.explosion=null),this.funnel&&(this.funnel.destroy(),this.funnel=null),this.parent&&this.parent.removeChild(this),super.destroy({children:!0}))}}const fi=4,se=400,ll=0,hl=0,cl=8,it={particleLifetime:{min:800,max:1800},particleStartSizeFactor:{1:2,2:1},particleEndSizeFactor:{1:3,2:2},particleStartAlpha:.08,particleEndAlpha:0,particleColor:3355443,particleSpawnRate:{1:60,2:50},particleInitialVelocity:{away:{min:-10,max:100},side:{min:-30,max:30}},airResistance:.92,particleVelocityVariance:10,streamOffsetFactor:.1,burstParticleCount:3,exhaust:{spawnRate:45,idleSpawnRate:4,minLoad:.05,startSizeFactor:.6,endSizeFactor:1.6,startAlpha:.05,color:5592405,lifetime:{min:350,max:750}}};class ul extends ${constructor(t,e,s={}){super(),this._level=t[pt]||0,this.zIndex=W(fi,this._level);const{texture:n,contentSize:o}=e.smokeTexture;this._smokeTexture=n,this._textureScale=cl/o,this._emitterX=t[bt],this._emitterY=t[kt],this._emitterRotation=t[Ft],this._emitterVX=t[ue],this._emitterVY=t[fe],this._engineLoad=t[Ot],this._condition=t[vt],this._z=t[Jt]||0,this._size=t[Pe],this._width=this._size*4,this._height=this._size*3,this._particleScaleMultiplier=Math.max(.5,Math.sqrt(this._width*this._height*.001)),this._particles=[],this._levelView=s.levelView||null,this._renderer=s.renderer||null,(this._levelView||this._renderer)&&(this.onRender=()=>{this._levelView&&(this.alpha=this._levelView.alphaFor(this._level,this._emitterX,this._emitterY,this._z),this.tint=this._levelView.tintFor(this._level)),gt(this,ut(this.parent,this._renderer),this._z*B.shear,1)}),this._particleContainer=new Ke({texture:this._smokeTexture,boundsArea:new rt(this._emitterX-se,this._emitterY-se,se*2,se*2),dynamicProperties:{position:!0,vertex:!0,rotation:!0,color:!0}}),this.addChild(this._particleContainer),this._timeSinceLastSpawn=0,this._timeSinceExhaust=0,this._tickListener=r=>this._updateParticles(r.deltaMS),Q.shared.add(this._tickListener)}update(t){const e=this._condition,s=t[pt]||0;s!==this._level&&(this._level=s,this.zIndex=W(fi,s)),this._emitterX=t[bt],this._emitterY=t[kt],this._emitterRotation=t[Ft],this._emitterVX=t[ue],this._emitterVY=t[fe],this._engineLoad=t[Ot],this._condition=t[vt],this._z=t[Jt]||0,this._particleContainer.boundsArea.x=this._emitterX-se,this._particleContainer.boundsArea.y=this._emitterY-se,this._condition!==e&&(this._condition===1||this._condition===2)&&this._triggerSmokeBurst()}_triggerSmokeBurst(){let t=0;if(this._condition===1?t=2:this._condition===2&&(t=1),t>0){const e=it.burstParticleCount,s=Math.ceil(e/t);for(let n=0;n<s;n+=1)for(let o=0;o<t;o+=1)this.spawnParticle(o,t,"burst")}}_updateParticles(t){if(t<=0)return;const e=t/1e3;this._timeSinceLastSpawn+=t,this._timeSinceExhaust+=t;let s=0;this._condition===3?s=0:this._condition===1?s=2:this._condition===2&&(s=1);const n=it.particleSpawnRate[this._condition]||0,o=n>0?1e3/n:1/0;if(s>0&&n>0)for(;this._timeSinceLastSpawn>=o;){for(let u=0;u<s;u+=1)this.spawnParticle(u,s);this._timeSinceLastSpawn-=o}else this._timeSinceLastSpawn=0;const r=Math.min(this._engineLoad,1),a=this._condition>0&&r>=it.exhaust.minLoad?ct(it.exhaust.idleSpawnRate,it.exhaust.spawnRate,r):0;if(a>0){const u=1e3/a;for(;this._timeSinceExhaust>=u;)this.spawnParticle(0,1,"exhaust"),this._timeSinceExhaust-=u}else this._timeSinceExhaust=0;const h=1-Math.pow(it.airResistance,t/16);for(let u=this._particles.length-1;u>=0;u-=1){const c=this._particles[u];if(c.age+=t,c.age>=c.lifetime){this._particleContainer.removeParticle(c.view),wt.release(c.view),this._particles.splice(u,1);continue}c.vx=c.vx+(ll-c.vx)*h,c.vy=c.vy+(hl-c.vy)*h,c.x+=c.vx*e,c.y+=c.vy*e;const _=c.age/c.lifetime,f=1-(1-_)*(1-_),p=ct(c.startSizeFactor,c.endSizeFactor,f),d=ct(c.startAlpha,c.endAlpha,_),g=p*this._particleScaleMultiplier*this._textureScale,m=c.view;m.x=c.x,m.y=c.y,m.scaleX=g,m.scaleY=g,m.alpha=d,m.rotation+=c.rotSpeed*e}}spawnParticle(t,e,s="damage"){const n=s==="burst",o=s==="exhaust",r=it.exhaust,a=o?F(r.lifetime.min,r.lifetime.max):F(it.particleLifetime.min,it.particleLifetime.max);let l=o?r.startSizeFactor:it.particleStartSizeFactor[this._condition]||.3,h=o?r.endSizeFactor:it.particleEndSizeFactor[this._condition]||1,u=o?r.startAlpha:it.particleStartAlpha,c=1;n&&(l*=2,h*=2.5,u=.8,c=2);const _=this._emitterRotation,f=_+Math.PI,p=Math.cos(f),d=Math.sin(f),g=_+Math.PI/2,m=Math.cos(g),w=Math.sin(g);let M=0;const b=this._width/2*it.streamOffsetFactor;e===2?M=t===0?-b:b:e===3&&(M=(t-1)*b);const v=this._height*.22,S=this._emitterX+p*v+m*M,y=this._emitterY+d*v+w*M;let z=F(it.particleInitialVelocity.away.min,it.particleInitialVelocity.away.max),T=F(it.particleInitialVelocity.side.min,it.particleInitialVelocity.side.max);z*=c,T*=c;let L=p*z+m*T,R=d*z+w*T;const D=it.particleVelocityVariance;L+=F(-D,D),R+=F(-D,D),L+=this._emitterVX,R+=this._emitterVY;const I=wt.get(this._smokeTexture);I.tint=o?r.color:it.particleColor,I.x=S,I.y=y,I.alpha=u;const X=l*this._particleScaleMultiplier*this._textureScale;I.scaleX=X,I.scaleY=X,I.rotation=F(0,Math.PI*2);const Y={view:I,x:S,y,vx:L,vy:R,age:0,lifetime:a,startSizeFactor:l,endSizeFactor:h,startAlpha:u,endAlpha:it.particleEndAlpha,rotSpeed:F(-1,1)};this._particleContainer.addParticle(I),this._particles.push(Y)}_stopTimer(){this._tickListener&&(Q.shared.remove(this._tickListener),this._tickListener=null)}destroy(t){this._stopTimer();for(let e=0;e<this._particles.length;e+=1)wt.release(this._particles[e].view);this._particles=[],super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}class fl extends J{constructor(t,e,s,n,o,r,a,l=1){super(a),this.anchor.set(.5),this.x=t,this.y=e,this.rotation=s,this.width=o,this.height=n,this.alpha=r,this._initialAlpha=r,this._elapsedTime=0,this._fadeDuration=(1800+Math.random()*700)*l}update(t){this._elapsedTime+=t;const e=Math.min(this._elapsedTime/this._fadeDuration,1);return this.alpha=(1-e)*this._initialAlpha,e>=1}}const ss=1;class dl extends ${constructor(t,e,s={}){super(),this._levelView=s.levelView||null,this._renderer=s.renderer||null,this._surfaces=s.surfaces||null,this._level=t[pt]||0,this._markLayers=new Map,this.zIndex=W(ss,this._level),this._currentX=t[bt]||0,this._currentY=t[kt]||0,this._currentRotation=t[Ft]||0,this._engineLoad=t[Ot]||0,this._condition=t[vt],this._size=t[Pe],this._prevX=this._currentX,this._prevY=this._currentY,this._prevRotation=this._currentRotation,this._prevSpeed=0,this._prevAngularSpeed=0,this._assets=e,this._trackMarkCooldown=2,this._lastTrackMarkTime=0,this._minAbsAccelerationForMark=4,this._minAngularSpeedForMark=.02,this._minRotationAccelerationForMark=.4,this._minSpeedForRotationMarks=1.4,this._trackWidth=this._size*.4,this._trackLength=this._size*.5;const n=this._size*3;this._trackOffset=n/2*.7,this._backwardOffset=n*.4,this._trackInitialAlpha=.4,this._trailKind=null,this._trailLeft=0,this._tickListener=o=>this._internalUpdate(o.deltaMS),Q.shared.add(this._tickListener),this._levelView&&(this.onRender=()=>this._updateLayers())}update(t){this._currentX=t[bt],this._currentY=t[kt],this._currentRotation=t[Ft],this._engineLoad=t[Ot],this._condition=t[vt];const e=t[pt]||0;e!==this._level&&(this._level=e,this.zIndex=W(ss,e))}_markLayer(t){let e=this._markLayers.get(t);if(e)return e;e=new $,e.zIndex=W(ss,t),this._markLayers.set(t,e);const s=this.parent||this;return s.addChild(e),s.sortChildren(),e}_internalUpdate(t){if(t<=0)return;for(const f of this._markLayers.values())for(let p=f.children.length-1;p>=0;p-=1){const d=f.children[p];d.update(t)&&d.destroy()}this._stepTrail(t/1e3);const e=this._currentX-this._prevX,s=this._currentY-this._prevY,n=Math.sqrt(e*e+s*s),o=xr(this._currentRotation-this._prevRotation),r=Math.abs(o),a=n-this._prevSpeed,l=Math.abs(a),h=r-this._prevAngularSpeed,u=Math.abs(h),c=performance.now();let _=!1;this._condition!==0&&c-this._lastTrackMarkTime>this._trackMarkCooldown&&(l>this._minAbsAccelerationForMark&&(_=!0),n>this._minSpeedForRotationMarks&&(r>this._minAngularSpeedForMark||u>this._minRotationAccelerationForMark)&&(_=!0)),this._engineLoad>1&&(_=!0),_&&(this.createTrackMarksAtPreviousPosition(),this._lastTrackMarkTime=c),this._prevX=this._currentX,this._prevY=this._currentY,this._prevRotation=this._currentRotation,this._prevSpeed=n,this._prevAngularSpeed=r}_stepTrail(t){if(!this._surfaces)return;const e=this._surfaces.kindAt(this._currentX,this._currentY,this._level),s=e&&Pt.tracks[e]?.trail;s?(this._trailKind=e,this._trailLeft=s):this._trailLeft>0&&(this._trailLeft=Math.max(0,this._trailLeft-t))}createTrackMarksAtPreviousPosition(){const t=this._surfaces?this._surfaces.kindAt(this._prevX,this._prevY,this._level):null;if(t&&Pt.tracks.noMarks.includes(t))return;let e=t&&Pt.tracks[t]||null,s=1;!e&&this._trailLeft>0&&(e=Pt.tracks[this._trailKind],s=this._trailLeft/e.trail);const n=this._markLayer(this._level);for(let o=-1;o<=1;o+=2){const r=Math.cos(this._prevRotation+Math.PI/2)*this._trackOffset*o,a=Math.sin(this._prevRotation+Math.PI/2)*this._trackOffset*o,l=-Math.cos(this._prevRotation)*this._backwardOffset,h=-Math.sin(this._prevRotation)*this._backwardOffset,u=this._prevX+r+l,c=this._prevY+a+h,_=new fl(u,c,this._prevRotation,this._trackWidth,this._trackLength,Math.min(1,this._trackInitialAlpha*(e?e.alpha:1))*s,this._assets.trackMarkTexture,e?e.lifetime:1);e&&(_.tint=e.tint),n.addChild(_)}}_updateLayers(){if(!this._markLayers.size)return;const t=ut(this.parent,this._renderer);for(const[e,s]of this._markLayers)s.alpha=this._levelView.alphaFor(e,this._currentX,this._currentY),s.tint=this._levelView.tintFor(e),e&>(s,t,e*B.shear)}_stopTimer(){this._tickListener&&(Q.shared.remove(this._tickListener),this._tickListener=null)}destroy(t){this._stopTimer();for(const e of this._markLayers.values())e.destroyed||e.destroy({children:!0});this._markLayers.clear(),super.destroy({children:!0,texture:!1,textureSource:!1,...t})}}const di=2,ie=300,_l=6,st={lifetime:{min:300,max:700},startSizeFactor:.7,endSizeFactor:2,startAlpha:.35,endAlpha:0,color:10260343,airResistance:.86,spawnRate:30,maxSpinSpeed:8,spinVelocity:{back:{min:20,max:70},side:{min:-25,max:25}},landingBurst:14,landingVelocity:{min:40,max:110},landingSizeFactor:1.6},pl={color:st.color,alpha:st.startAlpha,lifetime:st.lifetime},ml=["sand","mud","water"],_i=.35,gl=(i,t)=>i.kind==="boost"&&i.dir!==null&&i.dir[0]===t[0]&&i.dir[1]===t[1];class xl extends ${constructor(t,e,s={}){super(),this._level=t[pt]||0,this.zIndex=W(di,this._level);const{texture:n,contentSize:o}=e.dustTexture;this._dustTexture=n,this._textureScale=_l/o,this._x=t[bt],this._y=t[kt],this._rotation=t[Ft],this._vx=t[ue]||0,this._vy=t[fe]||0,this._engineLoad=t[Ot]||0,this._condition=t[vt],this._z=t[Jt]||0,this._vz=t[Ae]||0,this._prevVz=this._vz,this._size=t[Pe];const r=this._size*3;this._trackOffset=r/2*.7,this._backwardOffset=r*.4,this._particleScaleMultiplier=Math.max(.5,Math.sqrt(this._size*4*r*.001)),this._particles=[],this._timeSinceSpawn=0,this._levelView=s.levelView||null,this._renderer=s.renderer||null,this._soundManager=s.soundManager||null,this._surfaces=s.surfaces||null,this._surfaceKind=null,this._surfaceCell=null,this._timeSinceSurfaceSpawn=0;const a=this._soundManager?.getSoundConfig("tankLanding");this._landingVolume=a?.volume||0,this._hasLandingSound=!!a,(this._levelView||this._renderer)&&(this.onRender=()=>{this._levelView&&(this.alpha=this._levelView.alphaFor(this._level,this._x,this._y,this._z),this.tint=this._levelView.tintFor(this._level)),gt(this,ut(this.parent,this._renderer),this._z*B.shear,1)}),this._particleContainer=new Ke({texture:this._dustTexture,boundsArea:new rt(this._x-ie,this._y-ie,ie*2,ie*2),dynamicProperties:{position:!0,vertex:!0,rotation:!0,color:!0}}),this.addChild(this._particleContainer),this._tickListener=l=>this._updateParticles(l.deltaMS),Q.shared.add(this._tickListener)}update(t){const e=this._x,s=this._y,n=this._condition>0,o=t[pt]||0;o!==this._level&&(this._level=o,this.zIndex=W(di,o)),this._x=t[bt],this._y=t[kt],this._rotation=t[Ft],this._vx=t[ue]||0,this._vy=t[fe]||0,this._engineLoad=t[Ot]||0,this._condition=t[vt],this._z=t[Jt]||0,this._vz=t[Ae]||0,this._particleContainer.boundsArea.x=this._x-ie,this._particleContainer.boundsArea.y=this._y-ie;const r=hn(this._prevVz,this._vz,Zt);r>0&&(this._triggerLandingBurst(r),this._playLandingSound(r)),this._prevVz=this._vz,this._updateSurface(e,s,n)}_updateSurface(t,e,s){if(!this._surfaces)return;const n=this._surfaces.kindAt(this._x,this._y,this._level),o=n==="boost"?this._surfaces.dirAt(this._x,this._y,this._level):null,r=this._surfaceCell,a=Math.hypot(this._x-t,this._y-e)>Pt.boost.resetDistance,l=!s&&this._condition>0;this._surfaceKind=n,this._surfaceCell={kind:n,dir:o},!(r===null||l||a||this._condition<=0||this._vz!==0)&&(n==="water"&&r.kind!=="water"&&this._triggerWaterEntry(),o&&!gl(r,o)&&this._vx*o[0]+this._vy*o[1]>=Pt.boost.boostMinSpeed&&this._triggerBoostFlash(o))}_triggerWaterEntry(){const t=Pt.water;if(!(Math.hypot(this._vx,this._vy)<t.entryMinSpeed))for(let e=-1;e<=1;e+=2){const s=this._contactPoint(e);for(let n=0;n<t.entryBurst;n+=1){const[o,r]=this._sideSprayVelocity(e,t);this._spawnParticle(s.x,s.y,o,r,t.sizeFactor*1.5,t)}}}_triggerBoostFlash(t){const e=Pt.boost,s=Math.atan2(-t[1],-t[0]);for(let n=0;n<e.burst;n+=1){const o=s+F(-_i,_i),r=F(e.tailSpeed.min,e.tailSpeed.max);this._spawnParticle(this._x,this._y,Math.cos(o)*r,Math.sin(o)*r,e.sizeFactor,e)}}_sideSprayVelocity(t,e){const s=this._rotation+Math.PI/2,n=this._rotation+Math.PI,o=F(e.sideSpeed.min,e.sideSpeed.max)*t,r=F(0,e.sideSpeed.min);return[Math.cos(s)*o+Math.cos(n)*r,Math.sin(s)*o+Math.sin(n)*r]}_spawnSurfaceDust(t,e){for(let s=-1;s<=1;s+=2){const n=this._contactPoint(s);let o,r;if(t==="water")[o,r]=this._sideSprayVelocity(s,e);else{const a=this._rotation+Math.PI,l=this._rotation+Math.PI/2,h=F(st.spinVelocity.back.min,st.spinVelocity.back.max),u=F(st.spinVelocity.side.min,st.spinVelocity.side.max);o=Math.cos(a)*h+Math.cos(l)*u,r=Math.sin(a)*h+Math.sin(l)*u}this._spawnParticle(n.x,n.y,o,r,e.sizeFactor,e)}}_playLandingSound(t){this._hasLandingSound&&this._soundManager.registerSound("tankLanding",{position:{x:this._x,y:this._y},volume:this._landingVolume*t})}_contactPoint(t){const e=this._rotation+Math.PI/2;return{x:this._x+Math.cos(e)*this._trackOffset*t-Math.cos(this._rotation)*this._backwardOffset,y:this._y+Math.sin(e)*this._trackOffset*t-Math.sin(this._rotation)*this._backwardOffset}}_triggerLandingBurst(t){const e=Math.round(st.landingBurst*t);if(!(e<=0))for(let s=-1;s<=1;s+=2){const n=this._contactPoint(s);for(let o=0;o<e;o+=1){const r=F(0,Math.PI*2),a=F(st.landingVelocity.min,st.landingVelocity.max)*t;this._spawnParticle(n.x,n.y,Math.cos(r)*a,Math.sin(r)*a,st.landingSizeFactor*t)}}}_spawnSpinDust(){const t=this._rotation+Math.PI,e=this._rotation+Math.PI/2;for(let s=-1;s<=1;s+=2){const n=this._contactPoint(s),o=F(st.spinVelocity.back.min,st.spinVelocity.back.max),r=F(st.spinVelocity.side.min,st.spinVelocity.side.max);this._spawnParticle(n.x,n.y,Math.cos(t)*o+Math.cos(e)*r,Math.sin(t)*o+Math.sin(e)*r,1)}}_spawnParticle(t,e,s,n,o,r=pl){const a=st.startSizeFactor*o,l=st.endSizeFactor*o,h=wt.get(this._dustTexture),u=a*this._particleScaleMultiplier*this._textureScale;h.tint=r.color,h.x=t,h.y=e,h.alpha=r.alpha,h.scaleX=u,h.scaleY=u,h.rotation=F(0,Math.PI*2),this._particles.push({view:h,x:t,y:e,vx:s,vy:n,age:0,lifetime:F(r.lifetime.min,r.lifetime.max),startAlpha:r.alpha,startSizeFactor:a,endSizeFactor:l,rotSpeed:F(-1,1)}),this._particleContainer.addParticle(h)}_updateParticles(t){if(t<=0)return;const e=t/1e3;this._timeSinceSpawn+=t;const s=Math.max(0,this._engineLoad-1),n=Math.hypot(this._vx,this._vy),r=this._condition>0&&s>0&&n<st.maxSpinSpeed&&this._surfaceKind!=="oil"?st.spawnRate*Math.min(s,1):0;if(r>0){const l=1e3/r;for(;this._timeSinceSpawn>=l;)this._spawnSpinDust(),this._timeSinceSpawn-=l}else this._timeSinceSpawn=0;this._emitSurface(t,n);const a=Math.pow(st.airResistance,t/16);for(let l=this._particles.length-1;l>=0;l-=1){const h=this._particles[l];if(h.age+=t,h.age>=h.lifetime){this._particleContainer.removeParticle(h.view),wt.release(h.view),this._particles.splice(l,1);continue}h.vx*=a,h.vy*=a,h.x+=h.vx*e,h.y+=h.vy*e;const u=h.age/h.lifetime,c=1-(1-u)*(1-u),_=(h.startSizeFactor+(h.endSizeFactor-h.startSizeFactor)*c)*this._particleScaleMultiplier*this._textureScale,f=h.view;f.x=h.x,f.y=h.y,f.scaleX=_,f.scaleY=_,f.alpha=h.startAlpha+(st.endAlpha-h.startAlpha)*u,f.rotation+=h.rotSpeed*e}}_emitSurface(t,e){const s=this._surfaceKind,n=ml.includes(s)?Pt[s]:null;if(!n||this._condition<=0||this._vz!==0||e<n.minSpeed){this._timeSinceSurfaceSpawn=0;return}const o=1e3/(n.rate*Math.min(e/n.fullSpeed,1));for(this._timeSinceSurfaceSpawn+=t;this._timeSinceSurfaceSpawn>=o;)this._spawnSurfaceDust(s,n),this._timeSinceSurfaceSpawn-=o}_stopTimer(){this._tickListener&&(Q.shared.remove(this._tickListener),this._tickListener=null)}destroy(t){this._stopTimer();for(let e=0;e<this._particles.length;e+=1)wt.release(this._particles[e].view);this._particles=[],super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}function yl({progress:i,totalDist:t,trailLength:e,trailShare:s=0}){const n=t*zt(i,0,1),o=Math.max(e,t*s),r=ct(o,0,zt(i,0,1));return{tail:Math.max(0,n-r),head:n}}class wl extends Qt{constructor(t,e,s,n,o,r=De,a={}){super(o),this.startPositionX=t,this.startPositionY=e,this.endPositionX=s,this.endPositionY=n,this.config=r,this._layerFor=a.layerFor||null,this._stopLine=a.stopLine||null,this.pieces=a.pieces?.length?a.pieces:[{from:0,to:1/0,level:null}],this._graphics=new Map;for(const{level:l}of this.pieces)if(!this._graphics.has(l)){const h=new U;h.blendMode="add",(this._layerFor?.(l)||this).addChild(h),this._graphics.set(l,h)}this.elapsedTime=0,this.progress=0,this._aim(),this.animationDuration=zt(this.totalDist/r.speed*1e3,r.minDuration,r.maxDuration)}_aim(){const t=this.endPositionX-this.startPositionX,e=this.endPositionY-this.startPositionY;this.totalDist=Math.hypot(t,e),this.totalDist>.001?(this.nx=t/this.totalDist,this.ny=e/this.totalDist):(this.nx=0,this.ny=0,this.totalDist=0)}shiftTo(t,e){this.isComplete||(this.endPositionX+=t-this.startPositionX,this.endPositionY+=e-this.startPositionY,this.startPositionX=t,this.startPositionY=e,this._clipToStopLine(),this._draw())}_clipToStopLine(){const t=this._stopLine;if(!t)return;const e=t.axis==="x",s=e?this.nx:this.ny;if(Math.abs(s)<1e-9)return;const n=e?this.startPositionX:this.startPositionY,o=(t.coord-n)/s;o<this.totalDist&&(this.totalDist=Math.max(0,o),this.endPositionX=this.startPositionX+this.nx*this.totalDist,this.endPositionY=this.startPositionY+this.ny*this.totalDist)}_clear(){for(const t of this._graphics.values())t.clear()}_draw(){this._clear();const{tail:t,head:e}=yl({progress:this.progress,totalDist:this.totalDist,trailLength:this.config.trailLength,trailShare:this.config.trailShare});e-t>.001&&this._drawTrail(t,e,ct(this.config.alphaStart,this.config.alphaEnd,this.progress))}_update(t){this.isComplete||(this.elapsedTime+=t,this.progress=Math.min(this.elapsedTime/this.animationDuration,1),this._draw(),this.elapsedTime>=this.animationDuration&&(this._clear(),this._completeEffect()))}_drawTrail(t,e,s){const{color:n,coreColor:o,coreWidth:r,glowWidth:a,glowAlpha:l}=this.config,h=Math.max(1,this.config.fadeSteps),u=[];for(let _=0;_<h;_+=1){const f=ct(t,e,_/h),p=ct(t,e,(_+1)/h),d=(_+1)/h;u.push({from:f,to:p,fade:d*d})}const c=this._split(u);for(const{graphics:_,from:f,to:p,fade:d}of c)_.moveTo(f[0],f[1]).lineTo(p[0],p[1]).stroke({width:a,color:n,alpha:s*l*d,cap:"round"});for(const{graphics:_,from:f,to:p,fade:d}of c)_.moveTo(f[0],f[1]).lineTo(p[0],p[1]).stroke({width:r,color:o,alpha:s*d,cap:"round"})}_split(t){const e=n=>[this.startPositionX+this.nx*n,this.startPositionY+this.ny*n],s=[];for(const{from:n,to:o,fade:r}of t)for(const a of this.pieces){const l=Math.max(n,a.from),h=Math.min(o,a.to);h-l>1e-6&&s.push({graphics:this._graphics.get(a.level),from:e(l),to:e(h),fade:r})}return s}destroy(t){for(const e of this._graphics.values())e.destroyed||(e.clear(),e.parent!==this&&e.destroy());this._graphics.clear(),super.destroy(t)}}function vl(i,t,e){const s=e||0;if(!(t>0))return[{from:0,to:0,level:s}];const n=(i||[]).filter(c=>c.t1>c.t0&&c.t0<t);if(n.length===0)return[{from:0,to:t,level:s}];const o=c=>Math.min(t,Math.max(0,c)),r=[...new Set([0,t,...n.flatMap(c=>[o(c.t0),o(c.t1)])])].sort((c,_)=>c-_),a=[];for(let c=0;c+1<r.length;c+=1){const _=r[c],f=r[c+1];if(f-_<1e-6)continue;const p=(_+f)/2;let d=null;for(const m of n)m.t0<=p&&p<m.t1&&(d===null||m.t0<d.t0)&&(d=m);const g=d?d.level:a.at(-1)?.level??s;is(a,_,f,g)}if(a.at(-1).level===s)return a;const l=n.filter(c=>c.level===s&&c.t0<t&&c.t1>=t-.001).sort((c,_)=>_.t0-c.t0)[0],h=l?o(l.t0):a.at(-1).from,u=[];for(const c of a)c.from<h&&is(u,c.from,Math.min(c.to,h),c.level);return is(u,h,t,s),u}function is(i,t,e,s){if(e-t<1e-6)return;const n=i.at(-1);n&&n.level===s&&Math.abs(n.to-t)<1e-6?n.to=e:i.push({from:t,to:e,level:s})}class Ml extends Qt{constructor(t,e,s,n,o,r,{surfaceK:a=null,startK:l=null}={}){super(o),this.x=t,this.y=e,this._assets=r;const{texture:h,contentSize:u}=this._assets.impactParticleTexture;this._particleTexture=h,this._textureContentSize=u,this.config={particleCount:F(2,4),particleMinSize:.8,particleMaxSize:2.4,minInitialSpeed:10,maxInitialSpeed:300,minLifetime:8e3,maxLifetime:15e3,color:[3355443,2236962,4473924],fadeOutStart:.8,impactDirectionX:s,impactDirectionY:n,spreadAngle:60,dragCoefficient:13,minSpeedThreshold:1,lingerDuration:6e3,fallDuration:250},this.config.impactDirectionX===0&&this.config.impactDirectionY===0?this.useOmnidirectionalSpread=!0:this.useOmnidirectionalSpread=!1,this.particlesData=[],this.elapsedTime=0,this._surfaceK=typeof a=="function"?a:null,this._startK=typeof l=="number"?l:null,this._createParticles()}_kAt(t){return this._surfaceK?this._surfaceK(this.x+t.x,this.y+t.y):null}_createParticles(){let t;this.useOmnidirectionalSpread||(t=Math.atan2(this.config.impactDirectionY,this.config.impactDirectionX));const s=this.config.spreadAngle*(Math.PI/180)/2;for(let n=0,o=this.config.particleCount;n<o;n+=1){let r;this.useOmnidirectionalSpread?r=Math.random()*Math.PI*2:r=t+F(-s,s);const a=F(this.config.minInitialSpeed,this.config.maxInitialSpeed),l=new J(this._particleTexture);l.anchor.set(.5);const h={sprite:l,x:0,y:0,vx:Math.cos(r)*a,vy:Math.sin(r)*a,size:F(this.config.particleMinSize,this.config.particleMaxSize),color:Array.isArray(this.config.color)?this.config.color[Math.floor(Math.random()*this.config.color.length)]:this.config.color,lifetime:F(this.config.minLifetime,this.config.maxLifetime),age:0,alpha:1,active:!0,isMoving:!0,timeSinceStopped:0,k:null,lift:1};h.k=this._kAt(h),l.tint=h.color,this.particlesData.push(h),this.addChild(l)}}_update(t){if(this.isComplete)return;this.elapsedTime+=t;const e=t/1e3;let s=0;for(let n=0,o=this.particlesData.length;n<o;n+=1){const r=this.particlesData[n];if(!r.active)continue;s+=1,r.age+=t;const a=Math.min(r.age/this.config.fallDuration,1);if(r.lift=1-a*a,r.isMoving){const c=Math.hypot(r.vx,r.vy);if(c>0){const f=c*this.config.dragCoefficient*e,p=Math.max(0,1-f/c);r.vx*=p,r.vy*=p}r.x+=r.vx*e,r.y+=r.vy*e,r.k=this._kAt(r),Math.hypot(r.vx,r.vy)<this.config.minSpeedThreshold&&(r.isMoving=!1,r.vx=0,r.vy=0)}else r.timeSinceStopped+=t;const l=r.age/r.lifetime;if(!r.isMoving&&r.timeSinceStopped>=this.config.lingerDuration){const c=r.timeSinceStopped-this.config.lingerDuration,_=Math.min(500,r.lifetime*(1-this.config.fadeOutStart));r.alpha=ct(1,0,Math.min(c/_,1))}else if(l>=this.config.fadeOutStart){const c=r.age-r.lifetime*this.config.fadeOutStart,_=r.lifetime*(1-this.config.fadeOutStart);r.alpha=_>0?ct(1,0,Math.min(c/_,1)):0}(r.age>=r.lifetime||r.alpha<.01)&&(r.active=!1,r.alpha=0);const h=r.sprite;h.position.set(r.x,r.y),h.alpha=r.alpha,h.visible=r.active;const u=r.size/this._textureContentSize;h.scale.set(u)}s===0&&this._isStarted&&this._completeEffect()}isFalling(){return this._startK!==null&&this.particlesData.some(t=>t.active&&t.lift>0)}project(t,e){if(!(!this._surfaceK&&this._startK===null))for(const s of this.particlesData){if(!s.active)continue;const n=s.k??e,o=this._startK===null?n:n+(this._startK-n)*s.lift,r=ke(this.x+s.x,this.y+s.y,t,e,o);s.sprite.position.set(r.x-this.x,r.y-this.y),s.sprite.scale.set(s.size/this._textureContentSize*r.scale)}}destroy(t){this.particlesData=[],super.destroy(t)}}function Sl(i,t=Math.random){const e=[],s=Math.max(1,i.spikes);for(let o=0;o<s;o+=1){const r=s===1?.5:(o+t())/s;e.push({angle:(r*2-1)*i.spread,length:1-t()*i.jitter})}const n=[1-t()*i.jitter,1-t()*i.jitter];return{forward:e,sides:n}}function bl({dirX:i,dirY:t,t:e,roll:s,config:n}){const o=1-zt(e,0,1),r=o*o,a=1-n.shrink*(1-o),l=Math.atan2(t,i),h=[],u=(c,_,f)=>{const p=Math.cos(c),d=Math.sin(c),g=f/2;return[-d*g,p*g,p*_,d*_,d*g,-p*g]};for(const c of n.layers){const _=c.scale*a,f=c.core?n.coreColor:n.color,p=c.alpha*r;if(!(p<=0)){for(const{angle:d,length:g}of s.forward)h.push({points:u(l+d,n.length*g*_,n.width*_),color:f,alpha:p});s.sides.forEach((d,g)=>{h.push({points:u(l+(g===0?Math.PI/2:-Math.PI/2),n.sideLength*d*_,n.sideWidth*_),color:f,alpha:p})})}}return h}class kl extends Qt{constructor(t,e,s,n,o,r=Kn,a=Math.random){super(o),this.position.set(t,e),this.dirX=s,this.dirY=n,this.config=r,this.roll=Sl(r,a),this.elapsedTime=0,this.graphics=new U,this.graphics.blendMode="add",this.addChild(this.graphics)}_update(t){if(this.isComplete)return;this.elapsedTime+=t,this.graphics.clear();const e=this.config.duration?this.elapsedTime/this.config.duration:1;if(e<1){const s=bl({dirX:this.dirX,dirY:this.dirY,t:e,roll:this.roll,config:this.config});for(const{points:n,color:o,alpha:r}of s)this.graphics.poly(n).fill({color:o,alpha:r})}else this._completeEffect()}destroy(t){this.graphics&&this.graphics.clear(),super.destroy(t)}}const pi=(i,t)=>Math.round(i/t)*t;function fn(i,t,e,s,n,o,r){const a=pi(i,n),l=pi(t,o),h=Math.abs(e)>1e-9&&Math.abs(i-a)<=r,u=Math.abs(s)>1e-9&&Math.abs(t-l)<=r;return h&&(!u||Math.abs(e)>=Math.abs(s))?{axis:"x",coord:a,nx:e>0?-1:1,ny:0}:u?{axis:"y",coord:l,nx:0,ny:s>0?-1:1}:null}function mi(i,t,e,s){return i.nx*(s.x-t)+i.ny*(s.y-e)>0}function Tl({x0:i,y0:t,dx:e,dy:s,face:n,camera:o,kBase:r,kLine:a}){const l=n.axis==="x",h=l?i:t,u=l?e:s,c=l?o.x:o.y;return Math.abs(u)<1e-9?null:(n.coord+(n.coord-c)*a+c*r-h*(1+r))/(u*(1+r))}const ns=2,gi=Fi+.5,os=.15;class Al extends ${constructor(t,e,s){super(),this.startPositionX=t[wr],this.startPositionY=t[vr],this.endPositionX=t[Mr],this.endPositionY=t[Sr],this.soundPositionX=t[br],this.soundPositionY=t[kr],this.hitCode=t[Tr]||0,this.hit=this.hitCode!==0,this.endLevel=t[Lr]||0,this.startLevel=t[Ar]||0,this.zIndex=W(ns,this.endLevel),this.anchorKey=null,this.anchorLocalX=0,this.anchorLocalY=0,Array.isArray(t[Hs])&&([this.anchorKey,this.anchorLocalX,this.anchorLocalY]=t[Hs]),this._assets=e,this._soundManager=s.soundManager,this._isLocalShot=s.localPlayer?.is(t[Qe])===!0,s.shots?.fired(t[Qe]),this._mapDynamics=s.mapDynamics||null,this._shots=s.shots||null,this._shooterId=t[Qe],this._levelView=s.levelView||null,this._lighting=s.lighting||null,this._volumes=s.volumes||null,this._rampRuns=s.rampRuns||null,this._wall=null,this._renderer=s.renderer||null,(this._levelView||this._renderer)&&(this.onRender=()=>{this._levelView&&(this.alpha=this._levelView.alphaFor(this.endLevel,this.endPositionX,this.endPositionY),this.tint=this._levelView.tintFor(this.endLevel));const n=ut(this.parent,this._renderer);gt(this,n,this.endLevel*B.shear,1);for(const[o,r]of this.layers)this._levelView&&(r.alpha=this._levelView.alphaFor(o,r.refX,r.refY),r.tint=this._levelView.tintFor(o)),gt(r,n,o*B.shear,1);this._followMuzzle(),this._placeFlash(n),this._placeDebris(n),this._placeImpactZ(n)}),this.tracer=null,this.layers=new Map,this.impact=null,this.flash=null,this._flashComplete=!0,this._isDestroyed=!1,this._visualsComplete=!1,this._soundComplete=!1,this._soundId=this._soundManager.registerSound("shot",{position:{x:this.soundPositionX,y:this.soundPositionY},spatial:!this._isLocalShot},()=>{this._soundComplete=!0,this._soundId=null,this._tryDestroy()}),this._soundId||(this._soundComplete=!0)}run(){if(this._isDestroyed)return;this._lighting?.flash({...St.flash.shot,level:this.startLevel,x:this.startPositionX,y:this.startPositionY,z:this.startLevel});const t=this.endPositionX-this.startPositionX,e=this.endPositionY-this.startPositionY,s=Math.hypot(t,e);s>.001&&(this._flashComplete=!1,this.flash=new kl(this.startPositionX,this.startPositionY,t/s,e/s,()=>{this._flashComplete=!0,this._tryDestroy()}),this.addChild(this.flash),this.flash.run());const n=this._slopeEnd(s)??this._wallEnd(t,e,s),o=vl(this._shots?.path?.(this.startPositionX,this.startPositionY,n.x,n.y,this.startLevel),n.dist,this.endLevel);this.tracer=new wl(this.startPositionX,this.startPositionY,n.x,n.y,this._onTracerComplete.bind(this),De,{pieces:o,layerFor:r=>this._layerFor(r,o),stopLine:n.stopLine}),this.addChild(this.tracer),this.tracer.run()}_wallAt(t,e){if(!this.hit)return null;if(this.hitCode===Pr){const c=2*os,_=this._floorAt(this.endPositionX+t*c,this.endPositionY+e*c),f=this._rampRuns?.faceAt?.(_,this.endPositionX,this.endPositionY,t,e,os);return f?{...f,base:_}:null}if(!this._volumes)return null;const{cellW:s,cellH:n}=this._volumes.cellSize();if(!(s>0&&n>0))return null;const o=fn(this.endPositionX,this.endPositionY,t,e,s,n,os);if(!o)return null;const r=.01*Math.min(s,n),a=this.endPositionX+t*r,l=this.endPositionY+e*r,h=this._floorAt(a,l),u=this._volumes.heightAt(h,a,l);return u>0?{face:o,volume:u,base:h}:null}_floorAt(t,e){const s=this._rampRuns?.floorAt?.(this.endLevel,t,e);return Number.isInteger(s)?s:this.endLevel}_wallEnd(t,e,s){const n={x:this.endPositionX,y:this.endPositionY,dist:s,stopLine:null};if(!(s>.001))return n;const o=t/s,r=e/s;if(this._wall=this._wallAt(o,r),!this._wall)return n;const a=this._levelView?.camera()??ut(this.parent,this._renderer);if(!a)return n;const{face:l,volume:h,base:u}=this._wall,{shear:c}=B,_=this.endLevel*c;let f,p;if(mi(l,this.endPositionX,this.endPositionY,a))({x:f,y:p}=ke(this.endPositionX,this.endPositionY,a,_,(this.endLevel+De.height)*c)),this.zIndex=W(gi,this.endLevel);else{const d=Tl({x0:this.startPositionX,y0:this.startPositionY,dx:o,dy:r,face:l,camera:a,kBase:_,kLine:(u+h)*c}),g=d===null?s:Math.min(s,Math.max(0,d));f=this.startPositionX+o*g,p=this.startPositionY+r*g}return{x:f,y:p,dist:Math.hypot(f-this.startPositionX,p-this.startPositionY),stopLine:{axis:l.axis,coord:l.axis==="x"?f:p}}}_slopeEnd(t){const e=this.hitCode===Gs&&t>.001?this._rampRuns?.slopeAt?.(this.endLevel,this.endPositionX,this.endPositionY):null;if(!e)return null;const s=this._levelView?.camera()??ut(this.parent,this._renderer),{shear:n}=B,{x:o,y:r}=ke(this.endPositionX,this.endPositionY,s,this.endLevel*n,e.height*n);return{x:o,y:r,dist:Math.hypot(o-this.startPositionX,r-this.startPositionY),stopLine:{axis:e.axis===0?"x":"y",coord:e.axis===0?o:r}}}_debrisSurface(){const t=this._rampRuns;if(typeof t?.heightAt!="function")return null;const e=this.endLevel,{shear:s}=B;return(n,o)=>{const r=this._floorAt(n,o),a=t.heightAt(r,n,o);return a!==null?a*s:r<e?r*s:null}}_debrisStartK(){const{shear:t}=B;return this._wall?(this.endLevel+De.height)*t:this.hitCode===Gs?null:this._floorAt(this.endPositionX,this.endPositionY)<this.endLevel?this.endLevel*t:null}_placeDebris(t){const e=this.impact;!e||e.destroyed||e.parent!==this||e.project(t,this.endLevel*B.shear)}_placeImpactZ(t){const e=this.impact;if(!this._wall||!e||e.destroyed)return;const s=!!(t&&mi(this._wall.face,this.endPositionX,this.endPositionY,t));this.zIndex=W(s&&e.isFalling()?gi:ns,this.endLevel)}_layerFor(t,e){const s=!!this._lighting?.isNight?.();if(!s&&t===this.endLevel||!this.parent)return this;let n=this.layers.get(t);if(!n){const o=e.find(u=>u.level===t),r=o?(o.from+o.to)/2:0,a=this.endPositionX-this.startPositionX,l=this.endPositionY-this.startPositionY,h=Math.hypot(a,l)||1;n=new $,n.label=`shot-tracer-${t}`,n.eventMode="none",n.zIndex=W(s?Gi:ns,t),n.refX=this.startPositionX+a/h*r,n.refY=this.startPositionY+l/h*r,this.parent.addChild(n),this.layers.set(t,n)}return n}_followMuzzle(){if(!this._shots||this.impact)return;const t=this.tracer&&!this.tracer.isComplete,e=this.flash&&!this.flash.isComplete;if(!t&&!e)return;const s=this._shots.muzzle(this._shooterId);s&&(this.startPositionX=s.x,this.startPositionY=s.y,t&&this.tracer.shiftTo(s.x,s.y))}_placeFlash(t){if(!this.flash||this.flash.destroyed)return;const{shear:e}=B,s=ke(this.startPositionX,this.startPositionY,t,this.endLevel*e,this.startLevel*e);this.flash.position.set(s.x,s.y),this.flash.scale.set(s.scale)}_onTracerComplete(){if(!this._isDestroyed)if(this.hit){let t=this.endPositionX,e=this.endPositionY;if(this.anchorKey!==null&&this._mapDynamics){const l=this._mapDynamics.toWorld(this.anchorKey,this.anchorLocalX,this.anchorLocalY);l&&(t=l.x,e=l.y)}const s=t-this.startPositionX,n=e-this.startPositionY,o=Math.hypot(s,n);let r=0,a=0;o>.001&&(r=-(s/o),a=-(n/o)),this.impact=new Ml(t,e,r,a,this._onImpactComplete.bind(this),this._assets,{surfaceK:this._debrisSurface(),startK:this._debrisStartK()}),this.addChild(this.impact),this.impact.run()}else this._visualsComplete=!0,this._tryDestroy()}_onImpactComplete(){this._isDestroyed||(this._visualsComplete=!0,this._tryDestroy())}_tryDestroy(){this._visualsComplete&&this._soundComplete&&this._flashComplete&&this.destroy()}destroy(){if(!this._isDestroyed){this._isDestroyed=!0,this._soundId&&(this._soundManager.unregisterSound(this._soundId),this._soundId=null),this.tracer&&(this.tracer.destroy(),this.tracer=null);for(const t of this.layers.values())t.destroy({children:!0});this.layers.clear(),this.impact&&(this.impact.destroy(),this.impact=null),this.flash&&(this.flash.destroy(),this.flash=null),this.parent&&this.parent.removeChild(this),super.destroy({children:!0})}}}class xi{constructor({texture:t,max:e,blendMode:s="normal",padding:n}){this.texture=t,this.max=e,this.items=[],this._padding=n,this.container=new Ke({texture:t,boundsArea:new rt(-n,-n,n*2,n*2),dynamicProperties:{position:!0,vertex:!0,rotation:!0,color:!0}}),this.container.blendMode=s}get size(){return this.items.length}follow(t,e){this.container.boundsArea.x=t-this._padding,this.container.boundsArea.y=e-this._padding}spawn(t){if(this.items.length>=this.max)return null;const e=wt.get(this.texture);return t.view=e,this.container.addParticle(e),this.items.push(t),t}removeAt(t){const[e]=this.items.splice(t,1);e&&(this.container.removeParticle(e.view),wt.release(e.view))}clear(){this.container.removeParticles();for(let t=0;t<this.items.length;t+=1)wt.release(this.items[t].view);this.items.length=0}}const Ll=2,Pl=Math.PI*2;class zl{constructor(t,e,{x:s,y:n,z:o,level:r,sizeScale:a}){const{textures:l}=e,h=new J(l[Math.floor(Math.random()*l.length)]);h.anchor.set(.5),h.rotation=Math.random()*Pl,h.alpha=0,h.zIndex=W(Ll,r),this.sprite=h,this.x=s,this.y=n,this.z=o,this.level=r,this.scale=K.scorch.size*a/e.contentSize,this.age=0,this.alpha=0,t.addChild(h),t.sortChildren()}get settled(){return this.age>=K.scorch.fadeIn}step(t){const{alpha:e,fadeIn:s}=K.scorch;this.age+=t,this.alpha=e*zt(this.age/s,0,1)}render(t,e){const s=this.z*B.shear,n=mt(this.x,this.y,t,s);this.sprite.position.set(n.x,n.y),this.sprite.scale.set(this.scale*(1+s));const o=e?e.alphaFor(this.level,this.x,this.y,this.z):1;this.sprite.alpha=this.alpha*o,e&&(this.sprite.tint=e.tintFor(this.level))}destroy(){this.sprite.destroy({texture:!1,textureSource:!1})}}const yi=(i,t)=>i>>t&255;function Me(i,t,e){const s=Math.min(Math.max(e,0),1),n=o=>{const r=yi(i,o);return Math.round(r+(yi(t,o)-r)*s)};return n(16)<<16|n(8)<<8|n(0)}function Cl(i,t){const[e,s]=i[0];if(t<=e)return s;for(let n=1;n<i.length;n+=1){const[o,r]=i[n];if(t<=o){const[a,l]=i[n-1];return Me(l,r,(t-a)/(o-a))}}return i[i.length-1][1]}function dn(i,t){return i<=t.duration?1:t.fadeOut>0?Math.max(0,1-(i-t.duration)/t.fadeOut):0}function _n(i){return i.duration+i.fadeOut}function El(i,t,e){const s=_n(t);if(i<s){const n=dn(i,t);return e.tailRate+(e.rate-e.tailRate)*n}return e.tailRate*Math.max(0,1-(i-s)/e.tail)}function Il(i,t){return _n(i)+t.tail}function Rl(i,t){return i<=0||i>=1?0:i<.12?t*(i/.12):i<=.45?t:t*(1-(i-.45)/.55)}const wi=4,vi=400,Fl=100,ne=Math.PI*2,Ie={min:.8,max:1.2},Re=1,Mi={min:.7,max:1.3},Si=.3,Xl=.6,bi=.5,Yl=.8,Dl=[[0,0]],Vl=.8,Ol=1.3,Bl=.5,lt=i=>F(i.min,i.max),Fe=i=>({kind:"flame",x:0,y:0,vx:0,vy:0,windX:0,windY:0,drag:0,h:0,rise:0,age:0,life:1,size0:0,width:0,grow:1,aspectX:1,aspectY:1,spin:0,alpha:1,scaleX:0,scaleY:0,...i});class Nl extends ${constructor(t,e,s={}){super(),this._readRow(t),this._condition=t[vt],this.zIndex=W(wi,this._level),this.visible=!1;const n=e.wreckFireTexture,o=e.wreckSmokeTexture;this._fireAsset=n||null,this._smokeAsset=o||null,this._scorchAsset=e.wreckScorchTexture||null,this._fireUnit=n?1/n.contentSize:0,this._smokeUnit=o?1/o.contentSize:0,this._enabled=!!n&&!!o,this._renderer=s.renderer||null,this._levelView=s.levelView||null,this._soundManager=s.soundManager||null,this._blasts=s.blasts||null,this._lighting=s.lighting?.enabled?s.lighting:null,this._active=!1,this._elapsed=0,this._flameAcc=0,this._smokeAcc=0,this._seed=0,this._tickListener=null,this._light=null,this._soundId=null,this._scorch=null,this._scorchPending=!1,this._fire=null,this._smoke=null,this._glow=null,this._flash=null,this._flashAge=0}_readRow(t){this._x=t[bt],this._y=t[kt],this._heading=t[Ft],this._z=t[Jt]||0,this._physLevel=t[pt]||0,this._vz=t[Ae]||0,this._level=Te(t[pt],this._z);const e=t[Pe]||K.referenceSize;this._length=e*4,this._width=e*3,this._sizeScale=e/K.referenceSize}update(t){const e=this._condition,s=this._level;this._readRow(t),this._level!==s&&(this.zIndex=W(wi,this._level)),this._active&&(this._fire.follow(this._x,this._y),this._smoke.follow(this._x,this._y));const n=t[vt];n!==void 0&&n!==e&&(this._condition=n,n===0&&e>0?this._ignite():n>0&&e===0&&this._reset()),this._scorchPending&&this._vz===0&&this._addScorch()}_ensureViews(){if(this._fire)return;const t=this._fireAsset.texture;this._smoke=new xi({texture:this._smokeAsset.texture,max:K.maxSmoke,padding:vi}),this._fire=new xi({texture:t,max:K.maxFire,blendMode:"add",padding:vi});const e=()=>{const s=new J(t);return s.anchor.set(.5),s.blendMode="add",s.visible=!1,s};this._glow=e(),this._flash=e(),this.addChild(this._glow,this._smoke.container,this._fire.container,this._flash)}_ignite(){this._enabled&&(this._reset(),this._ensureViews(),this._elapsed=0,this._flameAcc=0,this._smokeAcc=0,this._seed=Math.random()*1e3,this._active=!0,this.visible=!0,this._fire.follow(this._x,this._y),this._smoke.follow(this._x,this._y),this._explode(),this._notify(),this._addLight(),this._addScorch(),this._tickListener=t=>this._tick(t.deltaMS),Q.shared.add(this._tickListener),this.onRender=()=>this._render())}_explode(){const t=this._flash;this._flashAge=0,t.position.set(this._x,this._y),t.tint=K.flash.color,t.visible=!0,this._stepFlash(0);for(let e=0;e<K.fireball.count;e+=1)this._spawnFireball();for(let e=0;e<K.sparks.count;e+=1)this._spawnSpark();for(let e=0;e<K.smoke.burst.count;e+=1)this._spawnBurstSmoke()}_notify(){this._soundManager&&(this._soundId=this._soundManager.registerSound(K.sound,{position:{x:this._x,y:this._y}})),this._lighting?.flash({...St.flash.wreck,level:this._level,x:this._x,y:this._y,z:this._z}),this._blasts?.exploded({x:this._x,y:this._y,radius:K.joltRadius*this._sizeScale,level:this._physLevel})}_addLight(){this._lighting&&(this._light=this._lighting.addLight({kind:"radial",radius:St.wreckFire.radius*this._sizeScale,color:St.wreckFire.color,intensity:0}))}_addScorch(){const t=this._scorchAsset;if(!(!t||!this.parent)){if(this._vz!==0){this._scorchPending=!0;return}this._scorchPending=!1,this._scorch=new zl(this.parent,t,{x:this._x,y:this._y,z:this._z,level:this._level,sizeScale:this._sizeScale})}}_hullPoint(t,e){const[s,n]=t[Math.floor(Math.random()*t.length)],o=(s+F(-e,e)/2)*this._length,r=(n+F(-e,e)/2)*this._width,a=Math.cos(this._heading),l=Math.sin(this._heading);return{x:this._x+a*o-l*r,y:this._y+l*o+a*r}}_spawnFlame(t){const{fire:e,wind:s}=K,n=this._hullPoint(e.points,e.spread),o=this._fire.spawn(Fe({kind:"flame",x:n.x,y:n.y,vx:s.x*bi+F(-4,e.jitter)*this._sizeScale,vy:s.y*bi+F(-4,e.jitter)*this._sizeScale,windX:s.x,windY:s.y,rise:e.rise,life:lt(e.lifetime),size0:lt(e.size)*this._sizeScale*ct(Xl,1,t)*this._fireUnit,grow:e.grow,aspectX:lt(Ie),aspectY:lt(Ie),spin:F(-Re,Re),alpha:e.alpha}));o&&(o.view.rotation=Math.random()*ne,this._applyFire(o,0))}_spawnFireball(){const{fireball:t,wind:e}=K,s=this._hullPoint(Dl,Yl),n=Math.random()*ne,o=lt(t.speed)*this._sizeScale,r=this._fire.spawn(Fe({kind:"fireball",x:s.x,y:s.y,vx:Math.cos(n)*o,vy:Math.sin(n)*o,windX:e.x,windY:e.y,drag:t.drag,rise:t.rise,life:lt(t.lifetime),size0:lt(t.size)*this._sizeScale*this._fireUnit,grow:t.grow,aspectX:lt(Ie),aspectY:lt(Ie),spin:F(-Re,Re),alpha:t.alpha}));r&&(r.view.rotation=Math.random()*ne,this._applyFire(r,0))}_spawnSpark(){const{sparks:t}=K,e=Math.random()*ne,s=lt(t.speed)*this._sizeScale,n=this._fire.spawn(Fe({kind:"spark",x:this._x,y:this._y,vx:Math.cos(e)*s,vy:Math.sin(e)*s,drag:t.drag,life:lt(t.lifetime),size0:t.length*this._sizeScale*this._fireUnit,width:t.width*this._sizeScale*this._fireUnit}));n&&(n.view.rotation=e,this._applyFire(n,0))}_spawnSmoke(t){const{smoke:e}=K;this._emitSmoke({heat:t,speed:F(0,e.speed),lifeFactor:1,sizeFactor:1,alpha:ct(e.tailAlpha,e.alpha,t)})}_spawnBurstSmoke(){const{smoke:t}=K;this._emitSmoke({heat:1,speed:lt(t.burst.speed),lifeFactor:Vl,sizeFactor:Ol,alpha:t.burst.alpha})}_emitSmoke({heat:t,speed:e,lifeFactor:s,sizeFactor:n,alpha:o}){const{fire:r,smoke:a,wind:l}=K,h=this._hullPoint(r.points,r.spread),u=Math.random()*ne,c=e*this._sizeScale,_=Math.random(),f=Me(Me(a.cooling[0],a.cooling[1],_),Me(a.burning[0],a.burning[1],_),t),p=this._smoke.spawn(Fe({kind:"smoke",x:h.x,y:h.y,vx:Math.cos(u)*c+l.x,vy:Math.sin(u)*c+l.y,windX:l.x,windY:l.y,drag:a.drag,rise:a.rise,life:lt(a.lifetime)*s,size0:lt(a.size)*this._sizeScale*n*this._smokeUnit,grow:a.grow,aspectX:lt(Mi),aspectY:lt(Mi),spin:F(-Si,Si),alpha:o}));p&&(p.view.tint=f,p.view.rotation=Math.random()*ne,this._applySmoke(p,0))}_tick(t){if(!this._active)return;const e=zt(t,0,Fl);this._elapsed+=e;const s=dn(this._elapsed,K.fire);for(this._flameAcc+=K.fire.rate*s*e/1e3;this._flameAcc>=1;)this._flameAcc-=1,this._spawnFlame(s);for(this._smokeAcc+=El(this._elapsed,K.fire,K.smoke)*e/1e3;this._smokeAcc>=1;)this._smokeAcc-=1,this._spawnSmoke(s);this._stepChannel(this._fire,e,n=>this._applyFire(n,e)),this._stepChannel(this._smoke,e,n=>this._applySmoke(n,e)),this._stepFlash(e),this._stepGlow(s),this._stepLight(s),this._stepScorch(e),this._elapsed>=Il(K.fire,K.smoke)&&this._fire.size===0&&this._smoke.size===0&&!this._flash.visible&&this._scorchSettled()&&this._finish()}_stepChannel(t,e,s){const{items:n}=t;for(let o=n.length-1;o>=0;o-=1){const r=n[o];r.age+=e,r.age>=r.life?t.removeAt(o):s(r)}}_move(t,e){const s=Math.exp(-t.drag*e);return t.vx=t.windX+(t.vx-t.windX)*s,t.vy=t.windY+(t.vy-t.windY)*s,t.x+=t.vx*e,t.y+=t.vy*e,t.age/t.life}_applyFire(t,e){const s=e/1e3,n=this._move(t,s),o=t.view;if(t.kind==="spark"){const{colors:r}=K.sparks;t.scaleX=t.size0*(1-Bl*n),t.scaleY=t.width,o.rotation=Math.atan2(t.vy,t.vx),o.tint=Me(r[0],r[1],n),o.alpha=1-n}else{const r=1-(1-n)*(1-n),a=t.size0*(1+(t.grow-1)*r);t.scaleX=a*t.aspectX,t.scaleY=a*t.aspectY,t.h=t.rise*r,o.rotation+=t.spin*s,o.tint=Cl(K.fire.ramp,n),o.alpha=t.alpha*(1-n*n)}}_applySmoke(t,e){const s=e/1e3,n=this._move(t,s),o=t.view,r=t.size0*(1+(t.grow-1)*(1-(1-n)**3));t.scaleX=r*t.aspectX,t.scaleY=r*t.aspectY,t.h=t.rise*(1-(1-n)*(1-n)),o.rotation+=t.spin*s,o.alpha=Rl(n,t.alpha)}_stepFlash(t){const e=this._flash;if(!e.visible)return;const{duration:s,startSize:n,endSize:o,alpha:r}=K.flash;this._flashAge+=t;const a=this._flashAge/s;if(a>=1){e.visible=!1;return}const l=ct(n,o,1-(1-a)*(1-a))*this._sizeScale;e.scale.set(l*this._fireUnit),e.alpha=r*(1-a)*(1-a)}_stepGlow(t){const e=this._glow,s=K.glow;e.visible=t>0,e.visible&&(e.position.set(this._x,this._y),e.scale.set(s.size*this._sizeScale*this._fireUnit),e.tint=s.color,e.alpha=s.alpha*t*ce(this._seed,this._elapsed,s.flicker))}_stepLight(t){if(!this._light)return;if(t<=0){this._removeLight();return}const e=St.wreckFire;this._lighting.updateLight(this._light,{x:this._x,y:this._y,z:this._z,level:this._level,levels:$i(this._physLevel,this._z,this._vz!==0),intensity:e.intensity*t*ce(this._seed+1,this._elapsed,e.flicker)})}_stepScorch(t){this._scorch?.step(t)}_scorchSettled(){return!this._scorchPending&&(!this._scorch||this._scorch.settled)}_render(){const t=ut(this.parent,this._renderer),e=B.shear;if(this._active){const s=this._z*e;gt(this,t,s,1),this._levelView&&(this.alpha=this._levelView.alphaFor(this._level,this._x,this._y,this._z),this.tint=this._levelView.tintFor(this._level));for(const n of[this._fire,this._smoke])for(const o of n.items){const r=ke(o.x,o.y,t,s,s+o.h*e);o.view.x=r.x,o.view.y=r.y,o.view.scaleX=o.scaleX*r.scale,o.view.scaleY=o.scaleY*r.scale}}this._scorch?.render(t,this._levelView)}_finish(){this._stopTicker(),this._active=!1,this._flash.visible=!1,this._glow.visible=!1,this._removeLight(),this.visible=!1,this._scorch||(this.onRender=null)}_reset(){this._stopTicker(),this._fire&&(this._fire.clear(),this._smoke.clear(),this._flash.visible=!1,this._glow.visible=!1),this._removeLight(),this._soundId!==null&&(this._soundManager?.releaseSound(this._soundId),this._soundId=null),this._scorch?.destroy(),this._scorch=null,this._scorchPending=!1,this._active=!1,this.visible=!1,this.onRender=null}_stopTicker(){this._tickListener&&(Q.shared.remove(this._tickListener),this._tickListener=null)}_removeLight(){this._light&&(this._lighting.removeLight(this._light),this._light=null)}destroy(t){this._reset(),super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}const Ul={Map:Hr,MapRadar:Kr,TankRadar:qr,Tank:Ha,Bomb:$a,ExplosionEffect:al,Smoke:ul,Tracks:dl,Dust:xl,ShotEffect:Al,WreckFire:Nl};function Xt(i,t,{blur:e,quality:s=10,width:n,height:o}){const r=new ys({strength:e,quality:s});r.padding=en(e),t.filters=[r];const a=i.generateTexture({target:t,frame:new rt(0,0,n,o)});return t.destroy(!0),r.destroy(),a}function xe(i,t){const{radius:e,blur:s,color:n,quality:o=40}=i,r=new U,a=(e+Tt(s))*2,l=a/2;return r.circle(l,l,e),r.fill(n),{texture:Xt(t,r,{blur:s,quality:o,width:a,height:a}),contentSize:e*2}}function Wl(i,t){const{baseRadius:e,irregularity:s=0,blur:n=0,numPoints:o=20,colorFill:r,colorRim:a=r,rimWidth:l=0,variants:h=1}=i,u=Math.max(1,Math.floor(h)||1),c=(e+s+l)*2,_=c+Tt(n)*2,f=_/2,p=[];for(let d=0;d<u;d+=1){const g=new U,m=[];for(let w=0;w<o;w+=1){const M=w/o*Math.PI*2,b=e+F(-s,s);m.push(f+b*Math.cos(M),f+b*Math.sin(M))}g.poly(m).fill(r).stroke({width:l,color:a,alignment:1}),p.push(Xt(t,g,{blur:n,width:_,height:_}))}return{textures:p,contentSize:c}}function yt(i,t,e){const s=Math.hypot(i,t,e)||1,n=o=>Math.round((o/s*.5+.5)*255);return n(i)<<16|n(t)<<8|n(e)}const oe=yt(0,0,1);function pn(i,{x:t,y:e,w:s,h:n},{l:o,r,t:a,b:l},h){i.poly([t,e,t+s,e,t+s-r,e+a,t+o,e+a]).fill(h.t),i.poly([t,e+n,t+s,e+n,t+s-r,e+n-l,t+o,e+n-l]).fill(h.b),i.poly([t,e,t+o,e+a,t+o,e+n-l,t,e+n]).fill(h.l),i.poly([t+s,e,t+s-r,e+a,t+s-r,e+n-l,t+s,e+n]).fill(h.r)}function mn(i,t,e,s){const n=t.length/2;for(let o=0;o<n;o+=1){const r=(o+1)%n,a=t[o*2],l=t[o*2+1],h=t[r*2],u=t[r*2+1];let c=u-l,_=-(h-a);c*(a+h)+_*(l+u)<0&&(c=-c,_=-_),i.poly([a,l,h,u,h*e,u*e,a*e,l*e]).fill(s(c,_))}}const ot=10,He=ot*4,Ge=ot*3,Hl=13158852,tt={x:-He/2,y:-Ge/2,w:He,h:Ge},ae={x:-18,y:-9,w:36,h:18},gn={l:2,r:4,t:2,b:2},Gl=[{x:-19,y:-14,w:38,h:5},{x:-19,y:9,w:38,h:5}],$e=[1.33,-.42,.42,-1,-.42,-1,-1.33,-.42,-1.33,.42,-.42,1,.42,1,1.33,.42].map(i=>i*ot),xn=.6,Be={x:.25*ot,y:-.25*ot,w:2.08*ot},Se={x:2.1*ot,y:-.36*ot,w:.35*ot,h:.72*ot},rs={x:-.45*ot,y:.35*ot,r:.28*ot},_s={width:.08*ot},$l=.55;function yn(i){i.rect(tt.x,tt.y,tt.w,tt.h).fill(5592405);for(const t of Gl){i.rect(t.x,t.y,t.w,t.h).fill(3947580);for(let e=t.x+1;e<t.x+t.w;e+=3)i.rect(e,t.y,1,t.h).fill(2763306)}i.rect(ae.x,ae.y,ae.w,ae.h).fill(Hl),pn(i,ae,gn,{l:11119269,r:11974578,t:11119269,b:11119269});for(let t=-6;t<=5;t+=3)i.rect(-15,t,4,1).fill(7829619)}function ps(i,t){const e={..._s,color:qt(t,$l)},s={width:.06*ot,color:e.color};i.poly($e).fill(t).stroke(e),mn(i,$e,xn,()=>qt(t,.8)),i.circle(rs.x,rs.y,rs.r).fill(qt(t,.65)).stroke(s),i.rect(Be.x,Be.y,Be.w,2.5*2).fill(t).stroke(e),i.rect(Se.x,Se.y,Se.w,Se.h).fill(qt(t,.7)).stroke(s)}const ye={width:He,height:Ge};function Kl(i,t){const{colors:e}=i,s={},n=yn,o=ps,r=f=>{f.rect(tt.x,tt.y,tt.w,tt.h).fill(oe),f.rect(tt.x,tt.y,tt.w,1).fill(yt(0,-1,1)),f.rect(tt.x,tt.y+tt.h-1,tt.w,1).fill(yt(0,1,1)),f.rect(tt.x,tt.y+1,1,tt.h-2).fill(yt(-1,0,1)),f.rect(tt.x+tt.w-1,tt.y+1,1,tt.h-2).fill(yt(1,0,1)),pn(f,ae,gn,{l:yt(-1,0,1),r:yt(1,0,2),t:yt(0,-1,1),b:yt(0,1,1)})},a=f=>{f.poly($e).fill(oe).stroke({..._s,color:oe}),mn(f,$e,xn,(d,g)=>yt(d,g,1));const p=({x:d,y:g,w:m,h:w},M)=>{f.rect(d,g,m,w).fill(oe).stroke({...M,color:oe}),f.rect(d,g,m,w/2).fill(yt(0,-1,1)),f.rect(d,g+w/2,m,w/2).fill(yt(0,1,1))};p({...Be,h:2.5*2},_s),p(Se,{width:.06*ot})},l=(f,p)=>{const d=new U;f(d);const g=t.generateTexture({target:d,frame:p});return d.destroy(!0),g},h=f=>{const p=new U;f(p);const d=p.getBounds();return p.destroy(!0),new rt(d.x,d.y,d.width,d.height)},u=f=>{const p=h(n),d=h(m=>o(m,f)),g={x:-d.x/d.width,y:-d.y/d.height};return{body:l(n,p),bodyNormal:l(r,p),gun:l(m=>o(m,f),d),gunNormal:l(a,d),gunAnchor:g}},c=()=>{const f=new $,p=new U,d=new U;f.addChild(p,d);const g=3815994,m=2434341,w=3158064,M=1579032,b=5263440,v=He,S=Ge,y=ot;p.moveTo(-v/2-y*.1,-S/2+y*.2).lineTo(v/2+y*.2,-S/2-y*.1).lineTo(v/2-y*.1,S/2+y*.3).lineTo(-v/2+y*.3,S/2-y*.2).closePath().fill(g).stroke({width:y*.2,color:b,alignment:.5}),p.moveTo(-v/2+y*.4,-S/2+y*.5).lineTo(v/2-y*.3,-S/2+y*.2).lineTo(v/2-y*.4,S/2-y*.1).lineTo(-v/2+y*.2,S/2-y*.4).closePath().fill(m),p.circle(v*.15,S*.1,y*1.2).fill(M),p.circle(-v*.3,-S*.25,y*.5).fill(M),d.position.set(y*.3,-y*.2);const z=[y*1.1,-y*.7,y*.2,-y*1,-y*.6,-y*.9,-y*1.3,-y*.2,-y*1.1,y*.6,-y*.2,y*1,y*.7,y*.8,y*1.3,y*.1];d.poly(z).fill(w).stroke({width:y*.15,color:b,alignment:0});const T=[y*.8,-y*.25,y*1.5,-y*.4,y*1.4,y*.15,y*.7,y*.05];d.poly(T).fill(w).stroke({width:y*.1,color:b,alignment:0}),d.circle(y*.1,-y*.2,y*.4).fill(M);const L=f.getBounds(),R=t.generateTexture({target:f,frame:new rt(L.x,L.y,L.width,L.height)});f.destroy({children:!0});const D=new U().rect(L.x,L.y,L.width,L.height).fill(oe),I=t.generateTexture({target:D,frame:new rt(L.x,L.y,L.width,L.height)});return D.destroy(!0),{texture:R,normal:I}};s.liveTeamId1=u(e.teamId1),s.liveTeamId2=u(e.teamId2);const _=c();return s.destroyed=_.texture,s.destroyedNormal=_.normal,s}const ht=2;function Zl(i,{x:t,y:e,w:s,h:n}){i.rect(t,e,s,n).fill(3026478),i.rect(t,e,s,1).fill(3947580);const o=Math.max(1,n*.38);for(let r=t+o+1;r<t+s-o;r+=o*2.6)i.circle(r,e+n*.58,o).fill(4868682),i.circle(r,e+n*.58,o*.4).fill(2236962)}function ki(i,{x:t,y:e,w:s,h:n},o){i.rect(t,e,s,n).fill(qt(o,.75)),n>2&&i.rect(t,e+1,s,n-2).fill(o)}function jl(i,t,e=Mt){const{colors:s}=i,n=(o,r=!1)=>{const a=new U;ps(a,o);const l=a.getBounds();a.destroy(!0);const h=Math.ceil(l.width),u=Math.ceil(l.height),c={x:ht,y:ht,w:ye.width,h:ye.height,originX:ht+ye.width/2,originY:ht+ye.height/2},_={x:c.x+c.w+ht,y:ht,w:h,h:u,originX:c.x+c.w+ht-l.x,originY:ht-l.y},f=ht+Math.max(c.h,_.h)+ht,p={x:ht,y:f,w:ye.width,h:e.trackHeight},d={x:p.x+p.w+ht,y:f,w:22,h:e.barrelRadius*2},g={x:d.x+d.w+ht,y:f,w:8,h:e.brakeRadius*2},m={x:g.x+g.w+ht,y:f,w:4,h:4},w=Math.max(_.x+_.w,m.x+m.w)+ht,M=f+Math.max(p.h,d.h,g.h,m.h)+ht,b=new $,v=new U,S=new U,y=new U;if(yn(v),v.position.set(c.originX,c.originY),ps(S,o),S.position.set(_.originX,_.originY),Zl(y,p),ki(y,d,o),ki(y,g,qt(o,.7)),y.rect(m.x,m.y,m.w,m.h).fill(1710618),b.addChild(v,S,y),r){const T=new U;for(const L of[c,_,p,d,g])T.rect(L.x,L.y,L.w,L.h).fill({color:789e3,alpha:.62});T.circle(c.originX+4,c.originY+2,6).fill({color:0,alpha:.5}),T.circle(c.originX-9,c.originY-4,3).fill({color:0,alpha:.5}),T.circle(_.originX-2,_.originY+1,4).fill({color:0,alpha:.5}),b.addChild(T)}const z=t.generateTexture({target:b,frame:new rt(0,0,w,M)});return b.destroy({children:!0}),{texture:z,width:w,height:M,regions:{body:c,gun:_,trackSide:p,barrelSide:d,brakeSide:g,bottom:m}}};return{liveTeamId1:n(s.teamId1),liveTeamId2:n(s.teamId2),destroyed:n(3815994,!0)}}function ql(i,t){const{radius:e,borderWidth:s,crossSize:n,crossThickness:o,colors:r}=i,a={},l=(e+s)*2,h=l/2,u=15658734,c=3355443,_=p=>{const d=new U;d.circle(h,h,e).fill(u),d.circle(h,h,e-s).fill(p);const g=t.generateTexture({target:d,frame:new rt(0,0,l,l)});return d.destroy(!0),g},f=()=>{const p=new U,d=n/2;p.moveTo(h-d,h-d).lineTo(h+d,h+d).moveTo(h-d,h+d).lineTo(h+d,h-d).stroke({width:o,color:c});const g=t.generateTexture({target:p,frame:new rt(0,0,l,l)});return p.destroy(!0),g};return a.liveTeamId1=_(r.teamId1),a.liveTeamId2=_(r.teamId2),a.destroyed=f(),a}function Jl(i,t){const{colorOuter:e,colorInner:s}=i,n=new U,o=20,r=1;n.rect(0,0,o,o).fill(e),n.rect(r,r,o-r*2,o-r*2).fill(s);const a=t.generateTexture({target:n,frame:new rt(0,0,o,o)});return n.destroy(!0),a}function Ql(i,t){const{width:e,length:s,color:n}=i,o=new U;o.rect(0,0,s,e).fill(n);const r=t.generateTexture({target:o,frame:new rt(0,0,s,e)});return o.destroy(!0),r}function th(i,t){const{width:e,height:s,radius:n,blur:o,color:r,quality:a=20}=i,l=new U,h=Tt(o),u=e+h*2,c=s+h*2;return l.roundRect(h,h,e,s,n),l.fill(r),{texture:Xt(t,l,{blur:o,quality:a,width:u,height:c}),contentSize:e}}function Ti(i,t){const{baseRadius:e,irregularity:s=0,blur:n=0,numPoints:o=16,color:r,coreColor:a=r,coreRatio:l=.5,variants:h=1}=i,u=Math.max(1,Math.floor(h)||1),c=(e+s)*2,_=c+Tt(n)*2,f=_/2,p=[],d=(g,m)=>{const w=[];for(let M=0;M<o;M+=1){const b=M/o*Math.PI*2,v=g+F(-m,m);w.push(f+v*Math.cos(b),f+v*Math.sin(b))}return w};for(let g=0;g<u;g+=1){const m=new U;m.poly(d(e,s)).fill(r).poly(d(e*l,s*l)).fill(a),p.push(Xt(t,m,{blur:n,width:_,height:_}))}return{textures:p,contentSize:c}}function eh(i,t){const{length:e,width:s,color:n,variants:o=1}=i,r=Math.max(1,Math.floor(o)||1),a=e/2,l=[];for(let h=0;h<r;h+=1){const u=new U,c=F(s*.3,s)/2,_=F(s*.1,s*.6)/2;u.poly([0,a-_,e,a-c,e,a+c,0,a+_]).fill(n),l.push(t.generateTexture({target:u,frame:new rt(0,0,e,e)})),u.destroy(!0)}return{textures:l,contentSize:e}}function wn(i,t,e,s,n){for(let o=0;o<s;o+=1){const r=e*o/s,a=e*(o+1)/s,l=n((o+.5)/s);l<=0||(i.circle(t,t,a),i.fill({color:16777215,alpha:l}),r>0&&(i.circle(t,t,r),i.cut()))}}function Ai(i,t){const{radius:e,rings:s=32,blur:n=2,quality:o=10}=i,r=new U,a=Tt(n),l=(e+a)*2,h=l/2;return wn(r,h,e,s,Zi),{texture:Xt(t,r,{blur:n,quality:o,width:l,height:l}),contentSize:e*2}}function sh(i,t){const{length:e,halfWidth:s,strips:n=24,blur:o=4,quality:r=10}=i,a=new U,l=Tt(o),h=e+l*2,u=(s+l)*2,c=l,_=u/2;for(let p=0;p<n;p+=1){const d=e*p/n,g=e*(p+1)/n,m=s*p/n,w=s*(p+1)/n,M=(p+.5)/n,b=ji(M);a.poly([c+d,_-m,c+g,_-w,c+g,_+w,c+d,_+m]),a.fill({color:16777215,alpha:b})}return{texture:Xt(t,a,{blur:o,quality:r,width:h,height:u}),length:e,halfWidth:s,margin:l}}function ih(i,t){const{core:e,halo:s,rings:n=12,blur:o=1,quality:r=10}=i,a=new U,l=Tt(o),h=(s+l)*2,u=h/2,c=e/s;return wn(a,u,s,n,f=>f<=c?1:.6*(1-(f-c)/(1-c))**2),{texture:Xt(t,a,{blur:o,quality:r,width:h,height:h}),contentSize:s*2}}function nh(i,t){const{radius:e,strips:s=16,blur:n=2,quality:o=10}=i,r=new U,a=Tt(n),l=(e+a)*2,h=l/2;for(let c=0;c<s;c+=1){const _=e*c/s,f=e*(c+1)/s,p=(c+.5)/s;r.rect(h+_,h-e,f-_,e*2),r.fill({color:16777215,alpha:p*p})}return{texture:Xt(t,r,{blur:n,quality:o,width:l,height:l}),contentSize:e*2}}function oh(i){let t=i>>>0;return()=>{t=t+1831565813>>>0;let e=t;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}function rh(i,t){const{radius:e,rays:s=14,width:n=.05,strips:o=8,seed:r=1,blur:a=3,quality:l=10}=i,h=new U,u=Tt(a),c=(e+u)*2,_=c/2,f=oh(r);for(let d=0;d<s;d+=1){const g=(d+(f()-.5)*.8)/s*Math.PI*2,m=e*(.55+.45*f()),w=.35+.65*f(),M=n*(.5+f()),b=Math.cos(g-M),v=Math.sin(g-M),S=Math.cos(g+M),y=Math.sin(g+M);for(let z=0;z<o;z+=1){const T=m*z/o,L=m*(z+1)/o,R=(z+.5)/o;h.poly([_+b*T,_+v*T,_+b*L,_+v*L,_+S*L,_+y*L,_+S*T,_+y*T]),h.fill({color:16777215,alpha:w*(1-R)})}}return{texture:Xt(t,h,{blur:a,quality:l,width:c,height:c}),contentSize:e*2}}const ah={explosionTexture:xe,smokeTexture:xe,impactParticleTexture:xe,dustTexture:xe,wreckSmokeTexture:xe,wreckFireTexture:Ai,wreckScorchTexture:Ti,tankShadowTexture:th,funnelTexture:Wl,tankTexture:Kl,tankModelTexture:jl,tankRadarTexture:ql,bombTexture:Jl,trackMarkTexture:Ql,scorchTexture:Ti,debrisTexture:eh,lightRadialTexture:Ai,headlightConeTexture:sh,lampHeadTexture:ih,glintTexture:nh,lightShaftTexture:rh},lh=i=>(i??"").split(/[?#]/)[0].endsWith(".js"),hh=i=>import(i);function ch(i=$n,t={}){const e={level:0,x:0,y:0,z:0,camera:null,key:null,stage:t.stage||null,renderer:t.renderer||null,warned:!1,diagnostics:null},s=()=>{if(e.warned)return;e.warned=!0;const o=e.stage,r=e.renderer?.screen,a={destroyed:o?o.destroyed:null,position:o?{x:o.position?.x,y:o.position?.y}:null,scale:o?{x:o.scale?.x,y:o.scale?.y}:null,screen:r?{width:r.width,height:r.height}:null};console.warn("[tanks] levelView: центра камеры нет — кадр без трансформа сцены",a),e.diagnostics?.warn("tanks.camera.missing",a)},n=()=>{if(!e.stage)return null;if(e.stage.destroyed)return s(),null;const{position:o,scale:r}=e.stage,a=e.renderer?.screen,l=a?a.width:0,h=a?a.height:0,u=e.key;return(e.camera===null||u===null||u.x!==o.x||u.y!==o.y||u.scaleX!==r.x||u.scaleY!==r.y||u.width!==l||u.height!==h)&&(e.key={x:o.x,y:o.y,scaleX:r.x,scaleY:r.y,width:l,height:h},e.camera=ut(e.stage,e.renderer),e.camera===null&&s()),e.camera};return{attachStage(o,r){!o||!r||e.stage&&!e.stage.destroyed||(e.stage=o,e.renderer=r,e.key=null,e.camera=null)},setDiagnostics(o){!e.diagnostics&&o&&(e.diagnostics=o)},camera(){return n()},set(o,r,a,l=0){e.level=o,e.x=r,e.y=a,e.z=l},alphaFor(o,r,a,l=o){const h=n(),u=mt(e.x,e.y,h,e.z*B.shear),c=mt(r,a,h,l*B.shear);return so({viewLevel:e.level,viewX:u.x,viewY:u.y,level:o,x:c.x,y:c.y,cfg:i})},tintFor(o){return io(e.level,o,i)},get cfg(){return i},get mode(){return i.mode},get level(){return e.level},get x(){return e.x},get y(){return e.y},get z(){return e.z}}}function bs(i,t,e){const s=i.axis===0;return{alongX:s,a0:s?i.col0*t:i.row0*e,a1:s?i.col1*t:i.row1*e,b0:s?i.row0*e:i.col0*t,b1:s?i.row1*e:i.col1*t}}function vn(i,t){const e=i.sign>0?t:1-t;return i.from+(i.to-i.from)*e}function uh(i,t,e,s,n,o){const{alongX:r,a0:a,a1:l,b0:h,b1:u}=bs(i,t*e.x,t*e.y),c=(m,w)=>r?[m,w]:[w,m],_=r?i.col1-i.col0:i.row1-i.row0,f=Math.max(1,_*Math.max(1,Math.round(o)||1)),p=(m,w,M)=>[m+(m-s.x)*M,w+(w-s.y)*M],d=[],g=[];for(let m=0;m<=f;m+=1){const w=m/f,M=vn(i,w)*n,b=a+(l-a)*w;d.push(p(...c(b,h),M)),g.push(p(...c(b,u),M))}return[...d,...g.reverse()].flat()}function ks(i,t,e,s,n,o,r,a){let l=Math.floor(i/r),h=Math.floor(t/a);if(o(l,h,null,null,i,t))return 0;const u=e>0?1:-1,c=s>0?1:-1,_=e!==0?Math.abs(r/e):1/0,f=s!==0?Math.abs(a/s):1/0;let p=1/0,d=1/0;for(e!==0&&(p=((e>0?l+1:l)*r-i)/e),s!==0&&(d=((s>0?h+1:h)*a-t)/s);;){const g=l,m=h;let w;if(p<d?(w=p,l+=u,p+=_):(w=d,h+=c,d+=f),!(w<n))return n;if(o(l,h,g,m,i+e*w,t+s*w))return Math.max(0,w)}}const fh=.2;function Ts(i,t,e,s,n){const{alongX:o,a0:r,a1:a}=bs(i,s,n),l=o?t:e,h=a-r||1,u=Math.min(1,Math.max(0,(l-r)/h));return vn(i,u)}function dh({lane:i,prevLane:t,col:e,row:s,prevCol:n,prevRow:o,x:r,y:a,z:l,cellW:h,cellH:u,clearance:c=fh}){if(t&&t!==i){const p=t.axis===0?s!==o:e!==n;return!!i||!p}return!i||t===i||n===null||n===void 0||(i.axis===0?e-n:s-o)===i.sign?!1:Ts(i,r,a,h,u)-(l||0)>c}function Li(i,t,e,s,n,o,r){if(!i)return!1;const a=Math.max(0,s),l=Math.min(t-1,o),h=Math.max(0,n),u=Math.min(e-1,r);for(let c=h;c<=u;c+=1){const _=c*t;for(let f=a;f<=l;f+=1)if(i[_+f]!==0)return!0}return!1}function _h(i,t,e,s,n,o,r,a){const l=ks(i,t,e,s,n,o,r,a);return l>=n?null:{distance:l,x:i+e*l,y:t+s*l}}function ph({x:i,y:t,rotation:e,alongMax:s,alongBack:n=0,acrossMax:o,rays:r},a,l,h){const u=Math.max(2,Math.round(r)||2),c=n>0,_=c?Math.max(3,Math.round(u/8)):0,f=[];for(let m=0;m<u;m+=1)f.push(-Math.PI/2+Math.PI*m/(u-1));for(let m=0;m<_;m+=1)f.push(Math.PI/2+Math.PI*(m+1)/(_+1));const p=new Float32Array((f.length+1)*2),d=new Float32Array(f.length);let g=!1;return p[0]=i,p[1]=t,f.forEach((m,w)=>{const M=e+m,b=Math.cos(M),v=Math.sin(M),S=Math.cos(m),y=Math.abs(Math.sin(m));let z=y>1e-9?o/y:1/0;S>1e-9?z=Math.min(z,s/S):S<-1e-9&&(z=Math.min(z,n/-S));const T=ks(i,t,b,v,z,a,l,h);d[w]=z,T<z-1e-6&&(g=!0),p[(w+1)*2]=i+b*T,p[(w+1)*2+1]=t+v*T}),{points:p,clipped:g,closed:c,reaches:d,forward:u}}function As(i,t){const{width:e,height:s}=t.texture;if(i.kind==="cone")return{x:i.x,y:i.y,rotation:i.rotation||0,sx:i.radius/t.length,sy:i.radius*(i.spread??.5)/t.halfWidth,margin:t.margin,width:e,height:s};const n=i.radius*2/t.contentSize;return{x:i.x,y:i.y,rotation:0,sx:n,sy:n,margin:e/2,width:e,height:s}}function Ls(i,t,{x:e,y:s,rotation:n,sx:o,sy:r,margin:a,width:l,height:h},u=Math.cos(n),c=Math.sin(n)){const _=i-e,f=t-s,p=_*u+f*c,d=f*u-_*c;return[(a+p/o)/l,(h/2+d/r)/h]}function mh(i,t){const e=Math.cos(t.rotation),s=Math.sin(t.rotation),n=new Float32Array(i.length);for(let o=0;o<i.length;o+=2){const[r,a]=Ls(i[o],i[o+1],t,e,s);n[o]=r,n[o+1]=a}return n}const gh=[0,1,3,0,3,2];function xh({x:i,y:t,points:e,reaches:s,forward:n,uvOf:o,wallAt:r,cellW:a,cellH:l,height:h,level:u=0}){const c=.01*Math.min(a,l),_=v=>{const S=e[v*2],y=e[v*2+1],z=Math.hypot(S-i,y-t),T=s[v-1];if(!(z>1e-9)||!(z<T-1e-6))return null;const L=(S-i)/z,R=(y-t)/z,D=fn(S,y,L,R,a,l,.001);if(!D)return null;const I=r(S+L*c,y+R*c);return I>0?{face:D,x:S,y,endX:S+L*(T-z),endY:y+R*(T-z),height:Math.min(h,I)}:null},f=[];for(let v=1;v<=n;v+=1)f.push(_(v));const p=[];for(let v=0;v+1<f.length;v+=1){const S=f[v],y=f[v+1];S&&y&&S.face.axis===y.face.axis&&Math.abs(S.face.coord-y.face.coord)<1e-6&&p.push([S,y])}if(!p.length)return null;const d=new Float32Array(p.length*8),g=new Float32Array(p.length*4),m=new Float32Array(p.length*8),w=new Uint32Array(p.length*6),M=new Float32Array(p.length*2),b=new Float32Array(p.length*2);return p.forEach(([v,S],y)=>{[[v.x,v.y,v.height,v.endX,v.endY],[S.x,S.y,S.height,S.endX,S.endY],[v.x,v.y,0,v.x,v.y],[S.x,S.y,0,S.x,S.y]].forEach(([T,L,R,D,I],X)=>{const Y=y*4+X,[N,V]=o(D,I);d[Y*2]=T,d[Y*2+1]=L,g[Y]=u+R,m[Y*2]=N,m[Y*2+1]=V});for(let T=0;T<6;T+=1)w[y*6+T]=y*4+gh[T];M[y*2]=v.face.nx,M[y*2+1]=v.face.ny,b[y*2]=(v.x+S.x)/2,b[y*2+1]=(v.y+S.y)/2}),{base:d,heights:g,uvs:m,indices:w,normals:M,mids:b}}function Mn(i,t=!1){const e=Math.max(0,i-1),s=new Uint32Array((e+(t&&i>2?1:0))*3);for(let n=0;n<e;n+=1)s[n*3]=0,s[n*3+1]=n+1,s[n*3+2]=n+2;return t&&i>2&&(s[e*3]=0,s[e*3+1]=i,s[e*3+2]=1),s}function re(i,t,e,s){const n=[];for(let o=0;o<i.length;o+=1){const r=i[o],a=i[(o+1)%i.length],l=s?r[t]>=e:r[t]<=e,h=s?a[t]>=e:a[t]<=e;if(l&&n.push(r),l!==h){const u=(e-r[t])/(a[t]-r[t]);n.push([r[0]+(a[0]-r[0])*u,r[1]+(a[1]-r[1])*u])}}return n}function yh({points:i,closed:t,lane:e,frame:s,cellW:n,cellH:o,segmentsPerCell:r}){const{alongX:a,a0:l,a1:h,b0:u,b1:c}=bs(e,n,o),_=I=>a?[i[I*2],i[I*2+1]]:[i[I*2+1],i[I*2]],f=i.length/2;let p=1/0,d=-1/0,g=1/0,m=-1/0;for(let I=0;I<f;I+=1){const[X,Y]=_(I);p=Math.min(p,X),d=Math.max(d,X),g=Math.min(g,Y),m=Math.max(m,Y)}if(!(d>l&&p<h&&m>u&&g<c))return null;const w=a?e.col1-e.col0:e.row1-e.row0,M=Math.max(1,w*Math.max(1,Math.round(r)||1)),b=(h-l)/M,v=Math.cos(s.rotation),S=Math.sin(s.rotation),y=[],z=[],T=[],L=[],R=I=>{const X=z.length;for(const[Y,N]of I){const V=a?Y:N,G=a?N:Y,[j,H]=Ls(V,G,s,v,S);y.push(V,G),z.push(Ts(e,V,G,n,o)),T.push(j,H)}for(let Y=1;Y+1<I.length;Y+=1)L.push(X,X+Y,X+Y+1)},D=Mn(f-1,t);for(let I=0;I<D.length;I+=3){let X=[_(D[I]),_(D[I+1]),_(D[I+2])];if(X=re(X,1,u,!0),X=re(X,1,c,!1),X=re(X,0,l,!0),X=re(X,0,h,!1),X.length<3)continue;const Y=Math.min(...X.map(([j])=>j)),N=Math.max(...X.map(([j])=>j)),V=Math.max(0,Math.floor((Y-l)/b)),G=Math.min(M-1,Math.ceil((N-l)/b)-1);for(let j=V;j<=G;j+=1){const H=re(re(X,0,l+j*b,!0),0,l+(j+1)*b,!1);H.length>=3&&R(H)}}return L.length?{base:new Float32Array(y),heights:new Float32Array(z),uvs:new Float32Array(T),indices:new Uint32Array(L)}:null}const Xe=16777215;class Pi{constructor({level:t,ambient:e,resolution:s,area:n,roof:o=!1}){this.level=t,this.ambient=e,this.roof=o,this.overlay=new $,this.overlay.label=o?`lighting-roof-${t}`:`lighting-${t}`,this.overlay.zIndex=W(Po,t),this.overlay.eventMode="none",this.base=new J(Ue.WHITE),this.base.tint=t===0?e:Xe,this.base.position.set(n.x,n.y),this.base.width=n.width,this.base.height=n.height,this.overlay.addChild(this.base),this.mask=t>=1?new U:null,this.mask&&this.overlay.addChild(this.mask),this.lights=new $,this.overlay.addChild(this.lights),this.rampLights=new $,this.overlay.addChild(this.rampLights),this.rampMask=null,this.lightsMask=null,this.ramps=[],this.rampLightPool=[],this.shafts=new $,this.overlay.addChild(this.shafts),this.shaftPool=[],this.tops=new $,this.overlay.addChild(this.tops),this.topGroups=[],this.pool=[],this.fanPool=[],this.washPool=[],this.filter=new Ri({alpha:1}),this.filter.resolution=s,this.filter.blendMode="multiply",this.overlay.filters=[this.filter],this.overlay.filterArea=new rt(n.x,n.y,n.width,n.height),this.resolution=s,this.hole=hs(),this.hasMask=!1}setMask(t,e,s){if(this.mask){this.mask.clear(),this.hasMask=t.length>0;for(const n of t)this.mask.rect(n.col*e*s.x,n.row*e*s.y,n.length*e*s.x,e*s.y);this.hasMask&&this.mask.fill(this.ambient)}}setTops(t,e,s){for(const n of this.topGroups)n.graphics.destroy();this.topGroups=[];for(const{volume:n,runs:o}of t){if(!o.length)continue;const r=new U;for(const a of o)r.rect(a.col*e*s.x,a.row*e*s.y,a.length*e*s.x,e*s.y);r.fill(this.ambient),this.tops.addChild(r),this.topGroups.push({graphics:r,volume:n})}}setRamps(t,e,s,n){this.ramps=t,this.rampGeometry={step:e,scale:s,segments:n},t.length&&!this.rampMask?(this.rampMask=new U,this.lightsMask=new U,this.overlay.addChild(this.rampMask,this.lightsMask),this.rampLights.mask=this.rampMask,this.lights.setMask({mask:this.lightsMask,inverse:!0})):!t.length&&this.rampMask&&(this.rampLights.mask=null,this.lights.mask=null,this.rampMask.destroy(),this.lightsMask.destroy(),this.rampMask=null,this.lightsMask=null)}rampLevels(){return new Set(this.ramps.map(t=>t.to))}place(t,e){if(this.mask&>(this.mask,t,this.level*e,1),this.rampMask){const{step:s,scale:n,segments:o}=this.rampGeometry;this.rampMask.clear(),this.lightsMask.clear();for(const r of this.ramps){const a=uh(r,s,n,t,e,o);this.rampMask.poly(a),this.lightsMask.poly(a)}this.rampMask.fill(Xe),this.lightsMask.fill(Xe)}for(const{graphics:s,volume:n}of this.topGroups)gt(s,t,(this.level+n)*e,1)}syncFilters(){this.hole.attached?(this.hole.filter.blendMode="multiply",this.hole.filter.resolution=this.resolution):this.overlay.filters?.[0]!==this.filter&&(this.overlay.filters=[this.filter])}layout(t){wh(this.pool,this.lights,t.filter(e=>!e.fan)),vh(this.fanPool,this.lights,t.filter(e=>e.fan))}layoutWashes(t,e,s){ms(this.washPool,this.lights,t.length);for(let n=0;n<this.washPool.length;n+=1){const o=this.washPool[n],r=t[n];if(!r){o.visible=!1;continue}const{wash:a}=r,l=o.geometry;o.wash!==a&&(l.positions=new Float32Array(a.base.length),l.uvs=a.uvs,l.indices=new Uint32Array(a.indices.length),o.wash=a,o.facing=new Int8Array(a.normals.length/2).fill(-1));const h=l.positions;zi(h,a.base,a.heights,e,s),l.positions=h;const{normals:u,mids:c}=a,_=l.indices;let f=!1;for(let p=0;p<o.facing.length;p+=1){const d=e&&u[p*2]*(e.x-c[p*2])+u[p*2+1]*(e.y-c[p*2+1])>0?1:0;if(o.facing[p]!==d){o.facing[p]=d,f=!0;for(let g=0;g<6;g+=1)_[p*6+g]=d?a.indices[p*6+g]:p*4}}f&&(l.indices=_),gs(o,r)}}layoutRampLights(t,e,s){ms(this.rampLightPool,this.rampLights,t.length);for(let n=0;n<this.rampLightPool.length;n+=1){const o=this.rampLightPool[n],r=t[n];if(!r){o.visible=!1;continue}const{ramp:a}=r,l=o.geometry;o.ramp!==a&&(l.positions=new Float32Array(a.base.length),l.uvs=a.uvs,l.indices=a.indices,o.ramp=a);const h=l.positions;zi(h,a.base,a.heights,e,s),l.positions=h,gs(o,r)}}layoutShafts(t){for(;this.shaftPool.length<t.length;){const e=new $,s=new J,n=new U;s.anchor.set(.5),s.blendMode="add",e.addChild(s,n),this.shafts.addChild(e),this.shaftPool.push({container:e,sprite:s,shadow:n,masked:!1})}for(let e=0;e<this.shaftPool.length;e+=1){const s=this.shaftPool[e],n=t[e];if(!n){s.container.visible=!1;continue}const{container:o,sprite:r,shadow:a}=s,l=n.shadows||[];o.visible=!0,r.texture=n.texture,r.position.set(n.x,n.y),r.scale.set(n.scale),r.rotation=n.rotation,r.tint=n.color,r.alpha=n.alpha,a.clear();for(const u of l)a.poly(u);l.length&&a.fill(Xe);const h=l.length>0;h!==s.masked&&(s.masked=h,h?o.setMask({mask:a,inverse:!0}):(o.mask=null,a.visible=!1)),h&&(a.visible=!0)}}destroy(){const t=this.overlay;t.parent?.removeChild(t),cs(this.hole,t),t.filters=[],this.filter.destroy();for(const e of this.pool)e.texture=null;for(const e of[...this.fanPool,...this.rampLightPool,...this.washPool])e.texture=Ue.EMPTY,e.geometry.destroy();this.pool=[],this.fanPool=[],this.rampLightPool=[],this.washPool=[],this.rampLights.mask=null,this.lights.mask=null,this.rampMask=null,this.lightsMask=null,this.ramps=[];for(const e of this.shaftPool)e.container.mask=null,e.sprite.texture=null;this.shaftPool=[],this.topGroups=[],t.destroy({children:!0,texture:!1,textureSource:!1})}}function Sn(i,t){return i.levels.has(t)||i.roofLevels.has(t)}function ms(i,t,e){for(;i.length<e;){const s=new Xn({positions:new Float32Array(6),uvs:new Float32Array(6),indices:new Uint32Array(3)}),n=new Ii({geometry:s,texture:Ue.EMPTY});n.blendMode="add",i.push(n),t.addChild(n)}}function gs(i,t){i.visible=!0,i.texture=t.texture,i.tint=t.color,i.alpha=t.alpha}function zi(i,t,e,s,n){for(let o=0;o<e.length;o+=1){const r=t[o*2],a=t[o*2+1],l=s?e[o]*n:0;i[o*2]=s?r+(r-s.x)*l:r,i[o*2+1]=s?a+(a-s.y)*l:a}}function wh(i,t,e){for(;i.length<e.length;){const s=new J;s.blendMode="add",i.push(s),t.addChild(s)}for(let s=0;s<i.length;s+=1){const n=i[s],o=e[s];if(!o){n.visible=!1;continue}n.visible=!0,n.texture=o.texture,n.anchor.set(o.anchorX,o.anchorY),n.position.set(o.x,o.y),n.scale.set(o.scaleX,o.scaleY),n.rotation=o.rotation,n.tint=o.color,n.alpha=o.alpha}}function vh(i,t,e){ms(i,t,e.length);for(let s=0;s<i.length;s+=1){const n=i[s],o=e[s];if(!o){n.visible=!1;continue}const{fan:r}=o,{shape:a}=r;if(n.shape!==a){const l=n.geometry,h=a.points.length/2-1,u=`${h}:${!!a.closed}`;n.topology!==u&&(l.indices=Mn(h,a.closed),n.topology=u),l.positions=a.points,l.uvs=a.uvs,n.shape=a}gs(n,o),n.position.set(r.x,r.y),n.scale.set(r.scale)}}const Mh=.6;function Sh({getMap:i,cfg:t}){const e=new WeakMap;let s=0;const n=(f,p)=>{const d=i();d.blockers=new Map,d.rampCells=new Map,s+=1;const{cols:g,rows:m}=d;if(!(g>0&&m>0))return;const w=(M,b)=>M>=0&&M<g&&b>=0&&b<m;for(const[M,b]of f){let v=null;for(const{cells:S,volume:y}of b)for(const[z,T]of S)w(z,T)&&(v||=new Float32Array(g*m),v[T*g+z]=Math.max(v[T*g+z],y));v&&d.blockers.set(M,v)}for(const[M,b]of p){const v=[...b.values()].flat();if(!v.length)continue;const S=new Int32Array(g*m);v.forEach((y,z)=>{for(let T=y.row0;T<y.row1;T+=1)for(let L=y.col0;L<y.col1;L+=1)w(L,T)&&(S[T*g+L]=z+1)}),d.rampCells.set(M,{cells:S,lanes:v})}},o=f=>{const p=i(),d=f.level??0,g=p.blockers.get(d)||null,{cols:m,rows:w}=p,{cellW:M,cellH:b}=p,v=(T,L)=>T>=0&&T<m&&L>=0&&L<w?L*m+T:-1,S=p.rampCells.get(d)||null;if(!g&&!S)return null;const y=T=>S&&T>=0&&S.cells[T]>0?S.lanes[S.cells[T]-1]:null,z=y(v(Math.floor(f.x/M),Math.floor(f.y/b)));return(T,L,R,D,I,X)=>{const Y=v(T,L);if(g&&Y>=0&&g[Y]>0)return!0;if(!S||R===null||R===void 0)return!1;const N=y(Y),V=y(v(R,D));return z&&(N===z||V===z)?!1:dh({lane:N,prevLane:V,col:T,row:L,prevCol:R,prevRow:D,x:I,y:X,z:f.z??d,cellW:M,cellH:b})}},r=(f,p,d,g,m)=>{const w=i(),M=f.level??0,{cols:b,rows:v}=w,{cellW:S,cellH:y}=w,z=Math.cos(p),T=Math.sin(p);let L=1/0,R=1/0,D=-1/0,I=-1/0;for(const G of[-g,d])for(const j of[-m,m]){const H=f.x+G*z-j*T,xt=f.y+G*T+j*z;L=Math.min(L,H),R=Math.min(R,xt),D=Math.max(D,H),I=Math.max(I,xt)}const X=Math.floor(L/S)-1,Y=Math.floor(R/y)-1,N=Math.floor(D/S)+1,V=Math.floor(I/y)+1;return Li(w.blockers.get(M),b,v,X,Y,N,V)||Li(w.rampCells.get(M)?.cells,b,v,X,Y,N,V)},a=()=>t.headlights?.occlusion,l=(f,p,d)=>{const g=i(),m=g.blockers.get(f),w=Math.floor(p/g.cellW),M=Math.floor(d/g.cellH);return!m||w<0||w>=g.cols||M<0||M>=g.rows?0:m[M*g.cols+w]},h=(f,p,d)=>{const g=i(),m=g.rampCells.get(f),{cellW:w,cellH:M}=g,b=Math.floor(p/w),v=Math.floor(d/M);if(!m||b<0||b>=g.cols||v<0||v>=g.rows)return 0;const S=m.cells[v*g.cols+b];return S>0?Ts(m.lanes[S-1],p,d,w,M)-f:0};return{sync:n,occlusionOf:(f,p)=>{const d=a();if(!d?.enabled||!p||!(f.radius>0))return null;const g=f.level??0,m=f.rotation||0,w=f.spread??.5,M=`${f.x},${f.y},${f.z},${m},${g},${f.radius},${w},${s},${d.rays}`,b=e.get(f);if(b&&b.key===M&&b.texture===p.texture)return b;const v=o(f);if(!v)return null;const S=i(),{cellW:y,cellH:z}=S,T=As(f,p),L=(T.width-T.margin)*T.sx,R=T.margin*T.sx,D=T.height/2*T.sy;if(!r(f,m,L,R,D)){const H={key:M,texture:p.texture,shape:null,hit:null,wash:null,fan:null};return e.set(f,H),H}const{points:I,clipped:X,closed:Y,reaches:N,forward:V}=ph({x:f.x,y:f.y,rotation:m,alongMax:L,alongBack:R,acrossMax:D,rays:d.rays},v,y,z),G=t.headlights?.wash,j={key:M,texture:p.texture,shape:X?{points:I,closed:Y,uvs:mh(I,T)}:null,hit:_h(f.x,f.y,Math.cos(m),Math.sin(m),f.radius,v,y,z),fan:{points:I,closed:Y,frame:T},wash:G?.intensity>0?xh({x:f.x,y:f.y,points:I,reaches:N,forward:V,uvOf:(H,xt)=>Ls(H,xt,T),wallAt:(H,xt)=>Math.max(l(g,H,xt),h(g,H,xt)),cellW:y,cellH:z,height:G.height,level:g}):null};return e.set(f,j),j},reachesPoint:(f,p,d)=>{if(f.kind!=="cone"||!a()?.enabled)return!0;const g=o(f);if(!g)return!0;const m=Math.hypot(p-f.x,d-f.y);if(m<1e-6)return!0;const w=i();return ks(f.x,f.y,(p-f.x)/m,(d-f.y)/m,m,g,w.cellW,w.cellH)>=m},bounceOf:(f,p)=>{const d=t.headlights?.bounce;if(!d||!(d.intensity>0)||!(d.radius>0)||p.distance>(d.maxDistance??f.radius))return null;const g=f.rotation||0,m=d.radius*Mh;return{kind:"radial",level:f.level,levels:f.levels,x:p.x-Math.cos(g)*m,y:p.y-Math.sin(g)*m,z:f.z,radius:d.radius,color:f.color,intensity:(f.intensity??1)*d.intensity*(1-p.distance/f.radius)}}}}function bh({getMap:i,textures:t}){const e=new WeakMap,s=new WeakMap,n=(a,l)=>{const h=`${a.kind},${a.x},${a.y},${a.rotation},${a.radius},${a.spread}`,u=e.get(a);if(u&&u.key===h&&u.texture===l.texture)return u.fan;const c=As(a,l),_=Math.cos(c.rotation),f=Math.sin(c.rotation),p=-c.margin*c.sx,d=(c.width-c.margin)*c.sx,g=c.height/2*c.sy,m=new Float32Array(10);m[0]=c.x,m[1]=c.y,[[p,-g],[d,-g],[d,g],[p,g]].forEach(([M,b],v)=>{m[(v+1)*2]=c.x+M*_-b*f,m[(v+1)*2+1]=c.y+M*f+b*_});const w={points:m,closed:!0,frame:c};return e.set(a,{key:h,texture:l.texture,fan:w}),w};return{push:(a,l,h,u,c,_)=>{if(!h?.length)return!1;const f=i(),p=u.kind==="cone"?t.cone:t.radial,d=c.rampFan??n(u,p);let g=s.get(d.points);g||(g=new Map,s.set(d.points,g));let m=!1;for(const w of h){g.has(w)||g.set(w,yh({points:d.points,closed:d.closed,lane:w,frame:d.frame,cellW:f.cellW,cellH:f.cellH,segmentsPerCell:Rt.rampSegments}));const M=g.get(w);M&&(a.has(l)||a.set(l,[]),a.get(l).push({ramp:M,texture:c.texture,color:c.color,alpha:_}),m=!0)}return m},targets:()=>{const a=new Map;for(const l of i().levels.values())for(const h of l.rampLevels())a.has(h)||a.set(h,[]),a.get(h).push(l.level);return a}}}function kh({getMap:i,lights:t,flashes:e,cfg:s,reachesPoint:n}){let o=null,r=0;const a=(h,u,c,_,f)=>{const p=i(),d=[],g=m=>(m.levels??[m.level??0]).includes(c);for(const m of Do(p.lampGrid,h,u))m.level===c&&d.push({light:m,factor:ce(m.seed,f,m.flicker)});for(const m of t)m.kind==="cone"&&!_?.includes(m)&&g(m)&&qi(m,h,u)>0&&n(m,h,u)&&d.push({light:m,factor:1});for(const m of e){const w=Ki(f-m.start,m.duration);w>0&&g(m)&&d.push({light:m,factor:w})}return d};return{lightsAt:(h,u,c,_=1,f=null)=>{if(!(_>0))return[];const p=Q.shared.lastTime;if(o!==p&&(o=p,r=0),r>=s.maxLights)return[];const d=Xo(a(h,u,c,f,p),h,u,_);return d.length&&(r+=1),d},candidatesAt:a}}const Th=.08;function Ah({lamp:i,view:t,reach:e,camera:s,shaftsCfg:n,casters:o,shear:r}){if(!n.shadows||!(n.maxShadowCasters>0))return[];const a=i.radius*n.length,l=[];for(const u of o.values()){const c=Math.hypot(u.x-i.x,u.y-i.y);u.level===i.level&&c<a&&l.push({caster:u,distance:c})}l.sort((u,c)=>u.distance-c.distance);const h=[];for(const{caster:u}of l.slice(0,n.maxShadowCasters)){const c=(u.z??u.level)*r,_=mt(u.x,u.y,s,c),f=Vo(t.x,t.y,_.x,_.y,u.radius*(1+c),e);f&&h.push(f)}return h}function Lh({map:i,casters:t,cfg:e,asset:s,camera:n,screen:o,now:r,stage:a,shear:l}){const h=new Map,u=e.shafts;if(!u?.enabled||!s)return h;let c=0;for(const _ of i.lamps){if(!_.head||!Sn(i,_.level))continue;if(c>=e.maxLights)break;const f=Ve(_.x,_.y,_.level,n,a,l),p=_.radius*u.length*f.scale;!(p>0)||!us(f.screenX,f.screenY,p*a.scale.x,o.width,o.height)||(h.has(_.level)||h.set(_.level,[]),h.get(_.level).push({texture:s.texture,x:f.x,y:f.y,scale:p*2/s.contentSize,rotation:Oo(_.seed,r,Th),color:_.color,alpha:u.intensity*_.intensity*ce(_.seed,r,_.flicker),shadows:Ah({lamp:_,view:f,reach:p,camera:n,shaftsCfg:u,casters:t,shear:l})}),c+=1)}return h}const Ph=3818080,zh=["radial","cone","head","glint","shaft"];function Ch(i,t,e){const s=(i?.cols??0)*t*e.x,n=(i?.rows??0)*t*e.y,o=Math.max(s,n);return{x:-o,y:-o,width:s+o*2,height:n+o*2}}function Eh(i=St,t={}){const e=!!i.enabled,s=t.levelView||null,n=t.volumes||null,o=t.shear??B.shear;let r=null,a=null;const l={},h=new Set,u=new Map,c=[],_=new Map;let f=null;const p=new Map;let d=null;const g=new Map,m=new Map;let w=null;const M=new Map;let b=!1,v=null;const S=Sh({getMap:()=>d,cfg:i}),y=kh({getMap:()=>d,lights:h,flashes:c,cfg:i,reachesPoint:S.reachesPoint}),z=bh({getMap:()=>d,textures:l}),T=()=>s?.cfg||null,L=(x,k,P,A)=>{let E=x.get(A);return E||(E=new $,E.label=`${P}-${A}`,E.zIndex=W(k,A),E.eventMode="none",x.set(A,E)),E},R=x=>L(d.emissive,Gi,"emissive",x),D=x=>L(d.lampHeads,zo,"lamp-heads",x),I=()=>{if(!(!d?.night||!l.head||d.headsReady)){d.headsReady=!0;for(const x of d.lamps){if(!x.head)continue;const k=new J(l.head.texture);k.anchor.set(.5),k.blendMode="add",k.tint=x.color,x.headSprite=k,D(x.level).addChild(k)}}},X=(x,k,P,A)=>{const E=x||{},Z=!!E.night,q=Le(P??1);if(d={night:Z,ambient:E.ambient??Ph,step:k,scale:q,cellW:k*q.x,cellH:k*q.y,area:Ch(A,k,q),cols:A?.cols??0,rows:A?.rows??0,blockers:new Map,rampCells:new Map,lamps:[],headsReady:!1,levels:new Map,roofLevels:new Map,emissive:new Map,lampHeads:new Map,maskCells:new Map,roofCells:new Map},!!Z){(E.lamps||[]).forEach((at,Et)=>{const[te,Yt]=at.cell||[0,0],ee=at.level||0,O=Io(te,Yt,k,q);d.lamps.push({kind:"radial",level:ee,x:O.x,y:O.y,z:ee,radius:at.radius??0,rotation:0,color:at.color??16777215,intensity:at.intensity??1,flicker:at.flicker||0,seed:Et+1,head:!!at.head,headSprite:null})});for(const[at,Et]of u)R(Et).addChild(at);d.lampGrid=Yo(d.lamps,Math.max(1,...d.lamps.map(at=>at.radius))),I(),b=!0,v=null}},Y=()=>{if(d){for(const x of[...d.emissive.values(),...d.lampHeads.values()])x.parent?.removeChild(x);for(const x of V())x.overlay.parent?.removeChild(x.overlay);for(const x of d.emissive.values())for(const k of u.keys())k.parent===x&&x.removeChild(k);for(const x of d.lamps)x.headSprite&&(x.headSprite.destroy({texture:!1,textureSource:!1}),x.headSprite=null);for(const x of[...d.emissive.values(),...d.lampHeads.values()])x.destroy({children:!0});for(const x of V())x.destroy();d=null,v=null}},N=()=>{Y(),g.clear(),m.clear(),M.clear(),b=!1,w=null,f=null},V=()=>[...d.levels.values(),...d.roofLevels.values()],G=()=>n?.levels()??new Map,j=()=>n!==null&&n.version!==w,H=(x,k=null)=>{const P=[],A=new Set;for(const E of x?.values()||[])for(const Z of E){const q=`${Z[0]},${Z[1]}`;!A.has(q)&&!k?.has(q)&&(A.add(q),P.push(Z))}return[P,A]},xt=(x,k,P,A)=>{let E=x.get(k);if(P.length===0){E&&(E.destroy(),x.delete(k));return}E||(E=new Pi({level:k,ambient:d.ambient,resolution:i.resolution,area:d.area,roof:A}),x.set(k,E)),E.setMask(Ys(P),d.step,d.scale)},Ct=x=>{const k=new Map;for(const{cells:P,volume:A}of G().get(x)||[])k.has(A)||k.set(A,[]),k.get(A).push(...P);return[...k].map(([P,A])=>({volume:P,runs:Ys(A)}))},Bt=()=>{j()&&(w=n.version,b=!0);const x=b;if(b){b=!1;const k=new Set([...g.keys(),...m.keys(),...d.levels.keys(),...d.roofLevels.keys()]);for(const P of k){if(P<1)continue;const[A,E]=H(m.get(P)),[Z,q]=H(g.get(P),E);d.maskCells.set(P,q),d.roofCells.set(P,E),xt(d.levels,P,Z,!1),xt(d.roofLevels,P,A,!0)}}if(d.levels.has(0)||d.levels.set(0,new Pi({level:0,ambient:d.ambient,resolution:i.resolution,area:d.area})),x){S.sync(G(),M);for(const k of d.levels.values())k.setTops(Ct(k.level),d.step,d.scale),k.setRamps([...M.get(k.level)?.values()||[]].flat(),d.step,d.scale,Rt.rampSegments)}},Nt=()=>{for(const x of V())x.overlay.parent!==r&&r.addChild(x.overlay);for(const x of[...d.emissive.values(),...d.lampHeads.values()])x.parent!==r&&r.addChild(x)},Ut=(x,k,P)=>{const A=x.kind==="cone"?l.cone:l.radial;if(!A||!(x.intensity*P>0))return null;const E=Ve(x.x,x.y,x.z??x.level,k,r,o),Z=As(x,A),q={reach:x.radius*E.scale*r.scale.x,view:E,texture:A.texture,anchorX:Z.margin/Z.width,anchorY:.5,scaleX:Z.sx*E.scale,scaleY:Z.sy*E.scale,rotation:Z.rotation,color:x.color,alpha:x.intensity*P};return x.kind==="cone"&&(q.fan=null,q.hit=null),q},Wt=(x,k)=>{if(k.kind!=="cone")return;const P=S.occlusionOf(k,l.cone);if(!P)return;const{view:A}=x;P.shape&&(x.fan={shape:P.shape,x:A.x-k.x*A.scale,y:A.y-k.y*A.scale,scale:A.scale}),x.hit=P.hit,x.wash=P.wash,x.rampFan=P.fan},nt=(x,k,P)=>{const A=new Map,E=new Map,Z=new Map;let q=0;const at=z.targets(),Et=i.rampSpill??1,te=[],Yt=(O,Dt)=>{const $t=O.levels??[O.level],zs=$t.filter(dt=>Sn(d,dt)),Cs=Et>0?$t.flatMap(dt=>at.get(dt)||[]).filter(dt=>!$t.includes(dt)):[];if(q>=i.maxLights||zs.length===0&&Cs.length===0)return;const et=Ut(O,x,Dt);if(!et||!us(et.view.screenX,et.view.screenY,et.reach,k.width,k.height))return;et.x=et.view.x,et.y=et.view.y,Wt(et,O);const ze=O.level??0;et.wash&&d.levels.has(ze)&&(Z.has(ze)||Z.set(ze,[]),Z.get(ze).push({wash:et.wash,texture:et.texture,color:et.color,alpha:et.alpha*i.headlights.wash.intensity}));for(const dt of zs){if(q>=i.maxLights)return;A.has(dt)||A.set(dt,[]),A.get(dt).push(et),q+=1,z.push(E,dt,d.levels.get(dt)?.ramps,O,et,et.alpha)}for(const dt of new Set(Cs)){if(q>=i.maxLights)return;const Tn=d.levels.get(dt)?.ramps.filter(An=>$t.includes(An.to));z.push(E,dt,Tn,O,et,et.alpha*Et)&&(q+=1)}const Es=et.hit?S.bounceOf(O,et.hit):null;Es&&te.push({light:Es,factor:Dt})};for(let O=c.length-1;O>=0;O-=1){const Dt=c[O],$t=Ki(P-Dt.start,Dt.duration);$t<=0?c.splice(O,1):Yt(Dt,$t)}for(const O of h)Yt(O,1);for(const O of d.lamps)Yt(O,ce(O.seed,P,O.flicker));for(const{light:O,factor:Dt}of te)Yt(O,Dt);const ee=Lh({map:d,casters:_,cfg:i,asset:l.shaft,camera:x,screen:k,now:P,stage:r,shear:o});for(const O of V())O.place(x,o),O.layout(A.get(O.level)||[]),O.roof||O.layoutWashes(Z.get(O.level)||[],x,o),O.layoutRampLights(O.roof?[]:E.get(O.level)||[],x,o),O.layoutShafts(ee.get(O.level)||[])},Ht=x=>{const k=T();if(!k)return;const P=mt(s.x,s.y,x,s.z*o);for(const A of V()){if(A.level<1)continue;const E=s.level<A.level,Z=A.roof&&E&&to(d.roofCells.get(A.level),d.step,d.scale,P,x,[A.level*o],k.roofMargin??0),q=A.overlay,at=Vi(A.hole,k.fadeRate);if(s.mode==="layer"){let Et=Z;if(!A.roof){const Yt=he(s.x,d.scale.x,d.step),ee=he(s.y,d.scale.y,d.step);Et=E&&!!d.maskCells.get(A.level)?.has(`${Yt},${ee}`)}const te=Et?k.layerAlpha:1;q.alpha+=(te-q.alpha)*at;continue}ws(A.hole,A.roof?Z:E,at),vs(q,A.hole,k,s,r,x),A.syncFilters()}},Gt=(x,k)=>{for(const P of d.lamps){const A=P.headSprite;if(!A)continue;const E=Ve(P.x,P.y,P.level,x,r,o);A.position.set(E.x,E.y),A.scale.set(E.scale),A.alpha=(s?s.alphaFor(P.level,E.x,E.y,0):1)*ce(P.seed,k,P.flicker)}},ft=()=>e&&d?.night===!0;return{get enabled(){return e},attachStage(x,k){!e||r||!x||!k||(r=x,a=k,v=null,s?.attachStage(x,k))},acquireMap(x,k,P,A,E){e&&(p.set(x,(p.get(x)||0)+1),x!==f&&(Y(),f=x,X(k,P,A,E)))},releaseMap(x,k){if(!e)return;if(k!==void 0)for(const A of[g,m,M])for(const E of A.values())E.delete(k)&&(b=!0);const P=p.get(x);if(P!==void 0){if(P>1){p.set(x,P-1);return}p.delete(x),x===f&&N()}},setLevelMask(x,k,P,{roof:A=!1}={}){if(!e||!(x>=1))return;const E=A?m:g;E.has(x)||E.set(x,new Map),k&&k.length>0?E.get(x).set(P,k):E.get(x).delete(P),b=!0},setRampWedges(x,k,P){if(!e||!(x>=0))return;M.has(x)||M.set(x,new Map);const A=(k||[]).filter(E=>E.from===x&&E.to>E.from);A.length>0?M.get(x).set(P,A):M.get(x).delete(P),b=!0},registerTextures(x){if(!(!e||!x)){for(const k of zh){const P=x[k];if(!P)continue;const A=l[k];if(l[k]=P,k==="head"&&A&&A!==P){for(const E of u.keys())E.texture===A.texture&&(E.texture=P.texture);for(const E of d?.lamps||[])E.headSprite&&(E.headSprite.texture=P.texture)}}l.head&&I()}},texture(x){return l[x]||null},addLight(x){if(!e)return null;const k={kind:"radial",level:0,x:0,y:0,radius:0,rotation:0,color:16777215,intensity:1,...x};return h.add(k),k},updateLight(x,k){x&&h.has(x)&&Object.assign(x,k)},removeLight(x){h.delete(x)},flash(x){!ft()||!l.radial||c.push({kind:"radial",level:0,color:16777215,intensity:1,...x,start:Q.shared.lastTime})},addEmissive(x,k){return!ft()||!x?!1:(u.get(x)!==void 0&&x.parent&&x.parent.removeChild(x),u.set(x,k||0),R(k||0).addChild(x),!0)},removeEmissive(x){if(u.has(x)){u.delete(x);for(const k of d?.emissive.values()||[])x.parent===k&&k.removeChild(x)}},isNight:ft,lightsAt(x,k,P,A=1,E=null){return ft()?y.lightsAt(x,k,P,A,E):[]},onScreen(x,k,P,A){if(!r||!a?.screen)return!1;const E=s?s.camera():ut(r,a);if(!E)return!1;const Z=Ve(x,k,P,E,r,o);return us(Z.screenX,Z.screenY,A*Z.scale*r.scale.x,a.screen.width,a.screen.height)},setCaster(x,k){e&&(k?_.set(x,k):_.delete(x))},castsShadows(){const x=i.shafts;return ft()&&!!(x?.enabled&&x.shadows&&x.maxShadowCasters>0)},render(){if(!ft()||!r||!a)return;const x=s?s.camera():ut(r,a),k=a.screen;if(!x||!k)return;const P=Q.shared.lastTime,A=v;A!==null&&A.tick===P&&A.x===r.position.x&&A.y===r.position.y&&A.scaleX===r.scale.x&&A.scaleY===r.scale.y&&A.width===k.width&&A.height===k.height&&!b&&!j()||(v={tick:P,x:r.position.x,y:r.position.y,scaleX:r.scale.x,scaleY:r.scale.y,width:k.width,height:k.height},Bt(),I(),Nt(),nt(x,k,P),s&&Ht(x),Gt(x,P))},clear:N}}function Ih({segments:i=null}={}){const t=new Map;return{subscribe(e,s){const n=String(e);return t.has(n)||t.set(n,new Set),t.get(n).add(s),()=>{const o=t.get(n);o&&(o.delete(s),o.size===0&&t.delete(n))}},fired(e){const s=t.get(String(e));if(s)for(const n of s)n.fired?.()},muzzle(e){const s=t.get(String(e));if(s)for(const n of s){const o=n.muzzle?.();if(o)return o}return null},path(e,s,n,o,r){const a=Math.hypot(n-e,o-s);if(!i||!(a>.001))return null;const l=i(e,s,(n-e)/a,(o-s)/a,a,r||0),h=[];for(let u=0;u+2<(l?.length??0);u+=3)h.push({t0:l[u],t1:l[u+1],level:l[u+2]});return h.length?h:null}}}function Rh(){const i=new Set;return{subscribe(t){return i.add(t),()=>{i.delete(t)}},exploded(t){for(const e of i)e(t)}}}function Fh(){const i=new Map;let t=0,e=0,s=null,n=null,o=0;const r=()=>{s=null,n=null,o+=1},a=()=>{s=new Map;for(const{level:l,cells:h,volume:u}of i.values()){s.has(l)||s.set(l,new Map);const c=s.get(l);for(const[_,f]of h){const p=`${_},${f}`;c.set(p,Math.max(c.get(p)||0,u))}}return s};return{setLayerVolume(l,h,u,c,{step:_,scale:f}){const{x:p,y:d}=Le(f??1);t=_*p,e=_*d,i.set(c,{level:l||0,cells:h,volume:u}),r()},release(l){i.delete(l)&&r()},get version(){return o},levels(){if(!n){n=new Map;for(const{level:l,cells:h,volume:u}of i.values())n.has(l)||n.set(l,[]),n.get(l).push({cells:h,volume:u})}return n},heightAt(l,h,u){if(!(t>0&&e>0))return 0;const c=(s||a()).get(l||0);return c&&c.get(`${Math.floor(h/t)},${Math.floor(u/e)}`)||0},cellSize(){return{cellW:t,cellH:e}}}}const Xh=(i,t)=>t>=Math.min(i.from,i.to)&&t<=Math.max(i.from,i.to),Ps=(i,t)=>{const e=i.max-i.min,s=e>0?(t-i.min)/e:0,n=i.sign>0?s:1-s;return i.from+(i.to-i.from)*n},bn=(i,t,e)=>{const s=i.axis===0?t:e,n=i.axis===0?e:t;return s>=i.min&&s<=i.max&&n>=i.crossMin&&n<=i.crossMax};function Yh(i,t,e,s){const n=kn(i,t,e,s);return n?Ps(n,n.axis===0?e:s):null}function kn(i,t,e,s){return Array.isArray(i)?i.find(n=>Xh(n,t)&&bn(n,e,s))??null:null}function Dh(i,t,e,s){const n=kn(i,t,e,s);return n?{height:Ps(n,n.axis===0?e:s),axis:n.axis}:null}function Vh(i,t,e,s,n,o,r){if(!Array.isArray(i))return null;const a=2*r,l=e+n*a,h=s+o*a;for(const u of i){if(Math.min(u.from,u.to)!==t||!bn(u,l,h))continue;const c=u.axis===0,_=c?e:s,f=c?s:e,p=c?n:o,d=c?o:n,g=[{coord:u.min,dist:Math.abs(_-u.min),end:!0,d:p},{coord:u.max,dist:Math.abs(_-u.max),end:!0,d:p},{coord:u.crossMin,dist:Math.abs(f-u.crossMin),end:!1,d},{coord:u.crossMax,dist:Math.abs(f-u.crossMax),end:!1,d}].filter(b=>b.dist<=r&&Math.abs(b.d)>1e-9);if(g.length===0)continue;const m=g.reduce((b,v)=>v.dist<b.dist?v:b),w=m.end===c?"x":"y",M=m.d>0?-1:1;return{face:{axis:w,coord:m.coord,nx:w==="x"?M:0,ny:w==="y"?M:0},volume:Ps(u,c?l:h)-t}}return null}const Oh=[[0,-1],[0,1],[-1,0],[1,0]],Uh={id:"tanks",engineApi:Yn,requires:["map.layers","map.levelsN","map.gameData","map.bodyState"],async createClientCore(i,{wasmUrl:t}){if(lh(t)){const s=await hh(t);return{core:new s.ClientCore(i),memory:null}}const e=await Hn({module_or_path:t});return{core:new ls(i),memory:e.memory}},parts:Ul,bakers:ah,styles:Gn,serviceNames:["levelView","mapDynamics","rampRuns","surfaces","volumes","lighting","shots","blasts"],hooks:{services(i){const t=ch(),e=Fh(),s=Eh(void 0,{levelView:t,volumes:e});let n=[],o=null;const r=()=>{const h=i.map_generation();return h!==o&&(o=h,n=JSON.parse(i.ramp_runs())),n};let a=[],l=null;return{levelView:t,lighting:s,shots:Ih({segments:(h,u,c,_,f,p)=>i.shot_segments(h,u,c,_,f,p)}),blasts:Rh(),volumes:e,mapDynamics:{toWorld(h,u,c){const _=i.map_dynamics_to_world(h,u,c);return _.length===0?null:{x:_[0],y:_[1]}}},rampRuns:{forLevel(h){return r().filter(u=>u.from===h)},heightAt(h,u,c){return Yh(r(),h,u,c)},slopeAt(h,u,c){return Dh(r(),h,u,c)},faceAt(h,u,c,_,f,p){return Vh(r(),h,u,c,_,f,p)},floorAt(h,u,c){return i.floor_level(h,u,c)}},surfaces:{kindAt(h,u,c){const _=i.surface_at(h,u,c);if(_<0)return null;const f=i.map_generation();return f!==l&&(l=f,a=JSON.parse(i.surface_types())),a[_]??null},dirAt(h,u,c){return Oh[i.surface_dir_at(h,u,c)]??null}}}},onAuth(i,t){i.set_model(t.model)},onPanel(i,t){i.sync_panel(JSON.stringify(t))},onLocalAction(i,t,e,s){return t!=="down"?null:e==="fire"?i.try_fire(s)||null:((e==="nextWeapon"||e==="prevWeapon")&&i.cycle_weapon(e==="prevWeapon"),null)}}};export{Uh as default};
|