screeps-client 0.2.0 → 0.2.1

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.
Files changed (49) hide show
  1. package/dist/embedded/assets/CodePanel-kZMDxJko.js +1 -0
  2. package/dist/embedded/assets/MapViewer-DNoUiB29.js +1 -0
  3. package/dist/embedded/assets/index-Dy8WKdu-.js +4 -0
  4. package/dist/embedded/assets/vendor-codemirror-BbK0dVBs.js +24 -0
  5. package/dist/embedded/assets/vendor-pixi-c1qrZX58.js +906 -0
  6. package/dist/embedded/index.html +3 -1
  7. package/dist/standalone/assets/CodePanel-p80_iKqu.js +1 -0
  8. package/dist/standalone/assets/MapViewer-CHW78LaK.js +1 -0
  9. package/dist/standalone/assets/index-p9z9vEY_.js +4 -0
  10. package/dist/standalone/assets/vendor-codemirror-BbK0dVBs.js +24 -0
  11. package/dist/standalone/assets/vendor-pixi-CqiKBxHw.js +906 -0
  12. package/dist/standalone/index.html +3 -1
  13. package/dist/xxscreeps-mod/assets/CodePanel-DjI4Md1t.js +1 -0
  14. package/dist/xxscreeps-mod/assets/MapViewer-D66NMczX.js +1 -0
  15. package/dist/xxscreeps-mod/assets/index-BKZ4Y5Yn.js +4 -0
  16. package/dist/xxscreeps-mod/assets/vendor-codemirror-BbK0dVBs.js +24 -0
  17. package/dist/xxscreeps-mod/assets/vendor-pixi-CqiKBxHw.js +906 -0
  18. package/dist/xxscreeps-mod/index.html +3 -1
  19. package/package.json +1 -1
  20. package/dist/embedded/assets/BufferResource-BaQPK-V7.js +0 -185
  21. package/dist/embedded/assets/CanvasRenderer-PSblDCb7.js +0 -1
  22. package/dist/embedded/assets/Filter-D4pZOpc_.js +0 -1
  23. package/dist/embedded/assets/RenderTargetSystem-RBdRUxEE.js +0 -184
  24. package/dist/embedded/assets/WebGLRenderer-B8_Hqbp3.js +0 -156
  25. package/dist/embedded/assets/WebGPURenderer-DRt8eJ5g.js +0 -41
  26. package/dist/embedded/assets/browserAll-BDwT5mR2.js +0 -14
  27. package/dist/embedded/assets/canvasUtils-BYjxCPau.js +0 -1
  28. package/dist/embedded/assets/index-Pf1rCDHu.js +0 -274
  29. package/dist/embedded/assets/webworkerAll-D81v1dCp.js +0 -83
  30. package/dist/standalone/assets/BufferResource-C7cuPJ_p.js +0 -185
  31. package/dist/standalone/assets/CanvasRenderer-QY3I2Ik-.js +0 -1
  32. package/dist/standalone/assets/Filter-Ciqmecbs.js +0 -1
  33. package/dist/standalone/assets/RenderTargetSystem-l6SPJ7_m.js +0 -184
  34. package/dist/standalone/assets/WebGLRenderer-uPjAJqZs.js +0 -156
  35. package/dist/standalone/assets/WebGPURenderer-n9UczIr_.js +0 -41
  36. package/dist/standalone/assets/browserAll-D_MMKcyh.js +0 -14
  37. package/dist/standalone/assets/canvasUtils-BThzuUuN.js +0 -1
  38. package/dist/standalone/assets/index-B6UNpeEn.js +0 -274
  39. package/dist/standalone/assets/webworkerAll-B0QfJus3.js +0 -83
  40. package/dist/xxscreeps-mod/assets/BufferResource-CE78HmbQ.js +0 -185
  41. package/dist/xxscreeps-mod/assets/CanvasRenderer-BH4PjMGX.js +0 -1
  42. package/dist/xxscreeps-mod/assets/Filter-ZZPoYeTC.js +0 -1
  43. package/dist/xxscreeps-mod/assets/RenderTargetSystem-EVgeaEAK.js +0 -184
  44. package/dist/xxscreeps-mod/assets/WebGLRenderer-DDvszQ53.js +0 -156
  45. package/dist/xxscreeps-mod/assets/WebGPURenderer-UUnYdUOg.js +0 -41
  46. package/dist/xxscreeps-mod/assets/browserAll-CppuWcbH.js +0 -14
  47. package/dist/xxscreeps-mod/assets/canvasUtils-Dmy9CrII.js +0 -1
  48. package/dist/xxscreeps-mod/assets/index-CINA8e_Z.js +0 -274
  49. package/dist/xxscreeps-mod/assets/webworkerAll-D7azZfkM.js +0 -83
@@ -0,0 +1 @@
1
+ import{f as E,e as w,j as r,s as c,u as ee,g as te,t as u,h as oe}from"./index-Dy8WKdu-.js";import{l as f,e as ie,g as ne,c as re,r as le,h as P,f as b,j as $,F as R,S as j,n as se,E as de}from"./vendor-codemirror-BbK0dVBs.js";import"./vendor-pixi-c1qrZX58.js";var ae=u("<span style=font-size:11px;color:#e3b341>Unsaved changes"),ce=u('<div style="padding:12px 10px;font-size:12px;color:#484f58;font-style:italic">Loading…'),fe=u("<div style=flex:1;display:flex;align-items:center;justify-content:center;color:#484f58;font-size:13px;font-style:italic>"),ue=u('<div style=position:absolute;inset:0px;background:#0d1117;z-index:100;display:flex;flex-direction:column;overflow:hidden><div style="display:flex;align-items:center;gap:12px;padding:10px 16px;border-bottom:1px solid #30363d;flex-shrink:0"><span style=font-size:15px;font-weight:600;color:#c9d1d9>Code</span><select style="background:#010409;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:4px 8px;font-size:12px;cursor:pointer"></select><div style=flex:1></div><button style="padding:5px 14px;border-radius:4px;border:1px solid #238636;font-size:12px;font-weight:600"></button><button style="background:transparent;border:none;color:#8b949e;font-size:18px;cursor:pointer;line-height:1;padding:2px 6px">✕</button></div><div style=flex:1;display:flex;overflow:hidden><div style="width:180px;flex-shrink:0;border-right:1px solid #21262d;display:flex;flex-direction:column;overflow:hidden"><div style="padding:6px 10px;font-size:10px;font-weight:700;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;border-bottom:1px solid #21262d;flex-shrink:0">Modules</div><div style=flex:1;overflow:auto></div></div><div style=flex:1;display:flex;flex-direction:column;overflow:hidden><div style="padding:5px 14px;font-size:12px;color:#8b949e;border-bottom:1px solid #21262d;flex-shrink:0;font-family:monospace;background:#0d1117">.js</div><div style=flex:1;overflow:hidden;flex-direction:column>'),pe=u("<option>"),xe=u('<div style="padding:7px 12px;font-size:12px;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis">');const{error:L}=te("code"),ve=de.theme({"&":{height:"100%"},".cm-scroller":{"font-family":"'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace","font-size":"13px","line-height":"1.6",overflow:"auto"},".cm-gutters":{background:"#0d1117","border-right":"1px solid #21262d"},".cm-lineNumbers .cm-gutterElement":{color:"#484f58","min-width":"3em"},".cm-activeLineGutter":{background:"#161b22"},".cm-activeLine":{background:"#161b22"}}),he=[re,se(),le,ve];function ye(W){const[A,G]=f([]),[k,F]=f(""),[m,S]=f({}),[s,C]=f(""),[_,M]=f(!1),[p,B]=f(!1),[x,z]=f(!1),J=()=>Object.keys(m()),{editorView:U,ref:q,createExtension:H}=ie({onValueChange:o=>{const t=s();!t||m()[t]===o||(S(n=>({...n,[t]:o})),z(!0))}});ne(U,()=>m()[s()]??""),H(he),P(()=>{const o=E();o&&o.http.user.branches().then(t=>{G(t.list);const n=t.list.find(d=>d.activeWorld)??t.list[0];n&&F(n.branch)}).catch(t=>{L("branches failed:",t),w("Failed to load branches","error")})}),P(()=>{const o=k(),t=E();!o||!t||(M(!0),S({}),C(""),z(!1),t.http.user.code.get(o).then(n=>{const d=n.modules??{};S(d),C(Object.keys(d)[0]??"")}).catch(n=>{L("get failed:",n),w("Failed to load code","error")}).finally(()=>M(!1)))});const I=()=>{const o=E(),t=k();!o||!t||(B(!0),o.http.user.code.set(t,m()).then(()=>{w("Code saved","success"),z(!1)}).catch(n=>{L("set failed:",n),w("Failed to save code","error")}).finally(()=>B(!1)))};return(()=>{var o=ue(),t=o.firstChild,n=t.firstChild,d=n.nextSibling,K=d.nextSibling,a=K.nextSibling,Q=a.nextSibling,X=t.nextSibling,V=X.firstChild,Y=V.firstChild,T=Y.nextSibling,D=V.nextSibling,y=D.firstChild,Z=y.firstChild,N=y.nextSibling;return d.addEventListener("change",e=>F(e.currentTarget.value)),r(d,b(R,{get each(){return A()},children:e=>(()=>{var i=pe();return r(i,()=>e.branch,null),r(i,()=>e.activeWorld?" ★":"",null),$(()=>i.value=e.branch),i})()})),r(t,b(j,{get when(){return x()},get children(){return ae()}}),a),a.$$click=I,r(a,()=>p()?"Saving…":"Save"),Q.$$click=()=>W.onClose(),r(T,b(j,{get when(){return _()},get children(){return ce()}}),null),r(T,b(R,{get each(){return J()},children:e=>(()=>{var i=xe();return i.$$click=()=>C(e),r(i,e),$(l=>{var v=s()===e?"#1f3158":"transparent",h=s()===e?"#58a6ff":"#c9d1d9",g=`2px solid ${s()===e?"#388bfd":"transparent"}`;return v!==l.e&&c(i,"background",l.e=v),h!==l.t&&c(i,"color",l.t=h),g!==l.a&&c(i,"border-left",l.a=g),l},{e:void 0,t:void 0,a:void 0}),i})()}),null),r(y,s,Z),ee(q,N),r(D,b(j,{get when(){return!s()},get children(){var e=fe();return r(e,()=>_()?"Loading code…":"Select a module"),e}}),null),$(e=>{var i=p()||_()||!x(),l=p()||!x()?"#161b22":"#1a3a2a",v=p()||!x()?"#484f58":"#3fb950",h=p()||!x()?"default":"pointer",g=s()?"block":"none",O=s()?"flex":"none";return i!==e.e&&(a.disabled=e.e=i),l!==e.t&&c(a,"background",e.t=l),v!==e.a&&c(a,"color",e.a=v),h!==e.o&&c(a,"cursor",e.o=h),g!==e.i&&c(y,"display",e.i=g),O!==e.n&&c(N,"display",e.n=O),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),$(()=>d.value=k()),o})()}oe(["click"]);export{ye as CodePanel};
@@ -0,0 +1 @@
1
+ var ce=Object.defineProperty;var he=(a,t,e)=>t in a?ce(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var w=(a,t,e)=>he(a,typeof t!="symbol"?t+"":t,e);import{B as de,d as me,c as fe,E as ue,O as we,a as ie,b as se,p as O,T as ge,i as U,g as oe,f as I,o as be,w as X,n as ye,m as ve,l as Re,q,u as xe,k as pe,t as Se}from"./index-Dy8WKdu-.js";import{l as V,h as D,q as Ce,p as H}from"./vendor-codemirror-BbK0dVBs.js";import{A as Me,a as F,G as Y,c as $,S as J,T as j}from"./vendor-pixi-c1qrZX58.js";const ne="screeps-terrain-v1";async function Le(a,t,e){try{const o=await caches.open(ne),i=`/terrain/${a}_${t}_z${e}.webp`,s=new Request(i),n=await o.match(s);if(n)return await n.blob()}catch{}return null}async function Oe(a,t,e,o){try{const i=await caches.open(ne),s=`/terrain/${a}_${t}_z${e}.webp`,n=new Request(s),r=new Response(o);await i.put(n,r)}catch{}}async function Be(a){const t=new OffscreenCanvas(a.width,a.height),e=t.getContext("2d");if(!e)throw new Error("OffscreenCanvas 2D context not available");return e.drawImage(a,0,0),await t.convertToBlob({type:"image/webp"})}async function ke(a){return await createImageBitmap(a)}function Te(a){return new Worker("/client/assets/terrain.worker-D9zNeJfz.js",{name:a==null?void 0:a.name})}const{warn:De}=oe("MapRenderer"),ae=3,f=ae*50,Ee=[50,60,70,80,90,100,110],G=1,z=50,Ae=2600,_e=5,Q=.2,ee=5,Ie=ue,Ge=we,Ye=ie,Xe=se,He=4491519,$e=new Set(["w","r","pb","p","s","c","m","k"]),ze={H:13421772,O:13421772,U:5809919,L:4176208,K:10711543,Z:13801762,X:16273737},Ne=[16,24,32,40];class Ze{constructor(t){w(this,"app");w(this,"world");w(this,"boundsGraphics",null);w(this,"selectionGraphics",null);w(this,"safeModeGraphics",null);w(this,"safeModeRooms",new Set);w(this,"activeRooms",new Map);w(this,"roomPool",[]);w(this,"terrainBaked",new Set);w(this,"terrainData",new Map);w(this,"worker");w(this,"pendingBakes",new Map);w(this,"nextBakeId",0);w(this,"currentShard","shard0");w(this,"callbacks");w(this,"resizeObserver",null);w(this,"_destroyed",!1);w(this,"showRoomNames",!1);w(this,"worldBoundsSet",null);w(this,"lastVisibleBounds",null);w(this,"animTargetX",0);w(this,"animTargetY",0);w(this,"isAnimating",!1);w(this,"overlayMode","owner");w(this,"isDragging",!1);w(this,"hasDragged",!1);w(this,"dragStartX",0);w(this,"dragStartY",0);w(this,"dragWorldX",0);w(this,"dragWorldY",0);w(this,"lastVisibleKey","");w(this,"visibleDebounceTimer",null);w(this,"selectedRoom",null);w(this,"currentUserId",null);w(this,"badgeCache",new de);w(this,"lastCheckX",0);w(this,"lastCheckY",0);w(this,"lastCheckScale",0);this.app=new Me,this.callbacks=t,this.worker=new Te,this.worker.onmessage=e=>{const{id:o,bitmap:i}=e.data,s=this.pendingBakes.get(o);s&&(this.pendingBakes.delete(o),s.resolve(i))}}async init(t){const e=t.parentElement??t,{width:o,height:i}=e.getBoundingClientRect();await this.app.init({canvas:t,width:o,height:i,background:me,antialias:!1,preference:"webgl"}),this.resizeObserver=new ResizeObserver(s=>{const{width:n,height:r}=s[0].contentRect,d=this.app.screen.width,h=this.app.screen.height;this.app.renderer.resize(n,r),this.world.x+=(n-d)/2,this.world.y+=(r-h)/2}),this.resizeObserver.observe(e),this.world=new F,this.app.stage.addChild(this.world),this.boundsGraphics=new Y,this.world.addChild(this.boundsGraphics),this.selectionGraphics=new Y,this.world.addChild(this.selectionGraphics),this.safeModeGraphics=new Y,this.world.addChild(this.safeModeGraphics),this.setupInteraction(),this.app.ticker.add(()=>{if(this.isAnimating){const s=this.animTargetX-this.world.x,n=this.animTargetY-this.world.y;Math.abs(s)<.5&&Math.abs(n)<.5?(this.world.x=this.animTargetX,this.world.y=this.animTargetY,this.isAnimating=!1):(this.world.x+=s*.2,this.world.y+=n*.2)}this.checkVisibleRooms()})}get zoom(){var t;return((t=this.world)==null?void 0:t.scale.x)??1}setZoom(t){var h,y;if(!this.world)return;t=Math.max(Q,Math.min(ee,t));const e=this.world.scale.x;if(t===e)return;const o=this.app.screen.width/2,i=this.app.screen.height/2,s=(o-this.world.x)/e,n=(i-this.world.y)/e,r=this.getLOD(),d=this.zoom>=G;this.world.scale.set(t),this.world.x=o-s*t,this.world.y=i-n*t,this.getLOD()!==r&&this.applyLOD(),t>=G!==d&&this.updateAllNameLabels(),this.updateAllRoomScales(t),(y=(h=this.callbacks).onZoomChanged)==null||y.call(h,t),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode()}centerOn(t,e,o=!1){const i=t*f+f/2,s=e*f+f/2,n=this.world.scale.x,r=this.app.screen.width/2-i*n,d=this.app.screen.height/2-s*n;o?(this.animTargetX=r,this.animTargetY=d,this.isAnimating=!0):(this.isAnimating=!1,this.world.x=r,this.world.y=d)}async getTerrainBitmap(t,e,o){const i=this.currentShard;try{const s=await Le(i,t,e);if(s)return await ke(s);const n=this.nextBakeId++,r=new Promise((h,y)=>{this.pendingBakes.set(n,{roomName:t,lod:e,resolve:h,reject:y})});this.worker.postMessage({id:n,roomName:t,lod:e,raw:o});const d=await r;return Be(d).then(h=>{Oe(i,t,e,h)}).catch(h=>De("failed to save to terrainCache:",h)),d}catch{return null}}async setRoomTerrain(t,e){const o=e.raw;let i=!1;for(let h=0;h<o.length;h++)if(o[h]!==0){i=!0;break}if(!i){this.terrainBaked.add(t);return}const s=this.getOrCreate(t),n=this.getLOD();n===0&&this.terrainData.set(t,o);const r=await this.getTerrainBitmap(t,n,o);if(!r)return;if(!this.activeRooms.has(t)){r.close();return}const d=$.from(r);n===0?(s.texLo&&!s.texLo.destroyed&&s.texLo.destroy(!0),s.texLo=d,this.getLOD()===0&&s.texLo&&(s.terrainSprite.texture=s.texLo)):(s.texHi&&!s.texHi.destroyed&&s.texHi.destroy(!0),s.texHi=d,this.getLOD()===1&&s.texHi&&(s.terrainSprite.texture=s.texHi)),s.terrainSprite.width=f,s.terrainSprite.height=f,this.terrainBaked.add(t)}getLOD(){return this.zoom<G?0:1}async applyLOD(){const t=this.getLOD()===1,e=[];for(const[o,i]of this.activeRooms)if(this.terrainBaked.has(o))if(t&&!i.texHi){const s=this.terrainData.get(o);s&&(this.terrainData.delete(o),e.push(this.getTerrainBitmap(o,1,s).then(n=>{n&&this.activeRooms.has(o)?(i.texHi=$.from(n),this.getLOD()===1&&(i.terrainSprite.texture=i.texHi)):n&&n.close()})))}else{const s=t?i.texHi:i.texLo;s&&!s.destroyed&&(i.terrainSprite.texture=s)}await Promise.all(e)}setRoomMap2(t,e,o="live"){const s=this.getOrCreate(t).map2Graphics;s.alpha=o==="cache"?.6:1;const n=ae;s.clear();const r=e.r??[];for(const[R,v]of r)s.rect(R*n,v*n,n,n);r.length&&s.fill(fe);const d=e.w??[];for(const[R,v]of d)s.rect(R*n+.5,v*n+.5,n-1,n-1);d.length&&s.fill(4486980);const h=e.s??[];for(const[R,v]of h)s.circle((R+.5)*n,(v+.5)*n,2.5);h.length&&s.fill(Ie);const y=e.c??[];for(const[R,v]of y)s.circle((R+.5)*n,(v+.5)*n,2);y.length&&s.fill(Ge);const p=e.m??[];for(const[R,v]of p)s.circle((R+.5)*n,(v+.5)*n,2);p.length&&s.fill(Ye);const S=e.k??[];for(const[R,v]of S)s.circle((R+.5)*n,(v+.5)*n,2);S.length&&s.fill(Xe);const B=e.pb??[];for(const[R,v]of B)s.circle((R+.5)*n,(v+.5)*n,1.5);B.length&&s.fill(se);const k=e;for(const R in k){if($e.has(R))continue;const v=k[R];if(!Array.isArray(v)||v.length===0)continue;for(const[W,E]of v)s.circle((W+.5)*n,(E+.5)*n,1);const Z=R===this.currentUserId?He:16711680;s.fill(Z)}}clearRoomMap2(t){var e;(e=this.activeRooms.get(t))==null||e.map2Graphics.clear()}clearAllMap2(){for(const t of this.activeRooms.values())t.map2Graphics.clear()}setRoomOwned(t,e){const i=this.getOrCreate(t).ownerOverlay;i.clear(),e&&(i.rect(0,0,f,f),i.fill({color:10027008,alpha:.18}))}async setRoomBadge(t,e,o){const i=this.activeRooms.get(t);if(i){if(!e){i.badgeSprite&&(i.container.removeChild(i.badgeSprite),i.badgeSprite.destroy(),i.badgeSprite=void 0),i.badgeLevel=void 0;return}try{const s=await this.badgeCache.getOrCreate(e);if(!this.activeRooms.has(t))return;if(i.badgeSprite){if(i.badgeSprite.texture===s){i.badgeLevel=o,this.applyBadgeSize(i,this.zoom),this.applyOverlayMode(i);return}i.badgeSprite.texture=s}else{const n=new J(s);n.anchor.set(.5),n.x=f/2,n.y=f/2;const r=i.container.getChildIndex(i.nameLabel);i.container.addChildAt(n,r),i.badgeSprite=n}i.badgeLevel=o,this.applyBadgeSize(i,this.zoom),this.applyOverlayMode(i)}catch{}}}applyBadgeSize(t,e){if(!t.badgeSprite||t.badgeLevel===void 0)return;const i=(Ee[t.badgeLevel-1]??24)*Math.min(1,e);t.badgeSprite.width=i/e,t.badgeSprite.height=i/e}setOverlayMode(t){if(this.overlayMode!==t){this.overlayMode=t;for(const e of this.activeRooms.values())this.applyOverlayMode(e)}}setRoomMineral(t,e,o){const i=this.activeRooms.get(t);if(!i)return;if(!e||!o){i.mineralCircle&&(i.container.removeChild(i.mineralCircle),i.mineralCircle.destroy(),i.mineralCircle=void 0),i.mineralLabel&&(i.container.removeChild(i.mineralLabel),i.mineralLabel.destroy(),i.mineralLabel=void 0),i.mineralDensity=void 0;return}const s=ze[e]??ie;if(i.mineralDensity=o,i.mineralColor=s,!i.mineralCircle){const n=new Y;n.x=f/2,n.y=f/2;const r=i.container.getChildIndex(i.nameLabel);i.container.addChildAt(n,r),i.mineralCircle=n}if(i.mineralLabel)i.mineralLabel.text=e;else{const n=new j({text:e,style:{fontSize:36,fill:16777215,fontFamily:"ui-monospace, monospace",fontWeight:"bold"}});n.anchor.set(.5),n.x=f/2,n.y=f/2,i.container.addChild(n),i.mineralLabel=n}this.applyMineralSize(i,this.zoom),this.applyOverlayMode(i)}applyOverlayMode(t){t.badgeSprite&&(t.badgeSprite.visible=this.overlayMode==="owner"),t.mineralCircle&&(t.mineralCircle.visible=this.overlayMode==="mineral"),t.mineralLabel&&(t.mineralLabel.visible=this.overlayMode==="mineral")}applyMineralSize(t,e){if(!t.mineralCircle||!t.mineralLabel||t.mineralDensity===void 0||t.mineralColor===void 0)return;const o=Math.max(.5,Math.min(1.5,e)),i=(Ne[t.mineralDensity-1]??24)*o,s=i/2/e;t.mineralCircle.clear(),t.mineralCircle.circle(0,0,1),t.mineralCircle.fill(t.mineralColor);const r=2/e;t.mineralCircle.stroke({color:0,width:r/s}),t.mineralCircle.scale.set(s);const h=i*.55/36/e;t.mineralLabel.scale.set(h)}updateNameLabelScale(t,e){t.nameLabel.scale.set(.5/e)}updateAllRoomScales(t){for(const e of this.activeRooms.values())this.applyBadgeSize(e,t),this.updateNameLabelScale(e,t),this.applyMineralSize(e,t)}setCurrentUser(t){this.currentUserId=t}setSelectedRoom(t){if(this.selectedRoom=t,!this.selectionGraphics||(this.selectionGraphics.clear(),this.world.removeChild(this.selectionGraphics),this.world.addChild(this.selectionGraphics),!t))return;const e=O(t);if(!e)return;const o=e.x*f,i=e.y*f;this.selectionGraphics.rect(o,i,f,f);const s=Math.max(2,Math.ceil(2/this.zoom));this.selectionGraphics.stroke({color:16777215,width:s,alignment:0})}setRoomSafeMode(t,e){e?this.safeModeRooms.add(t):this.safeModeRooms.delete(t),this.redrawSafeMode()}redrawSafeMode(){if(!this.safeModeGraphics||(this.safeModeGraphics.clear(),this.safeModeRooms.size===0))return;const t=Math.max(1,Math.ceil(1/this.zoom));for(const e of this.safeModeRooms){const o=O(e);if(!o)continue;const i=o.x*f,s=o.y*f;this.safeModeGraphics.rect(i,s,f,f),this.safeModeGraphics.stroke({color:16776960,width:t,alignment:1,alpha:.5})}this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)}setBounds(t,e,o,i){if(!this.boundsGraphics)return;this.worldBoundsSet={minX:t,maxX:e,minY:o,maxY:i},this.boundsGraphics.clear();const s=t*f,n=o*f,r=(e-t+1)*f,d=(i-o+1)*f;this.boundsGraphics.rect(s,n,r,d),this.boundsGraphics.stroke({color:ge,width:6,alignment:0}),this.updateAllNameLabels()}clearBounds(){var t;this.worldBoundsSet=null,(t=this.boundsGraphics)==null||t.clear(),this.updateAllNameLabels()}setShowRoomNames(t){this.showRoomNames=t,this.updateAllNameLabels()}hasRoom(t){return this.terrainBaked.has(t)}clearRoom(t){const e=this.activeRooms.get(t);e&&(e.texLo&&!e.texLo.destroyed&&e.texLo.destroy(!0),e.texHi&&!e.texHi.destroyed&&e.texHi.destroy(!0),e.texLo=null,e.texHi=null,e.terrainSprite.texture=$.EMPTY,e.map2Graphics.clear(),e.ownerOverlay.clear(),e.badgeSprite&&(e.container.removeChild(e.badgeSprite),e.badgeSprite.destroy(),e.badgeSprite=void 0),e.mineralCircle&&(e.container.removeChild(e.mineralCircle),e.mineralCircle.destroy(),e.mineralCircle=void 0),e.mineralLabel&&(e.container.removeChild(e.mineralLabel),e.mineralLabel.destroy(),e.mineralLabel=void 0),e.mineralDensity=void 0,e.mineralColor=void 0,e.container.visible=!1,this.safeModeRooms.delete(t),this.terrainBaked.delete(t),this.terrainData.delete(t),this.activeRooms.delete(t),this.roomPool.length<Ae?this.roomPool.push(e):(this.world.removeChild(e.container),e.container.destroy({children:!0,context:!0})))}clearInvisibleRooms(t){const e=this.lastVisibleBounds;for(const o of[...this.activeRooms.keys()])if(!t.has(o)){if(e){const i=O(o);if(i&&i.x>=e.rxMin-z&&i.x<=e.rxMax+z&&i.y>=e.ryMin-z&&i.y<=e.ryMax+z)continue}this.clearRoom(o)}}destroy(){var t;if(!this._destroyed){this._destroyed=!0,(t=this.resizeObserver)==null||t.disconnect(),this.resizeObserver=null,this.visibleDebounceTimer!==null&&(clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=null);for(const[,e]of this.activeRooms)e.texLo&&!e.texLo.destroyed&&e.texLo.destroy(!0),e.texHi&&!e.texHi.destroyed&&e.texHi.destroy(!0);this.activeRooms.clear(),this.safeModeRooms.clear();for(const e of this.roomPool)e.texLo&&!e.texLo.destroyed&&e.texLo.destroy(!0),e.texHi&&!e.texHi.destroyed&&e.texHi.destroy(!0);this.roomPool.length=0,this.terrainBaked.clear(),this.terrainData.clear(),this.worker.terminate(),this.pendingBakes.clear(),this.badgeCache.destroy();try{this.app.destroy(!1,{children:!0,texture:!0,context:!0})}catch{}}}getOrCreate(t){const e=this.activeRooms.get(t);if(e)return e;const o=O(t);if(!o)throw new Error(`MapRenderer: invalid room "${t}"`);let i;if(this.roomPool.length>0)i=this.roomPool.pop();else{const s=new F;s.cullable=!0;const n=new J($.EMPTY),r=new Y,d=new Y;s.addChild(n),s.addChild(r),s.addChild(d);const h=new j({text:"",style:{fontSize:36,fill:9147550,fontFamily:"ui-monospace, monospace"}});h.scale.set(.25),h.x=2,h.y=2,s.addChild(h),this.world.addChild(s),i={container:s,terrainSprite:n,texLo:null,texHi:null,map2Graphics:r,ownerOverlay:d,nameLabel:h}}return i.container.x=o.x*f,i.container.y=o.y*f,i.container.visible=!0,i.nameLabel.text=t,i.nameLabel.visible=this.showRoomNames&&this.zoom>=G&&this.nameLabelShouldShow(o.x,o.y),this.updateNameLabelScale(i,this.zoom),i.badgeSprite&&(i.container.removeChild(i.badgeSprite),i.badgeSprite.destroy(),i.badgeSprite=void 0),i.mineralCircle&&(i.container.removeChild(i.mineralCircle),i.mineralCircle.destroy(),i.mineralCircle=void 0),i.mineralLabel&&(i.container.removeChild(i.mineralLabel),i.mineralLabel.destroy(),i.mineralLabel=void 0),i.mineralDensity=void 0,i.mineralColor=void 0,this.safeModeGraphics&&(this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)),this.selectionGraphics&&(this.world.removeChild(this.selectionGraphics),this.world.addChild(this.selectionGraphics)),this.activeRooms.set(t,i),i}nameLabelShouldShow(t,e){const o=this.worldBoundsSet;return!(o&&(t<o.minX||t>o.maxX||e<o.minY||e>o.maxY))}updateAllNameLabels(){const t=this.showRoomNames&&this.zoom>=G;for(const[e,o]of this.activeRooms){if(!t){o.nameLabel.visible=!1;continue}const i=O(e);i&&(o.nameLabel.visible=this.nameLabelShouldShow(i.x,i.y))}}setupInteraction(){const t=this.app.canvas;t.style.touchAction="none",t.style.userSelect="none",t.addEventListener("pointermove",e=>{if(this.isDragging)return;const o=t.getBoundingClientRect();this.emitHover(e.clientX-o.left,e.clientY-o.top)}),t.addEventListener("pointerleave",()=>{this.isDragging||this.callbacks.onRoomHover(null)}),t.addEventListener("pointerdown",e=>{e.preventDefault(),this.isAnimating=!1,this.isDragging=!0,this.hasDragged=!1,this.dragStartX=e.clientX,this.dragStartY=e.clientY,this.dragWorldX=this.world.x,this.dragWorldY=this.world.y;const o=n=>{const r=n.clientX-this.dragStartX,d=n.clientY-this.dragStartY;(Math.abs(r)>3||Math.abs(d)>3)&&(this.hasDragged=!0);const h=this.worldBoundsSet;if(h){const y=this.world.scale.x,p=50,S=p-(h.maxX+1)*f*y,B=this.app.screen.width-p-h.minX*f*y,k=p-(h.maxY+1)*f*y,R=this.app.screen.height-p-h.minY*f*y;this.world.x=this.rubberBand(this.dragWorldX+r,S,B),this.world.y=this.rubberBand(this.dragWorldY+d,k,R)}else this.world.x=this.dragWorldX+r,this.world.y=this.dragWorldY+d},i=n=>{if(!this.hasDragged){const r=t.getBoundingClientRect(),d=this.screenToRoom(n.clientX-r.left,n.clientY-r.top);d&&this.callbacks.onRoomClick(d)}s()},s=()=>{this.isDragging=!1,this.springBack(),window.removeEventListener("pointermove",o),window.removeEventListener("pointerup",i),window.removeEventListener("pointercancel",s)};window.addEventListener("pointermove",o),window.addEventListener("pointerup",i),window.addEventListener("pointercancel",s)}),t.addEventListener("wheel",e=>{var y,p;if(e.preventDefault(),this.isDragging)return;this.isAnimating=!1;const o=this.world.scale.x,i=e.deltaY<0?1.1:.9,s=Math.max(Q,Math.min(ee,o*i)),n=(e.offsetX-this.world.x)/o,r=(e.offsetY-this.world.y)/o,d=this.getLOD(),h=this.zoom>=G;this.world.scale.set(s),this.world.x=e.offsetX-n*s,this.world.y=e.offsetY-r*s,this.getLOD()!==d&&this.applyLOD(),s>=G!==h&&this.updateAllNameLabels(),this.updateAllRoomScales(s),(p=(y=this.callbacks).onZoomChanged)==null||p.call(y,s),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode()},{passive:!1})}rubberBand(t,e,o){const i=o-e;if(i<=0||t>=e&&t<=o)return t;const s=.55;if(t<e){const r=e-t;return e-(1-1/(r*s/i+1))*i*s}const n=t-o;return o+(1-1/(n*s/i+1))*i*s}springBack(){const t=this.worldBoundsSet;if(!t)return;const e=this.world.scale.x,o=this.app.screen.width,i=this.app.screen.height,s=50,n=this.world.x+t.minX*f*e,r=this.world.x+(t.maxX+1)*f*e,d=this.world.y+t.minY*f*e,h=this.world.y+(t.maxY+1)*f*e;let y=this.world.x,p=this.world.y;r<s?y+=s-r:n>o-s&&(y-=n-(o-s)),h<s?p+=s-h:d>i-s&&(p-=d-(i-s)),(y!==this.world.x||p!==this.world.y)&&(this.animTargetX=y,this.animTargetY=p,this.isAnimating=!0)}screenToRoom(t,e){const o=this.world.scale.x,i=(t-this.world.x)/o,s=(e-this.world.y)/o,n=Math.floor(i/f),r=Math.floor(s/f);return U(n,r)}emitHover(t,e){this.callbacks.onRoomHover(this.screenToRoom(t,e))}checkVisibleRooms(){const t=this.world.scale.x,e=this.world.x,o=this.world.y;if(this.lastCheckX===e&&this.lastCheckY===o&&this.lastCheckScale===t)return;this.lastCheckX=e,this.lastCheckY=o,this.lastCheckScale=t;const i=-e/t,s=-o/t,n=(this.app.screen.width-e)/t,r=(this.app.screen.height-o)/t,d=Math.floor(i/f)-1,h=Math.ceil(n/f),y=Math.floor(s/f)-1,p=Math.ceil(r/f);this.lastVisibleBounds={rxMin:d,rxMax:h,ryMin:y,ryMax:p};const S=[];for(let k=d;k<=h;k++)for(let R=y;R<=p;R++){const v=U(k,R);v&&S.push(v)}const B=`${d},${y},${h},${p}`;B!==this.lastVisibleKey&&(this.lastVisibleKey=B,this.visibleDebounceTimer!==null&&clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=setTimeout(()=>{this.visibleDebounceTimer=null,this.callbacks.onVisibleRoomsChanged(S)},_e))}}var We=Se("<div style=width:100%;height:100%;position:relative><canvas style=display:block>");const{log:N,error:te}=oe("map");function qe(a){let t,e=null;const[o,i]=V([]),[s,n]=V(1),r=()=>a.originRoom,[d,h]=V(r()??null);let y=null,p=null;const S=new Map,B=new Map,k=new Map,R=l=>{const c=X();if(!c)return!0;const g=O(l);return!!g&&pe(g.x,g.y,c)},v=l=>{var g;const c=B.get(l);return{room:l,owner:(c==null?void 0:c.username)??((g=c==null?void 0:c.own)!=null&&g.user?`user:${c.own.user}`:null),mineral:(c==null?void 0:c.mineral)??null,density:(c==null?void 0:c.density)??null}},Z=200,W=0;let E=[],_=null;const K=()=>{_=null;const l=I();if(!l||!e)return;const c=new Set(o());if(E=E.filter(m=>c.has(m)&&!e.hasRoom(m)),E.length===0)return;const g=E.splice(0,Z);l.stores.room.terrainBulk(g,a.shard).then(m=>{for(const[u,b]of m)e==null||e.setRoomTerrain(u,b)}).catch(m=>te("terrain fetch failed:",m)).finally(()=>{E.length>0&&(_=setTimeout(K,W))})};return D(()=>{I(),a.shard,B.clear()}),Ce(()=>{t&&(async()=>{var c,g;if(e=new Ze({onRoomHover:m=>{var u;(u=a.onHoveredRoomChanged)==null||u.call(a,m?v(m):null)},onRoomClick:m=>{var u;d()!==m?(h(m),e==null||e.setSelectedRoom(m),(u=a.onSelectedRoomChanged)==null||u.call(a,v(m))):R(m)&&setTimeout(()=>a.onNavigateToRoom(m),0)},onVisibleRoomsChanged:m=>{const u=m.length===0;p!==u&&(p=u,u||N(`zoom in — terrain loading active, ${m.length} rooms visible`)),i(m)},onZoomChanged:m=>{var u;n(m),(u=a.onZoomChanged)==null||u.call(a,m)}}),await e.init(t),!e)return;a.initialZoom!==void 0&&a.initialZoom>0&&e.setZoom(a.initialZoom),(c=a.onZoomChanged)==null||c.call(a,e.zoom);const l=X();if(l&&e.setBounds(l.minX,l.maxX,l.minY,l.maxY),a.originRoom){const m=O(a.originRoom);m&&e.centerOn(m.x,m.y),e.setSelectedRoom(a.originRoom),(g=a.onSelectedRoomChanged)==null||g.call(a,v(a.originRoom))}else{const m=I();if(m)try{const u=await m.http.user.worldStartRoom(a.shard??"shard0");if(!e)return;const b=Array.isArray(u==null?void 0:u.room)?u.room[0]:u==null?void 0:u.room;if(typeof b=="string"){const x=O(b);x&&e.centerOn(x.x,x.y)}}catch(u){te("worldStartRoom failed:",u)}}})()}),H(()=>{_!==null&&(clearTimeout(_),_=null),E=[];for(const l of S.values())l.dispose();S.clear(),e==null||e.destroy(),e=null}),D(()=>{be({currentRoom:d,worldBounds:X,onMove:(g,m)=>{var b,x;const u=U(g,m);h(u),e==null||e.setSelectedRoom(u),e==null||e.centerOn(g,m,!0),(b=a.onSelectedRoomChanged)==null||b.call(a,v(u)),(x=a.onHoveredRoomChanged)==null||x.call(a,v(u))}});const c=g=>{var b,x;const m=((b=g.target)==null?void 0:b.tagName)??"",u=((x=g.target)==null?void 0:x.isContentEditable)??!1;if(!(m==="INPUT"||m==="TEXTAREA"||u)&&g.key==="m"){const C=d();C&&R(C)&&a.onNavigateToRoom(C)}};window.addEventListener("keydown",c),H(()=>window.removeEventListener("keydown",c))}),D(()=>{var x;const l=I(),c=o(),g=a.shard;if(!l||c.length===0)return;const m=new Set(c),u=c.filter(C=>!(e!=null&&e.hasRoom(C)));if(u.length>0){const C=c.reduce((T,A)=>{var L;return T+(((L=O(A))==null?void 0:L.x)??0)},0)/c.length,M=c.reduce((T,A)=>{var L;return T+(((L=O(A))==null?void 0:L.y)??0)},0)/c.length;E=u.slice().sort((T,A)=>{const L=O(T),P=O(A),re=L?Math.abs(L.x-C)+Math.abs(L.y-M):999,le=P?Math.abs(P.x-C)+Math.abs(P.y-M):999;return re-le}),_===null&&(_=setTimeout(K,0))}l.stores.mapStats.request(c,"owner0",g??void 0);const b=s()>=.4;if(b!==y&&(y=b,(x=a.onSubscriptionStateChanged)==null||x.call(a,b),b||e==null||e.clearAllMap2()),b){const C=new Set(c.map(M=>`${M}/${g}`));for(const[M,T]of S)C.has(M)||(T.dispose(),S.delete(M),e==null||e.clearRoomMap2(M.split("/")[0]));for(const M of c){const T=`${M}/${g}`;S.has(T)||S.set(T,l.stores.map.subscribeMap2(M,g))}}else{for(const[,C]of S)C.dispose();S.clear()}e==null||e.clearInvisibleRooms(m)}),D(()=>{e==null||e.setShowRoomNames(ye()),e&&(e.currentShard=a.shard??"shard0")}),D(()=>{e==null||e.setOverlayMode(ve())}),D(()=>{const l=I(),c=a.shard;l&&l.stores.server.worldInfo(c??void 0).then(g=>{N(`worldInfo(shard=${c??"none"}) — x: [${g.minX}, ${g.maxX}] y: [${g.minY}, ${g.maxY}]`),Re(g)}).catch(g=>{})}),D(()=>{var l;e==null||e.setCurrentUser(((l=q())==null?void 0:l._id)??null)}),D(()=>{const l=X();l?(e==null||e.setBounds(l.minX,l.maxX,l.minY,l.maxY),N(`worldBounds applied — shard: ${a.shard??"none"} x: [${l.minX}, ${l.maxX}] y: [${l.minY}, ${l.maxY}] (fetched for shard: ${l.shard??"none"})`)):(e==null||e.clearBounds(),N(`worldBounds — none (shard: ${a.shard??"none"})`))}),D(()=>{const l=I();if(!l)return;const c=l.stores.map.on("room:map2update",({room:g,shard:m,data:u,source:b})=>{m===a.shard&&(e==null||e.setRoomMap2(g,u,b))});H(()=>c.dispose())}),D(()=>{var u;const l=I();if(!l)return;const c=(u=q())==null?void 0:u._id,g=new Set(o()),m=l.stores.mapStats.on("mapStats:room",({room:b,stat:x})=>{var A,L;B.set(b,x);const C=!!(x.own&&x.own.user!==c);g.has(b)&&(e==null||e.setRoomOwned(b,C),e==null||e.setRoomSafeMode(b,!!x.safeMode)),e==null||e.setRoomMineral(b,x.mineral,x.density);const M=x.badge?JSON.stringify(x.badge):"";k.get(b)!==M&&(k.set(b,M),e==null||e.setRoomBadge(b,x.badge,(A=x.own)==null?void 0:A.level)),d()===b&&((L=a.onSelectedRoomChanged)==null||L.call(a,v(b)))});H(()=>m.dispose())}),(()=>{var l=We(),c=l.firstChild;return xe(g=>t=g,c),l})()}export{qe as MapViewer};
@@ -0,0 +1,4 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodePanel-kZMDxJko.js","assets/vendor-codemirror-BbK0dVBs.js","assets/vendor-pixi-c1qrZX58.js","assets/MapViewer-DNoUiB29.js"])))=>i.map(i=>d[i]);
2
+ var Un=Object.defineProperty;var Wn=(r,e,t)=>e in r?Un(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var y=(r,e,t)=>Wn(r,typeof e!="symbol"?e+"":e,t);import{k as Qs,j as F,i as kr,u as Qt,t as qn,s as pe,$ as Vn,l as R,f as M,S as q,F as fe,h as ue,p as $e,D as Xn,a as qe,d as Yn,b as ps,m as Tr,q as Lt,o as en}from"./vendor-codemirror-BbK0dVBs.js";import{a as Se,G as j,A as jn,P as yt,R as Zn,c as Kn,T as Mr,S as gs,b as Jn,C as Qn,_ as tn}from"./vendor-pixi-c1qrZX58.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))s(n);new MutationObserver(n=>{for(const i of n)if(i.type==="childList")for(const l of i.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&s(l)}).observe(document,{childList:!0,subtree:!0});function t(n){const i={};return n.integrity&&(i.integrity=n.integrity),n.referrerPolicy&&(i.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?i.credentials="include":n.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function s(n){if(n.ep)return;n.ep=!0;const i=t(n);fetch(n.href,i)}})();const ei=["allowfullscreen","async","alpha","autofocus","autoplay","checked","controls","default","disabled","formnovalidate","hidden","indeterminate","inert","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","seamless","selected","adauctionheaders","browsingtopics","credentialless","defaultchecked","defaultmuted","defaultselected","defer","disablepictureinpicture","disableremoteplayback","preservespitch","shadowrootclonable","shadowrootcustomelementregistry","shadowrootdelegatesfocus","shadowrootserializable","sharedstoragewritable"],ti=new Set(["className","value","readOnly","noValidate","formNoValidate","isMap","noModule","playsInline","adAuctionHeaders","allowFullscreen","browsingTopics","defaultChecked","defaultMuted","defaultSelected","disablePictureInPicture","disableRemotePlayback","preservesPitch","shadowRootClonable","shadowRootCustomElementRegistry","shadowRootDelegatesFocus","shadowRootSerializable","sharedStorageWritable",...ei]),ri=new Set(["innerHTML","textContent","innerText","children"]),si=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),ni=Object.assign(Object.create(null),{class:"className",novalidate:{$:"noValidate",FORM:1},formnovalidate:{$:"formNoValidate",BUTTON:1,INPUT:1},ismap:{$:"isMap",IMG:1},nomodule:{$:"noModule",SCRIPT:1},playsinline:{$:"playsInline",VIDEO:1},readonly:{$:"readOnly",INPUT:1,TEXTAREA:1},adauctionheaders:{$:"adAuctionHeaders",IFRAME:1},allowfullscreen:{$:"allowFullscreen",IFRAME:1},browsingtopics:{$:"browsingTopics",IMG:1},defaultchecked:{$:"defaultChecked",INPUT:1},defaultmuted:{$:"defaultMuted",AUDIO:1,VIDEO:1},defaultselected:{$:"defaultSelected",OPTION:1},disablepictureinpicture:{$:"disablePictureInPicture",VIDEO:1},disableremoteplayback:{$:"disableRemotePlayback",AUDIO:1,VIDEO:1},preservespitch:{$:"preservesPitch",AUDIO:1,VIDEO:1},shadowrootclonable:{$:"shadowRootClonable",TEMPLATE:1},shadowrootdelegatesfocus:{$:"shadowRootDelegatesFocus",TEMPLATE:1},shadowrootserializable:{$:"shadowRootSerializable",TEMPLATE:1},sharedstoragewritable:{$:"sharedStorageWritable",IFRAME:1,IMG:1}});function ii(r,e){const t=ni[r];return typeof t=="object"?t[e]?t.$:void 0:t}const oi=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),li=new Set(["altGlyph","altGlyphDef","altGlyphItem","animate","animateColor","animateMotion","animateTransform","circle","clipPath","color-profile","cursor","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","font","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignObject","g","glyph","glyphRef","hkern","image","line","linearGradient","marker","mask","metadata","missing-glyph","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","svg","switch","symbol","text","textPath","tref","tspan","use","view","vkern"]),ai={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},ne=r=>kr(()=>r());function ci(r,e,t){let s=t.length,n=e.length,i=s,l=0,o=0,a=e[n-1].nextSibling,c=null;for(;l<n||o<i;){if(e[l]===t[o]){l++,o++;continue}for(;e[n-1]===t[i-1];)n--,i--;if(n===l){const d=i<s?o?t[o-1].nextSibling:t[i-o]:a;for(;o<i;)r.insertBefore(t[o++],d)}else if(i===o)for(;l<n;)(!c||!c.has(e[l]))&&e[l].remove(),l++;else if(e[l]===t[i-1]&&t[o]===e[n-1]){const d=e[--n].nextSibling;r.insertBefore(t[o++],e[l++].nextSibling),r.insertBefore(t[--i],d),e[n]=t[i]}else{if(!c){c=new Map;let u=o;for(;u<i;)c.set(t[u],u++)}const d=c.get(e[l]);if(d!=null)if(o<d&&d<i){let u=l,h=1,f;for(;++u<n&&u<i&&!((f=c.get(e[u]))==null||f!==d+h);)h++;if(h>d-o){const p=e[l];for(;o<d;)r.insertBefore(t[o++],p)}else r.replaceChild(t[o++],e[l++])}else l++;else e[l++].remove()}}}const ms="_$DX_DELEGATE";function di(r,e,t,s={}){if(!e)throw new Error("The `element` passed to `render(..., element)` doesn't exist. Make sure `element` exists in the document.");let n;return Qs(i=>{n=i,e===document?r():m(e,r(),e.firstChild?null:void 0,t)},s.owner),()=>{n(),e.textContent=""}}function k(r,e,t,s){let n;const i=()=>{if(De())throw new Error("Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration.");const o=document.createElement("template");return o.innerHTML=r,o.content.firstChild},l=()=>(n||(n=i())).cloneNode(!0);return l.cloneNode=l,l}function be(r,e=window.document){const t=e[ms]||(e[ms]=new Set);for(let s=0,n=r.length;s<n;s++){const i=r[s];t.has(i)||(t.add(i),e.addEventListener(i,vi))}}function Er(r,e,t){De(r)||(t==null?r.removeAttribute(e):r.setAttribute(e,t))}function ui(r,e,t,s){De(r)||(s==null?r.removeAttributeNS(e,t):r.setAttributeNS(e,t,s))}function hi(r,e,t){De(r)||(t?r.setAttribute(e,""):r.removeAttribute(e))}function fi(r,e){De(r)||(e==null?r.removeAttribute("class"):r.className=e)}function er(r,e,t,s){if(s)Array.isArray(t)?(r[`$$${e}`]=t[0],r[`$$${e}Data`]=t[1]):r[`$$${e}`]=t;else if(Array.isArray(t)){const n=t[0];r.addEventListener(e,t[0]=i=>n.call(r,t[1],i))}else r.addEventListener(e,t,typeof t!="function"&&t)}function pi(r,e,t={}){const s=Object.keys(e||{}),n=Object.keys(t);let i,l;for(i=0,l=n.length;i<l;i++){const o=n[i];!o||o==="undefined"||e[o]||(ys(r,o,!1),delete t[o])}for(i=0,l=s.length;i<l;i++){const o=s[i],a=!!e[o];!o||o==="undefined"||t[o]===a||!a||(ys(r,o,!0),t[o]=a)}return t}function de(r,e,t){if(!e)return t?Er(r,"style"):e;const s=r.style;if(typeof e=="string")return s.cssText=e;typeof t=="string"&&(s.cssText=t=void 0),t||(t={}),e||(e={});let n,i;for(i in t)e[i]==null&&s.removeProperty(i),delete t[i];for(i in e)n=e[i],n!==t[i]&&(s.setProperty(i,n),t[i]=n);return t}function W(r,e,t){t!=null?r.style.setProperty(e,t):r.style.removeProperty(e)}function gi(r,e={},t,s){const n={};return F(()=>n.children=Pt(r,e.children,n.children)),F(()=>typeof e.ref=="function"&&Mt(e.ref,r)),F(()=>mi(r,e,t,!0,n,!0)),n}function Mt(r,e,t){return Qt(()=>r(e,t))}function m(r,e,t,s){if(t!==void 0&&!s&&(s=[]),typeof e!="function")return Pt(r,e,s,t);F(n=>Pt(r,e(),n,t),s)}function mi(r,e,t,s,n={},i=!1){e||(e={});for(const l in n)if(!(l in e)){if(l==="children")continue;n[l]=ws(r,l,null,n[l],t,i,e)}for(const l in e){if(l==="children")continue;const o=e[l];n[l]=ws(r,l,o,n[l],t,i,e)}}function yi(r){let e,t,s=De();if(!s||!(e=pe.registry.get(t=bi()))){if(s)throw pe.done=!0,new Error(`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${t}
3
+ `);return r()}return pe.completed&&pe.completed.add(e),pe.registry.delete(t),e}function De(r){return!!pe.context&&!pe.done&&(!r||r.isConnected)}function wi(r){return r.toLowerCase().replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function ys(r,e,t){const s=e.trim().split(/\s+/);for(let n=0,i=s.length;n<i;n++)r.classList.toggle(s[n],t)}function ws(r,e,t,s,n,i,l){let o,a,c,d,u;if(e==="style")return de(r,t,s);if(e==="classList")return pi(r,t,s);if(t===s)return s;if(e==="ref")i||t(r);else if(e.slice(0,3)==="on:"){const h=e.slice(3);s&&r.removeEventListener(h,s,typeof s!="function"&&s),t&&r.addEventListener(h,t,typeof t!="function"&&t)}else if(e.slice(0,10)==="oncapture:"){const h=e.slice(10);s&&r.removeEventListener(h,s,!0),t&&r.addEventListener(h,t,!0)}else if(e.slice(0,2)==="on"){const h=e.slice(2).toLowerCase(),f=oi.has(h);if(!f&&s){const p=Array.isArray(s)?s[0]:s;r.removeEventListener(h,p)}(f||t)&&(er(r,h,t,f),f&&be([h]))}else if(e.slice(0,5)==="attr:")Er(r,e.slice(5),t);else if(e.slice(0,5)==="bool:")hi(r,e.slice(5),t);else if((u=e.slice(0,5)==="prop:")||(c=ri.has(e))||!n&&((d=ii(e,r.tagName))||(a=ti.has(e)))||(o=r.nodeName.includes("-")||"is"in l)){if(u)e=e.slice(5),a=!0;else if(De(r))return t;e==="class"||e==="className"?fi(r,t):o&&!a&&!c?r[wi(e)]=t:r[d||e]=t}else{const h=n&&e.indexOf(":")>-1&&ai[e.split(":")[0]];h?ui(r,h,e,t):Er(r,si[e]||e,t)}return t}function vi(r){if(pe.registry&&pe.events&&pe.events.find(([a,c])=>c===r))return;let e=r.target;const t=`$$${r.type}`,s=r.target,n=r.currentTarget,i=a=>Object.defineProperty(r,"target",{configurable:!0,value:a}),l=()=>{const a=e[t];if(a&&!e.disabled){const c=e[`${t}Data`];if(c!==void 0?a.call(e,c,r):a.call(e,r),r.cancelBubble)return}return e.host&&typeof e.host!="string"&&!e.host._$host&&e.contains(r.target)&&i(e.host),!0},o=()=>{for(;l()&&(e=e._$host||e.parentNode||e.host););};if(Object.defineProperty(r,"currentTarget",{configurable:!0,get(){return e||document}}),pe.registry&&!pe.done&&(pe.done=_$HY.done=!0),r.composedPath){const a=r.composedPath();i(a[0]);for(let c=0;c<a.length-2&&(e=a[c],!!l());c++){if(e._$host){e=e._$host,o();break}if(e.parentNode===n)break}}else o();i(s)}function Pt(r,e,t,s,n){const i=De(r);if(i){!t&&(t=[...r.childNodes]);let a=[];for(let c=0;c<t.length;c++){const d=t[c];d.nodeType===8&&d.data.slice(0,2)==="!$"?d.remove():a.push(d)}t=a}for(;typeof t=="function";)t=t();if(e===t)return t;const l=typeof e,o=s!==void 0;if(r=o&&t[0]&&t[0].parentNode||r,l==="string"||l==="number"){if(i||l==="number"&&(e=e.toString(),e===t))return t;if(o){let a=t[0];a&&a.nodeType===3?a.data!==e&&(a.data=e):a=document.createTextNode(e),t=je(r,t,s,a)}else t!==""&&typeof t=="string"?t=r.firstChild.data=e:t=r.textContent=e}else if(e==null||l==="boolean"){if(i)return t;t=je(r,t,s)}else{if(l==="function")return F(()=>{let a=e();for(;typeof a=="function";)a=a();t=Pt(r,a,t,s)}),()=>t;if(Array.isArray(e)){const a=[],c=t&&Array.isArray(t);if(Pr(a,e,t,n))return F(()=>t=Pt(r,a,t,s,!0)),()=>t;if(i){if(!a.length)return t;if(s===void 0)return t=[...r.childNodes];let d=a[0];if(d.parentNode!==r)return t;const u=[d];for(;(d=d.nextSibling)!==s;)u.push(d);return t=u}if(a.length===0){if(t=je(r,t,s),o)return t}else c?t.length===0?vs(r,a,s):ci(r,t,a):(t&&je(r),vs(r,a));t=a}else if(e.nodeType){if(i&&e.parentNode)return t=o?[e]:e;if(Array.isArray(t)){if(o)return t=je(r,t,s,e);je(r,t,null,e)}else t==null||t===""||!r.firstChild?r.appendChild(e):r.replaceChild(e,r.firstChild);t=e}else console.warn("Unrecognized value. Skipped inserting",e)}return t}function Pr(r,e,t,s){let n=!1;for(let i=0,l=e.length;i<l;i++){let o=e[i],a=t&&t[r.length],c;if(!(o==null||o===!0||o===!1))if((c=typeof o)=="object"&&o.nodeType)r.push(o);else if(Array.isArray(o))n=Pr(r,o,a)||n;else if(c==="function")if(s){for(;typeof o=="function";)o=o();n=Pr(r,Array.isArray(o)?o:[o],Array.isArray(a)?a:[a])||n}else r.push(o),n=!0;else{const d=String(o);a&&a.nodeType===3&&a.data===d?r.push(a):r.push(document.createTextNode(d))}}return n}function vs(r,e,t=null){for(let s=0,n=e.length;s<n;s++)r.insertBefore(e[s],t)}function je(r,e,t,s){if(t===void 0)return r.textContent="";const n=s||document.createTextNode("");if(e.length){let i=!1;for(let l=e.length-1;l>=0;l--){const o=e[l];if(n!==o){const a=o.parentNode===r;!i&&!l?a?r.replaceChild(n,o):r.insertBefore(n,t):a&&o.remove()}else i=!0}}else r.insertBefore(n,t);return[n]}function bi(){return pe.getNextContextId()}const xi="http://www.w3.org/2000/svg";function $i(r,e=!1,t=void 0){return e?document.createElementNS(xi,r):document.createElement(r,{is:t})}function _i(r,e){const t=kr(r);return kr(()=>{const s=t();switch(typeof s){case"function":return Object.assign(s,{[Vn]:!0}),Qt(()=>s(e));case"string":const n=li.has(s),i=pe.context?yi():$i(s,n,Qt(()=>e.is));return gi(i,e,n),i}})}function Si(r){const[,e]=qn(r,["component"]);return _i(()=>r.component,e)}async function rn(r,e){const t=r.slice(3),s=Uint8Array.from(atob(t),u=>u.charCodeAt(0)),n=new DecompressionStream(e),i=n.writable.getWriter();await i.write(s),await i.close();const l=n.readable.getReader(),o=[];try{for(;;){const{done:u,value:h}=await l.read();if(u)break;o.push(h)}}catch(u){throw l.cancel(),u}let a=0;for(const u of o)a+=u.length;const c=new Uint8Array(a);let d=0;for(const u of o)c.set(u,d),d+=u.length;return JSON.parse(new TextDecoder().decode(c))}function Ci(r){return rn(r,"gzip")}function ki(r){return rn(r,"deflate")}class Ee{constructor(e){y(this,"fn");this.fn=e}static create(e){return e===!0?new Ee(console.debug.bind(console)):typeof e=="function"?new Ee(e):new Ee(null)}child(e){if(!this.fn)return this;const t=this.fn;return new Ee((...s)=>t(`[screeps:${e}]`,...s))}log(...e){var t;(t=this.fn)==null||t.call(this,...e)}}function Ti(r){return{signin:(e,t)=>r.request("POST","/api/auth/signin",{email:e,password:t}),me:()=>r.request("GET","/api/auth/me"),queryToken:e=>r.request("GET","/api/auth/query-token",{token:e}),steamTicket:(e,t)=>r.request("POST","/api/auth/steam-ticket",{ticket:e,...t!=null?{useNativeAuth:t}:{}}),modInfo:()=>r.request("GET","/api/authmod")}}function Mi(r){return{list:()=>r.request("GET","/api/game/power-creeps/list"),create:(e,t)=>r.request("POST","/api/game/power-creeps/create",{name:e,className:t}),delete:e=>r.request("POST","/api/game/power-creeps/delete",{id:e}),cancelDelete:e=>r.request("POST","/api/game/power-creeps/cancel-delete",{id:e}),upgrade:(e,t)=>r.request("POST","/api/game/power-creeps/upgrade",{id:e,powers:t}),rename:(e,t)=>r.request("POST","/api/game/power-creeps/rename",{id:e,name:t}),experimentation:()=>r.request("POST","/api/game/power-creeps/experimentation")}}function ge(r,e){return e&&(r.shard=e),r}function Ei(r){return{roomTerrain:(e,t)=>r.request("GET","/api/game/room-terrain",ge({room:e,encoded:1},t)),roomObjects:(e,t)=>r.request("GET","/api/game/room-objects",ge({room:e},t)),roomStatus:(e,t)=>r.request("GET","/api/game/room-status",ge({room:e},t)),roomOverview:(e,t=8,s)=>r.request("GET","/api/game/room-overview",ge({room:e,interval:t},s)),time:e=>r.request("GET","/api/game/time",ge({},e)),worldSize:e=>r.request("GET","/api/game/world-size",ge({},e)),mapStats:(e,t,s)=>r.request("POST","/api/game/map-stats",ge({rooms:e,statName:t},s)),roomsTerrain:(e,t)=>{const s=new URLSearchParams({encoded:"true"});return t&&s.set("shard",t),r.request("POST",`/api/game/rooms?${s}`,{rooms:e})},createFlag:(e,t,s,n,i,l,o)=>r.request("POST","/api/game/create-flag",ge({room:e,x:t,y:s,name:n,color:i,secondaryColor:l},o)),genUniqueFlagName:()=>r.request("POST","/api/game/gen-unique-flag-name"),checkUniqueFlagName:e=>r.request("POST","/api/game/check-unique-flag-name",{name:e}),changeFlagColor:(e,t,s,n)=>r.request("POST","/api/game/change-flag-color",{room:e,name:t,color:s,secondaryColor:n}),removeFlag:(e,t)=>r.request("POST","/api/game/remove-flag",{room:e,name:t}),genUniqueObjectName:e=>r.request("POST","/api/game/gen-unique-object-name",{type:e}),checkUniqueObjectName:(e,t)=>r.request("POST","/api/game/check-unique-object-name",{type:e,name:t}),placeSpawn:(e,t,s,n,i)=>r.request("POST","/api/game/place-spawn",ge({room:e,x:t,y:s,...n?{name:n}:{}},i)),createConstruction:(e,t,s,n,i,l)=>r.request("POST","/api/game/create-construction",ge({room:e,x:t,y:s,structureType:n,...i?{name:i}:{}},l)),removeConstructionSite:(e,t,s)=>r.request("POST","/api/game/add-object-intent",ge({_id:"room",room:e,name:"removeConstructionSite",intent:t.map(n=>({id:n,roomName:e}))},s)),addObjectIntent:(e,t,s,n)=>r.request("POST","/api/game/add-object-intent",{_id:e,room:t,name:s,intent:n}),addGlobalIntent:(e,t)=>r.request("POST","/api/game/add-global-intent",{name:e,intent:t}),setNotifyWhenAttacked:(e,t)=>r.request("POST","/api/game/set-notify-when-attacked",{_id:e,enabled:t}),createInvader:(e,t,s,n,i,l)=>r.request("POST","/api/game/create-invader",{room:e,x:t,y:s,size:n,type:i,...l!=null?{boosted:l}:{}}),removeInvader:e=>r.request("POST","/api/game/remove-invader",{_id:e}),tick:()=>r.request("GET","/api/game/tick"),powerCreeps:Mi(r),market:{ordersIndex:e=>r.request("GET","/api/game/market/orders-index",ge({},e)),myOrders:()=>r.request("GET","/api/game/market/my-orders"),orders:(e,t)=>r.request("GET","/api/game/market/orders",ge({resourceType:e},t)),stats:(e,t)=>r.request("GET","/api/game/market/stats",ge({resourceType:e},t))},shards:{info:()=>r.request("GET","/api/game/shards/info")}}}function Pi(r){return{send:(e,t)=>r.request("POST","/api/user/messages/send",{respondent:e,text:t}),list:e=>r.request("GET","/api/user/messages/list",{respondent:e}),index:()=>r.request("GET","/api/user/messages/index"),markRead:e=>r.request("POST","/api/user/messages/mark-read",{id:e}),unreadCount:()=>r.request("GET","/api/user/messages/unread-count")}}function Ze(r,e){return e&&(r.shard=e),r}function Oi(r){return{branches:()=>r.request("GET","/api/user/branches"),code:{get:e=>r.request("GET","/api/user/code",e?{branch:e}:{}),set:(e,t)=>r.request("POST","/api/user/code",{branch:e,modules:t,_hash:Date.now()})},memory:{get:(e,t)=>r.request("GET","/api/user/memory",Ze({path:e},t)),set:(e,t,s)=>r.request("POST","/api/user/memory",Ze({path:e,value:t},s)),segment:{get:(e,t)=>r.request("GET","/api/user/memory-segment",Ze({segment:e},t)),set:(e,t,s)=>r.request("POST","/api/user/memory-segment",Ze({segment:e,data:t},s))}},console:(e,t)=>r.request("POST","/api/user/console",Ze({expression:e},t)),stats:e=>r.request("GET","/api/user/stats",{interval:e}),rooms:e=>r.request("GET","/api/user/rooms",{id:e}),overview:(e,t)=>r.request("GET","/api/user/overview",{interval:e,statName:t}),worldStatus:()=>r.request("GET","/api/user/world-status"),worldStartRoom:e=>r.request("GET","/api/user/world-start-room",Ze({},e)),find:e=>r.request("GET","/api/user/find",e),moneyHistory:e=>r.request("GET","/api/user/money-history",e!=null?{page:e}:{}),respawn:()=>r.request("POST","/api/user/respawn"),respawnProhibitedRooms:()=>r.request("GET","/api/user/respawn-prohibited-rooms"),badge:e=>r.request("POST","/api/user/badge",{badge:e}),setActiveBranch:(e,t)=>r.request("POST","/api/user/set-active-branch",{activeName:e,branch:t}),cloneBranch:(e,t,s)=>r.request("POST","/api/user/clone-branch",{newName:e,...t?{branch:t}:{},...s!=null?{defaultModules:s}:{}}),deleteBranch:e=>r.request("POST","/api/user/delete-branch",{branch:e}),notifyPrefs:e=>r.request("POST","/api/user/notify-prefs",e),tutorialDone:()=>r.request("POST","/api/user/tutorial-done"),email:e=>r.request("POST","/api/user/email",{email:e}),setSteamVisible:e=>r.request("POST","/api/user/set-steam-visible",{visible:e}),password:(e,t)=>r.request("POST","/api/user/password",{password:e,...t!=null?{oldPassword:t}:{}}),messages:Pi(r)}}function Ri(r){return{list:(e=10,t="world",s=0,n)=>r.request("GET","/api/leaderboard/list",{limit:e,mode:t,offset:s,season:n}),find:(e,t="world",s="")=>r.request("GET","/api/leaderboard/find",{username:e,mode:t,season:s}),seasons:()=>r.request("GET","/api/leaderboard/seasons")}}function Li(r){return{pvp:(e=100)=>r.request("GET","/api/experimental/pvp",{interval:e}),nukes:()=>r.request("GET","/api/experimental/nukes")}}function Ai(r){return{checkEmail:e=>r.request("GET","/api/register/check-email",{email:e}),checkUsername:e=>r.request("GET","/api/register/check-username",{username:e}),setUsername:(e,t)=>r.request("POST","/api/register/set-username",{username:e,...t!=null?{email:t}:{}}),submit:(e,t,s,n)=>r.request("POST","/api/register/submit",{username:e,email:t,password:s,...n!=null?{modules:n}:{}})}}class Ii extends EventTarget{constructor(t){super();y(this,"baseUrl");y(this,"authStrategy");y(this,"logger");y(this,"serverPassword");y(this,"token",null);y(this,"rateLimits",new Map);y(this,"authenticating",!1);y(this,"auth");y(this,"register");y(this,"game");y(this,"user");y(this,"leaderboard");y(this,"experimental");this.baseUrl=t.url.endsWith("/")?t.url:`${t.url}/`,this.authStrategy=t.auth,this.logger=t.logger??Ee.create(),this.serverPassword=t.serverPassword??null,this.auth=Ti(this),this.register=Ai(this),this.game=Ei(this),this.user=Oi(this),this.leaderboard=Ri(this),this.experimental=Li(this)}emit(t,s){this.dispatchEvent(new CustomEvent(t,{detail:s}))}on(t,s){const n=i=>s(i.detail);return this.addEventListener(t,n),{dispose:()=>{this.removeEventListener(t,n)}}}async authenticate(){this.logger.log("authenticate"),this.authenticating=!0;try{this.token=await this.authStrategy.authenticate(this),this.logger.log("authenticated")}finally{this.authenticating=!1}}setToken(t){this.token=t}async request(t,s,n,i=!1){this.logger.log(t,s);const l=new URL(s.startsWith("/")?s.slice(1):s,this.baseUrl),o={};this.token&&(o["X-Token"]=this.token,o["X-Username"]=this.token),this.serverPassword&&(o["X-Server-Password"]=this.serverPassword);const a={method:t,headers:o};if(t==="GET"&&n)for(const[h,f]of Object.entries(n))f!=null&&l.searchParams.set(h,String(f));else n&&(o["Content-Type"]="application/json",a.body=JSON.stringify(n));const c=await fetch(l.toString(),a),d=c.headers.get("x-token");if(d&&(this.token=d,this.emit("http:tokenRefresh",{token:d})),this.updateRateLimit(s,c),c.status===401&&!i&&!this.authenticating)return await this.authenticate(),this.request(t,s,n,!0);if(!c.ok){let h="";try{h=await c.text()}catch{}const f=new Error(`HTTP ${c.status}: ${h}`);throw this.emit("http:error",{method:t,path:s,status:c.status,error:f}),f}this.emit("http:success",{method:t,path:s,status:c.status});const u=await c.json();if(typeof u.error=="string"){const h=new Error(`Screeps API error: ${u.error}`);throw this.emit("http:error",{method:t,path:s,status:c.status,error:h}),h}return typeof u.data=="string"&&u.data.startsWith("gz:")&&(u.data=await Ci(u.data)),u}updateRateLimit(t,s){const n=s.headers.get("x-ratelimit-limit"),i=s.headers.get("x-ratelimit-remaining"),l=s.headers.get("x-ratelimit-reset");n&&i&&l&&this.rateLimits.set(t,{limit:parseInt(n,10),remaining:parseInt(i,10),reset:parseInt(l,10)})}}async function Gi(r){let e=typeof r=="string"?r:r.data;if(e.startsWith("gz:")&&(e=JSON.stringify(await ki(e))),e.startsWith("[")){const[n,i]=JSON.parse(e);return{kind:"channel",message:{channel:n,data:i}}}const[t,...s]=e.split(" ");switch(t){case"auth":return{kind:"server",command:{type:"auth",status:s[0],token:s[1]}};case"time":return{kind:"server",command:{type:"time",time:parseInt(s[0],10)}};case"protocol":return{kind:"server",command:{type:"protocol",protocol:parseInt(s[0],10)}};case"package":return{kind:"server",command:{type:"package",package:parseInt(s[0],10)}};default:throw new Error(`Unknown server command: ${t}`)}}class Ni{constructor(e){y(this,"wsUrl");y(this,"WS");y(this,"logger");y(this,"ws",null);y(this,"token",null);y(this,"authed",!1);y(this,"_connected",!1);y(this,"reconnecting",!1);y(this,"authSub",null);y(this,"queue",[]);y(this,"subs",new Map);y(this,"listeners",new Map);y(this,"MAX_RETRIES",10);y(this,"MAX_DELAY_MS",6e4);y(this,"_intentionalClose",!1);const t=e.url.replace(/^http/,"ws").replace(/\/$/,"");this.wsUrl=`${t}/socket/websocket`,this.WS=e.WebSocket??globalThis.WebSocket,this.logger=e.logger??Ee.create()}get isConnected(){return this._connected}setToken(e){this.token=e}connect(e){var t;return this.logger.log("connect",this.wsUrl),this.reconnecting||(this._intentionalClose=!1),this.token=e,(t=this.authSub)==null||t.dispose(),this.authSub=null,new Promise((s,n)=>{this.ws=new this.WS(this.wsUrl),this.ws.onopen=()=>{this.logger.log("WebSocket opened"),this._connected=!0,this.reconnecting=!1,this.rawSend(`auth ${this.token}`),this.authSub=this.once("auth",i=>{const l=i;if(l.status==="ok"){for(this.logger.log("auth ok"),this.authed=!0,l.token&&(this.token=l.token,this.emit("socket:tokenRefresh",{token:l.token}));this.queue.length;)this.rawSend(this.queue.shift());this.emit("connected",{}),s()}else this.logger.log("auth failed"),n(new Error("WebSocket auth failed"))})},this.ws.onclose=()=>{var i;this.logger.log("WebSocket closed"),this._connected=!1,this.authed=!1,(i=this.authSub)==null||i.dispose(),this.authSub=null,this.emit("disconnected",{willReconnect:this.reconnecting}),this.scheduleReconnect()},this.ws.onerror=i=>{this._connected||n(i)},this.ws.onmessage=i=>{this.handleMessage(i).catch(l=>{this.logger.log("message parse error",l),this.emit("socket:error",l instanceof Error?l:new Error(String(l)))})}})}disconnect(){var e;this.logger.log("disconnect"),this._intentionalClose=!0,this.reconnecting=!1,(e=this.ws)==null||e.close(),this.ws=null,this._connected=!1,this.authed=!1,this.queue.length=0}activeSubs(){return Array.from(this.subs.entries()).map(([e,t])=>`${e}(${t})`).join(", ")||"(none)"}subscribe(e){const t=this.subs.get(e)??0;return this.subs.set(e,t+1),t===0?(this.logger.log("subscribe",e,"active:",this.activeSubs()),this.sendOrQueue(`subscribe ${e}`)):this.logger.log("subscribe",e,`(refs: ${t+1})`,"active:",this.activeSubs()),{dispose:()=>this.doUnsubscribe(e)}}on(e,t){let s=this.listeners.get(e);return s||(s=new Set,this.listeners.set(e,s)),s.add(t),{dispose:()=>{var n;(n=this.listeners.get(e))==null||n.delete(t)}}}once(e,t){const s=this.on(e,n=>{s.dispose(),t(n)});return s}doUnsubscribe(e){const t=this.subs.get(e)??0;t<=1?(this.subs.delete(e),this.authed&&this.rawSend(`unsubscribe ${e}`),this.logger.log("unsubscribe",e,"active:",this.activeSubs())):(this.subs.set(e,t-1),this.logger.log("unsubscribe",e,`(refs: ${t-1})`,"active:",this.activeSubs()))}rawSend(e){var t;(t=this.ws)==null||t.send(e)}sendOrQueue(e){this.authed?this.rawSend(e):this.queue.push(e)}emit(e,t){var s;(s=this.listeners.get(e))==null||s.forEach(n=>n(t))}async handleMessage(e){const t=await Gi(e);t.kind==="server"?this.emit(t.command.type,t.command):this.emit(t.message.channel,t.message.data)}async scheduleReconnect(){var t;if(this.reconnecting||this._intentionalClose)return;if(!this.token){this.reconnecting=!1;return}this.reconnecting=!0;let e=0;for(;e<this.MAX_RETRIES&&this.reconnecting&&!this._intentionalClose;){const s=Math.min(Math.pow(2,e)*100,this.MAX_DELAY_MS);if(this.logger.log(`reconnect attempt ${e+1}/${this.MAX_RETRIES} in ${s}ms`),await new Promise(n=>setTimeout(n,s)),!this.reconnecting||this._intentionalClose)return;try{if(await this.connect(this.token),this._intentionalClose){(t=this.ws)==null||t.close(),this.ws=null;return}for(const n of this.subs.keys())this.rawSend(`subscribe ${n}`);return}catch{e++}}this.reconnecting=!1,e>=this.MAX_RETRIES&&!this._intentionalClose&&this.emit("socket:error",new Error(`WebSocket reconnection failed after ${this.MAX_RETRIES} retries`))}}class Di{constructor(e,t){y(this,"memory",new Map);y(this,"storage");y(this,"namespace");this.namespace=e,this.storage=t}memKey(e){return`${this.namespace}/${e}`}get(e){const t=this.memory.get(this.memKey(e));if(t){if(t.expires!==void 0&&Date.now()>t.expires){this.memory.delete(this.memKey(e));return}return t.data}}set(e,t,s){this.memory.set(this.memKey(e),{data:t,expires:s!==void 0?Date.now()+s:void 0})}delete(e){this.memory.delete(this.memKey(e))}async getPersistent(e){return this.storage?this.storage.get(`${this.namespace}/${e}`):null}async setPersistent(e,t){this.storage&&await this.storage.set(`${this.namespace}/${e}`,t)}async deletePersistent(e){this.storage&&await this.storage.delete(`${this.namespace}/${e}`)}clearMemory(){this.memory.clear()}async clearPersistent(){this.storage&&await this.storage.clear()}async clearAll(){this.clearMemory(),await this.clearPersistent()}}class ht extends EventTarget{constructor(t){super();y(this,"logger");this.logger=t??Ee.create()}emit(t,s){this.dispatchEvent(new CustomEvent(t,{detail:s}))}on(t,s){this.logger.log(`on "${t}"`);const n=i=>s(i.detail);return this.addEventListener(t,n),{dispose:()=>{this.logger.log(`off "${t}"`),this.removeEventListener(t,n)}}}}var Pe=(r=>(r[r.Plain=0]="Plain",r[r.Wall=1]="Wall",r[r.Swamp=2]="Swamp",r))(Pe||{});class nt{constructor(e){y(this,"raw");this.raw=e}static fromEncodedString(e){const t=new Uint8Array(2500);for(let s=0;s<2500;s++){const n=parseInt(e[s],10);t[s]=n===3?1:n}return new nt(t)}get(e,t){return this.raw[t*50+e]}}class Fi extends ht{constructor(t,s,n,i){super(i);y(this,"http");y(this,"socket");y(this,"cache");y(this,"roomObjects",new Map);y(this,"roomUsers",new Map);y(this,"roomSubCount",new Map);y(this,"lastFlagsString",new Map);this.http=t,this.socket=s,this.cache=n}parseFlagsString(t,s){if(!t||t.length===0)return[];const n=[],i=t.split("|");for(const l of i){const o=l.split("~");if(o.length!==5)continue;const[a,c,d,u,h]=o,f=parseInt(c,10),p=parseInt(d,10),b=parseInt(u,10),_=parseInt(h,10);isNaN(f)||isNaN(p)||isNaN(b)||isNaN(_)||n.push({_id:a,type:"flag",room:s,name:a,x:b,y:_,color:f,secondaryColor:p})}return n}async terrain(t,s){const n=`terrain/${s}/${t}`,i=this.cache.get(n);if(i)return this.logger.log("terrain",t,s,"(memory cache hit)"),i;const l=await this.cache.getPersistent(n);if(l){this.logger.log("terrain",t,s,"(persistent cache hit)");const d=new nt(l);return this.cache.set(n,d),d}this.logger.log("terrain",t,s,"(fetching)");const a=(await this.http.game.roomTerrain(t,s??void 0)).terrain[0];if(!a)throw new Error(`No terrain data for room ${t} shard ${s}`);const c=nt.fromEncodedString(a.terrain);return this.cache.set(n,c),await this.cache.setPersistent(n,c.raw),this.emit("room:terrainavailable",{room:t,shard:s,terrain:c}),c}async terrainBulk(t,s){const n=new Map,i=[];for(const a of t){const c=this.cache.get(`terrain/${s}/${a}`);c?n.set(a,c):i.push(a)}if(i.length===0)return n;const l=[];if(await Promise.all(i.map(async a=>{const c=`terrain/${s}/${a}`,d=await this.cache.getPersistent(c);if(d){const u=new nt(d);this.cache.set(c,u),n.set(a,u)}else l.push(a)})),l.length===0)return n;this.logger.log("terrainBulk",`fetching ${l.length} rooms`,s);const o=await this.http.game.roomsTerrain(l,s??void 0);return await Promise.all(o.rooms.map(async a=>{const c=nt.fromEncodedString(a.terrain),d=`terrain/${s}/${a.room}`;this.cache.set(d,c),await this.cache.setPersistent(d,c.raw),this.emit("room:terrainavailable",{room:a.room,shard:s,terrain:c}),n.set(a.room,c)})),n}objects(t,s){const n=this.roomObjects.get(`${t}/${s}`);return n?{...n}:null}async fetchObjects(t,s){const n=`${t}/${s}`,i=await this.http.game.roomObjects(t,s??void 0),l={};for(const a of i.objects)a&&typeof a=="object"&&"_id"in a&&(l[a._id]=a);this.roomObjects.set(n,l);const o=this.roomUsers.get(n);this.emit("room:update",{room:t,shard:s,gameTime:void 0,objects:l,diff:l,visual:"",users:o})}activeRooms(){return Array.from(this.roomSubCount.entries()).map(([t,s])=>`${t}(${s})`).join(", ")||"(none)"}subscribe(t,s){const n=`${t}/${s}`,i=this.roomSubCount.get(n)??0;this.roomSubCount.set(n,i+1),this.logger.log("subscribe",t,s,`(refs: ${i+1})`,"active:",this.activeRooms());const l=s?`room:${s}/${t}`:`room:${t}`,o=s?`err@room:${s}/${t}`:`err@room:${t}`,a=this.socket.subscribe(l),c=this.socket.on(o,u=>{const h=typeof u=="string"?u:JSON.stringify(u);this.logger.log("room error",t,s,h),this.emit("room:error",{room:t,shard:s,message:h})}),d=this.socket.on(l,u=>{const h=u,f={...this.roomObjects.get(n)??{}};for(const[_,w]of Object.entries(h.objects))w===null?delete f[_]:f[_]?f[_]={...f[_],...w}:f[_]=w;const p={...h.objects};if("flags"in h){const _=h.flags??"",w=this.lastFlagsString.get(n)??"";if(_!==w){this.lastFlagsString.set(n,_);const C=this.parseFlagsString(_,t),E=new Map;for(const T of C)E.set(T.name,T);for(const T in f){const v=f[T];(v==null?void 0:v.type)==="flag"&&!E.has(T)&&(delete f[T],p[T]=null,this.logger.log(`[flag:room] removed ${T} @ ${t}`))}for(const[T,v]of E){const P=f[T];(!P||P.x!==v.x||P.y!==v.y||P.color!==v.color||P.secondaryColor!==v.secondaryColor)&&(f[T]=v,p[T]=v,this.logger.log(`[flag:room] ${P?"changed":"added"} ${T} @ ${t} (${v.x},${v.y})`))}}}h.users&&this.roomUsers.set(n,h.users),this.roomObjects.set(n,f);const b=this.roomUsers.get(n);this.emit("room:update",{room:t,shard:s,gameTime:h.gameTime,objects:f,diff:p,visual:h.visual??"",users:b})});return{dispose:()=>{a.dispose(),d.dispose(),c.dispose();const u=(this.roomSubCount.get(n)??1)-1;u<=0?(this.roomSubCount.delete(n),this.roomObjects.delete(n),this.lastFlagsString.delete(n),this.logger.log("unsubscribe",t,s,"(last ref)","active:",this.activeRooms())):(this.roomSubCount.set(n,u),this.logger.log("unsubscribe",t,s,`(refs: ${u})`,"active:",this.activeRooms()))}}}}class zi extends ht{constructor(t,s,n,i,l=100){super(i);y(this,"http");y(this,"socket");y(this,"cache");y(this,"console",[]);y(this,"maxConsoleSize");y(this,"_cpu",null);y(this,"_userInfo",null);y(this,"_userId",null);y(this,"_worldStatus",null);y(this,"_mePromise",null);this.http=t,this.socket=s,this.cache=n,this.maxConsoleSize=l}get cpu(){return this._cpu}get userInfo(){return this._userInfo}get userId(){return this._userId}get worldStatusValue(){return this._worldStatus}async me(){const t=this.cache.get("user/me");return t?(this._userId=t._id,this._userInfo=t,t):this._mePromise?this._mePromise:(this.logger.log("fetch me"),this._mePromise=this.http.auth.me().then(s=>{const n=s;return this._userId=n._id,this._userInfo=n,this.cache.set("user/me",n,6e4),this.emit("user:me",n),n}).finally(()=>{this._mePromise=null}),this._mePromise)}async refreshMe(){return this.logger.log("refresh me"),this.cache.delete("user/me"),this.me()}async worldStatus(){const t=this.cache.get("user/worldStatus");if(t)return this._worldStatus=t,t;this.logger.log("fetch world status");const s=await this.http.user.worldStatus();return this._worldStatus=s.status,this.cache.set("user/worldStatus",s.status,6e4),this.emit("user:worldStatus",{status:s.status}),s.status}async refreshWorldStatus(){return this.logger.log("refresh world status"),this.cache.delete("user/worldStatus"),this.worldStatus()}subscribe(t){this.logger.log("subscribe",t);let s=null,n=null,i=!1;return(async()=>{try{const o=this._userId??(await this.me())._id;if(i)return;const a=`user:${o}/${t}`;s=this.socket.subscribe(a),n=this.socket.on(a,c=>{var d,u,h;if(t==="cpu")this._cpu=c,this.emit("user:cpu",this._cpu);else if(t==="console"){const f=c,p={log:((d=f.messages)==null?void 0:d.log)??[],results:((u=f.messages)==null?void 0:u.results)??[],error:((h=f.messages)==null?void 0:h.error)??[]};f.error&&p.error.push(f.error),this.console.push(p),this.console.length>this.maxConsoleSize&&this.console.splice(0,this.console.length-this.maxConsoleSize),this.emit("user:console",{messages:p})}else t==="code"&&this.emit("user:code",c)})}catch(o){i||this.dispatchEvent(new ErrorEvent("error",{error:o instanceof Error?o:new Error(String(o))}))}})(),{dispose:()=>{this.logger.log("unsubscribe",t),i=!0,s==null||s.dispose(),n==null||n.dispose()}}}subscribeUserStream(){this.logger.log("subscribe user stream");let t=null,s=null,n=!1;return(async()=>{try{const l=this._userId??(await this.me())._id;if(n)return;const o=`user:${l}`;t=this.socket.subscribe(o),s=this.socket.on(o,a=>{const c=a;if(c&&typeof c=="object"&&"flags"in c){const d=c.flags;if(d&&typeof d=="object")for(const[u,h]of Object.entries(d)){const f=h;if(f&&typeof f=="object"){const p=f.room??"unknown",b=f.x??"?",_=f.y??"?";this.logger.log(`[flag:user] ${u} @ ${p} (${b},${_})`)}}}this.emit("user:stream",c)})}catch(l){n||this.dispatchEvent(new ErrorEvent("error",{error:l instanceof Error?l:new Error(String(l))}))}})(),{dispose:()=>{this.logger.log("unsubscribe user stream"),n=!0,t==null||t.dispose(),s==null||s.dispose()}}}}class Hi extends ht{constructor(t,s,n,i){super(i);y(this,"http");y(this,"cache");y(this,"socketSubs",[]);y(this,"_version",null);y(this,"_shards",null);this.http=t,this.cache=n,this.socketSubs.push(s.on("connected",()=>{this.emit("server:connected",{})})),this.socketSubs.push(s.on("disconnected",l=>{const o=l;this.emit("server:disconnected",{willReconnect:o.willReconnect})})),this.socketSubs.push(s.on("socket:error",l=>{this.emit("server:error",{error:l instanceof Error?l:new Error(String(l))})}))}get versionInfo(){return this._version}get isPrivateServer(){var t,s;return this._version?(((s=(t=this._version.serverData)==null?void 0:t.shards)==null?void 0:s.length)??0)===0:null}get shardList(){return this._shards}destroy(){for(const t of this.socketSubs)t.dispose();this.socketSubs.length=0}async version(){const t=this.cache.get("server/version");if(t)return t;const s=await this.http.request("GET","/api/version");return this._version=s,this.cache.set("server/version",s,5*6e4),this.emit("server:version",s),s}async refreshVersion(){return this.cache.delete("server/version"),this.version()}async shards(){const t=this.cache.get("server/shards");if(t)return t;const s=await this.http.request("GET","/api/game/shards/info");return this._shards=s.shards,this.cache.set("server/shards",s.shards,5*6e4),this.emit("server:shards",s.shards),s.shards}async refreshShards(){return this.cache.delete("server/shards"),this.shards()}async worldInfo(t){const n=`server/world/${t??"default"}`,i=this.cache.get(n);if(i)return i;const l={};t&&(l.shard=t);const o=await this.http.request("GET","/api/game/world-size",l),{width:a,height:c}=o;this.logger.log(`worldInfo shard=${t??"none"} — raw size: ${a}x${c}`);let d=-a,u=-1,h=-c,f=-1;try{const _=(await this.http.request("POST","/api/game/map-stats",{rooms:["W0N0","E0N0","W0S0","E0S0"],statName:"owner0",...l})).stats??{},w=["W0N0","E0N0","W0S0","E0S0"].filter(C=>C in _);this.logger.log(`worldInfo corner probe — found: [${w.length?w.join(", "):"none"}]`),("E0N0"in _||"E0S0"in _)&&(d=-Math.ceil(a/2),u=Math.floor(a/2)-1),("W0S0"in _||"E0S0"in _)&&(h=-Math.ceil(c/2),f=Math.floor(c/2)-1)}catch(b){this.logger.log("worldInfo corner probe failed — keeping W/N defaults:",b)}this.logger.log(`worldInfo computed bounds — x: [${d}, ${u}] y: [${h}, ${f}]`);const p={shard:t??null,width:a,height:c,minX:d,maxX:u,minY:h,maxY:f};return this.cache.set(n,p,10*6e4),p}invalidateWorldInfo(t){this.cache.delete(`server/world/${t??"default"}`)}}class Bi{constructor(e){y(this,"memory",new Map);y(this,"adapter");y(this,"maxEntries");y(this,"namespace");y(this,"accessSeq",0);this.adapter=e.adapter,this.maxEntries=e.maxEntries,this.namespace=e.namespace}key(e,t){return`${t??"_"}/${e}`}adapterKey(e){return`map2/${e}`}tick(){return++this.accessSeq}serialize(e){const t={data:e.data,lastSeen:e.lastSeen,lastAccess:e.lastAccess};return new TextEncoder().encode(JSON.stringify(t))}deserialize(e){try{return JSON.parse(new TextDecoder().decode(e))}catch{return null}}getMemory(e,t){const s=this.memory.get(this.key(e,t));return s?(s.lastAccess=this.tick(),s.data):null}async get(e,t){const s=this.getMemory(e,t);if(s)return s;if(!this.adapter)return null;const n=this.key(e,t),i=await this.adapter.get(this.adapterKey(n));if(!i)return null;const l=this.deserialize(i);return l?(this.memory.set(n,{data:l.data,lastSeen:l.lastSeen,lastAccess:this.tick()}),l.data):null}async put(e,t,s){const n=this.key(e,t),i={data:s,lastSeen:Date.now(),lastAccess:this.tick()};this.memory.set(n,i),await this.pruneIfNeeded(),this.adapter&&await this.adapter.set(this.adapterKey(n),this.serialize(i))}async pruneIfNeeded(){if(this.memory.size<=this.maxEntries)return;const t=[...this.memory.entries()].sort((s,n)=>s[1].lastAccess-n[1].lastAccess).slice(0,this.memory.size-this.maxEntries);for(const[s]of t)this.memory.delete(s),this.adapter&&await this.adapter.delete(this.adapterKey(s))}}function bs(r){const e=Object.keys(r).sort(),t={};for(const s of e){const n=r[s];t[s]=n?[...n].sort((i,l)=>i[0]-l[0]||i[1]-l[1]):null}return JSON.stringify(t)}class Ui extends ht{constructor(t,s,n={},i){super(i);y(this,"socket");y(this,"storage");y(this,"maxSubscriptions");y(this,"active",new Map);y(this,"waitlist",[]);y(this,"keyStates",new Map);y(this,"warnedAboutWaitlist",!1);this.socket=t,this.storage=s,this.maxSubscriptions=n.maxSubscriptions??500,this.socket.on("connected",()=>this.onReconnect())}map2data(t,s){return this.storage.getMemory(t,s)}subscribeMap2(t,s){const n=`${t}/${s}`,i=this.active.get(n);if(i){i.refCount++,this.logger.log("subscribeMap2",t,s,`(active, refs: ${i.refCount})`);const a=this.getOrCreateKeyState(n,"active");return this.emitWarmStart(t,s),this.makeSubscription(t,s,n,a)}const l=this.waitlist.find(a=>a.key===n);if(l){l.refCount++,this.logger.log("subscribeMap2",t,s,`(pending, refs: ${l.refCount})`);const a=this.getOrCreateKeyState(n,"pending");return this.emitWarmStart(t,s),this.makeSubscription(t,s,n,a)}if(this.active.size<this.maxSubscriptions){this.activateKey(t,s,n,1),this.logger.log("subscribeMap2",t,s,"(new active)");const a=this.getOrCreateKeyState(n,"active");return this.emit("room:map2state",{room:t,shard:s,status:"active"}),this.emitWarmStart(t,s),this.makeSubscription(t,s,n,a)}this.waitlist.push({key:n,room:t,shard:s,refCount:1}),this.logger.log("subscribeMap2",t,s,"(new pending)");const o=this.getOrCreateKeyState(n,"pending");return this.emit("room:map2state",{room:t,shard:s,status:"pending"}),this.emitWarmStart(t,s),this.warnedAboutWaitlist||(this.logger.log(`subscription limit (${this.maxSubscriptions}) reached — `,"some rooms are on a waitlist and will be promoted as slots free up."),this.warnedAboutWaitlist=!0),this.makeSubscription(t,s,n,o)}activateKey(t,s,n,i){const l=s?`roomMap2:${s}/${t}`:`roomMap2:${t}`,o=this.socket.subscribe(l),a=this.storage.getMemory(t,s),c={room:t,shard:s,refCount:i,socketSub:o,listenerSub:void 0,lastHash:a?bs(a):null};c.listenerSub=this.socket.on(l,d=>{const u=d,h=bs(u);c.lastHash!==h&&(c.lastHash=h,this.storage.put(t,s,u),this.emit("room:map2update",{room:t,shard:s,data:u,source:"live"}))}),this.active.set(n,c)}promoteNext(){const t=this.waitlist.shift();if(!t)return;this.activateKey(t.room,t.shard,t.key,t.refCount),this.logger.log("promoteNext",t.room,t.shard,"(promoted from waitlist)");const s=this.keyStates.get(t.key);s&&(s.status="active",s.statusHandlers.forEach(n=>n("active"))),this.emit("room:map2state",{room:t.room,shard:t.shard,status:"active"})}getOrCreateKeyState(t,s){let n=this.keyStates.get(t);return n||(n={status:s,statusHandlers:new Set},this.keyStates.set(t,n)),n}makeSubscription(t,s,n,i){let l=!1;return{status:()=>i.status,cachedData:()=>this.storage.getMemory(t,s),onStatusChange:o=>(i.statusHandlers.add(o),{dispose:()=>{i.statusHandlers.delete(o)}}),dispose:()=>{l||(l=!0,this.disposeSubscription(t,s,n))}}}disposeSubscription(t,s,n){const i=this.waitlist.findIndex(o=>o.key===n);if(i>=0){const o=this.waitlist[i];o.refCount--,this.logger.log("unsubscribeMap2",t,s,`(pending, refs: ${o.refCount})`),o.refCount<=0&&(this.waitlist.splice(i,1),this.keyStates.delete(n),this.logger.log("unsubscribeMap2",t,s,"(removed from waitlist)"));return}const l=this.active.get(n);l&&(l.refCount--,this.logger.log("unsubscribeMap2",t,s,`(active, refs: ${l.refCount})`),l.refCount<=0&&(l.socketSub.dispose(),l.listenerSub.dispose(),this.active.delete(n),this.keyStates.delete(n),this.logger.log("unsubscribeMap2",t,s,"(deactivated, promoting next)"),this.promoteNext()))}emitWarmStart(t,s){const n=`${t}/${s}`,i=this.storage.getMemory(t,s);i?queueMicrotask(()=>{this.isSubscribed(n)&&this.emit("room:map2update",{room:t,shard:s,data:i,source:"cache"})}):this.storage.get(t,s).then(l=>{l&&this.isSubscribed(n)&&this.emit("room:map2update",{room:t,shard:s,data:l,source:"cache"})})}onReconnect(){this.logger.log("onReconnect —",this.active.size,"active,",this.waitlist.length,"pending");for(const t of this.active.values())t.lastHash=null,this.emit("room:map2state",{room:t.room,shard:t.shard,status:"active"});for(const t of this.waitlist)this.emit("room:map2state",{room:t.room,shard:t.shard,status:"pending"})}isSubscribed(t){return this.active.has(t)||this.waitlist.some(s=>s.key===t)}}class Wi extends ht{constructor(t,s=100,n=500,i){super(i);y(this,"http");y(this,"debounceMs");y(this,"minIntervalMs");y(this,"pending",new Map);y(this,"timer",null);y(this,"lastFlushTime",0);this.http=t,this.debounceMs=s,this.minIntervalMs=n}request(t,s,n){if(t.length===0)return;const i=JSON.stringify([s,n??"shard0"]);let l=this.pending.get(i);l||(l={rooms:new Set,statName:s,shard:n??"shard0"},this.pending.set(i,l));for(const d of t)l.rooms.add(d);this.timer&&clearTimeout(this.timer);const a=Date.now()-this.lastFlushTime,c=Math.max(this.debounceMs,this.minIntervalMs-a);this.timer=setTimeout(()=>this.flush(),c)}async flush(){const t=new Map(this.pending);this.pending.clear(),this.timer=null,this.lastFlushTime=Date.now();for(const[,s]of t){const n=[...s.rooms];try{const i=await this.http.request("POST","/api/game/map-stats",{rooms:n,statName:s.statName,shard:s.shard}),l=i.users??{};for(const[o,a]of Object.entries(i.stats)){const c=this.buildData(a,l);this.emit("mapStats:room",{room:o,shard:s.shard==="shard0"?null:s.shard,stat:c})}for(const o of n)i.stats[o]||this.emit("mapStats:room",{room:o,shard:s.shard==="shard0"?null:s.shard,stat:{}})}catch(i){this.logger.log("mapStats fetch failed:",i)}}}buildData(t,s){var o,a,c;let n,i;for(let d=0;d<3;d++){const u=`minerals${d}`,h=t[u];if(h){n=h.type,i=h.density;break}}const l=(o=t.own)==null?void 0:o.user;return{own:t.own,mineral:n,density:i,username:l?(a=s[l])==null?void 0:a.username:void 0,safeMode:t.safeMode,badge:l?(c=s[l])==null?void 0:c.badge:void 0}}}class qi extends ht{constructor(t=50,s){super(s);y(this,"_history",[]);y(this,"_index",-1);y(this,"maxHistory");this.maxHistory=t}navigateTo(t,s){this._history=this._history.slice(0,this._index+1),this._history.push({room:t,shard:s}),this._history.length>this.maxHistory?this._history.shift():this._index++,this.emit("navigation:change",this.current())}back(){return this.canBack()?(this._index--,this.emit("navigation:change",this.current()),!0):!1}forward(){return this.canForward()?(this._index++,this.emit("navigation:change",this.current()),!0):!1}canBack(){return this._index>0}canForward(){return this._index<this._history.length-1}current(){var t,s;return{room:((t=this._history[this._index])==null?void 0:t.room)??null,shard:((s=this._history[this._index])==null?void 0:s.shard)??null,index:this._index,history:[...this._history]}}}class Vi{constructor(e){y(this,"http");y(this,"socket");y(this,"stores");y(this,"cache");y(this,"logger");y(this,"tokenRefreshIntervalMs");y(this,"tokenSyncSubs",[]);y(this,"tokenRefreshTimer",null);y(this,"lastHttpActivity",0);y(this,"refreshInFlight",!1);var n,i,l;let t;try{t=new URL(e.url).hostname}catch{throw new TypeError(`ScreepsClient: invalid url "${e.url}"`)}this.logger=Ee.create(e.debug),this.logger.log(`[screeps:client] init ${e.url}`),this.cache=new Di(t,e.storage??null),this.http=new Ii({url:e.url,auth:e.auth,logger:this.logger.child("http"),serverPassword:e.serverPassword}),this.socket=new Ni({url:e.url,WebSocket:e.WebSocket,logger:this.logger.child("socket")});const s=new Bi({adapter:e.storage??null,namespace:t,maxEntries:((n=e.map2)==null?void 0:n.maxCacheEntries)??1e4});this.stores={room:new Fi(this.http,this.socket,this.cache,this.logger.child("room")),user:new zi(this.http,this.socket,this.cache,this.logger.child("user")),server:new Hi(this.http,this.socket,this.cache,this.logger.child("server")),map:new Ui(this.socket,s,{maxSubscriptions:((i=e.map2)==null?void 0:i.maxSubscriptions)??500},this.logger.child("map")),mapStats:new Wi(this.http,100,500,this.logger.child("mapStats")),navigation:new qi(50,this.logger.child("navigation"))},this.tokenRefreshIntervalMs=e.tokenRefresh===!1?null:((l=e.tokenRefresh)==null?void 0:l.intervalMs)??3e4,this.wireTokenSync()}wireTokenSync(){this.tokenSyncSubs.push(this.http.on("http:tokenRefresh",({token:e})=>{this.socket.setToken(e)})),this.tokenSyncSubs.push(this.socket.on("socket:tokenRefresh",e=>{const t=e;this.http.setToken(t.token)})),this.tokenSyncSubs.push(this.http.on("http:success",()=>{this.lastHttpActivity=Date.now()}))}get isConnected(){return this.socket.isConnected}async connect(){this.logger.log("[screeps:client] connect"),await this.http.authenticate(),await this.socket.connect(this.http.token),await Promise.all([this.stores.user.me(),this.stores.user.worldStatus(),this.stores.server.version()]),this.startTokenRefresh()}disconnect(){this.logger.log("[screeps:client] disconnect"),this.stopTokenRefresh(),this.socket.disconnect()}startTokenRefresh(){if(this.tokenRefreshIntervalMs===null||this.tokenRefreshTimer!==null)return;const e=this.tokenRefreshIntervalMs;this.lastHttpActivity=Date.now();const t=Math.max(1e3,Math.floor(e/2));this.tokenRefreshTimer=setInterval(()=>{Date.now()-this.lastHttpActivity<e||this.refreshTokenNow()},t)}stopTokenRefresh(){this.tokenRefreshTimer!==null&&(clearInterval(this.tokenRefreshTimer),this.tokenRefreshTimer=null)}async refreshTokenNow(){if(!this.refreshInFlight){this.refreshInFlight=!0;try{this.logger.log("[screeps:client] token refresh (idle)"),await this.stores.user.refreshWorldStatus()}catch(e){this.logger.log("[screeps:client] token refresh failed",e)}finally{this.refreshInFlight=!1}}}async clearCache(){this.logger.log("[screeps:client] clearCache"),await this.cache.clearAll()}}class Xi{constructor(e){y(this,"token");this.token=e.token}async authenticate(e){return this.token}}class Yi{constructor(e){y(this,"email");y(this,"password");this.email=e.email,this.password=e.password}async authenticate(e){return(await e.auth.signin(this.email,this.password)).token}}class ji{async authenticate(e){return"guest"}}const Zi=1,Ce="data";class Ki{constructor(e){y(this,"namespace");y(this,"db",null);y(this,"openPromise",null);this.namespace=e}get dbName(){return`screeps:${this.namespace}`}open(){return this.db?Promise.resolve(this.db):this.openPromise?this.openPromise:(this.openPromise=new Promise((e,t)=>{const s=indexedDB.open(this.dbName,Zi);s.onupgradeneeded=()=>{s.result.createObjectStore(Ce)},s.onsuccess=()=>{this.db=s.result,this.openPromise=null,e(s.result)},s.onerror=()=>t(s.error),s.onblocked=()=>t(new Error(`IndexedDB open blocked: ${this.dbName}`))}),this.openPromise)}async get(e){const t=await this.open();return new Promise((s,n)=>{const l=t.transaction(Ce,"readonly").objectStore(Ce).get(e);l.onsuccess=()=>s(l.result??null),l.onerror=()=>n(l.error)})}async set(e,t){const s=await this.open();return new Promise((n,i)=>{const o=s.transaction(Ce,"readwrite").objectStore(Ce).put(t,e);o.onsuccess=()=>n(),o.onerror=()=>i(o.error)})}async delete(e){const t=await this.open();return new Promise((s,n)=>{const l=t.transaction(Ce,"readwrite").objectStore(Ce).delete(e);l.onsuccess=()=>s(),l.onerror=()=>n(l.error)})}async clear(){const e=await this.open();return new Promise((t,s)=>{const i=e.transaction(Ce,"readwrite").objectStore(Ce).clear();i.onsuccess=()=>t(),i.onerror=()=>s(i.error)})}}class as{constructor(){y(this,"subs",[])}add(e){this.subs.push(e)}dispose(){for(const e of this.subs)e.dispose();this.subs.length=0}}const Ji=5*6e4;function sn(r,e){try{return`screeps:${r}:${new URL(e).hostname}`}catch{return`screeps:${r}:${e}`}}function nn(r){if(typeof sessionStorage>"u")return null;try{const e=sessionStorage.getItem(r);if(!e)return null;const t=JSON.parse(e);return Date.now()>t.expires?(sessionStorage.removeItem(r),null):t.data}catch{return null}}function on(r,e){if(!(typeof sessionStorage>"u"))try{sessionStorage.setItem(r,JSON.stringify({data:e,expires:Date.now()+Ji}))}catch{}}function At(r){return r.endsWith("/")?r:`${r}/`}async function Qi(r){const e=sn("version",r),t=nn(e);if(t)return t;const s=await fetch(`${At(r)}api/version`);if(!s.ok)throw new Error(`HTTP ${s.status}`);const n=await s.json();return on(e,n),n}async function eo(r){const e=sn("authmod",r),t=nn(e);if(t)return t;const s=await fetch(`${At(r)}api/authmod`);if(!s.ok)return null;const n=await s.json();return n.ok?(on(e,n),n):null}async function to(r,e){const t=new URLSearchParams({username:e}),s=await fetch(`${At(r)}api/register/check-username?${t}`);if(!s.ok)throw new Error(`HTTP ${s.status}`);return s.json()}async function ro(r,e){const t=new URLSearchParams({email:e}),s=await fetch(`${At(r)}api/register/check-email?${t}`);if(!s.ok)throw new Error(`HTTP ${s.status}`);return s.json()}async function so(r,e,t,s){const n=await fetch(`${At(r)}api/register/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,email:t,password:s})});if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json()}function no(r,e){return r.serverData.features.find(t=>t.name===e)}function ln(r){return no(r,"screepsmod-auth")}const ur={1:{calc(r=0){let e=0,t=0;r>0&&(e=r*30/100),r<0&&(t=-r*30/100),this.path1=`M 50 ${100-e} L ${t} 50 H ${100-t} Z`,this.path2=`M ${t} 50 H ${100-t} L 50 ${e} Z`}},2:{calc(r=0){let e=0,t=0;r>0&&(e=r*30/100),r<0&&(t=-r*30/100),this.path1=`M ${e} ${t} L 50 50 L ${100-e} ${t} V -1 H -1 Z`,this.path2=`M ${e} ${100-t} L 50 50 L ${100-e} ${100-t} V 101 H -1 Z`}},3:{calc(r=0){const e=Math.PI/4+Math.PI/4*(r+100)/200,t=-Math.PI/2,s=Math.PI/2+Math.PI/3,n=Math.PI/2-Math.PI/3;this.path1=`M 50 50 L ${50+100*Math.cos(t-e/2)} ${50+100*Math.sin(t-e/2)} L ${50+100*Math.cos(t+e/2)} ${50+100*Math.sin(t+e/2)} Z`,this.path2=`M 50 50 L ${50+100*Math.cos(s-e/2)} ${50+100*Math.sin(s-e/2)} L ${50+100*Math.cos(s+e/2)} ${50+100*Math.sin(s+e/2)} Z M 50 50 L ${50+100*Math.cos(n-e/2)} ${50+100*Math.sin(n-e/2)} L ${50+100*Math.cos(n+e/2)} ${50+100*Math.sin(n+e/2)}`},flip:"rotate180"},4:{calc(r=0){r+=100;const e=50-r*30/200,t=50+r*30/200;this.path1=`M 0 ${t} H 100 V 100 H 0 Z`,this.path2=r>0?`M 0 ${e} H 100 V ${t} H 0 Z`:""},flip:"rotate90"},5:{calc(r=0){r+=100;const e=50-r*10/200-10,t=50+r*10/200+10;this.path1=`M ${e} 0 H ${t} V 100 H ${e} Z`,this.path2=`M 0 ${e} H 100 V ${t} H 0 Z`},flip:"rotate45"},6:{calc(r=0){const e=5+(r+100)*8/200,t=50,s=20,n=80;this.path1=`M ${t-e} 0 H ${t+e} V 100 H ${t-e}`,this.path2=`M ${s-e} 0 H ${s+e} V 100 H ${s-e} Z M ${n-e} 0 H ${n+e} V 100 H ${n-e} Z`},flip:"rotate90"},7:{calc(r=0){const e=20+r*10/100;this.path1="M 0 50 Q 25 30 50 50 T 100 50 V 100 H 0 Z",this.path2=`M 0 ${50-e} Q 25 ${30-e} 50 ${50-e} T 100 ${50-e} V ${50+e} Q 75 ${70+e} 50 ${50+e} T 0 ${50+e} Z`},flip:"rotate90"},8:{calc(r=0){const e=r*20/100;this.path1="M 0 50 H 100 V 100 H 0 Z",this.path2=`M 0 50 Q 50 ${e} 100 50 Q 50 ${100-e} 0 50 Z`},flip:"rotate90"},9:{calc(r=0){let e=0,t=50;const s=70;r>0&&(e+=r/100*20),r<0&&(t+=r/100*30),this.path1=`M 50 ${e} L 100 ${e+s} V 101 H 0 V ${e+s} Z`,this.path2=`M 50 ${e+t} L 100 ${e+t+s} V 101 H 0 V ${e+t+s} Z`},flip:"rotate180"},10:{calc(r=0){let e=30,t=7;r>0&&(e+=r*50/100),r<0&&(t-=r*20/100),this.path1=`M ${50+t+e} ${50-e} A ${e} ${e} 0 0 0 ${50+t+e} ${50+e} H 101 V ${50-e} Z`,this.path2=`M ${50-t-e} ${50-e} A ${e} ${e} 0 0 1 ${50-t-e} ${50+e} H -1 V ${50-e} Z`},flip:"rotate90"},11:{calc(r=0){let e=30,t=30;const s=50-50*Math.cos(Math.PI/4),n=50-50*Math.sin(Math.PI/4);r>0&&(e+=r*25/100,t+=r*25/100),r<0&&(t-=r*50/100),this.path1=`M ${s} ${n} Q ${e} 50 ${s} ${100-n} H 0 V ${n} Z M ${100-s} ${n} Q ${100-e} 50 ${100-s} ${100-n} H 100 V ${n} Z`,this.path2=`M ${s} ${n} Q 50 ${t} ${100-s} ${n} V 0 H ${s} Z M ${s} ${100-n} Q 50 ${100-t} ${100-s} ${100-n} V 100 H ${s} Z`},flip:"rotate90"},12:{calc(r=0){let e=30,t=35;r>0&&(e+=r*30/100),r<0&&(t+=r*15/100),this.path1=`M 0 ${e} H 100 V 100 H 0 Z`,this.path2=`M 0 ${e} H ${t} V 100 H 0 Z M 100 ${e} H ${100-t} V 100 H 100 Z`},flip:"rotate180"},13:{calc(r=0){let e=30,t=0;r>0&&(e+=r*50/100),r<0&&(t-=r*20/100),this.path1="M 0 0 H 50 V 100 H 0 Z",this.path2=`M ${50-e} ${50-t-e} A ${e} ${e} 0 0 0 ${50+e} ${50-e-t} V 0 H ${50-e} Z`},flip:"rotate180"},14:{calc(r=0){let e=Math.PI/4;const t=0;e+=r*Math.PI/4/100,this.path1=`M 50 0 Q 50 ${50+t} ${50+50*Math.cos(e)} ${50+50*Math.sin(e)} H 100 V 0 H 50 Z`,this.path2=`M 50 0 Q 50 ${50+t} ${50-50*Math.cos(e)} ${50+50*Math.sin(e)} H 0 V 0 H 50 Z`},flip:"rotate180"},15:{calc(r=0){const e=13+r*6/100,t=80,s=45,n=10;this.path1=`M ${50-t-e} ${100+n} A ${t+e} ${t+e} 0 0 1 ${50+t+e} ${100+n} H ${50+t-e} A ${t-e} ${t-e} 0 1 0 ${50-t+e} ${100+n}`,this.path2=`M ${50-s-e} ${100+n} A ${s+e} ${s+e} 0 0 1 ${50+s+e} ${100+n} H ${50+s-e} A ${s-e} ${s-e} 0 1 0 ${50-s+e} ${100+n}`},flip:"rotate180"},16:{calc(r=0){let e=30*Math.PI/180,t=25;r>0&&(e+=30*Math.PI/180*r/100),r<0&&(t+=r*25/100),this.path1="";for(let s=0;s<3;s++){const n=s*Math.PI*2/3+e/2-Math.PI/2,i=s*Math.PI*2/3-e/2-Math.PI/2;this.path1+=`M ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} L ${50+t*Math.cos(i)} ${50+t*Math.sin(i)} A ${t} ${t} 0 0 1 ${50+t*Math.cos(n)} ${50+t*Math.sin(n)} Z`}this.path2="";for(let s=0;s<3;s++){const n=s*Math.PI*2/3+e/2+Math.PI/2,i=s*Math.PI*2/3-e/2+Math.PI/2;this.path2+=`M ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} L ${50+t*Math.cos(i)} ${50+t*Math.sin(i)} A ${t} ${t} 0 0 1 ${50+t*Math.cos(n)} ${50+t*Math.sin(n)} Z`}}},17:{calc(r=0){let e=35,t=45;r>0&&(e+=r*20/100),r<0&&(t-=r*30/100),this.path1=`M 50 45 L ${50-e} ${t+45} H ${50+e} Z`,this.path2=`M 50 0 L ${50-e} ${t} H ${50+e} Z`}},18:{calc(r=0){let e=90*Math.PI/180,t=10;r>0&&(e-=60/180*Math.PI*r/100),r<0&&(t-=r*15/100),this.path1="",this.path2="";for(let s=0;s<3;s++){const n=Math.PI*2/3*s+e/2-Math.PI/2,i=Math.PI*2/3*s-e/2-Math.PI/2,l=`M ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} L ${50+t*Math.cos((n+i)/2)} ${50+t*Math.sin((n+i)/2)} Z`;s?this.path2+=l:this.path1+=l}},flip:"rotate180"},19:{calc(r=0){let e=20,t=60;t+=r*20/100,e+=r*20/100,this.path1=`M 50 -10 L ${50-t} 100 H ${50+t} Z`,this.path2="",e>0&&(this.path2=`M 50 0 L ${50-e} 100 H ${50+e} Z`)},flip:"rotate180"},20:{calc(r=0){let e=10,t=20;r>0&&(e+=r*20/100),r<0&&(t+=r*40/100),this.path1=`M 0 ${50-t} H ${50-e} V 100 H 0 Z`,this.path2=`M ${50+e} 0 V ${50+t} H 100 V 0 Z`},flip:"rotate90"},21:{calc(r=0){let e=40,t=50;r>0&&(e-=r*20/100),r<0&&(t+=r*20/100),this.path1=`M 50 ${t} Q ${50+e} 0 50 0 T 50 ${t} Z M 50 ${100-t} Q ${50+e} 100 50 100 T 50 ${100-t} Z`,this.path2=`M ${t} 50 Q 0 ${50+e} 0 50 T ${t} 50 Z M ${100-t} 50 Q 100 ${50+e} 100 50 T ${100-t} 50 Z`},flip:"rotate45"},22:{calc(r=0){let e=20;e+=r*10/100,this.path1=`M ${50-e} ${50-e} H ${50+e} V ${50+e} H ${50-e} Z`,this.path2="";for(let t=-4;t<4;t++)for(let s=-4;s<4;s++){const n=(t+s)%2;this.path2+=`M ${50-e-e*2*t} ${50-e-e*2*(s+n)} h ${-e*2} v ${e*2} h ${e*2} Z`}},flip:"rotate45"},23:{calc(r=0){let e=17,t=25;r>0&&(e+=r*35/100),r<0&&(t-=r*23/100),this.path1="";for(let s=-4;s<=4;s++)this.path1+=`M ${50-e*s*2} ${50-t} l ${-e} ${-t} l ${-e} ${t} l ${e} ${t} Z`;this.path2="";for(let s=-4;s<=4;s++)this.path2+=`M ${50-e*s*2} ${50+t} l ${-e} ${-t} l ${-e} ${t} l ${e} ${t} Z`},flip:"rotate90"},24:{calc(r=0){let e=50,t=45;r>0&&(e+=r*60/100),r<0&&(t+=r*30/100),this.path1=`M 0 ${t} L 50 70 L 100 ${t} V 100 H 0 Z`,this.path2=`M 50 0 L ${50+e} 100 H 100 V ${t} L 50 70 L 0 ${t} V 100 H ${50-e} Z`},flip:"rotate180"}};function hr(r){const e=Math.round(r).toString(16);return e.length<2?"0"+e:e}function Le(r,e,t){const s=(1-Math.abs(2*t-1))*e,n=r/60,i=s*(1-Math.abs(n%2-1));let l=0,o=0,a=0;!Number.isNaN(r)&&r!==null&&r!==void 0&&(n>=0&&n<1?(l=s,o=i,a=0):n>=1&&n<2?(l=i,o=s,a=0):n>=2&&n<3?(l=0,o=s,a=i):n>=3&&n<4?(l=0,o=i,a=s):n>=4&&n<5?(l=i,o=0,a=s):n>=5&&n<6&&(l=s,o=0,a=i));const c=t-s/2,d=(l+c)*255,u=(o+c)*255,h=(a+c)*255;return"#"+hr(d)+hr(u)+hr(h)}function io(){const r=[];let e=0;r.push({index:e++,rgb:Le(0,0,.8)});for(let t=0;t<19;t++)r.push({index:e++,rgb:Le(t*360/19,.6,.8)});r.push({index:e++,rgb:Le(0,0,.5)});for(let t=0;t<19;t++)r.push({index:e++,rgb:Le(t*360/19,.7,.5)});r.push({index:e++,rgb:Le(0,0,.3)});for(let t=0;t<19;t++)r.push({index:e++,rgb:Le(t*360/19,.4,.3)});r.push({index:e++,rgb:Le(0,0,.1)});for(let t=0;t<19;t++)r.push({index:e++,rgb:Le(t*360/19,.5,.1)});return r}const oo=io();function fr(r){if(typeof r=="string")return r;if(typeof r=="number"){const e=oo[r];return e?e.rgb:"#000000"}return"#000000"}function lo(r){const e=fr(r.color1),t=fr(r.color2),s=fr(r.color3),n=r.param??0;if(typeof r.type=="number"){const d=ur[r.type];d&&d.calc(n)}let i=0;if(r.flip&&typeof r.type=="number"){const d=ur[r.type];(d==null?void 0:d.flip)==="rotate180"&&(i=180),(d==null?void 0:d.flip)==="rotate90"&&(i=90),(d==null?void 0:d.flip)==="rotate45"&&(i=45)}let l,o;if(typeof r.type=="number"){const d=ur[r.type];l=(d==null?void 0:d.path1)??"",o=(d==null?void 0:d.path2)??""}else l=r.type.path1,o=r.type.path2;const a=50;let c='<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 100 100" shape-rendering="geometricPrecision">';return c+=`<defs><clipPath id="clip"><circle cx="50" cy="50" r="${a}"/></clipPath></defs>`,c+=`<g transform="rotate(${i} 50 50)">`,c+=`<rect x="0" y="0" width="100" height="100" fill="${e}" clip-path="url(#clip)"/>`,l&&(c+=`<path d="${l}" fill="${t}" clip-path="url(#clip)"/>`),o&&(c+=`<path d="${o}" fill="${s}" clip-path="url(#clip)"/>`),c+='<circle cx="50" cy="50" r="47.5" fill="transparent" stroke="#000" stroke-width="5"/>',c+="</g></svg>",c}const[ao,xs]=R([]);let co=0;function he(r,e="success",t=4e3){const s=co++;xs(n=>[...n,{id:s,message:r,type:e,duration:t}]),setTimeout(()=>{xs(n=>n.filter(i=>i.id!==s))},t)}const uo=!1;function lr(){return!0}function ho(){return uo}function cs(){return window.location.origin}function ar(){return"/client/".replace(/\/$/,"")}function ft(r){const e=`[${r}]`;return{log:()=>{},warn:()=>{},error:(...t)=>console.error(e,...t)}}const ce={room:"screeps:room",shard:"screeps:shard",sidebarWidth:"screeps:sidebarWidth",consoleHeight:"screeps:consoleHeight",consoleSplit:"screeps:consoleSplit",mapZoom:"screeps:mapZoom",widescreenMode:"screeps:settings:widescreenMode",showCreepLabels:"screeps:settings:showCreepLabels",showMapRoomNames:"screeps:settings:showMapRoomNames"},we={url:"screeps:url",token:"screeps:token",serverPassword:"screeps:serverPassword"};function pr(r){return localStorage.getItem(r)}function $s(r,e){localStorage.setItem(r,e)}function fo(r){localStorage.removeItem(r)}function kt(r,e){const t=localStorage.getItem(r);if(t===null)return e;const s=Number(t);return Number.isFinite(s)&&s!==0?s:e}function Vt(r,e){localStorage.setItem(r,String(e))}function Xt(r){return sessionStorage.getItem(r)}function Dt(r,e){sessionStorage.setItem(r,e)}function Et(r){sessionStorage.removeItem(r)}const{log:_e}=ft("client"),[ae,Yt]=R(null),[Ue,et]=R("idle"),[_s,jt]=R(null),[Or,Rr]=R(null),[vd,Lr]=R(null),[tr,Ar]=R(null),[Ir,an]=R(null),[Gr,cn]=R(!1),[Ss,dn]=R(null),[po,un]=R({}),[Ve,hn]=R(null);let Zt=-1,Nr=-1;const tt=[],go=5;function mo(r){if(r===void 0)return;const e=Date.now();if(Zt>=0&&r>Zt){const t=e-Nr;if(t>0){tt.push(t),tt.length>go&&tt.shift();const s=tt.reduce((n,i)=>n+i,0)/tt.length;an(Math.round(s))}}Zt=r,Nr=e}function yo(){Zt=-1,Nr=-1,tt.length=0,an(null)}async function Be(r){lr()&&(r={...r,url:cs()}),_e(`connecting to ${r.url} (auth: ${r.auth})`),et("connecting"),jt(null);try{let e;if(r.auth==="guest")e=new ji,cn(!0);else if(r.auth==="password"){if(!r.email||!r.password)throw new Error("Email and password are required");e=new Yi({email:r.email,password:r.password})}else{if(!r.token)throw new Error("Token is required");e=new Xi({token:r.token})}const t=new Vi({url:r.url,auth:e,storage:r.storage??new Ki("screeps-client"),debug:!1,serverPassword:r.serverPassword});t.http.on("http:tokenRefresh",({token:s})=>{_e("token refreshed"),Dt(we.token,s)}),t.http.on("http:error",({method:s,path:n,error:i})=>{_e("http error:",s,n,i.message),he(`Request failed: ${s} ${n} — ${i.message}`,"error",6e3)}),t.stores.server.on("server:disconnected",s=>{_e(`server disconnected (willReconnect: ${s.willReconnect})`),s.willReconnect||(et("idle"),Yt(null),Rr(null),Lr(null))}),t.stores.server.on("server:error",s=>{_e("server error:",s.error.message),jt(s.error.message),et("error")}),t.stores.user.on("user:me",s=>{_e(`user: ${s.username} (id: ${s._id})`),Rr(s)}),t.stores.server.on("server:version",s=>{_e(`server version: ${s.package??"unknown"}`),Lr(s)}),t.stores.user.on("user:stream",s=>{if(s&&typeof s=="object"&&"flags"in s){const n=s.flags;n&&typeof n=="object"&&un(n)}}),t.stores.user.on("user:worldStatus",({status:s})=>{_e(`world status: ${s}`),hn(s)}),await t.connect(),t.stores.user.subscribeUserStream(),Yt(t),et("connected"),_e(`connected to ${r.url}`),t.stores.server.worldInfo().then(s=>{dn(s),_e(`world: ${s.width}x${s.height} x[${s.minX},${s.maxX}] y[${s.minY},${s.maxY}]`)}).catch(()=>{}),Dt(we.url,r.url),t.http.token&&Dt(we.token,t.http.token),r.serverPassword?Dt(we.serverPassword,r.serverPassword):Et(we.serverPassword)}catch(e){const t=e instanceof Error?e.message:String(e);throw jt(t),et("error"),Yt(null),e}}async function wo(){const r=lr()?cs():Xt(we.url),e=Xt(we.token);if(!r||!e)return;const t=Xt(we.serverPassword)??void 0;try{e==="guest"?await Be({url:r,auth:"guest",storage:null,serverPassword:t}):await Be({url:r,auth:"token",token:e,serverPassword:t})}catch{Et(we.token)}}function vo(){const r=ae();r&&r.disconnect(),Yt(null),et("idle"),jt(null),Rr(null),Lr(null),Ar(null),cn(!1),dn(null),un({}),hn(null),yo(),Et(we.token),Et(we.url),Et(we.serverPassword)}var bo=k("<span style=font-size:11px>"),xo=k('<div style="color:#3fb950;font-size:14px;text-align:center;padding:8px 0">Account created! Logging you in…'),$o=k("<label style=display:flex;flex-direction:column;gap:4px><div style=display:flex;align-items:baseline;gap:8px><span style=font-size:12px;color:#8b949e>Username</span></div><input type=text name=username autocomplete=username>"),_o=k("<label style=display:flex;flex-direction:column;gap:4px><div style=display:flex;align-items:baseline;gap:8px><span style=font-size:12px;color:#8b949e>Email</span></div><input type=email name=email autocomplete=email>"),So=k("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Password</span><input type=password name=new-password autocomplete=new-password>"),Co=k("<span style=font-size:11px;color:#f85149>Passwords don't match"),ko=k("<label style=display:flex;flex-direction:column;gap:4px><div style=display:flex;align-items:baseline;gap:8px><span style=font-size:12px;color:#8b949e>Confirm Password</span></div><input type=password name=confirm-password autocomplete=new-password>"),To=k("<button type=submit style=padding:10px;border-radius:6px;border:none;background:#238636;color:#fff;font-weight:600>"),Mo=k('<button type=button style="padding:8px;border-radius:6px;border:1px solid #30363d;background:transparent;color:#8b949e;font-size:12px;cursor:pointer">Back to Login'),Eo=k("<form style=display:flex;flex-direction:column;gap:16px><h2 style=margin:0;font-size:20px>Create Account"),fn=k("<div style=color:#f85149;font-size:13px>"),Po=k('<div style="width:360px;padding:16px 20px;border-radius:8px;background:#161b22;border:1px solid #30363d;color:#c9d1d9;font-size:13px;line-height:1.6">'),Oo=k("<button type=button style=background:none;border:none;color:#58a6ff;font-size:12px;cursor:pointer;padding:0>Create account"),Ro=k('<div style=display:flex;gap:8px><button type=button style="flex:1;padding:8px;border-radius:6px;border:1px solid #30363d;color:#fff;cursor:pointer">Password</button><button type=button style="flex:1;padding:8px;border-radius:6px;border:1px solid #30363d;color:#fff;cursor:pointer">Token'),Lo=k("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Server URL</span><input type=url name=url autocomplete=url inputmode=url>"),Ao=k("<div style=color:#8b949e;font-size:12px;margin-top:-8px>"),Io=k("<div style=display:flex;align-items:center;gap:8px;color:#484f58;font-size:12px><div style=flex:1;height:1px;background:#30363d></div>or<div style=flex:1;height:1px;background:#30363d>"),Go=k("<button type=button style=padding:10px;border-radius:6px;border:none;background:#1b2838;color:#c7d5e0;font-weight:600>Login with Steam"),No=k('<button type=button style="padding:8px;border-radius:6px;border:1px solid #30363d;background:transparent;color:#8b949e;font-size:12px">Connect as Guest (read-only)'),Do=k('<form style=display:flex;flex-direction:column;gap:16px><div style=display:flex;align-items:baseline;justify-content:space-between><h2 style=margin:0;font-size:20px>Connect to Screeps</h2></div><label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Server Password <span style=color:#484f58>(optional)</span></span><input type=password name=server-password autocomplete=off data-1p-ignore data-lpignore=true placeholder="Leave empty if not required"></label><button type=submit style=padding:10px;border-radius:6px;border:none;background:#238636;color:#fff;font-weight:600>'),Fo=k('<div style="width:360px;padding:12px 20px;border-radius:8px;background:#161b22;border:1px solid #30363d"><div style=font-size:11px;color:#484f58;margin-bottom:8px;text-transform:uppercase;letter-spacing:0.05em>Server Mods</div><div style=display:flex;flex-wrap:wrap;gap:6px>'),zo=k('<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;gap:16px;width:100%;height:100%;overflow:auto;padding:24px 0;box-sizing:border-box"><div style="display:flex;flex-direction:column;gap:16px;width:360px;padding:32px;border-radius:8px;background:#161b22;border:1px solid #30363d">'),Ho=k("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Email or Username</span><input type=text id=username name=username autocomplete=username>"),Bo=k("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Password</span><input type=password id=password name=password autocomplete=current-password>"),Uo=k("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Auth Token</span><input type=password name=token autocomplete=off>"),Wo=k('<span style="font-size:11px;padding:2px 8px;border-radius:12px;background:#21262d;border:1px solid #30363d;color:#8b949e;font-family:monospace">');const Te={padding:"8px 12px","border-radius":"6px",border:"1px solid #30363d",background:"#0d1117",color:"#c9d1d9"};function qo(r){const[e,t]=R(null),[s,n]=R(null),[i,l]=R(null);return ue(()=>{const o=r();t(null),n(null),l(null);let a=!1;const c=setTimeout(async()=>{try{const d=await Qi(o);if(a)return;if(t(d),l(null),ln(d)){const u=await eo(o);a||n(u)}}catch{a||(l("Could not reach server"),t(null))}},400);$e(()=>{a=!0,clearTimeout(c)})}),{serverVersion:e,authModInfo:s,serverError:i}}function Cs(r,e,t){const[s,n]=R("idle");return ue(()=>{const i=e();if(!i){n("idle");return}n("checking");let l=!1;const o=setTimeout(async()=>{try{const a=await t(r(),i);l||n(a.error?"taken":"available")}catch{l||n("error")}},500);$e(()=>{l=!0,clearTimeout(o)})}),s}function ks(r){const e={idle:null,checking:{text:"Checking…",color:"#8b949e"},available:{text:"✓ Available",color:"#3fb950"},taken:{text:"✗ Already taken",color:"#f85149"},error:{text:"Could not verify",color:"#d29922"}},t=()=>e[r.state];return M(q,{get when(){return t()},get children(){var s=bo();return m(s,()=>t().text),F(n=>W(s,"color",t().color)),s}})}function Vo(r){const[e,t]=R(""),[s,n]=R(""),[i,l]=R(""),[o,a]=R(""),[c,d]=R(!1),[u,h]=R(null),[f,p]=R(!1),b=Cs(()=>r.url,e,to),_=Cs(()=>r.url,s,ro),w=()=>o()!==""&&i()!==o(),C=()=>!c()&&e()!==""&&s()!==""&&i().length>=4&&i()===o()&&b()!=="taken"&&b()!=="checking"&&_()!=="taken"&&_()!=="checking",E=async T=>{if(T.preventDefault(),!!C()){d(!0),h(null);try{const v=await so(r.url,e(),s(),i());if(v.error){h(v.error);return}p(!0),setTimeout(()=>r.onSuccess(s(),i()),1500)}catch(v){h(v instanceof Error?v.message:"Registration failed")}finally{d(!1)}}};return(()=>{var T=Eo();return T.firstChild,T.addEventListener("submit",E),m(T,M(q,{get when(){return f()},get children(){return xo()}}),null),m(T,M(q,{get when(){return!f()},get children(){return[(()=>{var v=$o(),P=v.firstChild;P.firstChild;var x=P.nextSibling;return m(P,M(ks,{get state(){return b()}}),null),x.$$input=S=>t(S.currentTarget.value),F(S=>{var I=Te,L=c();return S.e=de(x,I,S.e),L!==S.t&&(x.disabled=S.t=L),S},{e:void 0,t:void 0}),F(()=>x.value=e()),v})(),(()=>{var v=_o(),P=v.firstChild;P.firstChild;var x=P.nextSibling;return m(P,M(ks,{get state(){return _()}}),null),x.$$input=S=>n(S.currentTarget.value),F(S=>{var I=Te,L=c();return S.e=de(x,I,S.e),L!==S.t&&(x.disabled=S.t=L),S},{e:void 0,t:void 0}),F(()=>x.value=s()),v})(),(()=>{var v=So(),P=v.firstChild,x=P.nextSibling;return x.$$input=S=>l(S.currentTarget.value),F(S=>{var I=Te,L=c();return S.e=de(x,I,S.e),L!==S.t&&(x.disabled=S.t=L),S},{e:void 0,t:void 0}),F(()=>x.value=i()),v})(),(()=>{var v=ko(),P=v.firstChild;P.firstChild;var x=P.nextSibling;return m(P,M(q,{get when(){return w()},get children(){return Co()}}),null),x.$$input=S=>a(S.currentTarget.value),F(S=>{var I={...Te,border:w()?"1px solid #f85149":"1px solid #30363d"},L=c();return S.e=de(x,I,S.e),L!==S.t&&(x.disabled=S.t=L),S},{e:void 0,t:void 0}),F(()=>x.value=o()),v})(),ne(()=>ne(()=>!!u())()&&(()=>{var v=fn();return m(v,u),v})()),(()=>{var v=To();return m(v,()=>c()?"Creating account…":"Create Account"),F(P=>{var x=!C(),S=C()?"pointer":"not-allowed",I=C()?1:.5;return x!==P.e&&(v.disabled=P.e=x),S!==P.t&&W(v,"cursor",P.t=S),I!==P.a&&W(v,"opacity",P.a=I),P},{e:void 0,t:void 0,a:void 0}),v})(),(()=>{var v=Mo();return v.$$click=()=>r.onCancel(),v})()]}}),null),T})()}function Xo(){const r=lr(),e=ho(),[t,s]=R("login"),[n,i]=R("password"),[l,o]=R(r?cs():"http://localhost:21025"),[a,c]=R(""),[d,u]=R(""),[h,f]=R(""),[p,b]=R(""),{serverVersion:_,authModInfo:w,serverError:C}=qo(l),E=()=>{var A,O;return((O=(A=_())==null?void 0:A.serverData)==null?void 0:O.welcomeText)??null},T=()=>{var A,O;return(((O=(A=_())==null?void 0:A.serverData)==null?void 0:O.features)??[]).filter($=>$.name!=="auth"&&$.version!=null)},v=()=>{var O,$;const A=_();return A?(($=(O=ln(A))==null?void 0:O.authTypes)==null?void 0:$.includes("steam"))??!0:!0},P=()=>{var A,O,$;return((A=w())==null?void 0:A.allowRegistration)===!0||((($=(O=_())==null?void 0:O.serverData)==null?void 0:$.features)??[]).some(N=>N.name==="official-like")},x=()=>{const A=l().replace(/\/$/,""),O=window.open(`${A}/api/auth/steam`,"screeps-steam-auth","width=800,height=600,left=200,top=100"),$=H=>{try{const X=JSON.parse(H.data);X.token&&(z(),Be({url:A,auth:"token",token:X.token,serverPassword:p()||void 0,storage:null}))}catch{}},N=setInterval(()=>{O!=null&&O.closed&&z()},500),z=()=>{clearInterval(N),window.removeEventListener("message",$)};window.addEventListener("message",$),$e(z)},S=async A=>{A.preventDefault(),await Be({url:l(),auth:n(),email:a()||void 0,password:d()||void 0,token:h()||void 0,serverPassword:p()||void 0,storage:null})},I=async A=>{A.preventDefault(),await Be({url:l(),auth:"guest",serverPassword:p()||void 0,storage:null})},L=async(A,O)=>{try{await Be({url:l(),auth:"password",email:A,password:O,serverPassword:p()||void 0,storage:null})}catch{s("login"),i("password"),c(A),u(O)}},G=()=>Ue()==="connecting";return(()=>{var A=zo(),O=A.firstChild;return m(A,M(q,{get when(){return E()},get children(){var $=Po();return F(()=>$.innerHTML=E()),$}}),O),m(O,M(q,{get when(){return t()==="register"},get children(){return M(Vo,{get url(){return l()},get serverPassword(){return p()},onSuccess:L,onCancel:()=>s("login")})}}),null),m(O,M(q,{get when(){return t()==="login"},get children(){var $=Do(),N=$.firstChild;N.firstChild;var z=N.nextSibling,H=z.firstChild,X=H.firstChild;X.nextSibling;var te=H.nextSibling,K=z.nextSibling;return $.addEventListener("submit",S),m(N,M(q,{get when(){return P()},get children(){var D=Oo();return D.$$click=()=>s("register"),D}}),null),m($,M(q,{when:!r,get children(){var D=Ro(),B=D.firstChild,Y=B.nextSibling;return B.$$click=()=>i("password"),Y.$$click=()=>i("token"),F(V=>{var ee=n()==="password"?"#238636":"transparent",Fe=n()==="token"?"#238636":"transparent";return ee!==V.e&&W(B,"background",V.e=ee),Fe!==V.t&&W(Y,"background",V.t=Fe),V},{e:void 0,t:void 0}),D}}),z),m($,M(q,{when:!r,get children(){return[(()=>{var D=Lo(),B=D.firstChild,Y=B.nextSibling;return Y.$$input=V=>o(V.currentTarget.value),F(V=>de(Y,Te,V)),F(()=>Y.value=l()),D})(),M(q,{get when(){return C()},get children(){var D=Ao();return m(D,C),D}})]}}),z),m($,(()=>{var D=ne(()=>n()==="password");return()=>D()?[(()=>{var B=Ho(),Y=B.firstChild,V=Y.nextSibling;return V.$$input=ee=>c(ee.currentTarget.value),F(ee=>de(V,Te,ee)),F(()=>V.value=a()),B})(),(()=>{var B=Bo(),Y=B.firstChild,V=Y.nextSibling;return V.$$input=ee=>u(ee.currentTarget.value),F(ee=>de(V,Te,ee)),F(()=>V.value=d()),B})()]:(()=>{var B=Uo(),Y=B.firstChild,V=Y.nextSibling;return V.$$input=ee=>f(ee.currentTarget.value),F(ee=>de(V,Te,ee)),F(()=>V.value=h()),B})()})(),z),te.$$input=D=>b(D.currentTarget.value),m($,(()=>{var D=ne(()=>!!_s());return()=>D()&&(()=>{var B=fn();return m(B,_s),B})()})(),K),m(K,()=>G()?"Connecting…":"Connect"),m($,M(q,{get when(){return v()},get children(){return[(()=>{var D=Io(),B=D.firstChild,Y=B.nextSibling;return Y.nextSibling,D})(),(()=>{var D=Go();return D.$$click=x,F(B=>{var Y=G(),V=G()?"not-allowed":"pointer",ee=G()?.6:1;return Y!==B.e&&(D.disabled=B.e=Y),V!==B.t&&W(D,"cursor",B.t=V),ee!==B.a&&W(D,"opacity",B.a=ee),B},{e:void 0,t:void 0,a:void 0}),D})()]}}),null),m($,M(q,{when:!r||e,get children(){var D=No();return D.addEventListener("mouseleave",B=>{B.currentTarget.style.borderColor="#30363d"}),D.addEventListener("mouseenter",B=>{G()||(B.currentTarget.style.borderColor="#8b949e")}),D.$$click=I,F(B=>{var Y=G(),V=G()?"not-allowed":"pointer",ee=G()?.6:1;return Y!==B.e&&(D.disabled=B.e=Y),V!==B.t&&W(D,"cursor",B.t=V),ee!==B.a&&W(D,"opacity",B.a=ee),B},{e:void 0,t:void 0,a:void 0}),D}}),null),F(D=>{var B=Te,Y=G(),V=G()?"not-allowed":"pointer",ee=G()?.6:1;return D.e=de(te,B,D.e),Y!==D.t&&(K.disabled=D.t=Y),V!==D.a&&W(K,"cursor",D.a=V),ee!==D.o&&W(K,"opacity",D.o=ee),D},{e:void 0,t:void 0,a:void 0,o:void 0}),F(()=>te.value=p()),$}}),null),m(A,M(q,{get when(){return T().length>0},get children(){var $=Fo(),N=$.firstChild,z=N.nextSibling;return m(z,M(fe,{get each(){return T()},children:H=>(()=>{var X=Wo();return m(X,()=>H.name,null),m(X,(()=>{var te=ne(()=>!!H.version);return()=>te()?` ${H.version}`:""})(),null),X})()})),$}}),null),A})()}be(["input","click"]);var Yo=k('<span style="padding:2px 8px;border-radius:4px;background:#21262d;border:1px solid #30363d;color:#8b949e;font-size:11px;font-weight:600;letter-spacing:0.05em;text-transform:uppercase">Guest'),jo=k('<div style="display:flex;align-items:center;gap:12px;padding:8px 16px;border-bottom:1px solid #30363d;font-size:13px"><div style=display:flex;align-items:center;gap:6px><span style=width:8px;height:8px;border-radius:50%;display:inline-block></span><span style=color:#8b949e>');function Zo(){const r=()=>{switch(Ue()){case"connected":return"#238636";case"connecting":return"#d29922";case"error":return"#f85149";default:return"#8b949e"}};return(()=>{var e=jo(),t=e.firstChild,s=t.firstChild,n=s.nextSibling;return m(n,(()=>{var i=ne(()=>Ue()==="connected");return()=>i()?"Online":Ue()})()),m(e,M(q,{get when(){return Gr()},get children(){return Yo()}}),null),F(i=>W(s,"background-color",r())),e})()}class Ko{constructor(e){y(this,"container");y(this,"hoverGraphics");y(this,"pendingGraphics");y(this,"selectionContainer");y(this,"selectionGraphics",new Map);y(this,"selectionTypes",new Map);y(this,"selectionVisuals",new Map);y(this,"ticker",null);y(this,"tickerCallback",null);this.container=new Se,this.container.label="hoverHighlight",this.container.eventMode="none",this.hoverGraphics=new j,this.hoverGraphics.eventMode="none",this.container.addChild(this.hoverGraphics),this.pendingGraphics=new j,this.pendingGraphics.eventMode="none",this.container.addChild(this.pendingGraphics),this.selectionContainer=new Se,this.selectionContainer.eventMode="none",this.container.addChild(this.selectionContainer),e&&(this.ticker=e,this.tickerCallback=()=>this.trackCreepRings(),e.add(this.tickerCallback))}setHoveredTile(e,t){if(this.hoverGraphics.clear(),e===null||t===null)return;const s=e*g,n=t*g;this.hoverGraphics.rect(s,n,g,g),this.hoverGraphics.stroke({width:1,color:16777215,alpha:.35}),this.hoverGraphics.rect(s,n,g,g),this.hoverGraphics.fill({color:16777215,alpha:.06})}setSelectedObjects(e){this.selectionContainer.removeChildren();for(const t of this.selectionGraphics.values())t.destroy();this.selectionGraphics.clear(),this.selectionTypes.clear(),this.selectionVisuals.clear();for(const{id:t,type:s,visual:n}of e){const i=new j;i.eventMode="none",this.selectionContainer.addChild(i),this.selectionGraphics.set(t,i),this.selectionTypes.set(t,s),this.selectionVisuals.set(t,n),s==="creep"?this.drawCreepRing(i,n.x,n.y):this.drawStructureBox(i,n.x,n.y)}}clearSelection(){this.selectionContainer.removeChildren();for(const e of this.selectionGraphics.values())e.destroy();this.selectionGraphics.clear(),this.selectionTypes.clear(),this.selectionVisuals.clear()}setPendingTile(e,t){if(this.pendingGraphics.clear(),e===null||t===null)return;const s=e*g,n=t*g,i=s+g/2,l=n+g/2,o=g*.35;this.pendingGraphics.moveTo(i-o,l),this.pendingGraphics.lineTo(i+o,l),this.pendingGraphics.moveTo(i,l-o),this.pendingGraphics.lineTo(i,l+o),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.9}),this.pendingGraphics.rect(s+1,n+1,g-2,g-2),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.6})}clearPendingTile(){this.pendingGraphics.clear()}drawCreepRing(e,t,s){e.clear();const n=t+g/2,i=s+g/2,l=g*.48;e.circle(n,i,l),e.stroke({width:1.5,color:16777215,alpha:.9})}drawStructureBox(e,t,s){e.clear();const n=1;e.rect(t+n,s+n,g-n*2,g-n*2),e.stroke({width:1.5,color:16777215,alpha:.9}),e.rect(t+n,s+n,g-n*2,g-n*2),e.fill({color:16777215,alpha:.04})}trackCreepRings(){for(const[e,t]of this.selectionGraphics){if(this.selectionTypes.get(e)!=="creep")continue;const s=this.selectionVisuals.get(e);s&&this.drawCreepRing(t,s.x,s.y)}}destroy(){this.ticker&&this.tickerCallback&&this.ticker.remove(this.tickerCallback),this.ticker=null,this.tickerCallback=null,this.clearSelection(),this.clearPendingTile(),this.pendingGraphics.destroy(),this.hoverGraphics.destroy(),this.container.destroy()}}const g=12,ye=50*g,oe=48,wt=128;class ds{constructor(e,t){y(this,"app");y(this,"world");y(this,"hoverLayer");y(this,"destroyed",!1);y(this,"canDrag",!1);y(this,"container");y(this,"resizeObserver",null);y(this,"bounceRaf",null);y(this,"wheelTimeout",null);y(this,"navOverlay");y(this,"lastMouseX",0);y(this,"lastMouseY",0);y(this,"onHoverTile",null);y(this,"onClickTile",null);this.app=e,this.container=t,this.world=new Se,this.app.stage.addChild(this.world),this.hoverLayer=new Ko(e.ticker),this.world.addChild(this.hoverLayer.container),this.navOverlay=new Se,this.world.addChild(this.navOverlay),this.setupCamera(),this.centerView(),this.clampView(),this.setupResizeObserver()}bringNavOverlayToTop(){this.hoverLayer.container.parent===this.world&&(this.world.removeChild(this.hoverLayer.container),this.world.addChild(this.hoverLayer.container)),this.navOverlay.parent===this.world&&(this.world.removeChild(this.navOverlay),this.world.addChild(this.navOverlay))}static async create(e){const t=new jn;return await t.init({background:"#0d1117",antialias:!1,resolution:window.devicePixelRatio||1,autoDensity:!0}),e.appendChild(t.canvas),new ds(t,e)}getMinScale(){const t=this.container.clientWidth,s=this.container.clientHeight;return Math.min(t,s)/(ye+64)}clampView(e=!1){const t=this.world.scale.x,s=ye*t,n=this.container.clientWidth,i=this.container.clientHeight,l=e?wt:0;if(s<=n){const o=n/2-s/2;e?this.world.x=Math.min(o+wt,Math.max(o-wt,this.world.x)):this.world.x=o}else{const o=n-s-oe-l,a=oe+l;this.world.x=Math.min(a,Math.max(o,this.world.x))}if(s<=i){const o=i/2-s/2;e?this.world.y=Math.min(o+wt,Math.max(o-wt,this.world.y)):this.world.y=o}else{const o=i-s-oe-l,a=oe+l;this.world.y=Math.min(a,Math.max(o,this.world.y))}this.canDrag=!0}getTargetPosition(){const e=this.world.scale.x,t=ye*e,s=this.container.clientWidth,n=this.container.clientHeight;let i=null,l=null;if(t<=s)i=s/2-t/2;else{const o=s-t-oe,a=oe;this.world.x<o?i=o:this.world.x>a&&(i=a)}if(t<=n)l=n/2-t/2;else{const o=n-t-oe,a=oe;this.world.y<o?l=o:this.world.y>a&&(l=a)}return i===null&&l===null?null:{x:i??this.world.x,y:l??this.world.y}}springBack(){const e=this.getTargetPosition(),t=this.getTargetScale();if(!e&&t===null)return;const s=this.world.x,n=this.world.y,i=this.world.scale.x,l=performance.now(),o=300,a=this.container.clientWidth/2,c=this.container.clientHeight/2,d=(a-s)/i,u=(c-n)/i,h=f=>{const p=f-l,b=Math.min(1,p/o),_=1-Math.pow(1-b,3);if(t!==null){const w=i+(t-i)*_;this.world.scale.set(w),this.world.x=a-d*w,this.world.y=c-u*w}e&&t===null&&(this.world.x=s+(e.x-s)*_,this.world.y=n+(e.y-n)*_),b<1?this.bounceRaf=requestAnimationFrame(h):(this.bounceRaf=null,this.clampView())};this.cancelBounce(),this.bounceRaf=requestAnimationFrame(h)}cancelBounce(){this.bounceRaf!==null&&(cancelAnimationFrame(this.bounceRaf),this.bounceRaf=null)}cancelWheelTimeout(){this.wheelTimeout!==null&&(clearTimeout(this.wheelTimeout),this.wheelTimeout=null)}getTargetScale(){const e=this.getMinScale(),t=5;return this.world.scale.x<e?e:this.world.scale.x>t?t:null}setupCamera(){let e=!1,t=new yt(0,0),s=new yt(0,0);const n=this.app.canvas,i=4;n.addEventListener("contextmenu",o=>{o.preventDefault()}),n.addEventListener("pointerdown",o=>{this.cancelBounce(),this.cancelWheelTimeout(),e=this.canDrag,t=new yt(o.clientX,o.clientY),s=new yt(o.clientX,o.clientY),this.canDrag&&n.setPointerCapture(o.pointerId)}),n.addEventListener("pointermove",o=>{var h;const a=n.getBoundingClientRect();this.lastMouseX=o.clientX-a.left,this.lastMouseY=o.clientY-a.top;const c=this.screenToTile(this.lastMouseX,this.lastMouseY);if(this.hoverLayer.setHoveredTile((c==null?void 0:c.tx)??null,(c==null?void 0:c.ty)??null),(h=this.onHoverTile)==null||h.call(this,(c==null?void 0:c.tx)??null,(c==null?void 0:c.ty)??null),!e||!this.canDrag)return;const d=o.clientX-t.x,u=o.clientY-t.y;this.world.x+=d,this.world.y+=u,t=new yt(o.clientX,o.clientY),this.clampView(!0)});const l=o=>{var u;this.canDrag&&n.releasePointerCapture(o.pointerId),e=!1;const a=o.clientX-s.x,c=o.clientY-s.y;if(Math.sqrt(a*a+c*c)<i){const h=n.getBoundingClientRect(),f=o.clientX-h.left,p=o.clientY-h.top,b=this.screenToTile(f,p);b&&((u=this.onClickTile)==null||u.call(this,b.tx,b.ty,o.ctrlKey||o.metaKey))}this.springBack()};n.addEventListener("pointerup",l),n.addEventListener("pointercancel",l),n.addEventListener("pointerleave",()=>{var o;this.hoverLayer.setHoveredTile(null,null),(o=this.onHoverTile)==null||o.call(this,null,null)}),n.addEventListener("wheel",o=>{o.preventDefault();const a=o.deltaY>0?.9:1.1,c=this.getMinScale(),d=5;let u=this.world.scale.x*a;const h=.6;u<c&&(u=c+(u-c)*h),u>d&&(u=d+(u-d)*h);const f=n.getBoundingClientRect(),p=o.clientX-f.left,b=o.clientY-f.top;if(this.cancelBounce(),u<c){const _=this.container.clientWidth/2,w=this.container.clientHeight/2,C=(_-this.world.x)/this.world.scale.x,E=(w-this.world.y)/this.world.scale.y;this.world.scale.set(u),this.world.x=_-C*u,this.world.y=w-E*u}else{const _=(p-this.world.x)/this.world.scale.x,w=(b-this.world.y)/this.world.scale.y;this.world.scale.set(u),this.world.x=p-_*u,this.world.y=b-w*u}this.clampView(),this.cancelWheelTimeout(),this.wheelTimeout=window.setTimeout(()=>{this.wheelTimeout=null,this.springBack()},80)},{passive:!1})}setTileHandlers(e,t){this.onHoverTile=e,this.onClickTile=t}screenToTile(e,t){const s=(e-this.world.x)/this.world.scale.x,n=(t-this.world.y)/this.world.scale.y,i=Math.floor(s/g),l=Math.floor(n/g);return i<0||i>=50||l<0||l>=50?null:{tx:i,ty:l}}centerView(){const e=this.container.clientWidth/2,t=this.container.clientHeight/2,s=this.world.scale.x;this.world.x=e-ye*s/2,this.world.y=t-ye*s/2}resetView(){this.cancelBounce(),this.cancelWheelTimeout(),this.world.scale.set(this.getMinScale()),this.centerView(),this.clampView()}setupResizeObserver(){const{width:e,height:t}=this.container.getBoundingClientRect();this.app.renderer.resize(e,t),this.resizeObserver=new ResizeObserver(s=>{const{width:n,height:i}=s[0].contentRect;this.app.renderer.resize(n,i),this.clampView()}),this.resizeObserver.observe(this.container)}setupNavigationZones(e){this.navOverlay.removeChildren();const t=(l,o,a,c,d,u)=>{if(!u)return;const h=new j;h.x=l,h.y=o,h.hitArea=new Zn(0,0,a,c),h.fill({color:16777215,alpha:.12}),h.poly(d),h.fill(),h.eventMode="static",h.cursor="pointer",h.alpha=1,h.on("pointerover",()=>{h.clear(),h.fill({color:16777215,alpha:.06}),h.rect(0,0,a,c),h.fill(),h.fill({color:16777215,alpha:.35}),h.poly(d),h.fill()}),h.on("pointerout",()=>{h.clear(),h.fill({color:16777215,alpha:.12}),h.poly(d),h.fill()}),h.on("pointerdown",u),this.navOverlay.addChild(h)},s=ye/2,n=ye/2,i=18;t(-oe,0,oe,ye,[18,n,oe-6,n-i,oe-6,n+i],e.west),t(ye,0,oe,ye,[oe-18,n,6,n-i,6,n+i],e.east),t(0,-oe,ye,oe,[s,18,s-i,oe-6,s+i,oe-6],e.north),t(0,ye,ye,oe,[s,oe-18,s-i,6,s+i,6],e.south);for(const l of this.navOverlay.children){const o=l,a=o.hitArea,c=this.world.x+o.x*this.world.scale.x,d=this.world.y+o.y*this.world.scale.y,u=a.width*this.world.scale.x,h=a.height*this.world.scale.y;this.lastMouseX>=c&&this.lastMouseX<=c+u&&this.lastMouseY>=d&&this.lastMouseY<=d+h&&o.emit("pointerover",new Event("pointerover"))}}clear(){for(let e=this.world.children.length-1;e>=0;e--){const t=this.world.children[e];t!==this.navOverlay&&t!==this.hoverLayer.container&&this.world.removeChild(t)}this.navOverlay.removeChildren(),this.hoverLayer.clearSelection(),this.hoverLayer.setHoveredTile(null,null),this.world.scale.set(1),this.cancelBounce(),this.cancelWheelTimeout(),this.clampView()}destroy(){var e;this.destroyed||(this.destroyed=!0,this.cancelBounce(),this.cancelWheelTimeout(),(e=this.resizeObserver)==null||e.disconnect(),this.resizeObserver=null,this.hoverLayer.destroy(),this.app.destroy(!0,{children:!0}))}}const pn=856343,Jo=1448738,Qo=1843496,el=3421243,tl=el,bd=pn,gn=7039337,rl=3159613,sl=1711910,nl=658705,il=2242594,ol=1253907,ll=5000268,al=11122630,cl=16770413,dl=7829367,ul=16332866,hl=6127794,fl=6684002,pl=12164347,Ft={tough:ll,move:al,work:cl,carry:dl,attack:ul,ranged_attack:hl,heal:fl,claim:pl},gr=5809919,Kt=7979263,gl=4176208,mr=9147550,zt=13801762,Ts=10711543,ml=16218298,Ms=16273737,yr=15763518,yl=2172461,mn=gn,wl=13226457,Ht=12283502,it=[16777215,16711680,8388736,255,65535,32768,16776960,16753920,10824234,8421504,16777215],vl={creep:yr,spawn:gr,extension:Kt,tower:gl,container:mr,storage:zt,link:Ts,rampart:gr,road:mn,wall:yl,extractor:mr,lab:ml,terminal:zt,observer:Kt,powerSpawn:yr,nuker:Ms,factory:mr,invaderCore:Ms,source:zt,mineral:Kt,deposit:zt,controller:gr,powerBank:yr,portal:Ts},cr=16771195,bl=cr,xl=Kt,$l=cr,Dr=9419667,_l=7245682,Sl=12116924,Cl=12283502,kl=9787480,Tl=14721184,Es=Qo,Ml=13684944,le=1579032,ze=5592405,Jt=11184810,El=9419667,Oe=16771195,Pl=16069959,Ps=4410435,Ol=g*.125,Rl=g*.2;function Bt(r,e,t,s){const n=g,i=n/2;for(let l=0;l<50;l++)for(let o=0;o<50;o++){const a=e.get(o,l)===t,c=l>0&&e.get(o,l-1)===t,d=l<49&&e.get(o,l+1)===t,u=o>0&&e.get(o-1,l)===t,h=o<49&&e.get(o+1,l)===t,f=o*n+i,p=l*n+i;a?!c&&!u&&l>0&&o>0?(r.moveTo(f,l*n),r.arc(f,p,i,-Math.PI/2,Math.PI,!0),r.lineTo(f,p),r.closePath(),s(r)):(r.rect(o*n,l*n,i,i),s(r)):c&&u&&e.get(o-1,l-1)===t&&(r.moveTo(f,l*n),r.lineTo(o*n,l*n),r.lineTo(o*n,p),r.arc(f,p,i,Math.PI,-Math.PI/2,!1),r.closePath(),s(r)),a?!c&&!h&&l>0&&o<49?(r.moveTo(f,l*n),r.arc(f,p,i,-Math.PI/2,0,!1),r.lineTo(f,p),r.closePath(),s(r)):(r.rect(f,l*n,i,i),s(r)):c&&h&&e.get(o+1,l-1)===t&&(r.moveTo(f,l*n),r.lineTo(o*n+n,l*n),r.lineTo(o*n+n,p),r.arc(f,p,i,0,-Math.PI/2,!0),r.closePath(),s(r)),a?!d&&!u&&l<49&&o>0?(r.moveTo(o*n,p),r.arc(f,p,i,Math.PI,Math.PI/2,!0),r.lineTo(f,p),r.closePath(),s(r)):(r.rect(o*n,p,i,i),s(r)):d&&u&&e.get(o-1,l+1)===t&&(r.moveTo(o*n,p),r.lineTo(o*n,l*n+n),r.lineTo(f,l*n+n),r.arc(f,p,i,Math.PI/2,Math.PI,!1),r.closePath(),s(r)),a?!d&&!h&&l<49&&o<49?(r.moveTo(f,l*n+n),r.arc(f,p,i,Math.PI/2,0,!0),r.lineTo(f,p),r.closePath(),s(r)):(r.rect(f,p,i,i),s(r)):d&&h&&e.get(o+1,l+1)===t&&(r.moveTo(f,l*n+n),r.lineTo(o*n+n,l*n+n),r.lineTo(o*n+n,p),r.arc(f,p,i,0,Math.PI/2,!1),r.closePath(),s(r))}}function Ll(r,e){const t=gn,s=g,n=(i,l,o)=>{const a=i*s+s/2,c=l*s+s/2,d=s*.3;r.moveTo(a,c),o==="up"?(r.moveTo(a,c-d),r.lineTo(a+d,c+d),r.lineTo(a-d,c+d)):o==="down"?(r.moveTo(a,c+d),r.lineTo(a+d,c-d),r.lineTo(a-d,c-d)):o==="left"?(r.moveTo(a-d,c),r.lineTo(a+d,c-d),r.lineTo(a+d,c+d)):o==="right"&&(r.moveTo(a+d,c),r.lineTo(a-d,c-d),r.lineTo(a-d,c+d)),r.fill(t)};for(let i=0;i<50;i++)e.get(i,0)!==Pe.Wall&&n(i,0,"up"),e.get(i,49)!==Pe.Wall&&n(i,49,"down");for(let i=0;i<50;i++)e.get(0,i)!==Pe.Wall&&n(0,i,"left"),e.get(49,i)!==Pe.Wall&&n(49,i,"right")}function Os(r){const e=new j;e.rect(0,0,50*g,50*g),e.fill(tl);const t={color:ol,width:Rl,alignment:0,cap:"round",join:"round"};Bt(e,r,Pe.Swamp,n=>n.stroke(t)),Bt(e,r,Pe.Swamp,n=>n.fill(il));const s={color:nl,width:Ol,alignment:0,cap:"round",join:"round"};return Bt(e,r,Pe.Wall,n=>n.stroke(s)),Bt(e,r,Pe.Wall,n=>n.fill(sl)),Ll(e,r),e.rect(0,0,50*g,50*g),e.stroke({width:1,color:rl}),e}function Al(r){return new Promise((e,t)=>{const s=new Image;s.onload=()=>e(s),s.onerror=t,s.src=r})}class Il{constructor(){y(this,"cache",new Map);y(this,"pending",new Map)}getKey(e){return JSON.stringify(e)}has(e){return this.cache.has(this.getKey(e))}getOrCreate(e){const t=this.getKey(e),s=this.cache.get(t);if(s)return Promise.resolve(s);const n=this.pending.get(t);if(n)return n;const i=this.buildTexture(e,t);return this.pending.set(t,i),i.then(()=>{this.pending.delete(t)}).catch(()=>{this.pending.delete(t)}),i}async buildTexture(e,t){const s=lo(e),n=new Blob([s],{type:"image/svg+xml;charset=utf-8"}),i=URL.createObjectURL(n);try{const l=await Al(i),o=Kn.from(l);return this.cache.set(t,o),o}finally{URL.revokeObjectURL(i)}}destroy(){for(const e of this.cache.values())e.destroyed||e.destroy(!0);this.cache.clear(),this.pending.clear()}}const Gl=new Il,Ie=g*.44,Me=g*.28,vt=50,Fr=32,zr=12/Fr,yn=g/2-g*.44,wn=2,Rs=g*.42,vn=g*.3,Nl=Math.max(1,g*.08),Ls=g-4,As=g*.28;function Hr(r,e){if(e<=0)return Ls;const t=Math.max(0,Math.min(1,r/e));return As+(Ls-As)*t}function bn(r,e){const t=e/2,s=g/2,n=g/2,i=e*.25;r.clear(),r.roundRect(s-t,n-t,e,e,i),r.fill(Oe)}function Dl(r,e){const t=r.__sourceGraphics;t&&bn(t,e)}function Br(r){const e=typeof r.energy=="number"?r.energy:0,t=typeof r.energyCapacity=="number"?r.energyCapacity:3e3;return{energy:e,capacity:t}}const xn=g*.3,$n=Math.max(1,g*.12),Ur=xn-$n/2,Fl=g*.42,zl=1500;function Hl(r,e,t){const s=r>>16&255,n=r>>8&255,i=r&255,l=e>>16&255,o=e>>8&255,a=e&255,c=Math.round(s+(l-s)*t),d=Math.round(n+(o-n)*t),u=Math.round(i+(a-i)*t);return c<<16|d<<8|u}function _n(r,e){r.clear(),r.circle(g/2,g/2,xn),r.stroke({width:$n,color:e,alpha:.95})}function Wr(r,e,t,s,n,i,l){if(r.clear(),i<=0||n<=0)return;const o=Math.min(1,n/i);if(o>=1){r.circle(e,t,s),r.fill({color:l,alpha:.55});return}const a=-Math.PI/2,c=a+o*Math.PI*2;r.moveTo(e,t),r.lineTo(e+s*Math.cos(a),t+s*Math.sin(a)),r.arc(e,t,s,a,c),r.closePath(),r.fill({color:l,alpha:.55})}function Ae(r,e,t){return t.flatMap(([s,n])=>[r+s*g,e+n*g])}function Ke(r,e,t,s){t-e<.001||(r.moveTo(Ie*Math.cos(e),Ie*Math.sin(e)),r.arc(0,0,Ie,e,t),r.lineTo(Me*Math.cos(t),Me*Math.sin(t)),r.arc(0,0,Me,t,e,!0),r.closePath(),r.fill(s))}function qr(r){let e=0;if(typeof r.storeCapacity=="number")e=r.storeCapacity;else{const s=r.body;s&&(e=s.filter(n=>n.type==="carry").length*50)}if(e===0)return{used:0,capacity:0};let t=0;if(r.store&&typeof r.store=="object"){const s=r.store;for(const n in s){const i=s[n];typeof i=="number"&&(t+=i)}}else typeof r.energy=="number"&&(t=r.energy);return{used:t,capacity:e}}function Vr(r,e){return e<=0||r<=0?0:Me*.8*Math.min(1,r/e)}function Bl(r,e){const t=r.__creepFillGraphics;t&&(t.clear(),e>0&&(t.circle(0,0,e),t.fill(cr)))}function Ul(r){return vl[r]??wl}function ot(r){const e=typeof r.energyCapacity=="number"?r.energyCapacity:typeof r.storeCapacity=="number"?r.storeCapacity:50;let t=0;return typeof r.energy=="number"?t=r.energy:r.store&&typeof r.store=="object"&&(t=r.store.energy??0),{energy:t,capacity:e}}function Sn(r){return r<100?.7:1}function Xr(r,e){return e<=0||r<=0?0:vn*Sn(e)*Math.min(1,r/e)}function Wl(r,e,t,s){const n=g/2,i=g/2,l=Sn(t),o=new j;o.circle(n,i,Rs*l),o.fill(le),o.circle(n,i,Rs*l),o.stroke({width:Nl*l,color:s}),o.circle(n,i,vn*l),o.fill(Jt),r.addChild(o);const a=new j,c=Xr(e,t);c>0&&(a.circle(n,i,c),a.fill(Oe)),r.addChild(a),r.__fillGraphics=a}function ql(r,e){const t=g/2,s=g/2,n=r.__fillGraphics;n&&(n.clear(),e>0&&(n.circle(t,s,e),n.fill(Oe)))}const Yr=-g*.4,jr=-g*.3,Zr=g*.8,rr=g*.6;function Kr(r,e){return e<=0||r<=0?0:rr*Math.min(1,r/e)}function Cn(r,e){const t=r.__towerFillGraphics;if(t&&(t.clear(),e>0)){const s=Math.max(.5,g*.02);t.rect(Yr+s,jr+rr-e+s,Zr-s*2,e-s*2),t.fill(Oe)}}const Jr=g*.65,Qr=Jr,He=g*.42;function es(r,e,t,s,n,i,l,o){r.clear();const a=8,c=.1,d=2*Math.PI/a-c;for(let u=0;u<a;u++){const h=-Math.PI/2+u*(2*Math.PI/a)+c/2,f=h+d,p=e+n*Math.cos(h),b=t+n*Math.sin(h);if(u<i)r.moveTo(p,b),r.arc(e,t,s,h,f),r.arc(e,t,n,f,h,!0),r.closePath(),r.fill({color:14540253,alpha:.9});else if(u===i&&o>0){if(r.moveTo(p,b),r.arc(e,t,s,h,f),r.arc(e,t,n,f,h,!0),r.closePath(),r.fill({color:1973790,alpha:.85}),l>0){const _=Math.min(1,l/o),w=h+d*_;r.moveTo(p,b),r.arc(e,t,s,h,w),r.arc(e,t,n,w,h,!0),r.closePath(),r.fill({color:14540253,alpha:.9})}}else r.moveTo(p,b),r.arc(e,t,s,h,f),r.arc(e,t,n,f,h,!0),r.closePath(),r.fill({color:1973790,alpha:.6})}}function ts(r,e){const t=r.user;return typeof t!="string"||!e?!1:t!==e}function Ut(r,e=!0,t,s,n,i){var p,b,_;const l=new Se,o=new j,a=Ul(r.type),c=g/2,d=g/2,u=typeof r.user=="string"?r.user:void 0,f=u!==void 0&&t!==void 0&&u!==t?Ht:El;switch(r.type){case"creep":{const w=2*Math.PI,C=new Se;C.position.set(c,d),C.rotation=-Math.PI/2;const E=ts(r,t);if(E){const J=new j;J.circle(0,0,Ie+.75),J.stroke({width:1.5,color:Ht}),C.addChild(J)}const T=new j;T.circle(0,0,Ie),T.fill(pn),C.addChild(T);const v=r.body??[];let P=0,x=0,S=0;const I=[],L={};for(const J of v)J.type==="work"?P++:J.type==="move"?x++:(L[J.type]===void 0&&(I.push(J.type),L[J.type]=0),L[J.type]++,S++);const G=P/vt*w,A=x/vt*w,O=S/vt*w,$=G/2,N=$+O/2,z=Math.PI-A/2,H=Math.PI+A/2,X=w-G/2-O/2,te=w-G/2,K=new j;G>0&&Ke(K,-G/2,$,Ft.work);let D=$;for(const J of I){const xe=(L[J]??0)/vt*w/2;Ke(K,D,D+xe,Ft[J]??7829367),D+=xe}Ke(K,N,z,Es),A>0&&Ke(K,z,H,Ft.move),Ke(K,H,X,Es);let B=te;for(const J of I){const xe=(L[J]??0)/vt*w/2;Ke(K,B-xe,B,Ft[J]??7829367),B-=xe}C.addChild(K);const Y=new j;Y.circle(0,0,Me),Y.fill(Jo),C.addChild(Y);const V=typeof r.user=="string"?r.user:void 0,ee=V?(p=i==null?void 0:i[V])==null?void 0:p.badge:void 0;if(ee&&n){const J=new gs;J.anchor.set(.5,.5);const xe=Me*2;J.width=xe,J.height=xe,J.rotation=Math.PI/2,C.addChild(J),n.getOrCreate(ee).then(Nt=>{J.destroyed||(J.texture=Nt)}).catch(()=>{})}else if(E){const J=new j;J.circle(0,0,Me*.82),J.fill({color:Ht,alpha:.9}),C.addChild(J)}const{used:Fe,capacity:It}=qr(r),Gt=Vr(Fe,It),Ye=new j;Gt>0&&(Ye.circle(0,0,Gt),Ye.fill(cr)),C.addChild(Ye),l.__creepFillGraphics=Ye,l.__creepUsed=Fe,l.__creepCapacity=It;const pt=(Ie+Me)/2,gt=(Ie-Me)*.45,Re=new j;Re.moveTo(Ie,0),Re.lineTo(pt,-gt),Re.lineTo(pt,gt),Re.closePath(),Re.fill(Ml),C.addChild(Re),l.addChild(C),l.__bodyContainer=C;break}case"extension":{const{energy:w,capacity:C}=ot(r);Wl(l,w,C,f),l.__extEnergy=w,l.__extCapacity=C;break}case"spawn":{o.circle(c,d,g*.65),o.fill(le),o.circle(c,d,g*.65),o.stroke({width:g*.1,color:13421772}),o.circle(c,d,g*.4),o.fill(Oe);break}case"powerSpawn":{o.circle(c,d,g*.65),o.fill(le),o.circle(c,d,g*.65),o.stroke({width:g*.1,color:Pl}),o.circle(c,d,g*.4),o.fill(Oe);break}case"source":{const{energy:w,capacity:C}=Br(r),E=new j;bn(E,Hr(w,C)),l.addChild(E),l.__sourceGraphics=E,l.__sourceEnergy=w,l.__sourceCapacity=C;break}case"constructionSite":{const w=typeof r.user=="string"?r.user:void 0,C=w!==void 0&&w===t,E=C?Dr:Cl,T=C?_l:kl,v=C?Sl:Tl,P=typeof r.progress=="number"?r.progress:0,x=typeof r.progressTotal=="number"?r.progressTotal:1,S=new j;l.addChild(S),l.__csBuildGlow=S;const I=new j;Wr(I,c,d,Ur,P,x,E),l.addChild(I),l.__csFillGraphics=I;const L=new j;_n(L,E),l.addChild(L),l.__csRingGraphics=L,l.__csProgress=P,l.__csProgressTotal=x,l.__csUser=w,l.__csColor=E,l.__csColorDark=T,l.__csColorLight=v;break}case"mineral":case"deposit":{o.rect(2,2,g-4,g-4),o.fill(a);break}case"controller":{const w=typeof r.level=="number"?r.level:0,C=typeof r.progress=="number"?r.progress:0,E=typeof r.progressTotal=="number"?r.progressTotal:0,T=new j,v=[];for(let L=0;L<8;L++){const G=-Math.PI/2+L*Math.PI/4;v.push(c+Jr*Math.cos(G),d+Jr*Math.sin(G))}T.poly(v),T.fill(le),T.poly(v),T.stroke({width:g*.05,color:4737096}),l.addChild(T);const P=new j;es(P,c,d,Qr,He,w,C,E),l.addChild(P),l.__ctrlSegGraphics=P,l.__ctrlLevel=w,l.__ctrlProgress=C,l.__ctrlProgressTotal=E;const x=new j;x.circle(c,d,He),x.fill(le),l.addChild(x);const S=typeof r.user=="string"?r.user:void 0,I=S?(b=i==null?void 0:i[S])==null?void 0:b.badge:void 0;if(I&&n){const L=new gs;L.anchor.set(.5,.5),L.width=He*2,L.height=He*2,L.position.set(c,d);const G=new j;G.circle(c,d,He),G.fill(16777215),l.addChild(L),L.mask=G,l.addChild(G),n.getOrCreate(I).then(A=>{L.destroyed||(L.texture=A)}).catch(()=>{})}break}case"energy":{o.circle(c,d,g*.2),o.fill(Oe);break}case"road":break;case"wall":{o.circle(c,d,g*.4),o.fill(le),o.circle(c,d,g*.4),o.stroke({width:g*.05,color:Jt});break}case"rampart":break;case"tower":{const{energy:w,capacity:C}=ot(r),E=new j;E.circle(c,d,g*.6),E.fill(le),E.circle(c,d,g*.6),E.stroke({width:g*.05,color:f}),l.addChild(E);const T=new Se;T.position.set(c,d);const v=new j;v.rect(Yr,jr,Zr,rr),v.fill(le),T.addChild(v);const P=new j;T.addChild(P),l.__towerFillGraphics=P,l.__towerEnergy=w,l.__towerCapacity=C,Cn(l,Kr(w,C));const x=new j;x.rect(Yr,jr,Zr,rr),x.stroke({width:1,color:ze}),T.addChild(x);const S=new j;S.rect(-g*.2,-g*.9,g*.4,g*.5),S.fill(Jt),S.rect(-g*.2,-g*.9,g*.4,g*.5),S.stroke({width:g*.07,color:le}),T.addChild(S),l.addChild(T),l.__barrelContainer=T;break}case"storage":{const w=Ae(c,d,[[-.6,-.7],[0,-.8],[.6,-.7],[.65,0],[.6,.7],[0,.8],[-.6,.7],[-.65,0],[-.6,-.7]]);o.poly(w),o.fill(le),o.poly(w),o.stroke({width:g*.05,color:f}),o.rect(c-g*.5,d-g*.6,g*1,g*1.2),o.fill(ze),o.rect(c-g*.5,d-g*.6,g*1,g*1.2),o.stroke({width:g*.1,color:le});break}case"terminal":{const w=Ae(c,d,[[0,-.8],[.55,-.55],[.8,0],[.55,.55],[0,.8],[-.55,.55],[-.8,0],[-.55,-.55],[0,-.8]]),C=Ae(c,d,[[0,-.65],[.45,-.45],[.65,0],[.45,.45],[0,.65],[-.45,.45],[-.65,0],[-.45,-.45],[0,-.65]]);o.poly(w),o.fill(le),o.poly(w),o.stroke({width:g*.05,color:f}),o.poly(C),o.fill(Jt),o.rect(c-g*.45,d-g*.45,g*.9,g*.9),o.fill(ze),o.rect(c-g*.45,d-g*.45,g*.9,g*.9),o.stroke({width:g*.1,color:le});break}case"link":{const w=Ae(c,d,[[0,-.5],[.4,0],[0,.5],[-.4,0],[0,-.5]]),C=Ae(c,d,[[0,-.3],[.25,0],[0,.3],[-.25,0],[0,-.3]]);o.poly(w),o.fill(le),o.poly(w),o.stroke({width:g*.05,color:f}),o.poly(C),o.fill(ze);break}case"lab":{const w=d-g*.025;o.circle(c,w,g*.55),o.fill(le),o.circle(c,w,g*.55),o.stroke({width:g*.05,color:f}),o.circle(c,w,g*.4),o.fill(ze),o.rect(c-g*.45,d+g*.3,g*.9,g*.25),o.fill(le),o.poly(Ae(c,d,[[-.45,.3],[-.45,.55],[.45,.55],[.45,.3]])),o.stroke({width:g*.05,color:f});break}case"container":{o.rect(c-g*.225,d-g*.3,g*.45,g*.6),o.fill(Oe),o.rect(c-g*.225,d-g*.3,g*.45,g*.6),o.stroke({width:g*.1,color:le});break}case"observer":{o.circle(c,d,g*.45),o.fill(le),o.circle(c,d,g*.45),o.stroke({width:g*.05,color:f}),o.circle(c+g*.225,d,g*.2),o.fill(f);break}case"nuker":{const w=Ae(c,d,[[0,-1],[-.47,.2],[-.5,.5],[.5,.5],[.47,.2],[0,-1]]),C=Ae(c,d,[[0,-.8],[-.4,.2],[.4,.2],[0,-.8]]);o.poly(w),o.fill(le),o.poly(w),o.stroke({width:g*.05,color:f}),o.poly(C),o.fill(ze),o.poly(C),o.stroke({width:g*.01,color:f});break}case"factory":case"extractor":case"invaderCore":{o.circle(c,d,g*.45),o.fill(le),o.circle(c,d,g*.45),o.stroke({width:g*.05,color:f}),o.circle(c,d,g*.35),o.fill(ze);break}case"flag":{const w=typeof r.color=="number"?r.color:0,C=typeof r.secondaryColor=="number"?r.secondaryColor:0,E=it[w]??it[0],T=it[C]??it[0],v=1.5,P=g*.08*v,x=g*.7*v,S=c-P/2,I=d-g*.25*v;o.rect(S,I,P,x),o.fill(8947848);const L=S+P,G=I,A=L+g*.45*v,O=G,$=G+g*.44*v,N=(O+$)/2,z=N;if(o.moveTo(L,O),o.lineTo(A,N),o.lineTo(L,z),o.closePath(),o.fill(E),o.moveTo(L,z),o.lineTo(A,N),o.lineTo(L,$),o.closePath(),o.fill(T),l.addChild(o),l.__flagColor=w,l.__flagSecondaryColor=C,typeof r.name=="string"){const H=new Mr({text:r.name,style:{fontSize:Fr,fill:16777215}});H.scale.set(zr),H.anchor.set(.5,0),H.x=c,H.y=d+g*.55,H.visible=e,l.__nameLabel=H,l.addChild(H)}break}default:{const w=g-2;o.rect(1,1,w,w),o.fill(a)}}if(r.type!=="extension"&&r.type!=="road"&&r.type!=="creep"&&r.type!=="tower"&&r.type!=="controller"&&r.type!=="flag"&&r.type!=="source"&&r.type!=="constructionSite"&&l.addChild(o),r.type==="creep"&&typeof r.name=="string"){const w=ts(r,t);let C;if(w){const v=typeof r.user=="string"?r.user:void 0;C=v?((_=i==null?void 0:i[v])==null?void 0:_.username)??v:"Hostile"}else C=r.name;const E=w?Ht:16777215,T=new Mr({text:C,style:{fontSize:Fr,fill:E}});T.scale.set(zr),T.anchor.set(.5,1),T.x=c,T.y=yn-wn,T.visible=e,l.__nameLabel=T,l.addChild(T)}return r.type==="creep"&&(l.zIndex=1),r.type==="flag"&&(l.zIndex=10),l.position.set(r.x*g,r.y*g),l}function bt(r){r.destroy({children:!0})}class Vl{constructor(e,t=!0,s,n,i){y(this,"container");y(this,"objects",new Map);y(this,"rawObjects",new Map);y(this,"roadGraphics");y(this,"rampartGraphics");y(this,"ticker",null);y(this,"tickerCallback",null);y(this,"extAnimations",new Map);y(this,"creepFillAnimations",new Map);y(this,"towerFillAnimations",new Map);y(this,"sourceAnimations",new Map);y(this,"buildGlowAnimations",new Map);y(this,"EXT_ANIM_DURATION",300);y(this,"lastWorldScale",1);y(this,"showLabels");y(this,"currentUserId");y(this,"badge");y(this,"badgeCache",Gl);y(this,"users");this.showLabels=t,this.currentUserId=s,this.badge=n,this.users=i,this.container=new Se,this.container.sortableChildren=!0,this.rampartGraphics=new j,this.rampartGraphics.zIndex=-1,this.container.addChild(this.rampartGraphics),this.roadGraphics=new j,this.container.addChild(this.roadGraphics),e&&(this.ticker=e,this.tickerCallback=()=>this.tick(),e.add(this.tickerCallback))}tick(){var i;for(const l of this.objects.values()){const o=l.__targetX,a=l.__targetY;if(o!==void 0&&a!==void 0){const c=o-l.x,d=a-l.y;Math.abs(c)<.5&&Math.abs(d)<.5?(l.position.set(o,a),l.__targetX=void 0,l.__targetY=void 0):(l.x+=c*.15,l.y+=d*.15)}}const e=((i=this.container.parent)==null?void 0:i.scale.x)??1;if(e!==this.lastWorldScale){this.lastWorldScale=e;for(const l of this.objects.values())this.applyLabelScale(l)}const t=performance.now(),s=t/1e3,n=.5+.5*Math.sin(t*2*Math.PI/zl);for(const l of this.objects.values())l.__barrelContainer&&(l.__barrelContainer.rotation=s*.4),l.__csRingGraphics&&l.__csColorDark!==void 0&&l.__csColorLight!==void 0&&_n(l.__csRingGraphics,Hl(l.__csColorDark,l.__csColorLight,n));for(const[l,o]of this.extAnimations){const a=t-o.startTime,c=Math.min(1,a/this.EXT_ANIM_DURATION),d=c<.5?2*c*c:1-Math.pow(-2*c+2,2)/2;ql(o.visual,o.fromRadius+(o.toRadius-o.fromRadius)*d),c>=1&&this.extAnimations.delete(l)}for(const[l,o]of this.creepFillAnimations){const a=t-o.startTime,c=Math.min(1,a/this.EXT_ANIM_DURATION),d=c<.5?2*c*c:1-Math.pow(-2*c+2,2)/2;Bl(o.visual,o.fromRadius+(o.toRadius-o.fromRadius)*d),c>=1&&this.creepFillAnimations.delete(l)}for(const[l,o]of this.towerFillAnimations){const a=t-o.startTime,c=Math.min(1,a/this.EXT_ANIM_DURATION),d=c<.5?2*c*c:1-Math.pow(-2*c+2,2)/2;Cn(o.visual,o.fromRadius+(o.toRadius-o.fromRadius)*d),c>=1&&this.towerFillAnimations.delete(l)}for(const[l,o]of this.sourceAnimations){const a=t-o.startTime,c=Math.min(1,a/this.EXT_ANIM_DURATION),d=c<.5?2*c*c:1-Math.pow(-2*c+2,2)/2;Dl(o.visual,o.fromRadius+(o.toRadius-o.fromRadius)*d),c>=1&&this.sourceAnimations.delete(l)}for(const[l,o]of this.buildGlowAnimations){const a=this.objects.get(l),c=a==null?void 0:a.__csBuildGlow;if(!a||!c){this.buildGlowAnimations.delete(l);continue}const d=(t-o.startTime)/o.duration;let u;d<=0?u=0:d<.5?u=d/.5:d<.7?u=1:d<1?u=1-(d-.7)/.3:u=0,c.clear(),u>0&&(c.circle(g/2,g/2,Fl),c.fill({color:Oe,alpha:u*.75})),d>=1&&this.buildGlowAnimations.delete(l)}}startExtAnimation(e,t,s,n,i,l){const o=Xr(s,n),a=Xr(i,l);o!==a&&this.extAnimations.set(e,{visual:t,fromRadius:o,toRadius:a,startTime:performance.now()})}startCreepFillAnimation(e,t,s,n,i,l){const o=Vr(s,n),a=Vr(i,l);o!==a&&this.creepFillAnimations.set(e,{visual:t,fromRadius:o,toRadius:a,startTime:performance.now()})}startTowerFillAnimation(e,t,s,n,i,l){const o=Kr(s,n),a=Kr(i,l);o!==a&&this.towerFillAnimations.set(e,{visual:t,fromRadius:o,toRadius:a,startTime:performance.now()})}startSourceAnimation(e,t,s,n,i,l){const o=Hr(s,n),a=Hr(i,l);o!==a&&this.sourceAnimations.set(e,{visual:t,fromRadius:o,toRadius:a,startTime:performance.now()})}update(e,t,s){s&&(this.users=s);let n=!1;if(t)for(const i in t)if(t[i]===null){const o=this.rawObjects.get(i);o&&o.type==="road"&&(n=!0);const a=this.objects.get(i);a&&(this.container.removeChild(a),bt(a),this.objects.delete(i),this.rawObjects.delete(i),this.extAnimations.delete(i),this.creepFillAnimations.delete(i),this.towerFillAnimations.delete(i),this.sourceAnimations.delete(i),this.buildGlowAnimations.delete(i))}else{const o=e[i];if(!o)continue;if(o.type==="road"){const c=this.rawObjects.get(i);(!c||c.x!==o.x||c.y!==o.y)&&(n=!0)}this.rawObjects.set(i,o);const a=this.objects.get(i);if(a){const c=o.x*g,d=o.y*g;if(o.type==="creep"){const u=o.x-(a.__tileX??o.x),h=o.y-(a.__tileY??o.y);(u!==0||h!==0)&&(a.__angle=Math.atan2(h,u),a.__bodyContainer&&(a.__bodyContainer.rotation=a.__angle)),a.__tileX=o.x,a.__tileY=o.y,(a.x!==c||a.y!==d)&&(a.__targetX=c,a.__targetY=d);const{used:f,capacity:p}=qr(o);(a.__creepUsed!==f||a.__creepCapacity!==p)&&(this.startCreepFillAnimation(i,a,a.__creepUsed??0,a.__creepCapacity??p,f,p),a.__creepUsed=f,a.__creepCapacity=p)}else if(o.type==="flag"){const u=typeof o.color=="number"?o.color:0,h=typeof o.secondaryColor=="number"?o.secondaryColor:0;if(a.__flagColor!==u||a.__flagSecondaryColor!==h){this.container.removeChild(a),bt(a),this.objects.delete(i);const p=Ut(o,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);p.__tileX=o.x,p.__tileY=o.y,this.applyLabelScale(p),this.objects.set(i,p),this.container.addChild(p)}else a.position.set(c,d)}else a.position.set(c,d);if(o.type==="extension"){const{energy:u,capacity:h}=ot(o),f=a;(f.__extEnergy!==u||f.__extCapacity!==h)&&(this.startExtAnimation(i,a,f.__extEnergy??0,f.__extCapacity??h,u,h),f.__extEnergy=u,f.__extCapacity=h)}if(o.type==="tower"){const{energy:u,capacity:h}=ot(o);(a.__towerEnergy!==u||a.__towerCapacity!==h)&&(this.startTowerFillAnimation(i,a,a.__towerEnergy??0,a.__towerCapacity??h,u,h),a.__towerEnergy=u,a.__towerCapacity=h)}if(o.type==="controller"){const u=typeof o.level=="number"?o.level:0,h=typeof o.progress=="number"?o.progress:0,f=typeof o.progressTotal=="number"?o.progressTotal:0;(a.__ctrlLevel!==u||a.__ctrlProgress!==h||a.__ctrlProgressTotal!==f)&&(a.__ctrlSegGraphics&&es(a.__ctrlSegGraphics,g/2,g/2,Qr,He,u,h,f),a.__ctrlLevel=u,a.__ctrlProgress=h,a.__ctrlProgressTotal=f)}if(o.type==="source"){const{energy:u,capacity:h}=Br(o);(a.__sourceEnergy!==u||a.__sourceCapacity!==h)&&(this.startSourceAnimation(i,a,a.__sourceEnergy??0,a.__sourceCapacity??h,u,h),a.__sourceEnergy=u,a.__sourceCapacity=h)}if(o.type==="constructionSite"){const u=typeof o.progress=="number"?o.progress:0,h=typeof o.progressTotal=="number"?o.progressTotal:1;(a.__csProgress!==u||a.__csProgressTotal!==h)&&(a.__csFillGraphics&&Wr(a.__csFillGraphics,g/2,g/2,Ur,u,h,a.__csColor??Dr),a.__csProgress=u,a.__csProgressTotal=h)}}else{const c=Ut(o,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);c.__tileX=o.x,c.__tileY=o.y,this.applyLabelScale(c),this.objects.set(i,c),this.container.addChild(c)}}else{const i=new Set;for(const l in e){const o=e[l];if(!o)continue;i.add(l),this.rawObjects.set(l,o);const a=this.objects.get(l);if(a){const c=o.x*g,d=o.y*g;if(o.type==="creep"){const u=o.x-(a.__tileX??o.x),h=o.y-(a.__tileY??o.y);(u!==0||h!==0)&&(a.__angle=Math.atan2(h,u),a.__bodyContainer&&(a.__bodyContainer.rotation=a.__angle)),a.__tileX=o.x,a.__tileY=o.y,(a.x!==c||a.y!==d)&&(a.__targetX=c,a.__targetY=d);const{used:f,capacity:p}=qr(o);(a.__creepUsed!==f||a.__creepCapacity!==p)&&(this.startCreepFillAnimation(l,a,a.__creepUsed??0,a.__creepCapacity??p,f,p),a.__creepUsed=f,a.__creepCapacity=p)}else if(o.type==="flag"){const u=typeof o.color=="number"?o.color:0,h=typeof o.secondaryColor=="number"?o.secondaryColor:0;if(a.__flagColor!==u||a.__flagSecondaryColor!==h){this.container.removeChild(a),bt(a),this.objects.delete(l);const p=Ut(o,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);p.__tileX=o.x,p.__tileY=o.y,this.applyLabelScale(p),this.objects.set(l,p),this.container.addChild(p)}else a.position.set(c,d)}else a.position.set(c,d);if(o.type==="extension"){const{energy:u,capacity:h}=ot(o),f=a;(f.__extEnergy!==u||f.__extCapacity!==h)&&(this.startExtAnimation(l,a,f.__extEnergy??0,f.__extCapacity??h,u,h),f.__extEnergy=u,f.__extCapacity=h)}if(o.type==="tower"){const{energy:u,capacity:h}=ot(o);(a.__towerEnergy!==u||a.__towerCapacity!==h)&&(this.startTowerFillAnimation(l,a,a.__towerEnergy??0,a.__towerCapacity??h,u,h),a.__towerEnergy=u,a.__towerCapacity=h)}if(o.type==="controller"){const u=typeof o.level=="number"?o.level:0,h=typeof o.progress=="number"?o.progress:0,f=typeof o.progressTotal=="number"?o.progressTotal:0;(a.__ctrlLevel!==u||a.__ctrlProgress!==h||a.__ctrlProgressTotal!==f)&&(a.__ctrlSegGraphics&&es(a.__ctrlSegGraphics,g/2,g/2,Qr,He,u,h,f),a.__ctrlLevel=u,a.__ctrlProgress=h,a.__ctrlProgressTotal=f)}if(o.type==="source"){const{energy:u,capacity:h}=Br(o);(a.__sourceEnergy!==u||a.__sourceCapacity!==h)&&(this.startSourceAnimation(l,a,a.__sourceEnergy??0,a.__sourceCapacity??h,u,h),a.__sourceEnergy=u,a.__sourceCapacity=h)}if(o.type==="constructionSite"){const u=typeof o.progress=="number"?o.progress:0,h=typeof o.progressTotal=="number"?o.progressTotal:1;(a.__csProgress!==u||a.__csProgressTotal!==h)&&(a.__csFillGraphics&&Wr(a.__csFillGraphics,g/2,g/2,Ur,u,h,a.__csColor??Dr),a.__csProgress=u,a.__csProgressTotal=h)}}else{const c=Ut(o,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);c.__tileX=o.x,c.__tileY=o.y,this.applyLabelScale(c),this.objects.set(l,c),this.container.addChild(c)}}for(const[l,o]of this.objects)i.has(l)||(this.container.removeChild(o),bt(o),this.objects.delete(l),this.rawObjects.delete(l),this.extAnimations.delete(l),this.creepFillAnimations.delete(l),this.towerFillAnimations.delete(l),this.sourceAnimations.delete(l),this.buildGlowAnimations.delete(l));n=!0}this.redrawRamparts(),n&&this.redrawRoads(),this.refreshForeignCreepLabels()}redrawRoads(){this.roadGraphics.clear();const e=mn,t=Array.from({length:50},()=>new Array(50).fill(!1)),s=[];for(const a of this.rawObjects.values())a.type==="road"&&(s.push(a),a.x>=0&&a.x<50&&a.y>=0&&a.y<50&&(t[a.x][a.y]=!0));if(s.length===0)return;const n=g/2,i=g/2,l=g*.125;for(const a of s)this.roadGraphics.circle(a.x*g+n,a.y*g+i,l);this.roadGraphics.fill(e);const o=[[1,0],[1,1],[0,1],[-1,1]];for(const a of s){const c=a.x*g+n,d=a.y*g+i;for(const[u,h]of o){const f=a.x+u,p=a.y+h;if(f>=0&&f<50&&p>=0&&p<50&&t[f][p]){const b=f*g+n,_=p*g+i;this.roadGraphics.moveTo(c,d),this.roadGraphics.lineTo(b,_)}}}this.roadGraphics.stroke({width:l*2,color:e})}redrawRamparts(){this.rampartGraphics.clear();const e=g,t=e/2,s=Array.from({length:50},()=>new Array(50).fill(void 0));for(const i of this.rawObjects.values())i.type==="rampart"&&i.x>=0&&i.x<50&&i.y>=0&&i.y<50&&(s[i.x][i.y]=typeof i.user=="string"?i.user:void 0);const n=i=>!i||!this.currentUserId?{color:Ps,alpha:.7}:i===this.currentUserId?{color:Ps,alpha:.7}:{color:7807522,alpha:.5};for(let i=0;i<50;i++)for(let l=0;l<50;l++){const o=s[l][i],a=o!==void 0,c=i>0&&s[l][i-1]!==void 0,d=i<49&&s[l][i+1]!==void 0,u=l>0&&s[l-1][i]!==void 0,h=l<49&&s[l+1][i]!==void 0,f=l*e+t,p=i*e+t;if(a){const b=n(o);!c&&!u&&i>0&&l>0?(this.rampartGraphics.moveTo(f,i*e),this.rampartGraphics.arc(f,p,t,-Math.PI/2,Math.PI,!0),this.rampartGraphics.lineTo(f,p),this.rampartGraphics.fill(b)):(this.rampartGraphics.rect(l*e,i*e,t,t),this.rampartGraphics.fill(b))}else if(c&&u&&s[l-1][i-1]!==void 0){const b=n(s[l-1][i-1]);this.rampartGraphics.moveTo(f,i*e),this.rampartGraphics.lineTo(l*e,i*e),this.rampartGraphics.lineTo(l*e,p),this.rampartGraphics.arc(f,p,t,Math.PI,-Math.PI/2,!1),this.rampartGraphics.fill(b)}if(a){const b=n(o);!c&&!h&&i>0&&l<49?(this.rampartGraphics.moveTo(f,i*e),this.rampartGraphics.arc(f,p,t,-Math.PI/2,0,!1),this.rampartGraphics.lineTo(f,p),this.rampartGraphics.fill(b)):(this.rampartGraphics.rect(f,i*e,t,t),this.rampartGraphics.fill(b))}else if(c&&h&&s[l+1][i-1]!==void 0){const b=n(s[l+1][i-1]);this.rampartGraphics.moveTo(f,i*e),this.rampartGraphics.lineTo(l*e+e,i*e),this.rampartGraphics.lineTo(l*e+e,p),this.rampartGraphics.arc(f,p,t,0,-Math.PI/2,!0),this.rampartGraphics.fill(b)}if(a){const b=n(o);!d&&!u&&i<49&&l>0?(this.rampartGraphics.moveTo(l*e,p),this.rampartGraphics.arc(f,p,t,Math.PI,Math.PI/2,!0),this.rampartGraphics.lineTo(f,p),this.rampartGraphics.fill(b)):(this.rampartGraphics.rect(l*e,p,t,t),this.rampartGraphics.fill(b))}else if(d&&u&&s[l-1][i+1]!==void 0){const b=n(s[l-1][i+1]);this.rampartGraphics.moveTo(l*e,p),this.rampartGraphics.lineTo(l*e,i*e+e),this.rampartGraphics.lineTo(f,i*e+e),this.rampartGraphics.arc(f,p,t,Math.PI/2,Math.PI,!1),this.rampartGraphics.fill(b)}if(a){const b=n(o);!d&&!h&&i<49&&l<49?(this.rampartGraphics.moveTo(f,i*e+e),this.rampartGraphics.arc(f,p,t,Math.PI/2,0,!0),this.rampartGraphics.lineTo(f,p),this.rampartGraphics.fill(b)):(this.rampartGraphics.rect(f,p,t,t),this.rampartGraphics.fill(b))}else if(d&&h&&s[l+1][i+1]!==void 0){const b=n(s[l+1][i+1]);this.rampartGraphics.moveTo(f,i*e+e),this.rampartGraphics.lineTo(l*e+e,i*e+e),this.rampartGraphics.lineTo(l*e+e,p),this.rampartGraphics.arc(f,p,t,0,Math.PI/2,!1),this.rampartGraphics.fill(b)}}}getObjectsAtTile(e,t){const s=[];for(const[n,i]of this.objects){const l=this.rawObjects.get(n);l&&l.x===e&&l.y===t&&s.push({id:n,obj:l,visual:i})}return s}applyLabelScale(e){if(!e.__nameLabel)return;const t=this.lastWorldScale||1;e.__nameLabel.scale.set(zr/t),e.__nameLabel.anchor.y===0?e.__nameLabel.y=g/2+g*.55:e.__nameLabel.y=yn-wn/t}refreshForeignCreepLabels(){var e,t;if(this.currentUserId)for(const[s,n]of this.objects){const i=this.rawObjects.get(s);if(!i||i.type!=="creep"||!n.__nameLabel||!ts(i,this.currentUserId))continue;const l=typeof i.user=="string"?i.user:void 0,o=l?((t=(e=this.users)==null?void 0:e[l])==null?void 0:t.username)??l:"Hostile";n.__nameLabel.text!==o&&(n.__nameLabel.text=o)}}triggerBuildAt(e,t,s){for(const[n,i]of this.objects){const l=this.rawObjects.get(n);if(!(!l||l.type!=="constructionSite")&&!(l.x!==e||l.y!==t)&&i.__csBuildGlow){this.buildGlowAnimations.set(n,{startTime:performance.now(),duration:s});return}}}setShowLabels(e){this.showLabels=e;for(const t of this.objects.values())t.__nameLabel&&(t.__nameLabel.visible=e)}getVisualById(e){return this.objects.get(e)}clear(){for(const e of this.objects.values())bt(e);this.objects.clear(),this.rawObjects.clear(),this.extAnimations.clear(),this.creepFillAnimations.clear(),this.towerFillAnimations.clear(),this.sourceAnimations.clear(),this.buildGlowAnimations.clear(),this.roadGraphics.clear(),this.rampartGraphics.clear(),this.container.removeChildren()}destroy(){this.clear(),this.ticker&&this.tickerCallback&&this.ticker.remove(this.tickerCallback),this.ticker=null,this.tickerCallback=null}}const wr=2;function Je(r,e){return{cx:r*g+g/2,cy:e*g+g/2}}class Xl{constructor(e){y(this,"container");y(this,"graphics");y(this,"animations",[]);y(this,"ticker",null);y(this,"tickerCallback",null);this.container=new Se,this.graphics=new j,this.container.addChild(this.graphics),e&&(this.ticker=e,this.tickerCallback=()=>this.animate(),e.add(this.tickerCallback))}addHarvest(e,t,s,n,i){const l=Je(e,t),o=Je(s,n);this.animations.push({fromX:l.cx,fromY:l.cy,toX:o.cx,toY:o.cy,startTime:performance.now(),duration:i,color:bl,width:wr})}addUpgradeController(e,t,s,n,i){const l=Je(e,t),o=Je(s,n);this.animations.push({fromX:l.cx,fromY:l.cy,toX:o.cx,toY:o.cy,startTime:performance.now(),duration:i,color:xl,width:wr})}addBuild(e,t,s,n,i){const l=Je(e,t),o=Je(s,n);this.animations.push({fromX:l.cx,fromY:l.cy,toX:o.cx,toY:o.cy,startTime:performance.now(),duration:i,color:$l,width:wr})}animate(){this.graphics.clear();const e=performance.now();let t=!1;for(let s=this.animations.length-1;s>=0;s--){const n=this.animations[s],i=e-n.startTime,l=Math.min(1,i/n.duration);let o,a,c,d;const u=.5,h=.2;if(l<u){const f=l/u;o=n.fromX,a=n.fromY,c=n.fromX+(n.toX-n.fromX)*f,d=n.fromY+(n.toY-n.fromY)*f}else if(l<u+h)o=n.fromX,a=n.fromY,c=n.toX,d=n.toY;else{const f=(l-u-h)/(1-u-h);o=n.fromX+(n.toX-n.fromX)*f,a=n.fromY+(n.toY-n.fromY)*f,c=n.toX,d=n.toY}this.graphics.moveTo(o,a),this.graphics.lineTo(c,d),this.graphics.stroke({width:n.width,color:n.color}),t=!0,l>=1&&this.animations.splice(s,1)}t||this.graphics.clear()}clear(){this.animations.length=0,this.graphics.clear()}destroy(){this.clear(),this.ticker&&this.tickerCallback&&this.ticker.remove(this.tickerCallback),this.ticker=null,this.tickerCallback=null,this.graphics.destroy(),this.container.destroy()}}const me=r=>(r+.5)*g,xt=4,Wt={dashed:[.4*g,.4*g],dotted:[.1*g,.3*g]};function qt(r,e,t,s){let n=!0,i=t;for(let l=0;l<e.length-1;l++){const[o,a]=e[l],[c,d]=e[l+1],u=c-o,h=d-a,f=Math.sqrt(u*u+h*h);if(f<.001)continue;const p=u/f,b=h/f;let _=0;for(;_<f;){const w=Math.min(i,f-_);if(n){const C=o+p*_,E=a+b*_;r.moveTo(C,E),r.lineTo(C+p*w,E+b*w)}_+=w,i-=w,i<.001&&(n=!n,i=n?t:s)}}}function Yl(r,e,t){const s=Math.max(32,Math.ceil(2*Math.PI*t/2)),n=[];for(let i=0;i<=s;i++){const l=i/s*2*Math.PI;n.push([r+Math.cos(l)*t,e+Math.sin(l)*t])}return n}function jl(r){if(r==null)return .7;if(typeof r=="number")return r;const e=r.match(/^([0-9.]+)(px)?/);if(!e)return .7;const t=parseFloat(e[1]);return e[2]?t/g:t}function Zl(r){if(typeof r!="string")return"Arial";const e=r.match(/^[0-9.]+(px)?\s+(.+)$/);return e?e[2]:"Arial"}class Kl{constructor(){y(this,"container");y(this,"g");this.container=new Se,this.container.label="visuals",this.g=new j,this.container.addChild(this.g)}update(e){const t=this.container.removeChildren();for(const n of t)n!==this.g&&n.destroy();if(this.g.clear(),this.container.addChild(this.g),!e)return;const s=this.g;for(const n of e.split(`
4
+ `)){if(!n.trim())continue;let i;try{i=JSON.parse(n)}catch{continue}const l=i.s??{},o=l.opacity??1;switch(i.t){case"l":this.drawLine(s,i,l,o);break;case"c":this.drawCircle(s,i,l,o);break;case"r":this.drawRect(s,i,l,o);break;case"p":this.drawPoly(s,i,l,o);break;case"t":this.drawText(i,l,o);break}}}drawLine(e,t,s,n){const i=me(t.x1),l=me(t.y1),o=me(t.x2),a=me(t.y2),c=s.color??"#ffffff",d=(s.width??.1)*g;if(s.lineStyle&&s.lineStyle!=="solid"){const[u,h]=Wt[s.lineStyle];qt(e,[[i,l],[o,a]],u,h)}else e.moveTo(i,l),e.lineTo(o,a);e.stroke({color:c,width:d,alpha:n})}drawCircle(e,t,s,n){const i=me(t.x),l=me(t.y),o=(s.radius??.5)*g,a=!!(s.fill&&s.fill!=="transparent"),c=!!(s.stroke&&s.strokeWidth),d=s.lineStyle&&s.lineStyle!=="solid";if(a&&(e.circle(i,l,o),e.fill({color:s.fill,alpha:n})),c){const u=s.strokeWidth*g;if(d){const[h,f]=Wt[s.lineStyle];qt(e,Yl(i,l,o),h,f)}else e.circle(i,l,o);e.stroke({color:s.stroke,width:u,alpha:n})}}drawRect(e,t,s,n){const i=me(t.x),l=me(t.y),o=t.w*g,a=t.h*g,c=!!(s.fill&&s.fill!=="transparent"),d=!!(s.stroke&&s.strokeWidth),u=s.lineStyle&&s.lineStyle!=="solid";if(c&&(e.rect(i,l,o,a),e.fill({color:s.fill,alpha:n})),d){const h=s.strokeWidth*g;if(u){const[f,p]=Wt[s.lineStyle],b=[[i,l],[i+o,l],[i+o,l+a],[i,l+a],[i,l]];qt(e,b,f,p)}else e.rect(i,l,o,a);e.stroke({color:s.stroke,width:h,alpha:n})}}drawPoly(e,t,s,n){if(!t.points||t.points.length===0)return;const i=!!(s.fill&&s.fill!=="transparent"),l=!!(s.stroke&&s.strokeWidth);if(!i&&!l)return;const o=s.lineStyle&&s.lineStyle!=="solid",a=new Array(t.points.length*2);let c;l&&o&&(c=new Array(t.points.length));for(let d=0;d<t.points.length;d++){const[u,h]=t.points[d],f=me(u),p=me(h);a[d*2]=f,a[d*2+1]=p,c&&(c[d]=[f,p])}if(i&&(e.poly(a,!0),e.fill({color:s.fill,alpha:n})),l){const d=s.strokeWidth*g;if(o&&c){const[u,h]=Wt[s.lineStyle],f=c[0],p=c[c.length-1],b=f[0]===p[0]&&f[1]===p[1];qt(e,b?c:[...c,f],u,h)}else e.poly(a,!0);e.stroke({color:s.stroke,width:d,alpha:n})}}drawText(e,t,s){const n=jl(t.font),i=Zl(t.font),l=t.align??"left",o=new Jn({fill:t.color??"#ffffff",fontSize:Math.round(n*g*xt),fontFamily:i,align:l,...t.stroke&&t.strokeWidth?{stroke:{color:t.stroke,width:t.strokeWidth*g*xt}}:{}});if(t.backgroundColor&&t.backgroundColor!=="transparent"){const c=Qn.measureText(e.text,o),d=c.width/xt,u=c.height/xt,h=(t.backgroundPadding??.3)*g,f=l==="center"?.5:l==="right"?1:0,p=me(e.x)-f*d-h,b=me(e.y)-u/2-h,_=new j;_.rect(p,b,d+h*2,u+h*2),_.fill({color:t.backgroundColor,alpha:s}),this.container.addChild(_)}const a=new Mr({text:e.text,style:o});a.scale.set(1/xt),a.anchor.x=l==="center"?.5:l==="right"?1:0,a.anchor.y=.5,a.position.set(me(e.x),me(e.y)),a.alpha=s,this.container.addChild(a)}destroy(){const e=this.container.removeChildren();for(const t of e)t!==this.g&&t.destroy();this.g.destroy(),this.container.destroy()}}function us(r,e){const t=localStorage.getItem(r),[s,n]=R(t!==null?t==="true":e);return[s,i=>{n(i),localStorage.setItem(r,String(i))}]}const[kn,Jl]=us(ce.widescreenMode,!0),[rs,Ql]=us(ce.showCreepLabels,!0),[Tn,Mn]=us(ce.showMapRoomNames,!1),ss=Symbol("store-raw"),at=Symbol("store-node"),ke=Symbol("store-has"),En=Symbol("store-self");function Pn(r){let e=r[qe];if(!e&&(Object.defineProperty(r,qe,{value:e=new Proxy(r,ra)}),!Array.isArray(r))){const t=Object.keys(r),s=Object.getOwnPropertyDescriptors(r),n=Object.getPrototypeOf(r),i=n!==null&&r!==null&&typeof r=="object"&&!Array.isArray(r)&&n!==Object.prototype;if(i){const l=Object.getOwnPropertyDescriptors(n);t.push(...Object.keys(l)),Object.assign(s,l)}for(let l=0,o=t.length;l<o;l++){const a=t[l];i&&a==="constructor"||s[a].get&&Object.defineProperty(r,a,{configurable:!0,enumerable:s[a].enumerable,get:s[a].get.bind(e)})}}return e}function Ne(r){let e;return r!=null&&typeof r=="object"&&(r[qe]||!(e=Object.getPrototypeOf(r))||e===Object.prototype||Array.isArray(r))}function dt(r,e=new Set){let t,s,n,i;if(t=r!=null&&r[ss])return t;if(!Ne(r)||e.has(r))return r;if(Array.isArray(r)){Object.isFrozen(r)?r=r.slice(0):e.add(r);for(let l=0,o=r.length;l<o;l++)n=r[l],(s=dt(n,e))!==n&&(r[l]=s)}else{Object.isFrozen(r)?r=Object.assign({},r):e.add(r);const l=Object.keys(r),o=Object.getOwnPropertyDescriptors(r);for(let a=0,c=l.length;a<c;a++)i=l[a],!o[i].get&&(n=r[i],(s=dt(n,e))!==n&&(r[i]=s))}return r}function sr(r,e){let t=r[e];return t||Object.defineProperty(r,e,{value:t=Object.create(null)}),t}function Ot(r,e,t){if(r[e])return r[e];const[s,n]=R(t,{equals:!1,internal:!0});return s.$=n,r[e]=s}function ea(r,e){const t=Reflect.getOwnPropertyDescriptor(r,e);return!t||t.get||!t.configurable||e===qe||e===at||(delete t.value,delete t.writable,t.get=()=>r[qe][e]),t}function On(r){Tr()&&Ot(sr(r,at),En)()}function ta(r){return On(r),Reflect.ownKeys(r)}const ra={get(r,e,t){if(e===ss)return r;if(e===qe)return t;if(e===ps)return On(r),t;const s=sr(r,at),n=s[e];let i=n?n():r[e];if(e===at||e===ke||e==="__proto__")return i;if(!n){const l=Object.getOwnPropertyDescriptor(r,e);Tr()&&(typeof i!="function"||r.hasOwnProperty(e))&&!(l&&l.get)&&(i=Ot(s,e,i)())}return Ne(i)?Pn(i):i},has(r,e){return e===ss||e===qe||e===ps||e===at||e===ke||e==="__proto__"?!0:(Tr()&&Ot(sr(r,ke),e)(),e in r)},set(){return console.warn("Cannot mutate a Store directly"),!0},deleteProperty(){return console.warn("Cannot mutate a Store directly"),!0},ownKeys:ta,getOwnPropertyDescriptor:ea};function ve(r,e,t,s=!1){if(e==="__proto__"){console.warn('Refusing to set "__proto__" on a store.');return}if(!s&&r[e]===t)return;const n=r[e],i=r.length;t===void 0?(delete r[e],r[ke]&&r[ke][e]&&n!==void 0&&r[ke][e].$()):(r[e]=t,r[ke]&&r[ke][e]&&n===void 0&&r[ke][e].$());let l=sr(r,at),o;if((o=Ot(l,e,n))&&o.$(()=>t),Array.isArray(r)&&r.length!==i){for(let a=r.length;a<i;a++)(o=l[a])&&o.$();(o=Ot(l,"length",i))&&o.$(r.length)}(o=l[En])&&o.$()}function Rn(r,e){const t=Object.keys(e);for(let s=0;s<t.length;s+=1){const n=t[s];Ln(n)||ve(r,n,e[n])}}function Ln(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function sa(r,e){if(typeof e=="function"&&(e=e(r)),e=dt(e),Array.isArray(e)){if(r===e)return;let t=0,s=e.length;for(;t<s;t++){const n=e[t];r[t]!==n&&ve(r,t,n)}ve(r,"length",s)}else Rn(r,e)}function Tt(r,e,t=[]){let s,n=r;if(e.length>1){s=e.shift();const l=typeof s,o=Array.isArray(r);if(l==="string"&&(s==="__proto__"||e.length>1&&Ln(s))){console.warn(`Refusing to traverse unsafe key "${s}" on a store.`);return}if(Array.isArray(s)){for(let a=0;a<s.length;a++)Tt(r,[s[a]].concat(e),t);return}else if(o&&l==="function"){for(let a=0;a<r.length;a++)s(r[a],a)&&Tt(r,[a].concat(e),t);return}else if(o&&l==="object"){const{from:a=0,to:c=r.length-1,by:d=1}=s;for(let u=a;u<=c;u+=d)Tt(r,[u].concat(e),t);return}else if(e.length>1){Tt(r[s],e,[s].concat(t));return}n=r[s],t=[s].concat(t)}let i=e[0];typeof i=="function"&&(i=i(n,t),i===n)||s===void 0&&i==null||(i=dt(i),s===void 0||Ne(n)&&Ne(i)&&!Array.isArray(i)?Rn(n,i):ve(r,s,i))}function na(...[r,e]){const t=dt(r||{}),s=Array.isArray(t);if(typeof t!="object"&&typeof t!="function")throw new Error(`Unexpected type ${typeof t} received when initializing 'createStore'. Expected an object.`);const n=Pn(t);Xn.registerGraph({value:t,name:e&&e.name});function i(...l){Yn(()=>{s&&l.length===1?sa(t,l[0]):Tt(t,l)})}return[n,i]}const ns=Symbol("store-root");function Is(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function rt(r,e,t,s,n){if(Is(t))return;const i=e[t];if(r===i)return;const l=Array.isArray(r);if(t!==ns&&(!Ne(r)||!Ne(i)||l!==Array.isArray(i)||n&&r[n]!==i[n])){ve(e,t,r);return}if(l){if(r.length&&i.length&&(!s||n&&r[0]&&r[0][n]!=null)){let c,d,u,h,f,p,b,_;for(u=0,h=Math.min(i.length,r.length);u<h&&(i[u]===r[u]||n&&i[u]&&r[u]&&i[u][n]&&i[u][n]===r[u][n]);u++)rt(r[u],i,u,s,n);const w=new Array(r.length),C=new Map;for(h=i.length-1,f=r.length-1;h>=u&&f>=u&&(i[h]===r[f]||n&&i[h]&&r[f]&&i[h][n]&&i[h][n]===r[f][n]);h--,f--)w[f]=i[h];if(u>f||u>h){for(d=u;d<=f;d++)ve(i,d,r[d]);for(;d<r.length;d++)ve(i,d,w[d]),rt(r[d],i,d,s,n);i.length>r.length&&ve(i,"length",r.length);return}for(b=new Array(f+1),d=f;d>=u;d--)p=r[d],_=n&&p?p[n]:p,c=C.get(_),b[d]=c===void 0?-1:c,C.set(_,d);for(c=u;c<=h;c++)p=i[c],_=n&&p?p[n]:p,d=C.get(_),d!==void 0&&d!==-1&&(w[d]=i[c],d=b[d],C.set(_,d));for(d=u;d<r.length;d++)d in w?(ve(i,d,w[d]),rt(r[d],i,d,s,n)):ve(i,d,r[d])}else for(let c=0,d=r.length;c<d;c++)rt(r[c],i,c,s,n);i.length>r.length&&ve(i,"length",r.length);return}const o=Object.keys(r);for(let c=0,d=o.length;c<d;c++)Is(o[c])||rt(r[o[c]],i,o[c],s,n);const a=Object.keys(i);for(let c=0,d=a.length;c<d;c++)r[a[c]]===void 0&&ve(i,a[c],void 0)}function ia(r,e={}){const{merge:t,key:s="id"}=e,n=dt(r);return i=>{if(!Ne(i)||!Ne(n))return n;const l=rt(n,{[ns]:i},ns,t,s);return l===void 0?i:l}}const An=new WeakMap;function Gs(r,e){const[t,s]=na(e),n={id:r,type:e.type,raw:t};return An.set(n,i=>s(ia(i,{key:"_id",merge:!1}))),n}const[nr,Rt]=R([]);function oa(){Rt([])}function In(r){Rt(e=>e.filter(t=>t.id!==r))}function la(r,e){const t=nr();let s=!1;const n=[];for(const i of t){const l=r[i.id];if(l===null){s=!0;continue}if(l!==void 0){const o=e[i.id];if(o){const a=An.get(i);a==null||a(o)}}n.push(i)}s&&Rt(n)}const[aa,Ns]=R(null),[ca,Ds]=R(null),[lt,Fs]=R(null),[ir,zs]=R({});function Gn(r,e,t){return isNaN(t.minX)||isNaN(t.maxX)||isNaN(t.minY)||isNaN(t.maxY)?!0:r>=t.minX&&r<=t.maxX&&e>=t.minY&&e<=t.maxY}function hs(r){const e=r.match(/^([WE])(\d+)([NS])(\d+)$/);if(!e)return null;const[,t,s,n,i]=e,l=t==="W"?-(parseInt(s,10)+1):parseInt(s,10),o=n==="N"?-(parseInt(i,10)+1):parseInt(i,10);return{x:l,y:o}}function $t(r,e){const t=r<0?"W":"E",s=e<0?"N":"S",n=r<0?-r-1:r,i=e<0?-e-1:e;return`${t}${n}${s}${i}`}function Nn(r){const e=r;if(!e)return!1;const t=e.tagName??"";return t==="INPUT"||t==="TEXTAREA"?!0:e.isContentEditable===!0}function da(r){const e=t=>{if(Nn(t.target))return;const s=r.currentRoom(),n=s?hs(s):null;if(!n)return;const i=r.worldBounds(),l=(o,a)=>!i||Gn(o,a,i);switch(t.key){case"ArrowLeft":t.preventDefault(),l(n.x-1,n.y)&&r.onMove(n.x-1,n.y);break;case"ArrowRight":t.preventDefault(),l(n.x+1,n.y)&&r.onMove(n.x+1,n.y);break;case"ArrowUp":t.preventDefault(),l(n.x,n.y-1)&&r.onMove(n.x,n.y-1);break;case"ArrowDown":t.preventDefault(),l(n.x,n.y+1)&&r.onMove(n.x,n.y+1);break}};window.addEventListener("keydown",e),$e(()=>window.removeEventListener("keydown",e))}var ua=k('<div style=text-align:center;display:flex;flex-direction:column;align-items:center;gap:6px><div style=font-size:14px;font-weight:600;color:#f85149>You have no rooms!</div><button style="padding:4px 12px;border-radius:4px;border:1px solid #238636;background:#1a3a2a;color:#3fb950;font-size:12px;cursor:pointer">Place Spawn'),ha=k('<div style=text-align:center;display:flex;flex-direction:column;align-items:center;gap:6px><div style=font-size:14px;font-weight:600;color:#f85149>You lost all your spawns!</div><button style="padding:4px 12px;border-radius:4px;border:1px solid #da3633;background:#3d1a1a;color:#f85149;font-size:12px;cursor:pointer">Respawn'),fa=k("<span>Choose new flag position"),vr=k("<span>"),pa=k("<span>Select structure type, then click to build — Ctrl+click to remove construction sites");const{log:Hs,warn:ga,error:Bs}=ft("build"),Us={COLOR_RED:1,COLOR_PURPLE:2,COLOR_BLUE:3,COLOR_CYAN:4,COLOR_GREEN:5,COLOR_YELLOW:6,COLOR_ORANGE:7,COLOR_BROWN:8,COLOR_GREY:9,COLOR_WHITE:10},or={spawn:{0:0,1:1,2:1,3:1,4:1,5:1,6:1,7:2,8:3},extension:{0:0,1:0,2:5,3:10,4:20,5:30,6:40,7:50,8:60},link:{1:0,2:0,3:0,4:0,5:2,6:3,7:4,8:6},road:{0:2500,1:2500,2:2500,3:2500,4:2500,5:2500,6:2500,7:2500,8:2500},constructedWall:{1:0,2:2500,3:2500,4:2500,5:2500,6:2500,7:2500,8:2500},rampart:{1:0,2:2500,3:2500,4:2500,5:2500,6:2500,7:2500,8:2500},storage:{1:0,2:0,3:0,4:1,5:1,6:1,7:1,8:1},tower:{1:0,2:0,3:1,4:1,5:2,6:2,7:3,8:6},observer:{1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:1},powerSpawn:{1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:1},extractor:{1:0,2:0,3:0,4:0,5:0,6:1,7:1,8:1},terminal:{1:0,2:0,3:0,4:0,5:0,6:1,7:1,8:1},lab:{1:0,2:0,3:0,4:0,5:0,6:3,7:6,8:10},container:{0:5,1:5,2:5,3:5,4:5,5:5,6:5,7:5,8:5},nuker:{1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:1},factory:{1:0,2:0,3:0,4:0,5:0,6:0,7:1,8:1}},[Xe,ct]=R("view"),[st,Dn]=R({name:"",color:"COLOR_WHITE",secondaryColor:"COLOR_WHITE"}),[We,is]=R(null),[fs,os]=R(null),[ut,dr]=R({structureType:"",structureName:""});Qs(()=>{ue(()=>{const r=ut().structureType;if(!r)return;const e=lt()??0,t=or[r];if(!t)return;const s=Ve()==="empty"&&r==="spawn"?Math.max(t[e]??0,1):t[e]??0;if(s===2500)return;(ir()[r]??0)>=s&&(dr({structureType:"",structureName:""}),Ge())})});function Ge(){is(null)}function ls(){os(null)}function ma(){dr({structureType:"",structureName:""})}function ya(r,e){const t=ae(),s=ut(),n=We();if(!t||!s.structureType||!n){ga("missing requirements",{hasClient:!!t,structureType:s.structureType,pending:n});return}if(Ve()==="empty"&&s.structureType==="spawn"){Hs("placing spawn",{room:r,x:n.tx,y:n.ty,name:s.structureName||void 0,shard:e??void 0}),t.http.game.placeSpawn(r,n.tx,n.ty,s.structureName||"Spawn 1",e??void 0).then(()=>(he("Spawn placed successfully","success"),Ge(),t.stores.user.refreshWorldStatus())).catch(i=>{Bs("place spawn failed:",i),he(`Failed to place spawn: ${i.message}`,"error")});return}Hs("creating construction site",{room:r,x:n.tx,y:n.ty,structureType:s.structureType,name:s.structureName||void 0,shard:e??void 0}),t.http.game.createConstruction(r,n.tx,n.ty,s.structureType,s.structureName||void 0,e??void 0).then(()=>{he(`Construction site for ${s.structureType} created`,"success"),Ge()}).catch(i=>{Bs("create construction failed:",i),he(`Failed to create construction site: ${i.message}`,"error")})}function wa(){ct("view"),Ge(),ls(),ma()}function Ws(){const r=Xe(),e=We(),t=fs(),s=Ve();if(s==="empty")return(()=>{var n=ua(),i=n.firstChild,l=i.nextSibling;return l.$$click=()=>{ct("build"),dr({structureType:"spawn",structureName:""})},n})();if(s==="lost")return(()=>{var n=ha(),i=n.firstChild,l=i.nextSibling;return l.$$click=()=>{const o=ae();o&&o.http.user.respawn().then(()=>{he("Respawn successful","success"),o.stores.user.refreshWorldStatus()}).catch(a=>{he(`Respawn failed: ${a.message}`,"error")})},n})();if((t==null?void 0:t.type)==="moveFlag")return fa();if(r==="flag")return(()=>{var n=vr();return m(n,e?"Confirm position":"Choose position"),n})();if(r==="build"){const n=ut(),i=lt(),l=ir(),o=n.structureType,a=" — Ctrl+click to remove construction sites";if(!o)return pa();const c=or[o],d=(c==null?void 0:c[i??0])??0,u=l[o]??0,h=o.replace(/([A-Z])/g," $1").trim();return d===2500?(()=>{var f=vr();return m(f,`Click to build ${h} (${u}/∞)${a}`),f})():(()=>{var f=vr();return m(f,`Click to build ${h} (${u}/${d})${a}`),f})()}return null}be(["click"]);var va=k("<div style=width:100%;height:100%;position:relative><div style=width:100%;height:100%>"),ba=k('<div style="position:absolute;top:12px;left:50%;transform:translateX(-50%);padding:6px 16px;border-radius:6px;background:rgba(13, 17, 23, 0.65);border:1px solid rgba(48, 54, 61, 0.6);font-size:13px;font-weight:500;color:#c9d1d9;user-select:none;z-index:10">'),xa=k('<div style="position:absolute;top:8px;right:8px;padding:4px 10px;border-radius:4px;background:rgba(13, 17, 23, 0.8);border:1px solid #30363d;font-size:12px;color:#8b949e;z-index:10">Tick ');const{log:_t,error:St}=ft("room");function $a(r){let e,t=null,s=null,n=null,i=null;const[l,o]=R(null),[a,c]=R(null),[d,u]=R(null),[h,f]=R("");return Lt(async()=>{if(!e)return;const p=await ds.create(e);o(p)}),$e(()=>{t==null||t.destroy(),t=null,s==null||s.destroy(),s=null,n==null||n.destroy(),n=null;const p=l();p&&p.destroy()}),ue(()=>{const p=ae();if(!p)return;const b=r.room,_=r.shard;c(null),u(null),f(""),Ar(null),oa(),Ns(null),Ds(null),Fs(null),zs({});const w=new as;let C=!1;p.stores.room.terrain(b,_).then(E=>{C||c({room:b,data:E})}).catch(E=>{C||St(`terrain load failed for ${b}:`,E)}),w.add(p.stores.room.subscribe(b,_)),w.add(p.stores.room.on("room:error",E=>{he(`Room subscription error (${E.room}): ${E.message}`,"error",8e3)})),w.add(p.stores.room.on("room:update",E=>{var S,I;let T=0;const v={};let P=0,x=null;for(const L in E.objects){T++;const G=E.objects[L];if(!G)continue;const A=G.type;if(typeof A=="string")if(A==="constructionSite"){const O=G.structureType;typeof O=="string"&&(v[O]=(v[O]||0)+1)}else v[A]=(v[A]||0)+1;if(A==="controller"&&typeof G.user=="string"){const O=G.user,$=((I=(S=E.users)==null?void 0:S[O])==null?void 0:I.username)??O;x={userId:O,username:$},typeof G.level=="number"&&(P=G.level)}}E.diff||_t(`objects loaded — ${b}: ${T} objects, tick=${E.gameTime}`),u({objects:E.objects,diff:E.diff,users:E.users}),f(E.visual),Ar(E.gameTime??null),mo(E.gameTime),Ns(T),Ds(x),Fs(P||null),zs(v)})),$e(()=>{C=!0,w.dispose()})}),ue(()=>{const p=l();if(!p)return;r.room,r.shard,wa(),p.hoverLayer.clearPendingTile(),i==null||i.destroy(),i=null,p.clear(),p.resetView(),t==null||t.destroy(),t=null,s==null||s.destroy(),s=null,n==null||n.destroy(),n=null;const b=Qt(a);b&&b.room===r.room&&(_t(`terrain applied immediately (pre-loaded) — ${r.room}`),i=Os(b.data),p.world.addChildAt(i,0),p.bringNavOverlayToTop())}),ue(()=>{const p=l();if(!p)return;const b=r.room,_=r.shard,w=hs(b);if(w&&r.onNavigate){const C=r.onNavigate,E=Ss(),T=(P,x)=>!E||Gn(P,x,E),v=P=>{C(P,_)};da({currentRoom:()=>r.room,worldBounds:Ss,onMove:(P,x)=>v($t(P,x))}),p.setupNavigationZones({west:T(w.x-1,w.y)?()=>v($t(w.x-1,w.y)):void 0,east:T(w.x+1,w.y)?()=>v($t(w.x+1,w.y)):void 0,north:T(w.x,w.y-1)?()=>v($t(w.x,w.y-1)):void 0,south:T(w.x,w.y+1)?()=>v($t(w.x,w.y+1)):void 0})}}),ue(()=>{const p=Xe(),b=l();p==="view"&&b&&(Ge(),b.hoverLayer.clearPendingTile())}),ue(()=>{const p=l(),b=We();p&&(b?p.hoverLayer.setPendingTile(b.tx,b.ty):p.hoverLayer.clearPendingTile())}),ue(()=>{const p=l(),b=a();if(!(!p||!b||b.room!==r.room)){if(i!=null&&i.parent){_t(`terrain already in scene, skipping — ${r.room}`);return}_t(`terrain applied (async) — ${r.room}`),i=Os(b.data),p.world.addChildAt(i,0),p.bringNavOverlayToTop()}}),ue(()=>{var E,T;const p=l(),b=d();if(!p||!b)return;const{objects:_,diff:w,users:C}=b;if(t||(_t(`object layer created — ${r.room}`),t=new Vl(p.app.ticker,rs(),(E=Or())==null?void 0:E._id,(T=Or())==null?void 0:T.badge,C),t.container.label="objects",p.world.addChild(t.container),p.bringNavOverlayToTop(),s=new Xl(p.app.ticker),s.container.label="animations",p.world.addChild(s.container),n=new Kl,p.world.addChild(n.container),p.bringNavOverlayToTop(),p.setTileHandlers((v,P)=>{},(v,P,x)=>{const S=r.room,I=r.shard,L=Xe(),G=fs();if((G==null?void 0:G.type)==="moveFlag"){const N=ae();if(!N)return;const{name:z,room:H,color:X,secondaryColor:te}=G;N.http.game.removeFlag(H,z).then(()=>N.http.game.createFlag(S,v,P,z,X,te,I??void 0)).then(()=>{he(`Flag "${z}" moved`,"success"),ls()}).catch(K=>{St("move flag failed:",K),he(`Failed to move flag "${z}"`,"error"),ls()});return}if(L==="flag"){const N=We();if(!N||N.tx!==v||N.ty!==P){is({tx:v,ty:P}),p.hoverLayer.setPendingTile(v,P);return}const z=ae();if(!z)return;const H=st(),X=H.name.trim();if(!X){he("Flag name is required","error");return}const te=Us[H.color]??0,K=Us[H.secondaryColor]??0;z.http.game.createFlag(S,v,P,X,te,K,I??void 0).then(()=>{he(`Flag "${X}" created`,"success"),Ge(),p.hoverLayer.clearPendingTile(),z.http.game.genUniqueFlagName().then(D=>Dn(B=>({...B,name:D.name}))).catch(D=>St("gen unique flag name failed:",D))}).catch(D=>St("create flag failed:",D));return}if(L==="build"){if(!x&&!ut().structureType){he("Select a structure type first","error");return}if(x){if(!t)return;const z=t.getObjectsAtTile(v,P).filter(({obj:X})=>X.type==="constructionSite");if(z.length===0){he("No construction sites on this tile","error");return}const H=ae();if(!H)return;H.http.game.removeConstructionSite(S,z.map(({id:X})=>X),I??void 0).then(()=>{he(`Removed ${z.length} construction site${z.length>1?"s":""}`,"success"),Ge(),p.hoverLayer.clearPendingTile()}).catch(X=>{St("remove construction sites failed:",X),he(`Failed to remove construction sites: ${X.message}`,"error")});return}is({tx:v,ty:P}),p.hoverLayer.setPendingTile(v,P),ya(S,I);return}if(Ge(),p.hoverLayer.clearPendingTile(),!t)return;const A=t.getObjectsAtTile(v,P);if(A.length===0){x||(Rt([]),p.hoverLayer.clearSelection());return}let O=[...nr()];if(x){const N=new Set(A.map(H=>H.id));if(O.some(H=>N.has(H.id)))O=O.filter(H=>!N.has(H.id));else{const H=A.filter(({id:X})=>!O.some(te=>te.id===X)).map(({id:X,obj:te})=>Gs(X,te));O=[...O,...H]}}else O=A.map(({id:N,obj:z})=>Gs(N,z));Rt(O);const $=O.map(({id:N,type:z})=>({id:N,type:z,visual:t.getVisualById(N)})).filter(N=>N.visual!=null);p.hoverLayer.setSelectedObjects($)})),w&&la(w,_),t.update(_,w,C),s){s.clear();const v=(Ir()??2e3)*.6;for(const P in _){const x=_[P];if(!x||x.type!=="creep")continue;const S=x.actionLog;if(S){if(S.harvest){const I=S.harvest;s.addHarvest(I.x,I.y,x.x,x.y,v)}if(S.upgradeController){const I=S.upgradeController;s.addUpgradeController(x.x,x.y,I.x,I.y,v)}if(S.build){const I=S.build;s.addBuild(x.x,x.y,I.x,I.y,v),t==null||t.triggerBuildAt(I.x,I.y,v)}}}}}),ue(()=>{const p=h();n==null||n.update(p)}),ue(()=>{t==null||t.setShowLabels(rs())}),(()=>{var p=va(),b=p.firstChild;return Mt(_=>e=_,b),m(p,(()=>{var _=ne(()=>!!Ws());return()=>_()&&(()=>{var w=ba();return m(w,Ws),F(C=>W(w,"pointer-events",Ve()==="empty"||Ve()==="lost"?"auto":"none")),w})()})(),null),m(p,(()=>{var _=ne(()=>tr()!==null);return()=>_()&&(()=>{var w=xa();return w.firstChild,m(w,tr,null),w})()})(),null),p})()}var _a=k("<div style=position:fixed;bottom:16px;right:16px;display:flex;flex-direction:column;gap:8px;z-index:9999;pointer-events:none>"),Sa=k('<div style="padding:10px 16px;border-radius:6px;font-size:13px;color:#fff;box-shadow:0 4px 12px rgba(0,0,0,0.4);max-width:320px;word-break:break-word;pointer-events:auto;animation:toast-in 0.2s ease">');function Ca(){return(()=>{var r=_a();return m(r,M(fe,{get each(){return ao()},children:e=>(()=>{var t=Sa();return m(t,()=>e.message),F(s=>W(t,"background",e.type==="error"?"#da3633":"#238636")),t})()})),r})()}const[Ct,ka]=R(!0),[Qe,Ta]=R(!0);function Fn(){ka(r=>!r)}function zn(){Ta(r=>!r)}var Ma=k("<div style=overflow:auto;padding:8px>"),Ea=k("<div style=width:4px;flex-shrink:0;cursor:col-resize>"),Pa=k('<div style=flex:1;display:flex;flex-direction:column;overflow:hidden><div style=flex:1;overflow:auto;padding:8px></div><form style="display:flex;gap:6px;padding:8px;border-top:1px solid #30363d"><span style=color:#8b949e;font-size:13px;line-height:28px>&gt;</span><input type=text placeholder="Game.creeps.Harvester1.moveTo(10, 10)"style="flex:1;padding:6px 8px;border-radius:4px;border:1px solid #30363d;background:#161b22;color:#c9d1d9;font-size:12px;font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace"><button type=submit style="padding:6px 12px;border-radius:4px;border:none;background:#238636;color:#fff;font-size:12px;cursor:pointer">Run'),Oa=k("<div style=flex:1;display:flex;overflow:hidden>"),Ra=k('<div style=display:flex;flex-direction:column;height:100%;background:#0d1117><div style="height:32px;flex-shrink:0;padding:0 10px;border-bottom:1px solid #30363d;display:flex;align-items:center;gap:6px"><button>Log</button><button>Console</button><div style=margin-left:auto><button style=background:transparent;border:none;color:#8b949e;font-size:11px;cursor:pointer>Clear'),La=k("<div style=color:#484f58;font-style:italic>No log output yet…"),Aa=k("<div style=margin-bottom:4px;color:#f85149;white-space:pre-wrap;word-break:break-word>"),Ia=k("<div style=margin-bottom:4px;color:#c9d1d9;white-space:pre-wrap;word-break:break-word>"),Ga=k("<div style=color:#484f58;font-style:italic>No command results yet…"),Na=k("<div style=margin-bottom:4px;color:#58a6ff;white-space:pre-wrap;word-break:break-word>");const{error:Da}=ft("console");function Fa(r){const[e,t]=R([]),[s,n]=R(""),[i,l]=R(!0),[o,a]=R(kt(ce.consoleSplit,50)),[c,d]=R(!1);let u,h,f,p=0;Lt(()=>{const x=ae();if(!x)return;const S=new as;S.add(x.stores.user.subscribe("console")),S.add(x.stores.user.on("user:console",I=>{const L=I.messages,G={id:p++,log:L.log??[],results:L.results??[],error:L.error??[]};t(A=>{const O=[...A,G];return O.length>200?O.slice(O.length-200):O})})),$e(()=>S.dispose())}),ue(()=>{e(),i()&&requestAnimationFrame(()=>{Ct()&&u&&(u.scrollTop=u.scrollHeight),Qe()&&h&&(h.scrollTop=h.scrollHeight)})});const b=(x,S)=>{var L,G;const I=!x&&!S;I&&!r.isCollapsed&&((L=r.onToggle)==null||L.call(r)),!I&&r.isCollapsed&&((G=r.onToggle)==null||G.call(r))};ue(()=>{b(Ct(),Qe())});const _=x=>{x.preventDefault(),d(!0);const I=f.getBoundingClientRect(),L=A=>{const O=(A.clientX-I.left)/I.width*100,$=Math.max(15,Math.min(85,O));a($),Vt(ce.consoleSplit,$)},G=()=>{d(!1),window.removeEventListener("pointermove",L),window.removeEventListener("pointerup",G)};window.addEventListener("pointermove",L),window.addEventListener("pointerup",G)},w=async x=>{x.preventDefault();const S=ae();if(!(!S||!s().trim()))try{await S.http.user.console(s().trim(),r.shard??"shard0"),n("")}catch(I){Da("command failed:",I)}},C=x=>({background:x?"#30363d":"transparent",border:`1px solid ${x?"#58a6ff":"transparent"}`,color:x?"#c9d1d9":"#8b949e","font-size":"12px",cursor:"pointer",padding:"2px 10px","border-radius":"4px"}),E=()=>e().flatMap(x=>x.log),T=()=>e().flatMap(x=>x.error),v=()=>e().flatMap(x=>x.results),P={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"};return(()=>{var x=Ra(),S=x.firstChild,I=S.firstChild,L=I.nextSibling,G=L.nextSibling,A=G.firstChild;return er(I,"click",Fn,!0),er(L,"click",zn,!0),A.$$click=()=>t([]),m(x,M(q,{get when(){return!r.isCollapsed},get children(){var O=Oa();return Mt($=>f=$,O),m(O,M(q,{get when(){return Ct()},get children(){var $=Ma();$.addEventListener("scroll",()=>{u&&l(u.scrollHeight-u.scrollTop-u.clientHeight<20)});var N=u;return typeof N=="function"?Mt(N,$):u=$,m($,(()=>{var z=ne(()=>E().length===0&&T().length===0);return()=>z()&&La()})(),null),m($,M(fe,{get each(){return T()},children:z=>(()=>{var H=Aa();return H.innerHTML=z,H})()}),null),m($,M(fe,{get each(){return E()},children:z=>(()=>{var H=Ia();return H.innerHTML=z,H})()}),null),F(z=>de($,{...Qe()?{width:`${o()}%`,"flex-shrink":0}:{flex:1},...P},z)),$}}),null),m(O,M(q,{get when(){return ne(()=>!!Ct())()&&Qe()},get children(){var $=Ea();return $.$$pointerdown=_,F(N=>W($,"background",c()?"#388bfd":"#21262d")),$}}),null),m(O,M(q,{get when(){return Qe()},get children(){var $=Pa(),N=$.firstChild,z=N.nextSibling,H=z.firstChild,X=H.nextSibling;X.nextSibling,N.addEventListener("scroll",()=>{h&&l(h.scrollHeight-h.scrollTop-h.clientHeight<20)});var te=h;return typeof te=="function"?Mt(te,N):h=N,m(N,(()=>{var K=ne(()=>v().length===0);return()=>K()&&Ga()})(),null),m(N,M(fe,{get each(){return v()},children:K=>(()=>{var D=Na();return D.innerHTML=K,D})()}),null),z.addEventListener("submit",w),X.$$input=K=>n(K.currentTarget.value),F(K=>de(N,{...P},K)),F(()=>X.value=s()),$}}),null),F($=>W(O,"user-select",c()?"none":"auto")),O}}),null),F(O=>{var $=C(Ct()),N=C(Qe());return O.e=de(I,$,O.e),O.t=de(L,N,O.t),O},{e:void 0,t:void 0}),x})()}be(["click","pointerdown","input"]);var za=k('<div style="display:grid;grid-template-columns:1fr 1fr;gap:1px;background:#21262d;font-size:10px">'),Ha=k('<div style="padding:3px 8px;background:#0d1117;color:#8b949e;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">'),Ba=k('<div style="padding:3px 8px;background:#0d1117;color:#c9d1d9;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-variant-numeric:tabular-nums">'),Ua=k('<div style="background:#21262d;border-top:1px solid #30363d;font-size:10px"><div style="padding:4px 8px;background:#161b22;color:#8b949e;font-weight:600">Store Contents</div><div style="display:grid;grid-template-columns:1fr 1fr;gap:1px;background:#21262d">'),Wa=k('<div style="padding:3px 8px;background:#0d1117;color:#8b949e">'),qa=k('<div style="padding:3px 8px;background:#0d1117;color:#c9d1d9;font-variant-numeric:tabular-nums">'),Va=k('<div style=padding:8px;display:flex;flex-direction:column;gap:8px;background:#0d1117><label>Primary color<select></select></label><label>Secondary color<select></select></label><button style="color:#fff;border:none;border-radius:4px;padding:6px 8px;font-size:12px;transition:opacity 150ms ease, background 150ms ease">Apply color</button><button style="color:#fff;border:none;border-radius:4px;padding:6px 8px;font-size:12px;cursor:pointer;transition:background 150ms ease"></button><button style="color:#fff;border:none;border-radius:4px;padding:6px 8px;font-size:12px;cursor:pointer;margin-top:4px;transition:background 150ms ease">'),qs=k("<option>"),Xa=k('<div style="border-radius:6px;border:1px solid #30363d;margin-bottom:6px;overflow:hidden"><div style="display:flex;align-items:center;gap:7px;padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d"><div style=width:8px;height:8px;border-radius:50%;flex-shrink:0></div><span style=font-size:11px;font-weight:600;color:#c9d1d9;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap></span><span style=font-size:10px;color:#484f58;flex-shrink:0;margin-right:2px>(<!>,<!>)</span><button title=Deselect style="background:transparent;border:none;color:#8b949e;cursor:pointer;padding:0 4px;font-size:14px;line-height:1;display:flex;align-items:center;justify-content:center">×'),Ya=k("<span style=font-weight:400;color:#8b949e;margin-left:5px>"),ja=k("<div style=flex:1;overflow:auto;min-height:0;padding:8px>"),Za=k("<div style=color:#484f58;font-style:italic;font-size:12px>Click a tile to select objects…");const{log:Vs,error:Ka}=ft("SelectionList"),Ja={creep:"#f0883e",spawn:"#58a6ff",extension:"#79c0ff",tower:"#3fb950",container:"#8b949e",storage:"#d29922",link:"#a371f7",rampart:"#58a6ff",road:"#484f58",wall:"#21262d",extractor:"#8b949e",lab:"#f778ba",terminal:"#d29922",observer:"#79c0ff",powerSpawn:"#f0883e",nuker:"#f85149",factory:"#8b949e",invaderCore:"#f85149",source:"#d29922",mineral:"#79c0ff",deposit:"#d29922",controller:"#58a6ff",powerBank:"#f0883e",portal:"#a371f7",energy:"#d29922"},Qa={creep:"Creep",spawn:"Spawn",extension:"Extension",tower:"Tower",container:"Container",storage:"Storage",link:"Link",rampart:"Rampart",road:"Road",wall:"Wall",extractor:"Extractor",lab:"Lab",terminal:"Terminal",observer:"Observer",powerSpawn:"Power Spawn",nuker:"Nuker",factory:"Factory",invaderCore:"Invader Core",source:"Source",mineral:"Mineral",deposit:"Deposit",controller:"Controller",powerBank:"Power Bank",portal:"Portal",energy:"Energy",flag:"Flag"},ec=new Set(["x","y","type","id","name","user","_id","room","hitsMax","energyCapacity"]),Xs=new Set(["hits","energy","energyCapacity","store","progress","progressTotal","nextDecayTime"]);function tc(r){return typeof r=="number"?String(r):typeof r=="string"?r:typeof r=="boolean"?r?"yes":"no":null}function Hn(r){const e=()=>{const t=r.item.raw,s=[];for(const n in t){if(ec.has(n))continue;const i=t[n],l=n;let o=tc(i);if(n==="hits"&&typeof t.hitsMax=="number"&&(o=`${i} / ${t.hitsMax}`),n==="energy"&&typeof t.energyCapacity=="number"&&(o=`${i} / ${t.energyCapacity}`),n==="nextDecayTime"&&typeof i=="number"){const a=tr();a!==null&&(o=String(i-a))}o!==null&&s.push({key:l,value:o})}return s.sort((n,i)=>{const l=Xs.has(n.key)?0:1,o=Xs.has(i.key)?0:1;return l-o}),s};return M(q,{get when(){return e().length>0},get children(){var t=za();return m(t,M(fe,{get each(){return e()},children:s=>[(()=>{var n=Ha();return m(n,()=>s.key),n})(),(()=>{var n=Ba();return m(n,()=>s.value),n})()]})),t}})}function rc(r){const e=()=>{const t=r.store||{},s=[];for(const n in t)s.push([n,t[n]]);return s};return M(q,{get when(){return e().length>0},get children(){var t=Ua(),s=t.firstChild,n=s.nextSibling;return m(n,M(fe,{get each(){return e()},children:([i,l])=>[(()=>{var o=Wa();return m(o,i),o})(),(()=>{var o=qa();return m(o,l),o})()]})),t}})}function sc(r){const e=()=>r.item.raw.store;return[M(Hn,{get item(){return r.item}}),M(rc,{get store(){return e()}})]}const Ys=[{label:"Red",value:1},{label:"Purple",value:2},{label:"Blue",value:3},{label:"Cyan",value:4},{label:"Green",value:5},{label:"Yellow",value:6},{label:"Orange",value:7},{label:"Brown",value:8},{label:"Grey",value:9},{label:"White",value:10}];function nc(r){const e=()=>r.item.raw,t=()=>typeof e().name=="string"?e().name:"",s=()=>typeof e().room=="string"?e().room:"",n=()=>typeof e().color=="number"?e().color:1,i=()=>typeof e().secondaryColor=="number"?e().secondaryColor:1,[l,o]=R(n()),[a,c]=R(i());ue(()=>{o(n()),c(i())});const d=()=>l()!==n()||a()!==i(),u=()=>{const T=ae();if(!T)return;const v=l(),P=a();Vs(`changeFlagColor: name="${t()}" room=${s()} primary=${v} secondary=${P}`),T.http.game.changeFlagColor(s(),t(),v,P).then(()=>Vs("changeFlagColor OK")).catch(x=>Ka("changeFlagColor FAILED:",x))},h=()=>{const T=fs();return(T==null?void 0:T.type)==="moveFlag"&&T.id===r.item.id},f=()=>{if(h()){os(null);return}os({type:"moveFlag",id:r.item.id,name:t(),room:s(),color:l(),secondaryColor:a()})},[p,b]=R(!1);let _=null;const w=()=>{if(!p()){b(!0),_=setTimeout(()=>{b(!1)},3e3);return}_&&(clearTimeout(_),_=null),b(!1);const T=ae();if(!T)return;const v=r.item.id;T.http.game.removeFlag(s(),t()).then(()=>{In(v)}).catch(()=>{})},C={background:"#010409",color:"#c9d1d9",border:"1px solid #30363d","border-radius":"4px",padding:"5px 6px","font-size":"12px",width:"100%"},E={display:"flex","flex-direction":"column",gap:"4px","font-size":"11px",color:"#8b949e"};return(()=>{var T=Va(),v=T.firstChild,P=v.firstChild,x=P.nextSibling,S=v.nextSibling,I=S.firstChild,L=I.nextSibling,G=S.nextSibling,A=G.nextSibling,O=A.nextSibling;return x.addEventListener("change",$=>o(Number($.currentTarget.value))),m(x,M(fe,{each:Ys,children:$=>(()=>{var N=qs();return m(N,()=>$.label),F(()=>N.value=$.value),N})()})),L.addEventListener("change",$=>c(Number($.currentTarget.value))),m(L,M(fe,{each:Ys,children:$=>(()=>{var N=qs();return m(N,()=>$.label),F(()=>N.value=$.value),N})()})),G.addEventListener("mouseleave",$=>{d()&&($.currentTarget.style.background="#238636")}),G.addEventListener("mouseenter",$=>{d()&&($.currentTarget.style.background="#2ea043")}),G.$$click=u,A.addEventListener("mouseleave",$=>{h()||($.currentTarget.style.background="#d29922")}),A.addEventListener("mouseenter",$=>{h()||($.currentTarget.style.background="#e3b341")}),A.$$click=f,m(A,()=>h()?"Abort":"Move flag"),O.addEventListener("mouseleave",$=>{p()||($.currentTarget.style.background="#f85149")}),O.addEventListener("mouseenter",$=>{p()||($.currentTarget.style.background="#da3633")}),O.$$click=w,m(O,()=>p()?"Confirm deletion":"Delete flag"),F($=>{var N=E,z=C,H=E,X=C,te=!d(),K=d()?"#238636":"#1f6feb",D=d()?"pointer":"not-allowed",B=d()?1:.6,Y=h()?"#8b949e":"#d29922",V=p()?"#da3633":"#f85149";return $.e=de(v,N,$.e),$.t=de(x,z,$.t),$.a=de(S,H,$.a),$.o=de(L,X,$.o),te!==$.i&&(G.disabled=$.i=te),K!==$.n&&W(G,"background",$.n=K),D!==$.s&&W(G,"cursor",$.s=D),B!==$.h&&W(G,"opacity",$.h=B),Y!==$.r&&W(A,"background",$.r=Y),V!==$.d&&W(O,"background",$.d=V),$},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0}),F(()=>x.value=l()),F(()=>L.value=a()),T})()}const ic={creep:sc,flag:nc};function oc(r){const e=()=>Ja[r.item.type]??"#c9d1d9",t=()=>Qa[r.item.type]??r.item.type,s=()=>ic[r.item.type]||Hn;return(()=>{var n=Xa(),i=n.firstChild,l=i.firstChild,o=l.nextSibling,a=o.nextSibling,c=a.firstChild,d=c.nextSibling,u=d.nextSibling,h=u.nextSibling;h.nextSibling;var f=a.nextSibling;return m(o,t,null),m(o,M(q,{get when(){return ne(()=>typeof r.item.raw.name=="string")()&&r.item.raw.name},children:p=>(()=>{var b=Ya();return m(b,()=>p()),b})()}),null),m(a,()=>r.item.raw.x,d),m(a,()=>r.item.raw.y,h),f.addEventListener("mouseleave",p=>p.currentTarget.style.color="#8b949e"),f.addEventListener("mouseenter",p=>p.currentTarget.style.color="#fff"),f.$$click=()=>In(r.item.id),m(n,M(Si,{get component(){return s()},get item(){return r.item}}),null),F(p=>W(l,"background",e())),n})()}function lc(){return(()=>{var r=ja();return m(r,M(q,{get when(){return nr().length>0},get fallback(){return Za()},get children(){return M(fe,{get each(){return nr()},children:e=>M(oc,{item:e})})}})),r})()}be(["click"]);var ac=k('<div style="padding:8px;border-bottom:1px solid #30363d;flex-shrink:0"><div style="padding:4px 8px;background:#161b22;border-radius:6px;border:1px solid #30363d"><div style=font-size:10px;font-weight:600;color:#8b949e;text-transform:uppercase;letter-spacing:0.04em;margin-bottom:4px> Room</div><div style=font-size:13px;font-weight:600;color:#c9d1d9></div><div style="display:grid;grid-template-columns:auto 1fr;row-gap:1px;margin-top:4px;font-size:11px"><div style="padding:3px 0;color:#8b949e">Shard</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Tick</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Tick duration</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Objects</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Owner</div><div style="padding:3px 0;color:#c9d1d9"></div></div></div><div style="display:grid;grid-template-columns:repeat(3, 1fr);gap:4px;margin-top:8px">'),cc=k('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;font-size:11px;font-weight:600">');const dc=[{mode:"view",label:"View"},{mode:"flag",label:"Flag"},{mode:"build",label:"Build"}];function uc(r){return(()=>{var e=ac(),t=e.firstChild,s=t.firstChild,n=s.nextSibling,i=n.nextSibling,l=i.firstChild,o=l.nextSibling,a=o.nextSibling,c=a.nextSibling,d=c.nextSibling,u=d.nextSibling,h=u.nextSibling,f=h.nextSibling,p=f.nextSibling,b=p.nextSibling,_=t.nextSibling;return m(n,()=>r.room),m(o,()=>r.shard??"—"),m(c,()=>tr()??"—"),m(u,(()=>{var w=ne(()=>!!Ir());return()=>w()?`${Ir()}ms`:"—"})()),m(f,()=>aa()??"—"),m(b,()=>{var w;return((w=ca())==null?void 0:w.username)??"—"}),m(_,M(fe,{each:dc,children:w=>{const C=()=>Xe()===w.mode;return(()=>{var E=cc();return E.$$click=()=>ct(w.mode),m(E,()=>w.label),F(T=>{var v=`1px solid ${C()?"#58a6ff":"#30363d"}`,P=C()?"#1f6feb33":"#161b22",x=C()?"#c9d1d9":"#8b949e";return v!==T.e&&W(E,"border",T.e=v),P!==T.t&&W(E,"background",T.t=P),x!==T.a&&W(E,"color",T.a=x),T},{e:void 0,t:void 0,a:void 0}),E})()}})),e})()}be(["click"]);const[hc,fc]=R("owner");var pc=k('<div style="padding:8px;border-bottom:1px solid #30363d;flex-shrink:0"><div style="padding:4px 8px;background:#161b22;border-radius:6px;border:1px solid #30363d"><div style=font-size:10px;font-weight:600;color:#8b949e;text-transform:uppercase;letter-spacing:0.04em;margin-bottom:4px>Map</div><div style="display:grid;grid-template-columns:auto 1fr;row-gap:1px;font-size:11px;margin-bottom:8px"><div style="padding:3px 0;color:#8b949e">Zoom</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Live</div><div style="padding:3px 0;color:#c9d1d9"></div></div><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px;color:#c9d1d9;cursor:pointer><span>Show room names</span><input type=checkbox></label></div><div style="display:grid;grid-template-columns:repeat(3, 1fr);gap:4px;margin-top:8px">'),gc=k('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;font-size:11px;font-weight:600">');const mc=[{mode:"owner",label:"Owner"},{mode:"mineral",label:"Mineral"},{mode:"none",label:"None"}];function yc(r){return(()=>{var e=pc(),t=e.firstChild,s=t.firstChild,n=s.nextSibling,i=n.firstChild,l=i.nextSibling,o=l.nextSibling,a=o.nextSibling,c=n.nextSibling,d=c.firstChild,u=d.nextSibling,h=t.nextSibling;return m(l,()=>{var f;return((f=r.zoom)==null?void 0:f.toFixed(2))??"—"}),m(a,()=>r.subsActive?"Yes":"No"),u.addEventListener("change",f=>Mn(f.currentTarget.checked)),m(h,M(fe,{each:mc,children:f=>{const p=()=>hc()===f.mode;return(()=>{var b=gc();return b.$$click=()=>fc(f.mode),m(b,()=>f.label),F(_=>{var w=`1px solid ${p()?"#58a6ff":"#30363d"}`,C=p()?"#1f6feb33":"#161b22",E=p()?"#c9d1d9":"#8b949e";return w!==_.e&&W(b,"border",_.e=w),C!==_.t&&W(b,"background",_.t=C),E!==_.a&&W(b,"color",_.a=E),_},{e:void 0,t:void 0,a:void 0}),b})()}})),F(()=>u.checked=Tn()),e})()}be(["click"]);var wc=k('<div style="margin:8px 8px 0;border-radius:6px;overflow:hidden"><div style="padding:4px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:10px;font-weight:600;color:#8b949e;text-transform:uppercase;letter-spacing:0.04em">'),vc=k('<div style="padding:6px 8px;font-size:11px;color:#484f58;font-style:italic">None'),bc=k('<div style="padding:3px 8px;color:#8b949e">Mineral'),xc=k('<div style="padding:3px 8px;color:#79c0ff">'),$c=k('<div style="padding:3px 8px;color:#8b949e">Density'),_c=k('<div style="padding:3px 8px;color:#c9d1d9">'),Sc=k('<div style=font-size:11px><div style="padding:5px 8px;font-weight:600;color:#c9d1d9;font-size:12px;border-bottom:1px solid #21262d"></div><div style="display:grid;grid-template-columns:auto 1fr;row-gap:1px;column-gap:0"><div style="padding:3px 8px;color:#8b949e">Owner</div><div style="padding:3px 8px;color:#c9d1d9">');const Cc=["Low","Medium","High","Ultra"];function kc(r){return Cc[r-1]??String(r)}function js(r){return(()=>{var e=wc(),t=e.firstChild;return m(t,()=>r.label),m(e,M(q,{get when(){return r.info},get fallback(){return vc()},children:s=>(()=>{var n=Sc(),i=n.firstChild,l=i.nextSibling,o=l.firstChild,a=o.nextSibling;return m(i,()=>s().room),m(a,()=>s().owner??"None"),m(l,M(q,{get when(){return s().mineral},get children(){return[bc(),(()=>{var c=xc();return m(c,()=>s().mineral),c})(),$c(),(()=>{var c=_c();return m(c,()=>kc(s().density??0)),c})()]}}),null),n})()}),null),F(s=>{var n=`1px solid ${r.dim?"#21262d":"#30363d"}`,i=r.dim?.6:1;return n!==s.e&&W(e,"border",s.e=n),i!==s.t&&W(e,"opacity",s.t=i),s},{e:void 0,t:void 0}),e})()}var Tc=k("<span style=color:#8b949e;font-size:11px>Checking…"),Mc=k('<div style=margin-top:8px><div style="padding:6px 8px;font-size:11px;font-weight:600;color:#c9d1d9;margin-bottom:6px">Your flags'),Ec=k('<div style=flex:1;overflow:auto;min-height:0;padding:8px><div style="border-radius:6px;border:1px solid #30363d;overflow:hidden;background:#0d1117"><div style="padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:11px;font-weight:600;color:#c9d1d9">Create flag</div><div style=padding:8px;display:flex;flex-direction:column;gap:8px><label style=display:flex;flex-direction:column;gap:4px;font-size:11px;color:#8b949e>Name<input placeholder="Flag name"style="background:#010409;color:#c9d1d9;border-radius:4px;padding:5px 6px;font-size:12px"></label><label style=display:flex;flex-direction:column;gap:4px;font-size:11px;color:#8b949e>Primary color<select style="background:#010409;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:5px 6px;font-size:12px"></select></label><label style=display:flex;flex-direction:column;gap:4px;font-size:11px;color:#8b949e>Secondary color<select style="background:#010409;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:5px 6px;font-size:12px"></select></label><div style=color:#484f58;font-size:11px;line-height:1.4>'),Pc=k("<span style=color:#f85149;font-size:11px>"),Zs=k("<option>"),Oc=k("<div style=margin-top:8px;color:#484f58;font-style:italic;font-size:12px>No flags."),Rc=k('<div style="border-radius:6px;border:1px solid #30363d;margin-bottom:6px;overflow:hidden"><div style="display:flex;align-items:center;gap:7px;padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d"><div style=width:8px;height:8px;border-radius:50%;flex-shrink:0></div><span style=font-size:11px;font-weight:600;color:#c9d1d9;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap></span><span style=font-size:10px;color:#8b949e;flex-shrink:0></span><span style=font-size:10px;color:#484f58;flex-shrink:0;margin-left:4px>(<!>,<!>)');const{error:Lc}=ft("flag"),Ks=["COLOR_WHITE","COLOR_GREY","COLOR_RED","COLOR_PURPLE","COLOR_BLUE","COLOR_CYAN","COLOR_GREEN","COLOR_YELLOW","COLOR_ORANGE","COLOR_BROWN"];function Ac(){const r=c=>{Dn({...st(),...c})},[e,t]=R(null),[s,n]=R(!1);let i=null;ue(()=>{if(Xe()!=="flag"||st().name.trim()!=="")return;const c=ae();c&&c.http.game.genUniqueFlagName().then(d=>{r({name:d.name}),t(null)}).catch(d=>{Lc("gen unique name failed:",d)})});const l=c=>{r({name:c}),t(null),i&&clearTimeout(i);const d=c.trim();if(!d){n(!1);return}n(!0),i=setTimeout(()=>{const u=ae();if(!u){n(!1);return}u.http.game.checkUniqueFlagName(d).then(()=>{t(null)}).catch(h=>{t(h.message)}).finally(()=>{n(!1)})},300)},o=()=>{const c=po(),d=[];for(const[u,h]of Object.entries(c))h&&typeof h=="object"&&"room"in h&&"x"in h&&"y"in h&&d.push([u,h]);return d},a=c=>c===void 0||c<0||c>=it.length?"#8b949e":`#${it[c].toString(16).padStart(6,"0")}`;return(()=>{var c=Ec(),d=c.firstChild,u=d.firstChild,h=u.nextSibling,f=h.firstChild,p=f.firstChild,b=p.nextSibling,_=f.nextSibling,w=_.firstChild,C=w.nextSibling,E=_.nextSibling,T=E.firstChild,v=T.nextSibling,P=E.nextSibling;return b.$$input=x=>l(x.currentTarget.value),m(f,M(q,{get when(){return e()},children:x=>(()=>{var S=Pc();return m(S,x),S})()}),null),m(f,M(q,{get when(){return s()},get children(){return Tc()}}),null),C.addEventListener("change",x=>r({color:x.currentTarget.value})),m(C,M(fe,{each:Ks,children:x=>(()=>{var S=Zs();return S.value=x,m(S,()=>x.replace("COLOR_","")),S})()})),v.addEventListener("change",x=>r({secondaryColor:x.currentTarget.value})),m(v,M(fe,{each:Ks,children:x=>(()=>{var S=Zs();return S.value=x,m(S,()=>x.replace("COLOR_","")),S})()})),m(P,(()=>{var x=ne(()=>!!We());return()=>x()?`Marked at x=${We().tx}, y=${We().ty}. Click again to create the flag, or click elsewhere to move the mark.`:"Click a position in the room to mark it."})()),m(c,M(q,{get when(){return o().length>0},get fallback(){return Oc()},get children(){var x=Mc();return x.firstChild,m(x,M(fe,{get each(){return o()},children:([S,I])=>(()=>{var L=Rc(),G=L.firstChild,A=G.firstChild,O=A.nextSibling,$=O.nextSibling,N=$.nextSibling,z=N.firstChild,H=z.nextSibling,X=H.nextSibling,te=X.nextSibling;return te.nextSibling,m(O,S),m($,()=>I.room),m(N,()=>I.x,H),m(N,()=>I.y,te),F(K=>W(A,"background",a(I.color))),L})()}),null),x}}),null),F(x=>W(b,"border",`1px solid ${e()?"#f85149":"#30363d"}`)),F(()=>b.value=st().name),F(()=>C.value=st().color),F(()=>v.value=st().secondaryColor),c})()}be(["input"]);var Ic=k('<div style=flex:1;overflow:auto;min-height:0;padding:8px><div style="border-radius:6px;border:1px solid #30363d;overflow:hidden;background:#0d1117;margin-bottom:8px"><div style="padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:11px;font-weight:600;color:#c9d1d9">Controller Level </div><div style=padding:8px;font-size:11px;color:#8b949e></div></div><div style="border-radius:6px;border:1px solid #30363d;overflow:hidden;background:#0d1117"><div style="padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:11px;font-weight:600;color:#c9d1d9">Structures</div></div><div style="margin-top:8px;padding:0 4px"><div style=color:#484f58;font-style:italic;font-size:12px>'),Gc=k('<div style="padding:6px 8px;display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid #21262d;font-size:11px;color:#c9d1d9"><span style=text-transform:capitalize></span><span style=color:#8b949e>');function Nc(){const r=Object.keys(or),e=(n,i)=>{const l=or[n];return l?Ve()==="empty"&&n==="spawn"?Math.max(l[i]??0,1):l[i]??0:0},t=(n,i)=>{const l=e(n,i);if(l===2500)return 1/0;const o=ir()[n]??0;return Math.max(0,l-o)},s=n=>{dr({structureType:n,structureName:""})};return(()=>{var n=Ic(),i=n.firstChild,l=i.firstChild;l.firstChild;var o=l.nextSibling,a=i.nextSibling;a.firstChild;var c=a.nextSibling,d=c.firstChild;return m(l,()=>lt()??"?",null),m(o,()=>{const u=Ve();return u==="empty"?"World is empty — place a spawn to claim this room.":u==="lost"?"You lost all your spawns — respawn to continue.":lt()!=null?`RCL ${lt()} — Select a structure type and click a tile to build.`:"No controller — roads and containers only."}),m(a,M(fe,{each:r,children:u=>{const h=()=>lt()??0,f=()=>e(u,h()),p=()=>ir()[u]??0,b=()=>ut().structureType===u,_=()=>f()===2500,w=()=>!_()&&t(u,h())<=0;return M(q,{get when(){return f()>0},get children(){var C=Gc(),E=C.firstChild,T=E.nextSibling;return C.$$click=()=>!w()&&s(u),m(E,()=>u.replace(/([A-Z])/g," $1").trim(),null),m(E,()=>b()&&" ✓",null),m(T,(()=>{var v=ne(()=>!!_());return()=>v()?`${p()}/∞`:`${p()}/${f()}`})(),null),m(T,()=>w()&&" (Max)",null),F(v=>{var P=b()?"#1f3158":"transparent",x=w()?"default":"pointer",S=w()?.5:1;return P!==v.e&&W(C,"background",v.e=P),x!==v.t&&W(C,"cursor",v.t=x),S!==v.a&&W(C,"opacity",v.a=S),v},{e:void 0,t:void 0,a:void 0}),C}})}}),null),m(d,()=>ut().structureType?"Click a tile in the room to build.":"Select a structure type, then click a tile."),n})()}be(["click"]);var Dc=k("<div style=padding-bottom:8px;overflow:auto;min-height:0>"),Fc=k('<div style=display:flex;flex-direction:row;height:100%;background:#0d1117><div style="width:32px;height:100%;display:flex;flex-direction:column;align-items:center;border-right:1px solid #30363d;padding:8px 0;cursor:pointer"></div><div style=flex:1;display:flex;flex-direction:column;overflow:hidden><div style="padding:6px 10px;border-bottom:1px solid #30363d;font-size:12px;font-weight:600;color:#8b949e;display:flex;justify-content:space-between;align-items:center"><span>Properties'),zc=k("<button style=background:transparent;border:none;color:#8b949e;font-size:14px;cursor:pointer;padding:4px>"),Hc=k("<button style=background:transparent;border:none;color:#8b949e;font-size:11px;cursor:pointer>Collapse");function Bc(){return M(q,{get when(){return Xe()==="flag"},get fallback(){return M(q,{get when(){return Xe()==="build"},get fallback(){return M(lc,{})},get children(){return M(Nc,{})}})},get children(){return M(Ac,{})}})}function Uc(r){const e=()=>{var s;(s=r.onToggle)==null||s.call(r)},t=s=>{var n;s.stopPropagation(),(n=r.onToggle)==null||n.call(r)};return(()=>{var s=Fc(),n=s.firstChild,i=n.nextSibling,l=i.firstChild;return l.firstChild,n.$$click=e,m(n,(()=>{var o=ne(()=>!!r.onToggle);return()=>o()&&(()=>{var a=zc();return a.$$click=t,m(a,()=>r.isCollapsed?"▶":"◀"),a})()})()),m(l,(()=>{var o=ne(()=>!!r.onToggle);return()=>o()&&(()=>{var a=Hc();return a.$$click=t,a})()})(),null),m(i,M(q,{get when(){return r.mapMode},get fallback(){return M(uc,{get room(){return r.room??"—"},get shard(){return r.shard??null}})},get children(){return M(yc,{get zoom(){return r.mapZoom},get subsActive(){return r.mapSubsActive}})}}),null),m(i,M(q,{get when(){return r.mapMode},get fallback(){return M(Bc,{})},get children(){var o=Dc();return m(o,M(js,{label:"Selected",get info(){return r.selectedRoomInfo??null}}),null),m(o,M(js,{label:"Cursor",get info(){return r.hoveredRoomInfo??null},dim:!0}),null),o}}),null),s})()}be(["click"]);var Wc=k("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>CPU:</span><span style=color:#c9d1d9>"),qc=k("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Memory:</span><span style=color:#c9d1d9>"),Vc=k("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Zoom:</span><span style=color:#c9d1d9>%"),Xc=k("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Subs:</span><span>"),Yc=k('<div style="display:flex;gap:16px;padding:6px 16px;font-size:12px;color:#8b949e;align-items:center">');function jc(r){const[e,t]=R(null);Lt(()=>{const i=ae();if(!i)return;const l=new as;l.add(i.stores.user.subscribe("cpu")),l.add(i.stores.user.on("user:cpu",o=>{t(o)})),$e(()=>{l.dispose()})});const s=()=>{var o;const i=e();if(!i)return"—";const l=((o=Or())==null?void 0:o.cpu)??"?";return`${i.cpu.toFixed(1)} / ${l}`},n=()=>{const i=e();return i?`${(i.memory/1024).toFixed(1)} KB`:"—"};return(()=>{var i=Yc();return m(i,M(q,{get when(){return e()!==null},get children(){return[(()=>{var l=Wc(),o=l.firstChild,a=o.nextSibling;return m(a,s),l})(),(()=>{var l=qc(),o=l.firstChild,a=o.nextSibling;return m(a,n),l})()]}}),null),m(i,M(q,{get when(){return ne(()=>r.mapZoom!==null)()&&r.mapZoom!==void 0},get children(){return[(()=>{var l=Vc(),o=l.firstChild,a=o.nextSibling,c=a.firstChild;return m(a,()=>(r.mapZoom*100).toFixed(0),c),l})(),(()=>{var l=Xc(),o=l.firstChild,a=o.nextSibling;return m(a,()=>r.mapSubsActive===!1?"paused":"active"),F(c=>W(a,"color",r.mapSubsActive===!1?"#e3b341":"#3fb950")),l})()]}}),null),i})()}var Zc=k('<div style="display:flex;align-items:center;justify-content:space-between;padding:10px 0;border-bottom:1px solid #21262d"><div><div style=font-size:13px;color:#c9d1d9></div></div><button style="flex-shrink:0;margin-left:24px;width:40px;height:20px;border-radius:10px;border:none;cursor:pointer;position:relative;transition:background 0.15s"><div style="position:absolute;top:2px;width:16px;height:16px;border-radius:50%;background:#fff;transition:left 0.15s">'),Kc=k("<div style=font-size:11px;color:#8b949e;margin-top:3px>"),Jc=k("<div style=margin-bottom:24px><div style=font-size:10px;font-weight:700;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:4px>"),Qc=k('<div style="position:absolute;inset:0px;background:rgba(13, 17, 23, 0.96);z-index:100;display:flex;flex-direction:column;overflow:hidden"><div style="display:flex;align-items:center;justify-content:space-between;padding:14px 24px;border-bottom:1px solid #30363d;flex-shrink:0"><span style=font-size:15px;font-weight:600;color:#c9d1d9>Settings</span><button style="background:transparent;border:none;color:#8b949e;font-size:18px;cursor:pointer;line-height:1;padding:2px 6px">✕</button></div><div style="overflow:auto;flex:1;padding:20px 24px"><div style=max-width:480px>');function br(r){return(()=>{var e=Zc(),t=e.firstChild,s=t.firstChild,n=t.nextSibling,i=n.firstChild;return m(s,()=>r.label),m(t,(()=>{var l=ne(()=>!!r.description);return()=>l()&&(()=>{var o=Kc();return m(o,()=>r.description),o})()})(),null),n.$$click=()=>r.onChange(!r.value),F(l=>{var o=r.value?"#238636":"#30363d",a=r.value?"22px":"2px";return o!==l.e&&W(n,"background",l.e=o),a!==l.t&&W(i,"left",l.t=a),l},{e:void 0,t:void 0}),e})()}function xr(r){return(()=>{var e=Jc(),t=e.firstChild;return m(t,()=>r.title),m(e,()=>r.children,null),e})()}function ed(r){return(()=>{var e=Qc(),t=e.firstChild,s=t.firstChild,n=s.nextSibling,i=t.nextSibling,l=i.firstChild;return n.$$click=()=>r.onClose(),m(l,M(xr,{title:"Layout",get children(){return M(br,{label:"Widescreen mode",description:"Sidebar spans full height; console sits below the room view only. When off, the console spans the full width below both the view and the sidebar.",get value(){return kn()},onChange:Jl})}}),null),m(l,M(xr,{title:"Room View",get children(){return M(br,{label:"Show creep labels",description:"Display each creep's name above its sprite.",get value(){return rs()},onChange:Ql})}}),null),m(l,M(xr,{title:"Map View",get children(){return M(br,{label:"Show room names",description:"Render a small room name in the top-left corner of each map tile.",get value(){return Tn()},onChange:Mn})}}),null),e})()}be(["click"]);var td=k('<button style="padding:6px 14px;border-radius:4px;font-size:13px;cursor:pointer;margin:0 4px">'),rd=k('<button style="padding:6px 10px;border-radius:4px;border:1px solid #30363d;background:#21262d;font-size:14px;margin:0 2px">'),sd=k("<div style=flex:1;position:relative;overflow:hidden>"),nd=k('<div style="border-top:1px solid #30363d;overflow:hidden;position:relative"><div style=position:absolute;top:0;left:0;width:100%;height:4px;cursor:row-resize;z-index:10;background:#21262d>'),id=k('<div style="border-left:1px solid #30363d;overflow:hidden;position:relative"><div style=position:absolute;top:0;left:0;width:4px;height:100%;cursor:col-resize;z-index:10;background:#21262d>'),od=k("<div style=display:flex;flex:1;overflow:hidden><div style=display:flex;flex-direction:column;flex:1;overflow:hidden>"),ld=k('<div style=width:100%;height:100%;display:flex;flex-direction:column;overflow:hidden;background:#0d1117><div style="display:flex;border-bottom:1px solid #30363d;align-items:center"><div style=flex:1></div><button style="padding:6px 14px;border-radius:4px;border:none;background:#da3633;color:#fff;font-size:13px;cursor:pointer;margin:0 16px 0 8px">Logout'),ad=k("<div style=display:flex;flex-direction:column;flex:1;overflow:hidden><div style=display:flex;flex:1;overflow:hidden>");const cd=en(()=>tn(()=>import("./CodePanel-kZMDxJko.js"),__vite__mapDeps([0,1,2])).then(r=>({default:r.CodePanel}))),dd=en(()=>tn(()=>import("./MapViewer-DNoUiB29.js"),__vite__mapDeps([3,1,2])).then(r=>({default:r.MapViewer})));function $r(){const r=ar(),e=window.location.pathname.match(new RegExp(`^${r}/room/([A-Za-z0-9]+)`));if(!e)return{room:null,shard:null};const t=e[1].toUpperCase();if(!hs(t))return{room:null,shard:null};const s=new URLSearchParams(window.location.search).get("shard");return{room:t,shard:s}}function _r(r,e){return`${ar()}/room/${r}${e?`?shard=${encodeURIComponent(e)}`:""}`}function ud(r){return`${ar()}/map${r?`?shard=${encodeURIComponent(r)}`:""}`}function Sr(){return window.location.pathname.startsWith(`${ar()}/map`)?{shard:new URLSearchParams(window.location.search).get("shard")}:null}function Cr(r){return(()=>{var e=td();return e.$$click=()=>r.onClick(),m(e,()=>r.children),F(t=>{var s=`1px solid ${r.active?"#388bfd":"#30363d"}`,n=r.active?"#1f3158":"#21262d",i=r.active?"#58a6ff":"#c9d1d9";return s!==t.e&&W(e,"border",t.e=s),n!==t.t&&W(e,"background",t.t=n),i!==t.a&&W(e,"color",t.a=i),t},{e:void 0,t:void 0,a:void 0}),e})()}function Js(r){return(()=>{var e=rd();return e.$$click=()=>r.onClick(),m(e,()=>r.children),F(t=>{var s=r.disabled,n=r.disabled?"#484f58":"#c9d1d9",i=r.disabled?"default":"pointer";return s!==t.e&&(e.disabled=t.e=s),n!==t.t&&W(e,"color",t.t=n),i!==t.a&&W(e,"cursor",t.a=i),t},{e:void 0,t:void 0,a:void 0}),e})()}function hd(){const r=$r(),[e,t]=R(r.room??pr(ce.room)??"W1N1"),[s,n]=R(r.shard??pr(ce.shard)),[i,l]=R(Sr()!==null),[o,a]=R(!1),[c,d]=R(!1),[u,h]=R(!1);ue(()=>{c(),h(!0),Promise.resolve().then(()=>h(!1))});const[f,p]=R(void 0),[b,_]=R(null),[w,C]=R(null),E=pr(ce.mapZoom),[T,v]=R(E?Number(E):null),[P,x]=R(null),[S,I]=R(!1),[L,G]=R(!1),[A,O]=R(kt(ce.sidebarWidth,260)),[$,N]=R(kt(ce.sidebarWidth,260)),[z,H]=R(kt(ce.consoleHeight,220)),[X,te]=R(kt(ce.consoleHeight,220)),[K,D]=R(!1),[B,Y]=R(!1),V=()=>A()<=32,ee=()=>z()<=32,Fe=()=>{A()>32?(N(A()),O(32)):O($())},It=()=>{z()>32?(te(z()),H(32)):H(X())},Gt=Q=>{Q.preventDefault(),D(!0);const Z=Q.clientX,ie=A(),se=re=>{const mt=re.clientX-Z;O(Math.max(32,Math.min(500,ie-mt)))},U=()=>{D(!1),Vt(ce.sidebarWidth,A()),window.removeEventListener("pointermove",se),window.removeEventListener("pointerup",U)};window.addEventListener("pointermove",se),window.addEventListener("pointerup",U)},Ye=Q=>{Q.preventDefault(),Y(!0);const Z=Q.clientY,ie=z(),se=re=>{const mt=re.clientY-Z;H(Math.max(32,Math.min(500,ie-mt)))},U=()=>{Y(!1),Vt(ce.consoleHeight,z()),window.removeEventListener("pointermove",se),window.removeEventListener("pointerup",U)};window.addEventListener("pointermove",se),window.addEventListener("pointerup",U)},pt=(Q,Z)=>{var ie;(ie=ae())==null||ie.stores.navigation.navigateTo(Q,Z)},gt=Q=>{p(Q),l(!0),history.pushState(null,"",ud(s()))},Re=()=>{i()?(l(!1),_(null),C(null),history.pushState(null,"",_r(e(),s()))):gt(e())};Lt(()=>{var se;!$r().room&&!Sr()&&history.replaceState(null,"",_r(e(),s()));const Q=()=>{const U=Sr();if(U){l(!0),U.shard!==null&&n(U.shard);return}const{room:re,shard:mt}=$r();re&&(t(re),n(mt),l(!1))};window.addEventListener("popstate",Q),$e(()=>window.removeEventListener("popstate",Q));const Z=(se=ae())==null?void 0:se.stores.navigation;if(Z){const U=Z.on("navigation:change",re=>{re.room!==null&&(t(re.room),n(re.shard),l(!1),_(null),C(null),I(Z.canBack()),G(Z.canForward()),$s(ce.room,re.room),re.shard?$s(ce.shard,re.shard):fo(ce.shard),history.pushState(null,"",_r(re.room,re.shard)))});$e(()=>U.dispose())}const ie=U=>{if(!Nn(U.target)){if(U.key==="o"||U.key==="O"){d(re=>!re),a(!1);return}(U.key==="l"||U.key==="L")&&Fn(),(U.key==="c"||U.key==="C")&&zn(),i()||(U.key==="1"&&ct("view"),U.key==="2"&&ct("flag"),U.key==="3"&&ct("build"),U.key==="m"&&gt(e()))}};window.addEventListener("keydown",ie),$e(()=>window.removeEventListener("keydown",ie))});const J=()=>(()=>{var Q=sd();return m(Q,M(q,{get when(){return o()},get children(){return M(ed,{onClose:()=>a(!1)})}}),null),m(Q,M(q,{get when(){return c()},get children(){return M(cd,{onClose:()=>d(!1)})}}),null),m(Q,M(q,{get when(){return!i()},get fallback(){return M(dd,{get shard(){return s()},get originRoom(){return f()},get initialZoom(){return T()??void 0},onNavigateToRoom:Z=>pt(Z,s()),onHoveredRoomChanged:_,onSelectedRoomChanged:C,onZoomChanged:Z=>{v(Z),Vt(ce.mapZoom,Z)},onSubscriptionStateChanged:x})},get children(){return M($a,{get room(){return e()},get shard(){return s()},onNavigate:pt})}}),null),Q})(),xe=()=>M(q,{get when(){return!Gr()},get children(){var Q=nd(),Z=Q.firstChild;return Z.$$pointerdown=Ye,m(Q,M(Fa,{get shard(){return s()},get isCollapsed(){return ee()},onToggle:It}),null),F(ie=>{var se=`${z()}px`,U=B()?"none":"height 0.15s ease";return se!==ie.e&&W(Q,"height",ie.e=se),U!==ie.t&&W(Q,"transition",ie.t=U),ie},{e:void 0,t:void 0}),Q}}),Nt=Q=>(()=>{var Z=id(),ie=Z.firstChild;return ie.$$pointerdown=Gt,m(Z,M(Uc,{get isCollapsed(){return V()},onToggle:Fe,get mapMode(){return i()},get hoveredRoomInfo(){return b()},get selectedRoomInfo(){return w()},get room(){return e()},get shard(){return s()},get mapZoom(){return T()},get mapSubsActive(){return P()}}),null),F(se=>{var U=c()?"0":`${A()}px`,re=Q&&!(u()||K())?"width 0.15s ease":"none";return U!==se.e&&W(Z,"width",se.e=U),re!==se.t&&W(Z,"transition",se.t=re),se},{e:void 0,t:void 0}),Z})();return(()=>{var Q=ld(),Z=Q.firstChild,ie=Z.firstChild,se=ie.nextSibling;return m(Z,M(Zo,{}),ie),m(Z,M(q,{get when(){return!Gr()||i()},get children(){return M(jc,{get mapZoom(){return ne(()=>!!i())()?T():null},get mapSubsActive(){return ne(()=>!!i())()?P():null}})}}),ie),m(Z,M(Js,{get disabled(){return!S()},onClick:()=>{var U;return(U=ae())==null?void 0:U.stores.navigation.back()},children:"←"}),se),m(Z,M(Js,{get disabled(){return!L()},onClick:()=>{var U;return(U=ae())==null?void 0:U.stores.navigation.forward()},children:"→"}),se),m(Z,M(Cr,{get active(){return i()},onClick:Re,get children(){return i()?"Room View":"Map"}}),se),m(Z,M(Cr,{get active(){return c()},onClick:()=>{d(U=>!U),a(!1)},children:"Code"}),se),m(Z,M(Cr,{get active(){return o()},onClick:()=>{a(U=>!U),d(!1)},children:"Settings"}),se),er(se,"click",vo,!0),m(Q,M(q,{get when(){return kn()},get fallback(){return(()=>{var U=ad(),re=U.firstChild;return m(re,J,null),m(re,()=>Nt(!0),null),m(U,xe,null),U})()},get children(){var U=od(),re=U.firstChild;return m(re,J,null),m(re,xe,null),m(U,()=>Nt(!1),null),U}}),null),m(Q,M(Ca,{}),null),Q})()}be(["click","pointerdown"]);var fd=k("<div style=width:100%;height:100%>");function pd(){const r=new URLSearchParams(window.location.search).get("guest");return r===null?null:r.startsWith("http")?r:Xt(we.url)??"https://screeps.com"}function gd(){const r=()=>Ue()==="connected"&&ae()!==null;return Lt(async()=>{if(Ue()==="idle"&&(await wo().catch(()=>{}),Ue()!=="connected"&&!lr())){const e=pd();e&&Be({url:e,auth:"guest",storage:null}).catch(()=>{})}}),(()=>{var e=fd();return m(e,(()=>{var t=ne(()=>!!r());return()=>t()?M(hd,{}):M(Xo,{})})()),e})()}const Bn=document.getElementById("root");if(!Bn)throw new Error("Root element not found");di(()=>M(gd,{}),Bn);export{Il as B,cr as E,gr as O,rl as T,Kt as a,yr as b,gn as c,bd as d,he as e,ae as f,ft as g,be as h,$t as i,m as j,Gn as k,dn as l,hc as m,Tn as n,da as o,hs as p,Or as q,W as s,k as t,Mt as u,Ss as w};