@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
package/dist/client-ByYEfcjw.js
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import{UniformGroup as Ye,Filter as vn,GpuProgram as Mn,GlProgram as ps,defaultFilterVert as Sn,Ticker as Q,Container as $,Sprite as J,Rectangle as at,Spritesheet as bn,MeshSimple as kn,Text as bi,BlurFilter as ms,Assets as is,Texture as De,Graphics as U,Shader as ki,Geometry as Tn,Mesh as Ti,AlphaFilter as Ai,PerspectiveMesh as An,Particle as Ln,ParticleContainer as Ne,MeshGeometry as Pn}from"pixi.js";const zn=4;class ns{__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,Ps.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],Pt(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=ft,r=Vt(e,C.__wbindgen_malloc,C.__wbindgen_realloc),a=ft;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],Pt(s[0],s[1])}finally{C.__wbindgen_free(t,e,1)}}decode_frame(t){let e,s;try{const n=Ge(t,C.__wbindgen_malloc),o=ft,r=C.clientcore_decode_frame(this.__wbg_ptr,n,o);return e=r[0],s=r[1],Pt(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=ft,o=Ge(e,C.__wbindgen_malloc),r=ft,a=C.clientcore_dispatch(this.__wbg_ptr,s,n,o,r);var l=In(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=He(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=ft,r=C.clientcore_map_dynamics_to_world(this.__wbg_ptr,n,o,e,s);var a=He(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=ft,n=C.clientcore_new(e,s);if(n[2])throw zs(n[1]);return this.__wbg_ptr=n[0],Ps.register(this,this.__wbg_ptr,this),this}offset(){return C.clientcore_offset(this.__wbg_ptr)}push_frame(t,e){const s=Ge(t,C.__wbindgen_malloc),n=ft;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],Pt(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=ft,n=C.clientcore_set_map(this.__wbg_ptr,e,s);if(n[1])throw zs(n[0])}set_model(t){const e=Vt(t,C.__wbindgen_malloc,C.__wbindgen_realloc),s=ft;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=He(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],Pt(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=ft;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],Pt(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],Pt(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=Pt(e[0],e[1]).slice(),C.__wbindgen_free(e[0],e[1]*1,1)),s}}Symbol.dispose&&(ns.prototype[Symbol.dispose]=ns.prototype.free);function Cn(){return{__proto__:null,"./vimp_tanks_core_bg.js":{__proto__:null,__wbg_Error_92b29b0548f8b746:function(t,e){return Error(Pt(t,e))},__wbg___wbindgen_throw_344f42d3211c4765:function(t,e){throw new Error(Pt(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 Ps=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 He(i,t){return i=i>>>0,En().subarray(i/4,i/4+t)}function In(i,t){return i=i>>>0,ae().subarray(i/1,i/1+t)}let ye=null;function En(){return(ye===null||ye.byteLength===0)&&(ye=new Float32Array(C.memory.buffer)),ye}function Pt(i,t){return Fn(i>>>0,t)}let we=null;function ae(){return(we===null||we.byteLength===0)&&(we=new Uint8Array(C.memory.buffer)),we}function Ge(i,t){const e=t(i.length*1,1)>>>0;return ae().set(i,e/1),ft=i.length,e}function Vt(i,t,e){if(e===void 0){const a=Se.encode(i),l=t(a.length,1)>>>0;return ae().subarray(l,l+a.length).set(a),ft=a.length,l}let s=i.length,n=t(s,1)>>>0;const o=ae();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=ae().subarray(n+r,n+s),l=Se.encodeInto(i,a);r+=l.written,n=e(n,s,r,1)>>>0}return ft=r,n}function zs(i){const t=C.__wbindgen_externrefs.get(i);return C.__externref_table_dealloc(i),t}let Ie=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});Ie.decode();const Rn=2146435072;let $e=0;function Fn(i,t){return $e+=t,$e>=Rn&&(Ie=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),Ie.decode(),$e=t),Ie.decode(ae().subarray(i,i+t))}const Se=new TextEncoder;"encodeInto"in Se||(Se.encodeInto=function(i,t){const e=Se.encode(i);return t.set(e),{read:i.length,written:e.length}});let ft=0,C;function Xn(i,t){return C=i.exports,ye=null,we=null,C.__wbindgen_start(),C}async function Yn(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 Dn(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=Cn();(typeof i=="string"||typeof Request=="function"&&i instanceof Request||typeof URL=="function"&&i instanceof URL)&&(i=fetch(i));const{instance:e,module:s}=await Yn(await i,t);return Xn(e)}const Vn='@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}',On={mode:"hole",radius:260,softness:.45,minAlpha:.12,layerAlpha:.4,fadeRate:6,roofMargin:0,lowerTint:11579584},W={shear:.22,levelZStride:100},Rt={faceTilesPerLevel:3,faceSegments:4,faceBleedPx:2,rampSegments:4,sideTint:10133674},Lt={scaleGain:.1,baseAlpha:.4,alphaFalloff:.12,sizeFactor:1.05,groundOffset:3,groundAlpha:.3},Et={lift:.35,vertices:6,shading:.28,lightDir:[-.7,-.7]},jt={ambient:.55,diffuse:.6,lightZ:1},$t={duration:150,attack:.15,gunKick:1,bodyKick:0,rock:.1},vt={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},fe={rock:.22,wobbleHz:5,decay:180,duration:700,hop:.3,hopDuration:420,underShare:.5,shake:1.2,shakeDuration:220},Z={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}},Ee={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},Bn={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},zt={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},Wn={maxFps:30},Mt={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}},Un=W.levelZStride,N=(i,t)=>i+Un*(t||0),Li=5,ke=(i,t)=>Math.min(i||0,Math.round(t));function ht(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 _t(i,t,e,s){return!e||!s?{x:i,y:t}:{x:i+(i-e.x)*s,y:t+(t-e.y)*s}}function pt(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 be(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 Te(i){const t=typeof i=="number"?i:i.x,e=typeof i=="number"?i:i.y;return{x:t,y:e}}function le(i,t,e){return Math.floor(i/t/e)}function Nn(i,t,e){return Math.round(i/t/e)}function Hn(i,t,e){return{map:i,scale:t,step:e}}function Pi(i,t,e,s){const n=le(t,i.scale.x,i.step),o=le(e,i.scale.y,i.step),r=i.map?.[o]?.[n];return r!==void 0&&s.has(r)}function zi(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 Gn(i,t,e,s,n,o){return i?.map?zi((r,a)=>Pi(i,r,a,t),e,s,n,o):!1}function $n(i,t,e,s,n,o,r){return!i||i.size===0?!1:zi((a,l)=>i.has(`${le(a,e.x,t)},${le(l,e.y,t)}`),s,n,o,r)}const Ci=i=>i.radius*(1-i.softness),Kn=(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 Zn({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=Kn(Ci(r),r.radius,h);return r.minAlpha+(1-r.minAlpha)*u}function jn(i,t,e){return(t||0)<(i||0)?e.lowerTint:16777215}const qn=`
|
|
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
|
-
`,Cs=`
|
|
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 Jn(i){const t=new Ye({uHoleCenter:{value:new Float32Array([0,0]),type:"vec2<f32>"},uHoleParams:{value:new Float32Array([i.radius,Ci(i),i.minAlpha]),type:"vec3<f32>"}});return new vn({glProgram:ps.from({vertex:Sn,fragment:qn,name:"see-through-hole-filter"}),gpuProgram:Mn.from({vertex:{source:Cs,entryPoint:"mainVertex"},fragment:{source:Cs,entryPoint:"mainFragment"}}),resources:{holeUniforms:t}})}function Qn(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 to=.01;function os(){return{strength:0,filter:null,attached:!1,tick:null}}function Ii(i,t){const e=Q.shared.lastTime;return i.tick===e?0:(i.tick=e,Math.min(1,t*(Q.shared.deltaMS/1e3)))}function gs(i,t,e){return i.strength+=((t?1:0)-i.strength)*e,i.strength}function Ei(i,t){return 1+(t.minAlpha-1)*i.strength}function xs(i,t,e,s,n,o){if(t.strength<to||!n){t.attached&&(i.filters=[],t.attached=!1);return}t.filter||(t.filter=Jn(e)),t.attached||(i.filters=[t.filter],t.attached=!0);const r=_t(s.x,s.y,o,s.z*W.shear);Qn(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:Ei(t,e)})}function rs(i,t){if(!i.filter){i.attached=!1;return}t.filters=[],i.attached=!1,i.filter.destroy(),i.filter=null}async function Ri(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 bn(i,s);return await n.parse(),n}async function ys({baseTexture:i,spriteSheetData:t,map:e,tiles:s,step:n,renderer:o,exclude:r=[]}){const a=await Ri(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 at(0,0,u,c)});return _.destroy({children:!0}),a.destroy(),f}function eo(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 so(e)}function so(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 ws(i){const t=new kn(i);return t.geometry.batchMode="batch",t}const io=1e-6,no=1e3,Fi=[0,1,3,0,3,2];function oo(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 Xi(i,t){return Math.max(1,Math.ceil(i*t-1e-9))}function ro({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=oo(i,new Set(t)),_=n*r,f=(n+o)*r,p=f-io,d=Math.max(1,Math.ceil(o*u-1e-9)),g=Xi(o,h),m=o*h/g,w=(d+1)*2,M=Math.max(1,Math.floor(no/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 k=0;k<y.length;k+=M){const P=y.slice(k,k+M),R=P.length,D=R*w,E=new Float32Array(D*2),X=new Float32Array(D),Y=new Float32Array(D*2),B=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:mt,ny:It,x0:Bt,y0:Wt,x1:Ut,y1:Nt}=P[H],ot=Bt*e,Ht=Wt*e,gt=Ut*e,x=Nt*e,T=H*w;for(let L=0;L<=d;L+=1)for(let A=0;A<2;A+=1){const I=T+L*2+A;E[I*2]=(A===1?gt:ot)*s.x,E[I*2+1]=(A===1?x:Ht)*s.y,X[I]=f-(f-_)*L/d,Y[I*2]=A,Y[I*2+1]=m*L/d}for(let L=0;L<d;L+=1){const A=T+L*2,I=(H*d+L)*6;for(let K=0;K<6;K+=1)B[I+K]=A+Fi[K]}V[H*2]=mt,V[H*2+1]=It,G[H*2]=(ot+gt)/2*s.x,G[H*2+1]=(Ht+x)/2*s.y}const j=ws({texture:z,vertices:E.slice(),uvs:Y,indices:B});j.tint=a,b.push({target:j,k:p,base:E,heights:X,rows:d,k0:_,k1:f,occluder:!0,walls:!0,normals:V,centers:G,facing:new Uint8Array(R).fill(2)})}}return b}function Yi(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 ao(i,t,e=0){if(Yi(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 lo(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+Fi[g],c+=1}return e.geometry.indices=u,!0}function ho({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,k=new Float32Array(v*4),P=new Float32Array(v*4),R=new Float32Array(v*4),D=new Float32Array(v*2),E=new Uint32Array(p*6),X=1;for(let B=0;B<v;B+=1){const V=B/p,G=c.sign>0?V:1-V,j=(c.from+(c.to-c.from)*G)*s,H=_?m:M,It=H+((_?w:b)-H)*V,Bt=_?It:m,Wt=_?M:It,Ut=_?It:w,Nt=_?b:It,ot=B*4;k[ot]=Bt*n.x,k[ot+1]=Wt*n.y,k[ot+2]=Ut*n.x,k[ot+3]=Nt*n.y,P[ot]=Bt/l,P[ot+1]=Wt/h,P[ot+2]=Ut/l,P[ot+3]=Nt/h;const Ht=_?Wt+X:Bt+X,gt=_?Nt-X:Ut-X,x=Math.min(Math.max(It,(_?m:M)+X),(_?w:b)-X);R[ot]=(_?x:Ht)/l,R[ot+1]=(_?Ht:x)/h,R[ot+2]=(_?x:gt)/l,R[ot+3]=(_?gt:x)/h,D[B*2]=j,D[B*2+1]=j}for(let B=0;B<p;B+=1){const V=B*2,G=B*6;E[G]=V,E[G+1]=V+1,E[G+2]=V+3,E[G+3]=V,E[G+4]=V+3,E[G+5]=V+2}const Y=ws({texture:t,vertices:k.slice(),uvs:P,indices:E});a.push(co({base:k,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:k,heights:D})}return a}function co(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,k=t[y*2],P=t[y*2+1];p[z]=k,p[z+1]=P,p[z+2]=k,p[z+3]=P,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 k=y;k<z;k+=1){const P=k*2,R=b*6;w[R]=P,w[R+1]=P+1,w[R+2]=P+3,w[R+3]=P,w[R+4]=P+3,w[R+5]=P+2,b+=1}}const v=ws({texture:o,vertices:p.slice(),uvs:d,indices:w});return v.tint=l,{target:v,k:r,base:p,heights:g}}function uo(i,t){if(Yi(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 de={mapSprite:null,occluder:null,slices:[],rampTexture:null,wallTextures:[]};function fo({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 _o(i){try{const t=await i.baseTexture;if(i.isAborted())return de;const e=await ys({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),de;const s=new J(e);if(i.layerRoot.addChildAt(s,0),!i.extruding)return{...de,mapSprite:s};const n=await po(i,t,e),o={mapSprite:s,...n};return i.isAborted()?(fo({...o,bakedTexture:e}),de):o}catch(t){return console.error(`Failed to create static map with asset ${i.assetUrl}:`,t),de}}async function po(i,t,e){const s=W.shear,n=[],o=[];let r=null,a=null;if(i.volume>0){r=new $,r.zIndex=N(Math.max(i.layer,Li),i.level);{const h=await mo(i,t,o);if(i.isAborted())return{occluder:r,slices:n,rampTexture:a,wallTextures:o};n.push(...ro({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=Di(i);if(l.length){if(a=await ys({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(...ho({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||pt(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 mo(i,t,e){const s=new Map,n=Xi(i.volume,Rt.faceTilesPerLevel);for(const o of i.tiles){const r=await ys({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 Di(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 eo(e,(n,o)=>Nn(n,o===0?i.baseScale.x:i.baseScale.y,i.step))}function go(i,t){if(!i.levelView)return;const e=i.levelView.cfg,s=Ii(i.hole,e.fadeRate);i.hasSprite&&xo(i,e,s,t),i.occluder&&yo(i,e,s,t)}function xo(i,t,e,s){const{levelView:n,container:o}=i,r=i.roof?n.level<i.level&&vo(i,t,s):null;if(n.mode==="layer"){const h=(i.roof?r:n.level<i.level&&Pi(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;gs(i.hole,a,e),xs(o,i.hole,t,n,i.stage,s)}function yo(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}gs(i.occluderHole,r,e),xs(o,i.occluderHole,t,n,i.stage,s)}function wo(i,t){const e=i.levelView;return _t(e.x,e.y,t,e.z*W.shear)}function vo(i,t,e){return e?Gn(i.grid,i.tileSet,wo(i,e),e,[i.level*W.shear],t.roofMargin??0):!1}const Mo=40,Vi=45,So=1.5;function bo(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 ko(i){const t=i?.map?.length||0,e=i?.map?.[0]?.length||0,s=bo(JSON.stringify(i?.game?.lighting??null));return`${e}x${t}:${s.toString(16)}`}function To(i,t,e,s){const{x:n,y:o}=Te(s);return{x:(i+.5)*e*n,y:(t+.5)*e*o}}function Is(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 Es(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 Re(i,t,e,s,n,o){const r=e*o,a=_t(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 Oi(i,t,e){return!e&&Math.abs(t-Math.round(t))>.001?[Math.floor(t),Math.ceil(t)]:[ke(i,t)]}function as(i,t,e,s,n){return i+e>=0&&i-e<=s&&t+e>=0&&t-e<=n}function he(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 Bi(i,t){if(!(t>0)||i>=t)return 0;const e=1-Math.max(0,i)/t;return e*e}function Wi(i){return(1-i)*(1-i)}const Ao=.35;function Ui(i){return(1-i)*(1-i*Ao)}function Lo(i,t){return!(t>0)||i>=t?0:Wi(Math.max(0,i)/t)}function Ni(i,t,e){const s=t-i.x,n=e-i.y,o=i.intensity??1;if(i.kind!=="cone")return o*Lo(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*Ui(c)*(1-h/u)}function Po(i,t,e,s){const n=[];for(const{light:o,factor:r}of i){const a=Ni(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 Hi=(i,t)=>`${i},${t}`;function zo(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 _=Hi(c,u);s.has(_)||s.set(_,[]),s.get(_).push(n)}}return{cellSize:e,cells:s}}function Co(i,t,e){if(!i)return[];const s=Math.floor(t/i.cellSize),n=Math.floor(e/i.cellSize);return i.cells.get(Hi(s,n))||[]}function Io(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 Eo(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 Ro(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 Fo=Ro();function Xo(i,t){return Math.floor(i*t)/t}function Yo(i){return new Set(Object.keys(i||{}).map(Number))}function Do(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 Gi(i,t,e){return!(e>0)||!(t>0)?0:Math.floor(i*t)%e}function Vo(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:Do(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 Oo(i,t,e=()=>!0){for(let s=0;s<i.length;s+=1){const n=i[s];if(!e(n.container))continue;const o=Gi(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 Bo(i){i.container.parent?.removeChild(i.container),i.container.destroy({children:!0,texture:!1,textureSource:!1}),i.groups.length=0}function Rs(i,t,e){return(i||[]).filter(s=>(s.level||0)===t&&Number(s.layer)===e)}function Wo(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 Uo(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=Gi(t,s.item.fps,s.textures.length);n!==s.frame&&(s.frame=n,s.sprite.texture=s.textures[n])}}}function No(i){for(const t of i)t.sprite.parent?.removeChild(t.sprite),t.sprite.destroy({texture:!1,textureSource:!1});i.length=0}const Ho=.8,Ke=.6,Fs=.09,Go=.12,$o=.55;function $i(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 Ko(i,t,e=0){return $i((Math.imul(i,73856093)^Math.imul(t,19349663)^Math.imul(e,83492791))>>>0)}function Xs(i,t,e){return $i((i^Math.imul(t+e,668265261))>>>0)/4294967296}const _e=i=>Math.min(1,Math.max(0,i));function Zo(i,t,e){if(!(e>0))return!1;const s=Math.floor(i/Ke);if(Xs(t,s,0)>=e)return!1;const n=s*Ke+Xs(t,s,1)*(Ke-Fs);return i>=n&&i<n+Fs}function jo(i,t,e){const s=_e(e?.pulse||0),n=t%1e3/1e3,o=1-s*(.5+.5*Math.sin(2*Math.PI*(Ho*i+n)));return Zo(i,t,e?.dropouts||0)?{core:_e(o*Go),glow:_e(o*$o)}:{core:_e(o),glow:_e(o)}}const qo=4;function kt(i){return Math.ceil(i*qo)}function Ki(i){return kt(i)*2}const ls=new WeakMap;function Zi({text:i,size:t}){return`${t}|${i}`}function Jo(i){return Math.max(2,Math.round(i/4))}function Qo(i,{text:t,size:e}){const s=Jo(e),n=kt(s),o=new $,r=new bi({text:String(t),style:{fontFamily:"monospace",fontWeight:"bold",fontSize:e,fill:16777215}});r.position.set(n,n),o.addChild(r);const a=new at(0,0,Math.ceil(r.width)+n*2,Math.ceil(r.height)+n*2),l=i.generateTexture({target:o,frame:a}),h=new ms({strength:s,quality:6});h.padding=Ki(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 tr(i,t){let e=ls.get(i);e||(e=new Map,ls.set(i,e));const s=Zi(t);let n=e.get(s);return n||(n={...Qo(i,t),count:0},e.set(s,n)),n.count+=1,{core:n.core,glow:n.glow}}function er(i,t){const e=ls.get(i),s=Zi(t),n=e?.get(s);n&&(n.count-=1,!(n.count>0)&&(e.delete(s),n.core.destroy(!0),n.glow.destroy(!0)))}class sr{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=Ko(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=tr(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}:jo(t,this._seed,this._sign.flicker);if(!this.emissive){this.glow.alpha=o.glow,this.core.alpha=o.core;return}const r=this._level*W.shear,a=_t(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,()=>er(t,e)}}function ir(i,t,e,s){const n=Yo(i?.animatedTiles),o=new Set(t);return{exclude:[...n],hasTiles:[...n].some(r=>o.has(r)),signs:Rs(i?.signs,e,s),decals:Rs(i?.decals,e,s)}}function Ys(i){return i.hasTiles||i.signs.length>0||i.decals.length>0}async function nr({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 Ri(e,s),_()))return f.destroy(),null;const p={sheet:f,tiles:null,decals:[],signs:[],tick:null};return i.hasTiles&&(p.tiles=Vo({map:n,tiles:o,step:r,scale:a},f,t.animatedTiles),h.addChild(p.tiles.container)),f&&(p.decals=Wo(i.decals,f,r,h)),p.signs=i.signs.map(d=>new sr({sign:d,renderer:u,lighting:c,animated:h,step:r,scale:a,level:l})),p}function or(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 rr(i,{camera:t,levelView:e,screen:s,roofAlpha:n=null}){const o=Xo(Fo.now(),Wn.maxFps),r=Q.shared.lastTime;i.tick!==r&&(i.tick=r,i.tiles&&Oo(i.tiles.groups,o,or(s)),Uo(i.decals,o));for(let a=0;a<i.signs.length;a+=1)i.signs[a].update(o,t,e,n)}function ar(i){if(!i)return()=>{};i.tiles&&(Bo(i.tiles),i.tiles=null),No(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 lr{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=os(),this._occluderHole=os(),this._occluder=null,this._baseScale=Te(e.scale),this._slices=[],this._rampTexture=null,this._wallTextures=[],this.mapSprite=null,this._assetUrl=`${n}${e.spriteSheet.img}`,this._baseTexturePromise=is.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=hr(e.game,this._level,this._tiles),this._spriteSheetData=e.spriteSheet,this._step=e.step,this._layer=Number(e.layer)||1,t.zIndex=N(this._layer,this._level),this._parallaxK=this._level*W.shear,this._layerRoot=new $,this._layerRoot.label="layerRoot",this._animated=new $,this._animated.label="animated",this._layerRoot.addChild(this._animated),pt(this._layerRoot,null,this._parallaxK,this._baseScale),t.addChild(this._layerRoot),this._animationSpec=ir(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=Hn(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=ko(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,Is(this._map,this._roof?this._tiles:this._floor),this,{roof:this._roof}),this._ramps.length&&this._lighting.setRampWedges(this._level,Di({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,Is(this._map,this._tiles),this._volume,this,{step:this._step,scale:e.scale}),this.needsRender=this._level>=1||this._extruding||!!this._lighting?.isNight()||Ys(this._animationSpec),this._build(e)}async _build(t){const e=await _o({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||!Ys(this._animationSpec))&&(this._animations=await nr({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:Ei(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():ht(this._container.parent,this._renderer);if(this._lighting&&(this._lighting.attachStage(this._container.parent,this._renderer),this._lighting.render()),(this._level>=1||this._occluder)&&go(this._seeThroughView(),t),this._animations&&rr(this._animations,{camera:t,levelView:this._levelView,screen:this._renderer?.screen,roofAlpha:this._roofAlpha()}),!(!this._parallaxK&&!this._slices.length)&&t){pt(this._layerRoot,t,this._parallaxK,this._baseScale);for(let e=0;e<this._slices.length;e+=1){const s=this._slices[e];s.walls?(ao(s,t,Rt.faceBleedPx),lo(s,t)):s.base?uo(s,t):pt(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=ar(this._animations);if(this._animations=null,this._lighting&&(this._lighting.releaseMap(this._mapKey,this),this._lighting=null),this._volumes?.release(this),this._volumes=null,rs(this._hole,t),this._occluder){const a=this._occluder;this._occluder=null,a.filters=[],rs(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=De.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 hr(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,Ct=(i,t,e)=>Math.min(e,Math.max(t,i)),cr=i=>i*(Math.PI/180),ur=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 fr 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 ji(i,{x:t,y:e,z:s,level:n,reach:o,exclude:r=null}){const a=i?.texture("glint");return!Mt.glints?.enabled||!a||!i.isNight()||!i.onScreen(t,e,s,o)?null:i.lightsAt(t,e,n,1,r)[0]||null}function qi(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 Ji(i){i&&(i.sprite.visible=!1)}function Qi(i,{hit:t,asset:e,x:s,y:n,rotation:o,size:r}){const{sprite:a}=i,l=Mt.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 St=0,bt=1,Ft=2,Ds=3,ce=4,ue=5,Ot=6,wt=7,Ae=8,Ve=9,Jt=11,dt=12,Oe=13,Vs=14,Os=15,dr=0,_r=1,pr=2,mr=3,gr=4,xr=5,yr=6,Ze=7,wr=8,vr=9,Bs=10,Ws=2,Mr=3,Us=0,Ns=1,Hs=2,Sr=3,br=4,kr=6,Tr=0,Ar=1,Lr=2,Pr=3,Gs=0,$s=1,Ks=2,zr=3,Cr=4,Ir=5,Zs=0,Er=1,pe=2,Rr=1,Fr=2,Xr=1.4;class Yr{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=Te(e.scale),t.scale=e.scale,this._assetUrl=`${n}${e.img}`,this._baseTexturePromise=is.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=N(this._layer,this._level),this._rotation=cr(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!==Zs&&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)&&pt(t,this._levelView.camera()??ht(t.parent,this._renderer),this._z*W.shear,this._baseScale)}update(t){this.sprite&&(this.sprite.x=t[Gs]/this._baseScale.x,this.sprite.y=t[$s]/this._baseScale.y,this.sprite.rotation=t[Ks]),this._worldX=t[Gs],this._worldY=t[$s],this._rotation=t[Ks],this._z=t[zr]||0;const e=ke(t[Cr],this._z);e!==this._level&&(this._level=e,this._container.zIndex=N(this._drawLayer(),e),!e&&!this._z&&pt(this._container,null,0,this._baseScale));const s=t[Ir]||Zs;if(s!==this._state){const n=this._state===null;this._state=s,this._showState(s),s===pe&&!n&&this._burst()}this._placeScorch()}_drawLayer(){return this._state===pe?Rr:this._layer}_standing(){return this._state!==pe||!!this._destroyedUrl}_updateGlint(){const t=this._localCenter(),e=this.sprite.visible&&this._standing()?ji(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){Ji(this._glint);return}const s=this._lighting.texture("glint");this._glint=qi(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,Qi(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=N(this._drawLayer(),this._level),!this.sprite)return;if(t===pe&&!this._destroyedUrl){this.sprite.visible=!1,this._showScorch();return}this._scorch&&(this._scorch.visible=!1),this.sprite.visible=!0;let e=null;t===Er?e=this._damagedUrl:t===pe&&(e=this._destroyedUrl),this._setTexture(e?is.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)*Xr/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 fr(e,s,r,()=>{this._effects.delete(a),a.destroy()},o);a.zIndex=N(Fr,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 Dr=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 Yr(this,t,s,n,e):new lr(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 js=[16777215,9418751,10477760,15783820,14721232,10541296,15773836,12632280],tn=i=>js[i]??js[0],Vr=2,Or=.35;class Br 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=N(Vr,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:Or}),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(tn(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 qs=2,Wr=9,Ur=1.5;class Nr extends ${constructor(t,e){super(),this._level=t[dt]||0,this.zIndex=N(qs,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[St]||0,this.y=t[bt]||0,this._condition=t[wt],this._teamId=t[Ve],this.scale.set(5,5),this.create()}_drawLevelRing(){this.levelRing.clear(),this._level>0&&this.levelRing.circle(0,0,Wr).stroke({width:Ur,color:tn(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[St],this.y=t[bt];const e=t[dt]||0;e!==this._level&&(this._level=e,this.zIndex=N(qs,e),this._drawLevelRing());const s=t[wt],n=t[Ve];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 Hr({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,k]of p){const P=z*d-k*g,R=z*g+k*d,D=P*m,E=P*w,X=R*M,Y=R*b,B=E+Y,V=t?B/t*l:0,G=B*h;y.push(D*(1+V)+v*G,X*(1+V)+S*G)}return y}function Gr({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 en(i,t,{minImpact:e,fullImpact:s}){return!(i<-e)||t!==0?0:Math.min(1,-i/s)}function $r(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 Kr({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 Fe=Math.PI*2,Zr=.09,jr=.113;function qr(i,t){return!(t>0)||i>=t?0:1-i/t}function Jr({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=qr(u,o.radius);if(!c)return null;const _=u<r.underShare*n,f=_?a()*Fe:Math.atan2(h,l)-s;return{strength:c,dirU:Math.cos(f),dirV:Math.sin(f),hop:_,phaseX:a()*Fe,phaseY:a()*Fe}}function Js({elapsed:i,kick:t,config:e}){const s=t.strength,n=e.decay>0?Math.exp(-i/e.decay):0,o=n*Math.cos(Fe*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*Zr+t.phaseX),shakeY:u*Math.sin(i*jr+t.phaseY),envelope:s*n,done:i>=e.duration&&!a}}const Qs=[[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]),ti={track:0,hull:1,turret:2,barrel:3};function sn(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 Qr(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 me=(i,t,e,s)=>[[i,e],[t,e],[t,s],[i,s]],ta=(i,t)=>i.map(([e,s])=>[e*t,s*t]);function ea(i=vt){const t=[],e=[],s=({bottom:r,top:a,w0:l,w1:h,part:u,topMaterial:c,sideMaterial:_})=>{let f=r,p=a;sn(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=me(-20,20,r,a);s({bottom:l,top:l,w0:0,w1:i.trackHeight,part:"track",topMaterial:"trackTop",sideMaterial:"trackSide"})}s({bottom:me(-18,18,-9,9),top:me(-16,14,-7,7),w0:i.hullBase,w1:i.hullTop,part:"hull",topMaterial:"hullTop",sideMaterial:"hullSide"}),s({bottom:Qs,top:ta(Qs,.6),w0:i.turretBase,w1:i.turretTop,part:"turret",topMaterial:"turretTop",sideMaterial:"turretSide"});const n=me(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=me(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 ei=new Set(["turret","barrel"]);function sa({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,k=S*p+y*f;return[v*c-k*_,z,v*_+k*c]},w=([v,S,y])=>[v*h-S*u,v*u+S*h,y],M=i.vertices.map(([v,S,y],z)=>{let k=[v*l,S*l,y*l*d];const P=g[z];return ei.has(P)&&(k=w(k)),P==="barrel"&&(k=[k[0]+o.x,k[1]+o.y,k[2]]),k=m(k),[k[0]+r.x,k[1]+r.y,k[2]]}),b=i.faces.map(v=>{let S=ia(i,v,d);return ei.has(v.part)&&(S=w(S)),m(S)});return{points:M,normals:b}}function ia(i,t,e){return Qr(t.indices.map(s=>{const[n,o,r]=i.vertices[s];return[n,o,r*e]}))}function na({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 oa({points:i,lean:t,zScale:e=1}){return i.map(([s,n,o])=>[(s+t.x*o)*e,(n+t.y*o)*e])}function ra({model:i,points:t,projected:e}){const s=[];return i.faces.forEach((n,o)=>{const r=n.indices.map(a=>e[a]);if(sn(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)=>ti[n.face.part]-ti[o.face.part]||n.height-o.height||n.index-o.index),s.map(n=>n.index)}function aa(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 la={track:"body",hull:"body",turret:"gun",barrel:"gun"},ha={trackSide:"trackSide",barrel:"barrelSide",brake:"brakeSide"};function ca(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 ua(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=ha[r.material];if(r.kind==="side"&&a&&ca(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[la[r.part]];return r.indices.map(h=>{const[u,c]=i.vertices[h];return o([l.originX+u,l.originY+c])})})}const fa=`#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
|
-
`,da=`#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 si=null;function _a(i){return si||=ps.from({vertex:fa,fragment:da,name:"tank-model"}),new ki({glProgram:si,resources:{uTexture:i.source,textureUniforms:new Ye({uTextureMatrix:{value:i.textureMatrix.mapCoord,type:"mat3x3<f32>"}})}})}function pa(i,t){i.resources.uTexture=t.source,i.resources.textureUniforms.uniforms.uTextureMatrix=t.textureMatrix.mapCoord}function ma(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=>{ua(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 Tn({attributes:{aPosition:{buffer:o,format:"float32x2"},aUv:{buffer:r,format:"float32x2"},aShade:{buffer:a,format:"float32"}},indexBuffer:l}),c=_a(t.texture),_=new Ti({geometry:u,shader:c,texture:t.texture});return{mesh:_,setAtlas(f){h(f),u.getBuffer("aUv").update(),pa(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 ga(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 xa(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 ya({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(ga(a))}return o}const wa=`#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
|
-
`,va=`#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
|
-
`,Pe=i=>[Math.cos(i),Math.sin(i)];function nn({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:Pe(t),uPitch:Pe(e),uRoll:Pe(s),uHeading:Pe(i),uLight:c,uAmbient:r,uDiffuse:a,uNorm:_?1/_:1}}let ii=null;function Ma(i,t){return ii||=ps.from({vertex:wa,fragment:va,name:"tank-light"}),new ki({glProgram:ii,resources:{uTexture:i.source,uNormal:t.source,textureUniforms:new Ye({uTextureMatrix:{value:i.textureMatrix.mapCoord,type:"mat3x3<f32>"}}),tankLight:new Ye({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 Sa(i,t,e){i.resources.uTexture=t.source,i.resources.uNormal=e.source,i.resources.textureUniforms.uniforms.uTextureMatrix=t.textureMatrix.mapCoord}function ba(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 ka=0,Ta=1,ze=3;let ni=null;const je=()=>(ni||=ea(vt),ni),Aa=()=>nn({heading:0,rotation:0,pitch:0,roll:0,lightDir:Et.lightDir,lightZ:jt.lightZ,ambient:jt.ambient,diffuse:jt.diffuse}),La=.55,Pa=.6,oi=7,za=1,ri=1.15,Ca=1.25,Ia=.6,Ea=1,Ra=.015,Fa=2.5;function Xa(i,t=0){const e=Number.isFinite(i)?i:0,s=Ct(e,0,1),n=Math.max(0,e-1),o=ct(za,ri,s)+(Ca-ri)*n,r=ct(Ia,Ea,s),a=1+Ra*(1-s)*Math.sin(2*Math.PI*Fa*(t/1e3));return{rate:o*a,volumeFactor:r}}function Ya(i=Et.lightDir,t=Lt.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 Da extends ${constructor(t,e,s,n){super();const o=()=>{const c=new An({verticesX:Et.vertices,verticesY:Et.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=vt.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[St]||0,this._worldY=t[bt]||0,this.x=this._worldX,this.y=this._worldY,this.rotation=t[Ft]||0,this._gunRotation=t[Ds]||0,this._engineLoad=t[Ot]||0,this._condition=t[wt],this._size=t[Ae],this._teamId=t[Ve],this._z=t[Jt]||0,this._physLevel=t[dt]||0,this._vz=t[Oe]||0,this._prevVz=this._vz,this._pitch=t[Vs]||0,this._roll=t[Os]||0,this._landImpact=0,this._landTimer=0,this._squash=0,this._level=ke(t[dt],this._z),this.zIndex=N(ze,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[ce]||0,t[ue]||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}=Xa(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)*Pa,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[St],this._worldY=t[bt],this.rotation=t[Ft],this._gunRotation=t[Ds],this._engineLoad=t[Ot]||0,this._speed=Math.hypot(t[ce]||0,t[ue]||0),this._z=t[Jt]||0,this._physLevel=t[dt]||0,this._vz=t[Oe]||0,this._pitch=t[Vs]||0,this._roll=t[Os]||0;const e=en(this._prevVz,this._vz,Zt);e>0&&(this._landImpact=e,this._landTimer=Zt.duration),this._prevVz=this._vz;const s=ke(t[dt],this._z);s!==this._level&&(this._level=s,this.zIndex=N(ze,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[wt],o=t[Ve];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}=zt.water.sound,n=Ct(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*Mt.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}=Mt,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=Oi(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=$t.attack*$t.duration;this._recoilElapsed=this._recoilElapsed<$t.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*La;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=$r(this._recoilElapsed,$t.duration,$t.attack);if(t===0&&this._recoilElapsed>=$t.duration){this._resetRecoil();return}const e=Kr({amount:t,gunRotation:this._gunRotation,config:$t});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=Jr({x:this._worldX,y:this._worldY,level:this._physLevel,heading:this.rotation,hullLength:this._size*4,blast:t,config:fe});if(!e)return;const s=this._blastKick?Js({elapsed:this._blastElapsed,kick:this._blastKick,config:fe}).envelope:0;e.strength>=s&&(this._blastKick=e,this._blastElapsed=0)}_stepBlast(){if(!this._blastKick)return;const t=this._blastKick.hop&&this._blastElapsed<fe.hopDuration;this._blastElapsed+=Q.shared.deltaMS;const e=Js({elapsed:this._blastElapsed,kick:this._blastKick,config:fe});if(t&&this._blastElapsed>=fe.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()*W.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)Sa(n,e,s);else{const o=Ma(e,s);t.shader=o,this._lightShaders.set(t,o)}}_applyLight(){for(const[t,e]of this._lightShaders)ba(e,nn({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:Et.lightDir,lightZ:jt.lightZ,ambient:jt.ambient,diffuse:jt.diffuse}))}_setCorners(t,e,s,n,o){const{texture:r}=t;t.setCorners(...Hr({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:W.shear,lift:Et.lift}))}_groundZ(){return this._vz!==0?this._physLevel:this._z}_applyTilt(){const t=1+this._viewZ()*W.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():ht(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=_t(this._worldX,this._worldY,t,this._viewZ()*W.shear);if(this.position.set(s.x,s.y),this._lightShaders.size===0&&!this._model?.mesh.visible){const n=Ct(Gr({angle:this.rotation,pitch:this._pitch,roll:this._roll,lightDir:Et.lightDir,shading:Et.shading}),ka,Ta);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()*W.shear,e=ji(this._lighting,{x:this._worldX,y:this._worldY,z:this._viewZ(),level:this._level,reach:this._size*2*t,exclude:this._ownLights});if(!e){Ji(this._glint);return}const s=this._lighting.texture("glint");this._glint=qi(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)),Qi(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=ma(je(),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=je(),s=sa({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=na({x:this._worldX,y:this._worldY,camera:t,heading:this.rotation,shear:W.shear,levelHeight:vt.levelHeight,maxLean:vt.maxLean,gain:vt.leanGain,topHeight:vt.turretTop*this._size/10}),o=oa({points:s.points,lean:n,zScale:1+this._viewZ()*W.shear});this._modelPose=s;const r=ra({model:e,points:s.points,projected:o}),a=Aa(),l=s.normals.map(h=>aa(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 Ai({alpha:1}),h.filters=vt.shadowBlur?[new ms({strength:vt.shadowBlur,quality:2}),this._modelShadowAlpha]:[this._modelShadowAlpha],this.parent.addChild(h),this._modelShadow=h}const e=this._modelShadow,s=this._groundZ(),n=_t(this._worldX,this._worldY,t,s*W.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*W.shear),e.zIndex=N(ze-1,Math.min(oi,Math.floor(s)));const r=ya({model:je(),points:this._modelPose.points,lift:o*vt.levelHeight,drift:xa(Et.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,Lt.baseAlpha-o*Lt.alphaFalloff):Lt.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||Lt.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*Lt.sizeFactor/c,this.parent.addChild(this._shadow)}const n=this._shadow;n.visible=!0;const o=this._groundZ(),r=_t(this._worldX,this._worldY,t,o*W.shear),a=Ya();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*Lt.scaleGain));const h=e?Math.max(0,Lt.baseAlpha-l*Lt.alphaFalloff):Lt.groundAlpha;n.alpha=h*this.alpha,n.zIndex=N(ze-1,Math.min(oi,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 Va=2;class Oa extends ${constructor(t,e,s){super(),this._level=t[kr]||0,this.zIndex=N(Va,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[Us],this._worldY=t[Ns],this.x=this._worldX,this.y=this._worldY,this.rotation=t[Hs],this._size=t[Sr],this._totalDurationMs=t[br],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 bi({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[Us],this._worldY=t[Ns],this.x=this._worldX,this.y=this._worldY,this.rotation=t[Hs],this._soundId&&(this._soundManager.updateSoundData(this._soundId,{position:{x:this._worldX,y:this._worldY}})||(this._soundId=null))}_applyHeight(){const t=this._level*W.shear,e=ht(this.parent,this._renderer),s=_t(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 Ba 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 qe=[],yt={get(i){if(qe.length>0){const t=qe.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 Ln({texture:i,anchorX:.5,anchorY:.5})},release(i){i&&qe.push(i)}},hs=50,Wa=400,Ua=800;class Na extends Qt{constructor(t,e=hs){super();const s=e/hs;this._blastScale=s;const{texture:n,contentSize:o}=t.explosionTexture;this.explosionTexture=n,this._unitScale=1/o;const r=Wa*s,a=Ua*s;this._particleContainer=new Ne({texture:this.explosionTexture,boundsArea:new at(-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=yt.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),yt.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)yt.release(this._particles[e].view);this._particles=[],super.destroy(t)}}const Ha=.168,Ga=.225,ai=.15,$a=2e4,Ka=50,Za=4e3,ja=4e3;class qa extends Qt{constructor(t,e,s,n,o){super(n),this._assets=o,this._radius=s,this.x=t,this.y=e,this._funnelDurationMs=$a,this._funnelFadeInDurationMs=Ka,this._funnelFadeDurationMs=Za,this._elapsedMs=0,this._smokeDurationMs=ja,this._smokeSpawningStopped=!1,this._funnel=this._createFunnelSprite(),this._smoke=new Na(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*Ha*F(1-ai,1+ai);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=Ga*Ct(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 Ja=4,Qa=2;class tl extends ${constructor(t,e,s){super(),this.originX=t[Tr],this.originY=t[Ar],this.radius=t[Lr]??hs,this._level=t[Pr]||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*W.shear,e=ht(this.parent,this._renderer),s=_t(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({...Mt.flash.explosion,level:this._level,x:this.originX,y:this.originY,z:this._level}),this.explosion=new Ba(this.originX,this.originY,this.radius,this._onExplosionComplete.bind(this),this._assets),this.explosion.zIndex=N(Ja,this._level),this.funnel=new qa(this.originX,this.originY,this.radius,this._onFunnelComplete.bind(this),this._assets),this.funnel.zIndex=N(Qa,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 li=4,se=400,el=0,sl=0,il=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 nl extends ${constructor(t,e,s={}){super(),this._level=t[dt]||0,this.zIndex=N(li,this._level);const{texture:n,contentSize:o}=e.smokeTexture;this._smokeTexture=n,this._textureScale=il/o,this._emitterX=t[St],this._emitterY=t[bt],this._emitterRotation=t[Ft],this._emitterVX=t[ce],this._emitterVY=t[ue],this._engineLoad=t[Ot],this._condition=t[wt],this._z=t[Jt]||0,this._size=t[Ae],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)),pt(this,ht(this.parent,this._renderer),this._z*W.shear,1)}),this._particleContainer=new Ne({texture:this._smokeTexture,boundsArea:new at(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[dt]||0;s!==this._level&&(this._level=s,this.zIndex=N(li,s)),this._emitterX=t[St],this._emitterY=t[bt],this._emitterRotation=t[Ft],this._emitterVX=t[ce],this._emitterVY=t[ue],this._engineLoad=t[Ot],this._condition=t[wt],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),yt.release(c.view),this._particles.splice(u,1);continue}c.vx=c.vx+(el-c.vx)*h,c.vy=c.vy+(sl-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),k=F(it.particleInitialVelocity.side.min,it.particleInitialVelocity.side.max);z*=c,k*=c;let P=p*z+m*k,R=d*z+w*k;const D=it.particleVelocityVariance;P+=F(-D,D),R+=F(-D,D),P+=this._emitterVX,R+=this._emitterVY;const E=yt.get(this._smokeTexture);E.tint=o?r.color:it.particleColor,E.x=S,E.y=y,E.alpha=u;const X=l*this._particleScaleMultiplier*this._textureScale;E.scaleX=X,E.scaleY=X,E.rotation=F(0,Math.PI*2);const Y={view:E,x:S,y,vx:P,vy:R,age:0,lifetime:a,startSizeFactor:l,endSizeFactor:h,startAlpha:u,endAlpha:it.particleEndAlpha,rotSpeed:F(-1,1)};this._particleContainer.addParticle(E),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)yt.release(this._particles[e].view);this._particles=[],super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}class ol 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 Je=1;class rl extends ${constructor(t,e,s={}){super(),this._levelView=s.levelView||null,this._renderer=s.renderer||null,this._surfaces=s.surfaces||null,this._level=t[dt]||0,this._markLayers=new Map,this.zIndex=N(Je,this._level),this._currentX=t[St]||0,this._currentY=t[bt]||0,this._currentRotation=t[Ft]||0,this._engineLoad=t[Ot]||0,this._condition=t[wt],this._size=t[Ae],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[St],this._currentY=t[bt],this._currentRotation=t[Ft],this._engineLoad=t[Ot],this._condition=t[wt];const e=t[dt]||0;e!==this._level&&(this._level=e,this.zIndex=N(Je,e))}_markLayer(t){let e=this._markLayers.get(t);if(e)return e;e=new $,e.zIndex=N(Je,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=ur(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&&zt.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&&zt.tracks.noMarks.includes(t))return;let e=t&&zt.tracks[t]||null,s=1;!e&&this._trailLeft>0&&(e=zt.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 ol(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=ht(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&&pt(s,t,e*W.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 hi=2,ie=300,al=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},ll={color:st.color,alpha:st.startAlpha,lifetime:st.lifetime},hl=["sand","mud","water"],ci=.35,cl=(i,t)=>i.kind==="boost"&&i.dir!==null&&i.dir[0]===t[0]&&i.dir[1]===t[1];class ul extends ${constructor(t,e,s={}){super(),this._level=t[dt]||0,this.zIndex=N(hi,this._level);const{texture:n,contentSize:o}=e.dustTexture;this._dustTexture=n,this._textureScale=al/o,this._x=t[St],this._y=t[bt],this._rotation=t[Ft],this._vx=t[ce]||0,this._vy=t[ue]||0,this._engineLoad=t[Ot]||0,this._condition=t[wt],this._z=t[Jt]||0,this._vz=t[Oe]||0,this._prevVz=this._vz,this._size=t[Ae];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)),pt(this,ht(this.parent,this._renderer),this._z*W.shear,1)}),this._particleContainer=new Ne({texture:this._dustTexture,boundsArea:new at(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[dt]||0;o!==this._level&&(this._level=o,this.zIndex=N(hi,o)),this._x=t[St],this._y=t[bt],this._rotation=t[Ft],this._vx=t[ce]||0,this._vy=t[ue]||0,this._engineLoad=t[Ot]||0,this._condition=t[wt],this._z=t[Jt]||0,this._vz=t[Oe]||0,this._particleContainer.boundsArea.x=this._x-ie,this._particleContainer.boundsArea.y=this._y-ie;const r=en(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)>zt.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&&!cl(r,o)&&this._vx*o[0]+this._vy*o[1]>=zt.boost.boostMinSpeed&&this._triggerBoostFlash(o))}_triggerWaterEntry(){const t=zt.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=zt.boost,s=Math.atan2(-t[1],-t[0]);for(let n=0;n<e.burst;n+=1){const o=s+F(-ci,ci),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=ll){const a=st.startSizeFactor*o,l=st.endSizeFactor*o,h=yt.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),yt.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=hl.includes(s)?zt[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)yt.release(this._particles[e].view);this._particles=[],super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}function fl({progress:i,totalDist:t,trailLength:e,trailShare:s=0}){const n=t*Ct(i,0,1),o=Math.max(e,t*s),r=ct(o,0,Ct(i,0,1));return{tail:Math.max(0,n-r),head:n}}class dl extends Qt{constructor(t,e,s,n,o,r=Ee,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=Ct(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}=fl({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 _l(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;Qe(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&&Qe(u,c.from,Math.min(c.to,h),c.level);return Qe(u,h,t,s),u}function Qe(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 pl 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=be(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 ml(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 gl({dirX:i,dirY:t,t:e,roll:s,config:n}){const o=1-Ct(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 xl extends Qt{constructor(t,e,s,n,o,r=Bn,a=Math.random){super(o),this.position.set(t,e),this.dirX=s,this.dirY=n,this.config=r,this.roll=ml(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=gl({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 ui=(i,t)=>Math.round(i/t)*t;function on(i,t,e,s,n,o,r){const a=ui(i,n),l=ui(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 fi(i,t,e,s){return i.nx*(s.x-t)+i.ny*(s.y-e)>0}function yl({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 ts=2,di=Li+.5,es=.15;class wl extends ${constructor(t,e,s){super(),this.startPositionX=t[dr],this.startPositionY=t[_r],this.endPositionX=t[pr],this.endPositionY=t[mr],this.soundPositionX=t[gr],this.soundPositionY=t[xr],this.hitCode=t[yr]||0,this.hit=this.hitCode!==0,this.endLevel=t[vr]||0,this.startLevel=t[wr]||0,this.zIndex=N(ts,this.endLevel),this.anchorKey=null,this.anchorLocalX=0,this.anchorLocalY=0,Array.isArray(t[Bs])&&([this.anchorKey,this.anchorLocalX,this.anchorLocalY]=t[Bs]),this._assets=e,this._soundManager=s.soundManager,this._isLocalShot=s.localPlayer?.is(t[Ze])===!0,s.shots?.fired(t[Ze]),this._mapDynamics=s.mapDynamics||null,this._shots=s.shots||null,this._shooterId=t[Ze],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=ht(this.parent,this._renderer);pt(this,n,this.endLevel*W.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)),pt(r,n,o*W.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({...Mt.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 xl(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=_l(this._shots?.path?.(this.startPositionX,this.startPositionY,n.x,n.y,this.startLevel),n.dist,this.endLevel);this.tracer=new dl(this.startPositionX,this.startPositionY,n.x,n.y,this._onTracerComplete.bind(this),Ee,{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===Mr){const c=2*es,_=this._floorAt(this.endPositionX+t*c,this.endPositionY+e*c),f=this._rampRuns?.faceAt?.(_,this.endPositionX,this.endPositionY,t,e,es);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=on(this.endPositionX,this.endPositionY,t,e,s,n,es);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()??ht(this.parent,this._renderer);if(!a)return n;const{face:l,volume:h,base:u}=this._wall,{shear:c}=W,_=this.endLevel*c;let f,p;if(fi(l,this.endPositionX,this.endPositionY,a))({x:f,y:p}=be(this.endPositionX,this.endPositionY,a,_,(this.endLevel+Ee.height)*c)),this.zIndex=N(di,this.endLevel);else{const d=yl({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===Ws&&t>.001?this._rampRuns?.slopeAt?.(this.endLevel,this.endPositionX,this.endPositionY):null;if(!e)return null;const s=this._levelView?.camera()??ht(this.parent,this._renderer),{shear:n}=W,{x:o,y:r}=be(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}=W;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}=W;return this._wall?(this.endLevel+Ee.height)*t:this.hitCode===Ws?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*W.shear)}_placeImpactZ(t){const e=this.impact;if(!this._wall||!e||e.destroyed)return;const s=!!(t&&fi(this._wall.face,this.endPositionX,this.endPositionY,t));this.zIndex=N(s&&e.isFalling()?di:ts,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=N(s?Vi:ts,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}=W,s=be(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 pl(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 _i{constructor({texture:t,max:e,blendMode:s="normal",padding:n}){this.texture=t,this.max=e,this.items=[],this._padding=n,this.container=new Ne({texture:t,boundsArea:new at(-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=yt.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),yt.release(e.view))}clear(){this.container.removeParticles();for(let t=0;t<this.items.length;t+=1)yt.release(this.items[t].view);this.items.length=0}}const pi=(i,t)=>i>>t&255;function ve(i,t,e){const s=Math.min(Math.max(e,0),1),n=o=>{const r=pi(i,o);return Math.round(r+(pi(t,o)-r)*s)};return n(16)<<16|n(8)<<8|n(0)}function vl(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 ve(l,r,(t-a)/(o-a))}}return i[i.length-1][1]}function rn(i,t){return i<=t.duration?1:t.fadeOut>0?Math.max(0,1-(i-t.duration)/t.fadeOut):0}function an(i){return i.duration+i.fadeOut}function Ml(i,t,e){const s=an(t);if(i<s){const n=rn(i,t);return e.tailRate+(e.rate-e.tailRate)*n}return e.tailRate*Math.max(0,1-(i-s)/e.tail)}function Sl(i,t){return an(i)+t.tail}function bl(i,t){return i<=0||i>=1?0:i<.12?t*(i/.12):i<=.45?t:t*(1-(i-.45)/.55)}const mi=4,kl=2,gi=400,Tl=100,Kt=Math.PI*2,At=i=>F(i.min,i.max);class Al extends ${constructor(t,e,s={}){super(),this._readRow(t),this._condition=t[wt],this.zIndex=N(mi,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._fire=null,this._smoke=null,this._glow=null,this._flash=null,this._flashAge=0}_readRow(t){this._x=t[St],this._y=t[bt],this._heading=t[Ft],this._z=t[Jt]||0,this._physLevel=t[dt]||0,this._level=ke(t[dt],this._z);const e=t[Ae]||Z.referenceSize;this._length=e*4,this._width=e*3,this._sizeScale=e/Z.referenceSize}update(t){const e=this._condition,s=this._level;this._readRow(t),this._level!==s&&(this.zIndex=N(mi,this._level)),this._active&&(this._fire.follow(this._x,this._y),this._smoke.follow(this._x,this._y));const n=t[wt];n===void 0||n===e||(this._condition=n,n===0&&e>0?this._ignite():n>0&&e===0&&this._reset())}_ensureViews(){if(this._fire)return;const t=this._fireAsset.texture;this._smoke=new _i({texture:this._smokeAsset.texture,max:Z.maxSmoke,padding:gi}),this._fire=new _i({texture:t,max:Z.maxFire,blendMode:"add",padding:gi});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=Z.flash.color,t.visible=!0,this._stepFlash(0);for(let e=0;e<Z.fireball.count;e+=1)this._spawnFireball();for(let e=0;e<Z.sparks.count;e+=1)this._spawnSpark();for(let e=0;e<Z.smoke.burst.count;e+=1)this._spawnSmoke(1,!0)}_notify(){this._soundManager&&(this._soundId=this._soundManager.registerSound(Z.sound,{position:{x:this._x,y:this._y}})),this._lighting?.flash({...Mt.flash.wreck,level:this._level,x:this._x,y:this._y,z:this._z}),this._blasts?.exploded({x:this._x,y:this._y,radius:Z.joltRadius*this._sizeScale,level:this._physLevel})}_addLight(){this._lighting&&(this._light=this._lighting.addLight({kind:"radial",radius:Mt.wreckFire.radius*this._sizeScale,color:Mt.wreckFire.color,intensity:0}))}_addScorch(){const t=this._scorchAsset;if(!t||!this.parent)return;const{textures:e}=t,s=new J(e[Math.floor(Math.random()*e.length)]);s.anchor.set(.5),s.rotation=Math.random()*Kt,s.alpha=0,s.zIndex=N(kl,this._level),this._scorch=s,this._scorchX=this._x,this._scorchY=this._y,this._scorchZ=this._z,this._scorchLevel=this._level,this._scorchScale=Z.scorch.size*this._sizeScale/t.contentSize,this._scorchAge=0,this._scorchAlpha=0,this.parent.addChild(s),this.parent.sortChildren()}_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}=Z,n=this._hullPoint(e.points,e.spread),o=this._fire.spawn({kind:"flame",x:n.x,y:n.y,vx:s.x*.5+F(-4,e.jitter)*this._sizeScale,vy:s.y*.5+F(-4,e.jitter)*this._sizeScale,windX:s.x,windY:s.y,drag:0,h:0,rise:e.rise,age:0,life:At(e.lifetime),size0:At(e.size)*this._sizeScale*(.6+.4*t)*this._fireUnit,grow:e.grow,aspectX:F(.8,1.2),aspectY:F(.8,1.2),spin:F(-1,1),alpha:e.alpha,tint:16777215,scaleX:0,scaleY:0});o&&(o.view.rotation=Math.random()*Kt,this._applyFire(o,0))}_spawnFireball(){const{fireball:t,wind:e}=Z,s=this._hullPoint([[0,0]],.8),n=Math.random()*Kt,o=At(t.speed)*this._sizeScale,r=this._fire.spawn({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,h:0,rise:t.rise,age:0,life:At(t.lifetime),size0:At(t.size)*this._sizeScale*this._fireUnit,grow:t.grow,aspectX:F(.8,1.2),aspectY:F(.8,1.2),spin:F(-1,1),alpha:t.alpha,tint:16777215,scaleX:0,scaleY:0});r&&(r.view.rotation=Math.random()*Kt,this._applyFire(r,0))}_spawnSpark(){const{sparks:t}=Z,e=Math.random()*Kt,s=At(t.speed)*this._sizeScale,n=this._fire.spawn({kind:"spark",x:this._x,y:this._y,vx:Math.cos(e)*s,vy:Math.sin(e)*s,windX:0,windY:0,drag:t.drag,h:0,rise:0,age:0,life:At(t.lifetime),size0:t.length*this._sizeScale*this._fireUnit,width:t.width*this._sizeScale*this._fireUnit,grow:1,aspectX:1,aspectY:1,spin:0,alpha:1,tint:16777215,scaleX:0,scaleY:0});n&&(n.view.rotation=e,this._applyFire(n,0))}_spawnSmoke(t,e){const{fire:s,smoke:n,wind:o}=Z,r=this._hullPoint(s.points,s.spread),a=Math.random()*Kt,l=(e?At(n.burst.speed):F(0,n.speed))*this._sizeScale,h=Math.random(),u=ve(ve(n.cooling[0],n.cooling[1],h),ve(n.burning[0],n.burning[1],h),t),c=this._smoke.spawn({kind:"smoke",x:r.x,y:r.y,vx:Math.cos(a)*l+o.x,vy:Math.sin(a)*l+o.y,windX:o.x,windY:o.y,drag:n.drag,h:0,rise:n.rise,age:0,life:At(n.lifetime)*(e?.8:1),size0:At(n.size)*this._sizeScale*(e?1.3:1)*this._smokeUnit,grow:n.grow,aspectX:F(.7,1.3),aspectY:F(.7,1.3),spin:F(-.3,.3),alpha:e?n.burst.alpha:ct(n.tailAlpha,n.alpha,t),tint:u,scaleX:0,scaleY:0});c&&(c.view.tint=u,c.view.rotation=Math.random()*Kt,this._applySmoke(c,0))}_tick(t){if(!this._active)return;const e=Ct(t,0,Tl);this._elapsed+=e;const s=rn(this._elapsed,Z.fire);for(this._flameAcc+=Z.fire.rate*s*e/1e3;this._flameAcc>=1;)this._flameAcc-=1,this._spawnFlame(s);for(this._smokeAcc+=Ml(this._elapsed,Z.fire,Z.smoke)*e/1e3;this._smokeAcc>=1;)this._smokeAcc-=1,this._spawnSmoke(s,!1);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>=Sl(Z.fire,Z.smoke)&&this._fire.size===0&&this._smoke.size===0&&!this._flash.visible&&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}_writeView(t){const e=t.view;e.x=t.x,e.y=t.y,e.scaleX=t.scaleX,e.scaleY=t.scaleY}_applyFire(t,e){const s=e/1e3,n=this._move(t,s),o=t.view;if(t.kind==="spark"){const{colors:r}=Z.sparks;t.scaleX=t.size0*(1-.5*n),t.scaleY=t.width,o.rotation=Math.atan2(t.vy,t.vx),o.tint=ve(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=vl(Z.fire.ramp,n),o.alpha=t.alpha*(1-n*n)}this._writeView(t)}_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=bl(n,t.alpha),this._writeView(t)}_stepFlash(t){const e=this._flash;if(!e.visible)return;const{duration:s,startSize:n,endSize:o,alpha:r}=Z.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=Z.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*he(this._seed,this._elapsed,s.flicker))}_stepLight(t){if(!this._light)return;if(t<=0){this._removeLight();return}const e=Mt.wreckFire;this._lighting.updateLight(this._light,{x:this._x,y:this._y,z:this._z,level:this._level,levels:Oi(this._physLevel,this._z,!1),intensity:e.intensity*t*he(this._seed+1,this._elapsed,e.flicker)})}_stepScorch(t){if(!this._scorch)return;const{alpha:e,fadeIn:s}=Z.scorch;this._scorchAge+=t,this._scorchAlpha=e*Ct(this._scorchAge/s,0,1)}_render(){const t=ht(this.parent,this._renderer),e=W.shear;if(this._active){const s=this._z*e;pt(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=be(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}}if(this._scorch){const s=this._scorchZ*e,n=_t(this._scorchX,this._scorchY,t,s);this._scorch.position.set(n.x,n.y),this._scorch.scale.set(this._scorchScale*(1+s));const o=this._levelView?this._levelView.alphaFor(this._scorchLevel,this._scorchX,this._scorchY,this._scorchZ):1;this._scorch.alpha=this._scorchAlpha*o,this._levelView&&(this._scorch.tint=this._levelView.tintFor(this._scorchLevel))}}_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&&(this._scorch.destroy({texture:!1,textureSource:!1}),this._scorch=null),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 Ll={Map:Dr,MapRadar:Br,TankRadar:Nr,Tank:Da,Bomb:Oa,ExplosionEffect:tl,Smoke:nl,Tracks:rl,Dust:ul,ShotEffect:wl,WreckFire:Al};function Xt(i,t,{blur:e,quality:s=10,width:n,height:o}){const r=new ms({strength:e,quality:s});r.padding=Ki(e),t.filters=[r];const a=i.generateTexture({target:t,frame:new at(0,0,n,o)});return t.destroy(!0),r.destroy(),a}function ge(i,t){const{radius:e,blur:s,color:n,quality:o=40}=i,r=new U,a=(e+kt(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 Pl(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+kt(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 xt(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 ne=xt(0,0,1);function ln(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 hn(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 rt=10,Be=rt*4,We=rt*3,zl=13158852,tt={x:-Be/2,y:-We/2,w:Be,h:We},re={x:-18,y:-9,w:36,h:18},cn={l:2,r:4,t:2,b:2},Cl=[{x:-19,y:-14,w:38,h:5},{x:-19,y:9,w:38,h:5}],Ue=[1.33,-.42,.42,-1,-.42,-1,-1.33,-.42,-1.33,.42,-.42,1,.42,1,1.33,.42].map(i=>i*rt),un=.6,Xe={x:.25*rt,y:-.25*rt,w:2.08*rt},Me={x:2.1*rt,y:-.36*rt,w:.35*rt,h:.72*rt},ss={x:-.45*rt,y:.35*rt,r:.28*rt},cs={width:.08*rt},Il=.55;function fn(i){i.rect(tt.x,tt.y,tt.w,tt.h).fill(5592405);for(const t of Cl){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(re.x,re.y,re.w,re.h).fill(zl),ln(i,re,cn,{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 us(i,t){const e={...cs,color:qt(t,Il)},s={width:.06*rt,color:e.color};i.poly(Ue).fill(t).stroke(e),hn(i,Ue,un,()=>qt(t,.8)),i.circle(ss.x,ss.y,ss.r).fill(qt(t,.65)).stroke(s),i.rect(Xe.x,Xe.y,Xe.w,2.5*2).fill(t).stroke(e),i.rect(Me.x,Me.y,Me.w,Me.h).fill(qt(t,.7)).stroke(s)}const xe={width:Be,height:We};function El(i,t){const{colors:e}=i,s={},n=fn,o=us,r=f=>{f.rect(tt.x,tt.y,tt.w,tt.h).fill(ne),f.rect(tt.x,tt.y,tt.w,1).fill(xt(0,-1,1)),f.rect(tt.x,tt.y+tt.h-1,tt.w,1).fill(xt(0,1,1)),f.rect(tt.x,tt.y+1,1,tt.h-2).fill(xt(-1,0,1)),f.rect(tt.x+tt.w-1,tt.y+1,1,tt.h-2).fill(xt(1,0,1)),ln(f,re,cn,{l:xt(-1,0,1),r:xt(1,0,2),t:xt(0,-1,1),b:xt(0,1,1)})},a=f=>{f.poly(Ue).fill(ne).stroke({...cs,color:ne}),hn(f,Ue,un,(d,g)=>xt(d,g,1));const p=({x:d,y:g,w:m,h:w},M)=>{f.rect(d,g,m,w).fill(ne).stroke({...M,color:ne}),f.rect(d,g,m,w/2).fill(xt(0,-1,1)),f.rect(d,g+w/2,m,w/2).fill(xt(0,1,1))};p({...Xe,h:2.5*2},cs),p(Me,{width:.06*rt})},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 at(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=Be,S=We,y=rt;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 k=[y*.8,-y*.25,y*1.5,-y*.4,y*1.4,y*.15,y*.7,y*.05];d.poly(k).fill(w).stroke({width:y*.1,color:b,alignment:0}),d.circle(y*.1,-y*.2,y*.4).fill(M);const P=f.getBounds(),R=t.generateTexture({target:f,frame:new at(P.x,P.y,P.width,P.height)});f.destroy({children:!0});const D=new U().rect(P.x,P.y,P.width,P.height).fill(ne),E=t.generateTexture({target:D,frame:new at(P.x,P.y,P.width,P.height)});return D.destroy(!0),{texture:R,normal:E}};s.liveTeamId1=u(e.teamId1),s.liveTeamId2=u(e.teamId2);const _=c();return s.destroyed=_.texture,s.destroyedNormal=_.normal,s}const lt=2;function Rl(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 xi(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 Fl(i,t,e=vt){const{colors:s}=i,n=(o,r=!1)=>{const a=new U;us(a,o);const l=a.getBounds();a.destroy(!0);const h=Math.ceil(l.width),u=Math.ceil(l.height),c={x:lt,y:lt,w:xe.width,h:xe.height,originX:lt+xe.width/2,originY:lt+xe.height/2},_={x:c.x+c.w+lt,y:lt,w:h,h:u,originX:c.x+c.w+lt-l.x,originY:lt-l.y},f=lt+Math.max(c.h,_.h)+lt,p={x:lt,y:f,w:xe.width,h:e.trackHeight},d={x:p.x+p.w+lt,y:f,w:22,h:e.barrelRadius*2},g={x:d.x+d.w+lt,y:f,w:8,h:e.brakeRadius*2},m={x:g.x+g.w+lt,y:f,w:4,h:4},w=Math.max(_.x+_.w,m.x+m.w)+lt,M=f+Math.max(p.h,d.h,g.h,m.h)+lt,b=new $,v=new U,S=new U,y=new U;if(fn(v),v.position.set(c.originX,c.originY),us(S,o),S.position.set(_.originX,_.originY),Rl(y,p),xi(y,d,o),xi(y,g,qt(o,.7)),y.rect(m.x,m.y,m.w,m.h).fill(1710618),b.addChild(v,S,y),r){const k=new U;for(const P of[c,_,p,d,g])k.rect(P.x,P.y,P.w,P.h).fill({color:789e3,alpha:.62});k.circle(c.originX+4,c.originY+2,6).fill({color:0,alpha:.5}),k.circle(c.originX-9,c.originY-4,3).fill({color:0,alpha:.5}),k.circle(_.originX-2,_.originY+1,4).fill({color:0,alpha:.5}),b.addChild(k)}const z=t.generateTexture({target:b,frame:new at(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 Xl(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 at(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 at(0,0,l,l)});return p.destroy(!0),g};return a.liveTeamId1=_(r.teamId1),a.liveTeamId2=_(r.teamId2),a.destroyed=f(),a}function Yl(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 at(0,0,o,o)});return n.destroy(!0),a}function Dl(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 at(0,0,s,e)});return o.destroy(!0),r}function Vl(i,t){const{width:e,height:s,radius:n,blur:o,color:r,quality:a=20}=i,l=new U,h=kt(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 yi(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+kt(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 Ol(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 at(0,0,e,e)})),u.destroy(!0)}return{textures:l,contentSize:e}}function dn(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 wi(i,t){const{radius:e,rings:s=32,blur:n=2,quality:o=10}=i,r=new U,a=kt(n),l=(e+a)*2,h=l/2;return dn(r,h,e,s,Wi),{texture:Xt(t,r,{blur:n,quality:o,width:l,height:l}),contentSize:e*2}}function Bl(i,t){const{length:e,halfWidth:s,strips:n=24,blur:o=4,quality:r=10}=i,a=new U,l=kt(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=Ui(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 Wl(i,t){const{core:e,halo:s,rings:n=12,blur:o=1,quality:r=10}=i,a=new U,l=kt(o),h=(s+l)*2,u=h/2,c=e/s;return dn(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 Ul(i,t){const{radius:e,strips:s=16,blur:n=2,quality:o=10}=i,r=new U,a=kt(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 Nl(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 Hl(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=kt(a),c=(e+u)*2,_=c/2,f=Nl(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 k=m*z/o,P=m*(z+1)/o,R=(z+.5)/o;h.poly([_+b*k,_+v*k,_+b*P,_+v*P,_+S*P,_+y*P,_+S*k,_+y*k]),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 Gl={explosionTexture:ge,smokeTexture:ge,impactParticleTexture:ge,dustTexture:ge,wreckSmokeTexture:ge,wreckFireTexture:wi,wreckScorchTexture:yi,tankShadowTexture:Vl,funnelTexture:Pl,tankTexture:El,tankModelTexture:Fl,tankRadarTexture:Xl,bombTexture:Yl,trackMarkTexture:Dl,scorchTexture:yi,debrisTexture:Ol,lightRadialTexture:wi,headlightConeTexture:Bl,lampHeadTexture:Wl,glintTexture:Ul,lightShaftTexture:Hl},$l=i=>(i??"").split(/[?#]/)[0].endsWith(".js"),Kl=i=>import(i);function Zl(i=On,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=ht(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=_t(e.x,e.y,h,e.z*W.shear),c=_t(r,a,h,l*W.shear);return Zn({viewLevel:e.level,viewX:u.x,viewY:u.y,level:o,x:c.x,y:c.y,cfg:i})},tintFor(o){return jn(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 vs(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 _n(i,t){const e=i.sign>0?t:1-t;return i.from+(i.to-i.from)*e}function jl(i,t,e,s,n,o){const{alongX:r,a0:a,a1:l,b0:h,b1:u}=vs(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=_n(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 Ms(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 ql=.2;function Ss(i,t,e,s,n){const{alongX:o,a0:r,a1:a}=vs(i,s,n),l=o?t:e,h=a-r||1,u=Math.min(1,Math.max(0,(l-r)/h));return _n(i,u)}function Jl({lane:i,prevLane:t,col:e,row:s,prevCol:n,prevRow:o,x:r,y:a,z:l,cellW:h,cellH:u,clearance:c=ql}){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:Ss(i,r,a,h,u)-(l||0)>c}function vi(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 Ql(i,t,e,s,n,o,r,a){const l=Ms(i,t,e,s,n,o,r,a);return l>=n?null:{distance:l,x:i+e*l,y:t+s*l}}function th({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 k=Ms(i,t,b,v,z,a,l,h);d[w]=z,k<z-1e-6&&(g=!0),p[(w+1)*2]=i+b*k,p[(w+1)*2+1]=t+v*k}),{points:p,clipped:g,closed:c,reaches:d,forward:u}}function bs(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 eh(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]=bs(i[o],i[o+1],t,e,s);n[o]=r,n[o+1]=a}return n}const sh=[0,1,3,0,3,2];function ih({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),k=s[v-1];if(!(z>1e-9)||!(z<k-1e-6))return null;const P=(S-i)/z,R=(y-t)/z,D=on(S,y,P,R,a,l,.001);if(!D)return null;const E=r(S+P*c,y+R*c);return E>0?{face:D,x:S,y,endX:S+P*(k-z),endY:y+R*(k-z),height:Math.min(h,E)}: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(([k,P,R,D,E],X)=>{const Y=y*4+X,[B,V]=o(D,E);d[Y*2]=k,d[Y*2+1]=P,g[Y]=u+R,m[Y*2]=B,m[Y*2+1]=V});for(let k=0;k<6;k+=1)w[y*6+k]=y*4+sh[k];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 fs(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 oe(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 nh({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}=vs(e,n,o),_=E=>a?[i[E*2],i[E*2+1]]:[i[E*2+1],i[E*2]],f=i.length/2;let p=1/0,d=-1/0,g=1/0,m=-1/0;for(let E=0;E<f;E+=1){const[X,Y]=_(E);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=[],k=[],P=[],R=E=>{const X=z.length;for(const[Y,B]of E){const V=a?Y:B,G=a?B:Y,[j,H]=bs(V,G,s,v,S);y.push(V,G),z.push(Ss(e,V,G,n,o)),k.push(j,H)}for(let Y=1;Y+1<E.length;Y+=1)P.push(X,X+Y,X+Y+1)},D=fs(f-1,t);for(let E=0;E<D.length;E+=3){let X=[_(D[E]),_(D[E+1]),_(D[E+2])];if(X=oe(X,1,u,!0),X=oe(X,1,c,!1),X=oe(X,0,l,!0),X=oe(X,0,h,!1),X.length<3)continue;const Y=Math.min(...X.map(([j])=>j)),B=Math.max(...X.map(([j])=>j)),V=Math.max(0,Math.floor((Y-l)/b)),G=Math.min(M-1,Math.ceil((B-l)/b)-1);for(let j=V;j<=G;j+=1){const H=oe(oe(X,0,l+j*b,!0),0,l+(j+1)*b,!1);H.length>=3&&R(H)}}return P.length?{base:new Float32Array(y),heights:new Float32Array(z),uvs:new Float32Array(k),indices:new Uint32Array(P)}:null}const Ce=16777215;class Mi{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=N(Mo,t),this.overlay.eventMode="none",this.base=new J(De.WHITE),this.base.tint=t===0?e:Ce,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 Ai({alpha:1}),this.filter.resolution=s,this.filter.blendMode="multiply",this.overlay.filters=[this.filter],this.overlay.filterArea=new at(n.x,n.y,n.width,n.height),this.resolution=s,this.hole=os(),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&&pt(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=jl(r,s,n,t,e,o);this.rampMask.poly(a),this.lightsMask.poly(a)}this.rampMask.fill(Ce),this.lightsMask.fill(Ce)}for(const{graphics:s,volume:n}of this.topGroups)pt(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){oh(this.pool,this.lights,t.filter(e=>!e.fan)),rh(this.fanPool,this.lights,t.filter(e=>e.fan))}layoutWashes(t,e,s){ds(this.washPool,this.lights,t.length,()=>new Uint32Array(6));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;Si(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=_),_s(o,r)}}layoutRampLights(t,e,s){ds(this.rampLightPool,this.rampLights,t.length,()=>new Uint32Array(3));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;Si(h,a.base,a.heights,e,s),l.positions=h,_s(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(Ce);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),rs(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=De.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 pn(i,t){return i.levels.has(t)||i.roofLevels.has(t)}function ds(i,t,e,s){for(;i.length<e;){const n=new Pn({positions:new Float32Array(6),uvs:new Float32Array(6),indices:s()}),o=new Ti({geometry:n,texture:De.EMPTY});o.blendMode="add",i.push(o),t.addChild(o)}}function _s(i,t){i.visible=!0,i.texture=t.texture,i.tint=t.color,i.alpha=t.alpha}function Si(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 oh(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 rh(i,t,e){ds(i,t,e.length,()=>fs(2));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=fs(h,a.closed),n.topology=u),l.positions=a.points,l.uvs=a.uvs,n.shape=a}_s(n,o),n.position.set(r.x,r.y),n.scale.set(r.scale)}}const ah=.6;function mn(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 lh({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.values())for(const[z,k]of S)w(z,k)&&(v||=new Float32Array(g*m),v[k*g+z]=Math.max(v[k*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 k=y.row0;k<y.row1;k+=1)for(let P=y.col0;P<y.col1;P+=1)w(P,k)&&(S[k*g+P]=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=(k,P)=>k>=0&&k<m&&P>=0&&P<w?P*m+k:-1,S=p.rampCells.get(d)||null;if(!g&&!S)return null;const y=k=>S&&k>=0&&S.cells[k]>0?S.lanes[S.cells[k]-1]:null,z=y(v(Math.floor(f.x/M),Math.floor(f.y/b)));return(k,P,R,D,E,X)=>{const Y=v(k,P);if(g&&Y>=0&&g[Y]>0)return!0;if(!S||R===null||R===void 0)return!1;const B=y(Y),V=y(v(R,D));return z&&(B===z||V===z)?!1:Jl({lane:B,prevLane:V,col:k,row:P,prevCol:R,prevRow:D,x:E,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),k=Math.sin(p);let P=1/0,R=1/0,D=-1/0,E=-1/0;for(const G of[-g,d])for(const j of[-m,m]){const H=f.x+G*z-j*k,mt=f.y+G*k+j*z;P=Math.min(P,H),R=Math.min(R,mt),D=Math.max(D,H),E=Math.max(E,mt)}const X=Math.floor(P/S)-1,Y=Math.floor(R/y)-1,B=Math.floor(D/S)+1,V=Math.floor(E/y)+1;return vi(w.blockers.get(M),b,v,X,Y,B,V)||vi(w.rampCells.get(M)?.cells,b,v,X,Y,B,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?Ss(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,k=mn(f,p),P=(k.width-k.margin)*k.sx,R=k.margin*k.sx,D=k.height/2*k.sy;if(!r(f,m,P,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:E,clipped:X,closed:Y,reaches:B,forward:V}=th({x:f.x,y:f.y,rotation:m,alongMax:P,alongBack:R,acrossMax:D,rays:d.rays},v,y,z),G=t.headlights?.wash,j={key:M,texture:p.texture,shape:X?{points:E,closed:Y,uvs:eh(E,k)}:null,hit:Ql(f.x,f.y,Math.cos(m),Math.sin(m),f.radius,v,y,z),fan:{points:E,closed:Y,frame:k},wash:G?.intensity>0?ih({x:f.x,y:f.y,points:E,reaches:B,forward:V,uvOf:(H,mt)=>bs(H,mt,k),wallAt:(H,mt)=>Math.max(l(g,H,mt),h(g,H,mt)),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 Ms(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*ah;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 hh({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=mn(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,nh({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 ch({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 Co(p.lampGrid,h,u))m.level===c&&d.push({light:m,factor:he(m.seed,f,m.flicker)});for(const m of t)m.kind==="cone"&&!_?.includes(m)&&g(m)&&Ni(m,h,u)>0&&n(m,h,u)&&d.push({light:m,factor:1});for(const m of e){const w=Bi(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=Po(a(h,u,c,f,p),h,u,_);return d.length&&(r+=1),d},candidatesAt:a}}const uh=.08;function fh({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,_=_t(u.x,u.y,s,c),f=Io(t.x,t.y,_.x,_.y,u.radius*(1+c),e);f&&h.push(f)}return h}function dh({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||!pn(i,_.level))continue;if(c>=e.maxLights)break;const f=Re(_.x,_.y,_.level,n,a,l),p=_.radius*u.length*f.scale;!(p>0)||!as(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:Eo(_.seed,r,uh),color:_.color,alpha:u.intensity*_.intensity*he(_.seed,r,_.flicker),shadows:fh({lamp:_,view:f,reach:p,camera:n,shaftsCfg:u,casters:t,shear:l})}),c+=1)}return h}const _h=3818080,ph=["radial","cone","head","glint","shaft"];function mh(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 gh(i=Mt,t={}){const e=!!i.enabled,s=t.levelView||null,n=t.volumes||null,o=t.shear??W.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=lh({getMap:()=>d,cfg:i}),y=ch({getMap:()=>d,lights:h,flashes:c,cfg:i,reachesPoint:S.reachesPoint}),z=hh({getMap:()=>d,textures:l}),k=()=>s?.cfg||null,P=(x,T,L,A)=>{let I=x.get(A);return I||(I=new $,I.label=`${L}-${A}`,I.zIndex=N(T,A),I.eventMode="none",x.set(A,I)),I},R=x=>P(d.emissive,Vi,"emissive",x),D=x=>P(d.lampHeads,So,"lamp-heads",x),E=()=>{if(!(!d?.night||!l.head||d.headsReady)){d.headsReady=!0;for(const x of d.lamps){if(!x.head)continue;const T=new J(l.head.texture);T.anchor.set(.5),T.blendMode="add",T.tint=x.color,x.headSprite=T,D(x.level).addChild(T)}}},X=(x,T,L,A)=>{const I=x||{},K=!!I.night,q=Te(L??1);if(d={night:K,ambient:I.ambient??_h,step:T,scale:q,cellW:T*q.x,cellH:T*q.y,area:mh(A,T,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},!!K){(I.lamps||[]).forEach((nt,Tt)=>{const[te,Yt]=nt.cell||[0,0],ee=nt.level||0,O=To(te,Yt,T,q);d.lamps.push({kind:"radial",level:ee,x:O.x,y:O.y,z:ee,radius:nt.radius??0,rotation:0,color:nt.color??16777215,intensity:nt.intensity??1,flicker:nt.flicker||0,seed:Tt+1,head:!!nt.head,headSprite:null})});for(const[nt,Tt]of u)R(Tt).addChild(nt);d.lampGrid=zo(d.lamps,Math.max(1,...d.lamps.map(nt=>nt.radius))),E(),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 T of u.keys())T.parent===x&&x.removeChild(T);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}},B=()=>{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=(x,T=null)=>{const L=[],A=new Set;for(const I of x?.values()||[])for(const K of I){const q=`${K[0]},${K[1]}`;!A.has(q)&&!T?.has(q)&&(A.add(q),L.push(K))}return[L,A]},H=(x,T,L,A)=>{let I=x.get(T);if(L.length===0){I&&(I.destroy(),x.delete(T));return}I||(I=new Mi({level:T,ambient:d.ambient,resolution:i.resolution,area:d.area,roof:A}),x.set(T,I)),I.setMask(Es(L),d.step,d.scale)},mt=x=>{const T=new Map;for(const{cells:L,volume:A}of G().get(x)||[])T.has(A)||T.set(A,[]),T.get(A).push(...L);return[...T].map(([L,A])=>({volume:L,runs:Es(A)}))},It=()=>{n&&n.version!==w&&(w=n.version,b=!0);const x=b;if(b){b=!1;const T=new Set([...g.keys(),...m.keys(),...d.levels.keys(),...d.roofLevels.keys()]);for(const L of T){if(L<1)continue;const[A,I]=j(m.get(L)),[K,q]=j(g.get(L),I);d.maskCells.set(L,q),d.roofCells.set(L,I),H(d.levels,L,K,!1),H(d.roofLevels,L,A,!0)}}if(d.levels.has(0)||d.levels.set(0,new Mi({level:0,ambient:d.ambient,resolution:i.resolution,area:d.area})),x){S.sync(G(),M);for(const T of d.levels.values())T.setTops(mt(T.level),d.step,d.scale),T.setRamps([...M.get(T.level)?.values()||[]].flat(),d.step,d.scale,Rt.rampSegments)}},Bt=()=>{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)},Wt=(x,T,L)=>{const A=x.kind==="cone"?l.cone:l.radial;if(!A||!(x.intensity*L>0))return null;const I=Re(x.x,x.y,x.z??x.level,T,r,o);if(x.kind==="cone"){const q=x.radius*I.scale,nt=q*(x.spread??.5);return{reach:q*r.scale.x,view:I,fan:null,hit:null,texture:A.texture,anchorX:A.margin/A.texture.width,anchorY:.5,scaleX:q/A.length,scaleY:nt/A.halfWidth,rotation:x.rotation||0,color:x.color,alpha:x.intensity*L}}const K=x.radius*I.scale;return{reach:K*r.scale.x,view:I,texture:A.texture,anchorX:.5,anchorY:.5,scaleX:K*2/A.contentSize,scaleY:K*2/A.contentSize,rotation:0,color:x.color,alpha:x.intensity*L}},Ut=(x,T)=>{if(T.kind!=="cone")return;const L=S.occlusionOf(T,l.cone);if(!L)return;const{view:A}=x;L.shape&&(x.fan={shape:L.shape,x:A.x-T.x*A.scale,y:A.y-T.y*A.scale,scale:A.scale}),x.hit=L.hit,x.wash=L.wash,x.rampFan=L.fan},Nt=(x,T,L)=>{const A=new Map,I=new Map,K=new Map;let q=0;const nt=z.targets(),Tt=i.rampSpill??1,te=[],Yt=(O,Dt)=>{const Gt=O.levels??[O.level],Ts=Gt.filter(ut=>pn(d,ut)),As=Tt>0?Gt.flatMap(ut=>nt.get(ut)||[]).filter(ut=>!Gt.includes(ut)):[];if(q>=i.maxLights||Ts.length===0&&As.length===0)return;const et=Wt(O,x,Dt);if(!et||!as(et.view.screenX,et.view.screenY,et.reach,T.width,T.height))return;et.x=et.view.x,et.y=et.view.y,Ut(et,O);const Le=O.level??0;et.wash&&d.levels.has(Le)&&(K.has(Le)||K.set(Le,[]),K.get(Le).push({wash:et.wash,texture:et.texture,color:et.color,alpha:et.alpha*i.headlights.wash.intensity}));for(const ut of Ts){if(q>=i.maxLights)return;A.has(ut)||A.set(ut,[]),A.get(ut).push(et),q+=1,z.push(I,ut,d.levels.get(ut)?.ramps,O,et,et.alpha)}for(const ut of new Set(As)){if(q>=i.maxLights)return;const yn=d.levels.get(ut)?.ramps.filter(wn=>Gt.includes(wn.to));z.push(I,ut,yn,O,et,et.alpha*Tt)&&(q+=1)}const Ls=et.hit?S.bounceOf(O,et.hit):null;Ls&&te.push({light:Ls,factor:Dt})};for(let O=c.length-1;O>=0;O-=1){const Dt=c[O],Gt=Bi(L-Dt.start,Dt.duration);Gt<=0?c.splice(O,1):Yt(Dt,Gt)}for(const O of h)Yt(O,1);for(const O of d.lamps)Yt(O,he(O.seed,L,O.flicker));for(const{light:O,factor:Dt}of te)Yt(O,Dt);const ee=dh({map:d,casters:_,cfg:i,asset:l.shaft,camera:x,screen:T,now:L,stage:r,shear:o});for(const O of V())O.place(x,o),O.layout(A.get(O.level)||[]),O.roof||O.layoutWashes(K.get(O.level)||[],x,o),O.layoutRampLights(O.roof?[]:I.get(O.level)||[],x,o),O.layoutShafts(ee.get(O.level)||[])},ot=x=>{const T=k();if(!T)return;const L=_t(s.x,s.y,x,s.z*o);for(const A of V()){if(A.level<1)continue;const I=s.level<A.level,K=A.roof&&I&&$n(d.roofCells.get(A.level),d.step,d.scale,L,x,[A.level*o],T.roofMargin??0),q=A.overlay,nt=Ii(A.hole,T.fadeRate);if(s.mode==="layer"){let Tt=K;if(!A.roof){const Yt=le(s.x,d.scale.x,d.step),ee=le(s.y,d.scale.y,d.step);Tt=I&&!!d.maskCells.get(A.level)?.has(`${Yt},${ee}`)}const te=Tt?T.layerAlpha:1;q.alpha+=(te-q.alpha)*nt;continue}gs(A.hole,A.roof?K:I,nt),xs(q,A.hole,T,s,r,x),A.syncFilters()}},Ht=(x,T)=>{for(const L of d.lamps){const A=L.headSprite;if(!A)continue;const I=Re(L.x,L.y,L.level,x,r,o);A.position.set(I.x,I.y),A.scale.set(I.scale),A.alpha=(s?s.alphaFor(L.level,I.x,I.y,0):1)*he(L.seed,T,L.flicker)}},gt=()=>e&&d?.night===!0;return{get enabled(){return e},attachStage(x,T){!e||r||!x||!T||(r=x,a=T,v=null,s?.attachStage(x,T))},acquireMap(x,T,L,A,I){e&&(p.set(x,(p.get(x)||0)+1),x!==f&&(Y(),f=x,X(T,L,A,I)))},releaseMap(x,T){if(!e)return;if(T!==void 0)for(const A of[g,m,M])for(const I of A.values())I.delete(T)&&(b=!0);const L=p.get(x);if(L!==void 0){if(L>1){p.set(x,L-1);return}p.delete(x),x===f&&B()}},setLevelMask(x,T,L,{roof:A=!1}={}){if(!e||!(x>=1))return;const I=A?m:g;I.has(x)||I.set(x,new Map),T&&T.length>0?I.get(x).set(L,T):I.get(x).delete(L),b=!0},setRampWedges(x,T,L){if(!e||!(x>=0))return;M.has(x)||M.set(x,new Map);const A=(T||[]).filter(I=>I.from===x&&I.to>I.from);A.length>0?M.get(x).set(L,A):M.get(x).delete(L),b=!0},registerTextures(x){if(!(!e||!x)){for(const T of ph){const L=x[T];if(!L)continue;const A=l[T];if(l[T]=L,T==="head"&&A&&A!==L){for(const I of u.keys())I.texture===A.texture&&(I.texture=L.texture);for(const I of d?.lamps||[])I.headSprite&&(I.headSprite.texture=L.texture)}}l.head&&E()}},texture(x){return l[x]||null},addLight(x){if(!e)return null;const T={kind:"radial",level:0,x:0,y:0,radius:0,rotation:0,color:16777215,intensity:1,...x};return h.add(T),T},updateLight(x,T){x&&h.has(x)&&Object.assign(x,T)},removeLight(x){h.delete(x)},flash(x){!gt()||!l.radial||c.push({kind:"radial",level:0,color:16777215,intensity:1,...x,start:Q.shared.lastTime})},addEmissive(x,T){return!gt()||!x?!1:(u.get(x)!==void 0&&x.parent&&x.parent.removeChild(x),u.set(x,T||0),R(T||0).addChild(x),!0)},removeEmissive(x){if(u.has(x)){u.delete(x);for(const T of d?.emissive.values()||[])x.parent===T&&T.removeChild(x)}},isNight:gt,lightsAt(x,T,L,A=1,I=null){return gt()?y.lightsAt(x,T,L,A,I):[]},onScreen(x,T,L,A){if(!r||!a?.screen)return!1;const I=s?s.camera():ht(r,a);if(!I)return!1;const K=Re(x,T,L,I,r,o);return as(K.screenX,K.screenY,A*K.scale*r.scale.x,a.screen.width,a.screen.height)},setCaster(x,T){e&&(T?_.set(x,T):_.delete(x))},castsShadows(){const x=i.shafts;return gt()&&!!(x?.enabled&&x.shadows&&x.maxShadowCasters>0)},render(){if(!gt()||!r||!a)return;const x=s?s.camera():ht(r,a),T=a.screen;if(!x||!T)return;const L=Q.shared.lastTime,A=v;A!==null&&A.tick===L&&A.x===r.position.x&&A.y===r.position.y&&A.scaleX===r.scale.x&&A.scaleY===r.scale.y&&A.width===T.width&&A.height===T.height&&!b&&w===(n?n.version:null)||(v={tick:L,x:r.position.x,y:r.position.y,scaleX:r.scale.x,scaleY:r.scale.y,width:T.width,height:T.height},It(),E(),Bt(),Nt(x,T,L),s&&ot(x),Ht(x,L))},clear:B}}function xh({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 yh(){const i=new Set;return{subscribe(t){return i.add(t),()=>{i.delete(t)}},exploded(t){for(const e of i)e(t)}}}function wh(){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}=Te(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 vh=(i,t)=>t>=Math.min(i.from,i.to)&&t<=Math.max(i.from,i.to),ks=(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},gn=(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 Mh(i,t,e,s){const n=xn(i,t,e,s);return n?ks(n,n.axis===0?e:s):null}function xn(i,t,e,s){return Array.isArray(i)?i.find(n=>vh(n,t)&&gn(n,e,s))??null:null}function Sh(i,t,e,s){const n=xn(i,t,e,s);return n?{height:ks(n,n.axis===0?e:s),axis:n.axis}:null}function bh(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||!gn(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:ks(u,c?l:h)-t}}return null}const kh=[[0,-1],[0,1],[-1,0],[1,0]],Lh={id:"tanks",engineApi:zn,requires:["map.layers","map.levelsN","map.gameData","map.bodyState"],async createClientCore(i,{wasmUrl:t}){if($l(t)){const s=await Kl(t);return{core:new s.ClientCore(i),memory:null}}const e=await Dn({module_or_path:t});return{core:new ns(i),memory:e.memory}},parts:Ll,bakers:Gl,styles:Vn,serviceNames:["levelView","mapDynamics","rampRuns","surfaces","volumes","lighting","shots","blasts"],hooks:{services(i){const t=Zl(),e=wh(),s=gh(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:xh({segments:(h,u,c,_,f,p)=>i.shot_segments(h,u,c,_,f,p)}),blasts:yh(),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 Mh(r(),h,u,c)},slopeAt(h,u,c){return Sh(r(),h,u,c)},faceAt(h,u,c,_,f,p){return bh(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 kh[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{Lh as default};
|