screeps-client 0.4.0 → 0.5.0

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 (34) hide show
  1. package/dist/embedded/{assets/CodePanel-DkDYXbQL.js → _client/CodePanel-GQOhmg-I.js} +1 -1
  2. package/dist/{standalone/assets/MapViewer-BN8i0uFB.js → embedded/_client/MapViewer-qJGNT0CU.js} +1 -1
  3. package/dist/embedded/_client/index-DH5qlAud.js +24 -0
  4. package/dist/embedded/_client/vendor-pixi-D-Qjltr2.js +1215 -0
  5. package/dist/embedded/index.html +3 -3
  6. package/dist/embedded/themes/default/test.json +84 -0
  7. package/dist/embedded/themes/default/test.png +0 -0
  8. package/dist/standalone/{assets/CodePanel-C0efW9c6.js → _client/CodePanel-C-DMhyuw.js} +1 -1
  9. package/dist/{embedded/assets/MapViewer-CoCRN8TR.js → standalone/_client/MapViewer-CFzJVSsf.js} +1 -1
  10. package/dist/standalone/_client/index-RbsPr76e.js +24 -0
  11. package/dist/standalone/_client/vendor-pixi-CVMJwxeR.js +1215 -0
  12. package/dist/standalone/index.html +3 -3
  13. package/dist/standalone/themes/default/test.json +84 -0
  14. package/dist/standalone/themes/default/test.png +0 -0
  15. package/dist/xxscreeps-mod/{assets/CodePanel-OjDhyKF-.js → _client/CodePanel-C4wZSlgU.js} +1 -1
  16. package/dist/xxscreeps-mod/{assets/MapViewer-B7WO94rt.js → _client/MapViewer-DdHdvydQ.js} +1 -1
  17. package/dist/xxscreeps-mod/_client/index-BlhT0eYc.js +24 -0
  18. package/dist/xxscreeps-mod/_client/vendor-pixi-DOKo__Ml.js +1215 -0
  19. package/dist/xxscreeps-mod/index.html +3 -3
  20. package/dist/xxscreeps-mod/themes/default/test.json +84 -0
  21. package/dist/xxscreeps-mod/themes/default/test.png +0 -0
  22. package/package.json +2 -2
  23. package/dist/embedded/assets/index-DTRa3SgN.js +0 -24
  24. package/dist/embedded/assets/vendor-pixi-Do7-_WYv.js +0 -1160
  25. package/dist/standalone/assets/index-Cd5zMBNk.js +0 -24
  26. package/dist/standalone/assets/vendor-pixi-CXkRT4gi.js +0 -1160
  27. package/dist/xxscreeps-mod/assets/index-D5eNG4b5.js +0 -24
  28. package/dist/xxscreeps-mod/assets/vendor-pixi-CXkRT4gi.js +0 -1160
  29. /package/dist/embedded/{assets → _client}/terrain.worker-D9zNeJfz.js +0 -0
  30. /package/dist/embedded/{assets → _client}/vendor-codemirror-D3PB7yT8.js +0 -0
  31. /package/dist/standalone/{assets → _client}/terrain.worker-D9zNeJfz.js +0 -0
  32. /package/dist/standalone/{assets → _client}/vendor-codemirror-D3PB7yT8.js +0 -0
  33. /package/dist/xxscreeps-mod/{assets → _client}/terrain.worker-D9zNeJfz.js +0 -0
  34. /package/dist/xxscreeps-mod/{assets → _client}/vendor-codemirror-D3PB7yT8.js +0 -0
@@ -0,0 +1,24 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_client/CodePanel-C-DMhyuw.js","_client/vendor-codemirror-D3PB7yT8.js","_client/vendor-pixi-CVMJwxeR.js","_client/MapViewer-CFzJVSsf.js"])))=>i.map(i=>d[i]);
2
+ var gl=Object.defineProperty;var ml=(r,e,t)=>e in r?gl(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var _=(r,e,t)=>ml(r,typeof e!="symbol"?e+"":e,t);import{k as Hi,j as N,i as Ir,v as Ys,w as ge,$ as yl,u as Re,l as F,p as ye,f as b,F as xe,S as Z,h as fe,r as Le,D as vl,a as Ft,d as bl,b as ts,m as di,s as Wt,q as wl,o as Xs}from"./vendor-codemirror-D3PB7yT8.js";import{_ as Ui,b as Ae,G as re,A as js,P as vr,R as Vs,N as xl,S as De,B as _l,d as Oe,T as At,c as $l,C as Sl,a as kl}from"./vendor-pixi-CVMJwxeR.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))n(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&n(o)}).observe(document,{childList:!0,subtree:!0});function t(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function n(i){if(i.ep)return;i.ep=!0;const s=t(i);fetch(i.href,s)}})();const Cl=["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"],Tl=new Set(["className","value","readOnly","noValidate","formNoValidate","isMap","noModule","playsInline","adAuctionHeaders","allowFullscreen","browsingTopics","defaultChecked","defaultMuted","defaultSelected","disablePictureInPicture","disableRemotePlayback","preservesPitch","shadowRootClonable","shadowRootCustomElementRegistry","shadowRootDelegatesFocus","shadowRootSerializable","sharedStorageWritable",...Cl]),Ml=new Set(["innerHTML","textContent","innerText","children"]),El=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),Rl=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 Pl(r,e){const t=Rl[r];return typeof t=="object"?t[e]?t.$:void 0:t}const Ol=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),Ll=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"]),Al={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},ee=r=>Ir(()=>r());function Il(r,e,t){let n=t.length,i=e.length,s=n,o=0,c=0,l=e[i-1].nextSibling,a=null;for(;o<i||c<s;){if(e[o]===t[c]){o++,c++;continue}for(;e[i-1]===t[s-1];)i--,s--;if(i===o){const h=s<n?c?t[c-1].nextSibling:t[s-c]:l;for(;c<s;)r.insertBefore(t[c++],h)}else if(s===c)for(;o<i;)(!a||!a.has(e[o]))&&e[o].remove(),o++;else if(e[o]===t[s-1]&&t[c]===e[i-1]){const h=e[--i].nextSibling;r.insertBefore(t[c++],e[o++].nextSibling),r.insertBefore(t[--s],h),e[i]=t[s]}else{if(!a){a=new Map;let u=c;for(;u<s;)a.set(t[u],u++)}const h=a.get(e[o]);if(h!=null)if(c<h&&h<s){let u=o,d=1,f;for(;++u<i&&u<s&&!((f=a.get(e[u]))==null||f!==h+d);)d++;if(d>h-c){const p=e[o];for(;c<h;)r.insertBefore(t[c++],p)}else r.replaceChild(t[c++],e[o++])}else o++;else e[o++].remove()}}}const rs="_$DX_DELEGATE";function Nl(r,e,t,n={}){if(!e)throw new Error("The `element` passed to `render(..., element)` doesn't exist. Make sure `element` exists in the document.");let i;return Hi(s=>{i=s,e===document?r():g(e,r(),e.firstChild?null:void 0,t)},n.owner),()=>{i(),e.textContent=""}}function R(r,e,t,n){let i;const s=()=>{if(xt())throw new Error("Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration.");const c=document.createElement("template");return c.innerHTML=r,c.content.firstChild},o=()=>(i||(i=s())).cloneNode(!0);return o.cloneNode=o,o}function Ee(r,e=window.document){const t=e[rs]||(e[rs]=new Set);for(let n=0,i=r.length;n<i;n++){const s=r[n];t.has(s)||(t.add(s),e.addEventListener(s,Wl))}}function we(r,e,t){xt(r)||(t==null?r.removeAttribute(e):r.setAttribute(e,t))}function Dl(r,e,t,n){xt(r)||(n==null?r.removeAttributeNS(e,t):r.setAttributeNS(e,t,n))}function Gl(r,e,t){xt(r)||(t?r.setAttribute(e,""):r.removeAttribute(e))}function zl(r,e){xt(r)||(e==null?r.removeAttribute("class"):r.className=e)}function st(r,e,t,n){if(n)Array.isArray(t)?(r[`$$${e}`]=t[0],r[`$$${e}Data`]=t[1]):r[`$$${e}`]=t;else if(Array.isArray(t)){const i=t[0];r.addEventListener(e,t[0]=s=>i.call(r,t[1],s))}else r.addEventListener(e,t,typeof t!="function"&&t)}function Bl(r,e,t={}){const n=Object.keys(e||{}),i=Object.keys(t);let s,o;for(s=0,o=i.length;s<o;s++){const c=i[s];!c||c==="undefined"||e[c]||(ns(r,c,!1),delete t[c])}for(s=0,o=n.length;s<o;s++){const c=n[s],l=!!e[c];!c||c==="undefined"||t[c]===l||!l||(ns(r,c,!0),t[c]=l)}return t}function Q(r,e,t){if(!e)return t?we(r,"style"):e;const n=r.style;if(typeof e=="string")return n.cssText=e;typeof t=="string"&&(n.cssText=t=void 0),t||(t={}),e||(e={});let i,s;for(s in t)e[s]==null&&n.removeProperty(s),delete t[s];for(s in e)i=e[s],i!==t[s]&&(n.setProperty(s,i),t[s]=i);return t}function Y(r,e,t){t!=null?r.style.setProperty(e,t):r.style.removeProperty(e)}function qs(r,e={},t,n){const i={};return n||N(()=>i.children=Nr(r,e.children,i.children)),N(()=>typeof e.ref=="function"&&nr(e.ref,r)),N(()=>Fl(r,e,t,!0,i,!0)),i}function nr(r,e,t){return ge(()=>r(e,t))}function g(r,e,t,n){if(t!==void 0&&!n&&(n=[]),typeof e!="function")return Nr(r,e,n,t);N(i=>Nr(r,e(),i,t),n)}function Fl(r,e,t,n,i={},s=!1){e||(e={});for(const o in i)if(!(o in e)){if(o==="children")continue;i[o]=is(r,o,null,i[o],t,s,e)}for(const o in e){if(o==="children")continue;const c=e[o];i[o]=is(r,o,c,i[o],t,s,e)}}function Hl(r){let e,t,n=xt();if(!n||!(e=Re.registry.get(t=Yl()))){if(n)throw Re.done=!0,new Error(`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${t}
3
+ `);return r()}return Re.completed&&Re.completed.add(e),Re.registry.delete(t),e}function xt(r){return!!Re.context&&!Re.done&&(!r||r.isConnected)}function Ul(r){return r.toLowerCase().replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function ns(r,e,t){const n=e.trim().split(/\s+/);for(let i=0,s=n.length;i<s;i++)r.classList.toggle(n[i],t)}function is(r,e,t,n,i,s,o){let c,l,a,h,u;if(e==="style")return Q(r,t,n);if(e==="classList")return Bl(r,t,n);if(t===n)return n;if(e==="ref")s||t(r);else if(e.slice(0,3)==="on:"){const d=e.slice(3);n&&r.removeEventListener(d,n,typeof n!="function"&&n),t&&r.addEventListener(d,t,typeof t!="function"&&t)}else if(e.slice(0,10)==="oncapture:"){const d=e.slice(10);n&&r.removeEventListener(d,n,!0),t&&r.addEventListener(d,t,!0)}else if(e.slice(0,2)==="on"){const d=e.slice(2).toLowerCase(),f=Ol.has(d);if(!f&&n){const p=Array.isArray(n)?n[0]:n;r.removeEventListener(d,p)}(f||t)&&(st(r,d,t,f),f&&Ee([d]))}else if(e.slice(0,5)==="attr:")we(r,e.slice(5),t);else if(e.slice(0,5)==="bool:")Gl(r,e.slice(5),t);else if((u=e.slice(0,5)==="prop:")||(a=Ml.has(e))||!i&&((h=Pl(e,r.tagName))||(l=Tl.has(e)))||(c=r.nodeName.includes("-")||"is"in o)){if(u)e=e.slice(5),l=!0;else if(xt(r))return t;e==="class"||e==="className"?zl(r,t):c&&!l&&!a?r[Ul(e)]=t:r[h||e]=t}else{const d=i&&e.indexOf(":")>-1&&Al[e.split(":")[0]];d?Dl(r,d,e,t):we(r,El[e]||e,t)}return t}function Wl(r){if(Re.registry&&Re.events&&Re.events.find(([l,a])=>a===r))return;let e=r.target;const t=`$$${r.type}`,n=r.target,i=r.currentTarget,s=l=>Object.defineProperty(r,"target",{configurable:!0,value:l}),o=()=>{const l=e[t];if(l&&!e.disabled){const a=e[`${t}Data`];if(a!==void 0?l.call(e,a,r):l.call(e,r),r.cancelBubble)return}return e.host&&typeof e.host!="string"&&!e.host._$host&&e.contains(r.target)&&s(e.host),!0},c=()=>{for(;o()&&(e=e._$host||e.parentNode||e.host););};if(Object.defineProperty(r,"currentTarget",{configurable:!0,get(){return e||document}}),Re.registry&&!Re.done&&(Re.done=_$HY.done=!0),r.composedPath){const l=r.composedPath();s(l[0]);for(let a=0;a<l.length-2&&(e=l[a],!!o());a++){if(e._$host){e=e._$host,c();break}if(e.parentNode===i)break}}else c();s(n)}function Nr(r,e,t,n,i){const s=xt(r);if(s){!t&&(t=[...r.childNodes]);let l=[];for(let a=0;a<t.length;a++){const h=t[a];h.nodeType===8&&h.data.slice(0,2)==="!$"?h.remove():l.push(h)}t=l}for(;typeof t=="function";)t=t();if(e===t)return t;const o=typeof e,c=n!==void 0;if(r=c&&t[0]&&t[0].parentNode||r,o==="string"||o==="number"){if(s||o==="number"&&(e=e.toString(),e===t))return t;if(c){let l=t[0];l&&l.nodeType===3?l.data!==e&&(l.data=e):l=document.createTextNode(e),t=Yt(r,t,n,l)}else t!==""&&typeof t=="string"?t=r.firstChild.data=e:t=r.textContent=e}else if(e==null||o==="boolean"){if(s)return t;t=Yt(r,t,n)}else{if(o==="function")return N(()=>{let l=e();for(;typeof l=="function";)l=l();t=Nr(r,l,t,n)}),()=>t;if(Array.isArray(e)){const l=[],a=t&&Array.isArray(t);if(ui(l,e,t,i))return N(()=>t=Nr(r,l,t,n,!0)),()=>t;if(s){if(!l.length)return t;if(n===void 0)return t=[...r.childNodes];let h=l[0];if(h.parentNode!==r)return t;const u=[h];for(;(h=h.nextSibling)!==n;)u.push(h);return t=u}if(l.length===0){if(t=Yt(r,t,n),c)return t}else a?t.length===0?ss(r,l,n):Il(r,t,l):(t&&Yt(r),ss(r,l));t=l}else if(e.nodeType){if(s&&e.parentNode)return t=c?[e]:e;if(Array.isArray(t)){if(c)return t=Yt(r,t,n,e);Yt(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 ui(r,e,t,n){let i=!1;for(let s=0,o=e.length;s<o;s++){let c=e[s],l=t&&t[r.length],a;if(!(c==null||c===!0||c===!1))if((a=typeof c)=="object"&&c.nodeType)r.push(c);else if(Array.isArray(c))i=ui(r,c,l)||i;else if(a==="function")if(n){for(;typeof c=="function";)c=c();i=ui(r,Array.isArray(c)?c:[c],Array.isArray(l)?l:[l])||i}else r.push(c),i=!0;else{const h=String(c);l&&l.nodeType===3&&l.data===h?r.push(l):r.push(document.createTextNode(h))}}return i}function ss(r,e,t=null){for(let n=0,i=e.length;n<i;n++)r.insertBefore(e[n],t)}function Yt(r,e,t,n){if(t===void 0)return r.textContent="";const i=n||document.createTextNode("");if(e.length){let s=!1;for(let o=e.length-1;o>=0;o--){const c=e[o];if(i!==c){const l=c.parentNode===r;!s&&!o?l?r.replaceChild(i,c):r.insertBefore(i,t):l&&c.remove()}else s=!0}}else r.insertBefore(i,t);return[i]}function Yl(){return Re.getNextContextId()}const Xl="http://www.w3.org/2000/svg";function jl(r,e=!1,t=void 0){return e?document.createElementNS(Xl,r):document.createElement(r,{is:t})}function Vl(r,e){const t=Ir(r);return Ir(()=>{const n=t();switch(typeof n){case"function":return Object.assign(n,{[yl]:!0}),ge(()=>n(e));case"string":const i=Ll.has(n),s=Re.context?Hl():jl(n,i,ge(()=>e.is));return qs(s,e,i),s}})}function Zs(r){const[,e]=Ys(r,["component"]);return Vl(()=>r.component,e)}async function Ks(r,e){const t=r.slice(3),n=Uint8Array.from(atob(t),o=>o.charCodeAt(0)),i=new Blob([n]).stream().pipeThrough(new DecompressionStream(e)),s=await new Response(i).text();try{return JSON.parse(s)}catch{return s}}function Js(r){return Ks(r,"gzip")}function Qs(r){return Ks(r,"deflate")}const ql=Object.freeze(Object.defineProperty({__proto__:null,decompressGzip:Js,decompressZlib:Qs},Symbol.toStringTag,{value:"Module"}));class ct{constructor(e){_(this,"fn");this.fn=e}static create(e){return e===!0?new ct(console.debug.bind(console)):typeof e=="function"?new ct(e):new ct(null)}child(e){if(!this.fn)return this;const t=this.fn;return new ct((...n)=>t(`[screeps:${e}]`,...n))}log(...e){var t;(t=this.fn)==null||t.call(this,...e)}}function Zl(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 Kl(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 Me(r,e){return e&&(r.shard=e),r}function Jl(r){return{roomTerrain:(e,t)=>r.request("GET","/api/game/room-terrain",Me({room:e,encoded:1},t)),roomObjects:(e,t)=>r.request("GET","/api/game/room-objects",Me({room:e},t)),roomStatus:(e,t)=>r.request("GET","/api/game/room-status",Me({room:e},t)),roomOverview:(e,t=8,n)=>r.request("GET","/api/game/room-overview",Me({room:e,interval:t},n)),time:e=>r.request("GET","/api/game/time",Me({},e)),worldSize:e=>r.request("GET","/api/game/world-size",Me({},e)),mapStats:(e,t,n)=>r.request("POST","/api/game/map-stats",Me({rooms:e,statName:t},n)),roomsTerrain:(e,t)=>{const n=new URLSearchParams({encoded:"true"});return t&&n.set("shard",t),r.request("POST",`/api/game/rooms?${n}`,{rooms:e})},createFlag:(e,t,n,i,s,o,c)=>r.request("POST","/api/game/create-flag",Me({room:e,x:t,y:n,name:i,color:s,secondaryColor:o},c)),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,n,i)=>r.request("POST","/api/game/change-flag-color",{room:e,name:t,color:n,secondaryColor:i}),removeFlag:(e,t)=>r.request("POST","/api/game/remove-flag",{room:e,name:t}),genUniqueObjectName:(e,t)=>r.request("POST","/api/game/gen-unique-object-name",Me({type:e},t)),checkUniqueObjectName:(e,t,n)=>r.request("POST","/api/game/check-unique-object-name",Me({type:e,name:t},n)),placeSpawn:(e,t,n,i,s)=>r.request("POST","/api/game/place-spawn",Me({room:e,x:t,y:n,...i?{name:i}:{}},s)),createConstruction:(e,t,n,i,s,o)=>r.request("POST","/api/game/create-construction",Me({room:e,x:t,y:n,structureType:i,...s?{name:s}:{}},o)),removeConstructionSite:(e,t,n)=>r.request("POST","/api/game/add-object-intent",Me({_id:"room",room:e,name:"removeConstructionSite",intent:t.map(i=>({id:i,roomName:e}))},n)),addObjectIntent:(e,t,n,i,s)=>r.request("POST","/api/game/add-object-intent",Me({_id:e,room:t,name:n,intent:i},s)),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,n,i,s,o)=>r.request("POST","/api/game/create-invader",{room:e,x:t,y:n,size:i,type:s,...o!=null?{boosted:o}:{}}),removeInvader:e=>r.request("POST","/api/game/remove-invader",{_id:e}),tick:()=>r.request("GET","/api/game/tick"),powerCreeps:Kl(r),market:{ordersIndex:e=>r.request("GET","/api/game/market/orders-index",Me({},e)),myOrders:()=>r.request("GET","/api/game/market/my-orders"),orders:(e,t)=>r.request("GET","/api/game/market/orders",Me({resourceType:e},t)),stats:(e,t)=>r.request("GET","/api/game/market/stats",Me({resourceType:e},t))},shards:{info:()=>r.request("GET","/api/game/shards/info")}}}function Ql(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 Xt(r,e){return e&&(r.shard=e),r}function ea(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",Xt({path:e},t)),set:(e,t,n)=>r.request("POST","/api/user/memory",Xt({path:e,value:t},n)),segment:{get:(e,t)=>r.request("GET","/api/user/memory-segment",Xt({segment:e},t)),set:(e,t,n)=>r.request("POST","/api/user/memory-segment",Xt({segment:e,data:t},n))}},console:(e,t)=>r.request("POST","/api/user/console",Xt({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",Xt({},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,n)=>r.request("POST","/api/user/clone-branch",{newName:e,...t?{branch:t}:{},...n!=null?{defaultModules:n}:{}}),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:Ql(r)}}function ta(r){return{list:(e=10,t="world",n=0,i)=>r.request("GET","/api/leaderboard/list",{limit:e,mode:t,offset:n,season:i}),find:(e,t="world",n="")=>r.request("GET","/api/leaderboard/find",{username:e,mode:t,season:n}),seasons:()=>r.request("GET","/api/leaderboard/seasons")}}function ra(r){return{pvp:(e=100)=>r.request("GET","/api/experimental/pvp",{interval:e}),nukes:()=>r.request("GET","/api/experimental/nukes")}}function na(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,n,i)=>r.request("POST","/api/register/submit",{username:e,email:t,password:n,...i!=null?{modules:i}:{}})}}class ia extends EventTarget{constructor(t){super();_(this,"baseUrl");_(this,"authStrategy");_(this,"logger");_(this,"serverPassword");_(this,"token",null);_(this,"rateLimits",new Map);_(this,"authenticating",!1);_(this,"auth");_(this,"register");_(this,"game");_(this,"user");_(this,"leaderboard");_(this,"experimental");this.baseUrl=t.url.endsWith("/")?t.url:`${t.url}/`,this.authStrategy=t.auth,this.logger=t.logger??ct.create(),this.serverPassword=t.serverPassword??null,this.auth=Zl(this),this.register=na(this),this.game=Jl(this),this.user=ea(this),this.leaderboard=ta(this),this.experimental=ra(this)}emit(t,n){this.dispatchEvent(new CustomEvent(t,{detail:n}))}on(t,n){const i=s=>n(s.detail);return this.addEventListener(t,i),{dispose:()=>{this.removeEventListener(t,i)}}}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,n,i,s=!1){this.logger.log(t,n);const o=new URL(n.startsWith("/")?n.slice(1):n,this.baseUrl),c={};this.token&&(c["X-Token"]=this.token,c["X-Username"]=this.token),this.serverPassword&&(c["X-Server-Password"]=this.serverPassword);const l={method:t,headers:c};if(t==="GET"&&i)for(const[d,f]of Object.entries(i))f!=null&&o.searchParams.set(d,String(f));else i&&(c["Content-Type"]="application/json",l.body=JSON.stringify(i));const a=await fetch(o.toString(),l),h=a.headers.get("x-token");if(h&&(this.token=h,this.emit("http:tokenRefresh",{token:h})),this.updateRateLimit(n,a),a.status===401&&!s&&!this.authenticating)return await this.authenticate(),this.request(t,n,i,!0);if(!a.ok&&a.status!==304){let d="";try{d=await a.text()}catch{}const f=new Error(`HTTP ${a.status}: ${d}`);throw this.emit("http:error",{method:t,path:n,status:a.status,error:f}),f}this.emit("http:success",{method:t,path:n,status:a.status});const u=await a.json();if(typeof u.error=="string"){const d=new Error(`Screeps API error: ${u.error}`);throw this.emit("http:error",{method:t,path:n,status:a.status,error:d}),d}return typeof u.data=="string"&&u.data.startsWith("gz:")&&(u.data=await Js(u.data)),u}updateRateLimit(t,n){const i=n.headers.get("x-ratelimit-limit"),s=n.headers.get("x-ratelimit-remaining"),o=n.headers.get("x-ratelimit-reset");i&&s&&o&&this.rateLimits.set(t,{limit:parseInt(i,10),remaining:parseInt(s,10),reset:parseInt(o,10)})}}async function sa(r){let e=typeof r=="string"?r:r.data;if(e.startsWith("gz:")&&(e=JSON.stringify(await Qs(e))),e.startsWith("[")){const[i,s]=JSON.parse(e);return{kind:"channel",message:{channel:i,data:s}}}const[t,...n]=e.split(" ");switch(t){case"auth":return{kind:"server",command:{type:"auth",status:n[0],token:n[1]}};case"time":return{kind:"server",command:{type:"time",time:parseInt(n[0],10)}};case"protocol":return{kind:"server",command:{type:"protocol",protocol:parseInt(n[0],10)}};case"package":return{kind:"server",command:{type:"package",package:parseInt(n[0],10)}};default:throw new Error(`Unknown server command: ${t}`)}}class oa{constructor(e){_(this,"wsUrl");_(this,"WS");_(this,"logger");_(this,"ws",null);_(this,"token",null);_(this,"authed",!1);_(this,"_connected",!1);_(this,"reconnecting",!1);_(this,"authSub",null);_(this,"queue",[]);_(this,"subs",new Map);_(this,"listeners",new Map);_(this,"MAX_RETRIES",10);_(this,"MAX_DELAY_MS",6e4);_(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??ct.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((n,i)=>{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",s=>{const o=s;if(o.status==="ok"){for(this.logger.log("auth ok"),this.authed=!0,o.token&&(this.token=o.token,this.emit("socket:tokenRefresh",{token:o.token}));this.queue.length;)this.rawSend(this.queue.shift());this.emit("connected",{}),n()}else this.logger.log("auth failed"),i(new Error("WebSocket auth failed"))})},this.ws.onclose=()=>{var s;this.logger.log("WebSocket closed"),this._connected=!1,this.authed=!1,(s=this.authSub)==null||s.dispose(),this.authSub=null,this.emit("disconnected",{willReconnect:this.reconnecting}),this.scheduleReconnect()},this.ws.onerror=s=>{this._connected||i(s)},this.ws.onmessage=s=>{this.handleMessage(s).catch(o=>{const c=typeof s.data=="string"?s.data.slice(0,200):"(binary)";this.logger.log("message parse error",o instanceof Error?o.stack??o.message:String(o),"raw:",c),this.emit("socket:error",o instanceof Error?o:new Error(String(o)))})}})}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 n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),{dispose:()=>{var i;(i=this.listeners.get(e))==null||i.delete(t)}}}once(e,t){const n=this.on(e,i=>{n.dispose(),t(i)});return n}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 n;(n=this.listeners.get(e))==null||n.forEach(i=>{try{i(t)}catch(s){this.logger.log("listener error on channel",e,s instanceof Error?s.stack??s.message:String(s))}})}async handleMessage(e){const t=await sa(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 n=Math.min(Math.pow(2,e)*100,this.MAX_DELAY_MS);if(this.logger.log(`reconnect attempt ${e+1}/${this.MAX_RETRIES} in ${n}ms`),await new Promise(i=>setTimeout(i,n)),!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 i of this.subs.keys())this.rawSend(`subscribe ${i}`);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 la{constructor(e,t){_(this,"memory",new Map);_(this,"storage");_(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,n){this.memory.set(this.memKey(e),{data:t,expires:n!==void 0?Date.now()+n: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 pr extends EventTarget{constructor(t){super();_(this,"logger");this.logger=t??ct.create()}emit(t,n){this.dispatchEvent(new CustomEvent(t,{detail:n}))}on(t,n){this.logger.log(`on "${t}"`);const i=s=>n(s.detail);return this.addEventListener(t,i),{dispose:()=>{this.logger.log(`off "${t}"`),this.removeEventListener(t,i)}}}}var Xe=(r=>(r[r.Plain=0]="Plain",r[r.Wall=1]="Wall",r[r.Swamp=2]="Swamp",r))(Xe||{});class ir{constructor(e){_(this,"raw");this.raw=e}static fromEncodedString(e){const t=new Uint8Array(2500);for(let n=0;n<2500;n++){const i=parseInt(e[n],10);t[n]=i===3?1:i}return new ir(t)}get(e,t){return this.raw[t*50+e]}}class aa extends pr{constructor(t,n,i,s){super(s);_(this,"http");_(this,"socket");_(this,"cache");_(this,"roomObjects",new Map);_(this,"roomUsers",new Map);_(this,"roomSubCount",new Map);_(this,"lastFlagsString",new Map);this.http=t,this.socket=n,this.cache=i}parseFlagsString(t,n){if(!t||t.length===0)return[];const i=[],s=t.split("|");for(const o of s){const c=o.split("~");if(c.length!==5)continue;const[l,a,h,u,d]=c,f=parseInt(a,10),p=parseInt(h,10),m=parseInt(u,10),S=parseInt(d,10);isNaN(f)||isNaN(p)||isNaN(m)||isNaN(S)||i.push({_id:l,type:"flag",room:n,name:l,x:m,y:S,color:f,secondaryColor:p})}return i}async terrain(t,n){const i=`terrain/${n}/${t}`,s=this.cache.get(i);if(s)return this.logger.log("terrain",t,n,"(memory cache hit)"),s;const o=await this.cache.getPersistent(i);if(o){this.logger.log("terrain",t,n,"(persistent cache hit)");const h=new ir(o);return this.cache.set(i,h),h}this.logger.log("terrain",t,n,"(fetching)");const l=(await this.http.game.roomTerrain(t,n??void 0)).terrain[0];if(!l)throw new Error(`No terrain data for room ${t} shard ${n}`);const a=ir.fromEncodedString(l.terrain);return this.cache.set(i,a),await this.cache.setPersistent(i,a.raw),this.emit("room:terrainavailable",{room:t,shard:n,terrain:a}),a}async terrainBulk(t,n){const i=new Map,s=[];for(const l of t){const a=this.cache.get(`terrain/${n}/${l}`);a?i.set(l,a):s.push(l)}if(s.length===0)return i;const o=[];if(await Promise.all(s.map(async l=>{const a=`terrain/${n}/${l}`,h=await this.cache.getPersistent(a);if(h){const u=new ir(h);this.cache.set(a,u),i.set(l,u)}else o.push(l)})),o.length===0)return i;this.logger.log("terrainBulk",`fetching ${o.length} rooms`,n);const c=await this.http.game.roomsTerrain(o,n??void 0);return await Promise.all(c.rooms.map(async l=>{const a=ir.fromEncodedString(l.terrain),h=`terrain/${n}/${l.room}`;this.cache.set(h,a),await this.cache.setPersistent(h,a.raw),this.emit("room:terrainavailable",{room:l.room,shard:n,terrain:a}),i.set(l.room,a)})),i}objects(t,n){const i=this.roomObjects.get(`${t}/${n}`);return i?{...i}:null}async fetchObjects(t,n){const i=`${t}/${n}`,s=await this.http.game.roomObjects(t,n??void 0),o={};for(const l of s.objects)l&&typeof l=="object"&&"_id"in l&&(o[l._id]=l);this.roomObjects.set(i,o);const c=this.roomUsers.get(i);this.emit("room:update",{room:t,shard:n,gameTime:void 0,objects:o,diff:o,visual:"",users:c})}activeRooms(){return Array.from(this.roomSubCount.entries()).map(([t,n])=>`${t}(${n})`).join(", ")||"(none)"}subscribe(t,n){const i=`${t}/${n}`,s=this.roomSubCount.get(i)??0;this.roomSubCount.set(i,s+1),this.logger.log("subscribe",t,n,`(refs: ${s+1})`,"active:",this.activeRooms());const o=n?`room:${n}/${t}`:`room:${t}`,c=n?`err@room:${n}/${t}`:`err@room:${t}`,l=this.socket.subscribe(o),a=this.socket.on(c,u=>{const d=typeof u=="string"?u:JSON.stringify(u);this.logger.log("room error",t,n,d),this.emit("room:error",{room:t,shard:n,message:d})}),h=this.socket.on(o,u=>{const d=u,f={...this.roomObjects.get(i)??{}};if(d.objects==null)d.objects===null&&this.logger.log("room update has null objects field",t,n,`gameTime: ${d.gameTime}`);else for(const[S,O]of Object.entries(d.objects))O===null?delete f[S]:f[S]?f[S]={...f[S],...O}:f[S]=O;const p={...d.objects??{}};if("flags"in d){const S=d.flags??"",O=this.lastFlagsString.get(i)??"";if(S!==O){this.lastFlagsString.set(i,S);const z=this.parseFlagsString(S,t),P=new Map;for(const k of z)P.set(k.name,k);for(const k in f){const C=f[k];(C==null?void 0:C.type)==="flag"&&!P.has(k)&&(delete f[k],p[k]=null,this.logger.log(`[flag:room] removed ${k} @ ${t}`))}for(const[k,C]of P){const w=f[k];(!w||w.x!==C.x||w.y!==C.y||w.color!==C.color||w.secondaryColor!==C.secondaryColor)&&(f[k]=C,p[k]=C,this.logger.log(`[flag:room] ${w?"changed":"added"} ${k} @ ${t} (${C.x},${C.y})`))}}}if(d.users){const S=this.roomUsers.get(i)??{};this.roomUsers.set(i,{...S,...d.users})}this.roomObjects.set(i,f);const m=this.roomUsers.get(i);this.emit("room:update",{room:t,shard:n,gameTime:d.gameTime,objects:f,diff:p,visual:d.visual??"",users:m})});return{dispose:()=>{l.dispose(),h.dispose(),a.dispose();const u=(this.roomSubCount.get(i)??1)-1;u<=0?(this.roomSubCount.delete(i),this.roomObjects.delete(i),this.roomUsers.delete(i),this.lastFlagsString.delete(i),this.logger.log("unsubscribe",t,n,"(last ref)","active:",this.activeRooms())):(this.roomSubCount.set(i,u),this.logger.log("unsubscribe",t,n,`(refs: ${u})`,"active:",this.activeRooms()))}}}}class ca extends pr{constructor(t,n,i,s,o=100){super(s);_(this,"http");_(this,"socket");_(this,"cache");_(this,"console",[]);_(this,"maxConsoleSize");_(this,"_cpu",null);_(this,"_userInfo",null);_(this,"_userId",null);_(this,"_worldStatus",null);_(this,"_mePromise",null);this.http=t,this.socket=n,this.cache=i,this.maxConsoleSize=o}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(n=>{const i=n;return this._userId=i._id,this._userInfo=i,this.cache.set("user/me",i,6e4),this.emit("user:me",i),i}).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 n=await this.http.user.worldStatus();return this._worldStatus=n.status,this.cache.set("user/worldStatus",n.status,6e4),this.emit("user:worldStatus",{status:n.status}),n.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 n=null,i=null,s=!1;return(async()=>{try{const c=this._userId??(await this.me())._id;if(s)return;const l=`user:${c}/${t}`;n=this.socket.subscribe(l),i=this.socket.on(l,a=>{var h,u,d;if(t==="cpu")this._cpu=a,this.emit("user:cpu",this._cpu);else if(t==="console"){const f=a,p={log:((h=f.messages)==null?void 0:h.log)??[],results:((u=f.messages)==null?void 0:u.results)??[],error:((d=f.messages)==null?void 0:d.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",a)})}catch(c){s||this.dispatchEvent(new ErrorEvent("error",{error:c instanceof Error?c:new Error(String(c))}))}})(),{dispose:()=>{this.logger.log("unsubscribe",t),s=!0,n==null||n.dispose(),i==null||i.dispose()}}}subscribeMemory(t,n){this.logger.log("subscribe memory",t);let i=null,s=null,o=!1;return(async()=>{try{const l=this._userId??(await this.me())._id;if(o)return;const a=n?`${n}/`:"",h=`user:${l}/memory/${a}${t}`;i=this.socket.subscribe(h),s=this.socket.on(h,u=>{if(typeof u=="string"&&u.startsWith("gz:")){(async()=>{try{const{decompressZlib:f}=await Ui(async()=>{const{decompressZlib:m}=await Promise.resolve().then(()=>ql);return{decompressZlib:m}},void 0),p=await f(u);this.emit("user:memory",{path:t,shard:n??null,value:p})}catch(f){this.logger.log("memory decompress failed",f)}})();return}if(u==="[object Object]"){this.logger.log("memory object placeholder",t),this.emit("user:memory",{path:t,shard:n??null,value:{__screeps_object__:!0}});return}let d=u;if(u==="undefined")d=void 0;else if(typeof u=="string")try{d=JSON.parse(u)}catch{}this.logger.log("memory value received",t,d),this.emit("user:memory",{path:t,shard:n??null,value:d})})}catch(l){o||this.dispatchEvent(new ErrorEvent("error",{error:l instanceof Error?l:new Error(String(l))}))}})(),{dispose:()=>{this.logger.log("unsubscribe memory",t),o=!0,i==null||i.dispose(),s==null||s.dispose()}}}subscribeUserStream(){this.logger.log("subscribe user stream");let t=null,n=null,i=!1;return(async()=>{try{const o=this._userId??(await this.me())._id;if(i)return;const c=`user:${o}`;t=this.socket.subscribe(c),n=this.socket.on(c,l=>{const a=l;if(a&&typeof a=="object"&&"flags"in a){const h=a.flags;if(h&&typeof h=="object")for(const[u,d]of Object.entries(h)){const f=d;if(f&&typeof f=="object"){const p=f.room??"unknown",m=f.x??"?",S=f.y??"?";this.logger.log(`[flag:user] ${u} @ ${p} (${m},${S})`)}}}this.emit("user:stream",a)})}catch(o){i||this.dispatchEvent(new ErrorEvent("error",{error:o instanceof Error?o:new Error(String(o))}))}})(),{dispose:()=>{this.logger.log("unsubscribe user stream"),i=!0,t==null||t.dispose(),n==null||n.dispose()}}}}class da extends pr{constructor(t,n,i,s){super(s);_(this,"http");_(this,"cache");_(this,"socketSubs",[]);_(this,"_version",null);_(this,"_shards",null);this.http=t,this.cache=i,this.socketSubs.push(n.on("connected",()=>{this.emit("server:connected",{})})),this.socketSubs.push(n.on("disconnected",o=>{const c=o;this.emit("server:disconnected",{willReconnect:c.willReconnect})})),this.socketSubs.push(n.on("socket:error",o=>{this.emit("server:error",{error:o instanceof Error?o:new Error(String(o))})}))}get versionInfo(){return this._version}get isPrivateServer(){var t,n;return this._version?(((n=(t=this._version.serverData)==null?void 0:t.shards)==null?void 0:n.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 n=await this.http.request("GET","/api/version");return this._version=n,this.cache.set("server/version",n,5*6e4),this.emit("server:version",n),n}async refreshVersion(){return this.cache.delete("server/version"),this.version()}async shards(){const t=this.cache.get("server/shards");if(t)return t;const n=await this.http.request("GET","/api/game/shards/info");return this._shards=n.shards,this.cache.set("server/shards",n.shards,5*6e4),this.emit("server:shards",n.shards),n.shards}async refreshShards(){return this.cache.delete("server/shards"),this.shards()}async worldInfo(t){const i=`server/world/${t??"default"}`,s=this.cache.get(i);if(s)return s;const o={};t&&(o.shard=t);const c=await this.http.request("GET","/api/game/world-size",o),{width:l,height:a}=c;this.logger.log(`worldInfo shard=${t??"none"} — raw size: ${l}x${a}`);let h=-l,u=-1,d=-a,f=-1;try{const S=(await this.http.request("POST","/api/game/map-stats",{rooms:["W0N0","E0N0","W0S0","E0S0"],statName:"owner0",...o})).stats??{},O=["W0N0","E0N0","W0S0","E0S0"].filter(z=>z in S);this.logger.log(`worldInfo corner probe — found: [${O.length?O.join(", "):"none"}]`),("E0N0"in S||"E0S0"in S)&&(h=-Math.ceil(l/2),u=Math.floor(l/2)-1),("W0S0"in S||"E0S0"in S)&&(d=-Math.ceil(a/2),f=Math.floor(a/2)-1)}catch(m){this.logger.log("worldInfo corner probe failed — keeping W/N defaults:",m)}this.logger.log(`worldInfo computed bounds — x: [${h}, ${u}] y: [${d}, ${f}]`);const p={shard:t??null,width:l,height:a,minX:h,maxX:u,minY:d,maxY:f};return this.cache.set(i,p,10*6e4),p}invalidateWorldInfo(t){this.cache.delete(`server/world/${t??"default"}`)}}class ua{constructor(e){_(this,"memory",new Map);_(this,"adapter");_(this,"maxEntries");_(this,"namespace");_(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 n=this.memory.get(this.key(e,t));return n?(n.lastAccess=this.tick(),n.data):null}async get(e,t){const n=this.getMemory(e,t);if(n)return n;if(!this.adapter)return null;const i=this.key(e,t),s=await this.adapter.get(this.adapterKey(i));if(!s)return null;const o=this.deserialize(s);return o?(this.memory.set(i,{data:o.data,lastSeen:o.lastSeen,lastAccess:this.tick()}),o.data):null}async put(e,t,n){const i=this.key(e,t),s={data:n,lastSeen:Date.now(),lastAccess:this.tick()};this.memory.set(i,s),await this.pruneIfNeeded(),this.adapter&&await this.adapter.set(this.adapterKey(i),this.serialize(s))}async pruneIfNeeded(){if(this.memory.size<=this.maxEntries)return;const t=[...this.memory.entries()].sort((n,i)=>n[1].lastAccess-i[1].lastAccess).slice(0,this.memory.size-this.maxEntries);for(const[n]of t)this.memory.delete(n),this.adapter&&await this.adapter.delete(this.adapterKey(n))}}function os(r){const e=Object.keys(r).sort(),t={};for(const n of e){const i=r[n];t[n]=i?[...i].sort((s,o)=>s[0]-o[0]||s[1]-o[1]):null}return JSON.stringify(t)}class ha extends pr{constructor(t,n,i={},s){super(s);_(this,"socket");_(this,"storage");_(this,"maxSubscriptions");_(this,"active",new Map);_(this,"waitlist",[]);_(this,"keyStates",new Map);_(this,"warnedAboutWaitlist",!1);this.socket=t,this.storage=n,this.maxSubscriptions=i.maxSubscriptions??500,this.socket.on("connected",()=>this.onReconnect())}map2data(t,n){return this.storage.getMemory(t,n)}subscribeMap2(t,n){const i=`${t}/${n}`,s=this.active.get(i);if(s){s.refCount++,this.logger.log("subscribeMap2",t,n,`(active, refs: ${s.refCount})`);const l=this.getOrCreateKeyState(i,"active");return this.emitWarmStart(t,n),this.makeSubscription(t,n,i,l)}const o=this.waitlist.find(l=>l.key===i);if(o){o.refCount++,this.logger.log("subscribeMap2",t,n,`(pending, refs: ${o.refCount})`);const l=this.getOrCreateKeyState(i,"pending");return this.emitWarmStart(t,n),this.makeSubscription(t,n,i,l)}if(this.active.size<this.maxSubscriptions){this.activateKey(t,n,i,1),this.logger.log("subscribeMap2",t,n,"(new active)");const l=this.getOrCreateKeyState(i,"active");return this.emit("room:map2state",{room:t,shard:n,status:"active"}),this.emitWarmStart(t,n),this.makeSubscription(t,n,i,l)}this.waitlist.push({key:i,room:t,shard:n,refCount:1}),this.logger.log("subscribeMap2",t,n,"(new pending)");const c=this.getOrCreateKeyState(i,"pending");return this.emit("room:map2state",{room:t,shard:n,status:"pending"}),this.emitWarmStart(t,n),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,n,i,c)}activateKey(t,n,i,s){const o=n?`roomMap2:${n}/${t}`:`roomMap2:${t}`,c=this.socket.subscribe(o),l=this.storage.getMemory(t,n),a={room:t,shard:n,refCount:s,socketSub:c,listenerSub:void 0,lastHash:l?os(l):null};a.listenerSub=this.socket.on(o,h=>{const u=h,d=os(u);a.lastHash!==d&&(a.lastHash=d,this.storage.put(t,n,u),this.emit("room:map2update",{room:t,shard:n,data:u,source:"live"}))}),this.active.set(i,a)}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 n=this.keyStates.get(t.key);n&&(n.status="active",n.statusHandlers.forEach(i=>i("active"))),this.emit("room:map2state",{room:t.room,shard:t.shard,status:"active"})}getOrCreateKeyState(t,n){let i=this.keyStates.get(t);return i||(i={status:n,statusHandlers:new Set},this.keyStates.set(t,i)),i}makeSubscription(t,n,i,s){let o=!1;return{status:()=>s.status,cachedData:()=>this.storage.getMemory(t,n),onStatusChange:c=>(s.statusHandlers.add(c),{dispose:()=>{s.statusHandlers.delete(c)}}),dispose:()=>{o||(o=!0,this.disposeSubscription(t,n,i))}}}disposeSubscription(t,n,i){const s=this.waitlist.findIndex(c=>c.key===i);if(s>=0){const c=this.waitlist[s];c.refCount--,this.logger.log("unsubscribeMap2",t,n,`(pending, refs: ${c.refCount})`),c.refCount<=0&&(this.waitlist.splice(s,1),this.keyStates.delete(i),this.logger.log("unsubscribeMap2",t,n,"(removed from waitlist)"));return}const o=this.active.get(i);o&&(o.refCount--,this.logger.log("unsubscribeMap2",t,n,`(active, refs: ${o.refCount})`),o.refCount<=0&&(o.socketSub.dispose(),o.listenerSub.dispose(),this.active.delete(i),this.keyStates.delete(i),this.logger.log("unsubscribeMap2",t,n,"(deactivated, promoting next)"),this.promoteNext()))}emitWarmStart(t,n){const i=`${t}/${n}`,s=this.storage.getMemory(t,n);s?queueMicrotask(()=>{this.isSubscribed(i)&&this.emit("room:map2update",{room:t,shard:n,data:s,source:"cache"})}):this.storage.get(t,n).then(o=>{o&&this.isSubscribed(i)&&this.emit("room:map2update",{room:t,shard:n,data:o,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(n=>n.key===t)}}class fa extends pr{constructor(t,n=100,i=500,s){super(s);_(this,"http");_(this,"debounceMs");_(this,"minIntervalMs");_(this,"pending",new Map);_(this,"timer",null);_(this,"lastFlushTime",0);this.http=t,this.debounceMs=n,this.minIntervalMs=i}request(t,n,i){if(t.length===0)return;const s=JSON.stringify([n,i??"shard0"]);let o=this.pending.get(s);o||(o={rooms:new Set,statName:n,shard:i??"shard0"},this.pending.set(s,o));for(const h of t)o.rooms.add(h);this.timer&&clearTimeout(this.timer);const l=Date.now()-this.lastFlushTime,a=Math.max(this.debounceMs,this.minIntervalMs-l);this.timer=setTimeout(()=>this.flush(),a)}async flush(){const t=new Map(this.pending);this.pending.clear(),this.timer=null,this.lastFlushTime=Date.now();for(const[,n]of t){const i=[...n.rooms];try{const s=await this.http.request("POST","/api/game/map-stats",{rooms:i,statName:n.statName,shard:n.shard}),o=s.users??{};for(const[c,l]of Object.entries(s.stats)){const a=this.buildData(l,o);this.emit("mapStats:room",{room:c,shard:n.shard==="shard0"?null:n.shard,stat:a})}for(const c of i)s.stats[c]||this.emit("mapStats:room",{room:c,shard:n.shard==="shard0"?null:n.shard,stat:{}})}catch(s){this.logger.log("mapStats fetch failed:",s)}}}buildData(t,n){var c,l,a;let i,s;for(let h=0;h<3;h++){const u=`minerals${h}`,d=t[u];if(d){i=d.type,s=d.density;break}}const o=(c=t.own)==null?void 0:c.user;return{own:t.own,mineral:i,density:s,username:o?(l=n[o])==null?void 0:l.username:void 0,safeMode:t.safeMode,badge:o?(a=n[o])==null?void 0:a.badge:void 0,status:t.status}}}class pa extends pr{constructor(t=50,n){super(n);_(this,"_history",[]);_(this,"_index",-1);_(this,"maxHistory");this.maxHistory=t}navigateTo(t,n){this._history=this._history.slice(0,this._index+1),this._history.push({room:t,shard:n}),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,n;return{room:((t=this._history[this._index])==null?void 0:t.room)??null,shard:((n=this._history[this._index])==null?void 0:n.shard)??null,index:this._index,history:[...this._history]}}}class ga{constructor(e){_(this,"http");_(this,"socket");_(this,"stores");_(this,"cache");_(this,"logger");_(this,"tokenRefreshIntervalMs");_(this,"tokenSyncSubs",[]);_(this,"tokenRefreshTimer",null);_(this,"lastHttpActivity",0);_(this,"refreshInFlight",!1);var i,s,o;let t;try{t=new URL(e.url).hostname}catch{throw new TypeError(`ScreepsClient: invalid url "${e.url}"`)}this.logger=ct.create(e.debug),this.logger.log(`[screeps:client] init ${e.url}`),this.cache=new la(t,e.storage??null),this.http=new ia({url:e.url,auth:e.auth,logger:this.logger.child("http"),serverPassword:e.serverPassword}),this.socket=new oa({url:e.url,WebSocket:e.WebSocket,logger:this.logger.child("socket")});const n=new ua({adapter:e.storage??null,namespace:t,maxEntries:((i=e.map2)==null?void 0:i.maxCacheEntries)??1e4});this.stores={room:new aa(this.http,this.socket,this.cache,this.logger.child("room")),user:new ca(this.http,this.socket,this.cache,this.logger.child("user")),server:new da(this.http,this.socket,this.cache,this.logger.child("server")),map:new ha(this.socket,n,{maxSubscriptions:((s=e.map2)==null?void 0:s.maxSubscriptions)??500},this.logger.child("map")),mapStats:new fa(this.http,100,500,this.logger.child("mapStats")),navigation:new pa(50,this.logger.child("navigation"))},this.tokenRefreshIntervalMs=e.tokenRefresh===!1?null:((o=e.tokenRefresh)==null?void 0:o.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 ma{constructor(e){_(this,"token");this.token=e.token}async authenticate(e){return this.token}}class ya{constructor(e){_(this,"email");_(this,"password");this.email=e.email,this.password=e.password}async authenticate(e){return(await e.auth.signin(this.email,this.password)).token}}class va{async authenticate(e){return"guest"}}const ba=1,tt="data";class wa{constructor(e){_(this,"namespace");_(this,"db",null);_(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 n=indexedDB.open(this.dbName,ba);n.onupgradeneeded=()=>{n.result.createObjectStore(tt)},n.onsuccess=()=>{this.db=n.result,this.openPromise=null,e(n.result)},n.onerror=()=>t(n.error),n.onblocked=()=>t(new Error(`IndexedDB open blocked: ${this.dbName}`))}),this.openPromise)}async get(e){const t=await this.open();return new Promise((n,i)=>{const o=t.transaction(tt,"readonly").objectStore(tt).get(e);o.onsuccess=()=>n(o.result??null),o.onerror=()=>i(o.error)})}async set(e,t){const n=await this.open();return new Promise((i,s)=>{const c=n.transaction(tt,"readwrite").objectStore(tt).put(t,e);c.onsuccess=()=>i(),c.onerror=()=>s(c.error)})}async delete(e){const t=await this.open();return new Promise((n,i)=>{const o=t.transaction(tt,"readwrite").objectStore(tt).delete(e);o.onsuccess=()=>n(),o.onerror=()=>i(o.error)})}async clear(){const e=await this.open();return new Promise((t,n)=>{const s=e.transaction(tt,"readwrite").objectStore(tt).clear();s.onsuccess=()=>t(),s.onerror=()=>n(s.error)})}}class Wi{constructor(){_(this,"subs",[])}add(e){this.subs.push(e)}dispose(){for(const e of this.subs)e.dispose();this.subs.length=0}}const xa=5*6e4;function eo(r,e){try{return`screeps:${r}:${new URL(e).hostname}`}catch{return`screeps:${r}:${e}`}}function to(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 ro(r,e){if(!(typeof sessionStorage>"u"))try{sessionStorage.setItem(r,JSON.stringify({data:e,expires:Date.now()+xa}))}catch{}}function Yr(r){return r.endsWith("/")?r:`${r}/`}async function _a(r){const e=eo("version",r),t=to(e);if(t)return t;const n=await fetch(`${Yr(r)}api/version`);if(!n.ok)throw new Error(`HTTP ${n.status}`);const i=await n.json();return ro(e,i),i}async function $a(r){const e=eo("authmod",r),t=to(e);if(t)return t;const n=await fetch(`${Yr(r)}api/authmod`);if(!n.ok)return null;const i=await n.json();return i.ok?(ro(e,i),i):null}async function Sa(r,e){const t=new URLSearchParams({username:e}),n=await fetch(`${Yr(r)}api/register/check-username?${t}`);if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json()}async function ka(r,e){const t=new URLSearchParams({email:e}),n=await fetch(`${Yr(r)}api/register/check-email?${t}`);if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json()}async function Ca(r,e,t,n){const i=await fetch(`${Yr(r)}api/register/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,email:t,password:n})});if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}function Ta(r,e){return r.serverData.features.find(t=>t.name===e)}function no(r){return Ta(r,"screepsmod-auth")}const In={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,n=Math.PI/2+Math.PI/3,i=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(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)} Z M 50 50 L ${50+100*Math.cos(i-e/2)} ${50+100*Math.sin(i-e/2)} L ${50+100*Math.cos(i+e/2)} ${50+100*Math.sin(i+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,n=20,i=80;this.path1=`M ${t-e} 0 H ${t+e} V 100 H ${t-e}`,this.path2=`M ${n-e} 0 H ${n+e} V 100 H ${n-e} Z M ${i-e} 0 H ${i+e} V 100 H ${i-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 n=70;r>0&&(e+=r/100*20),r<0&&(t+=r/100*30),this.path1=`M 50 ${e} L 100 ${e+n} V 101 H 0 V ${e+n} Z`,this.path2=`M 50 ${e+t} L 100 ${e+t+n} V 101 H 0 V ${e+t+n} 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 n=50-50*Math.cos(Math.PI/4),i=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 ${n} ${i} Q ${e} 50 ${n} ${100-i} H 0 V ${i} Z M ${100-n} ${i} Q ${100-e} 50 ${100-n} ${100-i} H 100 V ${i} Z`,this.path2=`M ${n} ${i} Q 50 ${t} ${100-n} ${i} V 0 H ${n} Z M ${n} ${100-i} Q 50 ${100-t} ${100-n} ${100-i} V 100 H ${n} 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,n=45,i=10;this.path1=`M ${50-t-e} ${100+i} A ${t+e} ${t+e} 0 0 1 ${50+t+e} ${100+i} H ${50+t-e} A ${t-e} ${t-e} 0 1 0 ${50-t+e} ${100+i}`,this.path2=`M ${50-n-e} ${100+i} A ${n+e} ${n+e} 0 0 1 ${50+n+e} ${100+i} H ${50+n-e} A ${n-e} ${n-e} 0 1 0 ${50-n+e} ${100+i}`},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 n=0;n<3;n++){const i=n*Math.PI*2/3+e/2-Math.PI/2,s=n*Math.PI*2/3-e/2-Math.PI/2;this.path1+=`M ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} L ${50+100*Math.cos(s)} ${50+100*Math.sin(s)} L ${50+t*Math.cos(s)} ${50+t*Math.sin(s)} A ${t} ${t} 0 0 1 ${50+t*Math.cos(i)} ${50+t*Math.sin(i)} Z`}this.path2="";for(let n=0;n<3;n++){const i=n*Math.PI*2/3+e/2+Math.PI/2,s=n*Math.PI*2/3-e/2+Math.PI/2;this.path2+=`M ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} L ${50+100*Math.cos(s)} ${50+100*Math.sin(s)} L ${50+t*Math.cos(s)} ${50+t*Math.sin(s)} A ${t} ${t} 0 0 1 ${50+t*Math.cos(i)} ${50+t*Math.sin(i)} 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 n=0;n<3;n++){const i=Math.PI*2/3*n+e/2-Math.PI/2,s=Math.PI*2/3*n-e/2-Math.PI/2,o=`M ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} L ${50+100*Math.cos(s)} ${50+100*Math.sin(s)} L ${50+t*Math.cos((i+s)/2)} ${50+t*Math.sin((i+s)/2)} Z`;n?this.path2+=o:this.path1+=o}},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 n=-4;n<4;n++){const i=(t+n)%2;this.path2+=`M ${50-e-e*2*t} ${50-e-e*2*(n+i)} 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 n=-4;n<=4;n++)this.path1+=`M ${50-e*n*2} ${50-t} l ${-e} ${-t} l ${-e} ${t} l ${e} ${t} Z`;this.path2="";for(let n=-4;n<=4;n++)this.path2+=`M ${50-e*n*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 Nn(r){const e=Math.round(r).toString(16);return e.length<2?"0"+e:e}function pt(r,e,t){const n=(1-Math.abs(2*t-1))*e,i=r/60,s=n*(1-Math.abs(i%2-1));let o=0,c=0,l=0;!Number.isNaN(r)&&r!==null&&r!==void 0&&(i>=0&&i<1?(o=n,c=s,l=0):i>=1&&i<2?(o=s,c=n,l=0):i>=2&&i<3?(o=0,c=n,l=s):i>=3&&i<4?(o=0,c=s,l=n):i>=4&&i<5?(o=s,c=0,l=n):i>=5&&i<6&&(o=n,c=0,l=s));const a=t-n/2,h=(o+a)*255,u=(c+a)*255,d=(l+a)*255;return"#"+Nn(h)+Nn(u)+Nn(d)}function Ma(){const r=[];let e=0;r.push({index:e++,rgb:pt(0,0,.8)});for(let t=0;t<19;t++)r.push({index:e++,rgb:pt(t*360/19,.6,.8)});r.push({index:e++,rgb:pt(0,0,.5)});for(let t=0;t<19;t++)r.push({index:e++,rgb:pt(t*360/19,.7,.5)});r.push({index:e++,rgb:pt(0,0,.3)});for(let t=0;t<19;t++)r.push({index:e++,rgb:pt(t*360/19,.4,.3)});r.push({index:e++,rgb:pt(0,0,.1)});for(let t=0;t<19;t++)r.push({index:e++,rgb:pt(t*360/19,.5,.1)});return r}const Er=Ma();function Dn(r){if(typeof r=="string")return r;if(typeof r=="number"){const e=Er[r];return e?e.rgb:"#000000"}return"#000000"}function On(r){const e=Dn(r.color1),t=Dn(r.color2),n=Dn(r.color3),i=r.param??0;if(typeof r.type=="number"){const h=In[r.type];h&&h.calc(i)}let s=0;if(r.flip&&typeof r.type=="number"){const h=In[r.type];(h==null?void 0:h.flip)==="rotate180"&&(s=180),(h==null?void 0:h.flip)==="rotate90"&&(s=90),(h==null?void 0:h.flip)==="rotate45"&&(s=45)}let o,c;if(typeof r.type=="number"){const h=In[r.type];o=(h==null?void 0:h.path1)??"",c=(h==null?void 0:h.path2)??""}else o=r.type.path1,c=r.type.path2;const l=50;let a='<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 100 100" shape-rendering="geometricPrecision">';return a+=`<defs><clipPath id="clip"><circle cx="50" cy="50" r="${l}"/></clipPath></defs>`,a+=`<g transform="rotate(${s} 50 50)">`,a+=`<rect x="0" y="0" width="100" height="100" fill="${e}" clip-path="url(#clip)"/>`,o&&(a+=`<path d="${o}" fill="${t}" clip-path="url(#clip)"/>`),c&&(a+=`<path d="${c}" fill="${n}" clip-path="url(#clip)"/>`),a+='<circle cx="50" cy="50" r="47.5" fill="transparent" stroke="#000" stroke-width="5"/>',a+="</g></svg>",a}const[Ea,ls]=F([]);let Ra=0;function Se(r,e="success",t=4e3){const n=Ra++;ls(i=>[...i,{id:n,message:r,type:e,duration:t}]),setTimeout(()=>{ls(i=>i.filter(s=>s.id!==n))},t)}const Pa=!1;function Ln(){return typeof window>"u"?!1:window.location.pathname.startsWith("/client")}function Oa(){return Pa}function Yi(){return window.location.origin}function La(){return"0.5.0"}function Aa(){return typeof window>"u"?null:window.__SCREEPS_CLIENT_EMBEDDED__??null}function An(){return"/".replace(/\/$/,"")}function _t(r){const e=`[${r}]`;return{log:()=>{},warn:()=>{},error:(...t)=>console.error(e,...t)}}const ve={room:"screeps:room",shard:"screeps:shard",sidebarWidth:"screeps:sidebarWidth",consoleHeight:"screeps:consoleHeight",consoleWeights:"screeps:consoleWeights",memoryWatches:"screeps:memoryWatches",mapZoom:"screeps:mapZoom",widescreenMode:"screeps:settings:widescreenMode",showCreepLabels:"screeps:settings:showCreepLabels",showMapRoomNames:"screeps:settings:showMapRoomNames",showUnclaimableRooms:"screeps:settings:showUnclaimableRooms",terrainEffects:"screeps:settings:terrainEffects",showRoomVisuals:"screeps:settings:showRoomVisuals",spriteTheme:"screeps:settings:spriteTheme"},Be={url:"screeps:url",token:"screeps:token",serverPassword:"screeps:serverPassword"};function Gn(r){return localStorage.getItem(r)}function as(r,e){localStorage.setItem(r,e)}function Ia(r){localStorage.removeItem(r)}function Vr(r,e){const t=localStorage.getItem(r);if(t===null)return e;const n=Number(t);return Number.isFinite(n)&&n!==0?n:e}function zn(r,e){localStorage.setItem(r,String(e))}function io(r,e){const t=localStorage.getItem(r);if(t===null)return e;try{return JSON.parse(t)}catch{return e}}function Xi(r,e){localStorage.setItem(r,JSON.stringify(e))}function sn(r){return sessionStorage.getItem(r)}function qr(r,e){sessionStorage.setItem(r,e)}function Rr(r){sessionStorage.removeItem(r)}async function Na(){if(localStorage.clear(),indexedDB.databases){const r=await indexedDB.databases();await Promise.all(r.map(e=>e.name?new Promise(t=>{const n=indexedDB.deleteDatabase(e.name);n.onsuccess=()=>t(),n.onerror=()=>t(),n.onblocked=()=>t()}):Promise.resolve()))}if("caches"in window){const r=await caches.keys();await Promise.all(r.map(e=>caches.delete(e)))}}const{log:Ze}=_t("client"),[he,on]=F(null),[It,Qt]=F("idle"),[cs,ln]=F(null),[Fe,hi]=F(null),[ji,fi]=F(null),[ze,an]=F(null),[mn,so]=F(null),[Ye,oo]=F(!1),[Bn,lo]=F(null),[Da,ao]=F({}),[Ht,co]=F(null);let cn=-1,pi=-1;const er=[],Ga=5;function za(r){if(r===void 0)return;const e=Date.now();if(cn>=0&&r>cn){const t=e-pi;if(t>0){er.push(t),er.length>Ga&&er.shift();const n=er.reduce((i,s)=>i+s,0)/er.length;so(Math.round(n))}}cn=r,pi=e}function Ba(){cn=-1,pi=-1,er.length=0,so(null)}const uo=()=>{var e,t;const r=ji();return r?(((t=(e=r.serverData)==null?void 0:e.shards)==null?void 0:t.length)??0)===0:null};async function Ot(r){Ln()&&(r={...r,url:Yi()}),Ze(`connecting to ${r.url} (auth: ${r.auth})`),Qt("connecting"),ln(null);try{let e;if(r.auth==="guest")e=new va,oo(!0);else if(r.auth==="password"){if(!r.email||!r.password)throw new Error("Email and password are required");e=new ya({email:r.email,password:r.password})}else{if(!r.token)throw new Error("Token is required");e=new ma({token:r.token})}const t=new ga({url:r.url,auth:e,storage:r.storage??new wa("screeps-client"),debug:!1,serverPassword:r.serverPassword});t.http.on("http:tokenRefresh",({token:n})=>{Ze("token refreshed"),qr(Be.token,n)}),t.http.on("http:error",({method:n,path:i,error:s})=>{Ze("http error:",n,i,s.message),Se(`Request failed: ${n} ${i} — ${s.message}`,"error",6e3)}),t.stores.server.on("server:disconnected",n=>{Ze(`server disconnected (willReconnect: ${n.willReconnect})`),n.willReconnect||(Qt("idle"),on(null),hi(null),fi(null))}),t.stores.server.on("server:error",n=>{Ze("server error:",n.error.message),ln(n.error.message),Qt("error")}),t.stores.user.on("user:me",n=>{Ze(`user: ${n.username} (id: ${n._id})`),hi(n)}),t.stores.server.on("server:version",n=>{Ze(`server version: ${n.package??"unknown"}`),fi(n)}),t.stores.user.on("user:stream",n=>{if(n&&typeof n=="object"&&"flags"in n){const i=n.flags;i&&typeof i=="object"&&ao(i)}}),t.stores.user.on("user:worldStatus",({status:n})=>{Ze(`world status: ${n}`),co(n)}),await t.connect(),t.stores.user.subscribeUserStream(),on(t),Qt("connected"),Ze(`connected to ${r.url}`),t.stores.server.worldInfo().then(n=>{lo(n),Ze(`world: ${n.width}x${n.height} x[${n.minX},${n.maxX}] y[${n.minY},${n.maxY}]`)}).catch(()=>{}),qr(Be.url,r.url),t.http.token&&qr(Be.token,t.http.token),r.serverPassword?qr(Be.serverPassword,r.serverPassword):Rr(Be.serverPassword)}catch(e){const t=e instanceof Error?e.message:String(e);throw ln(t),Qt("error"),on(null),e}}async function Fa(){const r=Ln()?Yi():sn(Be.url),e=sn(Be.token);if(!r||!e)return;const t=sn(Be.serverPassword)??void 0;try{e==="guest"?await Ot({url:r,auth:"guest",storage:null,serverPassword:t}):await Ot({url:r,auth:"token",token:e,serverPassword:t})}catch{Rr(Be.token)}}function Ha(){const r=he();r&&r.disconnect(),on(null),Qt("idle"),ln(null),hi(null),fi(null),an(null),oo(!1),lo(null),ao({}),co(null),Ba(),Rr(Be.token),Rr(Be.url),Rr(Be.serverPassword)}/**
4
+ * @license lucide-solid v0.513.0 - ISC
5
+ *
6
+ * This source code is licensed under the ISC license.
7
+ * See the LICENSE file in the root directory of this source tree.
8
+ */var Ua={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"},jt=Ua,Wa=R("<svg>"),ds=r=>r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Ya=r=>r.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()),Xa=r=>{const e=Ya(r);return e.charAt(0).toUpperCase()+e.slice(1)},ja=(...r)=>r.filter((e,t,n)=>!!e&&e.trim()!==""&&n.indexOf(e)===t).join(" ").trim(),Va=r=>{const[e,t]=Ys(r,["color","size","strokeWidth","children","class","name","iconNode","absoluteStrokeWidth"]);return(()=>{var n=Wa();return qs(n,ye(jt,{get width(){return e.size??jt.width},get height(){return e.size??jt.height},get stroke(){return e.color??jt.stroke},get"stroke-width"(){return ee(()=>!!e.absoluteStrokeWidth)()?Number(e.strokeWidth??jt["stroke-width"])*24/Number(e.size):Number(e.strokeWidth??jt["stroke-width"])},get class(){return ja("lucide","lucide-icon",...e.name!=null?[`lucide-${ds(Xa(e.name))}`,`lucide-${ds(e.name)}`]:[],e.class!=null?e.class:"")}},t),!0,!0),g(n,b(xe,{get each(){return e.iconNode},children:([i,s])=>b(Zs,ye({component:i},s))})),n})()},be=Va,qa=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742",key:"178tsu"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05",key:"1hqiys"}]],Za=r=>b(be,ye(r,{iconNode:qa,name:"bell-off"})),Ka=Za,Ja=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],Qa=r=>b(be,ye(r,{iconNode:Ja,name:"bell"})),ec=Qa,tc=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],rc=r=>b(be,ye(r,{iconNode:tc,name:"check"})),ho=rc,nc=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],ic=r=>b(be,ye(r,{iconNode:nc,name:"chevron-down"})),sc=ic,oc=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],lc=r=>b(be,ye(r,{iconNode:oc,name:"chevron-right"})),fo=lc,ac=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],cc=r=>b(be,ye(r,{iconNode:ac,name:"chevron-left"})),dc=cc,uc=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]],hc=r=>b(be,ye(r,{iconNode:uc,name:"clock"})),fc=hc,pc=[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]],gc=r=>b(be,ye(r,{iconNode:pc,name:"code-xml"})),mc=gc,yc=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],vc=r=>b(be,ye(r,{iconNode:yc,name:"eye"})),po=vc,bc=[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]],wc=r=>b(be,ye(r,{iconNode:bc,name:"flag"})),go=wc,xc=[["path",{d:"m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9",key:"eefl8a"}],["path",{d:"m18 15 4-4",key:"16gjal"}],["path",{d:"m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172V7l-2.26-2.26a6 6 0 0 0-4.202-1.756L9 2.96l.92.82A6.18 6.18 0 0 1 12 8.4V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5",key:"b7pghm"}]],_c=r=>b(be,ye(r,{iconNode:xc,name:"hammer"})),$c=_c,Sc=[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]],kc=r=>b(be,ye(r,{iconNode:Sc,name:"layout-grid"})),Cc=kc,Tc=[["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m16.2 7.8 2.9-2.9",key:"r700ao"}],["path",{d:"M18 12h4",key:"wj9ykh"}],["path",{d:"m16.2 16.2 2.9 2.9",key:"1bxg5t"}],["path",{d:"M12 18v4",key:"jadmvz"}],["path",{d:"m4.9 19.1 2.9-2.9",key:"bwix9q"}],["path",{d:"M2 12h4",key:"j09sii"}],["path",{d:"m4.9 4.9 2.9 2.9",key:"giyufr"}]],Mc=r=>b(be,ye(r,{iconNode:Tc,name:"loader"})),Ec=Mc,Rc=[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]],Pc=r=>b(be,ye(r,{iconNode:Rc,name:"log-out"})),Oc=Pc,Lc=[["path",{d:"M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z",key:"169xi5"}],["path",{d:"M15 5.764v15",key:"1pn4in"}],["path",{d:"M9 3.236v15",key:"1uimfh"}]],Ac=r=>b(be,ye(r,{iconNode:Lc,name:"map"})),Ic=Ac,Nc=[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m19 9 3 3-3 3",key:"1mg7y2"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m5 9-3 3 3 3",key:"j64kie"}],["path",{d:"m9 5 3-3 3 3",key:"l8vdw6"}]],Dc=r=>b(be,ye(r,{iconNode:Nc,name:"move"})),Gc=Dc,zc=[["rect",{x:"14",y:"4",width:"4",height:"16",rx:"1",key:"zuxfzm"}],["rect",{x:"6",y:"4",width:"4",height:"16",rx:"1",key:"1okwgv"}]],Bc=r=>b(be,ye(r,{iconNode:zc,name:"pause"})),Fc=Bc,Hc=[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]],Uc=r=>b(be,ye(r,{iconNode:Hc,name:"play"})),Wc=Uc,Yc=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],Xc=r=>b(be,ye(r,{iconNode:Yc,name:"plus"})),jc=Xc,Vc=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],qc=r=>b(be,ye(r,{iconNode:Vc,name:"refresh-cw"})),Zc=qc,Kc=[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],Jc=r=>b(be,ye(r,{iconNode:Kc,name:"settings"})),Qc=Jc,ed=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],td=r=>b(be,ye(r,{iconNode:ed,name:"terminal"})),rd=td,nd=[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]],id=r=>b(be,ye(r,{iconNode:nd,name:"trash-2"})),dn=id,sd=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],od=r=>b(be,ye(r,{iconNode:sd,name:"x"})),Ut=od,ld=R("<span style=font-size:11px;display:inline-flex;align-items:center;gap:3px>"),ad=R('<div style="color:#3fb950;font-size:14px;text-align:center;padding:8px 0">Account created! Logging you in…'),cd=R("<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>"),dd=R("<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>"),ud=R("<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>"),hd=R("<span style=font-size:11px;color:#f85149>Passwords don't match"),fd=R("<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>"),pd=R("<button type=submit style=padding:10px;border-radius:6px;border:none;background:#238636;color:#fff;font-weight:600>"),gd=R('<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'),md=R("<form style=display:flex;flex-direction:column;gap:16px><h2 style=margin:0;font-size:20px>Create Account"),mo=R("<div style=color:#f85149;font-size:13px>"),yd=R('<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">'),vd=R("<button type=button style=background:none;border:none;color:#58a6ff;font-size:12px;cursor:pointer;padding:0>Create account"),bd=R('<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'),wd=R("<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>"),xd=R("<div style=color:#8b949e;font-size:12px;margin-top:-8px>"),_d=R("<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>"),$d=R("<button type=button style=padding:10px;border-radius:6px;border:none;background:#1b2838;color:#c7d5e0;font-weight:600>Login with Steam"),Sd=R('<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)'),kd=R('<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>'),Cd=R('<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>'),Td=R('<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">'),Md=R("<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>"),Ed=R("<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>"),Rd=R("<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>"),Pd=R('<span style="font-size:11px;padding:2px 8px;border-radius:12px;background:#21262d;border:1px solid #30363d;color:#8b949e;font-family:monospace">');const ot={padding:"8px 12px","border-radius":"6px",border:"1px solid #30363d",background:"#0d1117",color:"#c9d1d9"};function Od(r){const[e,t]=F(null),[n,i]=F(null),[s,o]=F(null);return fe(()=>{const c=r();t(null),i(null),o(null);let l=!1;const a=setTimeout(async()=>{try{const h=await _a(c);if(l)return;if(t(h),o(null),no(h)){const u=await $a(c);l||i(u)}}catch{l||(o("Could not reach server"),t(null))}},400);Le(()=>{l=!0,clearTimeout(a)})}),{serverVersion:e,authModInfo:n,serverError:s}}function us(r,e,t){const[n,i]=F("idle");return fe(()=>{const s=e();if(!s){i("idle");return}i("checking");let o=!1;const c=setTimeout(async()=>{try{const l=await t(r(),s);o||i(l.error?"taken":"available")}catch{o||i("error")}},500);Le(()=>{o=!0,clearTimeout(c)})}),n}function hs(r){const e={idle:null,checking:{children:"Checking…",color:"#8b949e"},available:{children:[b(ho,{size:12})," Available"],color:"#3fb950"},taken:{children:[b(Ut,{size:12})," Already taken"],color:"#f85149"},error:{children:"Could not verify",color:"#d29922"}},t=()=>e[r.state];return b(Z,{get when(){return t()},get children(){var n=ld();return g(n,()=>t().children),N(i=>Y(n,"color",t().color)),n}})}function Ld(r){const[e,t]=F(""),[n,i]=F(""),[s,o]=F(""),[c,l]=F(""),[a,h]=F(!1),[u,d]=F(null),[f,p]=F(!1),m=us(()=>r.url,e,Sa),S=us(()=>r.url,n,ka),O=()=>c()!==""&&s()!==c(),z=()=>!a()&&e()!==""&&n()!==""&&s().length>=4&&s()===c()&&m()!=="taken"&&m()!=="checking"&&S()!=="taken"&&S()!=="checking",P=async k=>{if(k.preventDefault(),!!z()){h(!0),d(null);try{const C=await Ca(r.url,e(),n(),s());if(C.error){d(C.error);return}p(!0),setTimeout(()=>r.onSuccess(n(),s()),1500)}catch(C){d(C instanceof Error?C.message:"Registration failed")}finally{h(!1)}}};return(()=>{var k=md();return k.firstChild,k.addEventListener("submit",P),g(k,b(Z,{get when(){return f()},get children(){return ad()}}),null),g(k,b(Z,{get when(){return!f()},get children(){return[(()=>{var C=cd(),w=C.firstChild;w.firstChild;var I=w.nextSibling;return g(w,b(hs,{get state(){return m()}}),null),I.$$input=y=>t(y.currentTarget.value),N(y=>{var $=ot,L=a();return y.e=Q(I,$,y.e),L!==y.t&&(I.disabled=y.t=L),y},{e:void 0,t:void 0}),N(()=>I.value=e()),C})(),(()=>{var C=dd(),w=C.firstChild;w.firstChild;var I=w.nextSibling;return g(w,b(hs,{get state(){return S()}}),null),I.$$input=y=>i(y.currentTarget.value),N(y=>{var $=ot,L=a();return y.e=Q(I,$,y.e),L!==y.t&&(I.disabled=y.t=L),y},{e:void 0,t:void 0}),N(()=>I.value=n()),C})(),(()=>{var C=ud(),w=C.firstChild,I=w.nextSibling;return I.$$input=y=>o(y.currentTarget.value),N(y=>{var $=ot,L=a();return y.e=Q(I,$,y.e),L!==y.t&&(I.disabled=y.t=L),y},{e:void 0,t:void 0}),N(()=>I.value=s()),C})(),(()=>{var C=fd(),w=C.firstChild;w.firstChild;var I=w.nextSibling;return g(w,b(Z,{get when(){return O()},get children(){return hd()}}),null),I.$$input=y=>l(y.currentTarget.value),N(y=>{var $={...ot,border:O()?"1px solid #f85149":"1px solid #30363d"},L=a();return y.e=Q(I,$,y.e),L!==y.t&&(I.disabled=y.t=L),y},{e:void 0,t:void 0}),N(()=>I.value=c()),C})(),ee(()=>ee(()=>!!u())()&&(()=>{var C=mo();return g(C,u),C})()),(()=>{var C=pd();return g(C,()=>a()?"Creating account…":"Create Account"),N(w=>{var I=!z(),y=z()?"pointer":"not-allowed",$=z()?1:.5;return I!==w.e&&(C.disabled=w.e=I),y!==w.t&&Y(C,"cursor",w.t=y),$!==w.a&&Y(C,"opacity",w.a=$),w},{e:void 0,t:void 0,a:void 0}),C})(),(()=>{var C=gd();return C.$$click=()=>r.onCancel(),C})()]}}),null),k})()}function Ad(){const r=Ln(),e=Oa(),[t,n]=F("login"),[i,s]=F("password"),[o,c]=F(r?Yi():window.location.origin),[l,a]=F(""),[h,u]=F(""),[d,f]=F(""),[p,m]=F(""),{serverVersion:S,authModInfo:O,serverError:z}=Od(o),P=()=>{var T,E;return((E=(T=S())==null?void 0:T.serverData)==null?void 0:E.welcomeText)??null},k=()=>{var T,E;return(((E=(T=S())==null?void 0:T.serverData)==null?void 0:E.features)??[]).filter(M=>M.name!=="auth"&&M.version!=null)},C=()=>{var E,M;const T=S();return T?((M=(E=no(T))==null?void 0:E.authTypes)==null?void 0:M.includes("steam"))??!0:!0},w=()=>{var T,E,M;return((T=O())==null?void 0:T.allowRegistration)===!0||(((M=(E=S())==null?void 0:E.serverData)==null?void 0:M.features)??[]).some(A=>A.name==="official-like")},I=()=>{const T=o().replace(/\/$/,""),E=window.open(`${T}/api/auth/steam`,"screeps-steam-auth","width=800,height=600,left=200,top=100"),M=U=>{try{const G=JSON.parse(U.data);G.token&&(D(),Ot({url:T,auth:"token",token:G.token,serverPassword:p()||void 0,storage:null}))}catch{}},A=setInterval(()=>{E!=null&&E.closed&&D()},500),D=()=>{clearInterval(A),window.removeEventListener("message",M)};window.addEventListener("message",M),Le(D)},y=async T=>{T.preventDefault(),await Ot({url:o(),auth:i(),email:l()||void 0,password:h()||void 0,token:d()||void 0,serverPassword:p()||void 0,storage:null})},$=async T=>{T.preventDefault(),await Ot({url:o(),auth:"guest",serverPassword:p()||void 0,storage:null})},L=async(T,E)=>{try{await Ot({url:o(),auth:"password",email:T,password:E,serverPassword:p()||void 0,storage:null})}catch{n("login"),s("password"),a(T),u(E)}},v=()=>It()==="connecting";return(()=>{var T=Td(),E=T.firstChild;return g(T,b(Z,{get when(){return P()},get children(){var M=yd();return N(()=>M.innerHTML=P()),M}}),E),g(E,b(Z,{get when(){return t()==="register"},get children(){return b(Ld,{get url(){return o()},get serverPassword(){return p()},onSuccess:L,onCancel:()=>n("login")})}}),null),g(E,b(Z,{get when(){return t()==="login"},get children(){var M=kd(),A=M.firstChild;A.firstChild;var D=A.nextSibling,U=D.firstChild,G=U.firstChild;G.nextSibling;var B=U.nextSibling,V=D.nextSibling;return M.addEventListener("submit",y),g(A,b(Z,{get when(){return w()},get children(){var X=vd();return X.$$click=()=>n("register"),X}}),null),g(M,b(Z,{when:!r,get children(){var X=bd(),j=X.firstChild,q=j.nextSibling;return j.$$click=()=>s("password"),q.$$click=()=>s("token"),N(H=>{var K=i()==="password"?"#238636":"transparent",le=i()==="token"?"#238636":"transparent";return K!==H.e&&Y(j,"background",H.e=K),le!==H.t&&Y(q,"background",H.t=le),H},{e:void 0,t:void 0}),X}}),D),g(M,b(Z,{when:!r,get children(){return[(()=>{var X=wd(),j=X.firstChild,q=j.nextSibling;return q.$$input=H=>c(H.currentTarget.value),N(H=>Q(q,ot,H)),N(()=>q.value=o()),X})(),b(Z,{get when(){return z()},get children(){var X=xd();return g(X,z),X}})]}}),D),g(M,(()=>{var X=ee(()=>i()==="password");return()=>X()?[(()=>{var j=Md(),q=j.firstChild,H=q.nextSibling;return H.$$input=K=>a(K.currentTarget.value),N(K=>Q(H,ot,K)),N(()=>H.value=l()),j})(),(()=>{var j=Ed(),q=j.firstChild,H=q.nextSibling;return H.$$input=K=>u(K.currentTarget.value),N(K=>Q(H,ot,K)),N(()=>H.value=h()),j})()]:(()=>{var j=Rd(),q=j.firstChild,H=q.nextSibling;return H.$$input=K=>f(K.currentTarget.value),N(K=>Q(H,ot,K)),N(()=>H.value=d()),j})()})(),D),B.$$input=X=>m(X.currentTarget.value),g(M,(()=>{var X=ee(()=>!!cs());return()=>X()&&(()=>{var j=mo();return g(j,cs),j})()})(),V),g(V,()=>v()?"Connecting…":"Connect"),g(M,b(Z,{get when(){return C()},get children(){return[(()=>{var X=_d(),j=X.firstChild,q=j.nextSibling;return q.nextSibling,X})(),(()=>{var X=$d();return X.$$click=I,N(j=>{var q=v(),H=v()?"not-allowed":"pointer",K=v()?.6:1;return q!==j.e&&(X.disabled=j.e=q),H!==j.t&&Y(X,"cursor",j.t=H),K!==j.a&&Y(X,"opacity",j.a=K),j},{e:void 0,t:void 0,a:void 0}),X})()]}}),null),g(M,b(Z,{when:!r||e,get children(){var X=Sd();return X.addEventListener("mouseleave",j=>{j.currentTarget.style.borderColor="#30363d"}),X.addEventListener("mouseenter",j=>{v()||(j.currentTarget.style.borderColor="#8b949e")}),X.$$click=$,N(j=>{var q=v(),H=v()?"not-allowed":"pointer",K=v()?.6:1;return q!==j.e&&(X.disabled=j.e=q),H!==j.t&&Y(X,"cursor",j.t=H),K!==j.a&&Y(X,"opacity",j.a=K),j},{e:void 0,t:void 0,a:void 0}),X}}),null),N(X=>{var j=ot,q=v(),H=v()?"not-allowed":"pointer",K=v()?.6:1;return X.e=Q(B,j,X.e),q!==X.t&&(V.disabled=X.t=q),H!==X.a&&Y(V,"cursor",X.a=H),K!==X.o&&Y(V,"opacity",X.o=K),X},{e:void 0,t:void 0,a:void 0,o:void 0}),N(()=>B.value=p()),M}}),null),g(T,b(Z,{get when(){return k().length>0},get children(){var M=Cd(),A=M.firstChild,D=A.nextSibling;return g(D,b(xe,{get each(){return k()},children:U=>(()=>{var G=Pd();return g(G,()=>U.name,null),g(G,(()=>{var B=ee(()=>!!U.version);return()=>B()?` ${U.version}`:""})(),null),G})()})),M}}),null),T})()}Ee(["input","click"]);var Id=R('<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'),Nd=R('<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 Dd(){const r=()=>{switch(It()){case"connected":return"#238636";case"connecting":return"#d29922";case"error":return"#f85149";default:return"#8b949e"}};return(()=>{var e=Nd(),t=e.firstChild,n=t.firstChild,i=n.nextSibling;return g(i,(()=>{var s=ee(()=>It()==="connected");return()=>s()?"Online":It()})()),g(e,b(Z,{get when(){return Ye()},get children(){return Id()}}),null),N(s=>Y(n,"background-color",r())),e})()}class Gd{constructor(e){_(this,"container");_(this,"hoverGraphics");_(this,"pendingGraphics");_(this,"selectionContainer");_(this,"selectionGraphics",new Map);_(this,"selectionTypes",new Map);_(this,"selectionVisuals",new Map);_(this,"ticker",null);_(this,"tickerCallback",null);this.container=new Ae,this.container.label="hoverHighlight",this.container.eventMode="none",this.hoverGraphics=new re,this.hoverGraphics.eventMode="none",this.container.addChild(this.hoverGraphics),this.pendingGraphics=new re,this.pendingGraphics.eventMode="none",this.container.addChild(this.pendingGraphics),this.selectionContainer=new Ae,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 n=e*x,i=t*x;this.hoverGraphics.rect(n,i,x,x),this.hoverGraphics.stroke({width:1,color:16777215,alpha:.35}),this.hoverGraphics.rect(n,i,x,x),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:n,visual:i}of e){const s=new re;s.eventMode="none",this.selectionContainer.addChild(s),this.selectionGraphics.set(t,s),this.selectionTypes.set(t,n),this.selectionVisuals.set(t,i),n==="creep"?this.drawCreepRing(s,i.x,i.y):this.drawStructureBox(s,i.x,i.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 n=e*x,i=t*x,s=n+x/2,o=i+x/2,c=x*.35;this.pendingGraphics.moveTo(s-c,o),this.pendingGraphics.lineTo(s+c,o),this.pendingGraphics.moveTo(s,o-c),this.pendingGraphics.lineTo(s,o+c),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.9}),this.pendingGraphics.rect(n+1,i+1,x-2,x-2),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.6})}clearPendingTile(){this.pendingGraphics.clear()}drawCreepRing(e,t,n){e.clear();const i=t+x/2,s=n+x/2,o=x*.48;e.circle(i,s,o),e.stroke({width:1.5,color:16777215,alpha:.9})}drawStructureBox(e,t,n){e.clear();const i=1;e.rect(t+i,n+i,x-i*2,x-i*2),e.stroke({width:1.5,color:16777215,alpha:.9}),e.rect(t+i,n+i,x-i*2,x-i*2),e.fill({color:16777215,alpha:.04})}trackCreepRings(){for(const[e,t]of this.selectionGraphics){if(this.selectionTypes.get(e)!=="creep")continue;const n=this.selectionVisuals.get(e);!n||n.destroyed||this.drawCreepRing(t,n.x,n.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 x=12,Ne=50*x,ke=48,br=128;class Vi{constructor(e,t){_(this,"app");_(this,"world");_(this,"hoverLayer");_(this,"destroyed",!1);_(this,"canDrag",!1);_(this,"container");_(this,"resizeObserver",null);_(this,"bounceRaf",null);_(this,"wheelTimeout",null);_(this,"navOverlay");_(this,"lastMouseX",0);_(this,"lastMouseY",0);_(this,"onHoverTile",null);_(this,"onClickTile",null);_(this,"onRightClick",null);this.app=e,this.container=t,this.world=new Ae,this.app.stage.addChild(this.world),this.hoverLayer=new Gd(e.ticker),this.world.addChild(this.hoverLayer.container),this.navOverlay=new Ae,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 js;return await t.init({background:"#0d1117",antialias:!0,resolution:window.devicePixelRatio||1,autoDensity:!0}),e.appendChild(t.canvas),new Vi(t,e)}getMinScale(){const t=this.container.clientWidth,n=this.container.clientHeight;return Math.min(t,n)/(Ne+64)}clampView(e=!1){const t=this.world.scale.x,n=Ne*t,i=this.container.clientWidth,s=this.container.clientHeight,o=e?br:0;if(n<=i){const c=i/2-n/2;e?this.world.x=Math.min(c+br,Math.max(c-br,this.world.x)):this.world.x=c}else{const c=i-n-ke-o,l=ke+o;this.world.x=Math.min(l,Math.max(c,this.world.x))}if(n<=s){const c=s/2-n/2;e?this.world.y=Math.min(c+br,Math.max(c-br,this.world.y)):this.world.y=c}else{const c=s-n-ke-o,l=ke+o;this.world.y=Math.min(l,Math.max(c,this.world.y))}this.canDrag=!0}getTargetPosition(){const e=this.world.scale.x,t=Ne*e,n=this.container.clientWidth,i=this.container.clientHeight;let s=null,o=null;if(t<=n)s=n/2-t/2;else{const c=n-t-ke,l=ke;this.world.x<c?s=c:this.world.x>l&&(s=l)}if(t<=i)o=i/2-t/2;else{const c=i-t-ke,l=ke;this.world.y<c?o=c:this.world.y>l&&(o=l)}return s===null&&o===null?null:{x:s??this.world.x,y:o??this.world.y}}springBack(){const e=this.getTargetPosition(),t=this.getTargetScale();if(!e&&t===null)return;const n=this.world.x,i=this.world.y,s=this.world.scale.x,o=performance.now(),c=300,l=this.container.clientWidth/2,a=this.container.clientHeight/2,h=(l-n)/s,u=(a-i)/s,d=f=>{const p=f-o,m=Math.min(1,p/c),S=1-Math.pow(1-m,3);if(t!==null){const O=s+(t-s)*S;this.world.scale.set(O),this.world.x=l-h*O,this.world.y=a-u*O}e&&t===null&&(this.world.x=n+(e.x-n)*S,this.world.y=i+(e.y-i)*S),m<1?this.bounceRaf=requestAnimationFrame(d):(this.bounceRaf=null,this.clampView())};this.cancelBounce(),this.bounceRaf=requestAnimationFrame(d)}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 vr(0,0),n=new vr(0,0);const i=this.app.canvas,s=4;i.style.touchAction="none",i.style.userSelect="none";const o=new Map;let c=!1,l=0,a=0,h=0,u=0;i.addEventListener("pointerdown",f=>{if(this.cancelBounce(),this.cancelWheelTimeout(),o.set(f.pointerId,{x:f.clientX,y:f.clientY}),i.setPointerCapture(f.pointerId),o.size>=2){e=!1,c=!0;const p=[...o.values()],m=i.getBoundingClientRect(),S=(p[0].x+p[1].x)/2-m.left,O=(p[0].y+p[1].y)/2-m.top;h=Math.hypot(p[1].x-p[0].x,p[1].y-p[0].y),u=this.world.scale.x,l=(S-this.world.x)/u,a=(O-this.world.y)/u}else c=!1,e=this.canDrag,t=new vr(f.clientX,f.clientY),n=new vr(f.clientX,f.clientY)}),i.addEventListener("pointermove",f=>{var O;const p=i.getBoundingClientRect();if(this.lastMouseX=f.clientX-p.left,this.lastMouseY=f.clientY-p.top,o.has(f.pointerId)&&o.set(f.pointerId,{x:f.clientX,y:f.clientY}),c&&o.size===2){const z=[...o.values()],P=(z[0].x+z[1].x)/2-p.left,k=(z[0].y+z[1].y)/2-p.top,C=Math.hypot(z[1].x-z[0].x,z[1].y-z[0].y),w=this.getMinScale(),I=5,y=.6;let $=u*(C/h);$<w&&($=w+($-w)*y),$>I&&($=I+($-I)*y),this.cancelBounce(),this.world.scale.set($),this.world.x=P-l*$,this.world.y=k-a*$,this.clampView(!0);return}if(!c){const z=this.screenToTile(this.lastMouseX,this.lastMouseY);this.hoverLayer.setHoveredTile((z==null?void 0:z.tx)??null,(z==null?void 0:z.ty)??null),(O=this.onHoverTile)==null||O.call(this,(z==null?void 0:z.tx)??null,(z==null?void 0:z.ty)??null)}if(!e||!this.canDrag)return;const m=f.clientX-t.x,S=f.clientY-t.y;this.world.x+=m,this.world.y+=S,t=new vr(f.clientX,f.clientY),this.clampView(!0)});const d=f=>{var O;if(i.releasePointerCapture(f.pointerId),o.delete(f.pointerId),c){o.size<2&&(c=!1,e=!1,this.springBack());return}e=!1;const p=f.clientX-n.x,m=f.clientY-n.y;if(Math.sqrt(p*p+m*m)<s){const z=i.getBoundingClientRect(),P=f.clientX-z.left,k=f.clientY-z.top,C=this.screenToTile(P,k);C&&((O=this.onClickTile)==null||O.call(this,C.tx,C.ty,f.ctrlKey||f.metaKey))}this.springBack()};i.addEventListener("pointerup",d),i.addEventListener("pointercancel",d),i.addEventListener("contextmenu",f=>{var p;f.preventDefault(),f.button===2&&((p=this.onRightClick)==null||p.call(this))}),i.addEventListener("pointerleave",()=>{var f;this.hoverLayer.setHoveredTile(null,null),(f=this.onHoverTile)==null||f.call(this,null,null)}),i.addEventListener("wheel",f=>{f.preventDefault();const p=f.deltaY>0?.9:1.1,m=this.getMinScale(),S=5;let O=this.world.scale.x*p;const z=.6;O<m&&(O=m+(O-m)*z),O>S&&(O=S+(O-S)*z);const P=i.getBoundingClientRect(),k=f.clientX-P.left,C=f.clientY-P.top;if(this.cancelBounce(),O<m){const w=this.container.clientWidth/2,I=this.container.clientHeight/2,y=(w-this.world.x)/this.world.scale.x,$=(I-this.world.y)/this.world.scale.y;this.world.scale.set(O),this.world.x=w-y*O,this.world.y=I-$*O}else{const w=(k-this.world.x)/this.world.scale.x,I=(C-this.world.y)/this.world.scale.y;this.world.scale.set(O),this.world.x=k-w*O,this.world.y=C-I*O}this.clampView(),this.cancelWheelTimeout(),this.wheelTimeout=window.setTimeout(()=>{this.wheelTimeout=null,this.springBack()},80)},{passive:!1})}setTileHandlers(e,t,n){this.onHoverTile=e,this.onClickTile=t,this.onRightClick=n??null}screenToTile(e,t){const n=(e-this.world.x)/this.world.scale.x,i=(t-this.world.y)/this.world.scale.y,s=Math.floor(n/x),o=Math.floor(i/x);return s<0||s>=50||o<0||o>=50?null:{tx:s,ty:o}}centerView(){const e=this.container.clientWidth/2,t=this.container.clientHeight/2,n=this.world.scale.x;this.world.x=e-Ne*n/2,this.world.y=t-Ne*n/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(n=>{const{width:i,height:s}=n[0].contentRect;this.app.renderer.resize(i,s),this.clampView()}),this.resizeObserver.observe(this.container)}setupNavigationZones(e){this.navOverlay.removeChildren();const t=(o,c,l,a,h,u)=>{if(!u)return;const d=new re;d.x=o,d.y=c,d.hitArea=new Vs(0,0,l,a),d.fill({color:16777215,alpha:.12}),d.poly(h),d.fill(),d.eventMode="static",d.cursor="pointer",d.alpha=1,d.on("pointerover",()=>{d.clear(),d.fill({color:16777215,alpha:.06}),d.rect(0,0,l,a),d.fill(),d.fill({color:16777215,alpha:.35}),d.poly(h),d.fill()}),d.on("pointerout",()=>{d.clear(),d.fill({color:16777215,alpha:.12}),d.poly(h),d.fill()}),d.on("pointerdown",u),this.navOverlay.addChild(d)},n=Ne/2,i=Ne/2,s=18;t(-ke,0,ke,Ne,[18,i,ke-6,i-s,ke-6,i+s],e.west),t(Ne,0,ke,Ne,[ke-18,i,6,i-s,6,i+s],e.east),t(0,-ke,Ne,ke,[n,18,n-s,ke-6,n+s,ke-6],e.north),t(0,Ne,Ne,ke,[n,ke-18,n-s,6,n+s,6],e.south);for(const o of this.navOverlay.children){const c=o,l=c.hitArea,a=this.world.x+c.x*this.world.scale.x,h=this.world.y+c.y*this.world.scale.y,u=l.width*this.world.scale.x,d=l.height*this.world.scale.y;this.lastMouseX>=a&&this.lastMouseX<=a+u&&this.lastMouseY>=h&&this.lastMouseY<=h+d&&c.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 yo=856343,zd=1448738,Bd=1843496,Fd=3421243,Hd=Fd,Ud=yo,qi=7039337,vo=3159613,Wd=1579032,Yd=0,Xd=2631720,jd=2632986,Vd=2500383,qd=2771488,Zd=5000268,Kd=11122630,Jd=16770413,Qd=7829367,eu=16332866,tu=6127794,ru=6684002,nu=12164347,Zr={tough:Zd,move:Kd,work:Jd,carry:Qd,attack:eu,ranged_attack:tu,heal:ru,claim:nu},Fn=5809919,Nt=7979263,bo=4176208,Hn=9147550,Kr=13801762,fs=10711543,iu=16218298,ps=16273737,Pr=15763518,su=2172461,wo=qi,ou=13226457,Mt=12283502,sr=[16777215,16711680,8388736,255,65535,32768,16776960,16753920,10824234,8421504,16777215],lu={creep:Pr,spawn:Fn,extension:Nt,tower:bo,container:Hn,storage:Kr,link:fs,rampart:Fn,road:wo,wall:su,extractor:Hn,lab:iu,terminal:Kr,observer:Nt,powerSpawn:Pr,nuker:ps,factory:Hn,invaderCore:ps,source:Kr,mineral:Nt,deposit:Kr,controller:Fn,powerBank:Pr,portal:fs},Xr=16771195,au=Xr,cu=Nt,du=Xr,Or=9419667,uu=7245682,hu=12116924,fu=12283502,pu=9787480,gu=14721184,gs=Bd,mu=13684944,Ce=1579032,St=5592405,un=11184810,yu=9419667,je=16771195,vu=16069959,ms=4410435,bu=x*.05,wu=x*.2;function or(r,e,t,n){const i=x,s=i/2;let o=!1;for(let c=0;c<50;c++)for(let l=0;l<50;l++){const a=e.get(l,c)===t,h=c>0&&e.get(l,c-1)===t,u=c<49&&e.get(l,c+1)===t,d=l>0&&e.get(l-1,c)===t,f=l<49&&e.get(l+1,c)===t,p=l*i+s,m=c*i+s;a?(o=!0,!h&&!d&&c>0&&l>0?(r.moveTo(p,c*i),r.arc(p,m,s,-Math.PI/2,Math.PI,!0),r.lineTo(p,m),r.closePath()):r.rect(l*i,c*i,s,s)):h&&d&&e.get(l-1,c-1)===t&&(o=!0,r.moveTo(p,c*i),r.lineTo(l*i,c*i),r.lineTo(l*i,m),r.arc(p,m,s,Math.PI,-Math.PI/2,!1),r.closePath()),a?!h&&!f&&c>0&&l<49?(r.moveTo(p,c*i),r.arc(p,m,s,-Math.PI/2,0,!1),r.lineTo(p,m),r.closePath()):r.rect(p,c*i,s,s):h&&f&&e.get(l+1,c-1)===t&&(o=!0,r.moveTo(p,c*i),r.lineTo(l*i+i,c*i),r.lineTo(l*i+i,m),r.arc(p,m,s,0,-Math.PI/2,!0),r.closePath()),a?!u&&!d&&c<49&&l>0?(r.moveTo(l*i,m),r.arc(p,m,s,Math.PI,Math.PI/2,!0),r.lineTo(p,m),r.closePath()):r.rect(l*i,m,s,s):u&&d&&e.get(l-1,c+1)===t&&(o=!0,r.moveTo(l*i,m),r.lineTo(l*i,c*i+i),r.lineTo(p,c*i+i),r.arc(p,m,s,Math.PI/2,Math.PI,!1),r.closePath()),a?!u&&!f&&c<49&&l<49?(r.moveTo(p,c*i+i),r.arc(p,m,s,Math.PI/2,0,!0),r.lineTo(p,m),r.closePath()):r.rect(p,m,s,s):u&&f&&e.get(l+1,c+1)===t&&(o=!0,r.moveTo(p,c*i+i),r.lineTo(l*i+i,c*i+i),r.lineTo(l*i+i,m),r.arc(p,m,s,0,Math.PI/2,!1),r.closePath())}o&&n(r)}function xu(r,e){const t=qi,n=x,i=(s,o,c)=>{const l=s*n+n/2,a=o*n+n/2,h=n*.3;c==="up"?(r.moveTo(l,a-h),r.lineTo(l+h,a+h),r.lineTo(l-h,a+h)):c==="down"?(r.moveTo(l,a+h),r.lineTo(l+h,a-h),r.lineTo(l-h,a-h)):c==="left"?(r.moveTo(l-h,a),r.lineTo(l+h,a-h),r.lineTo(l+h,a+h)):c==="right"&&(r.moveTo(l+h,a),r.lineTo(l-h,a-h),r.lineTo(l-h,a+h)),r.fill(t)};for(let s=0;s<50;s++)e.get(s,0)!==Xe.Wall&&i(s,0,"up"),e.get(s,49)!==Xe.Wall&&i(s,49,"down");for(let s=0;s<50;s++)e.get(0,s)!==Xe.Wall&&i(0,s,"left"),e.get(49,s)!==Xe.Wall&&i(49,s,"right")}function _u(r){const e=new re;e.rect(0,0,50*x,50*x),e.fill(Hd);const t={color:Vd,width:wu,alignment:0,cap:"round",join:"round"};or(e,r,Xe.Swamp,i=>i.stroke(t)),or(e,r,Xe.Swamp,i=>i.fill(jd));const n={color:Yd,width:bu,alignment:0,cap:"round",join:"round"};return or(e,r,Xe.Wall,i=>i.stroke(n)),or(e,r,Xe.Wall,i=>i.fill(Wd)),xu(e,r),e.rect(0,0,50*x,50*x),e.stroke({width:1,color:vo}),e}function $u(r){const e=new re;return e.label="swampGlow",or(e,r,Xe.Swamp,t=>t.fill(qd)),e.alpha=.45,e.filters=[new _l({strength:5,quality:3})],e}function Su(r,e){const t=new re;or(t,r,Xe.Wall,s=>s.fill(Xd)),t.alpha=.5,t.filters=[new xl({noise:.12,seed:1})],t.filterArea=new Vs(0,0,50*x,50*x);const n=e.generateTexture({target:t,frame:t.filterArea});t.filters=null,t.destroy();const i=new De(n);return i.label="wallNoise",i}function ys(r,e){const t=new Ae,n=Su(r,e),i=t.destroy.bind(t);return t.destroy=s=>{n.destroyed||(n.removeFromParent(),n.destroy({texture:!0,textureSource:!0})),i(s)},t.addChild(_u(r)),t.addChild($u(r)),t.addChild(n),t}function Un(r,e){r.getChildByLabel("swampGlow").visible=e,r.getChildByLabel("wallNoise").visible=e}function ku(r){return new Promise((e,t)=>{const n=new Image;n.onload=()=>e(n),n.onerror=t,n.src=r})}class xo{constructor(){_(this,"cache",new Map);_(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),n=this.cache.get(t);if(n)return Promise.resolve(n);const i=this.pending.get(t);if(i)return i;const s=this.buildTexture(e,t);return this.pending.set(t,s),s.then(()=>{this.pending.delete(t)}).catch(()=>{this.pending.delete(t)}),s}async buildTexture(e,t){const n=On(e),i=new Blob([n],{type:"image/svg+xml;charset=utf-8"}),s=URL.createObjectURL(i);try{const o=window.devicePixelRatio||1,c=128*Math.max(2,o),l=await ku(s),a=document.createElement("canvas");a.width=c,a.height=c,a.getContext("2d").drawImage(l,0,0,c,c);const u=Oe.from(a);return this.cache.set(t,u),u}finally{URL.revokeObjectURL(s)}}destroy(){for(const e of this.cache.values())e.destroyed||e.destroy(!0);this.cache.clear(),this.pending.clear()}}const _o={1:200,2:45e3,3:135e3,4:405e3,5:1215e3,6:3645e3,7:10935e3},$o={1:2e4,2:1e4,3:2e4,4:4e4,5:8e4,6:12e4,7:15e4,8:2e5},Cu=new xo,yt=x*.44,Qe=x*.28,wr=50,Dr=32,gi=12/Dr,mi=x/2-x*.44,So=2,Tu=12*1.2/Dr,Mu=5,Eu=2.5,Jr=2,Wn=2.6,Ru=2,vs=12,bs=15790320,Pu=1710618,ws=x*.42,ko=x*.3,Ou=Math.max(1,x*.08),Lu={H:13421772,O:16777215,U:5822457,L:62626,K:10514943,Z:16631694,X:11568379},Au={H:2236962,O:2236962},Iu=x*.42,Co=32,Nu=9/Co,yi=x-4,xs=x*.28,_s=1600,Du=16776428;function vi(r,e){if(e<=0)return yi;const t=Math.max(0,Math.min(1,r/e));return xs+(yi-xs)*t}function Zi(r,e,t=je){const n=e/2,i=x/2,s=x/2,o=e*.25;r.clear(),r.roundRect(i-n,s-n,e,e,o),r.fill(t)}function Yn(r,e){const t=r.__sourceGraphics;t&&(r.__sourceSize=e,Zi(t,e,Ki(performance.now())))}function Ki(r){const e=r%_s/_s,t=.5-.5*Math.cos(e*Math.PI*2);return hn(je,Du,t)}function bi(r){const e=typeof r.energy=="number"?r.energy:0,t=typeof r.energyCapacity=="number"?r.energyCapacity:3e3;return{energy:e,capacity:t}}const To=x*.3,Mo=Math.max(1,x*.12),wi=To-Mo/2,Gu=x*.42,zu=1500;function hn(r,e,t){const n=r>>16&255,i=r>>8&255,s=r&255,o=e>>16&255,c=e>>8&255,l=e&255,a=Math.round(n+(o-n)*t),h=Math.round(i+(c-i)*t),u=Math.round(s+(l-s)*t);return a<<16|h<<8|u}function Eo(r,e){r.clear(),r.circle(x/2,x/2,To),r.stroke({width:Mo,color:e,alpha:.95})}function xi(r,e,t,n,i,s,o){if(r.clear(),s<=0||i<=0)return;const c=Math.min(1,i/s);if(c>=1){r.circle(e,t,n),r.fill({color:o,alpha:.55});return}const l=-Math.PI/2,a=l+c*Math.PI*2;r.moveTo(e,t),r.lineTo(e+n*Math.cos(l),t+n*Math.sin(l)),r.arc(e,t,n,l,a),r.closePath(),r.fill({color:o,alpha:.55})}function gt(r,e,t){return t.flatMap(([n,i])=>[r+n*x,e+i*x])}function Vt(r,e,t,n){t-e<.001||(r.moveTo(yt*Math.cos(e),yt*Math.sin(e)),r.arc(0,0,yt,e,t),r.lineTo(Qe*Math.cos(t),Qe*Math.sin(t)),r.arc(0,0,Qe,t,e,!0),r.closePath(),r.fill(n))}function _i(r){let e=0;if(typeof r.storeCapacity=="number")e=r.storeCapacity;else{const n=r.body;n&&(e=n.filter(i=>i.type==="carry").length*50)}if(e===0)return{used:0,capacity:0};let t=0;if(r.store&&typeof r.store=="object"){const n=r.store;for(const i in n){const s=n[i];typeof s=="number"&&(t+=s)}}else typeof r.energy=="number"&&(t=r.energy);return{used:t,capacity:e}}function $i(r,e){return e<=0||r<=0?0:Qe*.8*Math.min(1,r/e)}function Xn(r,e){const t=r.__creepFillGraphics;t&&(t.clear(),e>0&&(t.circle(0,0,e),t.fill(Xr)))}function Bu(r){return lu[r]??ou}function lr(r){let e=50;typeof r.energyCapacity=="number"?e=r.energyCapacity:typeof r.storeCapacity=="number"?e=r.storeCapacity:r.storeCapacityResource&&typeof r.storeCapacityResource=="object"&&(e=r.storeCapacityResource.energy??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 Ro(r){return r>=200?1.15:r>=100?.85:.7}function Si(r,e){return e<=0||r<=0?0:ko*Ro(e)*Math.min(1,r/e)}function Fu(r,e,t,n){const i=x/2,s=x/2,o=Ro(t),c=new re;c.circle(i,s,ws*o),c.fill(Ce),c.circle(i,s,ws*o),c.stroke({width:Ou*o,color:n}),c.circle(i,s,ko*o),c.fill(un),r.addChild(c);const l=new re,a=Si(e,t);a>0&&(l.circle(i,s,a),l.fill(je)),r.addChild(l),r.__fillGraphics=l}function jn(r,e){const t=x/2,n=x/2,i=r.__fillGraphics;i&&(i.clear(),e>0&&(i.circle(t,n,e),i.fill(je)))}const ki=-x*.4,Ci=-x*.3,Ti=x*.8,yn=x*.6;function Mi(r,e){return e<=0||r<=0?0:yn*Math.min(1,r/e)}function fn(r,e){const t=r.__towerFillGraphics;if(t&&(t.clear(),e>0)){const n=Math.max(.5,x*.02);t.rect(ki+n,Ci+yn-e+n,Ti-n*2,e-n*2),t.fill(je)}}const Hu=0,Uu=-x*.1,Wu=x*1,Po=x*1.2;function Ei(r){const e=typeof r.storeCapacity=="number"?r.storeCapacity:0;if(e===0)return{used:0,capacity:0};let t=0;if(r.store&&typeof r.store=="object"){const n=r.store;for(const i in n){const s=n[i];typeof s=="number"&&(t+=s)}}return{used:t,capacity:e}}function vn(r,e){return e<=0||r<=0?0:Po*Math.min(1,r/e)}function bn(r,e){const t=r.__storageFillG;t&&(t.clear(),e>0&&(t.rect(Hu,Uu+Po-e,Wu,e),t.fill(je)))}const Ri=x*.65,Pi=Ri,nt=x*.42;function Oi(r,e,t,n,i,s,o,c){r.clear();const l=8,a=.1,h=2*Math.PI/l-a;for(let u=0;u<l;u++){const d=-Math.PI/2+u*(2*Math.PI/l)+a/2,f=d+h,p=e+i*Math.cos(d),m=t+i*Math.sin(d);if(u<s)r.moveTo(p,m),r.arc(e,t,n,d,f),r.arc(e,t,i,f,d,!0),r.closePath(),r.fill({color:14540253,alpha:.9});else if(u===s&&c>0){if(r.moveTo(p,m),r.arc(e,t,n,d,f),r.arc(e,t,i,f,d,!0),r.closePath(),r.fill({color:1973790,alpha:.85}),o>0){const S=Math.min(1,o/c),O=d+h*S;r.moveTo(p,m),r.arc(e,t,n,d,O),r.arc(e,t,i,O,d,!0),r.closePath(),r.fill({color:14540253,alpha:.9})}}else r.moveTo(p,m),r.arc(e,t,n,d,f),r.arc(e,t,i,f,d,!0),r.closePath(),r.fill({color:1973790,alpha:.6})}}function Li(r,e,t,n){const i=r.__ctrlSegSprites;if(i)for(let s=0;s<i.length;s++)s<e?i[s].alpha=1:s===e&&n>0?i[s].alpha=Math.max(.15,t/n):i[s].alpha=.15}function wn(r,e){const t=r.user;return typeof t!="string"||!e?!1:t!==e}function qt(r,e=!0,t,n,i,s,o,c){var z,P,k,C,w,I,y;const l=new Ae,a=new re,h=Bu(r.type),u=x/2,d=x/2,f=typeof r.user=="string"?r.user:void 0,m=f!==void 0&&t!==void 0&&f!==t?Mt:yu;switch(r.type){case"creep":{const $=2*Math.PI,L=new Ae;L.position.set(u,d),L.rotation=-Math.PI/2;const v=wn(r,t);if(v){const W=new re;W.circle(0,0,yt+.75),W.stroke({width:1.5,color:Mt}),L.addChild(W)}const T=new re;T.circle(0,0,yt),T.fill(yo),L.addChild(T);const E=r.body??[];let M=0,A=0,D=0;const U=[],G={};for(const W of E)W.type==="work"?M++:W.type==="move"?A++:(G[W.type]===void 0&&(U.push(W.type),G[W.type]=0),G[W.type]++,D++);const B=M/wr*$,V=A/wr*$,X=D/wr*$,j=B/2,q=j+X/2,H=Math.PI-V/2,K=Math.PI+V/2,le=$-B/2-X/2,ce=$-B/2,de=new re;B>0&&Vt(de,-B/2,j,Zr.work);let Te=j;for(const W of U){const J=(G[W]??0)/wr*$/2;Vt(de,Te,Te+J,Zr[W]??7829367),Te+=J}Vt(de,q,H,gs),V>0&&Vt(de,H,K,Zr.move),Vt(de,K,le,gs);let te=ce;for(const W of U){const J=(G[W]??0)/wr*$/2;Vt(de,te-J,te,Zr[W]??7829367),te-=J}L.addChild(de);const pe=new re;pe.circle(0,0,Qe),pe.fill(zd),L.addChild(pe);const Ie=typeof r.user=="string"?r.user:void 0,ht=Ie?(z=s==null?void 0:s[Ie])==null?void 0:z.badge:void 0;if(ht&&i){const W=new De;W.anchor.set(.5,.5);const J=Qe*2;W.width=J,W.height=J,W.rotation=Math.PI/2,L.addChild(W),l.__creepBadgeSprite=W,i.getOrCreate(ht).then(ne=>{W.destroyed||(W.texture=ne)}).catch(()=>{})}else if(v){const W=new re;W.circle(0,0,Qe*.82),W.fill({color:Mt,alpha:.9}),L.addChild(W),l.__creepForeignMark=W}const{used:et,capacity:Ve}=_i(r),$t=$i(et,Ve),qe=new re;$t>0&&(qe.circle(0,0,$t),qe.fill(Xr)),L.addChild(qe),l.__creepFillGraphics=qe,l.__creepUsed=et,l.__creepCapacity=Ve;const se=(yt+Qe)/2,ie=(yt-Qe)*.45,ae=new re;ae.moveTo(yt,0),ae.lineTo(se,-ie),ae.lineTo(se,ie),ae.closePath(),ae.fill(mu),L.addChild(ae),l.addChild(L),l.__bodyContainer=L;break}case"extension":{const{energy:$,capacity:L}=lr(r);Fu(l,$,L,m),l.__extEnergy=$,l.__extCapacity=L;break}case"spawn":{a.circle(u,d,x*.65),a.fill(Ce),a.circle(u,d,x*.65),a.stroke({width:x*.1,color:13421772}),a.circle(u,d,x*.4),a.fill(je);break}case"powerSpawn":{a.circle(u,d,x*.65),a.fill(Ce),a.circle(u,d,x*.65),a.stroke({width:x*.1,color:vu}),a.circle(u,d,x*.4),a.fill(je);break}case"source":{const{energy:$,capacity:L}=bi(r),v=vi($,L),T=new re;Zi(T,v,Ki(performance.now())),l.addChild(T),l.__sourceGraphics=T,l.__sourceEnergy=$,l.__sourceCapacity=L,l.__sourceSize=v;break}case"constructionSite":{const $=typeof r.user=="string"?r.user:void 0,L=$!==void 0&&$===t,v=L?Or:fu,T=L?uu:pu,E=L?hu:gu,M=typeof r.progress=="number"?r.progress:0,A=typeof r.progressTotal=="number"?r.progressTotal:1,D=new re;l.addChild(D),l.__csBuildGlow=D;const U=new re;xi(U,u,d,wi,M,A,v),l.addChild(U),l.__csFillGraphics=U;const G=new re;Eo(G,v),l.addChild(G),l.__csRingGraphics=G,l.__csProgress=M,l.__csProgressTotal=A,l.__csUser=$,l.__csColor=v,l.__csColorDark=T,l.__csColorLight=E;break}case"mineral":{const $=typeof r.mineralType=="string"?r.mineralType:"?",L=Lu[$]??Nt,v=Au[$]??16777215,T=new re;T.circle(u,d,Iu),T.fill(L),l.addChild(T);const E=new At({text:$,style:{fontSize:Co,fill:v,fontWeight:"bold"}});E.anchor.set(.5,.5),E.scale.set(Nu),E.position.set(u,d),l.addChild(E);break}case"deposit":{a.rect(2,2,x-4,x-4),a.fill(h);break}case"controller":{const $=typeof r.level=="number"?r.level:0,L=typeof r.progress=="number"?r.progress:0,v=typeof r.progressTotal=="number"?r.progressTotal:0,T=typeof r.user=="string"?r.user:void 0,E=T?(P=s==null?void 0:s[T])==null?void 0:P.badge:void 0,M=o==null?void 0:o.controller;if(M&&c){const D=x*M.tileScale,U=D/600,G=new De;G.anchor.set(.5,.5),G.x=u,G.y=d,G.width=D,G.height=D,l.addChild(G);const B=[];for(let q=0;q<8;q++){const H=new De;H.anchor.set(.5,.5),H.x=u,H.y=d,H.scale.set(U),H.rotation=q*(Math.PI/4),l.addChild(H),B.push(H)}l.__ctrlSegSprites=B,Li(l,$,L,v);const V=()=>c.getOrLoad(o.atlasUrl),X=c.getTexture(o.atlasUrl,M.backgroundFrame);X?G.texture=X:V().then(q=>{G.destroyed||(G.texture=q.textures[M.backgroundFrame]??Oe.EMPTY)}).catch(()=>{});const j=c.getTexture(o.atlasUrl,M.segmentFrame);if(j)for(const q of B)q.texture=j;else V().then(q=>{const H=q.textures[M.segmentFrame]??Oe.EMPTY;for(const K of B)K.destroyed||(K.texture=H)}).catch(()=>{})}else{const D=new re,U=[];for(let B=0;B<8;B++){const V=-Math.PI/2+B*Math.PI/4;U.push(u+Ri*Math.cos(V),d+Ri*Math.sin(V))}D.poly(U),D.fill(2238513),D.poly(U),D.stroke({width:x*.07,color:8027781}),l.addChild(D);const G=new re;Oi(G,u,d,Pi,nt,$,L,v),l.addChild(G),l.__ctrlSegGraphics=G}l.__ctrlLevel=$,l.__ctrlProgress=L,l.__ctrlProgressTotal=v,l.__ctrlDowngradeTime=typeof r.downgradeTime=="number"?r.downgradeTime:void 0,l.__ctrlUserId=T;const A=new re;if(E?(A.circle(u,d,nt),A.fill(Ce)):(A.circle(u,d,nt),A.fill(3028031),A.circle(u,d,nt),A.stroke({width:x*.04,color:8027781}),A.circle(u,d,x*.16),A.fill(10133672)),l.addChild(A),E&&i){const D=new De;D.anchor.set(.5,.5),D.width=nt*2,D.height=nt*2,D.position.set(u,d);const U=new re;U.circle(u,d,nt),U.fill(16777215),l.addChild(D),D.mask=U,l.addChild(U),i.getOrCreate(E).then(G=>{D.destroyed||(D.texture=G)}).catch(()=>{})}break}case"energy":{a.circle(u,d,x*.2),a.fill(je);break}case"road":break;case"wall":{a.circle(u,d,x*.4),a.fill(Ce),a.circle(u,d,x*.4),a.stroke({width:x*.05,color:un});break}case"rampart":break;case"tower":{const{energy:$,capacity:L}=lr(r),v=new re;v.circle(u,d,x*.6),v.fill(Ce),v.circle(u,d,x*.6),v.stroke({width:x*.05,color:m}),l.addChild(v);const T=new Ae;T.position.set(u,d);const E=new re;E.rect(ki,Ci,Ti,yn),E.fill(Ce),T.addChild(E);const M=new re;T.addChild(M),l.__towerFillGraphics=M,l.__towerEnergy=$,l.__towerCapacity=L,fn(l,Mi($,L));const A=new re;A.rect(ki,Ci,Ti,yn),A.stroke({width:1,color:St}),T.addChild(A);const D=new re;D.rect(-x*.2,-x*.9,x*.4,x*.5),D.fill(un),D.rect(-x*.2,-x*.9,x*.4,x*.5),D.stroke({width:x*.07,color:Ce}),T.addChild(D),l.addChild(T),l.__barrelContainer=T;break}case"storage":{const $=o==null?void 0:o.sprites.storage;if($&&c){const{used:A,capacity:D}=Ei(r),U=x*$.tileScale,G=(V,X)=>{V.texture=X,V.width=U,V.height=U};for(const V of $.layers){const X=new De;X.anchor.set(.5,.5),X.x=u,X.y=d,V.tint==="owner"&&(X.tint=m),l.addChild(X);const j=c.getTexture(o.atlasUrl,V.frame);j?G(X,j):c.getOrLoad(o.atlasUrl).then(q=>{X.destroyed||G(X,q.textures[V.frame]??Oe.EMPTY)}).catch(()=>{})}const B=new re;l.addChild(B),l.__storageFillG=B,l.__storageUsed=A,l.__storageCapacity=D,bn(l,vn(A,D));break}const{used:L,capacity:v}=Ei(r),T=gt(u,d,[[-.6,-.7],[0,-.8],[.6,-.7],[.65,0],[.6,.7],[0,.8],[-.6,.7],[-.65,0],[-.6,-.7]]);a.poly(T),a.fill(Ce),a.poly(T),a.stroke({width:x*.05,color:m}),a.rect(u-x*.5,d-x*.6,x*1,x*1.2),a.fill(St),l.addChild(a);const E=new re;l.addChild(E),l.__storageFillG=E,l.__storageUsed=L,l.__storageCapacity=v,bn(l,vn(L,v));const M=new re;M.rect(u-x*.5,d-x*.6,x*1,x*1.2),M.stroke({width:x*.1,color:Ce}),l.addChild(M);break}case"terminal":{const $=gt(u,d,[[0,-.8],[.55,-.55],[.8,0],[.55,.55],[0,.8],[-.55,.55],[-.8,0],[-.55,-.55],[0,-.8]]),L=gt(u,d,[[0,-.65],[.45,-.45],[.65,0],[.45,.45],[0,.65],[-.45,.45],[-.65,0],[-.45,-.45],[0,-.65]]);a.poly($),a.fill(Ce),a.poly($),a.stroke({width:x*.05,color:m}),a.poly(L),a.fill(un),a.rect(u-x*.45,d-x*.45,x*.9,x*.9),a.fill(St),a.rect(u-x*.45,d-x*.45,x*.9,x*.9),a.stroke({width:x*.1,color:Ce});break}case"link":{const $=gt(u,d,[[0,-.5],[.4,0],[0,.5],[-.4,0],[0,-.5]]),L=gt(u,d,[[0,-.3],[.25,0],[0,.3],[-.25,0],[0,-.3]]);a.poly($),a.fill(Ce),a.poly($),a.stroke({width:x*.05,color:m}),a.poly(L),a.fill(St);break}case"lab":{const $=d-x*.025;a.circle(u,$,x*.55),a.fill(Ce),a.circle(u,$,x*.55),a.stroke({width:x*.05,color:m}),a.circle(u,$,x*.4),a.fill(St),a.rect(u-x*.45,d+x*.3,x*.9,x*.25),a.fill(Ce),a.poly(gt(u,d,[[-.45,.3],[-.45,.55],[.45,.55],[.45,.3]])),a.stroke({width:x*.05,color:m});break}case"container":{a.rect(u-x*.225,d-x*.3,x*.45,x*.6),a.fill(je),a.rect(u-x*.225,d-x*.3,x*.45,x*.6),a.stroke({width:x*.1,color:Ce});break}case"observer":{a.circle(u,d,x*.45),a.fill(Ce),a.circle(u,d,x*.45),a.stroke({width:x*.05,color:m}),a.circle(u+x*.225,d,x*.2),a.fill(m);break}case"nuker":{const $=gt(u,d,[[0,-1],[-.47,.2],[-.5,.5],[.5,.5],[.47,.2],[0,-1]]),L=gt(u,d,[[0,-.8],[-.4,.2],[.4,.2],[0,-.8]]);a.poly($),a.fill(Ce),a.poly($),a.stroke({width:x*.05,color:m}),a.poly(L),a.fill(St),a.poly(L),a.stroke({width:x*.01,color:m});break}case"factory":case"extractor":case"invaderCore":{a.circle(u,d,x*.45),a.fill(Ce),a.circle(u,d,x*.45),a.stroke({width:x*.05,color:m}),a.circle(u,d,x*.35),a.fill(St);break}case"flag":{const $=typeof r.color=="number"?r.color:0,L=typeof r.secondaryColor=="number"?r.secondaryColor:0,v=sr[$]??sr[0],T=sr[L]??sr[0],E=o==null?void 0:o.flag;if(E&&c){const M=x*E.tileScale,A=()=>c.getOrLoad(o.atlasUrl),D=(B,V)=>{B.texture=V,B.width=M,B.height=M},U=new De;U.anchor.set(.5,.5),U.x=u,U.y=d,U.tint=v,l.addChild(U);const G=c.getTexture(o.atlasUrl,E.mainFrame);if(G?D(U,G):A().then(B=>{U.destroyed||D(U,B.textures[E.mainFrame]??Oe.EMPTY)}).catch(()=>{}),L!==$){const B=new De;B.anchor.set(.5,.5),B.x=u,B.y=d,B.tint=T,l.addChild(B);const V=c.getTexture(o.atlasUrl,E.secondFrame);V?D(B,V):A().then(X=>{B.destroyed||D(B,X.textures[E.secondFrame]??Oe.EMPTY)}).catch(()=>{})}}else{const A=x*.08*1.5,D=x*.7*1.5,U=u-A/2,G=d-x*.25*1.5;a.rect(U,G,A,D),a.fill(8947848);const B=U+A,V=G,X=B+x*.45*1.5,j=V,q=V+x*.44*1.5,H=(j+q)/2,K=H;a.moveTo(B,j),a.lineTo(X,H),a.lineTo(B,K),a.closePath(),a.fill(v),a.moveTo(B,K),a.lineTo(X,H),a.lineTo(B,q),a.closePath(),a.fill(T),l.addChild(a)}if(l.__flagColor=$,l.__flagSecondaryColor=L,typeof r.name=="string"){const M=new At({text:r.name,style:{fontSize:Dr,fill:16777215}});M.scale.set(gi),M.anchor.set(.5,0),M.x=u,M.y=d+x*.55,M.visible=e,l.__nameLabel=M,l.addChild(M)}break}case"ruin":{const $=typeof r.user=="string"?r.user:void 0,v=$!==void 0&&$===t?Or:Mt,T=x*.42,E=6,M=Math.PI/5,A=new re;for(let G=0;G<E;G++){const B=G*Math.PI*2/E,V=B-M/2,X=B+M/2,j=u+T*Math.cos(V),q=d+T*Math.sin(V);A.moveTo(j,q),A.arc(u,d,T,V,X),A.stroke({width:x*.09,color:v,alpha:.75,cap:"round"})}l.addChild(A);const D=x*.18,U=new re;U.moveTo(u-D,d-D),U.lineTo(u+D,d+D),U.moveTo(u+D,d-D),U.lineTo(u-D,d+D),U.stroke({width:x*.11,color:v,cap:"round"}),l.addChild(U);break}case"tombstone":{const $=typeof r.user=="string"?r.user:void 0,v=$!==void 0&&$===t?Or:Mt,T=o==null?void 0:o.tombstone;if(T&&c){const E=x*T.tileScale,M=()=>c.getOrLoad(o.atlasUrl),A=new De;A.anchor.set(.5,.5),A.x=u,A.y=d,A.width=E,A.height=E,l.addChild(A);const D=new De;D.anchor.set(.5,.5),D.x=u,D.y=d,D.width=E,D.height=E,D.tint=v,l.addChild(D);const U=c.getTexture(o.atlasUrl,T.shellFrame);U?A.texture=U:M().then(B=>{A.destroyed||(A.texture=B.textures[T.shellFrame]??Oe.EMPTY)}).catch(()=>{});const G=c.getTexture(o.atlasUrl,T.crossFrame);G?D.texture=G:M().then(B=>{D.destroyed||(D.texture=B.textures[T.crossFrame]??Oe.EMPTY)}).catch(()=>{})}else{const E=x*.62,M=x*.82,A=u-E/2,D=d-M/2,U=E/2,G=new re;G.moveTo(A,D+U),G.arc(u,D+U,U,Math.PI,0,!1),G.lineTo(A+E,D+M),G.lineTo(A,D+M),G.closePath(),G.fill(Ce),G.moveTo(A,D+U),G.arc(u,D+U,U,Math.PI,0,!1),G.lineTo(A+E,D+M),G.lineTo(A,D+M),G.closePath(),G.stroke({width:x*.07,color:v,alpha:.9}),l.addChild(G);const B=x*.18,V=new re;V.moveTo(u-B,d-B*.6),V.lineTo(u+B,d+B*.6),V.moveTo(u+B,d-B*.6),V.lineTo(u-B,d+B*.6),V.stroke({width:x*.09,color:v,cap:"round"}),l.addChild(V)}break}default:{const $=x-2;a.rect(1,1,$,$),a.fill(h)}}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"&&r.type!=="mineral"&&r.type!=="tombstone"&&r.type!=="ruin"&&r.type!=="storage"&&l.addChild(a),r.type==="creep"&&typeof r.name=="string"){const $=wn(r,t);let L;if($){const E=typeof r.user=="string"?r.user:void 0;L=E?((k=s==null?void 0:s[E])==null?void 0:k.username)??E:"Hostile"}else L=r.name;const v=$?Mt:16777215,T=new At({text:L,style:{fontSize:Dr,fill:v}});T.scale.set(gi),T.anchor.set(.5,1),T.x=u,T.y=mi-So,T.visible=e,l.__nameLabel=T,l.addChild(T)}const S=r.type==="creep"?100:r.type==="flag"?200:0,O=r.type==="flag"?((C=o==null?void 0:o.flag)==null?void 0:C.zIndex)??0:r.type==="controller"?((w=o==null?void 0:o.controller)==null?void 0:w.zIndex)??0:r.type==="tombstone"?((I=o==null?void 0:o.tombstone)==null?void 0:I.zIndex)??0:((y=o==null?void 0:o.sprites[r.type])==null?void 0:y.zIndex)??0;return l.zIndex=S+O,l.position.set(r.x*x,r.y*x),l}function kt(r){r.destroy({children:!0})}function Yu(r){const e=r.length>vs?r.slice(0,vs):r,t=new At({text:e,style:{fontSize:Dr,fill:Pu,fontWeight:"600"}});t.scale.set(Tu),t.anchor.set(.5,.5);const n=t.width,i=t.height,s=n+Mu*2,o=i+Eu*2,c=o/2,l=new re;l.roundRect(-s/2,-o/2,s,o,c),l.fill(bs),l.roundRect(-s/2,-o/2,s,o,c),l.stroke({width:.4,color:1118481,alpha:.55}),l.moveTo(-Jr,o/2-.1),l.lineTo(0,o/2+Wn),l.lineTo(Jr,o/2-.1),l.closePath(),l.fill(bs),l.moveTo(-Jr,o/2-.1),l.lineTo(0,o/2+Wn),l.lineTo(Jr,o/2-.1),l.stroke({width:.4,color:1118481,alpha:.55});const a=new Ae;return a.addChild(l),a.addChild(t),a.pivot.set(0,o/2+Wn),a}class Xu{constructor(e,t=!0,n,i,s){_(this,"container");_(this,"objects",new Map);_(this,"rawObjects",new Map);_(this,"roadGraphics");_(this,"rampartGraphics");_(this,"ticker",null);_(this,"tickerCallback",null);_(this,"extAnimations",new Map);_(this,"creepFillAnimations",new Map);_(this,"towerFillAnimations",new Map);_(this,"storageFillAnimations",new Map);_(this,"sourceAnimations",new Map);_(this,"buildGlowAnimations",new Map);_(this,"ctrlFlashAnimations",new Map);_(this,"currentGameTime",0);_(this,"sayBubbles",new Set);_(this,"moveDuration",600);_(this,"EXT_ANIM_DURATION",300);_(this,"instantMode",!1);_(this,"lastWorldScale",1);_(this,"showLabels");_(this,"currentUserId");_(this,"badge");_(this,"badgeCache",Cu);_(this,"users");_(this,"activeTheme",null);_(this,"atlasCache",null);this.showLabels=t,this.currentUserId=n,this.badge=i,this.users=s,this.container=new Ae,this.container.sortableChildren=!0,this.rampartGraphics=new re,this.rampartGraphics.zIndex=-1,this.container.addChild(this.rampartGraphics),this.roadGraphics=new re,this.container.addChild(this.roadGraphics),e&&(this.ticker=e,this.tickerCallback=()=>this.tick(),e.add(this.tickerCallback))}setTheme(e,t){this.activeTheme=e,this.atlasCache=t}tick(){var c;const e=performance.now();for(const l of this.objects.values()){if(l.__targetX===void 0||l.__targetY===void 0)continue;const a=l.__moveDur??0,h=l.__moveStartT??e,u=e-h;if(a<=0||u>=a){l.position.set(l.__targetX,l.__targetY),l.__targetX=void 0,l.__targetY=void 0,l.__moveStartX=void 0,l.__moveStartY=void 0,l.__moveStartT=void 0,l.__moveDur=void 0;continue}const d=u/a,f=l.__moveStartX??l.x,p=l.__moveStartY??l.y;l.x=f+(l.__targetX-f)*d,l.y=p+(l.__targetY-p)*d}const t=((c=this.container.parent)==null?void 0:c.scale.x)??1;if(t!==this.lastWorldScale){this.lastWorldScale=t;for(const l of this.objects.values())this.applyLabelScale(l)}const n=performance.now(),i=n/1e3,s=.5+.5*Math.sin(n*2*Math.PI/zu);for(const l of this.objects.values())l.__barrelContainer&&(l.__barrelContainer.rotation=i*.4),l.__csRingGraphics&&l.__csColorDark!==void 0&&l.__csColorLight!==void 0&&Eo(l.__csRingGraphics,hn(l.__csColorDark,l.__csColorLight,s));for(const[l,a]of this.extAnimations){const h=n-a.startTime,u=Math.min(1,h/this.EXT_ANIM_DURATION),d=u<.5?2*u*u:1-Math.pow(-2*u+2,2)/2;jn(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*d),u>=1&&this.extAnimations.delete(l)}for(const[l,a]of this.creepFillAnimations){const h=n-a.startTime,u=Math.min(1,h/this.EXT_ANIM_DURATION),d=u<.5?2*u*u:1-Math.pow(-2*u+2,2)/2;Xn(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*d),u>=1&&this.creepFillAnimations.delete(l)}for(const[l,a]of this.towerFillAnimations){const h=n-a.startTime,u=Math.min(1,h/this.EXT_ANIM_DURATION),d=u<.5?2*u*u:1-Math.pow(-2*u+2,2)/2;fn(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*d),u>=1&&this.towerFillAnimations.delete(l)}for(const[l,a]of this.storageFillAnimations){const h=n-a.startTime,u=Math.min(1,h/this.EXT_ANIM_DURATION),d=u<.5?2*u*u:1-Math.pow(-2*u+2,2)/2;bn(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*d),u>=1&&this.storageFillAnimations.delete(l)}for(const[l,a]of this.sourceAnimations){const h=n-a.startTime,u=Math.min(1,h/this.EXT_ANIM_DURATION),d=u<.5?2*u*u:1-Math.pow(-2*u+2,2)/2;Yn(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*d),u>=1&&this.sourceAnimations.delete(l)}const o=Ki(n);for(const l of this.objects.values()){const a=l.__sourceGraphics;a&&Zi(a,l.__sourceSize??yi,o)}for(const[l,a]of this.buildGlowAnimations){const h=this.objects.get(l),u=h==null?void 0:h.__csBuildGlow;if(!h||!u){this.buildGlowAnimations.delete(l);continue}const d=(n-a.startTime)/a.duration;let f;d<=0?f=0:d<.5?f=d/.5:d<.7?f=1:d<1?f=1-(d-.7)/.3:f=0,u.clear(),f>0&&(u.circle(x/2,x/2,Gu),u.fill({color:je,alpha:f*.75})),d>=1&&this.buildGlowAnimations.delete(l)}for(const[l,a]of this.ctrlFlashAnimations){const h=this.objects.get(l),u=h==null?void 0:h.__ctrlSegSprites;if(!h||!u){this.ctrlFlashAnimations.delete(l);continue}const d=Math.min(1,(n-a.startTime)/a.duration),f=1-(1-d)*(1-d),p=u[a.segIndex];p&&!p.destroyed&&(p.alpha=1-(1-.15)*f),d>=1&&(p&&!p.destroyed&&(p.alpha=.15),this.ctrlFlashAnimations.delete(l))}for(const l of this.objects.values()){const a=l.__ctrlLevel,h=l.__ctrlSegSprites;if(!a||!h)continue;const u=l.__ctrlDowngradeTime;if(!u){for(let k=0;k<a;k++){const C=h[k];C&&!C.destroyed&&(C.tint=16777215)}continue}const d=$o[a]??2e4,p=1-Math.max(0,u-this.currentGameTime)/d;if(p<=.2){for(let k=0;k<a;k++){const C=h[k];C&&!C.destroyed&&(C.tint=16777215)}continue}const m=(p-.2)/.8,S=.3+m*1.5,O=.5+.5*Math.sin(2*Math.PI*S*n/1e3),z=hn(16768477,16720418,m),P=hn(16777215,z,m*O);for(let k=0;k<a;k++){const C=h[k];C&&!C.destroyed&&(C.tint=P)}}}startExtAnimation(e,t,n,i,s,o){const c=Si(s,o);if(this.instantMode){jn(t,c);return}const l=Si(n,i);l!==c&&this.extAnimations.set(e,{visual:t,fromRadius:l,toRadius:c,startTime:performance.now()})}startCreepFillAnimation(e,t,n,i,s,o){const c=$i(s,o);if(this.instantMode){Xn(t,c);return}const l=$i(n,i);l!==c&&this.creepFillAnimations.set(e,{visual:t,fromRadius:l,toRadius:c,startTime:performance.now()})}startTowerFillAnimation(e,t,n,i,s,o){const c=Mi(s,o);if(this.instantMode){fn(t,c);return}const l=Mi(n,i);l!==c&&this.towerFillAnimations.set(e,{visual:t,fromRadius:l,toRadius:c,startTime:performance.now()})}startStorageFillAnimation(e,t,n,i,s,o){const c=vn(s,o);if(this.instantMode){bn(t,c);return}const l=vn(n,i);l!==c&&this.storageFillAnimations.set(e,{visual:t,fromRadius:l,toRadius:c,startTime:performance.now()})}startSourceAnimation(e,t,n,i,s,o){const c=vi(s,o);if(this.instantMode){Yn(t,c);return}const l=vi(n,i);l!==c&&this.sourceAnimations.set(e,{visual:t,fromRadius:l,toRadius:c,startTime:performance.now()})}update(e,t,n,i){n&&(this.users=n),i!==void 0&&(this.currentGameTime=i);let s=!1;if(t)for(const o in t)if(t[o]===null){const l=this.rawObjects.get(o);l&&l.type==="road"&&(s=!0);const a=this.objects.get(o);a&&(this.container.removeChild(a),kt(a),this.objects.delete(o),this.rawObjects.delete(o),this.extAnimations.delete(o),this.creepFillAnimations.delete(o),this.towerFillAnimations.delete(o),this.storageFillAnimations.delete(o),this.sourceAnimations.delete(o),this.buildGlowAnimations.delete(o),this.ctrlFlashAnimations.delete(o),this.sayBubbles.delete(o))}else{const l=e[o];if(!l)continue;if(l.type==="road"){const h=this.rawObjects.get(o);(!h||h.x!==l.x||h.y!==l.y)&&(s=!0)}this.rawObjects.set(o,l);const a=this.objects.get(o);if(a){const h=l.x*x,u=l.y*x;if(l.type==="creep"){const d=l.x-(a.__tileX??l.x),f=l.y-(a.__tileY??l.y);(d!==0||f!==0)&&(a.__angle=Math.atan2(f,d),a.__bodyContainer&&(a.__bodyContainer.rotation=a.__angle)),a.__tileX=l.x,a.__tileY=l.y,this.instantMode?(a.position.set(h,u),a.__targetX=void 0,a.__targetY=void 0,a.__moveStartX=void 0,a.__moveStartY=void 0,a.__moveStartT=void 0,a.__moveDur=void 0):(a.x!==h||a.y!==u)&&(a.__targetX=h,a.__targetY=u,a.__moveStartX=a.x,a.__moveStartY=a.y,a.__moveStartT=performance.now(),a.__moveDur=this.moveDuration);const{used:p,capacity:m}=_i(l);(a.__creepUsed!==p||a.__creepCapacity!==m)&&(this.startCreepFillAnimation(o,a,a.__creepUsed??0,a.__creepCapacity??m,p,m),a.__creepUsed=p,a.__creepCapacity=m)}else if(l.type==="flag"){const d=typeof l.color=="number"?l.color:0,f=typeof l.secondaryColor=="number"?l.secondaryColor:0;if(a.__flagColor!==d||a.__flagSecondaryColor!==f){this.container.removeChild(a),kt(a),this.objects.delete(o);const m=qt(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users,this.activeTheme,this.atlasCache);m.__tileX=l.x,m.__tileY=l.y,this.applyLabelScale(m),this.objects.set(o,m),this.container.addChild(m)}else a.position.set(h,u)}else a.position.set(h,u);if(l.type==="extension"){const{energy:d,capacity:f}=lr(l),p=a;(p.__extEnergy!==d||p.__extCapacity!==f)&&(this.startExtAnimation(o,a,p.__extEnergy??0,p.__extCapacity??f,d,f),p.__extEnergy=d,p.__extCapacity=f)}if(l.type==="tower"){const{energy:d,capacity:f}=lr(l);(a.__towerEnergy!==d||a.__towerCapacity!==f)&&(this.startTowerFillAnimation(o,a,a.__towerEnergy??0,a.__towerCapacity??f,d,f),a.__towerEnergy=d,a.__towerCapacity=f)}if(l.type==="storage"){const{used:d,capacity:f}=Ei(l);(a.__storageUsed!==d||a.__storageCapacity!==f)&&(this.startStorageFillAnimation(o,a,a.__storageUsed??0,a.__storageCapacity??f,d,f),a.__storageUsed=d,a.__storageCapacity=f)}if(l.type==="controller"){const d=typeof l.level=="number"?l.level:0,f=typeof l.progress=="number"?l.progress:0,p=typeof l.progressTotal=="number"?l.progressTotal:0,m=typeof l.user=="string"?l.user:void 0;if(a.__ctrlUserId!==m){this.container.removeChild(a),kt(a),this.objects.delete(o);const O=qt(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users,this.activeTheme,this.atlasCache);O.__tileX=l.x,O.__tileY=l.y,this.applyLabelScale(O),this.objects.set(o,O),this.container.addChild(O);continue}(a.__ctrlLevel!==d||a.__ctrlProgress!==f||a.__ctrlProgressTotal!==p)&&(a.__ctrlSegSprites?(!this.instantMode&&d<8&&f>(a.__ctrlProgress??0)&&this.ctrlFlashAnimations.set(o,{segIndex:d,startTime:performance.now(),duration:400}),Li(a,d,f,p)):a.__ctrlSegGraphics&&Oi(a.__ctrlSegGraphics,x/2,x/2,Pi,nt,d,f,p),a.__ctrlLevel=d,a.__ctrlProgress=f,a.__ctrlProgressTotal=p);const S=typeof l.downgradeTime=="number"?l.downgradeTime:void 0;a.__ctrlDowngradeTime!==S&&(a.__ctrlDowngradeTime=S)}if(l.type==="source"){const{energy:d,capacity:f}=bi(l);(a.__sourceEnergy!==d||a.__sourceCapacity!==f)&&(this.startSourceAnimation(o,a,a.__sourceEnergy??0,a.__sourceCapacity??f,d,f),a.__sourceEnergy=d,a.__sourceCapacity=f)}if(l.type==="constructionSite"){const d=typeof l.progress=="number"?l.progress:0,f=typeof l.progressTotal=="number"?l.progressTotal:1;(a.__csProgress!==d||a.__csProgressTotal!==f)&&(a.__csFillGraphics&&xi(a.__csFillGraphics,x/2,x/2,wi,d,f,a.__csColor??Or),a.__csProgress=d,a.__csProgressTotal=f)}}else{const h=qt(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users,this.activeTheme,this.atlasCache);h.__tileX=l.x,h.__tileY=l.y,this.applyLabelScale(h),this.objects.set(o,h),this.container.addChild(h)}}else{const o=new Set;for(const c in e){const l=e[c];if(!l)continue;o.add(c),this.rawObjects.set(c,l);const a=this.objects.get(c);if(a){const h=l.x*x,u=l.y*x;if(l.type==="creep"){const d=l.x-(a.__tileX??l.x),f=l.y-(a.__tileY??l.y);(d!==0||f!==0)&&(a.__angle=Math.atan2(f,d),a.__bodyContainer&&(a.__bodyContainer.rotation=a.__angle)),a.__tileX=l.x,a.__tileY=l.y,this.instantMode?(a.position.set(h,u),a.__targetX=void 0,a.__targetY=void 0,a.__moveStartX=void 0,a.__moveStartY=void 0,a.__moveStartT=void 0,a.__moveDur=void 0):(a.x!==h||a.y!==u)&&(a.__targetX=h,a.__targetY=u,a.__moveStartX=a.x,a.__moveStartY=a.y,a.__moveStartT=performance.now(),a.__moveDur=this.moveDuration);const{used:p,capacity:m}=_i(l);(a.__creepUsed!==p||a.__creepCapacity!==m)&&(this.startCreepFillAnimation(c,a,a.__creepUsed??0,a.__creepCapacity??m,p,m),a.__creepUsed=p,a.__creepCapacity=m)}else if(l.type==="flag"){const d=typeof l.color=="number"?l.color:0,f=typeof l.secondaryColor=="number"?l.secondaryColor:0;if(a.__flagColor!==d||a.__flagSecondaryColor!==f){this.container.removeChild(a),kt(a),this.objects.delete(c);const m=qt(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users,this.activeTheme,this.atlasCache);m.__tileX=l.x,m.__tileY=l.y,this.applyLabelScale(m),this.objects.set(c,m),this.container.addChild(m)}else a.position.set(h,u)}else a.position.set(h,u);if(l.type==="extension"){const{energy:d,capacity:f}=lr(l),p=a;(p.__extEnergy!==d||p.__extCapacity!==f)&&(this.startExtAnimation(c,a,p.__extEnergy??0,p.__extCapacity??f,d,f),p.__extEnergy=d,p.__extCapacity=f)}if(l.type==="tower"){const{energy:d,capacity:f}=lr(l);(a.__towerEnergy!==d||a.__towerCapacity!==f)&&(this.startTowerFillAnimation(c,a,a.__towerEnergy??0,a.__towerCapacity??f,d,f),a.__towerEnergy=d,a.__towerCapacity=f)}if(l.type==="controller"){const d=typeof l.level=="number"?l.level:0,f=typeof l.progress=="number"?l.progress:0,p=typeof l.progressTotal=="number"?l.progressTotal:0,m=typeof l.user=="string"?l.user:void 0;if(a.__ctrlUserId!==m){this.container.removeChild(a),kt(a),this.objects.delete(c);const O=qt(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users,this.activeTheme,this.atlasCache);O.__tileX=l.x,O.__tileY=l.y,this.applyLabelScale(O),this.objects.set(c,O),this.container.addChild(O);continue}(a.__ctrlLevel!==d||a.__ctrlProgress!==f||a.__ctrlProgressTotal!==p)&&(a.__ctrlSegSprites?(!this.instantMode&&d>(a.__ctrlLevel??0)&&d>0&&this.ctrlFlashAnimations.set(c,{segIndex:d-1,startTime:performance.now(),duration:500}),Li(a,d,f,p)):a.__ctrlSegGraphics&&Oi(a.__ctrlSegGraphics,x/2,x/2,Pi,nt,d,f,p),a.__ctrlLevel=d,a.__ctrlProgress=f,a.__ctrlProgressTotal=p);const S=typeof l.downgradeTime=="number"?l.downgradeTime:void 0;a.__ctrlDowngradeTime!==S&&(a.__ctrlDowngradeTime=S)}if(l.type==="source"){const{energy:d,capacity:f}=bi(l);(a.__sourceEnergy!==d||a.__sourceCapacity!==f)&&(this.startSourceAnimation(c,a,a.__sourceEnergy??0,a.__sourceCapacity??f,d,f),a.__sourceEnergy=d,a.__sourceCapacity=f)}if(l.type==="constructionSite"){const d=typeof l.progress=="number"?l.progress:0,f=typeof l.progressTotal=="number"?l.progressTotal:1;(a.__csProgress!==d||a.__csProgressTotal!==f)&&(a.__csFillGraphics&&xi(a.__csFillGraphics,x/2,x/2,wi,d,f,a.__csColor??Or),a.__csProgress=d,a.__csProgressTotal=f)}}else{const h=qt(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users,this.activeTheme,this.atlasCache);h.__tileX=l.x,h.__tileY=l.y,this.applyLabelScale(h),this.objects.set(c,h),this.container.addChild(h)}}for(const[c,l]of this.objects)o.has(c)||(this.container.removeChild(l),kt(l),this.objects.delete(c),this.rawObjects.delete(c),this.extAnimations.delete(c),this.creepFillAnimations.delete(c),this.towerFillAnimations.delete(c),this.sourceAnimations.delete(c),this.buildGlowAnimations.delete(c),this.ctrlFlashAnimations.delete(c),this.sayBubbles.delete(c));s=!0}this.redrawRamparts(),s&&this.redrawRoads(),this.refreshForeignCreepLabels(),this.refreshForeignCreepBadges()}redrawRoads(){this.roadGraphics.clear();const e=wo,t=Array.from({length:50},()=>new Array(50).fill(!1)),n=[];for(const l of this.rawObjects.values())l.type==="road"&&(n.push(l),l.x>=0&&l.x<50&&l.y>=0&&l.y<50&&(t[l.x][l.y]=!0));if(n.length===0)return;const i=x/2,s=x/2,o=x*.125;for(const l of n)this.roadGraphics.circle(l.x*x+i,l.y*x+s,o);this.roadGraphics.fill(e);const c=[[1,0],[1,1],[0,1],[-1,1]];for(const l of n){const a=l.x*x+i,h=l.y*x+s;for(const[u,d]of c){const f=l.x+u,p=l.y+d;if(f>=0&&f<50&&p>=0&&p<50&&t[f][p]){const m=f*x+i,S=p*x+s;this.roadGraphics.moveTo(a,h),this.roadGraphics.lineTo(m,S)}}}this.roadGraphics.stroke({width:o*2,color:e})}redrawRamparts(){this.rampartGraphics.clear();const e=x,t=e/2,n=Array.from({length:50},()=>new Array(50).fill(void 0));for(const s of this.rawObjects.values())s.type==="rampart"&&s.x>=0&&s.x<50&&s.y>=0&&s.y<50&&(n[s.x][s.y]=typeof s.user=="string"?s.user:void 0);const i=s=>!s||!this.currentUserId?{color:ms,alpha:.7}:s===this.currentUserId?{color:ms,alpha:.7}:{color:7807522,alpha:.5};for(let s=0;s<50;s++)for(let o=0;o<50;o++){const c=n[o][s],l=c!==void 0,a=s>0&&n[o][s-1]!==void 0,h=s<49&&n[o][s+1]!==void 0,u=o>0&&n[o-1][s]!==void 0,d=o<49&&n[o+1][s]!==void 0,f=o*e+t,p=s*e+t;if(l){const m=i(c);!a&&!u&&s>0&&o>0?(this.rampartGraphics.moveTo(f,s*e),this.rampartGraphics.arc(f,p,t,-Math.PI/2,Math.PI,!0),this.rampartGraphics.lineTo(f,p),this.rampartGraphics.fill(m)):(this.rampartGraphics.rect(o*e,s*e,t,t),this.rampartGraphics.fill(m))}else if(a&&u&&n[o-1][s-1]!==void 0){const m=i(n[o-1][s-1]);this.rampartGraphics.moveTo(f,s*e),this.rampartGraphics.lineTo(o*e,s*e),this.rampartGraphics.lineTo(o*e,p),this.rampartGraphics.arc(f,p,t,Math.PI,-Math.PI/2,!1),this.rampartGraphics.fill(m)}if(l){const m=i(c);!a&&!d&&s>0&&o<49?(this.rampartGraphics.moveTo(f,s*e),this.rampartGraphics.arc(f,p,t,-Math.PI/2,0,!1),this.rampartGraphics.lineTo(f,p),this.rampartGraphics.fill(m)):(this.rampartGraphics.rect(f,s*e,t,t),this.rampartGraphics.fill(m))}else if(a&&d&&n[o+1][s-1]!==void 0){const m=i(n[o+1][s-1]);this.rampartGraphics.moveTo(f,s*e),this.rampartGraphics.lineTo(o*e+e,s*e),this.rampartGraphics.lineTo(o*e+e,p),this.rampartGraphics.arc(f,p,t,0,-Math.PI/2,!0),this.rampartGraphics.fill(m)}if(l){const m=i(c);!h&&!u&&s<49&&o>0?(this.rampartGraphics.moveTo(o*e,p),this.rampartGraphics.arc(f,p,t,Math.PI,Math.PI/2,!0),this.rampartGraphics.lineTo(f,p),this.rampartGraphics.fill(m)):(this.rampartGraphics.rect(o*e,p,t,t),this.rampartGraphics.fill(m))}else if(h&&u&&n[o-1][s+1]!==void 0){const m=i(n[o-1][s+1]);this.rampartGraphics.moveTo(o*e,p),this.rampartGraphics.lineTo(o*e,s*e+e),this.rampartGraphics.lineTo(f,s*e+e),this.rampartGraphics.arc(f,p,t,Math.PI/2,Math.PI,!1),this.rampartGraphics.fill(m)}if(l){const m=i(c);!h&&!d&&s<49&&o<49?(this.rampartGraphics.moveTo(f,s*e+e),this.rampartGraphics.arc(f,p,t,Math.PI/2,0,!0),this.rampartGraphics.lineTo(f,p),this.rampartGraphics.fill(m)):(this.rampartGraphics.rect(f,p,t,t),this.rampartGraphics.fill(m))}else if(h&&d&&n[o+1][s+1]!==void 0){const m=i(n[o+1][s+1]);this.rampartGraphics.moveTo(f,s*e+e),this.rampartGraphics.lineTo(o*e+e,s*e+e),this.rampartGraphics.lineTo(o*e+e,p),this.rampartGraphics.arc(f,p,t,0,Math.PI/2,!1),this.rampartGraphics.fill(m)}}}getObjectsAtTile(e,t){const n=[];for(const[i,s]of this.objects){const o=this.rawObjects.get(i);o&&o.x===e&&o.y===t&&n.push({id:i,obj:o,visual:s})}return n}applyLabelScale(e){const t=this.lastWorldScale||1;e.__nameLabel&&(e.__nameLabel.scale.set(gi/t),e.__nameLabel.anchor.y===0?e.__nameLabel.y=x/2+x*.55:e.__nameLabel.y=mi-So/t),e.__sayBubble&&!e.__sayBubble.destroyed&&(e.__sayBubble.scale.set(1/t),e.__sayBubble.position.set(x/2,mi-Ru/t))}refreshForeignCreepLabels(){var e,t;if(this.currentUserId)for(const[n,i]of this.objects){const s=this.rawObjects.get(n);if(!s||s.type!=="creep"||!i.__nameLabel||!wn(s,this.currentUserId))continue;const o=typeof s.user=="string"?s.user:void 0,c=o?((t=(e=this.users)==null?void 0:e[o])==null?void 0:t.username)??o:"Hostile";i.__nameLabel.text!==c&&(i.__nameLabel.text=c)}}refreshForeignCreepBadges(){var e,t;if(this.currentUserId)for(const[n,i]of this.objects){const s=this.rawObjects.get(n);if(!s||s.type!=="creep"||!wn(s,this.currentUserId)||i.__creepBadgeSprite)continue;const o=typeof s.user=="string"?s.user:void 0,c=o?(t=(e=this.users)==null?void 0:e[o])==null?void 0:t.badge:void 0;if(!c)continue;const l=i.__bodyContainer;if(!l)continue;i.__creepForeignMark&&!i.__creepForeignMark.destroyed&&(l.removeChild(i.__creepForeignMark),i.__creepForeignMark.destroy(),i.__creepForeignMark=void 0);const a=new De;a.anchor.set(.5,.5);const h=Qe*2;a.width=h,a.height=h,a.rotation=Math.PI/2,l.addChild(a),i.__creepBadgeSprite=a,this.badgeCache.getOrCreate(c).then(u=>{a.destroyed||(a.texture=u)}).catch(()=>{a.destroyed||(l.removeChild(a),a.destroy()),i.__creepBadgeSprite=void 0})}}triggerBuildAt(e,t,n){if(!this.instantMode)for(const[i,s]of this.objects){const o=this.rawObjects.get(i);if(!(!o||o.type!=="constructionSite")&&!(o.x!==e||o.y!==t)&&s.__csBuildGlow){this.buildGlowAnimations.set(i,{startTime:performance.now(),duration:n});return}}}triggerSay(e,t){const n=this.objects.get(e);if(!n||n.__sayMessage===t&&n.__sayBubble&&!n.__sayBubble.destroyed)return;n.__sayBubble&&!n.__sayBubble.destroyed&&(n.removeChild(n.__sayBubble),n.__sayBubble.destroy({children:!0}));const i=Yu(t);n.addChild(i),n.__sayBubble=i,n.__sayMessage=t,this.applyLabelScale(n),this.sayBubbles.add(e)}setMoveDuration(e){this.moveDuration=Math.max(0,e)}pruneSayBubblesExcept(e){if(this.sayBubbles.size!==0)for(const t of this.sayBubbles){if(e.has(t))continue;const n=this.objects.get(t);n!=null&&n.__sayBubble&&!n.__sayBubble.destroyed&&(n.removeChild(n.__sayBubble),n.__sayBubble.destroy({children:!0})),n&&(n.__sayBubble=void 0,n.__sayMessage=void 0),this.sayBubbles.delete(t)}}setInstantMode(e){if(this.instantMode=e,!!e){for(const t of this.objects.values())t.__targetX!==void 0&&(t.position.set(t.__targetX,t.__targetY),t.__targetX=void 0,t.__targetY=void 0,t.__moveStartX=void 0,t.__moveStartY=void 0,t.__moveStartT=void 0,t.__moveDur=void 0),t.__sayBubble&&!t.__sayBubble.destroyed&&(t.removeChild(t.__sayBubble),t.__sayBubble.destroy({children:!0}),t.__sayBubble=void 0,t.__sayMessage=void 0);this.sayBubbles.clear();for(const t of this.extAnimations.values())jn(t.visual,t.toRadius);this.extAnimations.clear();for(const t of this.creepFillAnimations.values())Xn(t.visual,t.toRadius);this.creepFillAnimations.clear();for(const t of this.towerFillAnimations.values())fn(t.visual,t.toRadius);this.towerFillAnimations.clear();for(const t of this.sourceAnimations.values())Yn(t.visual,t.toRadius);this.sourceAnimations.clear(),this.buildGlowAnimations.clear(),this.ctrlFlashAnimations.clear()}}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())kt(e);this.objects.clear(),this.rawObjects.clear(),this.extAnimations.clear(),this.creepFillAnimations.clear(),this.towerFillAnimations.clear(),this.sourceAnimations.clear(),this.buildGlowAnimations.clear(),this.ctrlFlashAnimations.clear(),this.sayBubbles.clear(),this.roadGraphics.clear(),this.rampartGraphics.clear(),this.container.removeChildren(),this.container.addChild(this.rampartGraphics),this.container.addChild(this.roadGraphics)}destroy(){this.clear(),this.ticker&&this.tickerCallback&&this.ticker.remove(this.tickerCallback),this.ticker=null,this.tickerCallback=null}}const Vn=2;function Zt(r,e){return{cx:r*x+x/2,cy:e*x+x/2}}class ju{constructor(e){_(this,"container");_(this,"graphics");_(this,"animations",[]);_(this,"ticker",null);_(this,"tickerCallback",null);this.container=new Ae,this.graphics=new re,this.container.addChild(this.graphics),e&&(this.ticker=e,this.tickerCallback=()=>this.animate(),e.add(this.tickerCallback))}addHarvest(e,t,n,i,s){const o=Zt(e,t),c=Zt(n,i);this.animations.push({fromX:o.cx,fromY:o.cy,toX:c.cx,toY:c.cy,startTime:performance.now(),duration:s,color:au,width:Vn})}addUpgradeController(e,t,n,i,s){const o=Zt(e,t),c=Zt(n,i);this.animations.push({fromX:o.cx,fromY:o.cy,toX:c.cx,toY:c.cy,startTime:performance.now(),duration:s,color:cu,width:Vn})}addBuild(e,t,n,i,s){const o=Zt(e,t),c=Zt(n,i);this.animations.push({fromX:o.cx,fromY:o.cy,toX:c.cx,toY:c.cy,startTime:performance.now(),duration:s,color:du,width:Vn})}animate(){this.graphics.clear();const e=performance.now();let t=!1;for(let n=this.animations.length-1;n>=0;n--){const i=this.animations[n],s=e-i.startTime,o=Math.min(1,s/i.duration);let c,l,a,h;const u=.5,d=.2;if(o<u){const f=o/u;c=i.fromX,l=i.fromY,a=i.fromX+(i.toX-i.fromX)*f,h=i.fromY+(i.toY-i.fromY)*f}else if(o<u+d)c=i.fromX,l=i.fromY,a=i.toX,h=i.toY;else{const f=(o-u-d)/(1-u-d);c=i.fromX+(i.toX-i.fromX)*f,l=i.fromY+(i.toY-i.fromY)*f,a=i.toX,h=i.toY}this.graphics.moveTo(c,l),this.graphics.lineTo(a,h),this.graphics.stroke({width:i.width,color:i.color}),t=!0,o>=1&&this.animations.splice(n,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 Pe=r=>(r+.5)*x,xr=4,Qr={dashed:[.4*x,.4*x],dotted:[.1*x,.3*x]};function en(r,e,t,n){let i=!0,s=t;for(let o=0;o<e.length-1;o++){const[c,l]=e[o],[a,h]=e[o+1],u=a-c,d=h-l,f=Math.sqrt(u*u+d*d);if(f<.001)continue;const p=u/f,m=d/f;let S=0;for(;S<f;){const O=Math.min(s,f-S);if(i){const z=c+p*S,P=l+m*S;r.moveTo(z,P),r.lineTo(z+p*O,P+m*O)}S+=O,s-=O,s<.001&&(i=!i,s=i?t:n)}}}function Vu(r,e,t){const n=Math.max(32,Math.ceil(2*Math.PI*t/2)),i=[];for(let s=0;s<=n;s++){const o=s/n*2*Math.PI;i.push([r+Math.cos(o)*t,e+Math.sin(o)*t])}return i}function qu(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/x:t}function Zu(r){if(typeof r!="string")return"Arial";const e=r.match(/^[0-9.]+(px)?\s+(.+)$/);return e?e[2]:"Arial"}class Ku{constructor(){_(this,"container");_(this,"g");this.container=new Ae,this.container.label="visuals",this.g=new re,this.container.addChild(this.g)}update(e){const t=this.container.removeChildren();for(const i of t)i!==this.g&&i.destroy();if(this.g.clear(),this.container.addChild(this.g),!e)return;const n=this.g;for(const i of e.split(`
9
+ `)){if(!i.trim())continue;let s;try{s=JSON.parse(i)}catch{continue}const o=s.s??{},c=o.opacity??1;switch(s.t){case"l":this.drawLine(n,s,o,c);break;case"c":this.drawCircle(n,s,o,c);break;case"r":this.drawRect(n,s,o,c);break;case"p":this.drawPoly(n,s,o,c);break;case"t":this.drawText(s,o,c);break}}}drawLine(e,t,n,i){const s=Pe(t.x1),o=Pe(t.y1),c=Pe(t.x2),l=Pe(t.y2),a=n.color??"#ffffff",h=(n.width??.1)*x;if(n.lineStyle&&n.lineStyle!=="solid"){const[u,d]=Qr[n.lineStyle];en(e,[[s,o],[c,l]],u,d)}else e.moveTo(s,o),e.lineTo(c,l);e.stroke({color:a,width:h,alpha:i})}drawCircle(e,t,n,i){const s=Pe(t.x),o=Pe(t.y),c=(n.radius??.5)*x,l=!!(n.fill&&n.fill!=="transparent"),a=!!(n.stroke&&n.strokeWidth),h=n.lineStyle&&n.lineStyle!=="solid";if(l&&(e.circle(s,o,c),e.fill({color:n.fill,alpha:i})),a){const u=n.strokeWidth*x;if(h){const[d,f]=Qr[n.lineStyle];en(e,Vu(s,o,c),d,f)}else e.circle(s,o,c);e.stroke({color:n.stroke,width:u,alpha:i})}}drawRect(e,t,n,i){const s=Pe(t.x),o=Pe(t.y),c=t.w*x,l=t.h*x,a=!!(n.fill&&n.fill!=="transparent"),h=!!(n.stroke&&n.strokeWidth),u=n.lineStyle&&n.lineStyle!=="solid";if(a&&(e.rect(s,o,c,l),e.fill({color:n.fill,alpha:i})),h){const d=n.strokeWidth*x;if(u){const[f,p]=Qr[n.lineStyle],m=[[s,o],[s+c,o],[s+c,o+l],[s,o+l],[s,o]];en(e,m,f,p)}else e.rect(s,o,c,l);e.stroke({color:n.stroke,width:d,alpha:i})}}drawPoly(e,t,n,i){if(!t.points||t.points.length===0)return;const s=!!(n.fill&&n.fill!=="transparent"),o=!!(n.stroke&&n.strokeWidth);if(!s&&!o)return;const c=n.lineStyle&&n.lineStyle!=="solid",l=new Array(t.points.length*2);let a;o&&c&&(a=new Array(t.points.length));for(let h=0;h<t.points.length;h++){const[u,d]=t.points[h],f=Pe(u),p=Pe(d);l[h*2]=f,l[h*2+1]=p,a&&(a[h]=[f,p])}if(s&&(e.poly(l,!0),e.fill({color:n.fill,alpha:i})),o){const h=n.strokeWidth*x;if(c&&a){const[u,d]=Qr[n.lineStyle],f=a[0],p=a[a.length-1],m=f[0]===p[0]&&f[1]===p[1];en(e,m?a:[...a,f],u,d)}else e.poly(l,!0);e.stroke({color:n.stroke,width:h,alpha:i})}}drawText(e,t,n){const i=qu(t.font),s=Zu(t.font),o=t.align??"left",c=new $l({fill:t.color??"#ffffff",fontSize:Math.round(i*x*xr),fontFamily:s,align:o,...t.stroke&&t.strokeWidth?{stroke:{color:t.stroke,width:t.strokeWidth*x*xr}}:{}});if(t.backgroundColor&&t.backgroundColor!=="transparent"){const a=Sl.measureText(e.text,c),h=a.width/xr,u=a.height/xr,d=(t.backgroundPadding??.3)*x,f=o==="center"?.5:o==="right"?1:0,p=Pe(e.x)-f*h-d,m=Pe(e.y)-u/2-d,S=new re;S.rect(p,m,h+d*2,u+d*2),S.fill({color:t.backgroundColor,alpha:n}),this.container.addChild(S)}const l=new At({text:e.text,style:c});l.scale.set(1/xr),l.anchor.x=o==="center"?.5:o==="right"?1:0,l.anchor.y=.5,l.position.set(Pe(e.x),Pe(e.y)),l.alpha=n,this.container.addChild(l)}destroy(){const e=this.container.removeChildren();for(const t of e)t!==this.g&&t.destroy();this.g.destroy(),this.container.destroy()}}function gr(r,e){const t=localStorage.getItem(r),[n,i]=F(t!==null?t==="true":e);return[n,s=>{i(s),localStorage.setItem(r,String(s))}]}function Ju(r,e){const t=localStorage.getItem(r),[n,i]=F(t??e);return[n,s=>{i(s),localStorage.setItem(r,s)}]}const[Oo,Qu]=gr(ve.widescreenMode,!0),[xn,Lo]=gr(ve.showCreepLabels,!0),[Ao,Io]=gr(ve.showMapRoomNames,!1),[No,Do]=gr(ve.showUnclaimableRooms,!0),[pn,eh]=gr(ve.terrainEffects,!0),[Go,th]=gr(ve.showRoomVisuals,!0),[Ai,rh]=Ju(ve.spriteTheme,"default"),nh={id:"default",name:"Default",atlasUrl:"/themes/default/test.json",sprites:{storage:{layers:[{frame:"storage/shell",tint:"owner"},{frame:"storage/fill"}],tileScale:1.75}},controller:{backgroundFrame:"controller/background",segmentFrame:"controller/segment",tileScale:2},flag:{mainFrame:"flag/main",secondFrame:"flag/second",tileScale:3,zIndex:5},tombstone:{shellFrame:"grave/shell",crossFrame:"grave/cross",tileScale:1,zIndex:4}};class ih{constructor(){_(this,"cache",new Map);_(this,"pending",new Map)}getOrLoad(e){const t=this.cache.get(e);if(t)return Promise.resolve(t);const n=this.pending.get(e);if(n)return n;const i=kl.load(e).then(s=>(this.cache.set(e,s),this.pending.delete(e),s)).catch(s=>{throw this.pending.delete(e),s});return this.pending.set(e,i),i}getTexture(e,t){var n,i;return(i=(n=this.cache.get(e))==null?void 0:n.textures)==null?void 0:i[t]}destroy(){for(const[,e]of this.cache)e.destroy(!0);this.cache.clear(),this.pending.clear()}}const $s=new ih,Ii=Symbol("store-raw"),ar=Symbol("store-node"),it=Symbol("store-has"),zo=Symbol("store-self");function Bo(r){let e=r[Ft];if(!e&&(Object.defineProperty(r,Ft,{value:e=new Proxy(r,lh)}),!Array.isArray(r))){const t=Object.keys(r),n=Object.getOwnPropertyDescriptors(r),i=Object.getPrototypeOf(r),s=i!==null&&r!==null&&typeof r=="object"&&!Array.isArray(r)&&i!==Object.prototype;if(s){const o=Object.getOwnPropertyDescriptors(i);t.push(...Object.keys(o)),Object.assign(n,o)}for(let o=0,c=t.length;o<c;o++){const l=t[o];s&&l==="constructor"||n[l].get&&Object.defineProperty(r,l,{configurable:!0,enumerable:n[l].enumerable,get:n[l].get.bind(e)})}}return e}function wt(r){let e;return r!=null&&typeof r=="object"&&(r[Ft]||!(e=Object.getPrototypeOf(r))||e===Object.prototype||Array.isArray(r))}function dr(r,e=new Set){let t,n,i,s;if(t=r!=null&&r[Ii])return t;if(!wt(r)||e.has(r))return r;if(Array.isArray(r)){Object.isFrozen(r)?r=r.slice(0):e.add(r);for(let o=0,c=r.length;o<c;o++)i=r[o],(n=dr(i,e))!==i&&(r[o]=n)}else{Object.isFrozen(r)?r=Object.assign({},r):e.add(r);const o=Object.keys(r),c=Object.getOwnPropertyDescriptors(r);for(let l=0,a=o.length;l<a;l++)s=o[l],!c[s].get&&(i=r[s],(n=dr(i,e))!==i&&(r[s]=n))}return r}function _n(r,e){let t=r[e];return t||Object.defineProperty(r,e,{value:t=Object.create(null)}),t}function Gr(r,e,t){if(r[e])return r[e];const[n,i]=F(t,{equals:!1,internal:!0});return n.$=i,r[e]=n}function sh(r,e){const t=Reflect.getOwnPropertyDescriptor(r,e);return!t||t.get||!t.configurable||e===Ft||e===ar||(delete t.value,delete t.writable,t.get=()=>r[Ft][e]),t}function Fo(r){di()&&Gr(_n(r,ar),zo)()}function oh(r){return Fo(r),Reflect.ownKeys(r)}const lh={get(r,e,t){if(e===Ii)return r;if(e===Ft)return t;if(e===ts)return Fo(r),t;const n=_n(r,ar),i=n[e];let s=i?i():r[e];if(e===ar||e===it||e==="__proto__")return s;if(!i){const o=Object.getOwnPropertyDescriptor(r,e);di()&&(typeof s!="function"||r.hasOwnProperty(e))&&!(o&&o.get)&&(s=Gr(n,e,s)())}return wt(s)?Bo(s):s},has(r,e){return e===Ii||e===Ft||e===ts||e===ar||e===it||e==="__proto__"?!0:(di()&&Gr(_n(r,it),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:oh,getOwnPropertyDescriptor:sh};function He(r,e,t,n=!1){if(e==="__proto__"){console.warn('Refusing to set "__proto__" on a store.');return}if(!n&&r[e]===t)return;const i=r[e],s=r.length;t===void 0?(delete r[e],r[it]&&r[it][e]&&i!==void 0&&r[it][e].$()):(r[e]=t,r[it]&&r[it][e]&&i===void 0&&r[it][e].$());let o=_n(r,ar),c;if((c=Gr(o,e,i))&&c.$(()=>t),Array.isArray(r)&&r.length!==s){for(let l=r.length;l<s;l++)(c=o[l])&&c.$();(c=Gr(o,"length",s))&&c.$(r.length)}(c=o[zo])&&c.$()}function Ho(r,e){const t=Object.keys(e);for(let n=0;n<t.length;n+=1){const i=t[n];Uo(i)||He(r,i,e[i])}}function Uo(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function ah(r,e){if(typeof e=="function"&&(e=e(r)),e=dr(e),Array.isArray(e)){if(r===e)return;let t=0,n=e.length;for(;t<n;t++){const i=e[t];r[t]!==i&&He(r,t,i)}He(r,"length",n)}else Ho(r,e)}function Mr(r,e,t=[]){let n,i=r;if(e.length>1){n=e.shift();const o=typeof n,c=Array.isArray(r);if(o==="string"&&(n==="__proto__"||e.length>1&&Uo(n))){console.warn(`Refusing to traverse unsafe key "${n}" on a store.`);return}if(Array.isArray(n)){for(let l=0;l<n.length;l++)Mr(r,[n[l]].concat(e),t);return}else if(c&&o==="function"){for(let l=0;l<r.length;l++)n(r[l],l)&&Mr(r,[l].concat(e),t);return}else if(c&&o==="object"){const{from:l=0,to:a=r.length-1,by:h=1}=n;for(let u=l;u<=a;u+=h)Mr(r,[u].concat(e),t);return}else if(e.length>1){Mr(r[n],e,[n].concat(t));return}i=r[n],t=[n].concat(t)}let s=e[0];typeof s=="function"&&(s=s(i,t),s===i)||n===void 0&&s==null||(s=dr(s),n===void 0||wt(i)&&wt(s)&&!Array.isArray(s)?Ho(i,s):He(r,n,s))}function Wo(...[r,e]){const t=dr(r||{}),n=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 i=Bo(t);vl.registerGraph({value:t,name:e&&e.name});function s(...o){bl(()=>{n&&o.length===1?ah(t,o[0]):Mr(t,o)})}return[i,s]}const Ni=Symbol("store-root");function Ss(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function tr(r,e,t,n,i){if(Ss(t))return;const s=e[t];if(r===s)return;const o=Array.isArray(r);if(t!==Ni&&(!wt(r)||!wt(s)||o!==Array.isArray(s)||i&&r[i]!==s[i])){He(e,t,r);return}if(o){if(r.length&&s.length&&(!n||i&&r[0]&&r[0][i]!=null)){let a,h,u,d,f,p,m,S;for(u=0,d=Math.min(s.length,r.length);u<d&&(s[u]===r[u]||i&&s[u]&&r[u]&&s[u][i]&&s[u][i]===r[u][i]);u++)tr(r[u],s,u,n,i);const O=new Array(r.length),z=new Map;for(d=s.length-1,f=r.length-1;d>=u&&f>=u&&(s[d]===r[f]||i&&s[d]&&r[f]&&s[d][i]&&s[d][i]===r[f][i]);d--,f--)O[f]=s[d];if(u>f||u>d){for(h=u;h<=f;h++)He(s,h,r[h]);for(;h<r.length;h++)He(s,h,O[h]),tr(r[h],s,h,n,i);s.length>r.length&&He(s,"length",r.length);return}for(m=new Array(f+1),h=f;h>=u;h--)p=r[h],S=i&&p?p[i]:p,a=z.get(S),m[h]=a===void 0?-1:a,z.set(S,h);for(a=u;a<=d;a++)p=s[a],S=i&&p?p[i]:p,h=z.get(S),h!==void 0&&h!==-1&&(O[h]=s[a],h=m[h],z.set(S,h));for(h=u;h<r.length;h++)h in O?(He(s,h,O[h]),tr(r[h],s,h,n,i)):He(s,h,r[h])}else for(let a=0,h=r.length;a<h;a++)tr(r[a],s,a,n,i);s.length>r.length&&He(s,"length",r.length);return}const c=Object.keys(r);for(let a=0,h=c.length;a<h;a++)Ss(c[a])||tr(r[c[a]],s,c[a],n,i);const l=Object.keys(s);for(let a=0,h=l.length;a<h;a++)r[l[a]]===void 0&&He(s,l[a],void 0)}function ch(r,e={}){const{merge:t,key:n="id"}=e,i=dr(r);return s=>{if(!wt(s)||!wt(i))return i;const o=tr(i,{[Ni]:s},Ni,t,n);return o===void 0?s:o}}const Ji=new WeakMap;function ks(r,e){const[t,n]=Wo(e),i={id:r,type:e.type,raw:t};return Ji.set(i,s=>n(ch(s,{key:"_id",merge:!1}))),i}const[ur,hr]=F([]);function dh(){hr([])}function _r(r){hr(e=>e.filter(t=>t.id!==r))}function uh(r,e){const t=ur();let n=!1;const i=[];for(const s of t){const o=r[s.id];if(o===null){n=!0;continue}if(o!==void 0){const c=e[s.id];if(c){const l=Ji.get(s);l==null||l(c)}}i.push(s)}n&&hr(i)}function hh(r){var i;const e=ur();if(e.length===0)return;let t=!1;const n=[];for(const s of e){const o=r[s.id];if(!o){t=!0;continue}(i=Ji.get(s))==null||i(o),n.push(s)}t&&hr(n)}const[fh,qn]=F(null),[$n,Zn]=F(null),[Ge,Kn]=F(null),[Cs,Jn]=F(null),[Sn,Qn]=F({}),[Yo,Ts]=F(null),[cr,ph]=F(null),[zr,gh]=F(null);function Di(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 lt(r){const e=r.match(/^([WE])(\d+)([NS])(\d+)$/);if(!e)return null;const[,t,n,i,s]=e,o=t==="W"?-(parseInt(n,10)+1):parseInt(n,10),c=i==="N"?-(parseInt(s,10)+1):parseInt(s,10);return{x:o,y:c}}function We(r,e){const t=r<0?"W":"E",n=e<0?"N":"S",i=r<0?-r-1:r,s=e<0?-e-1:e;return`${t}${i}${n}${s}`}function Ms(r){return r===0||r<0&&(r+1)%10===0||r>0&&r%10===0}function C0(r,e){return Ms(r)||Ms(e)}function T0(r,e){const t=r<0?Math.abs(r+1)%10:Math.abs(r)%10,n=e<0?Math.abs(e+1)%10:Math.abs(e)%10;return t>=4&&t<=6&&n>=4&&n<=6}function Xo(r){const e=r;if(!e)return!1;const t=e.tagName??"";return t==="INPUT"||t==="TEXTAREA"?!0:e.isContentEditable===!0}function mh(r){const e=t=>{if(Xo(t.target))return;const n=r.currentRoom(),i=n?lt(n):null;if(!i)return;const s=r.worldBounds(),o=(c,l)=>!s||Di(c,l,s);switch(t.key){case"ArrowLeft":t.preventDefault(),o(i.x-1,i.y)&&r.onMove(i.x-1,i.y);break;case"ArrowRight":t.preventDefault(),o(i.x+1,i.y)&&r.onMove(i.x+1,i.y);break;case"ArrowUp":t.preventDefault(),o(i.x,i.y-1)&&r.onMove(i.x,i.y-1);break;case"ArrowDown":t.preventDefault(),o(i.x,i.y+1)&&r.onMove(i.x,i.y+1);break}};window.addEventListener("keydown",e),Le(()=>window.removeEventListener("keydown",e))}const[me,jo]=F(!1),[dt,Qi]=F(0),[Gi,yh]=F(0),[Br,Vo]=F(0),[Lr,Fr]=F(!1),[es,vh]=F(1),[Je,ei]=F(!1);let gn=null;function Hr(){gn!==null&&(clearInterval(gn),gn=null)}function qo(){Hr(),gn=setInterval(()=>{const r=dt()+1;r>Br()?(Hr(),Fr(!1)):Qi(r)},Math.max(50,Math.round(1e3/es())))}function Zo(r){const e=r,t=Math.max(0,e-2e5);Vo(e),yh(t),Qi(r),Fr(!1),Hr(),jo(!0)}function kn(){Hr(),Fr(!1),jo(!1)}function Cn(r){const e=Math.max(Gi(),Math.min(Br(),r));Qi(e)}function Es(r){Cn(dt()+r)}function bh(){Lr()?(Hr(),Fr(!1)):(Fr(!0),qo())}function wh(r){vh(r),Lr()&&qo()}class xh{constructor(e,t,n,i,s,o){_(this,"chunkCache",new Map);_(this,"inflight",new Map);this.room=e,this.shard=t,this.baseUrl=n,this.getToken=i,this.chunkSize=s,this.isPrivate=o}chunkBase(e){return e-e%this.chunkSize}buildUrl(e){return this.isPrivate||this.shard===null?`${this.baseUrl}room-history?room=${encodeURIComponent(this.room)}&time=${e}`:`${this.baseUrl}room-history/${encodeURIComponent(this.shard)}/${encodeURIComponent(this.room)}/${e}.json`}loadChunk(e){const t=this.chunkCache.get(e);if(t)return Promise.resolve(t);const n=this.inflight.get(e);if(n)return n;const i=this.buildUrl(e),s=this.getToken(),o={};s&&(o["X-Token"]=s,o["X-Username"]=s);const c=fetch(i,{headers:o}).then(l=>{if(!l.ok)throw new Error(`HTTP ${l.status}`);return l.json()}).then(l=>(this.chunkCache.set(e,l),this.inflight.delete(e),l)).catch(l=>{throw this.inflight.delete(e),l});return this.inflight.set(e,c),c}applyDiff(e,t){const n={...e};for(const i in t){const s=t[i];s===null?delete n[i]:n[i]?n[i]={...n[i],...s}:n[i]=s}return n}async getStateAtTick(e){let t=this.chunkBase(e),n,i;try{n=await this.loadChunk(t)}catch{const c=t-this.chunkSize;if(c<0)throw new Error(`No history data available before tick ${t}`);n=await this.loadChunk(c),t=c;const l=Object.keys(n.ticks).map(Number).filter(h=>h>=t),a=l.length>0?Math.max(...l):t;i=a,e=a}const s=n.ticks[String(t)]??{};let o={};for(const c in s)s[c]!==null&&(o[c]=s[c]);for(let c=t+1;c<=e;c++){const l=n.ticks[String(c)];l&&Object.keys(l).length>0&&(o=this.applyDiff(o,l))}return{objects:o,diff:n.ticks[String(e)]??{},gameTime:e,clampedTo:i}}}var _h=R('<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'),$h=R('<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'),Sh=R('<div style=display:flex;flex-direction:column;gap:2px;text-align:center><span>Moving "<!>" → </span><span style=opacity:0.6;font-size:0.9em>Navigate rooms or change target in sidebar · Right-click to cancel'),kh=R("<div style=display:flex;flex-direction:column;gap:2px;text-align:center><span></span><span style=opacity:0.6;font-size:0.9em>Right-click to exit flag mode"),Ch=R("<div style=display:flex;flex-direction:column;gap:2px;text-align:center><span>Select a structure type, then click to build</span><span style=opacity:0.6;font-size:0.9em>Ctrl+click to remove construction sites</span><span style=opacity:0.6;font-size:0.9em>Right-click to exit build mode"),Th=R("<div style=display:flex;flex-direction:column;gap:2px;text-align:center><span></span><span style=opacity:0.6;font-size:0.9em>Ctrl+click to remove construction sites</span><span style=opacity:0.6;font-size:0.9em>Right-click to exit build mode");const{log:Rs,warn:Mh,error:Ps}=_t("build"),Ur={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},Tn={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}},[bt,vt]=F("view"),[rr,Ko]=F({name:"",color:"COLOR_WHITE",secondaryColor:"COLOR_WHITE"}),[Dt,zi]=F(null),[Gt,Ar]=F(null),[at,Lt]=F({structureType:"",structureName:""});Hi(()=>{fe(()=>{const r=at().structureType;if(!r)return;const e=Ge()??0,t=Tn[r];if(!t)return;const n=Ht()==="empty"&&r==="spawn"?Math.max(t[e]??0,1):t[e]??0;if(n===2500)return;(Sn()[r]??0)>=n&&(Lt({structureType:"",structureName:""}),ut())})});function ut(){zi(null)}function Mn(){Ar(null)}function Jo(){Lt({structureType:"",structureName:""})}function Eh(r,e){const t=he(),n=at(),i=Dt();if(!t||!n.structureType||!i){Mh("missing requirements",{hasClient:!!t,structureType:n.structureType,pending:i});return}if(Ht()==="empty"&&n.structureType==="spawn"){Rs("placing spawn",{room:r,x:i.tx,y:i.ty,name:n.structureName||void 0,shard:e??void 0}),t.http.game.placeSpawn(r,i.tx,i.ty,n.structureName||void 0,e??void 0).then(()=>(Se("Spawn placed successfully","success"),ut(),t.stores.user.refreshWorldStatus())).catch(s=>{Ps("place spawn failed:",s),Se(`Failed to place spawn: ${s.message}`,"error")});return}Rs("creating construction site",{room:r,x:i.tx,y:i.ty,structureType:n.structureType,name:n.structureName||void 0,shard:e??void 0}),t.http.game.createConstruction(r,i.tx,i.ty,n.structureType,n.structureName||void 0,e??void 0).then(()=>{Se(`Construction site for ${n.structureType} created`,"success"),ut()}).catch(s=>{Ps("create construction failed:",s),Se(`Failed to create construction site: ${s.message}`,"error")})}function Rh(){vt("view"),ut(),Mn(),Jo()}function Ph(){var r;vt("view"),ut(),((r=ge(Gt))==null?void 0:r.type)!=="moveFlag"&&Mn(),Jo()}function Os(){const r=bt(),e=Dt(),t=Gt(),n=Ht();if(n==="empty")return(()=>{var i=_h(),s=i.firstChild,o=s.nextSibling;return o.$$click=()=>{vt("build"),Lt({structureType:"spawn",structureName:""})},i})();if(n==="lost")return(()=>{var i=$h(),s=i.firstChild,o=s.nextSibling;return o.$$click=()=>{const c=he();c&&c.http.user.respawn().then(()=>{Se("Respawn successful","success"),c.stores.user.refreshWorldStatus()}).catch(l=>{Se(`Respawn failed: ${l.message}`,"error")})},i})();if((t==null?void 0:t.type)==="moveFlag")return(()=>{var i=Sh(),s=i.firstChild,o=s.firstChild,c=o.nextSibling;return c.nextSibling,s.nextSibling,g(s,()=>t.name,c),g(s,()=>t.targetRoom,null),i})();if(r==="flag")return(()=>{var i=kh(),s=i.firstChild;return s.nextSibling,g(s,e?"Click again to confirm position":"Click to choose flag position"),i})();if(r==="build"){const i=at(),s=Ge(),o=Sn(),c=i.structureType;if(!c)return(()=>{var f=Ch(),p=f.firstChild,m=p.nextSibling;return m.nextSibling,f})();const l=Tn[c],a=(l==null?void 0:l[s??0])??0,h=o[c]??0,u=c.replace(/([A-Z])/g," $1").trim(),d=a===2500?`${h}/∞`:`${h}/${a}`;return(()=>{var f=Th(),p=f.firstChild,m=p.nextSibling;return m.nextSibling,g(p,`Click to build ${u} (${d})`),f})()}return null}Ee(["click"]);var Oh=R('<div style="position:absolute;bottom:0;left:0;right:0;padding:8px 12px;background:rgba(13, 17, 23, 0.85);border-top:1px solid #30363d;z-index:10"><input type=range step=1 style=width:100%;cursor:pointer><div style=display:flex;justify-content:space-between;font-size:10px;color:#8b949e;margin-top:2px><span></span><span></span><span>'),Lh=R("<div style=width:100%;height:100%;position:relative><div style=width:100%;height:100%>"),Ah=R('<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">'),Ih=R('<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:$r,error:Sr}=_t("room");function Nh(r){const e=P=>P==="default"?nh:null;let t,n=null,i=null,s=null,o=null,c=null;const[l,a]=F(null),[h,u]=F(null),[d,f]=F(null),[p,m]=F(""),[S,O]=F(dt());fe(()=>O(dt()));let z=null;return Wt(async()=>{if(!t)return;const P=await Vi.create(t);a(P)}),Le(()=>{z!==null&&clearTimeout(z),n==null||n.destroy(),n=null,s==null||s.destroy(),s=null,o==null||o.destroy(),o=null;const P=l();P&&P.destroy()}),fe(()=>{const P=he();if(!P||me())return;const k=r.room,C=r.shard;u(null),f(null),m(""),an(null),dh(),gh(k),ph(C),qn(null),Zn(null),Kn(null),Jn(null),Qn({}),Ts(null);const w=new Wi;let I=!1;P.stores.room.terrain(k,C).then(y=>{I||u({room:k,data:y})}).catch(y=>{I||Sr(`terrain load failed for ${k}:`,y)}),w.add(P.stores.room.subscribe(k,C)),w.add(P.stores.room.on("room:error",y=>{Se(`Room subscription error (${y.room}): ${y.message}`,"error",8e3)})),w.add(P.stores.room.on("room:update",y=>{var M,A;let $=0;const L={};let v=0,T=null,E=null;for(const D in y.objects){$++;const U=y.objects[D];if(!U)continue;const G=U.type;if(typeof G=="string")if(G==="constructionSite"){const B=U.structureType;typeof B=="string"&&(L[B]=(L[B]||0)+1)}else L[G]=(L[G]||0)+1;if(G==="controller"&&typeof U.user=="string"){const B=U.user,V=((A=(M=y.users)==null?void 0:M[B])==null?void 0:A.username)??B;E={userId:B,username:V},typeof U.level=="number"&&(v=U.level),typeof U.progress=="number"&&(T=U.progress)}}y.diff||$r(`objects loaded — ${k}: ${$} objects, tick=${y.gameTime}`),f({objects:y.objects,diff:y.diff,users:y.users}),m(y.visual),an(y.gameTime??null),za(y.gameTime),qn($),Zn(E),Kn(v||null),Jn(T),Qn(L),Ts(y.users??null)})),Le(()=>{I=!0,w.dispose()})}),fe(()=>{var L,v;const P=he();if(!P||!me())return;m("");const k=r.room,C=r.shard,w=uo()??!0,I=((v=(L=ji())==null?void 0:L.serverData)==null?void 0:v.historyChunkSize)??(w?20:100),y=ge(Yo)??void 0,$=new xh(k,C,P.http.baseUrl,()=>P.http.token,I,w);fe(()=>{const T=dt();let E=!1;ei(!0),$.getStateAtTick(T).then(M=>{var V;if(E)return;if(ei(!1),M.clampedTo!==void 0){Vo(M.clampedTo),Cn(M.clampedTo);return}f({objects:M.objects,diff:void 0,users:y}),an(M.gameTime);let A=0;const D={};let U=0,G=null,B=null;for(const X in M.objects){A++;const j=M.objects[X];if(!j)continue;const q=j.type;if(typeof q=="string")if(q==="constructionSite"){const H=j.structureType;typeof H=="string"&&(D[H]=(D[H]||0)+1)}else D[q]=(D[q]||0)+1;if(q==="controller"&&typeof j.user=="string"){const H=j.user,K=((V=y==null?void 0:y[H])==null?void 0:V.username)??H;B={userId:H,username:K},typeof j.level=="number"&&(U=j.level),typeof j.progress=="number"&&(G=j.progress)}}qn(A),Zn(B),Kn(U||null),Jn(G),Qn(D)}).catch(M=>{E||(ei(!1),Se(`History load failed for tick ${T}: ${M.message}`,"error",5e3))}),Le(()=>{E=!0})})}),fe(()=>{const P=l();if(!P)return;r.room,r.shard,Ph(),P.hoverLayer.clearPendingTile();const k=ge(Gt);(k==null?void 0:k.type)==="moveFlag"?Ar({...k,targetRoom:r.room}):P.resetView(),c==null||c.destroy(),c=null,P.clear(),P.resetView(),n==null||n.destroy(),n=null,s==null||s.destroy(),s=null,o==null||o.destroy(),o=null;const C=ge(h);C&&C.room===r.room&&($r(`terrain applied immediately (pre-loaded) — ${r.room}`),c=ys(C.data,P.app.renderer),Un(c,ge(pn)),P.world.addChildAt(c,0),P.bringNavOverlayToTop());const w=r.room,I=r.shard,y=lt(w),$=ge(()=>r.onNavigate),L=ge(Bn);if(y&&$){const v=(E,M)=>!L||Di(E,M,L),T=E=>{$(E,I)};P.setupNavigationZones({west:v(y.x-1,y.y)?()=>T(We(y.x-1,y.y)):void 0,east:v(y.x+1,y.y)?()=>T(We(y.x+1,y.y)):void 0,north:v(y.x,y.y-1)?()=>T(We(y.x,y.y-1)):void 0,south:v(y.x,y.y+1)?()=>T(We(y.x,y.y+1)):void 0})}}),fe(()=>{const P=l();if(!P)return;const k=ge(()=>r.room),C=ge(()=>r.shard),w=lt(k);if(w&&r.onNavigate){const I=r.onNavigate,y=Bn(),$=(v,T)=>!y||Di(v,T,y),L=v=>{I(v,C)};mh({currentRoom:()=>r.room,worldBounds:Bn,onMove:(v,T)=>L(We(v,T))}),P.setupNavigationZones({west:$(w.x-1,w.y)?()=>L(We(w.x-1,w.y)):void 0,east:$(w.x+1,w.y)?()=>L(We(w.x+1,w.y)):void 0,north:$(w.x,w.y-1)?()=>L(We(w.x,w.y-1)):void 0,south:$(w.x,w.y+1)?()=>L(We(w.x,w.y+1)):void 0})}}),fe(()=>{const P=bt(),k=l();P==="view"&&k&&(ut(),k.hoverLayer.clearPendingTile())}),fe(()=>{const P=l(),k=Dt();P&&(k?P.hoverLayer.setPendingTile(k.tx,k.ty):P.hoverLayer.clearPendingTile())}),fe(()=>{const P=l(),k=h();if(!(!P||!k||k.room!==r.room)){if(c!=null&&c.parent){$r(`terrain already in scene, skipping — ${r.room}`);return}$r(`terrain applied (async) — ${r.room}`),c=ys(k.data,P.app.renderer),Un(c,ge(pn)),P.world.addChildAt(c,0),P.bringNavOverlayToTop()}}),fe(()=>{var T,E;const P=l(),k=d();if(!P)return;if(!k){n==null||n.clear(),s==null||s.clear();return}const{objects:C,diff:w,users:I}=k;n||($r(`object layer created — ${r.room}`),n=new Xu(P.app.ticker,xn(),(T=Fe())==null?void 0:T._id,(E=Fe())==null?void 0:E.badge,I),n.setTheme(e(ge(Ai)),$s),n.setInstantMode(ge(me)),n.container.label="objects",P.world.addChild(n.container),P.bringNavOverlayToTop(),s=new ju(P.app.ticker),s.container.label="animations",P.world.addChild(s.container),o=new Ku,P.world.addChild(o.container),P.bringNavOverlayToTop(),P.setTileHandlers((M,A)=>{},(M,A,D)=>{const U=r.room,G=r.shard,B=bt(),V=Gt();if((V==null?void 0:V.type)==="moveFlag"){const H=he();if(!H)return;const{name:K,room:le,color:ce,secondaryColor:de,targetRoom:Te}=V;H.http.game.removeFlag(le,K).then(()=>H.http.game.createFlag(Te,M,A,K,ce,de,G??void 0)).then(()=>{Se(`Flag "${K}" moved`,"success"),Mn()}).catch(te=>{Sr("move flag failed:",te),Se(`Failed to move flag "${K}"`,"error"),Mn()});return}if(B==="flag"){const H=Dt();if(!H||H.tx!==M||H.ty!==A){zi({tx:M,ty:A}),P.hoverLayer.setPendingTile(M,A);return}const K=he();if(!K)return;const le=rr(),ce=le.name.trim();if(!ce){Se("Flag name is required","error");return}const de=Ur[le.color]??0,Te=Ur[le.secondaryColor]??0;K.http.game.createFlag(U,M,A,ce,de,Te,G??void 0).then(()=>{Se(`Flag "${ce}" created`,"success"),ut(),P.hoverLayer.clearPendingTile(),K.http.game.genUniqueFlagName().then(te=>Ko(pe=>({...pe,name:te.name}))).catch(te=>Sr("gen unique flag name failed:",te))}).catch(te=>Sr("create flag failed:",te));return}if(B==="build"){if(!D&&!at().structureType){Se("Select a structure type first","error");return}if(D){if(!n)return;const K=n.getObjectsAtTile(M,A).filter(({obj:ce})=>ce.type==="constructionSite");if(K.length===0){Se("No construction sites on this tile","error");return}const le=he();if(!le)return;le.http.game.removeConstructionSite(U,K.map(({id:ce})=>ce),G??void 0).then(()=>{Se(`Removed ${K.length} construction site${K.length>1?"s":""}`,"success"),ut(),P.hoverLayer.clearPendingTile()}).catch(ce=>{Sr("remove construction sites failed:",ce),Se(`Failed to remove construction sites: ${ce.message}`,"error")});return}zi({tx:M,ty:A}),P.hoverLayer.setPendingTile(M,A),Eh(U,G);return}if(ut(),P.hoverLayer.clearPendingTile(),!n)return;const X=n.getObjectsAtTile(M,A);if(X.length===0){D||(hr([]),P.hoverLayer.clearSelection());return}let j=[...ur()];if(D){const H=new Set(X.map(le=>le.id));if(j.some(le=>H.has(le.id)))j=j.filter(le=>!H.has(le.id));else{const le=X.filter(({id:ce})=>!j.some(de=>de.id===ce)).map(({id:ce,obj:de})=>ks(ce,de));j=[...j,...le]}}else j=X.map(({id:H,obj:K})=>ks(H,K));hr(j);const q=j.map(({id:H,type:K})=>({id:H,type:K,visual:n.getVisualById(H)})).filter(H=>H.visual!=null);P.hoverLayer.setSelectedObjects(q)},()=>{var A;const M=bt();(M==="build"||M==="flag"||((A=Gt())==null?void 0:A.type)==="moveFlag")&&(Rh(),P.hoverLayer.clearPendingTile())})),w?uh(w,C):hh(C);const y=me()?Math.round(1e3/ge(es)):mn()??2e3,$=y*.6,L=Math.round(y*.9);n.setMoveDuration(L),i={objects:C,users:I},n.update(C,w,I,ze()??void 0),n.setShowLabels(ge(xn));const v=new Set;if(s){s.clear();for(const M in C){const A=C[M];if(!A||A.type!=="creep")continue;const D=A.actionLog;if(!D)continue;const U=D.harvest;U&&s.addHarvest(U.x,U.y,A.x,A.y,$);const G=D.upgradeController;G&&s.addUpgradeController(A.x,A.y,G.x,G.y,$);const B=D.build;B&&(s.addBuild(A.x,A.y,B.x,B.y,$),n==null||n.triggerBuildAt(B.x,B.y,$));const V=D.say;V&&typeof V.message=="string"&&V.message.length>0&&(n==null||n.triggerSay(M,V.message),v.add(M))}}n.pruneSayBubblesExcept(v)}),fe(()=>{const P=p();o==null||o.update(Go()?P:"")}),fe(()=>{n==null||n.setInstantMode(me())}),fe(()=>{const P=pn();c&&Un(c,P)}),fe(()=>{const P=e(Ai());n&&(n.setTheme(P,$s),i&&(n.clear(),n.update(i.objects,void 0,i.users)))}),(()=>{var P=Lh(),k=P.firstChild;return nr(C=>t=C,k),g(P,(()=>{var C=ee(()=>!!Os());return()=>C()&&(()=>{var w=Ah();return g(w,Os),N(I=>Y(w,"pointer-events",Ht()==="empty"||Ht()==="lost"?"auto":"none")),w})()})(),null),g(P,(()=>{var C=ee(()=>!me()&&ze()!==null);return()=>C()&&(()=>{var w=Ih();return w.firstChild,g(w,ze,null),w})()})(),null),g(P,b(Z,{get when(){return me()},get children(){var C=Oh(),w=C.firstChild,I=w.nextSibling,y=I.firstChild,$=y.nextSibling,L=$.nextSibling;return w.$$input=v=>{const T=parseInt(v.currentTarget.value,10);O(T),z!==null&&clearTimeout(z),z=setTimeout(()=>{z=null,Cn(T)},150)},g(y,Gi),g($,(()=>{var v=ee(()=>!!Je());return()=>v()?"Loading…":`Tick ${dt()}`})()),g(L,Br),N(v=>{var T=Gi(),E=Br(),M=Je()?"#f0883e":"#8b949e";return T!==v.e&&we(w,"min",v.e=T),E!==v.t&&we(w,"max",v.t=E),M!==v.a&&Y($,"color",v.a=M),v},{e:void 0,t:void 0,a:void 0}),N(()=>w.value=S()),C}}),null),P})()}Ee(["input"]);var Dh=R("<div style=position:fixed;bottom:16px;right:16px;display:flex;flex-direction:column;gap:8px;z-index:9999;pointer-events:none>"),Gh=R('<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 zh(){return(()=>{var r=Dh();return g(r,b(xe,{get each(){return Ea()},children:e=>(()=>{var t=Gh();return g(t,()=>e.message),N(n=>Y(t,"background",e.type==="error"?"#da3633":"#238636")),t})()})),r})()}const[mt,Bh]=F(!0),[rt,Qo]=F(!0),[Kt,el]=F(!1),[ti,Et]=F("");let Rt;function Fh(r){Rt=r}function Hh(r){Et(r),Qo(!0),requestAnimationFrame(()=>{Rt==null||Rt.focus();const e=r.length;Rt==null||Rt.setSelectionRange(e,e)})}function tl(){Bh(r=>!r)}function rl(){Qo(r=>!r)}function nl(){el(r=>!r)}const[fr,il]=F(io(ve.memoryWatches,[])),[Wr,sl]=F(null),[Bi,Uh]=Wo({});function Wh(r){const e=r.trim();e&&(il(t=>t.includes(e)?t:[...t,e]),Xi(ve.memoryWatches,fr()))}function Yh(r){il(e=>e.filter(t=>t!==r)),Xi(ve.memoryWatches,fr())}function ol(){sl(null)}function Xh(r,e){sl({creepId:r,name:e})}function jh(r,e){const t=[...e];if(r){const n=`creeps.${r.name}`;t.includes(n)||t.push(n)}return t}function Vh(r){const e=new Map,t=()=>{const s=he();if(!s)return;const o=new Set(jh(Wr(),fr()));for(const c of o)e.has(c)||e.set(c,s.stores.user.subscribeMemory(c,r));for(const[c,l]of e)o.has(c)||(l.dispose(),e.delete(c))};fe(()=>{fr(),Wr(),t()});const n=he();let i=null;return n?i=n.stores.user.on("user:memory",s=>{console.log("[memoryStore] user:memory received",s.path,s.value),Uh(s.path,s.value),console.log("[memoryStore] memoryValues after set:",JSON.stringify(Bi))}):console.warn("[memoryStore] no client available when initMemorySubscriptions called"),Le(()=>{for(const s of e.values())s.dispose();e.clear(),i==null||i.dispose()}),t(),()=>{for(const s of e.values())s.dispose();e.clear(),i==null||i.dispose()}}Hi(()=>{fe(()=>{const r=Wr();if(!r)return;ur().some(t=>t.id===r.creepId)||ol()})});var qh=R("<button style=color:#8b949e>"),Zh=R("<span style=width:18px;flex-shrink:0>"),Kh=R("<span style=color:#484f58;font-style:italic>{…}"),Jh=R("<span style=color:#484f58;font-style:italic>"),Qh=R("<button title=Reload>"),ef=R('<span title="Click to edit"style=cursor:text;flex:1>'),tf=R('<input type=text autofocus style="background:#161b22;border:1px solid #388bfd;color:#c9d1d9;border-radius:3px;padding:0 4px;font-size:12px;font-family:inherit;flex:1;min-width:60px">'),rf=R("<button title=Save style=color:#3fb950>"),nf=R("<button title=Discard style=color:#f85149>"),sf=R('<div><div style=display:flex;align-items:center;gap:2px;min-height:20px><span style=color:#8b949e;flex-shrink:0></span><span style="color:#484f58;margin:0 2px;flex-shrink:0">:</span><button>');const{error:Ls}=_t("MemoryTree");function Ke(r){return r!==null&&typeof r=="object"&&"__screeps_object__"in r}const of={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"},kr={background:"transparent",border:"none",color:"#8b949e",cursor:"pointer",padding:"2px","border-radius":"3px",display:"inline-flex","align-items":"center","justify-content":"center","flex-shrink":0};function tn(r){return r.replace(/^Memory\.?/,"")}function ll(r){const[e,t]=F((r.depth??0)<2),n=()=>r.depth??0,[i,s]=F(!1),[o,c]=F(""),[l,a]=F(!1),[h,u]=F(void 0),d=()=>Ke(r.value)&&h()!==void 0?h():r.value,f=()=>{const w=d();return!Ke(w)&&w!==null&&typeof w=="object"},p=()=>f()?Object.entries(d()):[],m=()=>p().length,S=async()=>{a(!0);try{const w=he();if(!w)return;const I=tn(r.path),y=await w.http.user.memory.get(I,r.shard),$=y.data==="[object Object]"?{__screeps_object__:!0}:y.data;u($)}catch(w){Ls("fetch memory failed",w)}finally{a(!1)}},O=()=>{u(void 0),S()};Wt(()=>{e()&&Ke(r.value)&&h()===void 0&&S()});const z=async()=>{if(Ke(r.value)&&h()===void 0){await S(),t(!0);return}e()&&u(void 0),t(w=>!w)},P=async()=>{var L;const w=o().trim();let I;if(w==="null")I=null;else if(w==="true")I=!0;else if(w==="false")I=!1;else{const v=Number(w);if(!Number.isNaN(v)&&w!=="")I=v;else try{I=JSON.parse(w)}catch{I=w}}const y=he();if(!y)return;const $=tn(r.path);try{await y.http.user.memory.set($,I,r.shard)}catch(v){Ls("set memory failed",v),s(!1);return}s(!1),(L=r.onRefresh)==null||L.call(r)},k=()=>{const w=d();return f()?"#c9d1d9":typeof w=="string"?"#3fb950":typeof w=="number"?"#79c0ff":typeof w=="boolean"?"#a371f7":"#8b949e"},C=()=>{const w=d();return w===null?"null":w===void 0?"undefined":typeof w=="string"?JSON.stringify(w):String(w)};return(()=>{var w=sf(),I=w.firstChild,y=I.firstChild,$=y.nextSibling,L=$.nextSibling;return g(I,b(Z,{get when(){return f()||Ke(d())},get children(){var v=qh();return v.$$click=()=>void z(),g(v,b(Z,{get when(){return l()},get children(){return b(Ec,{size:12,style:{animation:"spin 1s linear infinite"}})}}),null),g(v,b(Z,{get when(){return!l()},get children(){return b(Z,{get when(){return e()},get fallback(){return b(fo,{size:12})},get children(){return b(sc,{size:12})}})}}),null),N(T=>{var E={...kr},M=e()?"Collapse":"Expand",A=l();return T.e=Q(v,E,T.e),M!==T.t&&we(v,"title",T.t=M),A!==T.a&&(v.disabled=T.a=A),T},{e:void 0,t:void 0,a:void 0}),v}}),y),g(I,b(Z,{get when(){return ee(()=>!f())()&&!Ke(d())},get children(){return Zh()}}),y),g(y,()=>r.label),g(I,b(Z,{get when(){return Ke(d())},get children(){return Kh()}}),L),g(I,b(Z,{get when(){return f()},get children(){var v=Jh();return g(v,(()=>{var T=ee(()=>!!Array.isArray(d()));return()=>T()?`[${m()}]`:`{${m()}}`})()),v}}),L),g(I,b(Z,{get when(){return ee(()=>!!Ke(r.value))()&&!l()},get children(){var v=Qh();return v.$$click=()=>O(),g(v,b(Zc,{size:11})),N(T=>Q(v,kr,T)),v}}),L),g(I,b(Z,{get when(){return ee(()=>!f())()&&!Ke(d())},get children(){return[b(Z,{get when(){return!i()},get children(){var v=ef();return v.$$click=()=>{c(C()),s(!0)},g(v,C),N(T=>Y(v,"color",k())),v}}),b(Z,{get when(){return i()},get children(){return[(()=>{var v=tf();return v.$$keydown=T=>{T.key==="Enter"&&P(),T.key==="Escape"&&s(!1)},v.$$input=T=>c(T.currentTarget.value),N(()=>v.value=o()),v})(),(()=>{var v=rf();return v.$$mousedown=T=>{T.preventDefault(),P()},g(v,b(ho,{size:12})),N(T=>Q(v,{...kr},T)),v})(),(()=>{var v=nf();return v.$$mousedown=T=>{T.preventDefault(),s(!1)},g(v,b(Ut,{size:12})),N(T=>Q(v,{...kr},T)),v})()]}})]}}),L),L.$$click=()=>Hh(`Memory.${tn(r.path)} = `),g(L,b(rd,{size:11})),g(w,b(Z,{get when(){return ee(()=>!!f())()&&e()},get children(){return b(xe,{get each(){return p()},children:([v,T])=>{const E=Array.isArray(d())?`${r.path}[${v}]`:`${r.path}.${v}`;return b(ll,{value:T,path:E,label:v,get shard(){return r.shard},get depth(){return n()+1},get onRefresh(){return ee(()=>!!Ke(r.value))()?O:r.onRefresh}})}})}}),null),N(v=>{var T={"padding-left":n()>0?"14px":"0",...of},E=kr,M=`Insert Memory.${tn(r.path)} = into console`;return v.e=Q(w,T,v.e),v.t=Q(L,E,v.t),M!==v.a&&we(L,"title",v.a=M),v},{e:void 0,t:void 0,a:void 0}),w})()}function As(r){return b(ll,{get value(){return r.value},get path(){return r.path},get label(){return r.label},get shard(){return r.shard},depth:0})}Ee(["click","input","keydown","mousedown"]);var lf=R("<div style=color:#484f58;font-style:italic>No paths watched — add one below."),af=R('<div style=flex-shrink:0;display:flex;flex-direction:column;overflow:hidden><div class=console-scroll style=flex:1;overflow:auto;padding:8px></div><form style="display:flex;gap:6px;padding:8px;border-top:1px solid #30363d"><input type=text placeholder=creeps.Harvester1.energy 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 title="Add watch"style="padding:6px 8px;border-radius:4px;border:none;background:#238636;color:#fff;font-size:12px;cursor:pointer;display:flex;align-items:center;gap:4px"> Watch'),cf=R('<div style=margin-bottom:8px><div style="display:flex;align-items:center;gap:4px;border-bottom:1px solid #21262d;padding-bottom:4px;margin-bottom:4px"><span style=color:#f0883e;font-weight:600;flex:1></span><span style=color:#484f58;font-size:10px;font-style:italic>temp</span><button title="Remove temp watch">'),df=R('<div style=margin-bottom:8px><div style="display:flex;align-items:center;gap:4px;border-bottom:1px solid #21262d;padding-bottom:4px;margin-bottom:4px"><span style=color:#c9d1d9;font-weight:600;flex:1></span><button title="Remove watch">'),uf=R('<div style=flex-shrink:0;display:flex;overflow:hidden><div style="width:32px;flex-shrink:0;border-right:1px solid #30363d;display:flex;flex-direction:column;align-items:center;padding:6px 0;gap:6px"><button></button><button title=Clear></button></div><div class=console-scroll style=flex:1;overflow:auto;padding:8px>'),Is=R("<div style=width:4px;flex-shrink:0;cursor:col-resize>"),hf=R('<div style=flex-shrink:0;display:flex;flex-direction:column;overflow:hidden><div class=console-scroll 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'),ff=R("<div style=flex:1;display:flex;overflow:hidden>"),pf=R(`<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><button>Memory</button></div><style>
10
+ .console-scroll::-webkit-scrollbar {
11
+ width: 8px;
12
+ height: 8px;
13
+ }
14
+ .console-scroll::-webkit-scrollbar-track {
15
+ background: #161b22;
16
+ }
17
+ .console-scroll::-webkit-scrollbar-thumb {
18
+ background: #484f58;
19
+ border-radius: 4px;
20
+ }
21
+ .console-scroll::-webkit-scrollbar-thumb:hover {
22
+ background: #6e7681;
23
+ }
24
+ `),gf=R("<div style=color:#484f58;font-style:italic>No log output yet…"),mf=R("<div style=margin-bottom:4px;color:#f85149;white-space:pre-wrap;word-break:break-word>"),yf=R("<div style=margin-bottom:4px;color:#c9d1d9;white-space:pre-wrap;word-break:break-word>"),vf=R("<div style=color:#484f58;font-style:italic>No command results yet…"),bf=R("<div style=margin-bottom:4px;color:#58a6ff;white-space:pre-wrap;word-break:break-word>");const{error:wf}=_t("console");function xf(r){const[e,t]=F(""),n=()=>r.shard??cr();Wt(()=>{Vh(n())});const i={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"},s={background:"transparent",border:"none",color:"#8b949e",cursor:"pointer",padding:"4px","border-radius":"4px",display:"flex","align-items":"center","justify-content":"center"};return(()=>{var o=af(),c=o.firstChild,l=c.nextSibling,a=l.firstChild,h=a.nextSibling,u=h.firstChild;return g(c,b(Z,{get when(){return Wr()},children:d=>{const f=`creeps.${d().name}`;return(()=>{var p=cf(),m=p.firstChild,S=m.firstChild,O=S.nextSibling,z=O.nextSibling;return g(S,f),st(z,"click",ol,!0),g(z,b(Ut,{size:12})),g(p,b(As,{get value(){return Bi[f]},path:`Memory.${f}`,label:f,get shard(){return n()}}),null),N(P=>Q(z,s,P)),p})()}}),null),g(c,b(xe,{get each(){return fr()},children:d=>(()=>{var f=df(),p=f.firstChild,m=p.firstChild,S=m.nextSibling;return g(m,d),S.$$click=()=>Yh(d),g(S,b(Ut,{size:12})),g(f,b(As,{get value(){return Bi[d]},path:`Memory.${d}`,label:d,get shard(){return n()}}),null),N(O=>Q(S,s,O)),f})()}),null),g(c,b(Z,{get when(){return ee(()=>fr().length===0)()&&!Wr()},get children(){return lf()}}),null),l.addEventListener("submit",d=>{d.preventDefault(),Wh(e()),t("")}),a.$$input=d=>t(d.currentTarget.value),g(h,b(jc,{size:14}),u),N(d=>{var f=`${r.width*100}%`,p={...i};return f!==d.e&&Y(o,"width",d.e=f),d.t=Q(c,p,d.t),d},{e:void 0,t:void 0}),N(()=>a.value=e()),o})()}function _f(r){const[e,t]=F([]),[n,i]=F(!0),s=[1,1,1],[o,c]=F(io(ve.consoleWeights,[...s])),[l,a]=F(null);let h,u,d,f=0;Wt(()=>{const G=he();if(!G)return;const B=new Wi;B.add(G.stores.user.subscribe("console")),B.add(G.stores.user.on("user:console",V=>{const X=V.messages,j={id:f++,log:X.log??[],results:X.results??[],error:X.error??[]};t(q=>{const H=[...q,j];return H.length>200?H.slice(H.length-200):H})})),Le(()=>B.dispose())}),fe(()=>{e(),n()&&requestAnimationFrame(()=>{mt()&&h&&(h.scrollTop=h.scrollHeight),rt()&&u&&(u.scrollTop=u.scrollHeight)})});const p=(G,B,V)=>{var j,q;const X=!G&&!B&&!V;X&&!r.isCollapsed&&((j=r.onToggle)==null||j.call(r)),!X&&r.isCollapsed&&((q=r.onToggle)==null||q.call(r))};fe(()=>{p(mt(),rt(),Kt())});const m=()=>{const G=o(),B=[mt(),rt(),Kt()],V=B.filter(Boolean).length;if(V===0)return[0,0,0];if(V===1){const q=B.findIndex(Boolean);return[0,0,0].map((H,K)=>K===q?1:0)}const j=B.map((q,H)=>q?G[H]:0).reduce((q,H)=>q+H,0);if(j===0){const q=1/V;return[0,0,0].map((H,K)=>B[K]?q:0)}return B.map((q,H)=>q?G[H]/j:0)};fe(()=>{Xi(ve.consoleWeights,o())});const S=G=>B=>{B.preventDefault(),B.stopPropagation(),a(G),document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("pointermove",O),window.addEventListener("pointerup",z,{once:!0})},O=G=>{const B=l();if(B===null)return;const V=d;if(!V)return;const X=V.getBoundingClientRect(),j=Math.max(.02,Math.min(.98,(G.clientX-X.left)/X.width)),q=[...o()],H=[mt(),rt(),Kt()];if(B===0){const K=H[0],le=H[1];if(!K||!le)return;const ce=j/(1-j);q[0]=ce,q[1]=1,c(q)}else{const K=H[1],le=H[2];if(!K||!le)return;const ce=j/(1-j);q[1]=ce,q[2]=1,c(q)}},z=()=>{a(null),document.body.style.cursor="",document.body.style.userSelect="",window.removeEventListener("pointermove",O)},[P,k]=F([]),[C,w]=F(null),[I,y]=F(""),$=G=>{const B=P();if(B.length!==0){if(G.key==="ArrowUp"){G.preventDefault();const V=C();V===null?(y(ti()),w(B.length-1),Et(B[B.length-1])):V>0&&(w(V-1),Et(B[V-1]))}else if(G.key==="ArrowDown"){G.preventDefault();const V=C();if(V===null)return;V<B.length-1?(w(V+1),Et(B[V+1])):(w(null),Et(I()))}}},L=async G=>{G.preventDefault();const B=he(),V=ti().trim();if(!(!B||!V))try{await B.http.user.console(V,r.shard??"shard0"),k(X=>[...X,V]),w(null),y(""),Et("")}catch(X){wf("command failed:",X)}},v=G=>({background:G?"#30363d":"transparent",border:`1px solid ${G?"#58a6ff":"transparent"}`,color:G?"#c9d1d9":"#8b949e","font-size":"12px",cursor:"pointer",padding:"2px 10px","border-radius":"4px"}),T=()=>e().flatMap(G=>G.log),E=()=>e().flatMap(G=>G.error),M=()=>e().flatMap(G=>G.results),A={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"},D={background:"transparent",border:"none",color:"#8b949e",cursor:"pointer",padding:"4px","border-radius":"4px",display:"flex","align-items":"center","justify-content":"center"},U=()=>{i(!0),requestAnimationFrame(()=>{mt()&&h&&(h.scrollTop=h.scrollHeight),rt()&&u&&(u.scrollTop=u.scrollHeight)})};return(()=>{var G=pf(),B=G.firstChild,V=B.firstChild,X=V.nextSibling,j=X.nextSibling;return B.nextSibling,st(V,"click",tl,!0),st(X,"click",rl,!0),st(j,"click",nl,!0),g(G,b(Z,{get when(){return!r.isCollapsed},get children(){var q=ff();return nr(H=>d=H,q),g(q,b(Z,{get when(){return mt()},get children(){var H=uf(),K=H.firstChild,le=K.firstChild,ce=le.nextSibling,de=K.nextSibling;le.$$click=()=>n()?i(!1):U(),g(le,(()=>{var te=ee(()=>!!n());return()=>te()?b(Fc,{size:16}):b(Wc,{size:16})})()),ce.$$click=()=>t([]),g(ce,b(dn,{size:16})),de.addEventListener("scroll",()=>{h&&i(h.scrollHeight-h.scrollTop-h.clientHeight<20)});var Te=h;return typeof Te=="function"?nr(Te,de):h=de,g(de,(()=>{var te=ee(()=>T().length===0&&E().length===0);return()=>te()&&gf()})(),null),g(de,b(xe,{get each(){return E()},children:te=>(()=>{var pe=mf();return pe.innerHTML=te,pe})()}),null),g(de,b(xe,{get each(){return T()},children:te=>(()=>{var pe=yf();return pe.innerHTML=te,pe})()}),null),N(te=>{var pe=`${m()[0]*100}%`,Ie=n()?"Pause scrolling":"Resume scrolling",ht=D,et=D,Ve={...A};return pe!==te.e&&Y(H,"width",te.e=pe),Ie!==te.t&&we(le,"title",te.t=Ie),te.a=Q(le,ht,te.a),te.o=Q(ce,et,te.o),te.i=Q(de,Ve,te.i),te},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),H}}),null),g(q,b(Z,{get when(){return ee(()=>!!mt())()&&rt()},get children(){var H=Is();return st(H,"pointerdown",S(0),!0),N(K=>Y(H,"background",l()===0?"#388bfd":"#21262d")),H}}),null),g(q,b(Z,{get when(){return rt()},get children(){var H=hf(),K=H.firstChild,le=K.nextSibling,ce=le.firstChild,de=ce.nextSibling;de.nextSibling,K.addEventListener("scroll",()=>{u&&i(u.scrollHeight-u.scrollTop-u.clientHeight<20)});var Te=u;return typeof Te=="function"?nr(Te,K):u=K,g(K,(()=>{var te=ee(()=>M().length===0);return()=>te()&&vf()})(),null),g(K,b(xe,{get each(){return M()},children:te=>(()=>{var pe=bf();return pe.innerHTML=te,pe})()}),null),le.addEventListener("submit",L),de.$$keydown=$,de.$$input=te=>{w(null),Et(te.currentTarget.value)},nr(te=>Fh(te),de),N(te=>{var pe=`${m()[1]*100}%`,Ie={...A};return pe!==te.e&&Y(H,"width",te.e=pe),te.t=Q(K,Ie,te.t),te},{e:void 0,t:void 0}),N(()=>de.value=ti()),H}}),null),g(q,b(Z,{get when(){return ee(()=>!!rt())()&&Kt()},get children(){var H=Is();return st(H,"pointerdown",S(1),!0),N(K=>Y(H,"background",l()===1?"#388bfd":"#21262d")),H}}),null),g(q,b(Z,{get when(){return Kt()},get children(){return b(xf,{get shard(){return r.shard??null},get width(){return m()[2]}})}}),null),N(H=>Y(q,"user-select",l()!==null?"none":"auto")),q}}),null),N(q=>{var H=v(mt()),K=v(rt()),le=v(Kt());return q.e=Q(V,H,q.e),q.t=Q(X,K,q.t),q.a=Q(j,le,q.a),q},{e:void 0,t:void 0,a:void 0}),G})()}Ee(["input","click","pointerdown","keydown"]);var $f=R("<div style=display:flex;gap:5px;flex-wrap:wrap>"),Sf=R("<div style=width:18px;height:18px;border-radius:50%;cursor:pointer;flex-shrink:0>");const kf=[{label:"Red",value:1,css:"#ff0000"},{label:"Purple",value:2,css:"#800080"},{label:"Blue",value:3,css:"#0000ff"},{label:"Cyan",value:4,css:"#00ffff"},{label:"Green",value:5,css:"#008000"},{label:"Yellow",value:6,css:"#ffff00"},{label:"Orange",value:7,css:"#ffa500"},{label:"Brown",value:8,css:"#a52a2a"},{label:"Grey",value:9,css:"#808080"},{label:"White",value:10,css:"#ffffff"}];function En(r){return(()=>{var e=$f();return g(e,b(xe,{each:kf,children:t=>(()=>{var n=Sf();return n.$$click=()=>r.onChange(t.value),N(i=>{var s=t.label,o=t.css,c=r.value===t.value?"0 0 0 2px #0d1117, 0 0 0 4px #c9d1d9":"none";return s!==i.e&&we(n,"title",i.e=s),o!==i.t&&Y(n,"background",i.t=o),c!==i.a&&Y(n,"box-shadow",i.a=c),i},{e:void 0,t:void 0,a:void 0}),n})()})),e})()}Ee(["click"]);var zt=R("<div>"),Rn=R("<div style=font-variant-numeric:tabular-nums>"),Cf=R("<span style=font-variant-numeric:tabular-nums;font-weight:400> / "),Tf=R('<div style="background:#21262d;border-top:1px solid #30363d;font-size:10px"><div style="padding:4px 8px;background:#161b22;color:#8b949e;font-weight:600;display:flex;justify-content:space-between"><span>Store Contents</span></div><div style="display:grid;grid-template-columns:1fr 1fr;gap:1px;background:#21262d">'),Mf=R('<div style="padding:3px 8px;background:#0d1117;color:#8b949e">'),Ef=R('<div style="padding:3px 8px;background:#0d1117;color:#c9d1d9;font-variant-numeric:tabular-nums">'),Rf=R("<div>Owner"),al=R("<div>Hits"),cl=R("<div style=font-variant-numeric:tabular-nums> / "),Pf=R("<div>Time to live"),Of=R("<div>Fatigue"),Lf=R('<div style="background:#21262d;border-top:1px solid #30363d;font-size:10px"><div style="padding:4px 8px;background:#161b22;color:#8b949e;font-weight:600">Body (<!>)</div><div style=display:flex;flex-wrap:wrap;gap:3px;padding:8px;background:#0d1117>'),Af=R("<div><div>"),If=R("<div style=width:11px;height:11px;border-radius:50%;flex-shrink:0>"),Nf=R('<div style=display:flex;gap:6px><button style="flex:1;border-radius:4px;padding:5px 8px;font-size:11px;transition:background 150ms ease, color 150ms ease, border-color 150ms ease">Apply color</button><button style="border-radius:4px;padding:5px 8px;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background 150ms ease, color 150ms ease">'),Df=R("<div style=padding:8px;display:flex;flex-direction:column;gap:8px;background:#0d1117><label>Primary color</label><label>Secondary color"),Gf=R('<label>Target room<input style="background:#010409;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:5px 6px;font-size:12px;outline:none"><span style=font-size:10px;color:#484f58>Navigate to target room, then click a tile'),zf=R("<div>Level"),Bf=R("<div>Safe modes"),Ff=R("<div>Power"),Hf=R("<div>Downgrade in"),Uf=R("<div>Safe mode active"),Wf=R("<div style=font-variant-numeric:tabular-nums> ticks"),Yf=R('<div style="padding:5px 8px;background:#0d1117;border-top:1px solid #21262d"><div style=display:flex;justify-content:space-between;font-size:10px;margin-bottom:4px><span style=color:#8b949e>RCL <!> → </span><span style=color:#c9d1d9;font-variant-numeric:tabular-nums> / <!> (<!>%)</span></div><div style=height:5px;background:#21262d;border-radius:3px;overflow:hidden><div style=height:100%;background:#58a6ff;border-radius:3px>'),Xf=R('<div style=padding:8px;display:flex;flex-direction:column;gap:6px;background:#0d1117><button style="color:#fff;border:none;border-radius:4px;padding:6px 8px;font-size:12px">Activate safe mode</button><button style="color:#fff;border:none;border-radius:4px;padding:6px 8px;font-size:12px;cursor:pointer">'),jf=R("<div><div><div>Owner</div><div>"),Vf=R("<div>Reserved"),qf=R("<div> (<!>)"),Zf=R("<div>Notify when attacked"),Kf=R("<div style=display:flex;align-items:center><button style=background:transparent;border:none;cursor:pointer;padding:0;display:flex;align-items:center>"),Jf=R("<div><div>Energy</div><div style=font-variant-numeric:tabular-nums> / "),Qf=R("<div><div>Hits</div><div style=font-variant-numeric:tabular-nums> / "),ep=R('<div style="padding:5px 8px;background:#0d1117;border-top:1px solid #21262d"><div style=display:flex;justify-content:space-between;font-size:10px;margin-bottom:4px><span style=color:#8b949e>Fill</span><span style=color:#c9d1d9;font-variant-numeric:tabular-nums> / <!> (<!>%)</span></div><div style=height:5px;background:#21262d;border-radius:3px;overflow:hidden><div style=height:100%;background:#ffe87b;border-radius:3px>'),tp=R("<div style=width:8px;height:8px;border-radius:50%;flex-shrink:0>"),ri=R('<button style="background:transparent;border:none;cursor:pointer;padding:0 2px;display:flex;align-items:center;justify-content:center;flex-shrink:0">'),rp=R('<button title="Watch memory"style="background:transparent;border:none;color:#8b949e;cursor:pointer;padding:0 2px;display:flex;align-items:center;justify-content:center;flex-shrink:0">'),np=R('<div style="border-radius:6px;margin-bottom:6px;overflow:hidden;transition:border-color 150ms ease"><div style="display:flex;align-items:center;gap:7px;padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d"><span style=font-size:11px;font-weight:600;color:#c9d1d9;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:flex;align-items:center;gap:5px></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">×'),ip=R("<span style=font-weight:400;color:#8b949e>"),sp=R('<div style="padding:3px 8px;border-top:1px solid #21262d;font-size:9px;color:#484f58;font-family:monospace;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:pointer">'),op=R("<div style=flex:1;overflow:auto;min-height:0;padding:8px>"),lp=R("<div style=color:#484f58;font-style:italic;font-size:12px>Click a tile to select objects…");const{log:Ns,error:Bt}=_t("SelectionList"),ap={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"},cp={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"},dp=new Set(["x","y","type","id","name","user","_id","room","hitsMax","energyCapacity","body","storeCapacity","storeCapacityResource"]),Ds=new Set(["hits","energy","energyCapacity","store","progress","progressTotal","nextDecayTime"]),Gs={hits:"Hits",energy:"Energy",progress:"Progress",progressTotal:"Progress total",ticksToLive:"Ticks to live",ticksToRegeneration:"Ticks to regen",ticksToDecay:"Ticks to decay",nextDecayTime:"Decays in",fatigue:"Fatigue",cooldown:"Cooldown",mineralType:"Mineral type",mineralAmount:"Mineral amount",density:"Density",notifyWhenAttacked:"Notify when attacked",isPublic:"Public",structureType:"Structure type",level:"Level",power:"Power",powerCapacity:"Power capacity",depositType:"Deposit type",lastCooldown:"Last cooldown",resourceType:"Resource type",amount:"Amount",decay:"Decay in",mode:"Mode",actionLog:"Action log",store:"Store"};function up(r){return Gs[r]?Gs[r]:r.replace(/([A-Z])/g," $1").replace(/^./,e=>e.toUpperCase()).trim()}function hp(r){return typeof r=="number"?String(r):typeof r=="string"?r:typeof r=="boolean"?r?"Yes":"No":null}function Pn(r){if(r>=1e6){const e=r/1e6;return`${parseFloat(e.toFixed(2))}M`}if(r>=1e3){const e=r/1e3;return`${parseFloat(e.toFixed(1))}K`}return String(r)}const ue=(r=!1)=>({padding:"3px 8px",background:"#0d1117",color:r?"#8b949e":"#c9d1d9",overflow:"hidden","text-overflow":"ellipsis","white-space":"nowrap"}),jr={display:"grid","grid-template-columns":"1fr 1fr",gap:"1px",background:"#21262d","font-size":"10px"};function fp(r){const e=()=>{const t=r.item.raw,n=[];for(const i in t){if(dp.has(i))continue;const s=t[i];let o=hp(s);if(!(i==="notifyWhenAttacked"&&s===!1)&&!(i==="off"&&s===!1)){if(i==="hits"&&typeof t.hitsMax=="number"&&(o=`${s} / ${t.hitsMax}`),i==="energy"&&typeof t.energyCapacity=="number"&&(o=`${s} / ${t.energyCapacity}`),i==="nextDecayTime"&&typeof s=="number"){const c=ze();c!==null&&(o=String(s-c))}o!==null&&n.push({key:i,label:up(i),value:o})}}return n.sort((i,s)=>{const o=Ds.has(i.key)?0:1,c=Ds.has(s.key)?0:1;return o-c}),n};return b(Z,{get when(){return e().length>0},get children(){var t=zt();return g(t,b(xe,{get each(){return e()},children:n=>[(()=>{var i=zt();return g(i,()=>n.label),N(s=>Q(i,ue(!0),s)),i})(),(()=>{var i=Rn();return g(i,()=>n.value),N(s=>Q(i,{...ue()},s)),i})()]})),N(n=>Q(t,jr,n)),t}})}function dl(r){const e=()=>{const n=r.store||{},i=[];for(const s in n)i.push([s,n[s]]);return i},t=()=>{const n=r.store||{};let i=0;for(const s in n)i+=n[s];return i};return b(Z,{get when(){return e().length>0},get children(){var n=Tf(),i=n.firstChild;i.firstChild;var s=i.nextSibling;return g(i,b(Z,{get when(){return r.capacity!=null},get children(){var o=Cf(),c=o.firstChild;return g(o,t,c),g(o,()=>r.capacity,null),o}}),null),g(s,b(xe,{get each(){return e()},children:([o,c])=>[(()=>{var l=Mf();return g(l,o),l})(),(()=>{var l=Ef();return g(l,c),l})()]})),n}})}const pp={tough:"#4c4c4c",move:"#a9b7c6",work:"#ffe56d",carry:"#777777",attack:"#f93842",ranged_attack:"#5d80b2",heal:"#65fd62",claim:"#b99cfb"};function gp(r){const e=()=>r.item.raw,t=()=>typeof e().user=="string"?e().user:null,n=()=>{var d,f;const u=t();return u?((f=(d=Yo())==null?void 0:d[u])==null?void 0:f.username)??u:null},i=()=>typeof e().hits=="number"?e().hits:null,s=()=>typeof e().hitsMax=="number"?e().hitsMax:null,o=()=>{const u=e().ageTime,d=ze();return typeof u=="number"&&d!==null?Math.max(0,u-d):null},c=()=>typeof e().fatigue=="number"?e().fatigue:null,l=()=>e().store,a=()=>typeof e().storeCapacity=="number"?e().storeCapacity:null,h=()=>e().body??[];return(()=>{var u=Af(),d=u.firstChild;return g(d,b(Z,{get when(){return n()},get children(){return[(()=>{var f=Rf();return N(p=>Q(f,ue(!0),p)),f})(),(()=>{var f=zt();return g(f,n),N(p=>Q(f,ue(),p)),f})()]}}),null),g(d,b(Z,{get when(){return ee(()=>i()!==null)()&&s()!==null},get children(){return[(()=>{var f=al();return N(p=>Q(f,ue(!0),p)),f})(),(()=>{var f=cl(),p=f.firstChild;return g(f,i,p),g(f,s,null),N(m=>Q(f,{...ue()},m)),f})()]}}),null),g(d,b(Z,{get when(){return o()!==null},get children(){return[(()=>{var f=Pf();return N(p=>Q(f,ue(!0),p)),f})(),(()=>{var f=Rn();return g(f,o),N(p=>Q(f,{...ue()},p)),f})()]}}),null),g(d,b(Z,{get when(){return c()!==null},get children(){return[(()=>{var f=Of();return N(p=>Q(f,ue(!0),p)),f})(),(()=>{var f=Rn();return g(f,c),N(p=>Q(f,{...ue(),color:c()>0?"#e3b341":void 0},p)),f})()]}}),null),g(u,b(dl,{get store(){return l()},get capacity(){return a()}}),null),g(u,b(Z,{get when(){return h().length>0},get children(){var f=Lf(),p=f.firstChild,m=p.firstChild,S=m.nextSibling;S.nextSibling;var O=p.nextSibling;return g(p,()=>h().length,S),g(O,b(xe,{get each(){return h()},children:z=>(()=>{var P=If();return N(k=>{var C=z.type.replace("_"," "),w=pp[z.type]??"#484f58",I=z.hits===0?.25:1;return C!==k.e&&we(P,"title",k.e=C),w!==k.t&&Y(P,"background",k.t=w),I!==k.a&&Y(P,"opacity",k.a=I),k},{e:void 0,t:void 0,a:void 0}),P})()})),f}}),null),N(f=>Q(d,jr,f)),u})()}function mp(r){const e=()=>r.item.raw,t=()=>typeof e().name=="string"?e().name:"",n=()=>typeof e().room=="string"?e().room:"",i=()=>typeof e().color=="number"?e().color:1,s=()=>typeof e().secondaryColor=="number"?e().secondaryColor:1,[o,c]=F(i()),[l,a]=F(s());fe(()=>{c(i()),a(s())});const h=()=>o()!==i()||l()!==s(),u=()=>{const S=he();if(!S)return;const O=o(),z=l();Ns(`changeFlagColor: name="${t()}" room=${n()} primary=${O} secondary=${z}`),S.http.game.changeFlagColor(n(),t(),O,z).then(()=>Ns("changeFlagColor OK")).catch(P=>Bt("changeFlagColor FAILED:",P))},d=()=>{const S=Gt();return(S==null?void 0:S.type)==="moveFlag"&&S.id===r.item.id},f=()=>{if(d()){Ar(null);return}Ar({type:"moveFlag",id:r.item.id,name:t(),room:n(),color:o(),secondaryColor:l(),targetRoom:zr()??n()})},p=()=>{const S=Gt();return(S==null?void 0:S.type)==="moveFlag"&&S.id===r.item.id?S:null},m={display:"flex","flex-direction":"column",gap:"5px","font-size":"11px",color:"#8b949e"};return(()=>{var S=Df(),O=S.firstChild;O.firstChild;var z=O.nextSibling;return z.firstChild,g(O,b(En,{get value(){return o()},onChange:c}),null),g(z,b(En,{get value(){return l()},onChange:a}),null),g(S,b(Z,{get when(){return!me()},get children(){return[(()=>{var P=Nf(),k=P.firstChild,C=k.nextSibling;return k.addEventListener("mouseleave",w=>{h()&&(w.currentTarget.style.background="#238636")}),k.addEventListener("mouseenter",w=>{h()&&(w.currentTarget.style.background="#2ea043")}),k.$$click=u,C.addEventListener("mouseleave",w=>{w.currentTarget.style.color=d()?"#c9d1d9":"#8b949e"}),C.addEventListener("mouseenter",w=>{w.currentTarget.style.color="#c9d1d9"}),C.$$click=f,g(C,(()=>{var w=ee(()=>!!d());return()=>w()?b(Ut,{size:13}):b(Gc,{size:13})})()),N(w=>{var I=!h(),y=h()?"#238636":"#161b22",$=h()?"#fff":"#484f58",L=`1px solid ${h()?"#238636":"#30363d"}`,v=h()?"pointer":"not-allowed",T=d()?"Abort move":"Move flag",E=d()?"#30363d":"#21262d",M=d()?"#c9d1d9":"#8b949e",A=`1px solid ${d()?"#8b949e":"#30363d"}`;return I!==w.e&&(k.disabled=w.e=I),y!==w.t&&Y(k,"background",w.t=y),$!==w.a&&Y(k,"color",w.a=$),L!==w.o&&Y(k,"border",w.o=L),v!==w.i&&Y(k,"cursor",w.i=v),T!==w.n&&we(C,"title",w.n=T),E!==w.s&&Y(C,"background",w.s=E),M!==w.h&&Y(C,"color",w.h=M),A!==w.r&&Y(C,"border",w.r=A),w},{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}),P})(),b(Z,{get when(){return p()},children:P=>(()=>{var k=Gf(),C=k.firstChild,w=C.nextSibling;return w.nextSibling,w.$$input=I=>Ar({...P(),targetRoom:I.currentTarget.value.toUpperCase()}),N(I=>Q(k,m,I)),N(()=>w.value=P().targetRoom),k})()})]}}),null),N(P=>{var k=m,C=m;return P.e=Q(O,k,P.e),P.t=Q(z,C,P.t),P},{e:void 0,t:void 0}),S})()}function yp(r){const e=()=>r.item.raw,t=()=>typeof e().level=="number"?e().level:0,n=()=>typeof e().progress=="number"?e().progress:null,i=()=>typeof e().progressTotal=="number"?e().progressTotal:_o[t()]??null,s=()=>typeof e().downgradeTime=="number"?e().downgradeTime:null,o=()=>typeof e().safeModeAvailable=="number"?e().safeModeAvailable:0,c=()=>typeof e().safeMode=="number"?e().safeMode:null,l=()=>e().isPowerEnabled===!0,a=()=>e().reservation,h=()=>typeof e().user=="string"?e().user:null,u=()=>{var C;const k=h();return k?((C=$n())==null?void 0:C.username)??k:null},d=()=>{const k=s(),C=ze();return k!==null&&C!==null?Math.max(0,k-C):null},f=()=>{const k=d();if(k===null)return"—";const C=$o[t()];return C!==void 0&&k>=C?"Max":String(k)},p=()=>{var k;return h()!==null&&h()===((k=Fe())==null?void 0:k._id)},[m,S]=F(!1);let O=null;const z=()=>{const k=he();k&&k.http.game.addObjectIntent(r.item.id,zr()??e().room??"","activateSafeMode",{id:r.item.id},cr()).catch(C=>Bt("activateSafeMode failed:",C))},P=()=>{if(!m()){S(!0),O=setTimeout(()=>S(!1),3e3);return}O&&(clearTimeout(O),O=null),S(!1);const k=he();k&&k.http.game.addObjectIntent(r.item.id,zr()??e().room??"","unclaim",{id:r.item.id},cr()).catch(C=>Bt("unclaim failed:",C))};return(()=>{var k=jf(),C=k.firstChild,w=C.firstChild,I=w.nextSibling;return g(I,()=>u()??"None"),g(C,b(Z,{get when(){return a()},children:y=>[(()=>{var $=Vf();return N(L=>Q($,ue(!0),L)),$})(),(()=>{var $=qf(),L=$.firstChild,v=L.nextSibling;return v.nextSibling,g($,()=>y().username,L),g($,()=>y().ticksToEnd,v),N(T=>Q($,ue(),T)),$})()]}),null),g(C,b(Z,{get when(){return t()>0},get children(){return[(()=>{var y=zf();return N($=>Q(y,ue(!0),$)),y})(),(()=>{var y=zt();return g(y,t),N($=>Q(y,ue(),$)),y})(),(()=>{var y=Bf();return N($=>Q(y,ue(!0),$)),y})(),(()=>{var y=zt();return g(y,o),N($=>Q(y,ue(),$)),y})(),(()=>{var y=Ff();return N($=>Q(y,ue(!0),$)),y})(),(()=>{var y=zt();return g(y,()=>l()?"Enabled":"Disabled"),N($=>Q(y,ue(),$)),y})(),(()=>{var y=Hf();return N($=>Q(y,ue(!0),$)),y})(),(()=>{var y=Rn();return g(y,f),N($=>Q(y,{...ue(),color:f()==="Max"?"#3fb950":void 0},$)),y})()]}}),null),g(C,b(Z,{get when(){return c()!==null},get children(){return[(()=>{var y=Uf();return N($=>Q(y,ue(!0),$)),y})(),(()=>{var y=Wf(),$=y.firstChild;return g(y,c,$),N(L=>Q(y,{...ue()},L)),y})()]}}),null),g(k,b(Z,{get when(){return ee(()=>t()>0&&t()<8&&n()!==null)()&&i()!==null},get children(){var y=Yf(),$=y.firstChild,L=$.firstChild,v=L.firstChild,T=v.nextSibling;T.nextSibling;var E=L.nextSibling,M=E.firstChild,A=M.nextSibling,D=A.nextSibling,U=D.nextSibling;U.nextSibling;var G=$.nextSibling,B=G.firstChild;return g(L,t,T),g(L,()=>t()+1,null),g(E,()=>Pn(n()),M),g(E,()=>Pn(i()),A),g(E,()=>(n()/i()*100).toFixed(1),U),N(V=>Y(B,"width",`${Math.min(100,n()/i()*100)}%`)),y}}),null),g(k,b(Z,{get when(){return ee(()=>!!p())()&&!me()},get children(){var y=Xf(),$=y.firstChild,L=$.nextSibling;return $.addEventListener("mouseleave",v=>{o()>0&&(v.currentTarget.style.background="#1f6feb")}),$.addEventListener("mouseenter",v=>{o()>0&&(v.currentTarget.style.background="#388bfd")}),$.$$click=z,L.addEventListener("mouseleave",v=>{m()||(v.currentTarget.style.background="#f85149")}),L.addEventListener("mouseenter",v=>{m()||(v.currentTarget.style.background="#da3633")}),L.$$click=P,g(L,()=>m()?"Confirm unclaim":"Unclaim"),N(v=>{var T=o()===0,E=o()>0?"#1f6feb":"#161b22",M=o()>0?"pointer":"not-allowed",A=o()>0?1:.5,D=m()?"#da3633":"#f85149";return T!==v.e&&($.disabled=v.e=T),E!==v.t&&Y($,"background",v.t=E),M!==v.a&&Y($,"cursor",v.a=M),A!==v.o&&Y($,"opacity",v.o=A),D!==v.i&&Y(L,"background",v.i=D),v},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),y}}),null),N(y=>{var $=jr,L=ue(!0),v=ue();return y.e=Q(C,$,y.e),y.t=Q(w,L,y.t),y.a=Q(I,v,y.a),y},{e:void 0,t:void 0,a:void 0}),k})()}function vp(r){const e=()=>r.item.raw,t=()=>{const h=e().store;return(h==null?void 0:h.energy)??0},n=()=>{const h=e().storeCapacityResource;return(h==null?void 0:h.energy)??0},i=()=>typeof e().hits=="number"?e().hits:null,s=()=>typeof e().hitsMax=="number"?e().hitsMax:null,o=()=>e().notifyWhenAttacked===!0,c=()=>typeof e().user=="string"?e().user:null,l=()=>{var h;return c()!==null&&c()===((h=Fe())==null?void 0:h._id)},a=()=>{const h=he();h&&h.http.game.addObjectIntent(r.item.id,e().room,"notifyWhenAttacked",{enabled:!o()}).catch(u=>Bt("notifyWhenAttacked failed:",u))};return(()=>{var h=Jf(),u=h.firstChild,d=u.nextSibling,f=d.firstChild;return g(d,t,f),g(d,n,null),g(h,b(Z,{get when(){return ee(()=>i()!==null)()&&s()!==null},get children(){return[(()=>{var p=al();return N(m=>Q(p,ue(!0),m)),p})(),(()=>{var p=cl(),m=p.firstChild;return g(p,i,m),g(p,s,null),N(S=>Q(p,{...ue()},S)),p})()]}}),null),g(h,b(Z,{get when(){return ee(()=>!!l())()&&!me()},get children(){return[(()=>{var p=Zf();return N(m=>Q(p,ue(!0),m)),p})(),(()=>{var p=Kf(),m=p.firstChild;return m.addEventListener("mouseleave",S=>{S.currentTarget.style.color=o()?"#3fb950":"#484f58"}),m.addEventListener("mouseenter",S=>{S.currentTarget.style.color=o()?"#56d364":"#8b949e"}),m.$$click=a,g(m,(()=>{var S=ee(()=>!!o());return()=>S()?b(ec,{size:12}):b(Ka,{size:12})})()),N(S=>{var O={...ue()},z=o()?"Notifications on — click to disable":"Notifications off — click to enable",P=o()?"#3fb950":"#484f58";return S.e=Q(p,O,S.e),z!==S.t&&we(m,"title",S.t=z),P!==S.a&&Y(m,"color",S.a=P),S},{e:void 0,t:void 0,a:void 0}),p})()]}}),null),N(p=>{var m=jr,S=ue(!0),O={...ue()};return p.e=Q(h,m,p.e),p.t=Q(u,S,p.t),p.a=Q(d,O,p.a),p},{e:void 0,t:void 0,a:void 0}),h})()}function Ct(r){const e=()=>r.item.raw,t=()=>typeof e().hits=="number"?e().hits:null,n=()=>typeof e().hitsMax=="number"?e().hitsMax:null,i=()=>e().store,s=()=>{if(typeof e().storeCapacity=="number")return e().storeCapacity;const l=e().storeCapacityResource;if(l){let a=0;for(const h in l)a+=l[h];return a}return null},o=()=>{const l=i();if(!l)return 0;let a=0;for(const h in l)a+=l[h];return a},c=()=>{const l=s();return!l||l===0?0:Math.min(100,o()/l*100)};return(()=>{var l=zt();return g(l,b(Z,{get when(){return ee(()=>t()!==null)()&&n()!==null},get children(){var a=Qf(),h=a.firstChild,u=h.nextSibling,d=u.firstChild;return g(u,t,d),g(u,n,null),N(f=>{var p=jr,m=ue(!0),S={...ue()};return f.e=Q(a,p,f.e),f.t=Q(h,m,f.t),f.a=Q(u,S,f.a),f},{e:void 0,t:void 0,a:void 0}),a}}),null),g(l,b(Z,{get when(){return s()!==null},get children(){var a=ep(),h=a.firstChild,u=h.firstChild,d=u.nextSibling,f=d.firstChild,p=f.nextSibling,m=p.nextSibling,S=m.nextSibling;S.nextSibling;var O=h.nextSibling,z=O.firstChild;return g(d,()=>Pn(o()),f),g(d,()=>Pn(s()),p),g(d,()=>c().toFixed(1),S),N(P=>Y(z,"width",`${c()}%`)),a}}),null),g(l,b(dl,{get store(){return i()},capacity:null}),null),l})()}const bp={creep:gp,flag:mp,controller:yp,extension:vp,storage:Ct,terminal:Ct,container:Ct,lab:Ct,factory:Ct,nuker:Ct,powerSpawn:Ct};function wp(r){const e=()=>ap[r.item.type]??"#c9d1d9",t=()=>cp[r.item.type]??r.item.type,n=()=>r.item.type==="creep",i=()=>r.item.type==="flag",s=()=>{var w;if(!n())return!1;const k=r.item.raw,C=typeof k.user=="string"?k.user:null;return C!==null&&C===((w=Fe())==null?void 0:w._id)},o=()=>{var w,I,y;if(n()||i()||r.item.type==="controller")return!1;const k=r.item.raw,C=typeof k.user=="string"?k.user:null;return C!==null?C===((w=Fe())==null?void 0:w._id):((I=$n())==null?void 0:I.userId)===((y=Fe())==null?void 0:y._id)},c=()=>bp[r.item.type]||fp,[l,a]=F(!1);let h=null;const[u,d]=F(!1);let f=null;const[p,m]=F(!1);let S=null;const O=k=>{if(k.stopPropagation(),!p()){m(!0),S=setTimeout(()=>m(!1),3e3);return}S&&(clearTimeout(S),S=null),m(!1);const C=he();if(!C)return;const w=r.item.id,I=r.item.raw;C.http.game.removeFlag(I.room,I.name).then(()=>_r(w)).catch(()=>{})},z=k=>{var $;if(k.stopPropagation(),!u()){d(!0),f=setTimeout(()=>d(!1),3e3);return}f&&(clearTimeout(f),f=null),d(!1);const C=he();if(!C)return;const w=r.item.id,I=r.item.raw,y=(typeof I.room=="string"?I.room:null)??zr()??"";if(r.item.type==="constructionSite")C.http.game.removeConstructionSite(y,[w],cr()??void 0).then(()=>_r(w)).catch(L=>Bt("removeConstructionSite failed:",L));else{const L=typeof I.user=="string"?I.user:(($=$n())==null?void 0:$.userId)??"";C.http.game.addObjectIntent("room",y,"destroyStructure",[{id:w,roomName:y,user:L}],cr()).then(()=>_r(w)).catch(v=>Bt("destroyStructure failed:",v))}},P=k=>{if(k.stopPropagation(),!l()){a(!0),h=setTimeout(()=>a(!1),3e3);return}h&&(clearTimeout(h),h=null),a(!1);const C=he();if(!C)return;const w=r.item.id;C.http.game.addObjectIntent(w,zr()??r.item.raw.room??"","suicide",{id:w},cr()).then(()=>_r(w)).catch(I=>Bt("suicide failed:",I))};return(()=>{var k=np(),C=k.firstChild,w=C.firstChild,I=w.nextSibling,y=I.firstChild,$=y.nextSibling,L=$.nextSibling,v=L.nextSibling;v.nextSibling;var T=I.nextSibling;return g(C,b(Z,{get when(){return ee(()=>!n())()&&!i()},get children(){var E=tp();return N(M=>Y(E,"background",e())),E}}),w),g(w,b(Z,{get when(){return i()},get fallback(){return ee(t)},get children(){return b(go,{size:12})}}),null),g(w,b(Z,{get when(){return ee(()=>typeof r.item.raw.name=="string")()&&r.item.raw.name},children:E=>(()=>{var M=ip();return g(M,()=>E()),M})()}),null),g(I,()=>r.item.raw.x,$),g(I,()=>r.item.raw.y,v),g(C,b(Z,{get when(){return ee(()=>!!s())()&&!me()},get children(){return[(()=>{var E=ri();return E.addEventListener("mouseleave",M=>{l()||(M.currentTarget.style.color="#8b949e")}),E.addEventListener("mouseenter",M=>{l()||(M.currentTarget.style.color="#f85149")}),E.$$click=P,g(E,b(dn,{size:13})),N(M=>{var A=l()?"Click again to confirm suicide":"Suicide",D=l()?"#f85149":"#8b949e";return A!==M.e&&we(E,"title",M.e=A),D!==M.t&&Y(E,"color",M.t=D),M},{e:void 0,t:void 0}),E})(),(()=>{var E=rp();return E.addEventListener("mouseleave",M=>M.currentTarget.style.color="#8b949e"),E.addEventListener("mouseenter",M=>M.currentTarget.style.color="#58a6ff"),E.$$click=()=>{Xh(r.item.id,r.item.raw.name),el(!0)},g(E,b(po,{size:13})),E})()]}}),T),g(C,b(Z,{get when(){return ee(()=>!!o())()&&!me()},get children(){var E=ri();return E.addEventListener("mouseleave",M=>{u()||(M.currentTarget.style.color="#8b949e")}),E.addEventListener("mouseenter",M=>{u()||(M.currentTarget.style.color="#f85149")}),E.$$click=z,g(E,b(dn,{size:13})),N(M=>{var A=u()?"Click again to confirm":r.item.type==="constructionSite"?"Remove construction site":"Destroy structure",D=u()?"#f85149":"#8b949e";return A!==M.e&&we(E,"title",M.e=A),D!==M.t&&Y(E,"color",M.t=D),M},{e:void 0,t:void 0}),E}}),T),g(C,b(Z,{get when(){return ee(()=>!!i())()&&!me()},get children(){var E=ri();return E.addEventListener("mouseleave",M=>{p()||(M.currentTarget.style.color="#8b949e")}),E.addEventListener("mouseenter",M=>{p()||(M.currentTarget.style.color="#f85149")}),E.$$click=O,g(E,b(dn,{size:13})),N(M=>{var A=p()?"Click again to confirm deletion":"Delete flag",D=p()?"#f85149":"#8b949e";return A!==M.e&&we(E,"title",M.e=A),D!==M.t&&Y(E,"color",M.t=D),M},{e:void 0,t:void 0}),E}}),T),T.addEventListener("mouseleave",E=>E.currentTarget.style.color="#8b949e"),T.addEventListener("mouseenter",E=>E.currentTarget.style.color="#fff"),T.$$click=()=>_r(r.item.id),g(k,b(Zs,{get component(){return c()},get item(){return r.item}}),null),g(k,b(Z,{get when(){return r.item.id},children:E=>(()=>{var M=sp();return M.$$click=()=>{var A;return(A=navigator.clipboard)==null?void 0:A.writeText(E())},g(M,E),N(()=>we(M,"title",E())),M})()}),null),N(E=>Y(k,"border",`1px solid ${s()&&l()||u()||p()?"#f85149":"#30363d"}`)),k})()}function xp(){return(()=>{var r=op();return g(r,b(Z,{get when(){return ur().length>0},get fallback(){return lp()},get children(){return b(xe,{get each(){return ur()},children:e=>b(wp,{item:e})})}})),r})()}Ee(["click","input"]);var _p=R('<div style="padding:3px 0;color:#8b949e">RCL'),$p=R("<span style=color:#8b949e>(<!>%)"),Sp=R('<div style="padding:3px 0;color:#c9d1d9;font-variant-numeric:tabular-nums">'),kp=R('<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><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px;color:#c9d1d9;cursor:pointer;margin-top:6px><span>Creep-Namen</span><input type=checkbox></label><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px;color:#c9d1d9;cursor:pointer;margin-top:4px><span>Room Visuals</span><input type=checkbox></label></div><div style=display:grid;gap:4px;margin-top:8px><button type=button title=History style="padding:5px 8px;border-radius:6px;display:flex;align-items:center;justify-content:center">'),Cp=R("<span>"),Tp=R('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;display:flex;align-items:center;justify-content:center">');const Mp=[{mode:"view",label:"View",icon:()=>b(po,{size:14})},{mode:"flag",label:"Flag",icon:()=>b(go,{size:14})},{mode:"build",label:"Build",icon:()=>b($c,{size:14})}];function Ep(r){return(()=>{var e=kp(),t=e.firstChild,n=t.firstChild,i=n.nextSibling,s=i.nextSibling,o=s.firstChild,c=o.nextSibling,l=c.nextSibling,a=l.nextSibling,h=a.nextSibling,u=h.nextSibling,d=u.nextSibling,f=d.nextSibling,p=f.nextSibling,m=p.nextSibling,S=s.nextSibling,O=S.firstChild,z=O.nextSibling,P=S.nextSibling,k=P.firstChild,C=k.nextSibling,w=t.nextSibling,I=w.firstChild;return g(i,()=>r.room),g(c,()=>r.shard??"—"),g(a,()=>ze()??"—"),g(u,(()=>{var y=ee(()=>!!mn());return()=>y()?`${mn()}ms`:"—"})()),g(f,()=>fh()??"—"),g(m,()=>{var y;return((y=$n())==null?void 0:y.username)??"—"}),g(s,b(Z,{get when(){return ee(()=>Ge()!==null)()&&Ge()>0},get children(){return[_p(),(()=>{var y=Sp();return g(y,b(Z,{get when(){return ee(()=>Ge()<8)()&&Cs()!==null},get fallback(){return(()=>{var $=Cp();return g($,Ge),$})()},get children(){return[ee(()=>Ge())," → ",ee(()=>Ge()+1)," ",(()=>{var $=$p(),L=$.firstChild,v=L.nextSibling;return v.nextSibling,g($,()=>(Cs()/(_o[Ge()]??1)*100).toFixed(1),v),$})()]}})),y})()]}}),null),z.addEventListener("change",y=>Lo(y.currentTarget.checked)),C.addEventListener("change",y=>th(y.currentTarget.checked)),g(w,b(Z,{get when(){return!Ye()},get children(){return b(xe,{each:Mp,children:y=>{const $=()=>!me()&&bt()===y.mode;return(()=>{var L=Tp();return L.$$click=()=>{me()&&kn(),vt(y.mode)},g(L,()=>y.icon()),N(v=>{var T=y.label,E=`1px solid ${$()?"#58a6ff":"#30363d"}`,M=$()?"#1f6feb33":"#161b22",A=$()?"#c9d1d9":"#8b949e";return T!==v.e&&we(L,"title",v.e=T),E!==v.t&&Y(L,"border",v.t=E),M!==v.a&&Y(L,"background",v.a=M),A!==v.o&&Y(L,"color",v.o=A),v},{e:void 0,t:void 0,a:void 0,o:void 0}),L})()}})}}),I),I.$$click=()=>me()?kn():ze()!==null&&Zo(ze()),g(I,b(fc,{size:14})),N(y=>{var $=`repeat(${Ye()?2:4}, 1fr)`,L=!me()&&ze()===null,v=Ye()?"span 2":void 0,T=`1px solid ${me()?"#58a6ff":"#30363d"}`,E=me()?"#1f6feb33":"#161b22",M=me()?"#c9d1d9":"#8b949e",A=!me()&&ze()===null?"not-allowed":"pointer",D=!me()&&ze()===null?.4:1;return $!==y.e&&Y(w,"grid-template-columns",y.e=$),L!==y.t&&(I.disabled=y.t=L),v!==y.a&&Y(I,"grid-column",y.a=v),T!==y.o&&Y(I,"border",y.o=T),E!==y.i&&Y(I,"background",y.i=E),M!==y.n&&Y(I,"color",y.n=M),A!==y.s&&Y(I,"cursor",y.s=A),D!==y.h&&Y(I,"opacity",y.h=D),y},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0}),N(()=>z.checked=xn()),N(()=>C.checked=Go()),e})()}Ee(["click"]);const[Rp,Pp]=F("owner"),ul="screeps-terrain-v1";async function Op(r,e,t){try{const n=await caches.open(ul),i=`/terrain/${r}_${e}_z${t}.webp`,s=new Request(i),o=await n.match(s);if(o)return await o.blob()}catch{}return null}async function Lp(r,e,t,n){try{const i=await caches.open(ul),s=`/terrain/${r}_${e}_z${t}.webp`,o=new Request(s),c=new Response(n);await i.put(o,c)}catch{}}async function Ap(r){const e=new OffscreenCanvas(r.width,r.height),t=e.getContext("2d");if(!t)throw new Error("OffscreenCanvas 2D context not available");return t.drawImage(r,0,0),await e.convertToBlob({type:"image/webp"})}async function Ip(r){return await createImageBitmap(r)}function Np(r){return new Worker("/_client/terrain.worker-D9zNeJfz.js",{name:r==null?void 0:r.name})}const{warn:Dp}=_t("MapRenderer"),hl=3,oe=hl*50,Gp=[50,60,70,80,90,100,110],Cr=1,Pt=.5,rn=50,zp=2600,Bp=5,ni=.2,ii=5,Fp=Xr,Hp=16777215,Up=Nt,Wp=Pr,Yp=bo,Xp=Mt,jp=4486980,Vp=8921634,qp=new Set(["w","r","pb","p","s","c","m","k"]),Zp={H:13421772,O:13421772,U:5809919,L:4176208,K:10711543,Z:13801762,X:16273737},Kp=[16,24,32,40];class M0{constructor(e){_(this,"app");_(this,"world");_(this,"boundsGraphics",null);_(this,"selectionGraphics",null);_(this,"safeModeGraphics",null);_(this,"safeModeRooms",new Set);_(this,"activeRooms",new Map);_(this,"roomPool",[]);_(this,"terrainBaked",new Set);_(this,"terrainData",new Map);_(this,"worker");_(this,"pendingBakes",new Map);_(this,"nextBakeId",0);_(this,"currentShard","shard0");_(this,"callbacks");_(this,"resizeObserver",null);_(this,"_destroyed",!1);_(this,"showRoomNames",!1);_(this,"worldBoundsSet",null);_(this,"lastVisibleBounds",null);_(this,"animTargetX",0);_(this,"animTargetY",0);_(this,"isAnimating",!1);_(this,"overlayMode","owner");_(this,"showUnclaimableOverlay",!0);_(this,"isDragging",!1);_(this,"hasDragged",!1);_(this,"dragStartX",0);_(this,"dragStartY",0);_(this,"dragWorldX",0);_(this,"dragWorldY",0);_(this,"isPinching",!1);_(this,"pinchPivotWorldX",0);_(this,"pinchPivotWorldY",0);_(this,"pinchStartDist",0);_(this,"pinchStartScale",0);_(this,"lastVisibleKey","");_(this,"visibleDebounceTimer",null);_(this,"selectedRoom",null);_(this,"currentUserId",null);_(this,"badgeCache",new xo);_(this,"lastCheckX",0);_(this,"lastCheckY",0);_(this,"lastCheckScale",0);this.app=new js,this.callbacks=e,this.worker=new Np,this.worker.onmessage=t=>{const{id:n,bitmap:i}=t.data,s=this.pendingBakes.get(n);s&&(this.pendingBakes.delete(n),s.resolve(i))}}async init(e){const t=e.parentElement??e,{width:n,height:i}=t.getBoundingClientRect();await this.app.init({canvas:e,width:n,height:i,background:Ud,antialias:!1,preference:"webgl"}),this.resizeObserver=new ResizeObserver(s=>{const{width:o,height:c}=s[0].contentRect,l=this.app.screen.width,a=this.app.screen.height;this.app.renderer.resize(o,c),this.world.x+=(o-l)/2,this.world.y+=(c-a)/2}),this.resizeObserver.observe(t),this.world=new Ae,this.app.stage.addChild(this.world),this.boundsGraphics=new re,this.world.addChild(this.boundsGraphics),this.selectionGraphics=new re,this.world.addChild(this.selectionGraphics),this.safeModeGraphics=new re,this.world.addChild(this.safeModeGraphics),this.setupInteraction(),this.app.ticker.add(()=>{if(this.isAnimating){const s=this.animTargetX-this.world.x,o=this.animTargetY-this.world.y;Math.abs(s)<.5&&Math.abs(o)<.5?(this.world.x=this.animTargetX,this.world.y=this.animTargetY,this.isAnimating=!1):(this.world.x+=s*.2,this.world.y+=o*.2)}this.checkVisibleRooms()})}get zoom(){var e;return((e=this.world)==null?void 0:e.scale.x)??1}setZoom(e){if(!this.world||(e=Math.max(ni,Math.min(ii,e)),e===this.world.scale.x))return;const t=this.app.screen.width/2,n=this.app.screen.height/2;this.applyZoomAt(e,t,n)}applyZoomAt(e,t,n){var h,u;const i=this.world.scale.x,s=this.getLOD(),o=this.zoom>=Cr,c=this.zoom>=Pt,l=(t-this.world.x)/i,a=(n-this.world.y)/i;this.world.scale.set(e),this.world.x=t-l*e,this.world.y=n-a*e,this.getLOD()!==s&&this.applyLOD(),(e>=Cr!==o||e>=Pt!==c)&&this.updateAllNameLabels(),this.updateAllRoomScales(e),(u=(h=this.callbacks).onZoomChanged)==null||u.call(h,e),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode()}centerOn(e,t,n=!1){const i=e*oe+oe/2,s=t*oe+oe/2,o=this.world.scale.x,c=this.app.screen.width/2-i*o,l=this.app.screen.height/2-s*o;n?(this.animTargetX=c,this.animTargetY=l,this.isAnimating=!0):(this.isAnimating=!1,this.world.x=c,this.world.y=l)}async getTerrainBitmap(e,t,n){const i=this.currentShard;try{const s=await Op(i,e,t);if(s)return await Ip(s);const o=this.nextBakeId++,c=new Promise((a,h)=>{this.pendingBakes.set(o,{roomName:e,lod:t,resolve:a,reject:h})});this.worker.postMessage({id:o,roomName:e,lod:t,raw:n});const l=await c;return Ap(l).then(a=>{Lp(i,e,t,a)}).catch(a=>Dp("failed to save to terrainCache:",a)),l}catch{return null}}async setRoomTerrain(e,t){const n=t.raw;let i=!1;for(let a=0;a<n.length;a++)if(n[a]!==0){i=!0;break}if(!i){this.terrainBaked.add(e);return}const s=this.getOrCreate(e),o=this.getLOD();o===0&&this.terrainData.set(e,n);const c=await this.getTerrainBitmap(e,o,n);if(!c)return;if(!this.activeRooms.has(e)){c.close();return}const l=Oe.from(c);o===0?(s.texLo&&!s.texLo.destroyed&&(s.terrainSprite.texture===s.texLo&&(s.terrainSprite.texture=Oe.EMPTY),s.texLo.destroy(!0)),s.texLo=l,this.getLOD()===0&&(s.terrainSprite.texture=l)):(s.texHi&&!s.texHi.destroyed&&(s.terrainSprite.texture===s.texHi&&(s.terrainSprite.texture=Oe.EMPTY),s.texHi.destroy(!0)),s.texHi=l,this.getLOD()===1&&(s.terrainSprite.texture=l)),s.terrainSprite.width=oe,s.terrainSprite.height=oe,this.terrainBaked.add(e)}getLOD(){return this.zoom<Cr?0:1}async applyLOD(){const e=this.getLOD()===1,t=[];for(const[n,i]of this.activeRooms)if(this.terrainBaked.has(n))if(e&&!i.texHi){const s=this.terrainData.get(n);s&&(this.terrainData.delete(n),t.push(this.getTerrainBitmap(n,1,s).then(o=>{o&&this.activeRooms.has(n)?(i.texHi=Oe.from(o),this.getLOD()===1&&(i.terrainSprite.texture=i.texHi)):o&&o.close()})))}else{const s=e?i.texHi:i.texLo;s&&!s.destroyed&&(i.terrainSprite.texture=s)}await Promise.all(t)}setRoomMap2(e,t,n="live"){const i=this.getOrCreate(e);i.lastMap2Data=t,i.lastMap2Source=n,this.drawMap2(i,t,n)}drawMap2(e,t,n){const i=e.map2Graphics;i.alpha=n==="cache"?.6:1;const s=hl;i.clear();const o=t.r??[];for(const[p,m]of o)i.rect(p*s,m*s,s,s);o.length&&i.fill(qi);const c=t.w??[];for(const[p,m]of c)i.rect(p*s+.5,m*s+.5,s-1,s-1);c.length&&i.fill(e.ownerState==="other"?Vp:jp);const l=t.s??[];for(const[p,m]of l)i.circle((p+.5)*s,(m+.5)*s,2.5);l.length&&i.fill(Fp);const a=t.c??[];for(const[p,m]of a)i.circle((p+.5)*s,(m+.5)*s,2);a.length&&i.fill(Hp);const h=t.m??[];for(const[p,m]of h)i.circle((p+.5)*s,(m+.5)*s,2);h.length&&i.fill(Up);const u=t.k??[];for(const[p,m]of u)i.circle((p+.5)*s,(m+.5)*s,2);u.length&&i.fill(Wp);const d=t.pb??[];for(const[p,m]of d)i.circle((p+.5)*s,(m+.5)*s,1.5);d.length&&i.fill(Pr);const f=t;for(const p in f){if(qp.has(p))continue;const m=f[p];if(!Array.isArray(m)||m.length===0)continue;for(const[O,z]of m)i.circle((O+.5)*s,(z+.5)*s,1);const S=p===this.currentUserId?Yp:Xp;i.fill(S)}}clearRoomMap2(e){var t;(t=this.activeRooms.get(e))==null||t.map2Graphics.clear()}clearAllMap2(){for(const e of this.activeRooms.values())e.map2Graphics.clear()}setRoomOwned(e,t){const n=this.activeRooms.get(e);if(!n)return;n.ownerState!==t&&(n.ownerState=t,n.lastMap2Data&&this.drawMap2(n,n.lastMap2Data,n.lastMap2Source??"live"));const i=n.ownerOverlay;i.clear(),t==="other"?(i.rect(0,0,oe,oe),i.fill({color:10027008,alpha:.18})):t==="own"&&(i.rect(0,0,oe,oe),i.fill({color:102,alpha:.35})),i.visible=this.showUnclaimableOverlay}setUnclaimableOverlayVisible(e){if(this.showUnclaimableOverlay!==e){this.showUnclaimableOverlay=e;for(const t of this.activeRooms.values())t.ownerOverlay.visible=e}}async setRoomBadge(e,t,n){const i=this.activeRooms.get(e);if(i){if(!t){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(t);if(!this.activeRooms.has(e))return;if(i.badgeSprite){if(i.badgeSprite.texture===s){i.badgeLevel=n,this.applyBadgeSize(i,this.zoom),this.applyOverlayMode(i);return}i.badgeSprite.texture=s}else{const o=new De(s);o.anchor.set(.5),o.x=oe/2,o.y=oe/2;const c=i.container.getChildIndex(i.nameLabel);i.container.addChildAt(o,c),i.badgeSprite=o}i.badgeLevel=n,this.applyBadgeSize(i,this.zoom),this.applyOverlayMode(i)}catch{}}}applyBadgeSize(e,t){if(!e.badgeSprite||e.badgeLevel===void 0)return;const i=(Gp[e.badgeLevel-1]??24)*Math.min(1,t);e.badgeSprite.width=i/t,e.badgeSprite.height=i/t}setOverlayMode(e){if(this.overlayMode!==e){this.overlayMode=e;for(const t of this.activeRooms.values())this.applyOverlayMode(t)}}setRoomMineral(e,t,n){const i=this.activeRooms.get(e);if(!i)return;if(!t||!n){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=Zp[t]??Nt;if(i.mineralDensity=n,i.mineralColor=s,!i.mineralCircle){const o=new re;o.x=oe/2,o.y=oe/2;const c=i.container.getChildIndex(i.nameLabel);i.container.addChildAt(o,c),i.mineralCircle=o}if(i.mineralLabel)i.mineralLabel.text=t;else{const o=new At({text:t,style:{fontSize:36,fill:16777215,fontFamily:"ui-monospace, monospace",fontWeight:"bold"}});o.anchor.set(.5),o.x=oe/2,o.y=oe/2,i.container.addChild(o),i.mineralLabel=o}this.applyMineralSize(i,this.zoom),this.applyOverlayMode(i)}applyOverlayMode(e){e.badgeSprite&&(e.badgeSprite.visible=this.overlayMode==="owner"),e.mineralCircle&&(e.mineralCircle.visible=this.overlayMode==="mineral"),e.mineralLabel&&(e.mineralLabel.visible=this.overlayMode==="mineral")}applyMineralSize(e,t){if(!e.mineralCircle||!e.mineralLabel||e.mineralDensity===void 0||e.mineralColor===void 0)return;const n=Math.max(.5,Math.min(1.5,t)),i=(Kp[e.mineralDensity-1]??24)*n,s=i/2/t;e.mineralCircle.clear(),e.mineralCircle.circle(0,0,1),e.mineralCircle.fill(e.mineralColor);const c=2/t;e.mineralCircle.stroke({color:0,width:c/s}),e.mineralCircle.scale.set(s);const a=i*.55/36/t;e.mineralLabel.scale.set(a)}updateNameLabelScale(e,t){const i=.3/Math.sqrt(t),s=12/(36*t);e.nameLabel.scale.set(Math.max(i,s))}updateAllRoomScales(e){for(const t of this.activeRooms.values())this.applyBadgeSize(t,e),this.updateNameLabelScale(t,e),this.applyMineralSize(t,e)}setCurrentUser(e){this.currentUserId=e}setSelectedRoom(e){if(this.selectedRoom=e,!this.selectionGraphics||(this.selectionGraphics.clear(),this.world.removeChild(this.selectionGraphics),this.world.addChild(this.selectionGraphics),!e))return;const t=lt(e);if(!t)return;const n=t.x*oe,i=t.y*oe;this.selectionGraphics.rect(n,i,oe,oe);const s=Math.max(2,Math.ceil(2/this.zoom));this.selectionGraphics.stroke({color:16777215,width:s,alignment:0})}setRoomSafeMode(e,t){t?this.safeModeRooms.add(e):this.safeModeRooms.delete(e),this.redrawSafeMode()}redrawSafeMode(){if(!this.safeModeGraphics||(this.safeModeGraphics.clear(),this.safeModeRooms.size===0))return;const e=Math.max(1,Math.ceil(1/this.zoom));for(const t of this.safeModeRooms){const n=lt(t);if(!n)continue;const i=n.x*oe,s=n.y*oe;this.safeModeGraphics.rect(i,s,oe,oe),this.safeModeGraphics.stroke({color:16776960,width:e,alignment:1,alpha:.5})}this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)}setBounds(e,t,n,i){if(!this.boundsGraphics)return;this.worldBoundsSet={minX:e,maxX:t,minY:n,maxY:i},this.boundsGraphics.clear();const s=e*oe,o=n*oe,c=(t-e+1)*oe,l=(i-n+1)*oe;this.boundsGraphics.rect(s,o,c,l),this.boundsGraphics.stroke({color:vo,width:6,alignment:0}),this.updateAllNameLabels()}clearBounds(){var e;this.worldBoundsSet=null,(e=this.boundsGraphics)==null||e.clear(),this.updateAllNameLabels()}setShowRoomNames(e){this.showRoomNames=e,this.updateAllNameLabels()}hasRoom(e){return this.terrainBaked.has(e)}markRoomFetched(e){this.terrainBaked.add(e)}clearRoom(e){const t=this.activeRooms.get(e);t&&(t.texLo&&!t.texLo.destroyed&&t.texLo.destroy(!0),t.texHi&&!t.texHi.destroyed&&t.texHi.destroy(!0),t.texLo=null,t.texHi=null,t.terrainSprite.texture=Oe.EMPTY,t.map2Graphics.clear(),t.ownerOverlay.clear(),t.badgeSprite&&(t.container.removeChild(t.badgeSprite),t.badgeSprite.destroy(),t.badgeSprite=void 0),t.mineralCircle&&(t.container.removeChild(t.mineralCircle),t.mineralCircle.destroy(),t.mineralCircle=void 0),t.mineralLabel&&(t.container.removeChild(t.mineralLabel),t.mineralLabel.destroy(),t.mineralLabel=void 0),t.mineralDensity=void 0,t.mineralColor=void 0,t.container.visible=!1,this.safeModeRooms.delete(e),this.terrainBaked.delete(e),this.terrainData.delete(e),this.activeRooms.delete(e),this.roomPool.length<zp?this.roomPool.push(t):(this.world.removeChild(t.container),t.container.destroy({children:!0,context:!0})))}clearInvisibleRooms(e){const t=this.lastVisibleBounds;for(const n of[...this.activeRooms.keys()])if(!e.has(n)){if(t){const i=lt(n);if(i&&i.x>=t.rxMin-rn&&i.x<=t.rxMax+rn&&i.y>=t.ryMin-rn&&i.y<=t.ryMax+rn)continue}this.clearRoom(n)}}destroy(){var e;if(!this._destroyed){this._destroyed=!0,(e=this.resizeObserver)==null||e.disconnect(),this.resizeObserver=null,this.visibleDebounceTimer!==null&&(clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=null);for(const[,t]of this.activeRooms)t.texLo&&!t.texLo.destroyed&&t.texLo.destroy(!0),t.texHi&&!t.texHi.destroyed&&t.texHi.destroy(!0);this.activeRooms.clear(),this.safeModeRooms.clear();for(const t of this.roomPool)t.texLo&&!t.texLo.destroyed&&t.texLo.destroy(!0),t.texHi&&!t.texHi.destroyed&&t.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(e){const t=this.activeRooms.get(e);if(t)return t;const n=lt(e);if(!n)throw new Error(`MapRenderer: invalid room "${e}"`);let i;if(this.roomPool.length>0)i=this.roomPool.pop();else{const s=new Ae;s.cullable=!0;const o=new De(Oe.EMPTY),c=new re,l=new re;s.addChild(o),s.addChild(c),s.addChild(l);const a=new At({text:"",style:{fontSize:36,fill:9147550,fontFamily:"ui-monospace, monospace"}});a.scale.set(.25),a.x=2,a.y=2,s.addChild(a),this.world.addChild(s),i={container:s,terrainSprite:o,texLo:null,texHi:null,map2Graphics:c,ownerOverlay:l,ownerState:"none",nameLabel:a}}return i.container.x=n.x*oe,i.container.y=n.y*oe,i.container.visible=!0,i.nameLabel.text=e,i.nameLabel.visible=this.showRoomNames&&this.zoom>=Pt&&this.nameLabelShouldShow(n.x,n.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(e,i),i}nameLabelShouldShow(e,t){const n=this.worldBoundsSet;return!(n&&(e<n.minX||e>n.maxX||t<n.minY||t>n.maxY))}updateAllNameLabels(){const e=this.showRoomNames&&this.zoom>=Pt;for(const[t,n]of this.activeRooms){if(!e){n.nameLabel.visible=!1;continue}const i=lt(t);i&&(n.nameLabel.visible=this.nameLabelShouldShow(i.x,i.y))}}setupInteraction(){const e=this.app.canvas;e.style.touchAction="none",e.style.userSelect="none";const t=new Map;e.addEventListener("pointermove",n=>{var i,s;if(!t.has(n.pointerId)){if(!this.isDragging&&!this.isPinching){const o=e.getBoundingClientRect();this.emitHover(n.clientX-o.left,n.clientY-o.top)}return}if(t.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.isPinching&&t.size===2){const o=[...t.values()],c=e.getBoundingClientRect(),l=(o[0].x+o[1].x)/2-c.left,a=(o[0].y+o[1].y)/2-c.top,h=Math.hypot(o[1].x-o[0].x,o[1].y-o[0].y),u=Math.max(ni,Math.min(ii,this.pinchStartScale*(h/this.pinchStartDist))),d=this.getLOD(),f=this.zoom>=Cr,p=this.zoom>=Pt;this.world.scale.set(u),this.world.x=l-this.pinchPivotWorldX*u,this.world.y=a-this.pinchPivotWorldY*u,this.getLOD()!==d&&this.applyLOD(),(u>=Cr!==f||u>=Pt!==p)&&this.updateAllNameLabels(),this.updateAllRoomScales(u),(s=(i=this.callbacks).onZoomChanged)==null||s.call(i,u),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode();return}if(this.isDragging){const o=n.clientX-this.dragStartX,c=n.clientY-this.dragStartY;(Math.abs(o)>3||Math.abs(c)>3)&&(this.hasDragged=!0);const l=this.worldBoundsSet;if(l){const a=this.world.scale.x,h=50,u=h-(l.maxX+1)*oe*a,d=this.app.screen.width-h-l.minX*oe*a,f=h-(l.maxY+1)*oe*a,p=this.app.screen.height-h-l.minY*oe*a;this.world.x=this.rubberBand(this.dragWorldX+o,u,d),this.world.y=this.rubberBand(this.dragWorldY+c,f,p)}else this.world.x=this.dragWorldX+o,this.world.y=this.dragWorldY+c}}),e.addEventListener("pointerleave",()=>{!this.isDragging&&!this.isPinching&&this.callbacks.onRoomHover(null)}),e.addEventListener("pointerdown",n=>{if(n.preventDefault(),this.isAnimating=!1,t.set(n.pointerId,{x:n.clientX,y:n.clientY}),e.setPointerCapture(n.pointerId),t.size>=2){this.isDragging=!1,this.isPinching=!0;const i=[...t.values()],s=e.getBoundingClientRect(),o=(i[0].x+i[1].x)/2-s.left,c=(i[0].y+i[1].y)/2-s.top;this.pinchStartDist=Math.hypot(i[1].x-i[0].x,i[1].y-i[0].y),this.pinchStartScale=this.world.scale.x,this.pinchPivotWorldX=(o-this.world.x)/this.pinchStartScale,this.pinchPivotWorldY=(c-this.world.y)/this.pinchStartScale}else this.isPinching=!1,this.isDragging=!0,this.hasDragged=!1,this.dragStartX=n.clientX,this.dragStartY=n.clientY,this.dragWorldX=this.world.x,this.dragWorldY=this.world.y}),e.addEventListener("pointerup",n=>{if(t.delete(n.pointerId),e.releasePointerCapture(n.pointerId),this.isPinching){t.size<2&&(this.isPinching=!1,this.isDragging=!1,this.springBack());return}if(this.isDragging){if(this.isDragging=!1,!this.hasDragged){const i=e.getBoundingClientRect(),s=this.screenToRoom(n.clientX-i.left,n.clientY-i.top);s&&this.callbacks.onRoomClick(s)}this.springBack()}}),e.addEventListener("pointercancel",n=>{t.delete(n.pointerId),e.releasePointerCapture(n.pointerId),(this.isPinching||this.isDragging)&&(this.isPinching=!1,this.isDragging=!1,this.springBack())}),e.addEventListener("wheel",n=>{if(n.preventDefault(),this.isDragging||this.isPinching)return;this.isAnimating=!1;const i=this.world.scale.x,s=n.deltaY<0?1.1:.9,o=Math.max(ni,Math.min(ii,i*s));this.applyZoomAt(o,n.offsetX,n.offsetY)},{passive:!1})}rubberBand(e,t,n){const i=n-t;if(i<=0||e>=t&&e<=n)return e;const s=.55;if(e<t){const c=t-e;return t-(1-1/(c*s/i+1))*i*s}const o=e-n;return n+(1-1/(o*s/i+1))*i*s}springBack(){const e=this.worldBoundsSet;if(!e)return;const t=this.world.scale.x,n=this.app.screen.width,i=this.app.screen.height,s=50,o=this.world.x+e.minX*oe*t,c=this.world.x+(e.maxX+1)*oe*t,l=this.world.y+e.minY*oe*t,a=this.world.y+(e.maxY+1)*oe*t;let h=this.world.x,u=this.world.y;c<s?h+=s-c:o>n-s&&(h-=o-(n-s)),a<s?u+=s-a:l>i-s&&(u-=l-(i-s)),(h!==this.world.x||u!==this.world.y)&&(this.animTargetX=h,this.animTargetY=u,this.isAnimating=!0)}screenToRoom(e,t){const n=this.world.scale.x,i=(e-this.world.x)/n,s=(t-this.world.y)/n,o=Math.floor(i/oe),c=Math.floor(s/oe);return We(o,c)}emitHover(e,t){this.callbacks.onRoomHover(this.screenToRoom(e,t))}checkVisibleRooms(){const e=this.world.scale.x,t=this.world.x,n=this.world.y;if(this.lastCheckX===t&&this.lastCheckY===n&&this.lastCheckScale===e)return;this.lastCheckX=t,this.lastCheckY=n,this.lastCheckScale=e;const i=-t/e,s=-n/e,o=(this.app.screen.width-t)/e,c=(this.app.screen.height-n)/e,l=Math.floor(i/oe)-1,a=Math.ceil(o/oe),h=Math.floor(s/oe)-1,u=Math.ceil(c/oe);this.lastVisibleBounds={rxMin:l,rxMax:a,ryMin:h,ryMax:u};const d=[],f=this.worldBoundsSet,p=f?Math.max(l,f.minX):l,m=f?Math.min(a,f.maxX):a,S=f?Math.max(h,f.minY):h,O=f?Math.min(u,f.maxY):u;for(let P=p;P<=m;P++)for(let k=S;k<=O;k++){const C=We(P,k);C&&d.push(C)}const z=`${l},${h},${a},${u}`;z!==this.lastVisibleKey&&(this.lastVisibleKey=z,this.visibleDebounceTimer!==null&&clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=setTimeout(()=>{this.visibleDebounceTimer=null,this.callbacks.onVisibleRoomsChanged(d)},Bp))}}var Jp=R('<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><span>Show room names</span><input type=checkbox></label><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px;color:#c9d1d9;cursor:pointer;margin-top:4px><span>Show unclaimable rooms</span><input type=checkbox></label></div><div style="display:grid;grid-template-columns:repeat(3, 1fr);gap:4px;margin-top:8px">'),Qp=R('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;font-size:11px;font-weight:600">');const eg=[{mode:"owner",label:"Owner"},{mode:"mineral",label:"Mineral"},{mode:"none",label:"None"}];function tg(r){const e=()=>(r.zoom??1)>=Pt;return(()=>{var t=Jp(),n=t.firstChild,i=n.firstChild,s=i.nextSibling,o=s.firstChild,c=o.nextSibling,l=c.nextSibling,a=l.nextSibling,h=s.nextSibling,u=h.firstChild,d=u.nextSibling,f=h.nextSibling,p=f.firstChild,m=p.nextSibling,S=n.nextSibling;return g(c,()=>{var O;return((O=r.zoom)==null?void 0:O.toFixed(2))??"—"}),g(a,()=>r.subsActive?"Yes":"No"),d.addEventListener("change",O=>Io(O.currentTarget.checked)),m.addEventListener("change",O=>Do(O.currentTarget.checked)),g(S,b(xe,{each:eg,children:O=>{const z=()=>Rp()===O.mode;return(()=>{var P=Qp();return P.$$click=()=>Pp(O.mode),g(P,()=>O.label),N(k=>{var C=`1px solid ${z()?"#58a6ff":"#30363d"}`,w=z()?"#1f6feb33":"#161b22",I=z()?"#c9d1d9":"#8b949e";return C!==k.e&&Y(P,"border",k.e=C),w!==k.t&&Y(P,"background",k.t=w),I!==k.a&&Y(P,"color",k.a=I),k},{e:void 0,t:void 0,a:void 0}),P})()}})),N(O=>{var z=e()?"#c9d1d9":"#484f58",P=e()?"pointer":"default",k=!e();return z!==O.e&&Y(h,"color",O.e=z),P!==O.t&&Y(h,"cursor",O.t=P),k!==O.a&&(d.disabled=O.a=k),O},{e:void 0,t:void 0,a:void 0}),N(()=>d.checked=Ao()),N(()=>m.checked=No()),t})()}Ee(["click"]);var rg=R('<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">'),ng=R('<div style="padding:6px 8px;font-size:11px;color:#484f58;font-style:italic">None'),ig=R('<div style="padding:3px 8px;color:#8b949e">Mineral'),sg=R('<div style="padding:3px 8px;color:#79c0ff">'),og=R('<div style="padding:3px 8px;color:#8b949e">Density'),lg=R('<div style="padding:3px 8px;color:#c9d1d9">'),ag=R('<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 cg=["Low","Medium","High","Ultra"];function dg(r){return cg[r-1]??String(r)}function zs(r){return(()=>{var e=rg(),t=e.firstChild;return g(t,()=>r.label),g(e,b(Z,{get when(){return r.info},get fallback(){return ng()},children:n=>(()=>{var i=ag(),s=i.firstChild,o=s.nextSibling,c=o.firstChild,l=c.nextSibling;return g(s,()=>n().room),g(l,()=>n().owner??"None"),g(o,b(Z,{get when(){return n().mineral},get children(){return[ig(),(()=>{var a=sg();return g(a,()=>n().mineral),a})(),og(),(()=>{var a=lg();return g(a,()=>dg(n().density??0)),a})()]}}),null),i})()}),null),N(n=>{var i=`1px solid ${r.dim?"#21262d":"#30363d"}`,s=r.dim?.6:1;return i!==n.e&&Y(e,"border",n.e=i),s!==n.t&&Y(e,"opacity",n.t=s),n},{e:void 0,t:void 0}),e})()}var ug=R("<span style=color:#8b949e;font-size:11px>Checking…"),hg=R('<div style=margin-top:8px><div style="padding:6px 8px;font-size:11px;font-weight:600;color:#c9d1d9;margin-bottom:6px">Your flags'),fg=R('<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>Name<input placeholder="Flag name"style="background:#010409;color:#c9d1d9;border-radius:4px;padding:5px 6px;font-size:12px;outline:none"></label><label>Primary color</label><label>Secondary color</label><div style=color:#484f58;font-size:11px;line-height:1.4>'),pg=R("<span style=color:#f85149;font-size:11px>"),gg=R("<div style=margin-top:8px;color:#484f58;font-style:italic;font-size:12px>No flags."),mg=R('<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:yg}=_t("flag"),Fi={};for(const[r,e]of Object.entries(Ur))Fi[e]=r;function vg(){const r=p=>{Ko({...rr(),...p})},[e,t]=F(null),[n,i]=F(!1);let s=null;fe(()=>{if(bt()!=="flag"||rr().name.trim()!=="")return;const p=he();p&&p.http.game.genUniqueFlagName().then(m=>{r({name:m.name}),t(null)}).catch(m=>{yg("gen unique name failed:",m)})});const o=p=>{r({name:p}),t(null),s&&clearTimeout(s);const m=p.trim();if(!m){i(!1);return}i(!0),s=setTimeout(()=>{const S=he();if(!S){i(!1);return}S.http.game.checkUniqueFlagName(m).then(()=>{t(null)}).catch(O=>{t(O.message)}).finally(()=>{i(!1)})},300)},c=()=>Ur[rr().color]??1,l=()=>Ur[rr().secondaryColor]??1,a=p=>{r({color:Fi[p]??"COLOR_WHITE"})},h=p=>{r({secondaryColor:Fi[p]??"COLOR_WHITE"})},u=()=>{const p=Da(),m=[];for(const[S,O]of Object.entries(p))O&&typeof O=="object"&&"room"in O&&"x"in O&&"y"in O&&m.push([S,O]);return m},d=p=>p===void 0||p<0||p>=sr.length?"#8b949e":`#${sr[p].toString(16).padStart(6,"0")}`,f={display:"flex","flex-direction":"column",gap:"5px","font-size":"11px",color:"#8b949e"};return(()=>{var p=fg(),m=p.firstChild,S=m.firstChild,O=S.nextSibling,z=O.firstChild,P=z.firstChild,k=P.nextSibling,C=z.nextSibling;C.firstChild;var w=C.nextSibling;w.firstChild;var I=w.nextSibling;return k.$$input=y=>o(y.currentTarget.value),g(z,b(Z,{get when(){return e()},children:y=>(()=>{var $=pg();return g($,y),$})()}),null),g(z,b(Z,{get when(){return n()},get children(){return ug()}}),null),g(C,b(En,{get value(){return c()},onChange:a}),null),g(w,b(En,{get value(){return l()},onChange:h}),null),g(I,(()=>{var y=ee(()=>!!Dt());return()=>y()?`Marked at x=${Dt().tx}, y=${Dt().ty}. Click again to create the flag, or click elsewhere to move the mark.`:"Click a position in the room to mark it."})()),g(p,b(Z,{get when(){return u().length>0},get fallback(){return gg()},get children(){var y=hg();return y.firstChild,g(y,b(xe,{get each(){return u()},children:([$,L])=>(()=>{var v=mg(),T=v.firstChild,E=T.firstChild,M=E.nextSibling,A=M.nextSibling,D=A.nextSibling,U=D.firstChild,G=U.nextSibling,B=G.nextSibling,V=B.nextSibling;return V.nextSibling,g(M,$),g(A,()=>L.room),g(D,()=>L.x,G),g(D,()=>L.y,V),N(X=>Y(E,"background",d(L.color))),v})()}),null),y}}),null),N(y=>{var $=f,L=`1px solid ${e()?"#f85149":"#30363d"}`,v=f,T=f;return y.e=Q(z,$,y.e),L!==y.t&&Y(k,"border",y.t=L),y.a=Q(C,v,y.a),y.o=Q(w,T,y.o),y},{e:void 0,t:void 0,a:void 0,o:void 0}),N(()=>k.value=rr().name),p})()}Ee(["input"]);var bg=R("<span style=color:#8b949e>…"),wg=R("<span style=color:#3fb950>✓"),xg=R("<span style=color:#f85149>✗"),_g=R("<div style=font-size:10px;color:#f85149>"),$g=R('<div style="margin-top:8px;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">Spawn name</div><div style=padding:8px;display:flex;flex-direction:column;gap:6px><div style=display:flex;gap:6px;align-items:center><input type=text style="flex:1;background:#010409;color:#c9d1d9;border-radius:4px;padding:5px 7px;font-size:12px;outline:none;transition:border-color 150ms ease"><span style=font-size:14px;flex-shrink:0;width:14px;text-align:center>'),Sg=R('<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>'),kg=R('<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 Cg(r){const e=Object.keys(Tn),[t,n]=F("idle"),[i,s]=F("");let o=null;const c=(p,m)=>{const S=Tn[p];return S?Ht()==="empty"&&p==="spawn"?Math.max(S[m]??0,1):S[m]??0:0},l=(p,m)=>{const S=c(p,m);if(S===2500)return 1/0;const O=Sn()[p]??0;return Math.max(0,S-O)},a=()=>at().structureType==="spawn";fe(wl(()=>at().structureType,(p,m)=>{if(p!=="spawn"||p===m)return;const S=he();if(!S)return;n("loading"),s("");let O=!1;Le(()=>{O=!0}),S.http.game.genUniqueObjectName("spawn",r.shard).then(z=>{O||(Lt({structureType:"spawn",structureName:z.name}),n("valid"))}).catch(()=>{O||(Lt({structureType:"spawn",structureName:"Spawn1"}),n("idle"))})}));const h=p=>{if(o&&clearTimeout(o),!p.trim()){n("invalid"),s("Name cannot be empty");return}n("loading"),s(""),o=setTimeout(()=>{const m=he();m&&m.http.game.checkUniqueObjectName("spawn",p.trim(),r.shard).then(S=>{S.error?(n("invalid"),s(S.error)):(n("valid"),s(""))}).catch(()=>{n("invalid"),s("Could not validate name")})},400)},u=p=>{Lt({structureType:"spawn",structureName:p}),h(p)},d=p=>{Lt({structureType:p,structureName:""}),n("idle"),s("")},f=()=>{switch(t()){case"loading":return bg();case"valid":return wg();case"invalid":return xg();default:return null}};return(()=>{var p=Sg(),m=p.firstChild,S=m.firstChild;S.firstChild;var O=S.nextSibling,z=m.nextSibling;z.firstChild;var P=z.nextSibling,k=P.firstChild;return g(S,()=>Ge()??"?",null),g(O,()=>{const C=Ht();return C==="empty"?"World is empty — place a spawn to claim this room.":C==="lost"?"You lost all your spawns — respawn to continue.":Ge()!=null?`RCL ${Ge()} — Select a structure type and click a tile to build.`:"No controller — roads and containers only."}),g(z,b(xe,{each:e,children:C=>{const w=()=>Ge()??0,I=()=>c(C,w()),y=()=>Sn()[C]??0,$=()=>at().structureType===C,L=()=>I()===2500,v=()=>!L()&&l(C,w())<=0;return b(Z,{get when(){return I()>0},get children(){var T=kg(),E=T.firstChild,M=E.nextSibling;return T.$$click=()=>!v()&&d(C),g(E,()=>C.replace(/([A-Z])/g," $1").trim(),null),g(E,()=>$()&&" ✓",null),g(M,(()=>{var A=ee(()=>!!L());return()=>A()?`${y()}/∞`:`${y()}/${I()}`})(),null),g(M,()=>v()&&" (Max)",null),N(A=>{var D=$()?"#1f3158":"transparent",U=v()?"default":"pointer",G=v()?.5:1;return D!==A.e&&Y(T,"background",A.e=D),U!==A.t&&Y(T,"cursor",A.t=U),G!==A.a&&Y(T,"opacity",A.a=G),A},{e:void 0,t:void 0,a:void 0}),T}})}}),null),g(p,b(Z,{get when(){return a()},get children(){var C=$g(),w=C.firstChild,I=w.nextSibling,y=I.firstChild,$=y.firstChild,L=$.nextSibling;return $.$$input=v=>u(v.currentTarget.value),g(L,f),g(I,b(Z,{get when(){return ee(()=>t()==="invalid")()&&i()},get children(){var v=_g();return g(v,i),v}}),null),N(v=>Y($,"border",`1px solid ${t()==="invalid"?"#f85149":t()==="valid"?"#238636":"#30363d"}`)),N(()=>$.value=at().structureName??""),C}}),P),g(k,()=>at().structureType?"Click a tile in the room to build.":"Select a structure type, then click a tile."),p})()}Ee(["input","click"]);var Tg=R('<div style="padding:8px;border-bottom:1px solid #30363d;flex-shrink:0"><div style=display:flex;flex-direction:column;gap:6px><div style=font-size:11px><div></div><div style=font-size:10px;color:#484f58;margin-top:2px>~</div></div><div style=display:flex;gap:3px><button type=button style="flex:1.5;padding:4px;border-radius:4px;border:1px solid #30363d;font-size:11px"></button></div><div style=display:flex;align-items:center;gap:6px><span style=font-size:10px;color:#8b949e;white-space:nowrap>Speed</span><select style="flex:1;background:#161b22;color:#8b949e;border:1px solid #30363d;border-radius:4px;padding:3px 6px;font-size:11px;cursor:pointer">'),Bs=R("<button type=button>"),Mg=R("<option>/s");const Eg=[.5,1,2,5,10,20],Rg=[{delta:-100,label:"-100"},{delta:-10,label:"-10"}],Pg=[{delta:10,label:"+10"},{delta:100,label:"+100"}];function Fs(r){return{flex:"1",padding:"4px","border-radius":"4px",border:"1px solid #30363d",background:"#161b22",color:r?"#484f58":"#8b949e",cursor:r?"not-allowed":"pointer","font-size":"11px"}}function Og(){const r=()=>{const e=Br(),t=dt(),n=mn()??3e3,i=(e-t)*n;return new Date(Date.now()-i).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})};return(()=>{var e=Tg(),t=e.firstChild,n=t.firstChild,i=n.firstChild,s=i.nextSibling;s.firstChild;var o=n.nextSibling,c=o.firstChild,l=o.nextSibling,a=l.firstChild,h=a.nextSibling;return g(i,(()=>{var u=ee(()=>!!Je());return()=>u()?"Loading…":`Tick ${dt()}`})()),g(s,r,null),g(o,b(xe,{each:Rg,children:u=>(()=>{var d=Bs();return d.$$click=()=>Es(u.delta),g(d,()=>u.label),N(f=>{var p=Je(),m=Fs(Je());return p!==f.e&&(d.disabled=f.e=p),f.t=Q(d,m,f.t),f},{e:void 0,t:void 0}),d})()}),c),st(c,"click",bh,!0),g(c,()=>Lr()?"⏸":"▶"),g(o,b(xe,{each:Pg,children:u=>(()=>{var d=Bs();return d.$$click=()=>Es(u.delta),g(d,()=>u.label),N(f=>{var p=Je(),m=Fs(Je());return p!==f.e&&(d.disabled=f.e=p),f.t=Q(d,m,f.t),f},{e:void 0,t:void 0}),d})()}),null),h.addEventListener("change",u=>wh(parseFloat(u.currentTarget.value))),g(h,b(xe,{each:Eg,children:u=>(()=>{var d=Mg(),f=d.firstChild;return d.value=u,g(d,u,f),d})()})),N(u=>{var d=Je()?"#f0883e":"#c9d1d9",f=Je(),p=Lr()?"#1a3a2a":"#161b22",m=Lr()?"#3fb950":"#8b949e",S=Je()?"not-allowed":"pointer";return d!==u.e&&Y(i,"color",u.e=d),f!==u.t&&(c.disabled=u.t=f),p!==u.a&&Y(c,"background",u.a=p),m!==u.o&&Y(c,"color",u.o=m),S!==u.i&&Y(c,"cursor",u.i=S),u},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),N(()=>h.value=es()),e})()}Ee(["click"]);var Lg=R("<div style=padding-bottom:8px;overflow:auto;min-height:0>"),Ag=R('<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'),Ig=R("<button style=background:transparent;border:none;color:#8b949e;font-size:14px;cursor:pointer;padding:4px>"),Ng=R("<button style=background:transparent;border:none;color:#8b949e;font-size:11px;cursor:pointer>Collapse");function Dg(r){return b(Z,{get when(){return bt()==="flag"},get fallback(){return b(Z,{get when(){return bt()==="build"},get fallback(){return b(xp,{})},get children(){return b(Cg,{get shard(){return r.shard}})}})},get children(){return b(vg,{})}})}function Gg(r){const e=()=>{var n;(n=r.onToggle)==null||n.call(r)},t=n=>{var i;n.stopPropagation(),(i=r.onToggle)==null||i.call(r)};return(()=>{var n=Ag(),i=n.firstChild,s=i.nextSibling,o=s.firstChild;return o.firstChild,i.$$click=e,g(i,(()=>{var c=ee(()=>!!r.onToggle);return()=>c()&&(()=>{var l=Ig();return l.$$click=t,g(l,()=>r.isCollapsed?"▶":"◀"),l})()})()),g(o,(()=>{var c=ee(()=>!!r.onToggle);return()=>c()&&(()=>{var l=Ng();return l.$$click=t,l})()})(),null),g(s,b(Z,{get when(){return r.mapMode},get fallback(){return b(Ep,{get room(){return r.room??"—"},get shard(){return r.shard??null}})},get children(){return b(tg,{get zoom(){return r.mapZoom},get subsActive(){return r.mapSubsActive}})}}),null),g(s,b(Z,{get when(){return ee(()=>!r.mapMode)()&&me()},get children(){return b(Og,{})}}),null),g(s,b(Z,{get when(){return r.mapMode},get fallback(){return b(Dg,{get shard(){return r.shard}})},get children(){var c=Lg();return g(c,b(zs,{label:"Selected",get info(){return r.selectedRoomInfo??null}}),null),g(c,b(zs,{label:"Cursor",get info(){return r.hoveredRoomInfo??null},dim:!0}),null),c}}),null),n})()}Ee(["click"]);var zg=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>CPU:</span><span style=color:#c9d1d9>"),Bg=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Memory:</span><span style=color:#c9d1d9>"),Fg=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Zoom:</span><span style=color:#c9d1d9>%"),Hg=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Subs:</span><span>"),Ug=R('<div style="display:flex;gap:16px;padding:6px 16px;font-size:12px;color:#8b949e;align-items:center">');function Wg(r){const[e,t]=F(null);Wt(()=>{const s=he();if(!s)return;const o=new Wi;o.add(s.stores.user.subscribe("cpu")),o.add(s.stores.user.on("user:cpu",c=>{t(c)})),Le(()=>{o.dispose()})});const n=()=>{var c;const s=e();if(!s)return"—";const o=((c=Fe())==null?void 0:c.cpu)??"?";return`${s.cpu.toFixed(1)} / ${o}`},i=()=>{const s=e();return s?`${(s.memory/1024).toFixed(1)} KB`:"—"};return(()=>{var s=Ug();return g(s,b(Z,{get when(){return e()!==null},get children(){return[(()=>{var o=zg(),c=o.firstChild,l=c.nextSibling;return g(l,n),o})(),(()=>{var o=Bg(),c=o.firstChild,l=c.nextSibling;return g(l,i),o})()]}}),null),g(s,b(Z,{get when(){return ee(()=>r.mapZoom!==null)()&&r.mapZoom!==void 0},get children(){return[(()=>{var o=Fg(),c=o.firstChild,l=c.nextSibling,a=l.firstChild;return g(l,()=>(r.mapZoom*100).toFixed(0),a),o})(),(()=>{var o=Hg(),c=o.firstChild,l=c.nextSibling;return g(l,()=>r.mapSubsActive===!1?"paused":"active"),N(a=>Y(l,"color",r.mapSubsActive===!1?"#e3b341":"#3fb950")),o})()]}}),null),s})()}var Yg=R('<div style=position:fixed;inset:0;background:rgba(0,0,0,0.65);z-index:200;display:flex;align-items:center;justify-content:center><div style="background:#161b22;border:1px solid #30363d;border-radius:10px;width:540px;max-height:90vh;display:flex;flex-direction:column;overflow:hidden"><div style="display:flex;align-items:center;justify-content:space-between;padding:14px 20px;border-bottom:1px solid #30363d;flex-shrink:0"><span style=font-size:15px;font-weight:600;color:#c9d1d9>Edit Badge</span><button style="background:transparent;border:none;color:#8b949e;cursor:pointer;line-height:1;padding:2px 6px"></button></div><div style=overflow:auto;flex:1;padding:20px><div style=display:flex;gap:16px;margin-bottom:20px><div style=flex-shrink:0><div style=font-size:11px;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:8px;font-weight:700>Preview</div><img width=96 height=96 style=display:block></div><div style=flex:1;min-width:0><div style=font-size:11px;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:8px;font-weight:700>Badge Design</div><div style="display:grid;grid-template-columns:repeat(6, 1fr);gap:4px"></div></div></div><div style=margin-bottom:20px><div style=font-size:11px;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:8px;font-weight:700>Colors</div><div style=display:flex;gap:6px;margin-bottom:10px></div><div style="display:grid;grid-template-columns:repeat(20, 1fr);gap:2px;margin-bottom:10px"></div><div style=display:flex;align-items:center;gap:8px><div style="width:24px;height:24px;border-radius:4px;border:1px solid rgba(255,255,255,0.2);flex-shrink:0"></div><input type=text maxlength=7 placeholder=#rrggbb style="width:90px;padding:4px 8px;border-radius:4px;background:#0d1117;color:#c9d1d9;font-size:12px;font-family:monospace;outline:none"></div></div><div style=margin-bottom:16px><div style=display:flex;align-items:baseline;gap:8px;margin-bottom:6px><span style=font-size:11px;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;font-weight:700>Variation</span><span style=font-size:12px;color:#c9d1d9></span></div><input type=range min=-100 max=100 style=width:100%;accent-color:#58a6ff></div><label style=display:flex;align-items:center;gap:8px;cursor:pointer;font-size:13px;color:#c9d1d9><input type=checkbox style=accent-color:#58a6ff;width:14px;height:14px>Rotate / Flip</label></div><div style="display:flex;justify-content:flex-end;gap:8px;padding:14px 20px;border-top:1px solid #30363d;flex-shrink:0"><button style="padding:8px 16px;border-radius:6px;border:1px solid #30363d;background:transparent;color:#8b949e;font-size:13px">Cancel</button><button style="padding:8px 16px;border-radius:6px;border:none;background:#238636;color:#fff;font-size:13px;font-weight:600">'),Xg=R("<button style=border-radius:4px;padding:3px;cursor:pointer;display:flex;align-items:center;justify-content:center><img width=48 height=48 style=display:block>"),jg=R('<button style="display:flex;align-items:center;gap:6px;padding:5px 10px;border-radius:6px;font-size:12px;cursor:pointer"><div style="width:12px;height:12px;border-radius:50%;border:1px solid rgba(255,255,255,0.2);flex-shrink:0">'),Vg=R("<button style=width:100%;aspect-ratio:1;border-radius:2px;cursor:pointer;padding:0;outline:none>");const fl={};for(let r=1;r<=24;r++){const e=On({type:r,color1:"#4a5060",color2:"#7a9ec0",color3:"#c0daf0",param:0,flip:!1});fl[r]=`data:image/svg+xml,${encodeURIComponent(e)}`}function Tt(r){var e;return typeof r=="string"?r:((e=Er[r])==null?void 0:e.rgb)??"#000000"}function nn(r){return typeof r=="number"?Math.max(0,Math.min(79,r)):r}const qg=[{slot:1,label:"Background"},{slot:2,label:"Primary"},{slot:3,label:"Secondary"}],Zg=Array.from({length:24},(r,e)=>e+1),si=/^#[0-9a-f]{6}$/i;function Kg(r){const[e,t]=F(ge(()=>typeof r.badge.type=="number"?r.badge.type:1)),[n,i]=F(ge(()=>nn(r.badge.color1))),[s,o]=F(ge(()=>nn(r.badge.color2))),[c,l]=F(ge(()=>nn(r.badge.color3))),[a,h]=F(ge(()=>r.badge.param??0)),[u,d]=F(ge(()=>r.badge.flip??!1)),[f,p]=F(1),[m,S]=F(!1),[O,z]=F(ge(()=>Tt(nn(r.badge.color1)))),P=v=>v===1?n():v===2?s():c(),k=v=>{const T=f();T===1?i(v):T===2?o(v):l(v)};fe(()=>{z(Tt(P(f())))});const C=v=>{var E;const T=P(f());return typeof T=="number"?T===v:T.toLowerCase()===(((E=Er[v])==null?void 0:E.rgb)??"").toLowerCase()},w=()=>({type:e(),color1:Tt(n()),color2:Tt(s()),color3:Tt(c()),param:a(),flip:u()}),I=Ir(()=>{const v=On(w());return`data:image/svg+xml,${encodeURIComponent(v)}`}),y=v=>{if(z(v),!si.test(v))return;const T=Er.findIndex(E=>E.rgb.toLowerCase()===v.toLowerCase());k(T>=0?T:v)},$=async()=>{var T;const v=he();if(v){S(!0);try{await v.http.user.badge(w()),await v.stores.user.refreshMe(),r.onClose(),(T=r.onSaved)==null||T.call(r),Se("Badge saved","success",3e3)}catch(E){Se(`Failed to save badge: ${E instanceof Error?E.message:String(E)}`,"error",5e3)}finally{S(!1)}}},L=v=>{v.target===v.currentTarget&&r.onClose()};return(()=>{var v=Yg(),T=v.firstChild,E=T.firstChild,M=E.firstChild,A=M.nextSibling,D=E.nextSibling,U=D.firstChild,G=U.firstChild,B=G.firstChild,V=B.nextSibling,X=G.nextSibling,j=X.firstChild,q=j.nextSibling,H=U.nextSibling,K=H.firstChild,le=K.nextSibling,ce=le.nextSibling,de=ce.nextSibling,Te=de.firstChild,te=Te.nextSibling,pe=H.nextSibling,Ie=pe.firstChild,ht=Ie.firstChild,et=ht.nextSibling,Ve=Ie.nextSibling,$t=pe.nextSibling,qe=$t.firstChild,se=D.nextSibling,ie=se.firstChild,ae=ie.nextSibling;return v.$$click=L,A.$$click=()=>r.onClose(),g(A,b(Ut,{size:18})),g(q,b(xe,{each:Zg,children:W=>(()=>{var J=Xg(),ne=J.firstChild;return J.$$click=()=>t(W),N(_e=>{var $e=e()===W?"#1f3a2a":"#0d1117",Ue=`1px solid ${e()===W?"#238636":"#21262d"}`,ft=e()===W?I():fl[W];return $e!==_e.e&&Y(J,"background",_e.e=$e),Ue!==_e.t&&Y(J,"border",_e.t=Ue),ft!==_e.a&&we(ne,"src",_e.a=ft),_e},{e:void 0,t:void 0,a:void 0}),J})()})),g(le,b(xe,{each:qg,children:({slot:W,label:J})=>(()=>{var ne=jg(),_e=ne.firstChild;return ne.$$click=()=>p(W),g(ne,J,null),N($e=>{var Ue=`1px solid ${f()===W?"#58a6ff":"#30363d"}`,ft=f()===W?"#1c2d47":"transparent",mr=f()===W?"#58a6ff":"#8b949e",yr=Tt(P(W));return Ue!==$e.e&&Y(ne,"border",$e.e=Ue),ft!==$e.t&&Y(ne,"background",$e.t=ft),mr!==$e.a&&Y(ne,"color",$e.a=mr),yr!==$e.o&&Y(_e,"background",$e.o=yr),$e},{e:void 0,t:void 0,a:void 0,o:void 0}),ne})()})),g(ce,b(xe,{each:Er,children:W=>(()=>{var J=Vg();return J.$$click=()=>k(W.index),N(ne=>{var _e=W.rgb,$e=W.rgb,Ue=C(W.index)?"2px solid #fff":"1px solid transparent";return _e!==ne.e&&we(J,"title",ne.e=_e),$e!==ne.t&&Y(J,"background",ne.t=$e),Ue!==ne.a&&Y(J,"border",ne.a=Ue),ne},{e:void 0,t:void 0,a:void 0}),J})()})),te.$$input=W=>y(W.currentTarget.value),g(et,a),Ve.$$input=W=>h(+W.currentTarget.value),qe.addEventListener("change",W=>d(W.currentTarget.checked)),ie.$$click=()=>r.onClose(),ae.$$click=$,g(ae,()=>m()?"Saving…":"Save Badge"),N(W=>{var J=I(),ne=si.test(O())?O():Tt(P(f())),_e=`1px solid ${si.test(O())?"#30363d":"#f85149"}`,$e=m(),Ue=m()?"not-allowed":"pointer",ft=m(),mr=m()?"not-allowed":"pointer",yr=m()?.7:1;return J!==W.e&&we(V,"src",W.e=J),ne!==W.t&&Y(Te,"background",W.t=ne),_e!==W.a&&Y(te,"border",W.a=_e),$e!==W.o&&(ie.disabled=W.o=$e),Ue!==W.i&&Y(ie,"cursor",W.i=Ue),ft!==W.n&&(ae.disabled=W.n=ft),mr!==W.s&&Y(ae,"cursor",W.s=mr),yr!==W.h&&Y(ae,"opacity",W.h=yr),W},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0}),N(()=>te.value=O()),N(()=>Ve.value=a()),N(()=>qe.checked=u()),v})()}Ee(["click","input"]);var Jg=R('<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">'),Qg=R("<div style=font-size:11px;color:#8b949e;margin-top:3px>"),e0=R("<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>"),t0=R('<div style="display:flex;align-items:center;justify-content:space-between;gap:24px;padding:10px 0;border-bottom:1px solid #21262d"><div style=font-size:13px;color:#c9d1d9></div><div style=font-size:12px;color:#8b949e;text-align:right>'),r0=R('<div style=display:flex;flex-direction:column;gap:4px><label style=font-size:13px;font-weight:500>Structure theme</label><select style="background:#2a2a2a;color:#eee;border:1px solid #444;border-radius:4px;padding:4px 8px;font-size:13px"><option value=vector>Vector (procedural)</option><option value=default>Default (sprites)'),n0=R("<img width=40 height=40 style=display:block>"),i0=R('<div style="display:flex;align-items:center;justify-content:space-between;padding:10px 0;border-bottom:1px solid #21262d"><div style=display:flex;align-items:center;gap:12px><span style=font-size:13px;color:#c9d1d9></span></div><button style="padding:6px 14px;border-radius:6px;border:1px solid #30363d;background:transparent;color:#c9d1d9;font-size:12px;cursor:pointer;flex-shrink:0">'),s0=R('<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>Clear all caches</div><div style=font-size:11px;color:#8b949e;margin-top:3px>Deletes IndexedDB, Cache API, and localStorage. Session is kept. Page reloads afterwards.</div></div><button style="flex-shrink:0;margin-left:24px;padding:6px 14px;border-radius:6px;border:1px solid #da3633;background:transparent;font-size:12px">'),o0=R('<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;cursor:pointer;line-height:1;padding:2px 6px"></button></div><div style="overflow:auto;flex:1;padding:20px 24px"><div style=max-width:480px>');const l0={type:1,color1:"#4a5060",color2:"#7a9ec0",color3:"#c0daf0",param:0,flip:!1};function Tr(r){return(()=>{var e=Jg(),t=e.firstChild,n=t.firstChild,i=t.nextSibling,s=i.firstChild;return g(n,()=>r.label),g(t,(()=>{var o=ee(()=>!!r.description);return()=>o()&&(()=>{var c=Qg();return g(c,()=>r.description),c})()})(),null),i.$$click=()=>r.onChange(!r.value),N(o=>{var c=r.value?"#238636":"#30363d",l=r.value?"22px":"2px";return c!==o.e&&Y(i,"background",o.e=c),l!==o.t&&Y(s,"left",o.t=l),o},{e:void 0,t:void 0}),e})()}function Jt(r){return(()=>{var e=e0(),t=e.firstChild;return g(t,()=>r.title),g(e,()=>r.children,null),e})()}function Hs(r){return(()=>{var e=t0(),t=e.firstChild,n=t.nextSibling;return g(t,()=>r.label),g(n,()=>r.value),e})()}function a0(r){var a;const e=Aa(),t=!Ye()&&!((a=Fe())!=null&&a.badge),[n,i]=F(t),[s,o]=F(!1),c=Ir(()=>{var d;const h=(d=Fe())==null?void 0:d.badge;if(!h)return null;const u=On(h);return`data:image/svg+xml,${encodeURIComponent(u)}`});async function l(){o(!0);try{await Na(),Se("All caches cleared. Reloading…","success",2e3),setTimeout(()=>window.location.reload(),1500)}catch{Se("Failed to clear caches.","error"),o(!1)}}return(()=>{var h=o0(),u=h.firstChild,d=u.firstChild,f=d.nextSibling,p=u.nextSibling,m=p.firstChild;return f.$$click=()=>r.onClose(),g(f,b(Ut,{size:18})),g(h,b(Z,{get when(){return n()},get children(){return b(Kg,{get badge(){var S;return((S=Fe())==null?void 0:S.badge)??l0},onClose:()=>i(!1),onSaved:t?()=>r.onClose():void 0})}}),p),g(m,b(Jt,{title:"Layout",get children(){return b(Tr,{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 Oo()},onChange:Qu})}}),null),g(m,b(Jt,{title:"Room View",get children(){return[b(Tr,{label:"Show creep labels",description:"Display each creep's name above its sprite.",get value(){return xn()},onChange:Lo}),b(Tr,{label:"Terrain effects",description:"Swamp glow and wall noise texture overlay.",get value(){return pn()},onChange:eh}),(()=>{var S=r0(),O=S.firstChild,z=O.nextSibling;return z.addEventListener("change",P=>rh(P.currentTarget.value)),N(()=>z.value=Ai()),S})()]}}),null),g(m,b(Jt,{title:"Map View",get children(){return[b(Tr,{label:"Show room names",description:"Render a small room name in the top-left corner of each map tile.",get value(){return Ao()},onChange:Io}),b(Tr,{label:"Show unclaimable rooms",description:"Highlight rooms where you cannot claim a controller: corridors, sector centres, rooms already owned, and restricted areas.",get value(){return No()},onChange:Do})]}}),null),g(m,b(Z,{get when(){return!Ye()},get children(){return b(Jt,{title:"Player Badge",get children(){var S=i0(),O=S.firstChild,z=O.firstChild,P=O.nextSibling;return g(O,b(Z,{get when(){return c()},get children(){var k=n0();return N(()=>we(k,"src",c())),k}}),z),g(z,()=>{var k;return((k=Fe())==null?void 0:k.username)??""}),P.$$click=()=>i(!0),g(P,()=>c()?"Edit Badge":"Create Badge"),S}})}}),null),g(m,b(Jt,{title:"Data",get children(){var S=s0(),O=S.firstChild,z=O.firstChild;z.nextSibling;var P=O.nextSibling;return P.$$click=l,g(P,()=>s()?"Clearing…":"Clear"),N(k=>{var C=s(),w=s()?"#8b949e":"#f85149",I=s()?"default":"pointer",y=s()?.6:1;return C!==k.e&&(P.disabled=k.e=C),w!==k.t&&Y(P,"color",k.t=w),I!==k.a&&Y(P,"cursor",k.a=I),y!==k.o&&Y(P,"opacity",k.o=y),k},{e:void 0,t:void 0,a:void 0,o:void 0}),S}}),null),g(m,b(Jt,{title:"About",get children(){return[b(Hs,{label:"Client version",get value(){return La()}}),ee(()=>e&&b(Hs,{label:"Mod version",get value(){return`${e.version} (${e.kind})`}}))]}}),null),h})()}Ee(["click"]);var c0=R('<button style="padding:7px;border-radius:4px;cursor:pointer;margin:0 4px;display:flex;align-items:center">'),d0=R('<button style="padding:7px;border-radius:4px;border:1px solid #30363d;background:#21262d;margin:0 2px;display:flex;align-items:center">'),u0=R("<div style=flex:1;position:relative;overflow:hidden>"),h0=R('<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>'),f0=R('<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>'),p0=R("<div style=display:flex;flex:1;overflow:hidden><div style=display:flex;flex-direction:column;flex:1;overflow:hidden>"),g0=R('<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 title=Logout style="padding:7px;border-radius:4px;border:none;background:#da3633;color:#fff;cursor:pointer;margin:0 16px 0 8px;display:flex;align-items:center">'),m0=R("<div style=display:flex;flex-direction:column;flex:1;overflow:hidden><div style=display:flex;flex:1;overflow:hidden>");const y0=Xs(()=>Ui(()=>import("./CodePanel-C-DMhyuw.js"),__vite__mapDeps([0,1,2])).then(r=>({default:r.CodePanel}))),v0=Xs(()=>Ui(()=>import("./MapViewer-CFzJVSsf.js"),__vite__mapDeps([3,1,2])).then(r=>({default:r.MapViewer})));function oi(){const r=An(),e=window.location.pathname.match(new RegExp(`^${r}/room/([A-Za-z0-9]+)`));if(!e)return{room:null,shard:null,tick:null};const t=e[1].toUpperCase();if(!lt(t))return{room:null,shard:null,tick:null};const n=new URLSearchParams(window.location.search).get("shard"),i=window.location.hash.match(/tick=(\d+)/),s=i?parseInt(i[1],10):null;return{room:t,shard:n,tick:s}}function li(r,e){return`${An()}/room/${r}${e?`?shard=${encodeURIComponent(e)}`:""}`}function Us(r){return`${An()}/map${r?`?shard=${encodeURIComponent(r)}`:""}`}function ai(){return window.location.pathname.startsWith(`${An()}/map`)?{shard:new URLSearchParams(window.location.search).get("shard")}:null}function ci(r){return(()=>{var e=c0();return e.$$click=()=>r.onClick(),g(e,()=>r.children),N(t=>{var n=r.title,i=`1px solid ${r.active?"#388bfd":"#30363d"}`,s=r.active?"#1f3158":"#21262d",o=r.active?"#58a6ff":"#c9d1d9";return n!==t.e&&we(e,"title",t.e=n),i!==t.t&&Y(e,"border",t.t=i),s!==t.a&&Y(e,"background",t.a=s),o!==t.o&&Y(e,"color",t.o=o),t},{e:void 0,t:void 0,a:void 0,o:void 0}),e})()}function Ws(r){return(()=>{var e=d0();return e.$$click=()=>r.onClick(),g(e,()=>r.children),N(t=>{var n=r.title,i=r.disabled,s=r.disabled?"#484f58":"#c9d1d9",o=r.disabled?"default":"pointer";return n!==t.e&&we(e,"title",t.e=n),i!==t.t&&(e.disabled=t.t=i),s!==t.a&&Y(e,"color",t.a=s),o!==t.o&&Y(e,"cursor",t.o=o),t},{e:void 0,t:void 0,a:void 0,o:void 0}),e})()}function b0(){var qe;const r=oi(),[e,t]=F(r.room??Gn(ve.room)??"W1N1"),[n,i]=F(r.shard??Gn(ve.shard)),[s,o]=F(ai()!==null||!r.room),[c,l]=F(!Ye()&&!((qe=Fe())!=null&&qe.badge)),[a,h]=F(!1),[u,d]=F(!1);fe(()=>{a(),d(!0),Promise.resolve().then(()=>d(!1))}),fe(()=>{Ye()&&vt("view")}),fe(()=>{var ie,ae,W;if(n()!==null||uo()!==!1)return;const se=(W=(ae=(ie=ji())==null?void 0:ie.serverData)==null?void 0:ae.shards)==null?void 0:W[0];se&&i(se)});const[f,p]=F(void 0),[m,S]=F(null),[O,z]=F(null),P=Gn(ve.mapZoom),[k,C]=F(r.room&&P?Number(P):null),[w,I]=F(null),[y,$]=F(!1),[L,v]=F(!1);let T=r.tick;fe(()=>{const se=ze();if(se===null||T===null)return;const ie=T;T=null,Zo(se),Cn(ie)}),fe(()=>{if(s())return;const se=li(e(),n());me()?history.replaceState(null,"",`${se}#tick=${dt()}`):history.replaceState(null,"",se)});const[E,M]=F(Vr(ve.sidebarWidth,300)),[A,D]=F(Vr(ve.sidebarWidth,300)),[U,G]=F(Vr(ve.consoleHeight,220)),[B,V]=F(Vr(ve.consoleHeight,220)),[X,j]=F(!1),[q,H]=F(!1),K=()=>E()<=32,le=()=>U()<=32,ce=()=>{E()>32?(D(E()),M(32)):M(A())},de=()=>{U()>32?(V(U()),G(32)):G(B())},Te=se=>{se.preventDefault(),j(!0);const ie=se.clientX,ae=E(),W=ne=>{const _e=ne.clientX-ie;M(Math.max(32,Math.min(500,ae-_e)))},J=()=>{j(!1),zn(ve.sidebarWidth,E()),window.removeEventListener("pointermove",W),window.removeEventListener("pointerup",J)};window.addEventListener("pointermove",W),window.addEventListener("pointerup",J)},te=se=>{se.preventDefault(),H(!0);const ie=se.clientY,ae=U(),W=ne=>{const _e=ne.clientY-ie;G(Math.max(32,Math.min(500,ae-_e)))},J=()=>{H(!1),zn(ve.consoleHeight,U()),window.removeEventListener("pointermove",W),window.removeEventListener("pointerup",J)};window.addEventListener("pointermove",W),window.addEventListener("pointerup",J)},pe=(se,ie)=>{var ae;(ae=he())==null||ae.stores.navigation.navigateTo(se,ie)},Ie=se=>{p(se),o(!0),history.pushState(null,"",Us(n()))},ht=()=>{s()?(o(!1),S(null),z(null),history.pushState(null,"",li(e(),n()))):Ie(e())};Wt(()=>{var W;!oi().room&&!ai()&&history.replaceState(null,"",Us(n()));const se=()=>{const J=ai();if(J){o(!0),J.shard!==null&&i(J.shard),ge(me)&&kn();return}const{room:ne,shard:_e,tick:$e}=oi();ne&&(t(ne),i(_e),o(!1),$e!==null?T=$e:ge(me)&&kn())};window.addEventListener("popstate",se),Le(()=>window.removeEventListener("popstate",se));const ie=(W=he())==null?void 0:W.stores.navigation;if(ie){const J=ie.on("navigation:change",ne=>{ne.room!==null&&(t(ne.room),i(ne.shard),o(!1),S(null),z(null),$(ie.canBack()),v(ie.canForward()),as(ve.room,ne.room),ne.shard?as(ve.shard,ne.shard):Ia(ve.shard),history.pushState(null,"",li(ne.room,ne.shard)))});Le(()=>J.dispose())}const ae=J=>{if(!Xo(J.target)){if(J.key==="o"||J.key==="O"){h(ne=>!ne),l(!1);return}(J.key==="l"||J.key==="L")&&tl(),(J.key==="c"||J.key==="C")&&rl(),(J.key==="y"||J.key==="Y")&&nl(),s()||(J.key==="1"&&vt("view"),Ye()||(J.key==="2"&&vt("flag"),J.key==="3"&&vt("build")),J.key==="m"&&Ie(e()))}};window.addEventListener("keydown",ae),Le(()=>window.removeEventListener("keydown",ae))});const et=()=>(()=>{var se=u0();return g(se,b(Z,{get when(){return c()},get children(){return b(a0,{onClose:()=>l(!1)})}}),null),g(se,b(Z,{get when(){return a()},get children(){return b(y0,{onClose:()=>h(!1)})}}),null),g(se,b(Z,{get when(){return!s()},get fallback(){return b(v0,{get shard(){return n()},get originRoom(){return f()},get initialZoom(){return k()??void 0},onNavigateToRoom:ie=>pe(ie,n()),onHoveredRoomChanged:S,onSelectedRoomChanged:z,onZoomChanged:ie=>{C(ie),zn(ve.mapZoom,ie)},onSubscriptionStateChanged:I})},get children(){return b(Nh,{get room(){return e()},get shard(){return n()},onNavigate:pe})}}),null),se})(),Ve=()=>b(Z,{get when(){return!Ye()},get children(){var se=h0(),ie=se.firstChild;return ie.$$pointerdown=te,g(se,b(_f,{get shard(){return n()},get isCollapsed(){return le()},onToggle:de}),null),N(ae=>{var W=`${U()}px`,J=q()?"none":"height 0.15s ease";return W!==ae.e&&Y(se,"height",ae.e=W),J!==ae.t&&Y(se,"transition",ae.t=J),ae},{e:void 0,t:void 0}),se}}),$t=se=>(()=>{var ie=f0(),ae=ie.firstChild;return ae.$$pointerdown=Te,g(ie,b(Gg,{get isCollapsed(){return K()},onToggle:ce,get mapMode(){return s()},get hoveredRoomInfo(){return m()},get selectedRoomInfo(){return O()},get room(){return e()},get shard(){return n()},get mapZoom(){return k()},get mapSubsActive(){return w()}}),null),N(W=>{var J=a()?"0":`${E()}px`,ne=se&&!(u()||X())?"width 0.15s ease":"none";return J!==W.e&&Y(ie,"width",W.e=J),ne!==W.t&&Y(ie,"transition",W.t=ne),W},{e:void 0,t:void 0}),ie})();return(()=>{var se=g0(),ie=se.firstChild,ae=ie.firstChild,W=ae.nextSibling;return g(ie,b(Dd,{}),ae),g(ie,b(Z,{get when(){return!Ye()||s()},get children(){return b(Wg,{get mapZoom(){return ee(()=>!!s())()?k():null},get mapSubsActive(){return ee(()=>!!s())()?w():null}})}}),ae),g(ie,b(Ws,{title:"Back",get disabled(){return!y()},onClick:()=>{var J;return(J=he())==null?void 0:J.stores.navigation.back()},get children(){return b(dc,{size:16})}}),W),g(ie,b(Ws,{title:"Forward",get disabled(){return!L()},onClick:()=>{var J;return(J=he())==null?void 0:J.stores.navigation.forward()},get children(){return b(fo,{size:16})}}),W),g(ie,b(ci,{get title(){return s()?"Room View":"Map"},get active(){return s()},onClick:ht,get children(){return ee(()=>!!s())()?b(Cc,{size:16}):b(Ic,{size:16})}}),W),g(ie,b(ci,{title:"Code Editor",get active(){return a()},onClick:()=>{h(J=>!J),l(!1)},get children(){return b(mc,{size:16})}}),W),g(ie,b(ci,{title:"Settings",get active(){return c()},onClick:()=>{l(J=>!J),h(!1)},get children(){return b(Qc,{size:16})}}),W),st(W,"click",Ha,!0),g(W,b(Oc,{size:16})),g(se,b(Z,{get when(){return Oo()},get fallback(){return(()=>{var J=m0(),ne=J.firstChild;return g(ne,et,null),g(ne,()=>$t(!0),null),g(J,Ve,null),J})()},get children(){var J=p0(),ne=J.firstChild;return g(ne,et,null),g(ne,Ve,null),g(J,()=>$t(!1),null),J}}),null),g(se,b(zh,{}),null),se})()}Ee(["click","pointerdown"]);var w0=R("<div style=width:100%;height:100%>");function x0(){const r=new URLSearchParams(window.location.search).get("guest");return r===null?null:r.startsWith("http")?r:sn(Be.url)??"https://screeps.com"}function _0(){const r=()=>It()==="connected"&&he()!==null;return Wt(async()=>{if(It()==="idle"&&(await Fa().catch(()=>{}),It()!=="connected"&&!Ln())){const e=x0();e&&Ot({url:e,auth:"guest",storage:null}).catch(()=>{})}}),(()=>{var e=w0();return g(e,(()=>{var t=ee(()=>!!r());return()=>t()?b(b0,{}):b(Ad,{})})()),e})()}const pl=document.getElementById("root");if(!pl)throw new Error("Root element not found");Nl(()=>b(_0,{}),pl);export{M0 as M,Se as a,_t as b,he as c,Ee as d,C0 as e,We as f,T0 as g,Di as h,g as i,lo as j,Ao as k,No as l,Rp as m,mh as n,Fe as o,lt as p,Y as s,R as t,nr as u,Bn as w};