screeps-client 0.5.1 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/embedded/_client/{CodePanel-DXjEDPYY.js → CodePanel-Bfbl4rrd.js} +1 -1
  2. package/dist/embedded/_client/MapViewer-Bv7oMh47.js +1 -0
  3. package/dist/embedded/_client/index-Bsvcj_u_.js +25 -0
  4. package/dist/embedded/_client/vendor-pixi-CWBnI4gg.js +1280 -0
  5. package/dist/embedded/index.html +2 -2
  6. package/dist/embedded/themes/default/test.json +23 -23
  7. package/dist/embedded/themes/default/test.png +0 -0
  8. package/dist/standalone/_client/{CodePanel-CIPkcnIz.js → CodePanel-B_hskJA-.js} +1 -1
  9. package/dist/standalone/_client/MapViewer-C4GLBatS.js +1 -0
  10. package/dist/standalone/_client/index-BlKO6rX8.js +25 -0
  11. package/dist/standalone/_client/vendor-pixi-DrpfKiIN.js +1280 -0
  12. package/dist/standalone/index.html +2 -2
  13. package/dist/standalone/themes/default/test.json +23 -23
  14. package/dist/standalone/themes/default/test.png +0 -0
  15. package/dist/xxscreeps-mod/_client/{CodePanel-DUqUzGAY.js → CodePanel-DZakAibP.js} +1 -1
  16. package/dist/xxscreeps-mod/_client/MapViewer-B6zrkNjN.js +1 -0
  17. package/dist/xxscreeps-mod/_client/index-BFLPaM4k.js +25 -0
  18. package/dist/xxscreeps-mod/_client/vendor-pixi-CerEzm_8.js +1280 -0
  19. package/dist/xxscreeps-mod/index.html +2 -2
  20. package/dist/xxscreeps-mod/themes/default/test.json +23 -23
  21. package/dist/xxscreeps-mod/themes/default/test.png +0 -0
  22. package/package.json +1 -1
  23. package/dist/embedded/_client/MapViewer-DEfylty3.js +0 -1
  24. package/dist/embedded/_client/index-iehPgM07.js +0 -24
  25. package/dist/embedded/_client/vendor-pixi-D-Qjltr2.js +0 -1215
  26. package/dist/standalone/_client/MapViewer-rS_HNnKY.js +0 -1
  27. package/dist/standalone/_client/index-Bz8cf6rc.js +0 -24
  28. package/dist/standalone/_client/vendor-pixi-CVMJwxeR.js +0 -1215
  29. package/dist/xxscreeps-mod/_client/MapViewer-CmlSeGvz.js +0 -1
  30. package/dist/xxscreeps-mod/_client/index-akQsPepe.js +0 -24
  31. package/dist/xxscreeps-mod/_client/vendor-pixi-DOKo__Ml.js +0 -1215
@@ -0,0 +1,25 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_client/CodePanel-Bfbl4rrd.js","_client/vendor-codemirror-D3PB7yT8.js","_client/vendor-pixi-CWBnI4gg.js","_client/MapViewer-Bv7oMh47.js"])))=>i.map(i=>d[i]);
2
+ var Zl=Object.defineProperty;var Kl=(r,e,t)=>e in r?Zl(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var S=(r,e,t)=>Kl(r,typeof e!="symbol"?e+"":e,t);import{k as fs,j as I,i as Xr,v as ko,w as ue,$ as Jl,u as Ge,l as z,p as ve,f as b,F as $e,S as j,h as fe,r as Be,D as Ql,a as Zt,d as ea,b as Es,m as Ti,s as tr,q as ta,o as To}from"./vendor-codemirror-D3PB7yT8.js";import{_ as ps,b as Ae,G as te,d as De,S as ze,A as Mo,P as Rr,R as Eo,a as Mi,e as Rs,N as ra,B as na,T as vt,c as Ro,C as ia}from"./vendor-pixi-CWBnI4gg.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 sa=["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"],oa=new Set(["className","value","readOnly","noValidate","formNoValidate","isMap","noModule","playsInline","adAuctionHeaders","allowFullscreen","browsingTopics","defaultChecked","defaultMuted","defaultSelected","disablePictureInPicture","disableRemotePlayback","preservesPitch","shadowRootClonable","shadowRootCustomElementRegistry","shadowRootDelegatesFocus","shadowRootSerializable","sharedStorageWritable",...sa]),la=new Set(["innerHTML","textContent","innerText","children"]),aa=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),ca=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 da(r,e){const t=ca[r];return typeof t=="object"?t[e]?t.$:void 0:t}const ua=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),ha=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"]),fa={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},re=r=>Xr(()=>r());function pa(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 Ps="_$DX_DELEGATE";function ga(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 fs(s=>{i=s,e===document?r():m(e,r(),e.firstChild?null:void 0,t)},n.owner),()=>{i(),e.textContent=""}}function R(r,e,t,n){let i;const s=()=>{if(Rt())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 Oe(r,e=window.document){const t=e[Ps]||(e[Ps]=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,$a))}}function _e(r,e,t){Rt(r)||(t==null?r.removeAttribute(e):r.setAttribute(e,t))}function ma(r,e,t,n){Rt(r)||(n==null?r.removeAttributeNS(e,t):r.setAttributeNS(e,t,n))}function ya(r,e,t){Rt(r)||(t?r.setAttribute(e,""):r.removeAttribute(e))}function va(r,e){Rt(r)||(e==null?r.removeAttribute("class"):r.className=e)}function ut(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 ba(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]||(Os(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||(Os(r,c,!0),t[c]=l)}return t}function J(r,e,t){if(!e)return t?_e(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 Po(r,e={},t,n){const i={};return n||I(()=>i.children=jr(r,e.children,i.children)),I(()=>typeof e.ref=="function"&&pr(e.ref,r)),I(()=>wa(r,e,t,!0,i,!0)),i}function pr(r,e,t){return ue(()=>r(e,t))}function m(r,e,t,n){if(t!==void 0&&!n&&(n=[]),typeof e!="function")return jr(r,e,n,t);I(i=>jr(r,e(),i,t),n)}function wa(r,e,t,n,i={},s=!1){e||(e={});for(const o in i)if(!(o in e)){if(o==="children")continue;i[o]=Ls(r,o,null,i[o],t,s,e)}for(const o in e){if(o==="children")continue;const c=e[o];i[o]=Ls(r,o,c,i[o],t,s,e)}}function xa(r){let e,t,n=Rt();if(!n||!(e=Ge.registry.get(t=Sa()))){if(n)throw Ge.done=!0,new Error(`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${t}
3
+ `);return r()}return Ge.completed&&Ge.completed.add(e),Ge.registry.delete(t),e}function Rt(r){return!!Ge.context&&!Ge.done&&(!r||r.isConnected)}function _a(r){return r.toLowerCase().replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function Os(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 Ls(r,e,t,n,i,s,o){let c,l,a,h,u;if(e==="style")return J(r,t,n);if(e==="classList")return ba(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=ua.has(d);if(!f&&n){const p=Array.isArray(n)?n[0]:n;r.removeEventListener(d,p)}(f||t)&&(ut(r,d,t,f),f&&Oe([d]))}else if(e.slice(0,5)==="attr:")_e(r,e.slice(5),t);else if(e.slice(0,5)==="bool:")ya(r,e.slice(5),t);else if((u=e.slice(0,5)==="prop:")||(a=la.has(e))||!i&&((h=da(e,r.tagName))||(l=oa.has(e)))||(c=r.nodeName.includes("-")||"is"in o)){if(u)e=e.slice(5),l=!0;else if(Rt(r))return t;e==="class"||e==="className"?va(r,t):c&&!l&&!a?r[_a(e)]=t:r[h||e]=t}else{const d=i&&e.indexOf(":")>-1&&fa[e.split(":")[0]];d?ma(r,d,e,t):_e(r,aa[e]||e,t)}return t}function $a(r){if(Ge.registry&&Ge.events&&Ge.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}}),Ge.registry&&!Ge.done&&(Ge.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 jr(r,e,t,n,i){const s=Rt(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=rr(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=rr(r,t,n)}else{if(o==="function")return I(()=>{let l=e();for(;typeof l=="function";)l=l();t=jr(r,l,t,n)}),()=>t;if(Array.isArray(e)){const l=[],a=t&&Array.isArray(t);if(Ei(l,e,t,i))return I(()=>t=jr(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=rr(r,t,n),c)return t}else a?t.length===0?As(r,l,n):pa(r,t,l):(t&&rr(r),As(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=rr(r,t,n,e);rr(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 Ei(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=Ei(r,c,l)||i;else if(a==="function")if(n){for(;typeof c=="function";)c=c();i=Ei(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 As(r,e,t=null){for(let n=0,i=e.length;n<i;n++)r.insertBefore(e[n],t)}function rr(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 Sa(){return Ge.getNextContextId()}const Ca="http://www.w3.org/2000/svg";function ka(r,e=!1,t=void 0){return e?document.createElementNS(Ca,r):document.createElement(r,{is:t})}function Ta(r,e){const t=Xr(r);return Xr(()=>{const n=t();switch(typeof n){case"function":return Object.assign(n,{[Jl]:!0}),ue(()=>n(e));case"string":const i=ha.has(n),s=Ge.context?xa():ka(n,i,ue(()=>e.is));return Po(s,e,i),s}})}function Oo(r){const[,e]=ko(r,["component"]);return Ta(()=>r.component,e)}async function Lo(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 Ao(r){return Lo(r,"gzip")}function Io(r){return Lo(r,"deflate")}const Ma=Object.freeze(Object.defineProperty({__proto__:null,decompressGzip:Ao,decompressZlib:Io},Symbol.toStringTag,{value:"Module"}));class pt{constructor(e){S(this,"fn");this.fn=e}static create(e){return e===!0?new pt(console.debug.bind(console)):typeof e=="function"?new pt(e):new pt(null)}child(e){if(!this.fn)return this;const t=this.fn;return new pt((...n)=>t(`[screeps:${e}]`,...n))}log(...e){var t;(t=this.fn)==null||t.call(this,...e)}}function Ea(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 Ra(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 Re(r,e){return e&&(r.shard=e),r}function Pa(r,e){return{roomTerrain:(t,n)=>r.request("GET","/api/game/room-terrain",Re({room:t,encoded:1},n)),roomObjects:(t,n)=>r.request("GET","/api/game/room-objects",Re({room:t},n)),roomDecorations:e?()=>Promise.resolve(e):(t,n)=>r.request("GET","/api/game/room-decorations",Re({room:t},n)),roomStatus:(t,n)=>r.request("GET","/api/game/room-status",Re({room:t},n)),roomOverview:(t,n=8,i)=>r.request("GET","/api/game/room-overview",Re({room:t,interval:n},i)),time:t=>r.request("GET","/api/game/time",Re({},t)),worldSize:t=>r.request("GET","/api/game/world-size",Re({},t)),mapStats:(t,n,i)=>r.request("POST","/api/game/map-stats",Re({rooms:t,statName:n},i)),roomsTerrain:(t,n)=>{const i=new URLSearchParams({encoded:"true"});return n&&i.set("shard",n),r.request("POST",`/api/game/rooms?${i}`,{rooms:t})},createFlag:(t,n,i,s,o,c,l)=>r.request("POST","/api/game/create-flag",Re({room:t,x:n,y:i,name:s,color:o,secondaryColor:c},l)),genUniqueFlagName:()=>r.request("POST","/api/game/gen-unique-flag-name"),checkUniqueFlagName:t=>r.request("POST","/api/game/check-unique-flag-name",{name:t}),changeFlagColor:(t,n,i,s)=>r.request("POST","/api/game/change-flag-color",{room:t,name:n,color:i,secondaryColor:s}),removeFlag:(t,n)=>r.request("POST","/api/game/remove-flag",{room:t,name:n}),genUniqueObjectName:(t,n)=>r.request("POST","/api/game/gen-unique-object-name",Re({type:t},n)),checkUniqueObjectName:(t,n,i)=>r.request("POST","/api/game/check-unique-object-name",Re({type:t,name:n},i)),placeSpawn:(t,n,i,s,o)=>r.request("POST","/api/game/place-spawn",Re({room:t,x:n,y:i,...s?{name:s}:{}},o)),createConstruction:(t,n,i,s,o,c)=>r.request("POST","/api/game/create-construction",Re({room:t,x:n,y:i,structureType:s,...o?{name:o}:{}},c)),removeConstructionSite:(t,n,i)=>r.request("POST","/api/game/add-object-intent",Re({_id:"room",room:t,name:"removeConstructionSite",intent:n.map(s=>({id:s,roomName:t}))},i)),addObjectIntent:(t,n,i,s,o)=>r.request("POST","/api/game/add-object-intent",Re({_id:t,room:n,name:i,intent:s},o)),addGlobalIntent:(t,n)=>r.request("POST","/api/game/add-global-intent",{name:t,intent:n}),roomHistory:(t,n,i)=>i?r.request("GET",`/room-history/${encodeURIComponent(i)}/${encodeURIComponent(t)}/${n}.json`):r.request("GET","/room-history",{room:t,time:n}),setNotifyWhenAttacked:(t,n)=>r.request("POST","/api/game/set-notify-when-attacked",{_id:t,enabled:n}),createInvader:(t,n,i,s,o,c)=>r.request("POST","/api/game/create-invader",{room:t,x:n,y:i,size:s,type:o,...c!=null?{boosted:c}:{}}),removeInvader:t=>r.request("POST","/api/game/remove-invader",{_id:t}),tick:()=>r.request("GET","/api/game/tick"),powerCreeps:Ra(r),market:{ordersIndex:t=>r.request("GET","/api/game/market/orders-index",Re({},t)),myOrders:()=>r.request("GET","/api/game/market/my-orders"),orders:(t,n)=>r.request("GET","/api/game/market/orders",Re({resourceType:t},n)),stats:(t,n)=>r.request("GET","/api/game/market/stats",Re({resourceType:t},n))},shards:{info:()=>r.request("GET","/api/game/shards/info")}}}function Oa(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 nr(r,e){return e&&(r.shard=e),r}function La(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",nr({path:e},t)),set:(e,t,n)=>r.request("POST","/api/user/memory",nr({path:e,value:t},n)),segment:{get:(e,t)=>r.request("GET","/api/user/memory-segment",nr({segment:e},t)),set:(e,t,n)=>r.request("POST","/api/user/memory-segment",nr({segment:e,data:t},n))}},console:(e,t)=>r.request("POST","/api/user/console",nr({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",nr({},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:Oa(r)}}function Aa(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 Ia(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 Da extends EventTarget{constructor(t){super();S(this,"baseUrl");S(this,"authStrategy");S(this,"logger");S(this,"serverPassword");S(this,"token",null);S(this,"rateLimits",new Map);S(this,"authenticating",!1);S(this,"auth");S(this,"register");S(this,"game");S(this,"user");S(this,"leaderboard");S(this,"experimental");this.baseUrl=t.url.endsWith("/")?t.url:`${t.url}/`,this.authStrategy=t.auth,this.logger=t.logger??pt.create(),this.serverPassword=t.serverPassword??null,this.auth=Ea(this),this.register=Na(this),this.game=Pa(this,t.decorationsMock),this.user=La(this),this.leaderboard=Aa(this),this.experimental=Ia(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 Ao(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 Ga(r){let e=typeof r=="string"?r:r.data;if(e.startsWith("gz:")&&(e=JSON.stringify(await Io(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 Fa{constructor(e){S(this,"wsUrl");S(this,"WS");S(this,"logger");S(this,"ws",null);S(this,"token",null);S(this,"authed",!1);S(this,"_connected",!1);S(this,"reconnecting",!1);S(this,"authSub",null);S(this,"queue",[]);S(this,"subs",new Map);S(this,"listeners",new Map);S(this,"MAX_RETRIES",10);S(this,"MAX_DELAY_MS",6e4);S(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??pt.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 Ga(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 za{constructor(e,t){S(this,"memory",new Map);S(this,"storage");S(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 kr extends EventTarget{constructor(t){super();S(this,"logger");this.logger=t??pt.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 gr{constructor(e){S(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 gr(t)}get(e,t){return this.raw[t*50+e]}}class Ba extends kr{constructor(t,n,i,s){super(s);S(this,"http");S(this,"socket");S(this,"cache");S(this,"roomObjects",new Map);S(this,"roomUsers",new Map);S(this,"roomSubCount",new Map);S(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),g=parseInt(u,10),w=parseInt(d,10);isNaN(f)||isNaN(p)||isNaN(g)||isNaN(w)||i.push({_id:l,type:"flag",room:n,name:l,x:g,y:w,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 gr(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=gr.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 gr(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=gr.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[w,L]of Object.entries(d.objects))L===null?delete f[w]:f[w]?f[w]={...f[w],...L}:f[w]=L;const p={...d.objects??{}};if("flags"in d){const w=d.flags??"",L=this.lastFlagsString.get(i)??"";if(w!==L){this.lastFlagsString.set(i,w);const A=this.parseFlagsString(w,t),N=new Map;for(const M of A)N.set(M.name,M);for(const M in f){const y=f[M];(y==null?void 0:y.type)==="flag"&&!N.has(M)&&(delete f[M],p[M]=null,this.logger.log(`[flag:room] removed ${M} @ ${t}`))}for(const[M,y]of N){const x=f[M];(!x||x.x!==y.x||x.y!==y.y||x.color!==y.color||x.secondaryColor!==y.secondaryColor)&&(f[M]=y,p[M]=y,this.logger.log(`[flag:room] ${x?"changed":"added"} ${M} @ ${t} (${y.x},${y.y})`))}}}if(d.users){const w=this.roomUsers.get(i)??{};this.roomUsers.set(i,{...w,...d.users})}this.roomObjects.set(i,f);const g=this.roomUsers.get(i);this.emit("room:update",{room:t,shard:n,gameTime:d.gameTime,objects:f,diff:p,visual:d.visual??"",users:g})});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 Wa extends kr{constructor(t,n,i,s,o=100){super(s);S(this,"http");S(this,"socket");S(this,"cache");S(this,"console",[]);S(this,"maxConsoleSize");S(this,"_cpu",null);S(this,"_userInfo",null);S(this,"_userId",null);S(this,"_worldStatus",null);S(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 ps(async()=>{const{decompressZlib:g}=await Promise.resolve().then(()=>Ma);return{decompressZlib:g}},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()}}}subscribeMapVisual(t){this.logger.log("subscribe mapVisual",t);let n=null,i=null,s=!1;return(async()=>{try{const c=this._userId??(await this.me())._id;if(s)return;const l=t?`mapVisual:${c}/${t}`:`mapVisual:${c}`;n=this.socket.subscribe(l),i=this.socket.on(l,a=>{this.emit("user:mapVisual",{shard:t,data:typeof a=="string"?a:""})})}catch(c){s||this.dispatchEvent(new ErrorEvent("error",{error:c instanceof Error?c:new Error(String(c))}))}})(),{dispose:()=>{this.logger.log("unsubscribe mapVisual",t),s=!0,n==null||n.dispose(),i==null||i.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",g=f.x??"?",w=f.y??"?";this.logger.log(`[flag:user] ${u} @ ${p} (${g},${w})`)}}}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 Ha extends kr{constructor(t,n,i,s){super(s);S(this,"http");S(this,"cache");S(this,"socketSubs",[]);S(this,"_version",null);S(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 w=(await this.http.request("POST","/api/game/map-stats",{rooms:["W0N0","E0N0","W0S0","E0S0"],statName:"owner0",...o})).stats??{},L=["W0N0","E0N0","W0S0","E0S0"].filter(A=>A in w);this.logger.log(`worldInfo corner probe — found: [${L.length?L.join(", "):"none"}]`),("E0N0"in w||"E0S0"in w)&&(h=-Math.ceil(l/2),u=Math.floor(l/2)-1),("W0S0"in w||"E0S0"in w)&&(d=-Math.ceil(a/2),f=Math.floor(a/2)-1)}catch(g){this.logger.log("worldInfo corner probe failed — keeping W/N defaults:",g)}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){S(this,"memory",new Map);S(this,"adapter");S(this,"maxEntries");S(this,"namespace");S(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 Is(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 Va extends kr{constructor(t,n,i={},s){super(s);S(this,"socket");S(this,"storage");S(this,"maxSubscriptions");S(this,"active",new Map);S(this,"waitlist",[]);S(this,"keyStates",new Map);S(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?Is(l):null};a.listenerSub=this.socket.on(o,h=>{const u=h,d=Is(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 Ya extends kr{constructor(t,n=100,i=500,s){super(s);S(this,"http");S(this,"debounceMs");S(this,"minIntervalMs");S(this,"pending",new Map);S(this,"timer",null);S(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 Xa extends kr{constructor(t=50,n){super(n);S(this,"_history",[]);S(this,"_index",-1);S(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 ja{constructor(e){S(this,"http");S(this,"socket");S(this,"stores");S(this,"cache");S(this,"logger");S(this,"tokenRefreshIntervalMs");S(this,"tokenSyncSubs",[]);S(this,"tokenRefreshTimer",null);S(this,"lastHttpActivity",0);S(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=pt.create(e.debug),this.logger.log(`[screeps:client] init ${e.url}`),this.cache=new za(t,e.storage??null),this.http=new Da({url:e.url,auth:e.auth,logger:this.logger.child("http"),serverPassword:e.serverPassword,decorationsMock:e.decorationsMock}),this.socket=new Fa({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 Ba(this.http,this.socket,this.cache,this.logger.child("room")),user:new Wa(this.http,this.socket,this.cache,this.logger.child("user")),server:new Ha(this.http,this.socket,this.cache,this.logger.child("server")),map:new Va(this.socket,n,{maxSubscriptions:((s=e.map2)==null?void 0:s.maxSubscriptions)??500},this.logger.child("map")),mapStats:new Ya(this.http,100,500,this.logger.child("mapStats")),navigation:new Xa(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 qa{constructor(e){S(this,"token");this.token=e.token}async authenticate(e){return this.token}}class Za{constructor(e){S(this,"email");S(this,"password");this.email=e.email,this.password=e.password}async authenticate(e){return(await e.auth.signin(this.email,this.password)).token}}class Ka{async authenticate(e){return"guest"}}const Ja=1,ot="data";class Qa{constructor(e){S(this,"namespace");S(this,"db",null);S(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,Ja);n.onupgradeneeded=()=>{n.result.createObjectStore(ot)},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(ot,"readonly").objectStore(ot).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(ot,"readwrite").objectStore(ot).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(ot,"readwrite").objectStore(ot).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(ot,"readwrite").objectStore(ot).clear();s.onsuccess=()=>t(),s.onerror=()=>n(s.error)})}}class gs{constructor(){S(this,"subs",[])}add(e){this.subs.push(e)}dispose(){for(const e of this.subs)e.dispose();this.subs.length=0}}const ec=5*6e4;function No(r,e){try{return`screeps:${r}:${new URL(e).hostname}`}catch{return`screeps:${r}:${e}`}}function Do(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 Go(r,e){if(!(typeof sessionStorage>"u"))try{sessionStorage.setItem(r,JSON.stringify({data:e,expires:Date.now()+ec}))}catch{}}function sn(r){return r.endsWith("/")?r:`${r}/`}async function tc(r){const e=No("version",r),t=Do(e);if(t)return t;const n=await fetch(`${sn(r)}api/version`);if(!n.ok)throw new Error(`HTTP ${n.status}`);const i=await n.json();return Go(e,i),i}async function rc(r){const e=No("authmod",r),t=Do(e);if(t)return t;const n=await fetch(`${sn(r)}api/authmod`);if(!n.ok)return null;const i=await n.json();return i.ok?(Go(e,i),i):null}async function nc(r,e){const t=new URLSearchParams({username:e}),n=await fetch(`${sn(r)}api/register/check-username?${t}`);if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json()}async function ic(r,e){const t=new URLSearchParams({email:e}),n=await fetch(`${sn(r)}api/register/check-email?${t}`);if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json()}async function sc(r,e,t,n){const i=await fetch(`${sn(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 oc(r,e){return r.serverData.features.find(t=>t.name===e)}function Fo(r){return oc(r,"screepsmod-auth")}const lc={ok:1,decorations:[{_id:"5fd719f496a97dbdd2f57bea",user:"58356f6fc8012784246abb7e",active:{strokeWidth:"30",foregroundColor:"#6A88FF",foregroundAlpha:1,backgroundColor:"#5261A0",backgroundBrightness:"1",strokeColor:"#465EC4",strokeBrightness:"1",strokeLighting:"1",foregroundBrightness:"1",world:!0,tileScale:1,shard:"shard1",room:"E2S49"},decoration:{_id:"5eea71d952fdab816c74e50c",graphics:[],description:"звездочки",rarityMultiplier:1,type:"wallLandscape",foregroundUrl:"https://s3.amazonaws.com/static.screeps.com/decorations/0e53bc662a2688275b9c6766cf946031b19bf0b.png",theme:"5e908ece62339b0045ac2d0e",rarity:4,name:"W-00031:WI:X",group:"5edf121e1f95b4047880e2ef",steamItemDefId:4415,enabled:!0,groupDescription:"Controllable brightness.",preview:{original:"https://s3.amazonaws.com/static.screeps.com/decorations/6c5533fd1f83ecadb8cf105fdda95fa4687114b.png","128x128":"https://s3.amazonaws.com/static.screeps.com/decorations/919410fbd3c74c697d7396ba0636b2d33ca3fa5.png","256x256":"https://s3.amazonaws.com/static.screeps.com/decorations/16f3453e69387abfe110050532d9e7c67e8fc41.png"}}},{_id:"60086a96a6ad8c744554e05c",user:"58356f6fc8012784246abb7e",active:{floorBackgroundColor:"#F67BFF",floorBackgroundBrightness:.98,floorForegroundColor:"#F67BFF",floorForegroundAlpha:.87,swampColor:"#4073A3",swampStrokeColor:"#CC7DD2",swampStrokeWidth:30,roadsColor:"#E9A7EE",roadsBrightness:.41,tileScale:1,floorForegroundBrightness:.42,world:!0,shard:"shard1",room:"E2S49"},decoration:{_id:"5eea668452fdab5ea674e1ca",graphics:[],description:"калейдоскоп",rarityMultiplier:1,type:"floorLandscape",floorForegroundUrl:"https://s3.amazonaws.com/static.screeps.com/decorations/7e3d680d2f48b1ff244a95e564275536fe4ed61.png",theme:"5e908ed162339b0045ac2d0f",rarity:4,name:"F-00065:AL:X",group:"5ee9016d961c4e27734cf301",steamItemDefId:3606,enabled:!0,groupDescription:"Adjustable brightness.",preview:{original:"https://s3.amazonaws.com/static.screeps.com/decorations/da7256631a2a2c8568221ad1f0bef0bb5525a7.png","128x128":"https://s3.amazonaws.com/static.screeps.com/decorations/3c0f0da6b41e413bdc4f66a01eed62b5b252c29.png","256x256":"https://s3.amazonaws.com/static.screeps.com/decorations/80c9978b58403e13b4a28f47ef1422e895c04fe.png"}}},{_id:"5fbab429b2f60e0fae891bcb",user:"58356f6fc8012784246abb7e",active:{lighting:!0,position:"below",width:256,height:256,syncRotate:!0,animation:"blink",brightness:"1",nameFilter:"ecarry*",exclude:!1,firstColor:"#FFFFFF",firstAlpha:1,secondColor:"#FFFFFF",secondAlpha:"1",flip:!1,color:"#1fe265",alpha:.79},decoration:{_id:"5f2ab6c1ad10bf3222df1b4f",graphics:[{url:"https://s3.amazonaws.com/static.screeps.com/decorations/a23d96123d27bf163babe0a29a54de003aea568.svg",color:"color",alpha:"alpha",visible:""}],description:"38.svg",rarityMultiplier:1,type:"creep",theme:"5ee3db64961c4e98dc4cf121",rarity:5,name:"C-00071:CC:X",group:"5eec306d0042094b2845f7d6",steamItemDefId:57779,enabled:!0,groupDescription:"Choose your own color.",preview:{original:"https://s3.amazonaws.com/static.screeps.com/decorations/3a7853ca055d7ae5738852f6f73f27389594e2e.png","128x128":"https://s3.amazonaws.com/static.screeps.com/decorations/8557cffe9216525092427f90b9847ef5bdcd6c8.png","256x256":"https://s3.amazonaws.com/static.screeps.com/decorations/e198e4f909cdb99f11a8cc7bc9f7e7a733faeca.png"}}}]},Qn={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 ei(r){const e=Math.round(r).toString(16);return e.length<2?"0"+e:e}function wt(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"#"+ei(h)+ei(u)+ei(d)}function ac(){const r=[];let e=0;r.push({index:e++,rgb:wt(0,0,.8)});for(let t=0;t<19;t++)r.push({index:e++,rgb:wt(t*360/19,.6,.8)});r.push({index:e++,rgb:wt(0,0,.5)});for(let t=0;t<19;t++)r.push({index:e++,rgb:wt(t*360/19,.7,.5)});r.push({index:e++,rgb:wt(0,0,.3)});for(let t=0;t<19;t++)r.push({index:e++,rgb:wt(t*360/19,.4,.3)});r.push({index:e++,rgb:wt(0,0,.1)});for(let t=0;t<19;t++)r.push({index:e++,rgb:wt(t*360/19,.5,.1)});return r}const zr=ac();function ti(r){if(typeof r=="string")return r;if(typeof r=="number"){const e=zr[r];return e?e.rgb:"#000000"}return"#000000"}function Kn(r){const e=ti(r.color1),t=ti(r.color2),n=ti(r.color3),i=r.param??0;if(typeof r.type=="number"){const h=Qn[r.type];h&&h.calc(i)}let s=0;if(r.flip&&typeof r.type=="number"){const h=Qn[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=Qn[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[cc,Ns]=z([]);let dc=0;function ke(r,e="success",t=4e3){const n=dc++;Ns(i=>[...i,{id:n,message:r,type:e,duration:t}]),setTimeout(()=>{Ns(i=>i.filter(s=>s.id!==n))},t)}const uc=!1;function Jn(){return!0}function hc(){return uc}function ms(){return window.location.origin}function fc(){return"0.6.1"}function pc(){return typeof window>"u"?null:window.__SCREEPS_CLIENT_EMBEDDED__??null}function on(){const r="/client/";return r.startsWith(".")?"":r.replace(/\/$/,"")}function Pt(r){const e=`[${r}]`;return{log:()=>{},warn:()=>{},error:(...t)=>console.error(e,...t)}}const ye={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",showRoomDecorations:"screeps:settings:showRoomDecorations",roomDarkOverlay:"screeps:settings:roomDarkOverlay",showRoomVisuals:"screeps:settings:showRoomVisuals",spriteTheme:"screeps:settings:spriteTheme",verboseCreepDetails:"screeps:settings:verboseCreepDetails",showMapVisuals:"screeps:settings:showMapVisuals"},He={url:"screeps:url",token:"screeps:token",serverPassword:"screeps:serverPassword"};function ri(r){return localStorage.getItem(r)}function Ds(r,e){localStorage.setItem(r,e)}function gc(r){localStorage.removeItem(r)}function an(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 ni(r,e){localStorage.setItem(r,String(e))}function zo(r,e){const t=localStorage.getItem(r);if(t===null)return e;try{return JSON.parse(t)}catch{return e}}function ys(r,e){localStorage.setItem(r,JSON.stringify(e))}function kn(r){return sessionStorage.getItem(r)}function cn(r,e){sessionStorage.setItem(r,e)}function Br(r){sessionStorage.removeItem(r)}async function mc(){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:et}=Pt("client"),[me,Tn]=z(null),[Vt,cr]=z("idle"),[Gs,Mn]=z(null),[Ue,Ri]=z(null),[vs,Pi]=z(null),[Ee,En]=z(null),[In,Bo]=z(null),[Ie,Wo]=z(!1),[ii,Ho]=z(null),[yc,Uo]=z({}),[Kt,Vo]=z(null);let Rn=-1,Oi=-1;const dr=[],vc=5;function bc(r){if(r===void 0)return;const e=Date.now();if(Rn>=0&&r>Rn){const t=e-Oi;if(t>0){dr.push(t),dr.length>vc&&dr.shift();const n=dr.reduce((i,s)=>i+s,0)/dr.length;Bo(Math.round(n))}}Rn=r,Oi=e}function wc(){Rn=-1,Oi=-1,dr.length=0,Bo(null)}const Yo=()=>{var e,t;const r=vs();return r?(((t=(e=r.serverData)==null?void 0:e.shards)==null?void 0:t.length)??0)===0:null};async function Wt(r){Jn()&&(r={...r,url:ms()}),et(`connecting to ${r.url} (auth: ${r.auth})`),cr("connecting"),Mn(null);try{let e;if(r.auth==="guest")e=new Ka,Wo(!0);else if(r.auth==="password"){if(!r.email||!r.password)throw new Error("Email and password are required");e=new Za({email:r.email,password:r.password})}else{if(!r.token)throw new Error("Token is required");e=new qa({token:r.token})}const t=new ja({url:r.url,auth:e,storage:r.storage??new Qa("screeps-client"),debug:!1,serverPassword:r.serverPassword,decorationsMock:lc});t.http.on("http:tokenRefresh",({token:n})=>{et("token refreshed"),cn(He.token,n)}),t.http.on("http:error",({method:n,path:i,error:s})=>{et("http error:",n,i,s.message),ke(`Request failed: ${n} ${i} — ${s.message}`,"error",6e3)}),t.stores.server.on("server:disconnected",n=>{et(`server disconnected (willReconnect: ${n.willReconnect})`),n.willReconnect||(cr("idle"),Tn(null),Ri(null),Pi(null))}),t.stores.server.on("server:error",n=>{et("server error:",n.error.message),Mn(n.error.message),cr("error")}),t.stores.user.on("user:me",n=>{et(`user: ${n.username} (id: ${n._id})`),Ri(n)}),t.stores.server.on("server:version",n=>{et(`server version: ${n.package??"unknown"}`),Pi(n)}),t.stores.user.on("user:stream",n=>{if(n&&typeof n=="object"&&"flags"in n){const i=n.flags;i&&typeof i=="object"&&Uo(i)}}),t.stores.user.on("user:worldStatus",({status:n})=>{et(`world status: ${n}`),Vo(n)}),await t.connect(),t.stores.user.subscribeUserStream(),Tn(t),cr("connected"),et(`connected to ${r.url}`),t.stores.server.worldInfo().then(n=>{Ho(n),et(`world: ${n.width}x${n.height} x[${n.minX},${n.maxX}] y[${n.minY},${n.maxY}]`)}).catch(()=>{}),cn(He.url,r.url),t.http.token&&cn(He.token,t.http.token),r.serverPassword?cn(He.serverPassword,r.serverPassword):Br(He.serverPassword)}catch(e){const t=e instanceof Error?e.message:String(e);throw Mn(t),cr("error"),Tn(null),e}}async function xc(){const r=Jn()?ms():kn(He.url),e=kn(He.token);if(!r||!e)return;const t=kn(He.serverPassword)??void 0;try{e==="guest"?await Wt({url:r,auth:"guest",storage:null,serverPassword:t}):await Wt({url:r,auth:"token",token:e,serverPassword:t})}catch{Br(He.token)}}function _c(){const r=me();r&&r.disconnect(),Tn(null),cr("idle"),Mn(null),Ri(null),Pi(null),En(null),Wo(!1),Ho(null),Uo({}),Vo(null),wc(),Br(He.token),Br(He.url),Br(He.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 $c={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"},ir=$c,Sc=R("<svg>"),Fs=r=>r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Cc=r=>r.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()),kc=r=>{const e=Cc(r);return e.charAt(0).toUpperCase()+e.slice(1)},Tc=(...r)=>r.filter((e,t,n)=>!!e&&e.trim()!==""&&n.indexOf(e)===t).join(" ").trim(),Mc=r=>{const[e,t]=ko(r,["color","size","strokeWidth","children","class","name","iconNode","absoluteStrokeWidth"]);return(()=>{var n=Sc();return Po(n,ve(ir,{get width(){return e.size??ir.width},get height(){return e.size??ir.height},get stroke(){return e.color??ir.stroke},get"stroke-width"(){return re(()=>!!e.absoluteStrokeWidth)()?Number(e.strokeWidth??ir["stroke-width"])*24/Number(e.size):Number(e.strokeWidth??ir["stroke-width"])},get class(){return Tc("lucide","lucide-icon",...e.name!=null?[`lucide-${Fs(kc(e.name))}`,`lucide-${Fs(e.name)}`]:[],e.class!=null?e.class:"")}},t),!0,!0),m(n,b($e,{get each(){return e.iconNode},children:([i,s])=>b(Oo,ve({component:i},s))})),n})()},we=Mc,Ec=[["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"}]],Rc=r=>b(we,ve(r,{iconNode:Ec,name:"bell-off"})),Pc=Rc,Oc=[["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"}]],Lc=r=>b(we,ve(r,{iconNode:Oc,name:"bell"})),Ac=Lc,Ic=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],Nc=r=>b(we,ve(r,{iconNode:Ic,name:"check"})),Xo=Nc,Dc=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],Gc=r=>b(we,ve(r,{iconNode:Dc,name:"chevron-down"})),Fc=Gc,zc=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Bc=r=>b(we,ve(r,{iconNode:zc,name:"chevron-right"})),jo=Bc,Wc=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Hc=r=>b(we,ve(r,{iconNode:Wc,name:"chevron-left"})),Uc=Hc,Vc=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]],Yc=r=>b(we,ve(r,{iconNode:Vc,name:"clock"})),Xc=Yc,jc=[["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"}]],qc=r=>b(we,ve(r,{iconNode:jc,name:"code-xml"})),Zc=qc,Kc=[["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"}]],Jc=r=>b(we,ve(r,{iconNode:Kc,name:"eye"})),qo=Jc,Qc=[["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"}]],ed=r=>b(we,ve(r,{iconNode:Qc,name:"flag"})),Zo=ed,td=[["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"}]],rd=r=>b(we,ve(r,{iconNode:td,name:"hammer"})),nd=rd,id=[["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"}]],sd=r=>b(we,ve(r,{iconNode:id,name:"layout-grid"})),od=sd,ld=[["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"}]],ad=r=>b(we,ve(r,{iconNode:ld,name:"loader"})),cd=ad,dd=[["path",{d:"m10 17 5-5-5-5",key:"1bsop3"}],["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}]],ud=r=>b(we,ve(r,{iconNode:dd,name:"log-in"})),hd=ud,fd=[["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"}]],pd=r=>b(we,ve(r,{iconNode:fd,name:"log-out"})),gd=pd,md=[["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"}]],yd=r=>b(we,ve(r,{iconNode:md,name:"map"})),vd=yd,bd=[["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"}]],wd=r=>b(we,ve(r,{iconNode:bd,name:"move"})),xd=wd,_d=[["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"}]],$d=r=>b(we,ve(r,{iconNode:_d,name:"pause"})),Sd=$d,Cd=[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]],kd=r=>b(we,ve(r,{iconNode:Cd,name:"play"})),Td=kd,Md=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],Ed=r=>b(we,ve(r,{iconNode:Md,name:"plus"})),Rd=Ed,Pd=[["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"}]],Od=r=>b(we,ve(r,{iconNode:Pd,name:"refresh-cw"})),Ld=Od,Ad=[["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"}]],Id=r=>b(we,ve(r,{iconNode:Ad,name:"settings"})),Nd=Id,Dd=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],Gd=r=>b(we,ve(r,{iconNode:Dd,name:"terminal"})),Fd=Gd,zd=[["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"}]],Bd=r=>b(we,ve(r,{iconNode:zd,name:"trash-2"})),Pn=Bd,Wd=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Hd=r=>b(we,ve(r,{iconNode:Wd,name:"x"})),Jt=Hd,Ud=R("<span style=font-size:11px;display:inline-flex;align-items:center;gap:3px>"),Vd=R('<div style="color:#3fb950;font-size:14px;text-align:center;padding:8px 0">Account created! Logging you in…'),Yd=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>"),Xd=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>"),jd=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>"),qd=R("<span style=font-size:11px;color:#f85149>Passwords don't match"),Zd=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>"),Kd=R("<button type=submit style=padding:10px;border-radius:6px;border:none;background:#238636;color:#fff;font-weight:600>"),Jd=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'),Qd=R("<form style=display:flex;flex-direction:column;gap:16px><h2 style=margin:0;font-size:20px>Create Account"),Ko=R("<div style=color:#f85149;font-size:13px>"),eu=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">'),tu=R("<button type=button style=background:none;border:none;color:#58a6ff;font-size:12px;cursor:pointer;padding:0>Create account"),ru=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'),nu=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>"),iu=R("<div style=color:#8b949e;font-size:12px;margin-top:-8px>"),su=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>"),ou=R("<button type=button style=padding:10px;border-radius:6px;border:none;background:#1b2838;color:#c7d5e0;font-weight:600>Login with Steam"),lu=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)'),au=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>'),cu=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>'),du=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">'),uu=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>"),hu=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>"),fu=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>"),pu=R('<span style="font-size:11px;padding:2px 8px;border-radius:12px;background:#21262d;border:1px solid #30363d;color:#8b949e;font-family:monospace">');const ht={padding:"8px 12px","border-radius":"6px",border:"1px solid #30363d",background:"#0d1117",color:"#c9d1d9"};function gu(r){const[e,t]=z(null),[n,i]=z(null),[s,o]=z(null);return fe(()=>{const c=r();t(null),i(null),o(null);let l=!1;const a=setTimeout(async()=>{try{const h=await tc(c);if(l)return;if(t(h),o(null),Fo(h)){const u=await rc(c);l||i(u)}}catch{l||(o("Could not reach server"),t(null))}},400);Be(()=>{l=!0,clearTimeout(a)})}),{serverVersion:e,authModInfo:n,serverError:s}}function zs(r,e,t){const[n,i]=z("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);Be(()=>{o=!0,clearTimeout(c)})}),n}function Bs(r){const e={idle:null,checking:{children:"Checking…",color:"#8b949e"},available:{children:[b(Xo,{size:12})," Available"],color:"#3fb950"},taken:{children:[b(Jt,{size:12})," Already taken"],color:"#f85149"},error:{children:"Could not verify",color:"#d29922"}},t=()=>e[r.state];return b(j,{get when(){return t()},get children(){var n=Ud();return m(n,()=>t().children),I(i=>Y(n,"color",t().color)),n}})}function mu(r){const[e,t]=z(""),[n,i]=z(""),[s,o]=z(""),[c,l]=z(""),[a,h]=z(!1),[u,d]=z(null),[f,p]=z(!1),g=zs(()=>r.url,e,nc),w=zs(()=>r.url,n,ic),L=()=>c()!==""&&s()!==c(),A=()=>!a()&&e()!==""&&n()!==""&&s().length>=4&&s()===c()&&g()!=="taken"&&g()!=="checking"&&w()!=="taken"&&w()!=="checking",N=async M=>{if(M.preventDefault(),!!A()){h(!0),d(null);try{const y=await sc(r.url,e(),n(),s());if(y.error){d(y.error);return}p(!0),setTimeout(()=>r.onSuccess(n(),s()),1500)}catch(y){d(y instanceof Error?y.message:"Registration failed")}finally{h(!1)}}};return(()=>{var M=Qd();return M.firstChild,M.addEventListener("submit",N),m(M,b(j,{get when(){return f()},get children(){return Vd()}}),null),m(M,b(j,{get when(){return!f()},get children(){return[(()=>{var y=Yd(),x=y.firstChild;x.firstChild;var O=x.nextSibling;return m(x,b(Bs,{get state(){return g()}}),null),O.$$input=v=>t(v.currentTarget.value),I(v=>{var C=ht,k=a();return v.e=J(O,C,v.e),k!==v.t&&(O.disabled=v.t=k),v},{e:void 0,t:void 0}),I(()=>O.value=e()),y})(),(()=>{var y=Xd(),x=y.firstChild;x.firstChild;var O=x.nextSibling;return m(x,b(Bs,{get state(){return w()}}),null),O.$$input=v=>i(v.currentTarget.value),I(v=>{var C=ht,k=a();return v.e=J(O,C,v.e),k!==v.t&&(O.disabled=v.t=k),v},{e:void 0,t:void 0}),I(()=>O.value=n()),y})(),(()=>{var y=jd(),x=y.firstChild,O=x.nextSibling;return O.$$input=v=>o(v.currentTarget.value),I(v=>{var C=ht,k=a();return v.e=J(O,C,v.e),k!==v.t&&(O.disabled=v.t=k),v},{e:void 0,t:void 0}),I(()=>O.value=s()),y})(),(()=>{var y=Zd(),x=y.firstChild;x.firstChild;var O=x.nextSibling;return m(x,b(j,{get when(){return L()},get children(){return qd()}}),null),O.$$input=v=>l(v.currentTarget.value),I(v=>{var C={...ht,border:L()?"1px solid #f85149":"1px solid #30363d"},k=a();return v.e=J(O,C,v.e),k!==v.t&&(O.disabled=v.t=k),v},{e:void 0,t:void 0}),I(()=>O.value=c()),y})(),re(()=>re(()=>!!u())()&&(()=>{var y=Ko();return m(y,u),y})()),(()=>{var y=Kd();return m(y,()=>a()?"Creating account…":"Create Account"),I(x=>{var O=!A(),v=A()?"pointer":"not-allowed",C=A()?1:.5;return O!==x.e&&(y.disabled=x.e=O),v!==x.t&&Y(y,"cursor",x.t=v),C!==x.a&&Y(y,"opacity",x.a=C),x},{e:void 0,t:void 0,a:void 0}),y})(),(()=>{var y=Jd();return y.$$click=()=>r.onCancel(),y})()]}}),null),M})()}function yu(){const r=Jn(),e=hc(),[t,n]=z("login"),[i,s]=z("password"),[o,c]=z(r?ms():window.location.origin),[l,a]=z(""),[h,u]=z(""),[d,f]=z(""),[p,g]=z(""),{serverVersion:w,authModInfo:L,serverError:A}=gu(o),N=()=>{var E,T;return((T=(E=w())==null?void 0:E.serverData)==null?void 0:T.welcomeText)??null},M=()=>{var E,T;return(((T=(E=w())==null?void 0:E.serverData)==null?void 0:T.features)??[]).filter(P=>P.name!=="auth"&&P.version!=null)},y=()=>{var T,P;const E=w();return E?((P=(T=Fo(E))==null?void 0:T.authTypes)==null?void 0:P.includes("steam"))??!0:!0},x=()=>{var E,T,P;return((E=L())==null?void 0:E.allowRegistration)===!0||(((P=(T=w())==null?void 0:T.serverData)==null?void 0:P.features)??[]).some(F=>F.name==="official-like")},O=()=>{const E=o().replace(/\/$/,""),T=window.open(`${E}/api/auth/steam`,"screeps-steam-auth","width=800,height=600,left=200,top=100"),P=W=>{try{const D=JSON.parse(W.data);D.token&&(G(),Wt({url:E,auth:"token",token:D.token,serverPassword:p()||void 0,storage:null}))}catch{}},F=setInterval(()=>{T!=null&&T.closed&&G()},500),G=()=>{clearInterval(F),window.removeEventListener("message",P)};window.addEventListener("message",P),Be(G)},v=async E=>{E.preventDefault(),await Wt({url:o(),auth:i(),email:l()||void 0,password:h()||void 0,token:d()||void 0,serverPassword:p()||void 0,storage:null})},C=async E=>{E.preventDefault(),await Wt({url:o(),auth:"guest",serverPassword:p()||void 0,storage:null})},k=async(E,T)=>{try{await Wt({url:o(),auth:"password",email:E,password:T,serverPassword:p()||void 0,storage:null})}catch{n("login"),s("password"),a(E),u(T)}},_=()=>Vt()==="connecting";return(()=>{var E=du(),T=E.firstChild;return m(E,b(j,{get when(){return N()},get children(){var P=eu();return I(()=>P.innerHTML=N()),P}}),T),m(T,b(j,{get when(){return t()==="register"},get children(){return b(mu,{get url(){return o()},get serverPassword(){return p()},onSuccess:k,onCancel:()=>n("login")})}}),null),m(T,b(j,{get when(){return t()==="login"},get children(){var P=au(),F=P.firstChild;F.firstChild;var G=F.nextSibling,W=G.firstChild,D=W.firstChild;D.nextSibling;var B=W.nextSibling,U=G.nextSibling;return P.addEventListener("submit",v),m(F,b(j,{get when(){return x()},get children(){var H=tu();return H.$$click=()=>n("register"),H}}),null),m(P,b(j,{when:!r,get children(){var H=ru(),q=H.firstChild,Z=q.nextSibling;return q.$$click=()=>s("password"),Z.$$click=()=>s("token"),I(X=>{var K=i()==="password"?"#238636":"transparent",he=i()==="token"?"#238636":"transparent";return K!==X.e&&Y(q,"background",X.e=K),he!==X.t&&Y(Z,"background",X.t=he),X},{e:void 0,t:void 0}),H}}),G),m(P,b(j,{when:!r,get children(){return[(()=>{var H=nu(),q=H.firstChild,Z=q.nextSibling;return Z.$$input=X=>c(X.currentTarget.value),I(X=>J(Z,ht,X)),I(()=>Z.value=o()),H})(),b(j,{get when(){return A()},get children(){var H=iu();return m(H,A),H}})]}}),G),m(P,(()=>{var H=re(()=>i()==="password");return()=>H()?[(()=>{var q=uu(),Z=q.firstChild,X=Z.nextSibling;return X.$$input=K=>a(K.currentTarget.value),I(K=>J(X,ht,K)),I(()=>X.value=l()),q})(),(()=>{var q=hu(),Z=q.firstChild,X=Z.nextSibling;return X.$$input=K=>u(K.currentTarget.value),I(K=>J(X,ht,K)),I(()=>X.value=h()),q})()]:(()=>{var q=fu(),Z=q.firstChild,X=Z.nextSibling;return X.$$input=K=>f(K.currentTarget.value),I(K=>J(X,ht,K)),I(()=>X.value=d()),q})()})(),G),B.$$input=H=>g(H.currentTarget.value),m(P,(()=>{var H=re(()=>!!Gs());return()=>H()&&(()=>{var q=Ko();return m(q,Gs),q})()})(),U),m(U,()=>_()?"Connecting…":"Connect"),m(P,b(j,{get when(){return y()},get children(){return[(()=>{var H=su(),q=H.firstChild,Z=q.nextSibling;return Z.nextSibling,H})(),(()=>{var H=ou();return H.$$click=O,I(q=>{var Z=_(),X=_()?"not-allowed":"pointer",K=_()?.6:1;return Z!==q.e&&(H.disabled=q.e=Z),X!==q.t&&Y(H,"cursor",q.t=X),K!==q.a&&Y(H,"opacity",q.a=K),q},{e:void 0,t:void 0,a:void 0}),H})()]}}),null),m(P,b(j,{when:!r||e,get children(){var H=lu();return H.addEventListener("mouseleave",q=>{q.currentTarget.style.borderColor="#30363d"}),H.addEventListener("mouseenter",q=>{_()||(q.currentTarget.style.borderColor="#8b949e")}),H.$$click=C,I(q=>{var Z=_(),X=_()?"not-allowed":"pointer",K=_()?.6:1;return Z!==q.e&&(H.disabled=q.e=Z),X!==q.t&&Y(H,"cursor",q.t=X),K!==q.a&&Y(H,"opacity",q.a=K),q},{e:void 0,t:void 0,a:void 0}),H}}),null),I(H=>{var q=ht,Z=_(),X=_()?"not-allowed":"pointer",K=_()?.6:1;return H.e=J(B,q,H.e),Z!==H.t&&(U.disabled=H.t=Z),X!==H.a&&Y(U,"cursor",H.a=X),K!==H.o&&Y(U,"opacity",H.o=K),H},{e:void 0,t:void 0,a:void 0,o:void 0}),I(()=>B.value=p()),P}}),null),m(E,b(j,{get when(){return M().length>0},get children(){var P=cu(),F=P.firstChild,G=F.nextSibling;return m(G,b($e,{get each(){return M()},children:W=>(()=>{var D=pu();return m(D,()=>W.name,null),m(D,(()=>{var B=re(()=>!!W.version);return()=>B()?` ${W.version}`:""})(),null),D})()})),P}}),null),E})()}Oe(["input","click"]);var vu=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'),bu=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 wu(){const r=()=>{switch(Vt()){case"connected":return"#238636";case"connecting":return"#d29922";case"error":return"#f85149";default:return"#8b949e"}};return(()=>{var e=bu(),t=e.firstChild,n=t.firstChild,i=n.nextSibling;return m(i,(()=>{var s=re(()=>Vt()==="connected");return()=>s()?"Online":Vt()})()),m(e,b(j,{get when(){return Ie()},get children(){return vu()}}),null),I(s=>Y(n,"background-color",r())),e})()}class xu{constructor(e){S(this,"container");S(this,"hoverGraphics");S(this,"pendingGraphics");S(this,"selectionContainer");S(this,"selectionGraphics",new Map);S(this,"selectionTypes",new Map);S(this,"selectionVisuals",new Map);S(this,"ticker",null);S(this,"tickerCallback",null);this.container=new Ae,this.container.label="hoverHighlight",this.container.eventMode="none",this.hoverGraphics=new te,this.hoverGraphics.eventMode="none",this.container.addChild(this.hoverGraphics),this.pendingGraphics=new te,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*$,i=t*$;this.hoverGraphics.rect(n,i,$,$),this.hoverGraphics.stroke({width:1,color:16777215,alpha:.35}),this.hoverGraphics.rect(n,i,$,$),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 te;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*$,i=t*$,s=n+$/2,o=i+$/2,c=$*.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,$-2,$-2),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.6})}clearPendingTile(){this.pendingGraphics.clear()}drawCreepRing(e,t,n){e.clear();const i=t+$/2,s=n+$/2,o=$*.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,$-i*2,$-i*2),e.stroke({width:1.5,color:16777215,alpha:.9}),e.rect(t+i,n+i,$-i*2,$-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 $=12,Me=50*$,Te=48,Pr=128,Ht={terrain:0,objects:10,animations:20,darkOverlay:30,visuals:40,hover:50,nav:60},_u=new Set(["road","constructedWall","rampart"]);class bs{constructor(e,t){S(this,"app");S(this,"world");S(this,"hoverLayer");S(this,"darkOverlay");S(this,"lightLayer");S(this,"overlayCanvas");S(this,"overlayCtx");S(this,"overlayTexture");S(this,"destroyed",!1);S(this,"canDrag",!1);S(this,"container");S(this,"resizeObserver",null);S(this,"bounceRaf",null);S(this,"wheelTimeout",null);S(this,"navOverlay");S(this,"lastMouseX",0);S(this,"lastMouseY",0);S(this,"onHoverTile",null);S(this,"onClickTile",null);S(this,"onRightClick",null);this.app=e,this.container=t,this.world=new Ae({sortableChildren:!0}),this.app.stage.addChild(this.world),this.overlayCanvas=document.createElement("canvas"),this.overlayCanvas.width=Me,this.overlayCanvas.height=Me,this.overlayCtx=this.overlayCanvas.getContext("2d"),this.redrawOverlayCanvas([]),this.overlayTexture=De.from(this.overlayCanvas),this.darkOverlay=new ze(this.overlayTexture),this.darkOverlay.label="darkOverlay",this.darkOverlay.zIndex=Ht.darkOverlay,this.world.addChild(this.darkOverlay),this.lightLayer=new Ae,this.lightLayer.label="lightLayer",this.hoverLayer=new xu(e.ticker),this.hoverLayer.container.zIndex=Ht.hover,this.world.addChild(this.hoverLayer.container),this.navOverlay=new Ae,this.navOverlay.zIndex=Ht.nav,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 Mo;return await t.init({background:"#0d1117",antialias:!0,resolution:window.devicePixelRatio||1,autoDensity:!0}),e.appendChild(t.canvas),new bs(t,e)}getMinScale(){const t=this.container.clientWidth,n=this.container.clientHeight;return Math.min(t,n)/(Me+64)}clampView(e=!1){const t=this.world.scale.x,n=Me*t,i=this.container.clientWidth,s=this.container.clientHeight,o=e?Pr:0;if(n<=i){const c=i/2-n/2;e?this.world.x=Math.min(c+Pr,Math.max(c-Pr,this.world.x)):this.world.x=c}else{const c=i-n-Te-o,l=Te+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+Pr,Math.max(c-Pr,this.world.y)):this.world.y=c}else{const c=s-n-Te-o,l=Te+o;this.world.y=Math.min(l,Math.max(c,this.world.y))}this.canDrag=!0}getTargetPosition(){const e=this.world.scale.x,t=Me*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-Te,l=Te;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-Te,l=Te;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,g=Math.min(1,p/c),w=1-Math.pow(1-g,3);if(t!==null){const L=s+(t-s)*w;this.world.scale.set(L),this.world.x=l-h*L,this.world.y=a-u*L}e&&t===null&&(this.world.x=n+(e.x-n)*w,this.world.y=i+(e.y-i)*w),g<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 Rr(0,0),n=new Rr(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()],g=i.getBoundingClientRect(),w=(p[0].x+p[1].x)/2-g.left,L=(p[0].y+p[1].y)/2-g.top;h=Math.hypot(p[1].x-p[0].x,p[1].y-p[0].y),u=this.world.scale.x,l=(w-this.world.x)/u,a=(L-this.world.y)/u}else c=!1,e=this.canDrag,t=new Rr(f.clientX,f.clientY),n=new Rr(f.clientX,f.clientY)}),i.addEventListener("pointermove",f=>{var L;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 A=[...o.values()],N=(A[0].x+A[1].x)/2-p.left,M=(A[0].y+A[1].y)/2-p.top,y=Math.hypot(A[1].x-A[0].x,A[1].y-A[0].y),x=this.getMinScale(),O=5,v=.6;let C=u*(y/h);C<x&&(C=x+(C-x)*v),C>O&&(C=O+(C-O)*v),this.cancelBounce(),this.world.scale.set(C),this.world.x=N-l*C,this.world.y=M-a*C,this.clampView(!0);return}if(!c){const A=this.screenToTile(this.lastMouseX,this.lastMouseY);this.hoverLayer.setHoveredTile((A==null?void 0:A.tx)??null,(A==null?void 0:A.ty)??null),(L=this.onHoverTile)==null||L.call(this,(A==null?void 0:A.tx)??null,(A==null?void 0:A.ty)??null)}if(!e||!this.canDrag)return;const g=f.clientX-t.x,w=f.clientY-t.y;this.world.x+=g,this.world.y+=w,t=new Rr(f.clientX,f.clientY),this.clampView(!0)});const d=f=>{var L;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,g=f.clientY-n.y;if(Math.sqrt(p*p+g*g)<s){const A=i.getBoundingClientRect(),N=f.clientX-A.left,M=f.clientY-A.top,y=this.screenToTile(N,M);y&&((L=this.onClickTile)==null||L.call(this,y.tx,y.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,g=this.getMinScale(),w=5;let L=this.world.scale.x*p;const A=.6;L<g&&(L=g+(L-g)*A),L>w&&(L=w+(L-w)*A);const N=i.getBoundingClientRect(),M=f.clientX-N.left,y=f.clientY-N.top;if(this.cancelBounce(),L<g){const x=this.container.clientWidth/2,O=this.container.clientHeight/2,v=(x-this.world.x)/this.world.scale.x,C=(O-this.world.y)/this.world.scale.y;this.world.scale.set(L),this.world.x=x-v*L,this.world.y=O-C*L}else{const x=(M-this.world.x)/this.world.scale.x,O=(y-this.world.y)/this.world.scale.y;this.world.scale.set(L),this.world.x=M-x*L,this.world.y=y-O*L}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/$),o=Math.floor(i/$);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-Me*n/2,this.world.y=t-Me*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 te;d.x=o,d.y=c,d.hitArea=new Eo(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=Me/2,i=Me/2,s=18;t(-Te,0,Te,Me,[18,i,Te-6,i-s,Te-6,i+s],e.west),t(Me,0,Te,Me,[Te-18,i,6,i-s,6,i+s],e.east),t(0,-Te,Me,Te,[n,18,n-s,Te-6,n+s,Te-6],e.north),t(0,Me,Me,Te,[n,Te-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&&t!==this.darkOverlay&&this.world.removeChild(t)}this.navOverlay.removeChildren(),this.hoverLayer.clearSelection(),this.hoverLayer.setHoveredTile(null,null),this.clearLighting(),this.world.scale.set(1),this.cancelBounce(),this.cancelWheelTimeout(),this.clampView()}clearLighting(){this.redrawOverlayCanvas([]),this.overlayTexture.source.update()}updateLighting(e){const t=[];for(const n of Object.values(e))typeof n.type=="string"&&_u.has(n.type)||typeof n.x!="number"||typeof n.y!="number"||t.push({x:n.x,y:n.y});this.redrawOverlayCanvas(t),this.overlayTexture.source.update()}redrawOverlayCanvas(e){const t=this.overlayCtx;if(t.clearRect(0,0,Me,Me),t.fillStyle="rgba(0,0,0,0.2)",t.fillRect(0,0,Me,Me),e.length>0){t.globalCompositeOperation="destination-out";for(const{x:n,y:i}of e){const s=(n+.5)*$,o=(i+.5)*$,c=3*$,l=t.createRadialGradient(s,o,0,s,o,c);l.addColorStop(0,"rgba(0,0,0,1)"),l.addColorStop(1,"rgba(0,0,0,0)"),t.fillStyle=l,t.beginPath(),t.arc(s,o,c,0,Math.PI*2),t.fill()}t.globalCompositeOperation="source-over"}}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.overlayTexture.destroy(!0),this.app.destroy(!0,{children:!0}))}}const Jo=856343,$u=1448738,Su=1843496,Cu=3421243,ku=Cu,Tu=Jo,ws=7039337,Qo=3159613,Mu=1579032,el=0,Eu=2631720,Ru=2632986,Pu=2500383,Ou=2771488,Lu=5000268,Au=11122630,Iu=16770413,Nu=7829367,Du=16332866,Gu=6127794,Fu=6684002,zu=12164347,dn={tough:Lu,move:Au,work:Iu,carry:Nu,attack:Du,ranged_attack:Gu,heal:Fu,claim:zu},si=5809919,Yt=7979263,tl=4176208,oi=9147550,un=13801762,Ws=10711543,Bu=16218298,Hs=16273737,Wr=15763518,Wu=2172461,xs=ws,Hu=13226457,Gt=12283502,mr=[16777215,16711680,8388736,255,65535,32768,16776960,16753920,10824234,8421504,16777215],Uu={creep:Wr,spawn:si,extension:Yt,tower:tl,container:oi,storage:un,link:Ws,rampart:si,road:xs,constructedWall:Wu,extractor:oi,lab:Bu,terminal:un,observer:Yt,powerSpawn:Wr,nuker:Hs,factory:oi,invaderCore:Hs,source:un,mineral:Yt,deposit:un,controller:si,powerBank:Wr,portal:Ws},Tr=16771195,Vu=Tr,Yu=Yt,Xu=Tr,ju=Tr,Hr=9419667,qu=7245682,Zu=12116924,Ku=12283502,Ju=9787480,Qu=14721184,Us=Su,eh=13684944,Ce=1579032,Lt=5592405,Li=11184810,th=9419667,Ke=16771195,rh=16069959,Vs=4410435;function nh(r){return{floorColor:(r==null?void 0:r.floorColor)??ku,swampFillColor:(r==null?void 0:r.swampFillColor)??Ru,swampBorderColor:(r==null?void 0:r.swampBorderColor)??Pu,swampBorderWidth:(r==null?void 0:r.swampBorderWidth)??.2,swampGlowColor:(r==null?void 0:r.swampGlowColor)??Ou,wallFillColor:(r==null?void 0:r.wallFillColor)??Mu,wallBorderColor:(r==null?void 0:r.wallBorderColor)??el,wallBorderWidth:(r==null?void 0:r.wallBorderWidth)??.05,wallNoiseColor:(r==null?void 0:r.wallNoiseColor)??Eu}}function Qt(r,e,t,n){const i=$,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,g=c*i+s;a?(o=!0,!h&&!d&&c>0&&l>0?(r.moveTo(p,c*i),r.arc(p,g,s,-Math.PI/2,Math.PI,!0),r.lineTo(p,g),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,g),r.arc(p,g,s,Math.PI,-Math.PI/2,!1),r.closePath()),a?!h&&!f&&c>0&&l<49?(r.moveTo(p,c*i),r.arc(p,g,s,-Math.PI/2,0,!1),r.lineTo(p,g),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,g),r.arc(p,g,s,0,-Math.PI/2,!0),r.closePath()),a?!u&&!d&&c<49&&l>0?(r.moveTo(l*i,g),r.arc(p,g,s,Math.PI,Math.PI/2,!0),r.lineTo(p,g),r.closePath()):r.rect(l*i,g,s,s):u&&d&&e.get(l-1,c+1)===t&&(o=!0,r.moveTo(l*i,g),r.lineTo(l*i,c*i+i),r.lineTo(p,c*i+i),r.arc(p,g,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,g,s,Math.PI/2,0,!0),r.lineTo(p,g),r.closePath()):r.rect(p,g,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,g),r.arc(p,g,s,0,Math.PI/2,!1),r.closePath())}o&&n(r)}function ih(r,e){const t=ws,n=$,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 sh(r){const e=new te;return e.rect(0,0,50*$,50*$),e.fill(r.floorColor),e}function oh(r,e){const t=new te,n={color:e.swampBorderColor,width:$*e.swampBorderWidth,alignment:0,cap:"round",join:"round"};return Qt(t,r,Xe.Swamp,i=>i.stroke(n)),Qt(t,r,Xe.Swamp,i=>i.fill(e.swampFillColor)),t}function lh(r,e){const t=new te,n={color:e.wallBorderColor,width:$*e.wallBorderWidth,alignment:0,cap:"round",join:"round"};return Qt(t,r,Xe.Wall,i=>i.stroke(n)),Qt(t,r,Xe.Wall,i=>i.fill(e.wallFillColor)),ih(t,r),t.rect(0,0,50*$,50*$),t.stroke({width:1,color:Qo}),t}function ah(r,e){const t=new te;return t.label="swampGlow",Qt(t,r,Xe.Swamp,n=>n.fill(e.swampGlowColor)),t.alpha=.45,t.filters=[new na({strength:5,quality:3})],t}function ch(r,e,t){const n=new te;Qt(n,r,Xe.Wall,o=>o.fill(t.wallNoiseColor)),n.alpha=.5,n.filters=[new ra({noise:.12,seed:1})],n.filterArea=new Eo(0,0,50*$,50*$);const i=e.generateTexture({target:n,frame:n.filterArea});n.filters=null,n.destroy();const s=new ze(i);return s.label="wallNoise",s}function hn(r,e,t){const n=nh(t),i=new Ae,s=ch(r,e,n),o=i.destroy.bind(i);i.destroy=l=>{s.destroyed||(s.removeFromParent(),s.destroy({texture:!0,textureSource:!0})),o(l)},i.addChild(sh(n)),i.addChild(oh(r,n)),i.addChild(lh(r,n)),i.addChild(ah(r,n)),i.addChild(s),t!=null&&t.wallTextureUrl&&(s.visible=!1);const c=50*$;if(t!=null&&t.floorTextureUrl){const{floorTextureUrl:l,floorTextureTint:a=16777215,floorTextureAlpha:h=1,floorTextureTileScale:u=1}=t;Mi.load(l).then(d=>{if(i.destroyed)return;const f=new Rs({texture:d,width:c,height:c});f.tint=a,f.alpha=h,f.tileScale.set(u),i.addChildAt(f,2)}).catch(()=>{})}if(t!=null&&t.wallTextureUrl){const{wallTextureUrl:l,wallTextureTint:a=16777215,wallTextureAlpha:h=1,wallTextureTileScale:u=1}=t;Mi.load(l).then(d=>{if(i.destroyed)return;const f=new Rs({texture:d,width:c,height:c});f.tint=a,f.alpha=h,f.tileScale.set(u);const p=new te;Qt(p,r,Xe.Wall,g=>g.fill(16777215)),i.addChild(p),f.mask=p,i.addChild(f)}).catch(()=>{})}return i}function Or(r,e){r.getChildByLabel("swampGlow").visible=e,r.getChildByLabel("wallNoise").visible=e}function vr(r,e){const t=parseInt(r.replace("#",""),16),n=Math.min(255,Math.round((t>>16&255)*e)),i=Math.min(255,Math.round((t>>8&255)*e)),s=Math.min(255,Math.round((t&255)*e));return n<<16|i<<8|s}function Ys(r){return parseInt(r.replace("#",""),16)}function Ye(r,e){if(r==null)return e;const t=Number(r);return isNaN(t)?e:t}function dh(r,e,t){const n=t.terrain??{};r.floorBackgroundColor&&(n.floorColor=vr(r.floorBackgroundColor,Ye(r.floorBackgroundBrightness,1))),r.swampColor&&(n.swampFillColor=Ys(r.swampColor)),r.swampStrokeColor&&(n.swampBorderColor=Ys(r.swampStrokeColor)),r.swampStrokeWidth!=null&&(n.swampBorderWidth=Ye(r.swampStrokeWidth,50)/250),r.roadsColor&&(t.roadColor=vr(r.roadsColor,Ye(r.roadsBrightness,1))),e.floorForegroundUrl&&(n.floorTextureUrl=e.floorForegroundUrl,r.floorForegroundColor&&(n.floorTextureTint=vr(r.floorForegroundColor,Ye(r.floorForegroundBrightness,1))),n.floorTextureAlpha=Ye(r.floorForegroundAlpha,1),n.floorTextureTileScale=Ye(r.tileScale??e.tileScale,1)),t.terrain=n}function uh(r,e,t){const n=t.terrain??{};r.backgroundColor&&(n.wallFillColor=vr(r.backgroundColor,Ye(r.backgroundBrightness,1))),r.strokeColor&&(n.wallBorderColor=vr(r.strokeColor,Ye(r.strokeBrightness,1))),r.strokeWidth!=null&&(n.wallBorderWidth=Ye(r.strokeWidth,10)/250),e.foregroundUrl&&(n.wallTextureUrl=e.foregroundUrl,r.foregroundColor&&(n.wallTextureTint=vr(r.foregroundColor,Ye(r.foregroundBrightness,1))),n.wallTextureAlpha=Ye(r.foregroundAlpha,1),n.wallTextureTileScale=Ye(r.tileScale??e.tileScale,1)),t.terrain=n}function hh(r){const e={};for(const t of r.decorations){const n=t.decoration.type;n==="floorLandscape"?dh(t.active,t.decoration,e):n==="wallLandscape"&&uh(t.active,t.decoration,e)}return e}function fh(r){return new Promise((e,t)=>{const n=new Image;n.onload=()=>e(n),n.onerror=t,n.src=r})}class rl{constructor(){S(this,"cache",new Map);S(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=Kn(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 fh(s),a=document.createElement("canvas");a.width=c,a.height=c,a.getContext("2d").drawImage(l,0,0,c,c);const u=De.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 nl={1:200,2:45e3,3:135e3,4:405e3,5:1215e3,6:3645e3,7:10935e3},il={1:2e4,2:1e4,3:2e4,4:4e4,5:8e4,6:12e4,7:15e4,8:2e5},ph=new rl,kt=$*.44,nt=$*.28,Lr=50,qr=32,Ai=12/qr,Ii=$/2-$*.44,sl=2,gh=12*1.2/qr,mh=5,yh=2.5,fn=2,li=2.6,vh=2,Xs=12,js=15790320,bh=1710618,qs=$*.42,ol=$*.3,wh=Math.max(1,$*.08),xh={H:13421772,O:16777215,U:5822457,L:62626,K:10514943,Z:16631694,X:11568379},_h={H:2236962,O:2236962},$h=$*.42,ll=32,Sh=9/ll,Ni=$-4,Zs=$*.28,Ks=1600,Ch=16776428;function Di(r,e){if(e<=0)return Ni;const t=Math.max(0,Math.min(1,r/e));return Zs+(Ni-Zs)*t}function _s(r,e,t=Ke){const n=e/2,i=$/2,s=$/2,o=e*.25;r.clear(),r.roundRect(i-n,s-n,e,e,o),r.fill(t)}function ai(r,e){const t=r.__sourceGraphics;t&&(r.__sourceSize=e,_s(t,e,$s(performance.now())))}function $s(r){const e=r%Ks/Ks,t=.5-.5*Math.cos(e*Math.PI*2);return On(Ke,Ch,t)}function Gi(r){const e=typeof r.energy=="number"?r.energy:0,t=typeof r.energyCapacity=="number"?r.energyCapacity:3e3;return{energy:e,capacity:t}}const al=$*.3,cl=Math.max(1,$*.12),Fi=al-cl/2,kh=$*.42,Th=1500;function On(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 dl(r,e){r.clear(),r.circle($/2,$/2,al),r.stroke({width:cl,color:e,alpha:.95})}function zi(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 xt(r,e,t){return t.flatMap(([n,i])=>[r+n*$,e+i*$])}function sr(r,e,t,n){t-e<.001||(r.moveTo(kt*Math.cos(e),kt*Math.sin(e)),r.arc(0,0,kt,e,t),r.lineTo(nt*Math.cos(t),nt*Math.sin(t)),r.arc(0,0,nt,t,e,!0),r.closePath(),r.fill(n))}function Bi(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 Wi(r,e){return e<=0||r<=0?0:nt*.8*Math.min(1,r/e)}function ci(r,e){const t=r.__creepFillGraphics;t&&(t.clear(),e>0&&(t.circle(0,0,e),t.fill(Tr)))}function Mh(r){return Uu[r]??Hu}function yr(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 ul(r){return r>=200?1.15:r>=100?.85:.7}function Hi(r,e){return e<=0||r<=0?0:ol*ul(e)*Math.min(1,r/e)}function Eh(r,e,t,n){const i=$/2,s=$/2,o=ul(t),c=new te;c.circle(i,s,qs*o),c.fill(Ce),c.circle(i,s,qs*o),c.stroke({width:wh*o,color:n}),c.circle(i,s,ol*o),c.fill(Li),r.addChild(c);const l=new te,a=Hi(e,t);a>0&&(l.circle(i,s,a),l.fill(Ke)),r.addChild(l),r.__fillGraphics=l}function di(r,e){const t=$/2,n=$/2,i=r.__fillGraphics;i&&(i.clear(),e>0&&(i.circle(t,n,e),i.fill(Ke)))}const Ui=-$*.4,Vi=-$*.3,Yi=$*.8,Nn=$*.6,Xi=$*.45,Dn=$*.6,ji=$*.275,qi=$*.2;function Zi(r,e){return e<=0||r<=0?0:Nn*Math.min(1,r/e)}function Ln(r,e){const t=r.__towerFillGraphics;if(t&&(t.clear(),e>0)){const n=Math.max(.5,$*.02);t.rect(Ui+n,Vi+Nn-e+n,Yi-n*2,e-n*2),t.fill(Ke)}}const Rh=0,Ph=-$*.1,Oh=$*1,hl=$*1.2;function Ur(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 Ki(r,e){return e<=0||r<=0?0:Dn*Math.min(1,r/e)}function Ji(r,e){const t=r.__containerFillG;if(t&&(t.clear(),e>0)){const n=Math.max(.5,$*.02);t.rect(ji+n,qi+Dn-e+n,Xi-n*2,e-n*2),t.fill(Ke)}}function Gn(r,e){return e<=0||r<=0?0:hl*Math.min(1,r/e)}function Fn(r,e){const t=r.__storageFillG;t&&(t.clear(),e>0&&(t.rect(Rh,Ph+hl-e,Oh,e),t.fill(Ke)))}const Qi=$*.65,es=Qi,ct=$*.42;function ts(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),g=t+i*Math.sin(d);if(u<s)r.moveTo(p,g),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,g),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 w=Math.min(1,o/c),L=d+h*w;r.moveTo(p,g),r.arc(e,t,n,d,L),r.arc(e,t,i,L,d,!0),r.closePath(),r.fill({color:14540253,alpha:.9})}}else r.moveTo(p,g),r.arc(e,t,n,d,f),r.arc(e,t,i,f,d,!0),r.closePath(),r.fill({color:1973790,alpha:.6})}}function rs(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 zn(r,e){const t=r.user;return typeof t!="string"||!e?!1:t!==e}function or(r,e=!0,t,n,i,s,o,c){var A,N,M,y,x,O,v;const l=new Ae,a=new te,h=Mh(r.type),u=$/2,d=$/2,f=typeof r.user=="string"?r.user:void 0,g=f!==void 0&&t!==void 0&&f!==t?Gt:th;switch(r.type){case"creep":{const C=2*Math.PI,k=new Ae;k.position.set(u,d),k.rotation=-Math.PI/2;const _=zn(r,t);if(_){const V=new te;V.circle(0,0,kt+.75),V.stroke({width:1.5,color:Gt}),k.addChild(V)}const E=new te;E.circle(0,0,kt),E.fill(Jo),k.addChild(E);const T=r.body??[];let P=0,F=0,G=0;const W=[],D={};for(const V of T)V.type==="work"?P++:V.type==="move"?F++:(D[V.type]===void 0&&(W.push(V.type),D[V.type]=0),D[V.type]++,G++);const B=P/Lr*C,U=F/Lr*C,H=G/Lr*C,q=B/2,Z=q+H/2,X=Math.PI-U/2,K=Math.PI+U/2,he=C-B/2-H/2,se=C-B/2,ie=new te;B>0&&sr(ie,-B/2,q,dn.work);let pe=q;for(const V of W){const Q=(D[V]??0)/Lr*C/2;sr(ie,pe,pe+Q,dn[V]??7829367),pe+=Q}sr(ie,Z,X,Us),U>0&&sr(ie,X,K,dn.move),sr(ie,K,he,Us);let ee=se;for(const V of W){const Q=(D[V]??0)/Lr*C/2;sr(ie,ee-Q,ee,dn[V]??7829367),ee-=Q}k.addChild(ie);const ge=new te;ge.circle(0,0,nt),ge.fill($u),k.addChild(ge);const Pe=typeof r.user=="string"?r.user:void 0,Le=Pe?(A=s==null?void 0:s[Pe])==null?void 0:A.badge:void 0;if(Le&&i){const V=new ze;V.anchor.set(.5,.5);const Q=nt*2;V.width=Q,V.height=Q,V.rotation=Math.PI/2,k.addChild(V),l.__creepBadgeSprite=V,i.getOrCreate(Le).then(ne=>{V.destroyed||(V.texture=ne)}).catch(()=>{})}else if(_){const V=new te;V.circle(0,0,nt*.82),V.fill({color:Gt,alpha:.9}),k.addChild(V),l.__creepForeignMark=V}const{used:je,capacity:Je}=Bi(r),Ot=Wi(je,Je),Qe=new te;Ot>0&&(Qe.circle(0,0,Ot),Qe.fill(Tr)),k.addChild(Qe),l.__creepFillGraphics=Qe,l.__creepUsed=je,l.__creepCapacity=Je;const le=(kt+nt)/2,oe=(kt-nt)*.45,de=new te;de.moveTo(kt,0),de.lineTo(le,-oe),de.lineTo(le,oe),de.closePath(),de.fill(eh),k.addChild(de),l.addChild(k),l.__bodyContainer=k;break}case"extension":{const{energy:C,capacity:k}=yr(r);Eh(l,C,k,g),l.__extEnergy=C,l.__extCapacity=k;break}case"spawn":{a.circle(u,d,$*.65),a.fill(Ce),a.circle(u,d,$*.65),a.stroke({width:$*.1,color:13421772}),a.circle(u,d,$*.4),a.fill(Ke);break}case"powerSpawn":{a.circle(u,d,$*.65),a.fill(Ce),a.circle(u,d,$*.65),a.stroke({width:$*.1,color:rh}),a.circle(u,d,$*.4),a.fill(Ke);break}case"source":{const{energy:C,capacity:k}=Gi(r),_=Di(C,k),E=new te;_s(E,_,$s(performance.now())),l.addChild(E),l.__sourceGraphics=E,l.__sourceEnergy=C,l.__sourceCapacity=k,l.__sourceSize=_;break}case"constructionSite":{const C=typeof r.user=="string"?r.user:void 0,k=C!==void 0&&C===t,_=k?Hr:Ku,E=k?qu:Ju,T=k?Zu:Qu,P=typeof r.progress=="number"?r.progress:0,F=typeof r.progressTotal=="number"?r.progressTotal:1,G=new te;l.addChild(G),l.__csBuildGlow=G;const W=new te;zi(W,u,d,Fi,P,F,_),l.addChild(W),l.__csFillGraphics=W;const D=new te;dl(D,_),l.addChild(D),l.__csRingGraphics=D,l.__csProgress=P,l.__csProgressTotal=F,l.__csUser=C,l.__csColor=_,l.__csColorDark=E,l.__csColorLight=T;break}case"mineral":{const C=typeof r.mineralType=="string"?r.mineralType:"?",k=xh[C]??Yt,_=_h[C]??16777215,E=new te;E.circle(u,d,$h),E.fill(k),l.addChild(E);const T=new vt({text:C,style:{fontSize:ll,fill:_,fontWeight:"bold"}});T.anchor.set(.5,.5),T.scale.set(Sh),T.position.set(u,d),l.addChild(T);break}case"deposit":{a.rect(2,2,$-4,$-4),a.fill(h);break}case"controller":{const C=typeof r.level=="number"?r.level:0,k=typeof r.progress=="number"?r.progress:0,_=typeof r.progressTotal=="number"?r.progressTotal:0,E=r.reservation,T=typeof r.user=="string"?r.user:typeof(E==null?void 0:E.user)=="string"?E.user:void 0,P=T?(N=s==null?void 0:s[T])==null?void 0:N.badge:void 0,F=o==null?void 0:o.controller;if(F&&c){const W=$*F.tileScale,D=W/600,B=new ze;B.anchor.set(.5,.5),B.x=u,B.y=d,B.width=W,B.height=W,l.addChild(B);const U=[];for(let X=0;X<8;X++){const K=new ze;K.anchor.set(.5,.5),K.x=u,K.y=d,K.scale.set(D),K.rotation=X*(Math.PI/4),l.addChild(K),U.push(K)}l.__ctrlSegSprites=U,rs(l,C,k,_);const H=()=>c.getOrLoad(o.atlasUrl),q=c.getTexture(o.atlasUrl,F.backgroundFrame);q?B.texture=q:H().then(X=>{B.destroyed||(B.texture=X.textures[F.backgroundFrame]??De.EMPTY)}).catch(()=>{});const Z=c.getTexture(o.atlasUrl,F.segmentFrame);if(Z)for(const X of U)X.texture=Z;else H().then(X=>{const K=X.textures[F.segmentFrame]??De.EMPTY;for(const he of U)he.destroyed||(he.texture=K)}).catch(()=>{})}else{const W=new te,D=[];for(let U=0;U<8;U++){const H=-Math.PI/2+U*Math.PI/4;D.push(u+Qi*Math.cos(H),d+Qi*Math.sin(H))}W.poly(D),W.fill(2238513),W.poly(D),W.stroke({width:$*.07,color:8027781}),l.addChild(W);const B=new te;ts(B,u,d,es,ct,C,k,_),l.addChild(B),l.__ctrlSegGraphics=B}l.__ctrlLevel=C,l.__ctrlProgress=k,l.__ctrlProgressTotal=_,l.__ctrlDowngradeTime=typeof r.downgradeTime=="number"?r.downgradeTime:void 0,l.__ctrlUserId=T;const G=new te;if(P?(G.circle(u,d,ct),G.fill(Ce)):(G.circle(u,d,ct),G.fill(3028031),G.circle(u,d,ct),G.stroke({width:$*.04,color:8027781}),G.circle(u,d,$*.16),G.fill(10133672)),l.addChild(G),P&&i){const W=new ze;W.anchor.set(.5,.5),W.width=ct*2,W.height=ct*2,W.position.set(u,d);const D=new te;D.circle(u,d,ct),D.fill(16777215),l.addChild(W),W.mask=D,l.addChild(D),i.getOrCreate(P).then(B=>{W.destroyed||(W.texture=B)}).catch(()=>{})}break}case"energy":{a.circle(u,d,$*.2),a.fill(Ke);break}case"road":break;case"constructedWall":break;case"rampart":break;case"tower":{const{energy:C,capacity:k}=yr(r),_=new te;_.circle(u,d,$*.6),_.fill(Ce),_.circle(u,d,$*.6),_.stroke({width:$*.05,color:g}),l.addChild(_);const E=new Ae;E.position.set(u,d);const T=new te;T.rect(Ui,Vi,Yi,Nn),T.fill(Ce),E.addChild(T);const P=new te;E.addChild(P),l.__towerFillGraphics=P,l.__towerEnergy=C,l.__towerCapacity=k,Ln(l,Zi(C,k));const F=new te;F.rect(Ui,Vi,Yi,Nn),F.stroke({width:1,color:Lt}),E.addChild(F);const G=new te;G.rect(-$*.2,-$*.9,$*.4,$*.5),G.fill(Li),G.rect(-$*.2,-$*.9,$*.4,$*.5),G.stroke({width:$*.07,color:Ce}),E.addChild(G),l.addChild(E),l.__barrelContainer=E;break}case"storage":{const C=o==null?void 0:o.sprites.storage;if(C&&c){const{used:F,capacity:G}=Ur(r),W=$*C.tileScale,D=(U,H)=>{U.texture=H,U.width=W,U.height=W};for(const U of C.layers){const H=new ze;H.anchor.set(.5,.5),H.x=u,H.y=d,U.tint==="owner"&&(H.tint=g),l.addChild(H);const q=c.getTexture(o.atlasUrl,U.frame);q?D(H,q):c.getOrLoad(o.atlasUrl).then(Z=>{H.destroyed||D(H,Z.textures[U.frame]??De.EMPTY)}).catch(()=>{})}const B=new te;l.addChild(B),l.__storageFillG=B,l.__storageUsed=F,l.__storageCapacity=G,Fn(l,Gn(F,G));break}const{used:k,capacity:_}=Ur(r),E=xt(u,d,[[-.6,-.7],[0,-.8],[.6,-.7],[.65,0],[.6,.7],[0,.8],[-.6,.7],[-.65,0],[-.6,-.7]]);a.poly(E),a.fill(Ce),a.poly(E),a.stroke({width:$*.05,color:g}),a.rect(u-$*.5,d-$*.6,$*1,$*1.2),a.fill(Lt),l.addChild(a);const T=new te;l.addChild(T),l.__storageFillG=T,l.__storageUsed=k,l.__storageCapacity=_,Fn(l,Gn(k,_));const P=new te;P.rect(u-$*.5,d-$*.6,$*1,$*1.2),P.stroke({width:$*.1,color:Ce}),l.addChild(P);break}case"terminal":{const C=xt(u,d,[[0,-.8],[.55,-.55],[.8,0],[.55,.55],[0,.8],[-.55,.55],[-.8,0],[-.55,-.55],[0,-.8]]),k=xt(u,d,[[0,-.65],[.45,-.45],[.65,0],[.45,.45],[0,.65],[-.45,.45],[-.65,0],[-.45,-.45],[0,-.65]]);a.poly(C),a.fill(Ce),a.poly(C),a.stroke({width:$*.05,color:g}),a.poly(k),a.fill(Li),a.rect(u-$*.45,d-$*.45,$*.9,$*.9),a.fill(Lt),a.rect(u-$*.45,d-$*.45,$*.9,$*.9),a.stroke({width:$*.1,color:Ce});break}case"link":{const C=xt(u,d,[[0,-.5],[.4,0],[0,.5],[-.4,0],[0,-.5]]),k=xt(u,d,[[0,-.3],[.25,0],[0,.3],[-.25,0],[0,-.3]]);a.poly(C),a.fill(Ce),a.poly(C),a.stroke({width:$*.05,color:g}),a.poly(k),a.fill(Lt);break}case"lab":{const C=d-$*.025;a.circle(u,C,$*.55),a.fill(Ce),a.circle(u,C,$*.55),a.stroke({width:$*.05,color:g}),a.circle(u,C,$*.4),a.fill(Lt),a.rect(u-$*.45,d+$*.3,$*.9,$*.25),a.fill(Ce),a.poly(xt(u,d,[[-.45,.3],[-.45,.55],[.45,.55],[.45,.3]])),a.stroke({width:$*.05,color:g});break}case"container":{const{used:C,capacity:k}=Ur(r);a.rect(ji,qi,Xi,Dn),a.fill(Ce),l.addChild(a);const _=new te;l.addChild(_),l.__containerFillG=_,l.__containerUsed=C,l.__containerCapacity=k,Ji(l,Ki(C,k));const E=new te;E.rect(ji,qi,Xi,Dn),E.stroke({width:$*.1,color:Ce}),l.addChild(E);break}case"observer":{a.circle(u,d,$*.45),a.fill(Ce),a.circle(u,d,$*.45),a.stroke({width:$*.05,color:g}),a.circle(u+$*.225,d,$*.2),a.fill(g);break}case"nuker":{const C=xt(u,d,[[0,-1],[-.47,.2],[-.5,.5],[.5,.5],[.47,.2],[0,-1]]),k=xt(u,d,[[0,-.8],[-.4,.2],[.4,.2],[0,-.8]]);a.poly(C),a.fill(Ce),a.poly(C),a.stroke({width:$*.05,color:g}),a.poly(k),a.fill(Lt),a.poly(k),a.stroke({width:$*.01,color:g});break}case"factory":case"extractor":case"invaderCore":{a.circle(u,d,$*.45),a.fill(Ce),a.circle(u,d,$*.45),a.stroke({width:$*.05,color:g}),a.circle(u,d,$*.35),a.fill(Lt);break}case"flag":{const C=typeof r.color=="number"?r.color:0,k=typeof r.secondaryColor=="number"?r.secondaryColor:0,_=mr[C]??mr[0],E=mr[k]??mr[0],T=o==null?void 0:o.flag;if(T&&c){const P=$*T.tileScale,F=()=>c.getOrLoad(o.atlasUrl),G=(B,U)=>{B.texture=U,B.width=P,B.height=P},W=new ze;W.anchor.set(.5,.5),W.x=u,W.y=d,W.tint=_,l.addChild(W);const D=c.getTexture(o.atlasUrl,T.mainFrame);if(D?G(W,D):F().then(B=>{W.destroyed||G(W,B.textures[T.mainFrame]??De.EMPTY)}).catch(()=>{}),k!==C){const B=new ze;B.anchor.set(.5,.5),B.x=u,B.y=d,B.tint=E,l.addChild(B);const U=c.getTexture(o.atlasUrl,T.secondFrame);U?G(B,U):F().then(H=>{B.destroyed||G(B,H.textures[T.secondFrame]??De.EMPTY)}).catch(()=>{})}}else{const F=$*.08*1.5,G=$*.7*1.5,W=u-F/2,D=d-$*.25*1.5;a.rect(W,D,F,G),a.fill(8947848);const B=W+F,U=D,H=B+$*.45*1.5,q=U,Z=U+$*.44*1.5,X=(q+Z)/2,K=X;a.moveTo(B,q),a.lineTo(H,X),a.lineTo(B,K),a.closePath(),a.fill(_),a.moveTo(B,K),a.lineTo(H,X),a.lineTo(B,Z),a.closePath(),a.fill(E),l.addChild(a)}if(l.__flagColor=C,l.__flagSecondaryColor=k,typeof r.name=="string"){const P=new vt({text:r.name,style:{fontSize:qr,fill:16777215}});P.scale.set(Ai),P.anchor.set(.5,0),P.x=u,P.y=d+$*.55,P.visible=e,l.__nameLabel=P,l.addChild(P)}break}case"ruin":{const C=typeof r.user=="string"?r.user:void 0,_=C!==void 0&&C===t?Hr:Gt,E=$*.42,T=6,P=Math.PI/5,F=new te;for(let D=0;D<T;D++){const B=D*Math.PI*2/T,U=B-P/2,H=B+P/2,q=u+E*Math.cos(U),Z=d+E*Math.sin(U);F.moveTo(q,Z),F.arc(u,d,E,U,H),F.stroke({width:$*.09,color:_,alpha:.75,cap:"round"})}l.addChild(F);const G=$*.18,W=new te;W.moveTo(u-G,d-G),W.lineTo(u+G,d+G),W.moveTo(u+G,d-G),W.lineTo(u-G,d+G),W.stroke({width:$*.11,color:_,cap:"round"}),l.addChild(W);break}case"tombstone":{const C=typeof r.user=="string"?r.user:void 0,_=C!==void 0&&C===t?Hr:Gt,E=o==null?void 0:o.tombstone;if(E&&c){const T=$*E.tileScale,P=()=>c.getOrLoad(o.atlasUrl),F=new ze;F.anchor.set(.5,.5),F.x=u,F.y=d,F.width=T,F.height=T,l.addChild(F);const G=new ze;G.anchor.set(.5,.5),G.x=u,G.y=d,G.width=T,G.height=T,G.tint=_,l.addChild(G);const W=c.getTexture(o.atlasUrl,E.shellFrame);W?F.texture=W:P().then(B=>{F.destroyed||(F.texture=B.textures[E.shellFrame]??De.EMPTY)}).catch(()=>{});const D=c.getTexture(o.atlasUrl,E.crossFrame);D?G.texture=D:P().then(B=>{G.destroyed||(G.texture=B.textures[E.crossFrame]??De.EMPTY)}).catch(()=>{})}else{const T=$*.62,P=$*.82,F=u-T/2,G=d-P/2,W=T/2,D=new te;D.moveTo(F,G+W),D.arc(u,G+W,W,Math.PI,0,!1),D.lineTo(F+T,G+P),D.lineTo(F,G+P),D.closePath(),D.fill(Ce),D.moveTo(F,G+W),D.arc(u,G+W,W,Math.PI,0,!1),D.lineTo(F+T,G+P),D.lineTo(F,G+P),D.closePath(),D.stroke({width:$*.07,color:_,alpha:.9}),l.addChild(D);const B=$*.18,U=new te;U.moveTo(u-B,d-B*.6),U.lineTo(u+B,d+B*.6),U.moveTo(u+B,d-B*.6),U.lineTo(u-B,d+B*.6),U.stroke({width:$*.09,color:_,cap:"round"}),l.addChild(U)}break}default:{const C=$-2;a.rect(1,1,C,C),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"&&r.type!=="constructedWall"&&r.type!=="rampart"&&r.type!=="container"&&l.addChild(a),r.type==="creep"&&typeof r.name=="string"){const C=zn(r,t);let k;if(C){const T=typeof r.user=="string"?r.user:void 0;k=T?((M=s==null?void 0:s[T])==null?void 0:M.username)??T:"Hostile"}else k=r.name;const _=C?Gt:16777215,E=new vt({text:k,style:{fontSize:qr,fill:_}});E.scale.set(Ai),E.anchor.set(.5,1),E.x=u,E.y=Ii-sl,E.visible=e,l.__nameLabel=E,l.addChild(E)}const w=r.type==="creep"?100:r.type==="flag"?200:0,L=r.type==="flag"?((y=o==null?void 0:o.flag)==null?void 0:y.zIndex)??0:r.type==="controller"?((x=o==null?void 0:o.controller)==null?void 0:x.zIndex)??0:r.type==="tombstone"?((O=o==null?void 0:o.tombstone)==null?void 0:O.zIndex)??0:((v=o==null?void 0:o.sprites[r.type])==null?void 0:v.zIndex)??0;return l.zIndex=w+L,l.position.set(r.x*$,r.y*$),l}function At(r){r.destroy({children:!0})}function Lh(r){const e=r.length>Xs?r.slice(0,Xs):r,t=new vt({text:e,style:{fontSize:qr,fill:bh,fontWeight:"600"}});t.scale.set(gh),t.anchor.set(.5,.5);const n=t.width,i=t.height,s=n+mh*2,o=i+yh*2,c=o/2,l=new te;l.roundRect(-s/2,-o/2,s,o,c),l.fill(js),l.roundRect(-s/2,-o/2,s,o,c),l.stroke({width:.4,color:1118481,alpha:.55}),l.moveTo(-fn,o/2-.1),l.lineTo(0,o/2+li),l.lineTo(fn,o/2-.1),l.closePath(),l.fill(js),l.moveTo(-fn,o/2-.1),l.lineTo(0,o/2+li),l.lineTo(fn,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+li),a}class Ah{constructor(e,t=!0,n,i,s){S(this,"container");S(this,"objects",new Map);S(this,"rawObjects",new Map);S(this,"roadGraphics");S(this,"rampartGraphics");S(this,"wallGraphics");S(this,"wallMarkGraphics");S(this,"ticker",null);S(this,"tickerCallback",null);S(this,"extAnimations",new Map);S(this,"creepFillAnimations",new Map);S(this,"towerFillAnimations",new Map);S(this,"storageFillAnimations",new Map);S(this,"containerFillAnimations",new Map);S(this,"sourceAnimations",new Map);S(this,"buildGlowAnimations",new Map);S(this,"ctrlFlashAnimations",new Map);S(this,"currentGameTime",0);S(this,"sayBubbles",new Set);S(this,"moveDuration",600);S(this,"EXT_ANIM_DURATION",300);S(this,"instantMode",!1);S(this,"lastWorldScale",1);S(this,"showLabels");S(this,"currentUserId");S(this,"badge");S(this,"badgeCache",ph);S(this,"users");S(this,"activeTheme",null);S(this,"atlasCache",null);S(this,"roadColor",xs);this.showLabels=t,this.currentUserId=n,this.badge=i,this.users=s,this.container=new Ae,this.container.sortableChildren=!0,this.wallGraphics=new te,this.wallGraphics.zIndex=-3,this.container.addChild(this.wallGraphics),this.wallMarkGraphics=new te,this.wallMarkGraphics.zIndex=-2,this.container.addChild(this.wallMarkGraphics),this.rampartGraphics=new te,this.rampartGraphics.zIndex=-1,this.container.addChild(this.rampartGraphics),this.roadGraphics=new te,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}setRoadColor(e){this.roadColor=e,this.redrawRoads()}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/Th);for(const l of this.objects.values())l.__barrelContainer&&(l.__barrelContainer.rotation=i*.4),l.__csRingGraphics&&l.__csColorDark!==void 0&&l.__csColorLight!==void 0&&dl(l.__csRingGraphics,On(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;di(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;ci(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;Ln(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;Fn(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*d),u>=1&&this.storageFillAnimations.delete(l)}for(const[l,a]of this.containerFillAnimations){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;Ji(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*d),u>=1&&this.containerFillAnimations.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;ai(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*d),u>=1&&this.sourceAnimations.delete(l)}const o=$s(n);for(const l of this.objects.values()){const a=l.__sourceGraphics;a&&_s(a,l.__sourceSize??Ni,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($/2,$/2,kh),u.fill({color:Ke,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 M=0;M<a;M++){const y=h[M];y&&!y.destroyed&&(y.tint=16777215)}continue}const d=il[a]??2e4,p=1-Math.max(0,u-this.currentGameTime)/d;if(p<=.2){for(let M=0;M<a;M++){const y=h[M];y&&!y.destroyed&&(y.tint=16777215)}continue}const g=(p-.2)/.8,w=.3+g*1.5,L=.5+.5*Math.sin(2*Math.PI*w*n/1e3),A=On(16768477,16720418,g),N=On(16777215,A,g*L);for(let M=0;M<a;M++){const y=h[M];y&&!y.destroyed&&(y.tint=N)}}}startExtAnimation(e,t,n,i,s,o){const c=Hi(s,o);if(this.instantMode){di(t,c);return}const l=Hi(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=Wi(s,o);if(this.instantMode){ci(t,c);return}const l=Wi(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=Zi(s,o);if(this.instantMode){Ln(t,c);return}const l=Zi(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=Gn(s,o);if(this.instantMode){Fn(t,c);return}const l=Gn(n,i);l!==c&&this.storageFillAnimations.set(e,{visual:t,fromRadius:l,toRadius:c,startTime:performance.now()})}startContainerFillAnimation(e,t,n,i,s,o){const c=Ki(s,o);if(this.instantMode){Ji(t,c);return}const l=Ki(n,i);l!==c&&this.containerFillAnimations.set(e,{visual:t,fromRadius:l,toRadius:c,startTime:performance.now()})}startSourceAnimation(e,t,n,i,s,o){const c=Di(s,o);if(this.instantMode){ai(t,c);return}const l=Di(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),At(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.containerFillAnimations.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*$,u=l.y*$;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:g}=Bi(l);(a.__creepUsed!==p||a.__creepCapacity!==g)&&(this.startCreepFillAnimation(o,a,a.__creepUsed??0,a.__creepCapacity??g,p,g),a.__creepUsed=p,a.__creepCapacity=g)}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),At(a),this.objects.delete(o);const g=or(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users,this.activeTheme,this.atlasCache);g.__tileX=l.x,g.__tileY=l.y,this.applyLabelScale(g),this.objects.set(o,g),this.container.addChild(g)}else a.position.set(h,u)}else a.position.set(h,u);if(l.type==="extension"){const{energy:d,capacity:f}=yr(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}=yr(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}=Ur(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==="container"){const{used:d,capacity:f}=Ur(l);(a.__containerUsed!==d||a.__containerCapacity!==f)&&(this.startContainerFillAnimation(o,a,a.__containerUsed??0,a.__containerCapacity??f,d,f),a.__containerUsed=d,a.__containerCapacity=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,g=l.reservation,w=typeof l.user=="string"?l.user:typeof(g==null?void 0:g.user)=="string"?g.user:void 0;if(a.__ctrlUserId!==w){this.container.removeChild(a),At(a),this.objects.delete(o);const A=or(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users,this.activeTheme,this.atlasCache);A.__tileX=l.x,A.__tileY=l.y,this.applyLabelScale(A),this.objects.set(o,A),this.container.addChild(A);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}),rs(a,d,f,p)):a.__ctrlSegGraphics&&ts(a.__ctrlSegGraphics,$/2,$/2,es,ct,d,f,p),a.__ctrlLevel=d,a.__ctrlProgress=f,a.__ctrlProgressTotal=p);const L=typeof l.downgradeTime=="number"?l.downgradeTime:void 0;a.__ctrlDowngradeTime!==L&&(a.__ctrlDowngradeTime=L)}if(l.type==="source"){const{energy:d,capacity:f}=Gi(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&&zi(a.__csFillGraphics,$/2,$/2,Fi,d,f,a.__csColor??Hr),a.__csProgress=d,a.__csProgressTotal=f)}}else{const h=or(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*$,u=l.y*$;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:g}=Bi(l);(a.__creepUsed!==p||a.__creepCapacity!==g)&&(this.startCreepFillAnimation(c,a,a.__creepUsed??0,a.__creepCapacity??g,p,g),a.__creepUsed=p,a.__creepCapacity=g)}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),At(a),this.objects.delete(c);const g=or(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users,this.activeTheme,this.atlasCache);g.__tileX=l.x,g.__tileY=l.y,this.applyLabelScale(g),this.objects.set(c,g),this.container.addChild(g)}else a.position.set(h,u)}else a.position.set(h,u);if(l.type==="extension"){const{energy:d,capacity:f}=yr(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}=yr(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,g=l.reservation,w=typeof l.user=="string"?l.user:typeof(g==null?void 0:g.user)=="string"?g.user:void 0;if(a.__ctrlUserId!==w){this.container.removeChild(a),At(a),this.objects.delete(c);const A=or(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users,this.activeTheme,this.atlasCache);A.__tileX=l.x,A.__tileY=l.y,this.applyLabelScale(A),this.objects.set(c,A),this.container.addChild(A);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}),rs(a,d,f,p)):a.__ctrlSegGraphics&&ts(a.__ctrlSegGraphics,$/2,$/2,es,ct,d,f,p),a.__ctrlLevel=d,a.__ctrlProgress=f,a.__ctrlProgressTotal=p);const L=typeof l.downgradeTime=="number"?l.downgradeTime:void 0;a.__ctrlDowngradeTime!==L&&(a.__ctrlDowngradeTime=L)}if(l.type==="source"){const{energy:d,capacity:f}=Gi(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&&zi(a.__csFillGraphics,$/2,$/2,Fi,d,f,a.__csColor??Hr),a.__csProgress=d,a.__csProgressTotal=f)}}else{const h=or(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),At(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.redrawWalls(),this.redrawRamparts(),s&&this.redrawRoads(),this.refreshForeignCreepLabels(),this.refreshForeignCreepBadges()}redrawWalls(){this.wallGraphics.clear(),this.wallMarkGraphics.clear();const e=$,t=e/2,n=Array.from({length:50},()=>new Array(50).fill(!1)),i=[];for(const a of this.rawObjects.values())a.type==="constructedWall"&&typeof a.x=="number"&&typeof a.y=="number"&&a.x>=0&&a.x<50&&a.y>=0&&a.y<50&&(n[a.x][a.y]=!0,i.push({x:a.x,y:a.y}));if(i.length===0)return;const s=a=>{let h=!1;for(let u=0;u<50;u++)for(let d=0;d<50;d++){const f=n[d][u],p=u>0&&n[d][u-1],g=u<49&&n[d][u+1],w=d>0&&n[d-1][u],L=d<49&&n[d+1][u],A=d*e+t,N=u*e+t;f?(h=!0,!p&&!w&&u>0&&d>0?(a.moveTo(A,u*e),a.arc(A,N,t,-Math.PI/2,Math.PI,!0),a.lineTo(A,N),a.closePath()):a.rect(d*e,u*e,t,t)):p&&w&&n[d-1][u-1]&&(h=!0,a.moveTo(A,u*e),a.lineTo(d*e,u*e),a.lineTo(d*e,N),a.arc(A,N,t,Math.PI,-Math.PI/2,!1),a.closePath()),f?!p&&!L&&u>0&&d<49?(a.moveTo(A,u*e),a.arc(A,N,t,-Math.PI/2,0,!1),a.lineTo(A,N),a.closePath()):a.rect(A,u*e,t,t):p&&L&&n[d+1][u-1]&&(h=!0,a.moveTo(A,u*e),a.lineTo(d*e+e,u*e),a.lineTo(d*e+e,N),a.arc(A,N,t,0,-Math.PI/2,!0),a.closePath()),f?!g&&!w&&u<49&&d>0?(a.moveTo(d*e,N),a.arc(A,N,t,Math.PI,Math.PI/2,!0),a.lineTo(A,N),a.closePath()):a.rect(d*e,N,t,t):g&&w&&n[d-1][u+1]&&(h=!0,a.moveTo(d*e,N),a.lineTo(d*e,u*e+e),a.lineTo(A,u*e+e),a.arc(A,N,t,Math.PI/2,Math.PI,!1),a.closePath()),f?!g&&!L&&u<49&&d<49?(a.moveTo(A,u*e+e),a.arc(A,N,t,Math.PI/2,0,!0),a.lineTo(A,N),a.closePath()):a.rect(A,N,t,t):g&&L&&n[d+1][u+1]&&(h=!0,a.moveTo(A,u*e+e),a.lineTo(d*e+e,u*e+e),a.lineTo(d*e+e,N),a.arc(A,N,t,0,Math.PI/2,!1),a.closePath())}return h},o={color:el,width:e*.06,alignment:0,cap:"round",join:"round"};s(this.wallGraphics)&&this.wallGraphics.stroke(o),s(this.wallGraphics),this.wallGraphics.fill(Ce);const c=e*.32,l=e*.09;for(const{x:a,y:h}of i){const u=a*e,d=h*e;this.wallMarkGraphics.rect(u+e*.12,d+e*.3,c,l),this.wallMarkGraphics.rect(u+e*.56,d+e*.58,c,l)}this.wallMarkGraphics.fill({color:4210752})}redrawRoads(){this.roadGraphics.clear();const e=this.roadColor,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=$/2,s=$/2,o=$*.125;for(const l of n)this.roadGraphics.circle(l.x*$+i,l.y*$+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*$+i,h=l.y*$+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 g=f*$+i,w=p*$+s;this.roadGraphics.moveTo(a,h),this.roadGraphics.lineTo(g,w)}}}this.roadGraphics.stroke({width:o*2,color:e})}redrawRamparts(){this.rampartGraphics.clear();const e=$,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:Vs,alpha:.7}:s===this.currentUserId?{color:Vs,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 g=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(g)):(this.rampartGraphics.rect(o*e,s*e,t,t),this.rampartGraphics.fill(g))}else if(a&&u&&n[o-1][s-1]!==void 0){const g=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(g)}if(l){const g=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(g)):(this.rampartGraphics.rect(f,s*e,t,t),this.rampartGraphics.fill(g))}else if(a&&d&&n[o+1][s-1]!==void 0){const g=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(g)}if(l){const g=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(g)):(this.rampartGraphics.rect(o*e,p,t,t),this.rampartGraphics.fill(g))}else if(h&&u&&n[o-1][s+1]!==void 0){const g=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(g)}if(l){const g=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(g)):(this.rampartGraphics.rect(f,p,t,t),this.rampartGraphics.fill(g))}else if(h&&d&&n[o+1][s+1]!==void 0){const g=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(g)}}}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(Ai/t),e.__nameLabel.anchor.y===0?e.__nameLabel.y=$/2+$*.55:e.__nameLabel.y=Ii-sl/t),e.__sayBubble&&!e.__sayBubble.destroyed&&(e.__sayBubble.scale.set(1/t),e.__sayBubble.position.set($/2,Ii-vh/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||!zn(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"||!zn(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 ze;a.anchor.set(.5,.5);const h=nt*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=Lh(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())di(t.visual,t.toRadius);this.extAnimations.clear();for(const t of this.creepFillAnimations.values())ci(t.visual,t.toRadius);this.creepFillAnimations.clear();for(const t of this.towerFillAnimations.values())Ln(t.visual,t.toRadius);this.towerFillAnimations.clear();for(const t of this.sourceAnimations.values())ai(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())At(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 pn=2;function _t(r,e){return{cx:r*$+$/2,cy:e*$+$/2}}class Ih{constructor(e){S(this,"container");S(this,"graphics");S(this,"animations",[]);S(this,"ticker",null);S(this,"tickerCallback",null);this.container=new Ae,this.graphics=new te,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=_t(e,t),c=_t(n,i);this.animations.push({fromX:o.cx,fromY:o.cy,toX:c.cx,toY:c.cy,startTime:performance.now(),duration:s,color:Vu,width:pn})}addUpgradeController(e,t,n,i,s){const o=_t(e,t),c=_t(n,i);this.animations.push({fromX:o.cx,fromY:o.cy,toX:c.cx,toY:c.cy,startTime:performance.now(),duration:s,color:Yu,width:pn})}addTransfer(e,t,n,i,s){const o=_t(e,t),c=_t(n,i);this.animations.push({fromX:o.cx,fromY:o.cy,toX:c.cx,toY:c.cy,startTime:performance.now(),duration:s,color:ju,width:pn})}addBuild(e,t,n,i,s){const o=_t(e,t),c=_t(n,i);this.animations.push({fromX:o.cx,fromY:o.cy,toX:c.cx,toY:c.cy,startTime:performance.now(),duration:s,color:Xu,width:pn})}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 Fe=r=>(r+.5)*$,Ar=4,gn={dashed:[.4*$,.4*$],dotted:[.1*$,.3*$]};function mn(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,g=d/f;let w=0;for(;w<f;){const L=Math.min(s,f-w);if(i){const A=c+p*w,N=l+g*w;r.moveTo(A,N),r.lineTo(A+p*L,N+g*L)}w+=L,s-=L,s<.001&&(i=!i,s=i?t:n)}}}function Nh(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 Dh(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/$:t}function Gh(r){if(typeof r!="string")return"Arial";const e=r.match(/^[0-9.]+(px)?\s+(.+)$/);return e?e[2]:"Arial"}class Fh{constructor(){S(this,"container");S(this,"g");this.container=new Ae,this.container.label="visuals",this.g=new te,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=Fe(t.x1),o=Fe(t.y1),c=Fe(t.x2),l=Fe(t.y2),a=n.color??"#ffffff",h=(n.width??.1)*$;if(n.lineStyle&&n.lineStyle!=="solid"){const[u,d]=gn[n.lineStyle];mn(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=Fe(t.x),o=Fe(t.y),c=(n.radius??.5)*$,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*$;if(h){const[d,f]=gn[n.lineStyle];mn(e,Nh(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=Fe(t.x),o=Fe(t.y),c=t.w*$,l=t.h*$,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*$;if(u){const[f,p]=gn[n.lineStyle],g=[[s,o],[s+c,o],[s+c,o+l],[s,o+l],[s,o]];mn(e,g,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=Fe(u),p=Fe(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*$;if(c&&a){const[u,d]=gn[n.lineStyle],f=a[0],p=a[a.length-1],g=f[0]===p[0]&&f[1]===p[1];mn(e,g?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=Dh(t.font),s=Gh(t.font),o=t.align??"left",c=new Ro({fill:t.color??"#ffffff",fontSize:Math.round(i*$*Ar),fontFamily:s,align:o,...t.stroke&&t.strokeWidth?{stroke:{color:t.stroke,width:t.strokeWidth*$*Ar}}:{}});if(t.backgroundColor&&t.backgroundColor!=="transparent"){const a=ia.measureText(e.text,c),h=a.width/Ar,u=a.height/Ar,d=(t.backgroundPadding??.3)*$,f=o==="center"?.5:o==="right"?1:0,p=Fe(e.x)-f*h-d,g=Fe(e.y)-u/2-d,w=new te;w.rect(p,g,h+d*2,u+d*2),w.fill({color:t.backgroundColor,alpha:n}),this.container.addChild(w)}const l=new vt({text:e.text,style:c});l.scale.set(1/Ar),l.anchor.x=o==="center"?.5:o==="right"?1:0,l.anchor.y=.5,l.position.set(Fe(e.x),Fe(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 st(r,e){const t=localStorage.getItem(r),[n,i]=z(t!==null?t==="true":e);return[n,s=>{i(s),localStorage.setItem(r,String(s))}]}function zh(r,e){const t=localStorage.getItem(r),[n,i]=z(t??e);return[n,s=>{i(s),localStorage.setItem(r,s)}]}const[fl,Bh]=st(ye.widescreenMode,!0),[Bn,pl]=st(ye.showCreepLabels,!0),[gl,ml]=st(ye.showMapRoomNames,!1),[yl,vl]=st(ye.showUnclaimableRooms,!0),[ur,Wh]=st(ye.terrainEffects,!0),[ns,Hh]=st(ye.showRoomDecorations,!1),[is,Uh]=st(ye.roomDarkOverlay,!0),[bl,Vh]=st(ye.showRoomVisuals,!0),[ss,Yh]=zh(ye.spriteTheme,"default"),[wl,Xh]=st(ye.verboseCreepDetails,!0),[jh,qh]=st(ye.showMapVisuals,!0),Zh={id:"default",name:"Default",atlasUrl:`${on()}/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 Kh{constructor(){S(this,"cache",new Map);S(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=Mi.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 Js=new Kh,os=Symbol("store-raw"),br=Symbol("store-node"),dt=Symbol("store-has"),xl=Symbol("store-self");function _l(r){let e=r[Zt];if(!e&&(Object.defineProperty(r,Zt,{value:e=new Proxy(r,ef)}),!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 Et(r){let e;return r!=null&&typeof r=="object"&&(r[Zt]||!(e=Object.getPrototypeOf(r))||e===Object.prototype||Array.isArray(r))}function xr(r,e=new Set){let t,n,i,s;if(t=r!=null&&r[os])return t;if(!Et(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=xr(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=xr(i,e))!==i&&(r[s]=n))}return r}function Wn(r,e){let t=r[e];return t||Object.defineProperty(r,e,{value:t=Object.create(null)}),t}function Zr(r,e,t){if(r[e])return r[e];const[n,i]=z(t,{equals:!1,internal:!0});return n.$=i,r[e]=n}function Jh(r,e){const t=Reflect.getOwnPropertyDescriptor(r,e);return!t||t.get||!t.configurable||e===Zt||e===br||(delete t.value,delete t.writable,t.get=()=>r[Zt][e]),t}function $l(r){Ti()&&Zr(Wn(r,br),xl)()}function Qh(r){return $l(r),Reflect.ownKeys(r)}const ef={get(r,e,t){if(e===os)return r;if(e===Zt)return t;if(e===Es)return $l(r),t;const n=Wn(r,br),i=n[e];let s=i?i():r[e];if(e===br||e===dt||e==="__proto__")return s;if(!i){const o=Object.getOwnPropertyDescriptor(r,e);Ti()&&(typeof s!="function"||r.hasOwnProperty(e))&&!(o&&o.get)&&(s=Zr(n,e,s)())}return Et(s)?_l(s):s},has(r,e){return e===os||e===Zt||e===Es||e===br||e===dt||e==="__proto__"?!0:(Ti()&&Zr(Wn(r,dt),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:Qh,getOwnPropertyDescriptor:Jh};function Ve(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[dt]&&r[dt][e]&&i!==void 0&&r[dt][e].$()):(r[e]=t,r[dt]&&r[dt][e]&&i===void 0&&r[dt][e].$());let o=Wn(r,br),c;if((c=Zr(o,e,i))&&c.$(()=>t),Array.isArray(r)&&r.length!==s){for(let l=r.length;l<s;l++)(c=o[l])&&c.$();(c=Zr(o,"length",s))&&c.$(r.length)}(c=o[xl])&&c.$()}function Sl(r,e){const t=Object.keys(e);for(let n=0;n<t.length;n+=1){const i=t[n];Cl(i)||Ve(r,i,e[i])}}function Cl(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function tf(r,e){if(typeof e=="function"&&(e=e(r)),e=xr(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&&Ve(r,t,i)}Ve(r,"length",n)}else Sl(r,e)}function Fr(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&&Cl(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++)Fr(r,[n[l]].concat(e),t);return}else if(c&&o==="function"){for(let l=0;l<r.length;l++)n(r[l],l)&&Fr(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)Fr(r,[u].concat(e),t);return}else if(e.length>1){Fr(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=xr(s),n===void 0||Et(i)&&Et(s)&&!Array.isArray(s)?Sl(i,s):Ve(r,n,s))}function kl(...[r,e]){const t=xr(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=_l(t);Ql.registerGraph({value:t,name:e&&e.name});function s(...o){ea(()=>{n&&o.length===1?tf(t,o[0]):Fr(t,o)})}return[i,s]}const ls=Symbol("store-root");function Qs(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function hr(r,e,t,n,i){if(Qs(t))return;const s=e[t];if(r===s)return;const o=Array.isArray(r);if(t!==ls&&(!Et(r)||!Et(s)||o!==Array.isArray(s)||i&&r[i]!==s[i])){Ve(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,g,w;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++)hr(r[u],s,u,n,i);const L=new Array(r.length),A=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--)L[f]=s[d];if(u>f||u>d){for(h=u;h<=f;h++)Ve(s,h,r[h]);for(;h<r.length;h++)Ve(s,h,L[h]),hr(r[h],s,h,n,i);s.length>r.length&&Ve(s,"length",r.length);return}for(g=new Array(f+1),h=f;h>=u;h--)p=r[h],w=i&&p?p[i]:p,a=A.get(w),g[h]=a===void 0?-1:a,A.set(w,h);for(a=u;a<=d;a++)p=s[a],w=i&&p?p[i]:p,h=A.get(w),h!==void 0&&h!==-1&&(L[h]=s[a],h=g[h],A.set(w,h));for(h=u;h<r.length;h++)h in L?(Ve(s,h,L[h]),hr(r[h],s,h,n,i)):Ve(s,h,r[h])}else for(let a=0,h=r.length;a<h;a++)hr(r[a],s,a,n,i);s.length>r.length&&Ve(s,"length",r.length);return}const c=Object.keys(r);for(let a=0,h=c.length;a<h;a++)Qs(c[a])||hr(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&&Ve(s,l[a],void 0)}function rf(r,e={}){const{merge:t,key:n="id"}=e,i=xr(r);return s=>{if(!Et(s)||!Et(i))return i;const o=hr(i,{[ls]:s},ls,t,n);return o===void 0?s:o}}const Ss=new WeakMap;function eo(r,e){const[t,n]=kl(e),i={id:r,type:e.type,raw:t};return Ss.set(i,s=>n(rf(s,{key:"_id",merge:!1}))),i}const[_r,$r]=z([]);function nf(){$r([])}function Ir(r){$r(e=>e.filter(t=>t.id!==r))}function sf(r,e){const t=_r();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=Ss.get(s);l==null||l(c)}}i.push(s)}n&&$r(i)}function of(r){var i;const e=_r();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=Ss.get(s))==null||i(o),n.push(s)}t&&$r(n)}const[lf,ui]=z(null),[Kr,hi]=z(null),[We,fi]=z(null),[to,pi]=z(null),[yn,gi]=z(null),[Hn,mi]=z({}),[ln,ro]=z(null),[wr,af]=z(null),[Jr,cf]=z(null);function as(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 it(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 Ze(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 no(r){return r===0||r<0&&(r+1)%10===0||r>0&&r%10===0}function Sm(r,e){return no(r)||no(e)}function Cm(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 Tl(r){const e=r;if(!e)return!1;const t=e.tagName??"";return t==="INPUT"||t==="TEXTAREA"?!0:e.isContentEditable===!0}function df(r){const e=t=>{if(Tl(t.target))return;const n=r.currentRoom(),i=n?it(n):null;if(!i)return;const s=r.worldBounds(),o=(c,l)=>!s||as(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),Be(()=>window.removeEventListener("keydown",e))}const[be,Ml]=z(!1),[gt,Cs]=z(0),[cs,uf]=z(0),[Qr,El]=z(0),[Vr,en]=z(!1),[ks,hf]=z(1),[rt,yi]=z(!1);let An=null;function tn(){An!==null&&(clearInterval(An),An=null)}function Rl(){tn(),An=setInterval(()=>{const r=gt()+1;r>Qr()?(tn(),en(!1)):Cs(r)},Math.max(50,Math.round(1e3/ks())))}function Pl(r){const e=r,t=Math.max(0,e-2e5);El(e),uf(t),Cs(r),en(!1),tn(),Ml(!0)}function Un(){tn(),en(!1),Ml(!1)}function Vn(r){const e=Math.max(cs(),Math.min(Qr(),r));Cs(e)}function io(r){Vn(gt()+r)}function ff(){Vr()?(tn(),en(!1)):(en(!0),Rl())}function pf(r){hf(r),Vr()&&Rl()}class gf{constructor(e,t,n,i){S(this,"chunkCache",new Map);S(this,"inflight",new Map);this.room=e,this.shard=t,this.http=n,this.chunkSize=i}chunkBase(e){return e-e%this.chunkSize}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.http.game.roomHistory(this.room,e,this.shard).then(s=>(this.chunkCache.set(e,s),this.inflight.delete(e),s)).catch(s=>{throw this.inflight.delete(e),s});return this.inflight.set(e,i),i}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 mf=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'),yf=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'),vf=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'),bf=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"),wf=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"),xf=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:so,warn:_f,error:oo}=Pt("build"),rn={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},Yn={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}},[Mt,Tt]=z("view"),[fr,Ol]=z({name:"",color:"COLOR_WHITE",secondaryColor:"COLOR_WHITE"}),[Xt,ds]=z(null),[jt,Yr]=z(null),[ft,Ut]=z({structureType:"",structureName:""});fs(()=>{fe(()=>{const r=ft().structureType;if(!r)return;const e=We()??0,t=Yn[r];if(!t)return;const n=Kt()==="empty"&&r==="spawn"?Math.max(t[e]??0,1):t[e]??0;if(n===2500)return;(Hn()[r]??0)>=n&&(Ut({structureType:"",structureName:""}),mt())})});function mt(){ds(null)}function Xn(){Yr(null)}function Ll(){Ut({structureType:"",structureName:""})}function $f(r,e){const t=me(),n=ft(),i=Xt();if(!t||!n.structureType||!i){_f("missing requirements",{hasClient:!!t,structureType:n.structureType,pending:i});return}if(Kt()==="empty"&&n.structureType==="spawn"){so("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(()=>(ke("Spawn placed successfully","success"),mt(),t.stores.user.refreshWorldStatus())).catch(s=>{oo("place spawn failed:",s),ke(`Failed to place spawn: ${s.message}`,"error")});return}so("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(()=>{ke(`Construction site for ${n.structureType} created`,"success"),mt()}).catch(s=>{oo("create construction failed:",s),ke(`Failed to create construction site: ${s.message}`,"error")})}function Sf(){Tt("view"),mt(),Xn(),Ll()}function Cf(){var r;Tt("view"),mt(),((r=ue(jt))==null?void 0:r.type)!=="moveFlag"&&Xn(),Ll()}function lo(){const r=Mt(),e=Xt(),t=jt(),n=Kt();if(n==="empty")return(()=>{var i=mf(),s=i.firstChild,o=s.nextSibling;return o.$$click=()=>{Tt("build"),Ut({structureType:"spawn",structureName:""})},i})();if(n==="lost")return(()=>{var i=yf(),s=i.firstChild,o=s.nextSibling;return o.$$click=()=>{const c=me();c&&c.http.user.respawn().then(()=>{ke("Respawn successful","success"),c.stores.user.refreshWorldStatus()}).catch(l=>{ke(`Respawn failed: ${l.message}`,"error")})},i})();if((t==null?void 0:t.type)==="moveFlag")return(()=>{var i=vf(),s=i.firstChild,o=s.firstChild,c=o.nextSibling;return c.nextSibling,s.nextSibling,m(s,()=>t.name,c),m(s,()=>t.targetRoom,null),i})();if(r==="flag")return(()=>{var i=bf(),s=i.firstChild;return s.nextSibling,m(s,e?"Click again to confirm position":"Click to choose flag position"),i})();if(r==="build"){const i=ft(),s=We(),o=Hn(),c=i.structureType;if(!c)return(()=>{var f=wf(),p=f.firstChild,g=p.nextSibling;return g.nextSibling,f})();const l=Yn[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=xf(),p=f.firstChild,g=p.nextSibling;return g.nextSibling,m(p,`Click to build ${u} (${d})`),f})()}return null}Oe(["click"]);var kf=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>'),Tf=R("<div style=width:100%;height:100%;position:relative><div style=width:100%;height:100%>"),Mf=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">'),Ef=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:It,error:Nr}=Pt("room");function Rf(r){const e=y=>y==="default"?Zh:null;let t,n=null,i=null,s=null,o=null,c=null;const[l,a]=z(null),[h,u]=z(null),[d,f]=z(null),[p,g]=z(null),[w,L]=z(""),[A,N]=z(gt());fe(()=>N(gt()));let M=null;return tr(async()=>{if(!t)return;const y=await bs.create(t);a(y)}),Be(()=>{M!==null&&clearTimeout(M),n==null||n.destroy(),n=null,s==null||s.destroy(),s=null,o==null||o.destroy(),o=null;const y=l();y&&y.destroy()}),fe(()=>{const y=me();if(!y||be())return;const x=r.room,O=r.shard;u(null),f(null),g(null),L(""),En(null),nf(),cf(x),af(O),ui(null),hi(null),fi(null),pi(null),gi(null),mi({}),ro(null);const v=new gs;let C=!1;y.stores.room.terrain(x,O).then(k=>{C||u({room:x,data:k})}).catch(k=>{C||Nr(`terrain load failed for ${x}:`,k)}),ue(ns)&&y.http.game.roomDecorations(x,O).then(k=>{C||(It(`decorations loaded — ${x}: ${k.decorations.length} item(s)`),f({room:x,decoration:hh(k)}))}).catch(k=>{}),v.add(y.stores.room.subscribe(x,O)),v.add(y.stores.room.on("room:error",k=>{ke(`Room subscription error (${k.room}): ${k.message}`,"error",8e3)})),v.add(y.stores.room.on("room:update",k=>{var W,D;let _=0;const E={};let T=0,P=null,F=null,G=null;for(const B in k.objects){_++;const U=k.objects[B];if(!U)continue;const H=U.type;if(typeof H=="string")if(H==="constructionSite"){const q=U.structureType;typeof q=="string"&&(E[q]=(E[q]||0)+1)}else E[H]=(E[H]||0)+1;if(H==="controller"){if(typeof U.user=="string"){const Z=U.user,X=((D=(W=k.users)==null?void 0:W[Z])==null?void 0:D.username)??Z;F={userId:Z,username:X},typeof U.level=="number"&&(T=U.level),typeof U.progress=="number"&&(P=U.progress)}const q=U.reservation;q&&typeof q.user=="string"&&typeof q.endTime=="number"&&(G={user:q.user,endTime:q.endTime})}}k.diff||It(`objects loaded — ${x}: ${_} objects, tick=${k.gameTime}`),g({objects:k.objects,diff:k.diff,users:k.users}),L(k.visual),En(k.gameTime??null),bc(k.gameTime),ui(_),hi(F),fi(T||null),pi(P),gi(G),mi(E),ro(k.users??null)})),Be(()=>{C=!0,v.dispose()})}),fe(()=>{var E,T;const y=me();if(!y||!be())return;L("");const x=r.room,O=r.shard,v=Yo()??!0,C=((T=(E=vs())==null?void 0:E.serverData)==null?void 0:T.historyChunkSize)??(v?20:100),k=ue(ln)??void 0,_=new gf(x,O,y.http,C);fe(()=>{const P=gt();let F=!1;yi(!0),_.getStateAtTick(P).then(G=>{var Z;if(F)return;if(yi(!1),G.clampedTo!==void 0){El(G.clampedTo),Vn(G.clampedTo);return}g({objects:G.objects,diff:void 0,users:k}),En(G.gameTime);let W=0;const D={};let B=0,U=null,H=null,q=null;for(const X in G.objects){W++;const K=G.objects[X];if(!K)continue;const he=K.type;if(typeof he=="string")if(he==="constructionSite"){const se=K.structureType;typeof se=="string"&&(D[se]=(D[se]||0)+1)}else D[he]=(D[he]||0)+1;if(he==="controller"){if(typeof K.user=="string"){const ie=K.user,pe=((Z=k==null?void 0:k[ie])==null?void 0:Z.username)??ie;H={userId:ie,username:pe},typeof K.level=="number"&&(B=K.level),typeof K.progress=="number"&&(U=K.progress)}const se=K.reservation;se&&typeof se.user=="string"&&typeof se.endTime=="number"&&(q={user:se.user,endTime:se.endTime})}}ui(W),hi(H),fi(B||null),pi(U),gi(q),mi(D)}).catch(G=>{F||(yi(!1),ke(`History load failed for tick ${P}: ${G.message}`,"error",5e3))}),Be(()=>{F=!0})})}),fe(()=>{const y=l();if(!y)return;r.room,r.shard,Cf(),y.hoverLayer.clearPendingTile();const x=ue(jt);(x==null?void 0:x.type)==="moveFlag"?Yr({...x,targetRoom:r.room}):y.resetView(),c==null||c.destroy(),c=null,y.clear(),y.resetView(),n==null||n.destroy(),n=null,s==null||s.destroy(),s=null,o==null||o.destroy(),o=null;const O=ue(h);if(O&&O.room===r.room){It(`terrain applied immediately (pre-loaded) — ${r.room}`);const T=ue(d);c=hn(O.data,y.app.renderer,(T==null?void 0:T.room)===r.room?T.decoration.terrain:void 0),Or(c,ue(ur)),c.zIndex=Ht.terrain,y.world.addChild(c),y.bringNavOverlayToTop()}const v=r.room,C=r.shard,k=it(v),_=ue(()=>r.onNavigate),E=ue(ii);if(k&&_){const T=(F,G)=>!E||as(F,G,E),P=F=>{_(F,C)};y.setupNavigationZones({west:T(k.x-1,k.y)?()=>P(Ze(k.x-1,k.y)):void 0,east:T(k.x+1,k.y)?()=>P(Ze(k.x+1,k.y)):void 0,north:T(k.x,k.y-1)?()=>P(Ze(k.x,k.y-1)):void 0,south:T(k.x,k.y+1)?()=>P(Ze(k.x,k.y+1)):void 0})}}),fe(()=>{const y=l();if(!y)return;const x=ue(()=>r.room),O=ue(()=>r.shard),v=it(x);if(v&&r.onNavigate){const C=r.onNavigate,k=ii(),_=(T,P)=>!k||as(T,P,k),E=T=>{C(T,O)};df({currentRoom:()=>r.room,worldBounds:ii,onMove:(T,P)=>E(Ze(T,P))}),y.setupNavigationZones({west:_(v.x-1,v.y)?()=>E(Ze(v.x-1,v.y)):void 0,east:_(v.x+1,v.y)?()=>E(Ze(v.x+1,v.y)):void 0,north:_(v.x,v.y-1)?()=>E(Ze(v.x,v.y-1)):void 0,south:_(v.x,v.y+1)?()=>E(Ze(v.x,v.y+1)):void 0})}}),fe(()=>{const y=Mt(),x=l();y==="view"&&x&&(mt(),x.hoverLayer.clearPendingTile())}),fe(()=>{const y=l(),x=Xt();y&&(x?y.hoverLayer.setPendingTile(x.tx,x.ty):y.hoverLayer.clearPendingTile())}),fe(()=>{const y=l(),x=h();if(!y||!x||x.room!==r.room)return;if(c!=null&&c.parent){It(`terrain already in scene, skipping — ${r.room}`);return}It(`terrain applied (async) — ${r.room}`);const O=ue(d);c=hn(x.data,y.app.renderer,(O==null?void 0:O.room)===r.room?O.decoration.terrain:void 0),Or(c,ue(ur)),y.world.addChildAt(c,0),y.bringNavOverlayToTop()}),fe(()=>{if(ns())return;f(null);const y=ue(l),x=ue(h);!y||!x||x.room!==r.room||c!=null&&c.parent&&(c.destroy(),c=hn(x.data,y.app.renderer),Or(c,ue(ur)),y.world.addChildAt(c,0),y.bringNavOverlayToTop(),n==null||n.setRoadColor(xs))}),fe(()=>{const y=l(),x=d(),O=ue(h);!y||!x||x.room!==r.room||!O||O.room!==r.room||c!=null&&c.parent&&(It(`decoration arrived, rebuilding terrain layer — ${r.room}`),c.destroy(),c=hn(O.data,y.app.renderer,x.decoration.terrain),Or(c,ue(ur)),y.world.addChildAt(c,0),y.bringNavOverlayToTop(),n&&x.decoration.roadColor!=null&&n.setRoadColor(x.decoration.roadColor))}),fe(()=>{var P,F;const y=l(),x=p();if(!y)return;if(!x){n==null||n.clear(),s==null||s.clear(),y.clearLighting();return}const{objects:O,diff:v,users:C}=x;if(!n){It(`object layer created — ${r.room}`),n=new Ah(y.app.ticker,Bn(),(P=Ue())==null?void 0:P._id,(F=Ue())==null?void 0:F.badge,C),n.setTheme(e(ue(ss)),Js),n.setInstantMode(ue(be));const G=ue(d);(G==null?void 0:G.room)===r.room&&G.decoration.roadColor!=null&&n.setRoadColor(G.decoration.roadColor),n.container.label="objects",n.container.zIndex=Ht.objects,y.world.addChild(n.container),s=new Ih(y.app.ticker),s.container.label="animations",s.container.zIndex=Ht.animations,y.world.addChild(s.container),o=new Fh,o.container.zIndex=Ht.visuals,y.world.addChild(o.container),y.setTileHandlers((W,D)=>{},(W,D,B)=>{const U=r.room,H=r.shard,q=Mt(),Z=jt();if((Z==null?void 0:Z.type)==="moveFlag"){const se=me();if(!se)return;const{name:ie,room:pe,color:ee,secondaryColor:ge,targetRoom:Pe}=Z;se.http.game.removeFlag(pe,ie).then(()=>se.http.game.createFlag(Pe,W,D,ie,ee,ge,H??void 0)).then(()=>{ke(`Flag "${ie}" moved`,"success"),Xn()}).catch(Le=>{Nr("move flag failed:",Le),ke(`Failed to move flag "${ie}"`,"error"),Xn()});return}if(q==="flag"){const se=Xt();if(!se||se.tx!==W||se.ty!==D){ds({tx:W,ty:D}),y.hoverLayer.setPendingTile(W,D);return}const ie=me();if(!ie)return;const pe=fr(),ee=pe.name.trim();if(!ee){ke("Flag name is required","error");return}const ge=rn[pe.color]??0,Pe=rn[pe.secondaryColor]??0;ie.http.game.createFlag(U,W,D,ee,ge,Pe,H??void 0).then(()=>{ke(`Flag "${ee}" created`,"success"),mt(),y.hoverLayer.clearPendingTile(),ie.http.game.genUniqueFlagName().then(Le=>Ol(je=>({...je,name:Le.name}))).catch(Le=>Nr("gen unique flag name failed:",Le))}).catch(Le=>Nr("create flag failed:",Le));return}if(q==="build"){if(!B&&!ft().structureType){ke("Select a structure type first","error");return}if(B){if(!n)return;const ie=n.getObjectsAtTile(W,D).filter(({obj:ee})=>ee.type==="constructionSite");if(ie.length===0){ke("No construction sites on this tile","error");return}const pe=me();if(!pe)return;pe.http.game.removeConstructionSite(U,ie.map(({id:ee})=>ee),H??void 0).then(()=>{ke(`Removed ${ie.length} construction site${ie.length>1?"s":""}`,"success"),mt(),y.hoverLayer.clearPendingTile()}).catch(ee=>{Nr("remove construction sites failed:",ee),ke(`Failed to remove construction sites: ${ee.message}`,"error")});return}ds({tx:W,ty:D}),y.hoverLayer.setPendingTile(W,D),$f(U,H);return}if(mt(),y.hoverLayer.clearPendingTile(),!n)return;const X=n.getObjectsAtTile(W,D);if(X.length===0){B||($r([]),y.hoverLayer.clearSelection());return}let K=[..._r()];if(B){const se=new Set(X.map(pe=>pe.id));if(K.some(pe=>se.has(pe.id)))K=K.filter(pe=>!se.has(pe.id));else{const pe=X.filter(({id:ee})=>!K.some(ge=>ge.id===ee)).map(({id:ee,obj:ge})=>eo(ee,ge));K=[...K,...pe]}}else K=X.map(({id:se,obj:ie})=>eo(se,ie));$r(K);const he=K.map(({id:se,type:ie})=>({id:se,type:ie,visual:n.getVisualById(se)})).filter(se=>se.visual!=null);y.hoverLayer.setSelectedObjects(he)},()=>{var D;const W=Mt();(W==="build"||W==="flag"||((D=jt())==null?void 0:D.type)==="moveFlag")&&(Sf(),y.hoverLayer.clearPendingTile())})}v?sf(v,O):of(O);const k=be()?Math.round(1e3/ue(ks)):In()??2e3,_=k*.6,E=Math.round(k*.9);n.setMoveDuration(E),i={objects:O,users:C},n.update(O,v,C,Ee()??void 0),n.setShowLabels(ue(Bn));const T=new Set;if(s){s.clear();for(const G in O){const W=O[G];if(!W||W.type!=="creep")continue;const D=W.actionLog;if(!D)continue;const B=D.harvest;B&&s.addHarvest(B.x,B.y,W.x,W.y,_);const U=D.upgradeController;U&&s.addUpgradeController(W.x,W.y,U.x,U.y,_);const H=D.build;H&&(s.addBuild(W.x,W.y,H.x,H.y,_),n==null||n.triggerBuildAt(H.x,H.y,_));const q=D.transfer;q&&s.addTransfer(W.x,W.y,q.x,q.y,_);const Z=D.say;Z&&typeof Z.message=="string"&&Z.message.length>0&&(n==null||n.triggerSay(G,Z.message),T.add(G))}}n.pruneSayBubblesExcept(T),ue(is)&&y.updateLighting(O)}),fe(()=>{const y=w();o==null||o.update(bl()?y:"")}),fe(()=>{n==null||n.setInstantMode(be())}),fe(()=>{const y=ur();c&&Or(c,y)}),fe(()=>{const y=l();if(!y)return;const x=is();y.darkOverlay.visible=x,y.lightLayer.visible=x,x||y.clearLighting()}),fe(()=>{const y=e(ss());n&&(n.setTheme(y,Js),i&&(n.clear(),n.update(i.objects,void 0,i.users)))}),(()=>{var y=Tf(),x=y.firstChild;return pr(O=>t=O,x),m(y,(()=>{var O=re(()=>!!lo());return()=>O()&&(()=>{var v=Mf();return m(v,lo),I(C=>Y(v,"pointer-events",Kt()==="empty"||Kt()==="lost"?"auto":"none")),v})()})(),null),m(y,(()=>{var O=re(()=>!be()&&Ee()!==null);return()=>O()&&(()=>{var v=Ef();return v.firstChild,m(v,Ee,null),v})()})(),null),m(y,b(j,{get when(){return be()},get children(){var O=kf(),v=O.firstChild,C=v.nextSibling,k=C.firstChild,_=k.nextSibling,E=_.nextSibling;return v.$$input=T=>{const P=parseInt(T.currentTarget.value,10);N(P),M!==null&&clearTimeout(M),M=setTimeout(()=>{M=null,Vn(P)},150)},m(k,cs),m(_,(()=>{var T=re(()=>!!rt());return()=>T()?"Loading…":`Tick ${gt()}`})()),m(E,Qr),I(T=>{var P=cs(),F=Qr(),G=rt()?"#f0883e":"#8b949e";return P!==T.e&&_e(v,"min",T.e=P),F!==T.t&&_e(v,"max",T.t=F),G!==T.a&&Y(_,"color",T.a=G),T},{e:void 0,t:void 0,a:void 0}),I(()=>v.value=A()),O}}),null),y})()}Oe(["input"]);var Pf=R("<div style=position:fixed;bottom:16px;right:16px;display:flex;flex-direction:column;gap:8px;z-index:9999;pointer-events:none>"),Of=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 Lf(){return(()=>{var r=Pf();return m(r,b($e,{get each(){return cc()},children:e=>(()=>{var t=Of();return m(t,()=>e.message),I(n=>Y(t,"background",e.type==="error"?"#da3633":"#238636")),t})()})),r})()}const[$t,Af]=z(!0),[lt,Al]=z(!0),[lr,Il]=z(!1),[vi,Ft]=z("");let zt;function If(r){zt=r}function Nf(r){Ft(r),Al(!0),requestAnimationFrame(()=>{zt==null||zt.focus();const e=r.length;zt==null||zt.setSelectionRange(e,e)})}function Nl(){Af(r=>!r)}function Dl(){Al(r=>!r)}function Gl(){Il(r=>!r)}const[Sr,Fl]=z(zo(ye.memoryWatches,[])),[nn,zl]=z(null),[us,Df]=kl({});function Gf(r){const e=r.trim();e&&(Fl(t=>t.includes(e)?t:[...t,e]),ys(ye.memoryWatches,Sr()))}function Ff(r){Fl(e=>e.filter(t=>t!==r)),ys(ye.memoryWatches,Sr())}function Bl(){zl(null)}function zf(r,e){zl({creepId:r,name:e})}function Bf(r,e){const t=[...e];if(r){const n=`creeps.${r.name}`;t.includes(n)||t.push(n)}return t}function Wf(r){const e=new Map,t=()=>{const s=me();if(!s)return;const o=new Set(Bf(nn(),Sr()));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(()=>{Sr(),nn(),t()});const n=me();let i=null;return n?i=n.stores.user.on("user:memory",s=>{console.log("[memoryStore] user:memory received",s.path,s.value),Df(s.path,s.value),console.log("[memoryStore] memoryValues after set:",JSON.stringify(us))}):console.warn("[memoryStore] no client available when initMemorySubscriptions called"),Be(()=>{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()}}fs(()=>{fe(()=>{const r=nn();if(!r)return;_r().some(t=>t.id===r.creepId)||Bl()})});var Hf=R("<button style=color:#8b949e>"),Uf=R("<span style=width:18px;flex-shrink:0>"),Vf=R("<span style=color:#484f58;font-style:italic>{…}"),Yf=R("<span style=color:#484f58;font-style:italic>"),Xf=R("<button title=Reload>"),jf=R('<span title="Click to edit"style=cursor:text;flex:1>'),qf=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">'),Zf=R("<button title=Save style=color:#3fb950>"),Kf=R("<button title=Discard style=color:#f85149>"),Jf=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:ao}=Pt("MemoryTree");function tt(r){return r!==null&&typeof r=="object"&&"__screeps_object__"in r}const Qf={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"},Dr={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 vn(r){return r.replace(/^Memory\.?/,"")}function Wl(r){const[e,t]=z((r.depth??0)<2),n=()=>r.depth??0,[i,s]=z(!1),[o,c]=z(""),[l,a]=z(!1),[h,u]=z(void 0),d=()=>tt(r.value)&&h()!==void 0?h():r.value,f=()=>{const x=d();return!tt(x)&&x!==null&&typeof x=="object"},p=()=>f()?Object.entries(d()):[],g=()=>p().length,w=async()=>{a(!0);try{const x=me();if(!x)return;const O=vn(r.path),v=await x.http.user.memory.get(O,r.shard),C=v.data==="[object Object]"?{__screeps_object__:!0}:v.data;u(C)}catch(x){ao("fetch memory failed",x)}finally{a(!1)}},L=()=>{u(void 0),w()};tr(()=>{e()&&tt(r.value)&&h()===void 0&&w()});const A=async()=>{if(tt(r.value)&&h()===void 0){await w(),t(!0);return}e()&&u(void 0),t(x=>!x)},N=async()=>{var k;const x=o().trim();let O;if(x==="null")O=null;else if(x==="true")O=!0;else if(x==="false")O=!1;else{const _=Number(x);if(!Number.isNaN(_)&&x!=="")O=_;else try{O=JSON.parse(x)}catch{O=x}}const v=me();if(!v)return;const C=vn(r.path);try{await v.http.user.memory.set(C,O,r.shard)}catch(_){ao("set memory failed",_),s(!1);return}s(!1),(k=r.onRefresh)==null||k.call(r)},M=()=>{const x=d();return f()?"#c9d1d9":typeof x=="string"?"#3fb950":typeof x=="number"?"#79c0ff":typeof x=="boolean"?"#a371f7":"#8b949e"},y=()=>{const x=d();return x===null?"null":x===void 0?"undefined":typeof x=="string"?JSON.stringify(x):String(x)};return(()=>{var x=Jf(),O=x.firstChild,v=O.firstChild,C=v.nextSibling,k=C.nextSibling;return m(O,b(j,{get when(){return f()||tt(d())},get children(){var _=Hf();return _.$$click=()=>void A(),m(_,b(j,{get when(){return l()},get children(){return b(cd,{size:12,style:{animation:"spin 1s linear infinite"}})}}),null),m(_,b(j,{get when(){return!l()},get children(){return b(j,{get when(){return e()},get fallback(){return b(jo,{size:12})},get children(){return b(Fc,{size:12})}})}}),null),I(E=>{var T={...Dr},P=e()?"Collapse":"Expand",F=l();return E.e=J(_,T,E.e),P!==E.t&&_e(_,"title",E.t=P),F!==E.a&&(_.disabled=E.a=F),E},{e:void 0,t:void 0,a:void 0}),_}}),v),m(O,b(j,{get when(){return re(()=>!f())()&&!tt(d())},get children(){return Uf()}}),v),m(v,()=>r.label),m(O,b(j,{get when(){return tt(d())},get children(){return Vf()}}),k),m(O,b(j,{get when(){return f()},get children(){var _=Yf();return m(_,(()=>{var E=re(()=>!!Array.isArray(d()));return()=>E()?`[${g()}]`:`{${g()}}`})()),_}}),k),m(O,b(j,{get when(){return re(()=>!!tt(r.value))()&&!l()},get children(){var _=Xf();return _.$$click=()=>L(),m(_,b(Ld,{size:11})),I(E=>J(_,Dr,E)),_}}),k),m(O,b(j,{get when(){return re(()=>!f())()&&!tt(d())},get children(){return[b(j,{get when(){return!i()},get children(){var _=jf();return _.$$click=()=>{c(y()),s(!0)},m(_,y),I(E=>Y(_,"color",M())),_}}),b(j,{get when(){return i()},get children(){return[(()=>{var _=qf();return _.$$keydown=E=>{E.key==="Enter"&&N(),E.key==="Escape"&&s(!1)},_.$$input=E=>c(E.currentTarget.value),I(()=>_.value=o()),_})(),(()=>{var _=Zf();return _.$$mousedown=E=>{E.preventDefault(),N()},m(_,b(Xo,{size:12})),I(E=>J(_,{...Dr},E)),_})(),(()=>{var _=Kf();return _.$$mousedown=E=>{E.preventDefault(),s(!1)},m(_,b(Jt,{size:12})),I(E=>J(_,{...Dr},E)),_})()]}})]}}),k),k.$$click=()=>Nf(`Memory.${vn(r.path)} = `),m(k,b(Fd,{size:11})),m(x,b(j,{get when(){return re(()=>!!f())()&&e()},get children(){return b($e,{get each(){return p()},children:([_,E])=>{const T=Array.isArray(d())?`${r.path}[${_}]`:`${r.path}.${_}`;return b(Wl,{value:E,path:T,label:_,get shard(){return r.shard},get depth(){return n()+1},get onRefresh(){return re(()=>!!tt(r.value))()?L:r.onRefresh}})}})}}),null),I(_=>{var E={"padding-left":n()>0?"14px":"0",...Qf},T=Dr,P=`Insert Memory.${vn(r.path)} = into console`;return _.e=J(x,E,_.e),_.t=J(k,T,_.t),P!==_.a&&_e(k,"title",_.a=P),_},{e:void 0,t:void 0,a:void 0}),x})()}function co(r){return b(Wl,{get value(){return r.value},get path(){return r.path},get label(){return r.label},get shard(){return r.shard},depth:0})}Oe(["click","input","keydown","mousedown"]);var ep=R("<div style=color:#484f58;font-style:italic>No paths watched — add one below."),tp=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'),rp=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">'),np=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">'),ip=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>'),uo=R("<div style=width:4px;flex-shrink:0;cursor:col-resize>"),sp=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'),op=R("<div style=flex:1;display:flex;overflow:hidden>"),lp=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
+ `),ap=R("<div style=color:#484f58;font-style:italic>No log output yet…"),cp=R("<div style=margin-bottom:4px;color:#f85149;white-space:pre-wrap;word-break:break-word>"),dp=R("<div style=margin-bottom:4px;color:#c9d1d9;white-space:pre-wrap;word-break:break-word>"),up=R("<div style=color:#484f58;font-style:italic>No command results yet…"),hp=R("<div style=margin-bottom:4px;color:#58a6ff;white-space:pre-wrap;word-break:break-word>");const{error:fp}=Pt("console");function pp(r){const[e,t]=z(""),n=()=>r.shard??wr();tr(()=>{Wf(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=tp(),c=o.firstChild,l=c.nextSibling,a=l.firstChild,h=a.nextSibling,u=h.firstChild;return m(c,b(j,{get when(){return nn()},children:d=>{const f=`creeps.${d().name}`;return(()=>{var p=rp(),g=p.firstChild,w=g.firstChild,L=w.nextSibling,A=L.nextSibling;return m(w,f),ut(A,"click",Bl,!0),m(A,b(Jt,{size:12})),m(p,b(co,{get value(){return us[f]},path:`Memory.${f}`,label:f,get shard(){return n()}}),null),I(N=>J(A,s,N)),p})()}}),null),m(c,b($e,{get each(){return Sr()},children:d=>(()=>{var f=np(),p=f.firstChild,g=p.firstChild,w=g.nextSibling;return m(g,d),w.$$click=()=>Ff(d),m(w,b(Jt,{size:12})),m(f,b(co,{get value(){return us[d]},path:`Memory.${d}`,label:d,get shard(){return n()}}),null),I(L=>J(w,s,L)),f})()}),null),m(c,b(j,{get when(){return re(()=>Sr().length===0)()&&!nn()},get children(){return ep()}}),null),l.addEventListener("submit",d=>{d.preventDefault(),Gf(e()),t("")}),a.$$input=d=>t(d.currentTarget.value),m(h,b(Rd,{size:14}),u),I(d=>{var f=`${r.width*100}%`,p={...i};return f!==d.e&&Y(o,"width",d.e=f),d.t=J(c,p,d.t),d},{e:void 0,t:void 0}),I(()=>a.value=e()),o})()}function gp(r){const[e,t]=z([]),[n,i]=z(!0),s=[1,1,1],[o,c]=z(zo(ye.consoleWeights,[...s])),[l,a]=z(null);let h,u,d,f=0;tr(()=>{const D=me();if(!D)return;const B=new gs;B.add(D.stores.user.subscribe("console")),B.add(D.stores.user.on("user:console",U=>{const H=U.messages,q={id:f++,log:H.log??[],results:H.results??[],error:H.error??[]};t(Z=>{const X=[...Z,q];return X.length>200?X.slice(X.length-200):X})})),Be(()=>B.dispose())}),fe(()=>{e(),n()&&requestAnimationFrame(()=>{$t()&&h&&(h.scrollTop=h.scrollHeight),lt()&&u&&(u.scrollTop=u.scrollHeight)})});const p=(D,B,U)=>{var q,Z;const H=!D&&!B&&!U;H&&!r.isCollapsed&&((q=r.onToggle)==null||q.call(r)),!H&&r.isCollapsed&&((Z=r.onToggle)==null||Z.call(r))};fe(()=>{p($t(),lt(),lr())});const g=()=>{const D=o(),B=[$t(),lt(),lr()],U=B.filter(Boolean).length;if(U===0)return[0,0,0];if(U===1){const Z=B.findIndex(Boolean);return[0,0,0].map((X,K)=>K===Z?1:0)}const q=B.map((Z,X)=>Z?D[X]:0).reduce((Z,X)=>Z+X,0);if(q===0){const Z=1/U;return[0,0,0].map((X,K)=>B[K]?Z:0)}return B.map((Z,X)=>Z?D[X]/q:0)};fe(()=>{ys(ye.consoleWeights,o())});const w=D=>B=>{B.preventDefault(),B.stopPropagation(),a(D),document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("pointermove",L),window.addEventListener("pointerup",A,{once:!0})},L=D=>{const B=l();if(B===null)return;const U=d;if(!U)return;const H=U.getBoundingClientRect(),q=Math.max(.02,Math.min(.98,(D.clientX-H.left)/H.width)),Z=[...o()],X=[$t(),lt(),lr()];if(B===0){const K=X[0],he=X[1];if(!K||!he)return;const se=q/(1-q);Z[0]=se,Z[1]=1,c(Z)}else{const K=X[1],he=X[2];if(!K||!he)return;const se=q/(1-q);Z[1]=se,Z[2]=1,c(Z)}},A=()=>{a(null),document.body.style.cursor="",document.body.style.userSelect="",window.removeEventListener("pointermove",L)},[N,M]=z([]),[y,x]=z(null),[O,v]=z(""),C=D=>{const B=N();if(B.length!==0){if(D.key==="ArrowUp"){D.preventDefault();const U=y();U===null?(v(vi()),x(B.length-1),Ft(B[B.length-1])):U>0&&(x(U-1),Ft(B[U-1]))}else if(D.key==="ArrowDown"){D.preventDefault();const U=y();if(U===null)return;U<B.length-1?(x(U+1),Ft(B[U+1])):(x(null),Ft(O()))}}},k=async D=>{D.preventDefault();const B=me(),U=vi().trim();if(!(!B||!U))try{await B.http.user.console(U,r.shard??"shard0"),M(H=>[...H,U]),x(null),v(""),Ft("")}catch(H){fp("command failed:",H)}},_=D=>({background:D?"#30363d":"transparent",border:`1px solid ${D?"#58a6ff":"transparent"}`,color:D?"#c9d1d9":"#8b949e","font-size":"12px",cursor:"pointer",padding:"2px 10px","border-radius":"4px"}),E=()=>e().flatMap(D=>D.log),T=()=>e().flatMap(D=>D.error),P=()=>e().flatMap(D=>D.results),F={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"},G={background:"transparent",border:"none",color:"#8b949e",cursor:"pointer",padding:"4px","border-radius":"4px",display:"flex","align-items":"center","justify-content":"center"},W=()=>{i(!0),requestAnimationFrame(()=>{$t()&&h&&(h.scrollTop=h.scrollHeight),lt()&&u&&(u.scrollTop=u.scrollHeight)})};return(()=>{var D=lp(),B=D.firstChild,U=B.firstChild,H=U.nextSibling,q=H.nextSibling;return B.nextSibling,ut(U,"click",Nl,!0),ut(H,"click",Dl,!0),ut(q,"click",Gl,!0),m(D,b(j,{get when(){return!r.isCollapsed},get children(){var Z=op();return pr(X=>d=X,Z),m(Z,b(j,{get when(){return $t()},get children(){var X=ip(),K=X.firstChild,he=K.firstChild,se=he.nextSibling,ie=K.nextSibling;he.$$click=()=>n()?i(!1):W(),m(he,(()=>{var ee=re(()=>!!n());return()=>ee()?b(Sd,{size:16}):b(Td,{size:16})})()),se.$$click=()=>t([]),m(se,b(Pn,{size:16})),ie.addEventListener("scroll",()=>{h&&i(h.scrollHeight-h.scrollTop-h.clientHeight<20)});var pe=h;return typeof pe=="function"?pr(pe,ie):h=ie,m(ie,(()=>{var ee=re(()=>E().length===0&&T().length===0);return()=>ee()&&ap()})(),null),m(ie,b($e,{get each(){return T()},children:ee=>(()=>{var ge=cp();return ge.innerHTML=ee,ge})()}),null),m(ie,b($e,{get each(){return E()},children:ee=>(()=>{var ge=dp();return ge.innerHTML=ee,ge})()}),null),I(ee=>{var ge=`${g()[0]*100}%`,Pe=n()?"Pause scrolling":"Resume scrolling",Le=G,je=G,Je={...F};return ge!==ee.e&&Y(X,"width",ee.e=ge),Pe!==ee.t&&_e(he,"title",ee.t=Pe),ee.a=J(he,Le,ee.a),ee.o=J(se,je,ee.o),ee.i=J(ie,Je,ee.i),ee},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),X}}),null),m(Z,b(j,{get when(){return re(()=>!!$t())()&&lt()},get children(){var X=uo();return ut(X,"pointerdown",w(0),!0),I(K=>Y(X,"background",l()===0?"#388bfd":"#21262d")),X}}),null),m(Z,b(j,{get when(){return lt()},get children(){var X=sp(),K=X.firstChild,he=K.nextSibling,se=he.firstChild,ie=se.nextSibling;ie.nextSibling,K.addEventListener("scroll",()=>{u&&i(u.scrollHeight-u.scrollTop-u.clientHeight<20)});var pe=u;return typeof pe=="function"?pr(pe,K):u=K,m(K,(()=>{var ee=re(()=>P().length===0);return()=>ee()&&up()})(),null),m(K,b($e,{get each(){return P()},children:ee=>(()=>{var ge=hp();return ge.innerHTML=ee,ge})()}),null),he.addEventListener("submit",k),ie.$$keydown=C,ie.$$input=ee=>{x(null),Ft(ee.currentTarget.value)},pr(ee=>If(ee),ie),I(ee=>{var ge=`${g()[1]*100}%`,Pe={...F};return ge!==ee.e&&Y(X,"width",ee.e=ge),ee.t=J(K,Pe,ee.t),ee},{e:void 0,t:void 0}),I(()=>ie.value=vi()),X}}),null),m(Z,b(j,{get when(){return re(()=>!!lt())()&&lr()},get children(){var X=uo();return ut(X,"pointerdown",w(1),!0),I(K=>Y(X,"background",l()===1?"#388bfd":"#21262d")),X}}),null),m(Z,b(j,{get when(){return lr()},get children(){return b(pp,{get shard(){return r.shard??null},get width(){return g()[2]}})}}),null),I(X=>Y(Z,"user-select",l()!==null?"none":"auto")),Z}}),null),I(Z=>{var X=_($t()),K=_(lt()),he=_(lr());return Z.e=J(U,X,Z.e),Z.t=J(H,K,Z.t),Z.a=J(q,he,Z.a),Z},{e:void 0,t:void 0,a:void 0}),D})()}Oe(["input","click","pointerdown","keydown"]);var mp=R("<div style=display:flex;gap:5px;flex-wrap:wrap>"),yp=R("<div style=width:18px;height:18px;border-radius:50%;cursor:pointer;flex-shrink:0>");const vp=[{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 jn(r){return(()=>{var e=mp();return m(e,b($e,{each:vp,children:t=>(()=>{var n=yp();return n.$$click=()=>r.onChange(t.value),I(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&&_e(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})()}Oe(["click"]);var yt=R("<div>"),Cr=R("<div style=font-variant-numeric:tabular-nums>"),bp=R("<span style=font-variant-numeric:tabular-nums;font-weight:400> / "),wp=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">'),xp=R('<div style="padding:3px 8px;background:#0d1117;color:#8b949e">'),_p=R('<div style="padding:3px 8px;background:#0d1117;color:#c9d1d9;font-variant-numeric:tabular-nums">'),Hl=R("<div>Owner"),Ts=R("<div>Hits"),qn=R("<div style=font-variant-numeric:tabular-nums> / "),$p=R("<div>Time to live"),Sp=R("<div>Fatigue"),Cp=R('<div style="display:flex;flex-wrap:wrap;gap:2px 10px;padding:0 8px 8px;background:#0d1117">'),kp=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>'),Ul=R("<div><div>"),Tp=R("<div style=width:11px;height:11px;border-radius:50%;flex-shrink:0>"),Mp=R("<span style=font-size:10px;font-variant-numeric:tabular-nums><span style=color:#8b949e>×</span><span>"),Ep=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">'),Rp=R("<div style=padding:8px;display:flex;flex-direction:column;gap:8px;background:#0d1117><label>Primary color</label><label>Secondary color"),Pp=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'),Op=R("<div>Reserved by"),Lp=R("<div>Reservation"),ho=R("<div style=font-variant-numeric:tabular-nums> ticks"),Vl=R("<div>Level"),Ap=R("<div>Safe modes"),Ip=R("<div>Power"),Np=R("<div>Downgrade in"),Dp=R("<div>Safe mode active"),Gp=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>'),Fp=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">'),zp=R("<div><div><div>Owner</div><div>"),Bp=R("<div>Notify when attacked"),Wp=R("<div style=display:flex;align-items:center><button style=background:transparent;border:none;cursor:pointer;padding:0;display:flex;align-items:center>"),Hp=R("<div><div>Energy</div><div style=font-variant-numeric:tabular-nums> / "),Up=R("<div><div>Hits</div><div style=font-variant-numeric:tabular-nums> / "),Vp=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>'),Yp=R("<div>Decay in"),Xp=R("<div>Energy cap"),jp=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">Was: </div><div>'),qp=R("<div style=width:8px;height:8px;border-radius:50%;flex-shrink:0>"),bi=R('<button style="background:transparent;border:none;cursor:pointer;padding:0 2px;display:flex;align-items:center;justify-content:center;flex-shrink:0">'),Zp=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">'),Kp=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">×'),Jp=R("<span style=font-weight:400;color:#8b949e>"),Qp=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">'),eg=R("<div style=flex:1;overflow:auto;min-height:0;padding:8px>"),tg=R("<div style=color:#484f58;font-style:italic;font-size:12px>Click a tile to select objects…");const{log:fo,error:qt}=Pt("SelectionList"),rg={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"},ng={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"},ig=new Set(["x","y","type","id","name","user","_id","room","hitsMax","energyCapacity","body","storeCapacity","storeCapacityResource","invaderHarvested","ticksToRegeneration"]),po=new Set(["hits","energy","energyCapacity","store","progress","progressTotal","nextDecayTime","ticksToRegeneration","nextRegenerationTime"]),go={hits:"Hits",energy:"Energy",progress:"Progress",progressTotal:"Progress total",ticksToLive:"Ticks to live",ticksToDecay:"Ticks to decay",nextDecayTime:"Decays in",nextRegenerationTime:"Regens 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 sg(r){return go[r]?go[r]:r.replace(/([A-Z])/g," $1").replace(/^./,e=>e.toUpperCase()).trim()}function og(r){return typeof r=="number"?String(r):typeof r=="string"?r:typeof r=="boolean"?r?"Yes":"No":null}function Zn(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 ce=(r=!1)=>({padding:"3px 8px",background:"#0d1117",color:r?"#8b949e":"#c9d1d9",overflow:"hidden","text-overflow":"ellipsis","white-space":"nowrap"}),er={display:"grid","grid-template-columns":"1fr 1fr",gap:"1px",background:"#21262d","font-size":"10px"};function lg(r){const e=()=>{const t=r.item.raw,n=[];for(const i in t){if(ig.has(i))continue;const s=t[i];let o=og(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=Ee();c!==null&&(o=String(s-c))}if(i==="nextRegenerationTime"&&typeof s=="number"){const c=Ee();c!==null&&(o=String(s-c))}o!==null&&n.push({key:i,label:sg(i),value:o})}}return n.sort((i,s)=>{const o=po.has(i.key)?0:1,c=po.has(s.key)?0:1;return o-c}),n};return b(j,{get when(){return e().length>0},get children(){var t=yt();return m(t,b($e,{get each(){return e()},children:n=>[(()=>{var i=yt();return m(i,()=>n.label),I(s=>J(i,ce(!0),s)),i})(),(()=>{var i=Cr();return m(i,()=>n.value),I(s=>J(i,{...ce()},s)),i})()]})),I(n=>J(t,er,n)),t}})}function Ms(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(j,{get when(){return e().length>0},get children(){var n=wp(),i=n.firstChild;i.firstChild;var s=i.nextSibling;return m(i,b(j,{get when(){return r.capacity!=null},get children(){var o=bp(),c=o.firstChild;return m(o,t,c),m(o,()=>r.capacity,null),o}}),null),m(s,b($e,{get each(){return e()},children:([o,c])=>[(()=>{var l=xp();return m(l,o),l})(),(()=>{var l=_p();return m(l,c),l})()]})),n}})}const mo={tough:"#4c4c4c",move:"#a9b7c6",work:"#ffe56d",carry:"#777777",attack:"#f93842",ranged_attack:"#5d80b2",heal:"#65fd62",claim:"#b99cfb"};function ag(r){const e=()=>r.item.raw,t=()=>typeof e().user=="string"?e().user:null,n=()=>{var f,p;const d=t();return d?((p=(f=ln())==null?void 0:f[d])==null?void 0:p.username)??d:null},i=()=>typeof e().hits=="number"?e().hits:null,s=()=>typeof e().hitsMax=="number"?e().hitsMax:null,o=()=>{const d=e().ageTime,f=Ee();return typeof d=="number"&&f!==null?Math.max(0,d-f):null},c=()=>typeof e().fatigue=="number"?e().fatigue:null,l=()=>e().store,a=()=>typeof e().storeCapacity=="number"?e().storeCapacity:null,h=()=>e().body??[],u=()=>{const d=new Map;for(const f of h())d.set(f.type,(d.get(f.type)??0)+1);return[...d.entries()].map(([f,p])=>({type:f,count:p}))};return(()=>{var d=Ul(),f=d.firstChild;return m(f,b(j,{get when(){return n()},get children(){return[(()=>{var p=Hl();return I(g=>J(p,ce(!0),g)),p})(),(()=>{var p=yt();return m(p,n),I(g=>J(p,ce(),g)),p})()]}}),null),m(f,b(j,{get when(){return re(()=>i()!==null)()&&s()!==null},get children(){return[(()=>{var p=Ts();return I(g=>J(p,ce(!0),g)),p})(),(()=>{var p=qn(),g=p.firstChild;return m(p,i,g),m(p,s,null),I(w=>J(p,{...ce()},w)),p})()]}}),null),m(f,b(j,{get when(){return o()!==null},get children(){return[(()=>{var p=$p();return I(g=>J(p,ce(!0),g)),p})(),(()=>{var p=Cr();return m(p,o),I(g=>J(p,{...ce()},g)),p})()]}}),null),m(f,b(j,{get when(){return c()!==null},get children(){return[(()=>{var p=Sp();return I(g=>J(p,ce(!0),g)),p})(),(()=>{var p=Cr();return m(p,c),I(g=>J(p,{...ce(),color:c()>0?"#e3b341":void 0},g)),p})()]}}),null),m(d,b(Ms,{get store(){return l()},get capacity(){return a()}}),null),m(d,b(j,{get when(){return h().length>0},get children(){var p=kp(),g=p.firstChild,w=g.firstChild,L=w.nextSibling;L.nextSibling;var A=g.nextSibling;return m(g,()=>h().length,L),m(A,b($e,{get each(){return h()},children:N=>(()=>{var M=Tp();return I(y=>{var x=N.type.replace("_"," "),O=mo[N.type]??"#484f58",v=N.hits===0?.25:1;return x!==y.e&&_e(M,"title",y.e=x),O!==y.t&&Y(M,"background",y.t=O),v!==y.a&&Y(M,"opacity",y.a=v),y},{e:void 0,t:void 0,a:void 0}),M})()})),m(p,b(j,{get when(){return wl()},get children(){var N=Cp();return m(N,b($e,{get each(){return u()},children:({type:M,count:y})=>(()=>{var x=Mp(),O=x.firstChild,v=O.firstChild,C=O.nextSibling;return m(O,y,v),m(C,()=>M.replace("_"," ").toUpperCase()),I(k=>Y(C,"color",mo[M]??"#484f58")),x})()})),N}}),null),p}}),null),I(p=>J(f,er,p)),d})()}function cg(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]=z(i()),[l,a]=z(s());fe(()=>{c(i()),a(s())});const h=()=>o()!==i()||l()!==s(),u=()=>{const w=me();if(!w)return;const L=o(),A=l();fo(`changeFlagColor: name="${t()}" room=${n()} primary=${L} secondary=${A}`),w.http.game.changeFlagColor(n(),t(),L,A).then(()=>fo("changeFlagColor OK")).catch(N=>qt("changeFlagColor FAILED:",N))},d=()=>{const w=jt();return(w==null?void 0:w.type)==="moveFlag"&&w.id===r.item.id},f=()=>{if(d()){Yr(null);return}Yr({type:"moveFlag",id:r.item.id,name:t(),room:n(),color:o(),secondaryColor:l(),targetRoom:Jr()??n()})},p=()=>{const w=jt();return(w==null?void 0:w.type)==="moveFlag"&&w.id===r.item.id?w:null},g={display:"flex","flex-direction":"column",gap:"5px","font-size":"11px",color:"#8b949e"};return(()=>{var w=Rp(),L=w.firstChild;L.firstChild;var A=L.nextSibling;return A.firstChild,m(L,b(jn,{get value(){return o()},onChange:c}),null),m(A,b(jn,{get value(){return l()},onChange:a}),null),m(w,b(j,{get when(){return!be()},get children(){return[(()=>{var N=Ep(),M=N.firstChild,y=M.nextSibling;return M.addEventListener("mouseleave",x=>{h()&&(x.currentTarget.style.background="#238636")}),M.addEventListener("mouseenter",x=>{h()&&(x.currentTarget.style.background="#2ea043")}),M.$$click=u,y.addEventListener("mouseleave",x=>{x.currentTarget.style.color=d()?"#c9d1d9":"#8b949e"}),y.addEventListener("mouseenter",x=>{x.currentTarget.style.color="#c9d1d9"}),y.$$click=f,m(y,(()=>{var x=re(()=>!!d());return()=>x()?b(Jt,{size:13}):b(xd,{size:13})})()),I(x=>{var O=!h(),v=h()?"#238636":"#161b22",C=h()?"#fff":"#484f58",k=`1px solid ${h()?"#238636":"#30363d"}`,_=h()?"pointer":"not-allowed",E=d()?"Abort move":"Move flag",T=d()?"#30363d":"#21262d",P=d()?"#c9d1d9":"#8b949e",F=`1px solid ${d()?"#8b949e":"#30363d"}`;return O!==x.e&&(M.disabled=x.e=O),v!==x.t&&Y(M,"background",x.t=v),C!==x.a&&Y(M,"color",x.a=C),k!==x.o&&Y(M,"border",x.o=k),_!==x.i&&Y(M,"cursor",x.i=_),E!==x.n&&_e(y,"title",x.n=E),T!==x.s&&Y(y,"background",x.s=T),P!==x.h&&Y(y,"color",x.h=P),F!==x.r&&Y(y,"border",x.r=F),x},{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}),N})(),b(j,{get when(){return p()},children:N=>(()=>{var M=Pp(),y=M.firstChild,x=y.nextSibling;return x.nextSibling,x.$$input=O=>Yr({...N(),targetRoom:O.currentTarget.value.toUpperCase()}),I(O=>J(M,g,O)),I(()=>x.value=N().targetRoom),M})()})]}}),null),I(N=>{var M=g,y=g;return N.e=J(L,M,N.e),N.t=J(A,y,N.t),N},{e:void 0,t:void 0}),w})()}function dg(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:nl[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 y;const M=h();return M?((y=Kr())==null?void 0:y.username)??M:null},d=()=>{const M=s(),y=Ee();return M!==null&&y!==null?Math.max(0,M-y):null},f=()=>{const M=d();if(M===null)return"—";const y=il[t()];return y!==void 0&&M>=y?"Max":String(M)},p=()=>{var M;return h()!==null&&h()===((M=Ue())==null?void 0:M._id)},[g,w]=z(!1);let L=null;const A=()=>{const M=me();M&&M.http.game.addObjectIntent(r.item.id,Jr()??e().room??"","activateSafeMode",{id:r.item.id},wr()).catch(y=>qt("activateSafeMode failed:",y))},N=()=>{if(!g()){w(!0),L=setTimeout(()=>w(!1),3e3);return}L&&(clearTimeout(L),L=null),w(!1);const M=me();M&&M.http.game.addObjectIntent(r.item.id,Jr()??e().room??"","unclaim",{id:r.item.id},wr()).catch(y=>qt("unclaim failed:",y))};return(()=>{var M=zp(),y=M.firstChild,x=y.firstChild,O=x.nextSibling;return m(O,()=>u()??"None"),m(y,b(j,{get when(){return a()},get children(){return[(()=>{var v=Op();return I(C=>J(v,ce(!0),C)),v})(),(()=>{var v=yt();return m(v,()=>{var C,k;return((k=(C=ln())==null?void 0:C[a().user])==null?void 0:k.username)??a().user}),I(C=>J(v,ce(),C)),v})(),(()=>{var v=Lp();return I(C=>J(v,ce(!0),C)),v})(),(()=>{var v=ho(),C=v.firstChild;return m(v,(()=>{var k=re(()=>Ee()!==null);return()=>k()?Math.max(0,a().endTime-Ee()):a().endTime})(),C),I(k=>J(v,{...ce()},k)),v})()]}}),null),m(y,b(j,{get when(){return t()>0},get children(){return[(()=>{var v=Vl();return I(C=>J(v,ce(!0),C)),v})(),(()=>{var v=yt();return m(v,t),I(C=>J(v,ce(),C)),v})(),(()=>{var v=Ap();return I(C=>J(v,ce(!0),C)),v})(),(()=>{var v=yt();return m(v,o),I(C=>J(v,ce(),C)),v})(),(()=>{var v=Ip();return I(C=>J(v,ce(!0),C)),v})(),(()=>{var v=yt();return m(v,()=>l()?"Enabled":"Disabled"),I(C=>J(v,ce(),C)),v})(),(()=>{var v=Np();return I(C=>J(v,ce(!0),C)),v})(),(()=>{var v=Cr();return m(v,f),I(C=>J(v,{...ce(),color:f()==="Max"?"#3fb950":void 0},C)),v})()]}}),null),m(y,b(j,{get when(){return c()!==null},get children(){return[(()=>{var v=Dp();return I(C=>J(v,ce(!0),C)),v})(),(()=>{var v=ho(),C=v.firstChild;return m(v,c,C),I(k=>J(v,{...ce()},k)),v})()]}}),null),m(M,b(j,{get when(){return re(()=>t()>0&&t()<8&&n()!==null)()&&i()!==null},get children(){var v=Gp(),C=v.firstChild,k=C.firstChild,_=k.firstChild,E=_.nextSibling;E.nextSibling;var T=k.nextSibling,P=T.firstChild,F=P.nextSibling,G=F.nextSibling,W=G.nextSibling;W.nextSibling;var D=C.nextSibling,B=D.firstChild;return m(k,t,E),m(k,()=>t()+1,null),m(T,()=>Zn(n()),P),m(T,()=>Zn(i()),F),m(T,()=>(n()/i()*100).toFixed(1),W),I(U=>Y(B,"width",`${Math.min(100,n()/i()*100)}%`)),v}}),null),m(M,b(j,{get when(){return re(()=>!!p())()&&!be()},get children(){var v=Fp(),C=v.firstChild,k=C.nextSibling;return C.addEventListener("mouseleave",_=>{o()>0&&(_.currentTarget.style.background="#1f6feb")}),C.addEventListener("mouseenter",_=>{o()>0&&(_.currentTarget.style.background="#388bfd")}),C.$$click=A,k.addEventListener("mouseleave",_=>{g()||(_.currentTarget.style.background="#f85149")}),k.addEventListener("mouseenter",_=>{g()||(_.currentTarget.style.background="#da3633")}),k.$$click=N,m(k,()=>g()?"Confirm unclaim":"Unclaim"),I(_=>{var E=o()===0,T=o()>0?"#1f6feb":"#161b22",P=o()>0?"pointer":"not-allowed",F=o()>0?1:.5,G=g()?"#da3633":"#f85149";return E!==_.e&&(C.disabled=_.e=E),T!==_.t&&Y(C,"background",_.t=T),P!==_.a&&Y(C,"cursor",_.a=P),F!==_.o&&Y(C,"opacity",_.o=F),G!==_.i&&Y(k,"background",_.i=G),_},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),v}}),null),I(v=>{var C=er,k=ce(!0),_=ce();return v.e=J(y,C,v.e),v.t=J(x,k,v.t),v.a=J(O,_,v.a),v},{e:void 0,t:void 0,a:void 0}),M})()}function yo(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=Ue())==null?void 0:h._id)},a=()=>{const h=me();h&&h.http.game.addObjectIntent(r.item.id,e().room,"notifyWhenAttacked",{enabled:!o()}).catch(u=>qt("notifyWhenAttacked failed:",u))};return(()=>{var h=Hp(),u=h.firstChild,d=u.nextSibling,f=d.firstChild;return m(d,t,f),m(d,n,null),m(h,b(j,{get when(){return re(()=>i()!==null)()&&s()!==null},get children(){return[(()=>{var p=Ts();return I(g=>J(p,ce(!0),g)),p})(),(()=>{var p=qn(),g=p.firstChild;return m(p,i,g),m(p,s,null),I(w=>J(p,{...ce()},w)),p})()]}}),null),m(h,b(j,{get when(){return re(()=>!!l())()&&!be()},get children(){return[(()=>{var p=Bp();return I(g=>J(p,ce(!0),g)),p})(),(()=>{var p=Wp(),g=p.firstChild;return g.addEventListener("mouseleave",w=>{w.currentTarget.style.color=o()?"#3fb950":"#484f58"}),g.addEventListener("mouseenter",w=>{w.currentTarget.style.color=o()?"#56d364":"#8b949e"}),g.$$click=a,m(g,(()=>{var w=re(()=>!!o());return()=>w()?b(Ac,{size:12}):b(Pc,{size:12})})()),I(w=>{var L={...ce()},A=o()?"Notifications on — click to disable":"Notifications off — click to enable",N=o()?"#3fb950":"#484f58";return w.e=J(p,L,w.e),A!==w.t&&_e(g,"title",w.t=A),N!==w.a&&Y(g,"color",w.a=N),w},{e:void 0,t:void 0,a:void 0}),p})()]}}),null),I(p=>{var g=er,w=ce(!0),L={...ce()};return p.e=J(h,g,p.e),p.t=J(u,w,p.t),p.a=J(d,L,p.a),p},{e:void 0,t:void 0,a:void 0}),h})()}function Nt(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=yt();return m(l,b(j,{get when(){return re(()=>t()!==null)()&&n()!==null},get children(){var a=Up(),h=a.firstChild,u=h.nextSibling,d=u.firstChild;return m(u,t,d),m(u,n,null),I(f=>{var p=er,g=ce(!0),w={...ce()};return f.e=J(a,p,f.e),f.t=J(h,g,f.t),f.a=J(u,w,f.a),f},{e:void 0,t:void 0,a:void 0}),a}}),null),m(l,b(j,{get when(){return s()!==null},get children(){var a=Vp(),h=a.firstChild,u=h.firstChild,d=u.nextSibling,f=d.firstChild,p=f.nextSibling,g=p.nextSibling,w=g.nextSibling;w.nextSibling;var L=h.nextSibling,A=L.firstChild;return m(d,()=>Zn(o()),f),m(d,()=>Zn(s()),p),m(d,()=>c().toFixed(1),w),I(N=>Y(A,"width",`${c()}%`)),a}}),null),m(l,b(Ms,{get store(){return i()},capacity:null}),null),l})()}function ug(r){const e=()=>r.item.raw,t=()=>{const p=e().decayTime;if(typeof p!="number")return null;const g=Ee();return g!==null?Math.max(0,p-g):p},n=()=>typeof e().user=="string"?e().user:null,i=()=>{var g,w;const p=n();return p?((w=(g=ln())==null?void 0:g[p])==null?void 0:w.username)??p:null},s=()=>e().structure,o=()=>{var p;return typeof((p=s())==null?void 0:p.type)=="string"?s().type:null},c=()=>{var p;return typeof((p=s())==null?void 0:p.hits)=="number"?s().hits:null},l=()=>{var p;return typeof((p=s())==null?void 0:p.hitsMax)=="number"?s().hitsMax:null},a=()=>{var p;return typeof((p=s())==null?void 0:p.level)=="number"?s().level:null},h=()=>{var p;return typeof((p=s())==null?void 0:p.energy)=="number"?s().energy:null},u=()=>{var p;return typeof((p=s())==null?void 0:p.energyCapacity)=="number"?s().energyCapacity:null},d=()=>e().store,f=()=>typeof e().storeCapacity=="number"?e().storeCapacity:null;return(()=>{var p=Ul(),g=p.firstChild;return m(g,b(j,{get when(){return t()!==null},get children(){return[(()=>{var w=Yp();return I(L=>J(w,ce(!0),L)),w})(),(()=>{var w=Cr();return m(w,t),I(L=>J(w,{...ce()},L)),w})()]}}),null),m(g,b(j,{get when(){return i()},get children(){return[(()=>{var w=Hl();return I(L=>J(w,ce(!0),L)),w})(),(()=>{var w=yt();return m(w,i),I(L=>J(w,ce(),L)),w})()]}}),null),m(p,b(j,{get when(){return o()},get children(){var w=jp(),L=w.firstChild;L.firstChild;var A=L.nextSibling;return m(L,o,null),m(A,b(j,{get when(){return l()!==null},get children(){return[(()=>{var N=Ts();return I(M=>J(N,ce(!0),M)),N})(),(()=>{var N=qn(),M=N.firstChild;return m(N,()=>c()??0,M),m(N,l,null),I(y=>J(N,{...ce()},y)),N})()]}}),null),m(A,b(j,{get when(){return a()!==null},get children(){return[(()=>{var N=Vl();return I(M=>J(N,ce(!0),M)),N})(),(()=>{var N=Cr();return m(N,a),I(M=>J(N,{...ce()},M)),N})()]}}),null),m(A,b(j,{get when(){return u()!==null},get children(){return[(()=>{var N=Xp();return I(M=>J(N,ce(!0),M)),N})(),(()=>{var N=qn(),M=N.firstChild;return m(N,()=>h()??0,M),m(N,u,null),I(y=>J(N,{...ce()},y)),N})()]}}),null),I(N=>J(A,er,N)),w}}),null),m(p,b(Ms,{get store(){return d()},get capacity(){return f()}}),null),I(w=>J(g,er,w)),p})()}const hg={creep:ag,flag:cg,controller:dg,extension:yo,tower:yo,storage:Nt,terminal:Nt,container:Nt,lab:Nt,factory:Nt,nuker:Nt,powerSpawn:Nt,ruin:ug};function fg(r){const e=()=>rg[r.item.type]??"#c9d1d9",t=()=>ng[r.item.type]??r.item.type,n=()=>r.item.type==="creep",i=()=>r.item.type==="flag",s=()=>{var x;if(!n())return!1;const M=r.item.raw,y=typeof M.user=="string"?M.user:null;return y!==null&&y===((x=Ue())==null?void 0:x._id)},o=()=>{var x,O,v;if(n()||i()||r.item.type==="controller")return!1;const M=r.item.raw,y=typeof M.user=="string"?M.user:null;return y!==null?y===((x=Ue())==null?void 0:x._id):((O=Kr())==null?void 0:O.userId)===((v=Ue())==null?void 0:v._id)},c=()=>hg[r.item.type]||lg,[l,a]=z(!1);let h=null;const[u,d]=z(!1);let f=null;const[p,g]=z(!1);let w=null;const L=M=>{if(M.stopPropagation(),!p()){g(!0),w=setTimeout(()=>g(!1),3e3);return}w&&(clearTimeout(w),w=null),g(!1);const y=me();if(!y)return;const x=r.item.id,O=r.item.raw;y.http.game.removeFlag(O.room,O.name).then(()=>Ir(x)).catch(()=>{})},A=M=>{var C;if(M.stopPropagation(),!u()){d(!0),f=setTimeout(()=>d(!1),3e3);return}f&&(clearTimeout(f),f=null),d(!1);const y=me();if(!y)return;const x=r.item.id,O=r.item.raw,v=(typeof O.room=="string"?O.room:null)??Jr()??"";if(r.item.type==="constructionSite")y.http.game.removeConstructionSite(v,[x],wr()??void 0).then(()=>Ir(x)).catch(k=>qt("removeConstructionSite failed:",k));else{const k=typeof O.user=="string"?O.user:((C=Kr())==null?void 0:C.userId)??"";y.http.game.addObjectIntent("room",v,"destroyStructure",[{id:x,roomName:v,user:k}],wr()).then(()=>Ir(x)).catch(_=>qt("destroyStructure failed:",_))}},N=M=>{if(M.stopPropagation(),!l()){a(!0),h=setTimeout(()=>a(!1),3e3);return}h&&(clearTimeout(h),h=null),a(!1);const y=me();if(!y)return;const x=r.item.id;y.http.game.addObjectIntent(x,Jr()??r.item.raw.room??"","suicide",{id:x},wr()).then(()=>Ir(x)).catch(O=>qt("suicide failed:",O))};return(()=>{var M=Kp(),y=M.firstChild,x=y.firstChild,O=x.nextSibling,v=O.firstChild,C=v.nextSibling,k=C.nextSibling,_=k.nextSibling;_.nextSibling;var E=O.nextSibling;return m(y,b(j,{get when(){return re(()=>!n())()&&!i()},get children(){var T=qp();return I(P=>Y(T,"background",e())),T}}),x),m(x,b(j,{get when(){return i()},get fallback(){return re(t)},get children(){return b(Zo,{size:12})}}),null),m(x,b(j,{get when(){return re(()=>typeof r.item.raw.name=="string")()&&r.item.raw.name},children:T=>(()=>{var P=Jp();return m(P,()=>T()),P})()}),null),m(O,()=>r.item.raw.x,C),m(O,()=>r.item.raw.y,_),m(y,b(j,{get when(){return re(()=>!!s())()&&!be()},get children(){return[(()=>{var T=bi();return T.addEventListener("mouseleave",P=>{l()||(P.currentTarget.style.color="#8b949e")}),T.addEventListener("mouseenter",P=>{l()||(P.currentTarget.style.color="#f85149")}),T.$$click=N,m(T,b(Pn,{size:13})),I(P=>{var F=l()?"Click again to confirm suicide":"Suicide",G=l()?"#f85149":"#8b949e";return F!==P.e&&_e(T,"title",P.e=F),G!==P.t&&Y(T,"color",P.t=G),P},{e:void 0,t:void 0}),T})(),(()=>{var T=Zp();return T.addEventListener("mouseleave",P=>P.currentTarget.style.color="#8b949e"),T.addEventListener("mouseenter",P=>P.currentTarget.style.color="#58a6ff"),T.$$click=()=>{zf(r.item.id,r.item.raw.name),Il(!0)},m(T,b(qo,{size:13})),T})()]}}),E),m(y,b(j,{get when(){return re(()=>!!o())()&&!be()},get children(){var T=bi();return T.addEventListener("mouseleave",P=>{u()||(P.currentTarget.style.color="#8b949e")}),T.addEventListener("mouseenter",P=>{u()||(P.currentTarget.style.color="#f85149")}),T.$$click=A,m(T,b(Pn,{size:13})),I(P=>{var F=u()?"Click again to confirm":r.item.type==="constructionSite"?"Remove construction site":"Destroy structure",G=u()?"#f85149":"#8b949e";return F!==P.e&&_e(T,"title",P.e=F),G!==P.t&&Y(T,"color",P.t=G),P},{e:void 0,t:void 0}),T}}),E),m(y,b(j,{get when(){return re(()=>!!i())()&&!be()},get children(){var T=bi();return T.addEventListener("mouseleave",P=>{p()||(P.currentTarget.style.color="#8b949e")}),T.addEventListener("mouseenter",P=>{p()||(P.currentTarget.style.color="#f85149")}),T.$$click=L,m(T,b(Pn,{size:13})),I(P=>{var F=p()?"Click again to confirm deletion":"Delete flag",G=p()?"#f85149":"#8b949e";return F!==P.e&&_e(T,"title",P.e=F),G!==P.t&&Y(T,"color",P.t=G),P},{e:void 0,t:void 0}),T}}),E),E.addEventListener("mouseleave",T=>T.currentTarget.style.color="#8b949e"),E.addEventListener("mouseenter",T=>T.currentTarget.style.color="#fff"),E.$$click=()=>Ir(r.item.id),m(M,b(Oo,{get component(){return c()},get item(){return r.item}}),null),m(M,b(j,{get when(){return r.item.id},children:T=>(()=>{var P=Qp();return P.$$click=()=>{var F;return(F=navigator.clipboard)==null?void 0:F.writeText(T())},m(P,T),I(()=>_e(P,"title",T())),P})()}),null),I(T=>Y(M,"border",`1px solid ${s()&&l()||u()||p()?"#f85149":"#30363d"}`)),M})()}function pg(){return(()=>{var r=eg();return m(r,b(j,{get when(){return _r().length>0},get fallback(){return tg()},get children(){return b($e,{get each(){return _r()},children:e=>b(fg,{item:e})})}})),r})()}Oe(["click","input"]);var gg=R('<div style="padding:3px 0;color:#8b949e">Reserved by'),mg=R('<div style="padding:3px 0;color:#c9d1d9">'),yg=R('<div style="padding:3px 0;color:#8b949e">Expires in'),vg=R('<div style="padding:3px 0;color:#c9d1d9;font-variant-numeric:tabular-nums"> ticks'),bg=R('<div style="padding:3px 0;color:#8b949e">RCL'),wg=R("<span style=color:#8b949e>(<!>%)"),xg=R('<div style="padding:3px 0;color:#c9d1d9;font-variant-numeric:tabular-nums">'),_g=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">'),$g=R("<span>"),Sg=R('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;display:flex;align-items:center;justify-content:center">');const Cg=[{mode:"view",label:"View",icon:()=>b(qo,{size:14})},{mode:"flag",label:"Flag",icon:()=>b(Zo,{size:14})},{mode:"build",label:"Build",icon:()=>b(nd,{size:14})}];function kg(r){return(()=>{var e=_g(),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,g=p.nextSibling,w=s.nextSibling,L=w.firstChild,A=L.nextSibling,N=w.nextSibling,M=N.firstChild,y=M.nextSibling,x=t.nextSibling,O=x.firstChild;return m(i,()=>r.room),m(c,()=>r.shard??"—"),m(a,()=>Ee()??"—"),m(u,(()=>{var v=re(()=>!!In());return()=>v()?`${In()}ms`:"—"})()),m(f,()=>lf()??"—"),m(g,()=>{var v;return((v=Kr())==null?void 0:v.username)??"—"}),m(s,b(j,{get when(){return re(()=>!Kr())()&&yn()},get children(){return[gg(),(()=>{var v=mg();return m(v,()=>{var C,k;return((k=(C=ln())==null?void 0:C[yn().user])==null?void 0:k.username)??yn().user}),v})(),yg(),(()=>{var v=vg(),C=v.firstChild;return m(v,(()=>{var k=re(()=>Ee()!==null);return()=>k()?Math.max(0,yn().endTime-Ee()):"—"})(),C),v})()]}}),null),m(s,b(j,{get when(){return re(()=>We()!==null)()&&We()>0},get children(){return[bg(),(()=>{var v=xg();return m(v,b(j,{get when(){return re(()=>We()<8)()&&to()!==null},get fallback(){return(()=>{var C=$g();return m(C,We),C})()},get children(){return[re(()=>We())," → ",re(()=>We()+1)," ",(()=>{var C=wg(),k=C.firstChild,_=k.nextSibling;return _.nextSibling,m(C,()=>(to()/(nl[We()]??1)*100).toFixed(1),_),C})()]}})),v})()]}}),null),A.addEventListener("change",v=>pl(v.currentTarget.checked)),y.addEventListener("change",v=>Vh(v.currentTarget.checked)),m(x,b(j,{get when(){return!Ie()},get children(){return b($e,{each:Cg,children:v=>{const C=()=>!be()&&Mt()===v.mode;return(()=>{var k=Sg();return k.$$click=()=>{be()&&Un(),Tt(v.mode)},m(k,()=>v.icon()),I(_=>{var E=v.label,T=`1px solid ${C()?"#58a6ff":"#30363d"}`,P=C()?"#1f6feb33":"#161b22",F=C()?"#c9d1d9":"#8b949e";return E!==_.e&&_e(k,"title",_.e=E),T!==_.t&&Y(k,"border",_.t=T),P!==_.a&&Y(k,"background",_.a=P),F!==_.o&&Y(k,"color",_.o=F),_},{e:void 0,t:void 0,a:void 0,o:void 0}),k})()}})}}),O),O.$$click=()=>be()?Un():Ee()!==null&&Pl(Ee()),m(O,b(Xc,{size:14})),I(v=>{var C=`repeat(${Ie()?2:4}, 1fr)`,k=!be()&&Ee()===null,_=Ie()?"span 2":void 0,E=`1px solid ${be()?"#58a6ff":"#30363d"}`,T=be()?"#1f6feb33":"#161b22",P=be()?"#c9d1d9":"#8b949e",F=!be()&&Ee()===null?"not-allowed":"pointer",G=!be()&&Ee()===null?.4:1;return C!==v.e&&Y(x,"grid-template-columns",v.e=C),k!==v.t&&(O.disabled=v.t=k),_!==v.a&&Y(O,"grid-column",v.a=_),E!==v.o&&Y(O,"border",v.o=E),T!==v.i&&Y(O,"background",v.i=T),P!==v.n&&Y(O,"color",v.n=P),F!==v.s&&Y(O,"cursor",v.s=F),G!==v.h&&Y(O,"opacity",v.h=G),v},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0}),I(()=>A.checked=Bn()),I(()=>y.checked=bl()),e})()}Oe(["click"]);const[Tg,Mg]=z("owner"),Ne=3,vo=Ne*50,bn=4;function at(r,e,t){const n=it(r);return n?[n.x*vo+e*Ne,n.y*vo+t*Ne]:null}const wn=3*Ne,xn=2.5*Ne,_n=1*Ne,$n=2*Ne;function St(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,g=d/f;let w=0;for(;w<f;){const L=Math.min(s,f-w);if(i){const A=c+p*w,N=l+g*w;r.moveTo(A,N),r.lineTo(A+p*L,N+g*L)}w+=L,s-=L,s<.001&&(i=!i,s=i?t:n)}}}function bo(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}class Eg{constructor(){S(this,"container");S(this,"g");this.container=new Ae,this.container.label="mapVisuals",this.g=new te,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(`
25
+ `)){if(!i.trim())continue;let s;try{s=JSON.parse(i)}catch{continue}const o=s.s??{},c=o.opacity??.5;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}}}clear(){const e=this.container.removeChildren();for(const t of e)t!==this.g&&t.destroy();this.g.clear(),this.container.addChild(this.g)}drawLine(e,t,n,i){const s=at(t.n1,t.x1,t.y1),o=at(t.n2,t.x2,t.y2);if(!s||!o)return;const c=n.color??"#ffffff",l=(n.width??.5)*Ne;n.lineStyle==="dashed"?St(e,[s,o],wn*(n.width??.5),xn*(n.width??.5)):n.lineStyle==="dotted"?St(e,[s,o],_n*(n.width??.5),$n*(n.width??.5)):(e.moveTo(s[0],s[1]),e.lineTo(o[0],o[1])),e.stroke({color:c,width:l,alpha:i})}drawCircle(e,t,n,i){const s=at(t.n,t.x,t.y);if(!s)return;const[o,c]=s,l=(n.radius??10)*Ne,a=!!(n.fill&&n.fill!=="transparent"),h=!!(n.stroke&&n.strokeWidth),u=(n.strokeWidth??.5)*Ne;a&&(e.circle(o,c,l),e.fill({color:n.fill,alpha:i})),h&&(n.lineStyle==="dashed"?St(e,bo(o,c,l),wn*(n.strokeWidth??.5),xn*(n.strokeWidth??.5)):n.lineStyle==="dotted"?St(e,bo(o,c,l),_n*(n.strokeWidth??.5),$n*(n.strokeWidth??.5)):e.circle(o,c,l),e.stroke({color:n.stroke,width:u,alpha:i}))}drawRect(e,t,n,i){const s=at(t.n,t.x,t.y),o=at(t.n,t.x+t.w,t.y),c=at(t.n,t.x+t.w,t.y+t.h),l=at(t.n,t.x,t.y+t.h);if(!s||!o||!c||!l)return;const a=!!(n.fill&&n.fill!=="transparent"),h=!!(n.stroke&&n.strokeWidth),u=[s,o,c,l,s],d=u.flatMap(p=>p),f=(n.strokeWidth??.5)*Ne;a&&(e.poly(d.slice(0,8),!0),e.fill({color:n.fill,alpha:i})),h&&(n.lineStyle==="dashed"?St(e,u,wn*(n.strokeWidth??.5),xn*(n.strokeWidth??.5)):n.lineStyle==="dotted"?St(e,u,_n*(n.strokeWidth??.5),$n*(n.strokeWidth??.5)):e.poly(d.slice(0,8),!0),e.stroke({color:n.stroke,width:f,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=[];for(const{n:h,x:u,y:d}of t.points){const f=at(h,u,d);if(!f)return;c.push(f)}const l=c.flatMap(h=>h),a=(n.strokeWidth??.5)*Ne;if(s&&(e.poly(l,!0),e.fill({color:n.fill,alpha:i})),o){if(n.lineStyle==="dashed"){const h=c[0],u=c[c.length-1],d=h[0]===u[0]&&h[1]===u[1];St(e,d?c:[...c,h],wn*(n.strokeWidth??.5),xn*(n.strokeWidth??.5))}else if(n.lineStyle==="dotted"){const h=c[0],u=c[c.length-1],d=h[0]===u[0]&&h[1]===u[1];St(e,d?c:[...c,h],_n*(n.strokeWidth??.5),$n*(n.strokeWidth??.5))}else e.poly(l,!0);e.stroke({color:n.stroke,width:a,alpha:i})}}drawText(e,t,n){const i=at(e.n,e.x,e.y);if(!i)return;const[s,o]=i,c=t.fontSize??10,l=t.fontFamily??"sans-serif",a=c*Ne,h=t.align??"center",u=new Ro({fill:t.color??"#ffffff",fontSize:a*bn,fontFamily:l,align:h,...t.fontStyle?{fontStyle:t.fontStyle}:{},...t.fontVariant?{fontVariant:t.fontVariant}:{},...t.stroke&&t.strokeWidth?{stroke:{color:t.stroke,width:t.strokeWidth*Ne*bn}}:{}});if(t.backgroundColor&&t.backgroundColor!=="transparent"){const f=(t.backgroundPadding??2)*Ne,p=new vt({text:e.text,style:u});p.scale.set(1/bn);const g=p.width,w=p.height;p.destroy();const A=s-(h==="center"?.5:h==="right"?1:0)*g-f,N=o-w/2-f,M=new te;M.rect(A,N,g+f*2,w+f*2),M.fill({color:t.backgroundColor,alpha:n}),this.container.addChild(M)}const d=new vt({text:e.text,style:u});d.scale.set(1/bn),d.anchor.x=h==="center"?.5:h==="right"?1:0,d.anchor.y=.5,d.position.set(s,o),d.alpha=n,this.container.addChild(d)}destroy(){const e=this.container.removeChildren();for(const t of e)t!==this.g&&t.destroy();this.g.destroy(),this.container.destroy()}}const Yl="screeps-terrain-v1";async function Rg(r,e,t){try{const n=await caches.open(Yl),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 Pg(r,e,t,n){try{const i=await caches.open(Yl),s=`/terrain/${r}_${e}_z${t}.webp`,o=new Request(s),c=new Response(n);await i.put(o,c)}catch{}}async function Og(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 Lg(r){return await createImageBitmap(r)}function Ag(r){return new Worker("/client/_client/terrain.worker-D9zNeJfz.js",{name:r==null?void 0:r.name})}const{warn:Ig}=Pt("MapRenderer"),Xl=3,ae=Xl*50,Ng=[50,60,70,80,90,100,105,120],Gr=1,Bt=.5,Sn=50,Dg=2600,Gg=5,wi=.2,xi=5,Fg=Tr,zg=16777215,Bg=Yt,Wg=Wr,Hg=tl,Ug=Gt,Vg=4486980,Yg=8921634,Xg=new Set(["w","r","pb","p","s","c","m","k"]),jg={H:13421772,O:13421772,U:5809919,L:4176208,K:10711543,Z:13801762,X:16273737},qg=[16,24,32,40];class km{constructor(e){S(this,"app");S(this,"world");S(this,"boundsGraphics",null);S(this,"selectionGraphics",null);S(this,"safeModeGraphics",null);S(this,"mapVisualLayer",null);S(this,"safeModeRooms",new Set);S(this,"activeRooms",new Map);S(this,"roomPool",[]);S(this,"terrainBaked",new Set);S(this,"terrainData",new Map);S(this,"worker");S(this,"pendingBakes",new Map);S(this,"nextBakeId",0);S(this,"currentShard","shard0");S(this,"callbacks");S(this,"resizeObserver",null);S(this,"_destroyed",!1);S(this,"showRoomNames",!1);S(this,"worldBoundsSet",null);S(this,"lastVisibleBounds",null);S(this,"animTargetX",0);S(this,"animTargetY",0);S(this,"isAnimating",!1);S(this,"overlayMode","owner");S(this,"showUnclaimableOverlay",!0);S(this,"isDragging",!1);S(this,"hasDragged",!1);S(this,"dragStartX",0);S(this,"dragStartY",0);S(this,"dragWorldX",0);S(this,"dragWorldY",0);S(this,"isPinching",!1);S(this,"pinchPivotWorldX",0);S(this,"pinchPivotWorldY",0);S(this,"pinchStartDist",0);S(this,"pinchStartScale",0);S(this,"lastVisibleKey","");S(this,"visibleDebounceTimer",null);S(this,"selectedRoom",null);S(this,"currentUserId",null);S(this,"badgeCache",new rl);S(this,"lastCheckX",0);S(this,"lastCheckY",0);S(this,"lastCheckScale",0);this.app=new Mo,this.callbacks=e,this.worker=new Ag,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:Tu,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 te,this.world.addChild(this.boundsGraphics),this.selectionGraphics=new te,this.world.addChild(this.selectionGraphics),this.safeModeGraphics=new te,this.world.addChild(this.safeModeGraphics),this.mapVisualLayer=new Eg,this.world.addChild(this.mapVisualLayer.container),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(wi,Math.min(xi,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>=Gr,c=this.zoom>=Bt,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>=Gr!==o||e>=Bt!==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*ae+ae/2,s=t*ae+ae/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 Rg(i,e,t);if(s)return await Lg(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 Og(l).then(a=>{Pg(i,e,t,a)}).catch(a=>Ig("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=De.from(c);o===0?(s.texLo&&!s.texLo.destroyed&&(s.terrainSprite.texture===s.texLo&&(s.terrainSprite.texture=De.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=De.EMPTY),s.texHi.destroy(!0)),s.texHi=l,this.getLOD()===1&&(s.terrainSprite.texture=l)),s.terrainSprite.width=ae,s.terrainSprite.height=ae,this.terrainBaked.add(e)}getLOD(){return this.zoom<Gr?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=De.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=Xl;i.clear();const o=t.r??[];for(const[p,g]of o)i.rect(p*s,g*s,s,s);o.length&&i.fill(ws);const c=t.w??[];for(const[p,g]of c)i.rect(p*s+.5,g*s+.5,s-1,s-1);c.length&&i.fill(e.ownerState==="other"?Yg:Vg);const l=t.s??[];for(const[p,g]of l)i.circle((p+.5)*s,(g+.5)*s,2.5);l.length&&i.fill(Fg);const a=t.c??[];for(const[p,g]of a)i.circle((p+.5)*s,(g+.5)*s,2);a.length&&i.fill(zg);const h=t.m??[];for(const[p,g]of h)i.circle((p+.5)*s,(g+.5)*s,2);h.length&&i.fill(Bg);const u=t.k??[];for(const[p,g]of u)i.circle((p+.5)*s,(g+.5)*s,2);u.length&&i.fill(Wg);const d=t.pb??[];for(const[p,g]of d)i.circle((p+.5)*s,(g+.5)*s,1.5);d.length&&i.fill(Wr);const f=t;for(const p in f){if(Xg.has(p))continue;const g=f[p];if(!Array.isArray(g)||g.length===0)continue;for(const[L,A]of g)i.circle((L+.5)*s,(A+.5)*s,1);const w=p===this.currentUserId?Hg:Ug;i.fill(w)}}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,ae,ae),i.fill({color:10027008,alpha:.18})):t==="own"&&(i.rect(0,0,ae,ae),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 ze(s);o.anchor.set(.5),o.x=ae/2,o.y=ae/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=(Ng[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=jg[t]??Yt;if(i.mineralDensity=n,i.mineralColor=s,!i.mineralCircle){const o=new te;o.x=ae/2,o.y=ae/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 vt({text:t,style:{fontSize:36,fill:16777215,fontFamily:"ui-monospace, monospace",fontWeight:"bold"}});o.anchor.set(.5),o.x=ae/2,o.y=ae/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=(qg[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}setMapVisual(e){var t;(t=this.mapVisualLayer)==null||t.update(e),this.mapVisualLayer&&(this.world.removeChild(this.mapVisualLayer.container),this.world.addChild(this.mapVisualLayer.container))}clearMapVisual(){var e;(e=this.mapVisualLayer)==null||e.clear()}setMapVisualVisible(e){this.mapVisualLayer&&(this.mapVisualLayer.container.visible=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=it(e);if(!t)return;const n=t.x*ae,i=t.y*ae;this.selectionGraphics.rect(n,i,ae,ae);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=it(t);if(!n)continue;const i=n.x*ae,s=n.y*ae;this.safeModeGraphics.rect(i,s,ae,ae),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*ae,o=n*ae,c=(t-e+1)*ae,l=(i-n+1)*ae;this.boundsGraphics.rect(s,o,c,l),this.boundsGraphics.stroke({color:Qo,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=De.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<Dg?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=it(n);if(i&&i.x>=t.rxMin-Sn&&i.x<=t.rxMax+Sn&&i.y>=t.ryMin-Sn&&i.y<=t.ryMax+Sn)continue}this.clearRoom(n)}}destroy(){var e,t;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[,n]of this.activeRooms)n.texLo&&!n.texLo.destroyed&&n.texLo.destroy(!0),n.texHi&&!n.texHi.destroyed&&n.texHi.destroy(!0);this.activeRooms.clear(),this.safeModeRooms.clear();for(const n of this.roomPool)n.texLo&&!n.texLo.destroyed&&n.texLo.destroy(!0),n.texHi&&!n.texHi.destroyed&&n.texHi.destroy(!0);this.roomPool.length=0,this.terrainBaked.clear(),this.terrainData.clear(),this.worker.terminate(),this.pendingBakes.clear(),this.badgeCache.destroy(),(t=this.mapVisualLayer)==null||t.destroy(),this.mapVisualLayer=null;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=it(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 ze(De.EMPTY),c=new te,l=new te;s.addChild(o),s.addChild(c),s.addChild(l);const a=new vt({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*ae,i.container.y=n.y*ae,i.container.visible=!0,i.nameLabel.text=e,i.nameLabel.visible=this.showRoomNames&&this.zoom>=Bt&&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>=Bt;for(const[t,n]of this.activeRooms){if(!e){n.nameLabel.visible=!1;continue}const i=it(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(wi,Math.min(xi,this.pinchStartScale*(h/this.pinchStartDist))),d=this.getLOD(),f=this.zoom>=Gr,p=this.zoom>=Bt;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>=Gr!==f||u>=Bt!==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)*ae*a,d=this.app.screen.width-h-l.minX*ae*a,f=h-(l.maxY+1)*ae*a,p=this.app.screen.height-h-l.minY*ae*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(wi,Math.min(xi,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*ae*t,c=this.world.x+(e.maxX+1)*ae*t,l=this.world.y+e.minY*ae*t,a=this.world.y+(e.maxY+1)*ae*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/ae),c=Math.floor(s/ae);return Ze(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/ae)-1,a=Math.ceil(o/ae),h=Math.floor(s/ae)-1,u=Math.ceil(c/ae);this.lastVisibleBounds={rxMin:l,rxMax:a,ryMin:h,ryMax:u};const d=[],f=this.worldBoundsSet,p=f?Math.max(l,f.minX):l,g=f?Math.min(a,f.maxX):a,w=f?Math.max(h,f.minY):h,L=f?Math.min(u,f.maxY):u;for(let N=p;N<=g;N++)for(let M=w;M<=L;M++){const y=Ze(N,M);y&&d.push(y)}const A=`${l},${h},${a},${u}`;A!==this.lastVisibleKey&&(this.lastVisibleKey=A,this.visibleDebounceTimer!==null&&clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=setTimeout(()=>{this.visibleDebounceTimer=null,this.callbacks.onVisibleRoomsChanged(d)},Gg))}}var Zg=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><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px;color:#c9d1d9;cursor:pointer;margin-top:4px><span>Show map visuals</span><input type=checkbox></label></div><div style="display:grid;grid-template-columns:repeat(3, 1fr);gap:4px;margin-top:8px">'),Kg=R('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;font-size:11px;font-weight:600">');const Jg=[{mode:"owner",label:"Owner"},{mode:"mineral",label:"Mineral"},{mode:"none",label:"None"}];function Qg(r){const e=()=>(r.zoom??1)>=Bt;return(()=>{var t=Zg(),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,g=p.nextSibling,w=f.nextSibling,L=w.firstChild,A=L.nextSibling,N=n.nextSibling;return m(c,()=>{var M;return((M=r.zoom)==null?void 0:M.toFixed(2))??"—"}),m(a,()=>r.subsActive?"Yes":"No"),d.addEventListener("change",M=>ml(M.currentTarget.checked)),g.addEventListener("change",M=>vl(M.currentTarget.checked)),A.addEventListener("change",M=>qh(M.currentTarget.checked)),m(N,b($e,{each:Jg,children:M=>{const y=()=>Tg()===M.mode;return(()=>{var x=Kg();return x.$$click=()=>Mg(M.mode),m(x,()=>M.label),I(O=>{var v=`1px solid ${y()?"#58a6ff":"#30363d"}`,C=y()?"#1f6feb33":"#161b22",k=y()?"#c9d1d9":"#8b949e";return v!==O.e&&Y(x,"border",O.e=v),C!==O.t&&Y(x,"background",O.t=C),k!==O.a&&Y(x,"color",O.a=k),O},{e:void 0,t:void 0,a:void 0}),x})()}})),I(M=>{var y=e()?"#c9d1d9":"#484f58",x=e()?"pointer":"default",O=!e();return y!==M.e&&Y(h,"color",M.e=y),x!==M.t&&Y(h,"cursor",M.t=x),O!==M.a&&(d.disabled=M.a=O),M},{e:void 0,t:void 0,a:void 0}),I(()=>d.checked=gl()),I(()=>g.checked=yl()),I(()=>A.checked=jh()),t})()}Oe(["click"]);var e0=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">'),t0=R('<div style="padding:6px 8px;font-size:11px;color:#484f58;font-style:italic">None'),r0=R('<div style="padding:3px 8px;color:#8b949e">Mineral'),n0=R('<div style="padding:3px 8px;color:#79c0ff">'),i0=R('<div style="padding:3px 8px;color:#8b949e">Density'),s0=R('<div style="padding:3px 8px;color:#c9d1d9">'),o0=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 l0=["Low","Medium","High","Ultra"];function a0(r){return l0[r-1]??String(r)}function wo(r){return(()=>{var e=e0(),t=e.firstChild;return m(t,()=>r.label),m(e,b(j,{get when(){return r.info},get fallback(){return t0()},children:n=>(()=>{var i=o0(),s=i.firstChild,o=s.nextSibling,c=o.firstChild,l=c.nextSibling;return m(s,()=>n().room),m(l,()=>n().owner??"None"),m(o,b(j,{get when(){return n().mineral},get children(){return[r0(),(()=>{var a=n0();return m(a,()=>n().mineral),a})(),i0(),(()=>{var a=s0();return m(a,()=>a0(n().density??0)),a})()]}}),null),i})()}),null),I(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 c0=R("<span style=color:#8b949e;font-size:11px>Checking…"),d0=R('<div style=margin-top:8px><div style="padding:6px 8px;font-size:11px;font-weight:600;color:#c9d1d9;margin-bottom:6px">Your flags'),u0=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>'),h0=R("<span style=color:#f85149;font-size:11px>"),f0=R("<div style=margin-top:8px;color:#484f58;font-style:italic;font-size:12px>No flags."),p0=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:g0}=Pt("flag"),hs={};for(const[r,e]of Object.entries(rn))hs[e]=r;function m0(){const r=p=>{Ol({...fr(),...p})},[e,t]=z(null),[n,i]=z(!1);let s=null;fe(()=>{if(Mt()!=="flag"||fr().name.trim()!=="")return;const p=me();p&&p.http.game.genUniqueFlagName().then(g=>{r({name:g.name}),t(null)}).catch(g=>{g0("gen unique name failed:",g)})});const o=p=>{r({name:p}),t(null),s&&clearTimeout(s);const g=p.trim();if(!g){i(!1);return}i(!0),s=setTimeout(()=>{const w=me();if(!w){i(!1);return}w.http.game.checkUniqueFlagName(g).then(()=>{t(null)}).catch(L=>{t(L.message)}).finally(()=>{i(!1)})},300)},c=()=>rn[fr().color]??1,l=()=>rn[fr().secondaryColor]??1,a=p=>{r({color:hs[p]??"COLOR_WHITE"})},h=p=>{r({secondaryColor:hs[p]??"COLOR_WHITE"})},u=()=>{const p=yc(),g=[];for(const[w,L]of Object.entries(p))L&&typeof L=="object"&&"room"in L&&"x"in L&&"y"in L&&g.push([w,L]);return g},d=p=>p===void 0||p<0||p>=mr.length?"#8b949e":`#${mr[p].toString(16).padStart(6,"0")}`,f={display:"flex","flex-direction":"column",gap:"5px","font-size":"11px",color:"#8b949e"};return(()=>{var p=u0(),g=p.firstChild,w=g.firstChild,L=w.nextSibling,A=L.firstChild,N=A.firstChild,M=N.nextSibling,y=A.nextSibling;y.firstChild;var x=y.nextSibling;x.firstChild;var O=x.nextSibling;return M.$$input=v=>o(v.currentTarget.value),m(A,b(j,{get when(){return e()},children:v=>(()=>{var C=h0();return m(C,v),C})()}),null),m(A,b(j,{get when(){return n()},get children(){return c0()}}),null),m(y,b(jn,{get value(){return c()},onChange:a}),null),m(x,b(jn,{get value(){return l()},onChange:h}),null),m(O,(()=>{var v=re(()=>!!Xt());return()=>v()?`Marked at x=${Xt().tx}, y=${Xt().ty}. Click again to create the flag, or click elsewhere to move the mark.`:"Click a position in the room to mark it."})()),m(p,b(j,{get when(){return u().length>0},get fallback(){return f0()},get children(){var v=d0();return v.firstChild,m(v,b($e,{get each(){return u()},children:([C,k])=>(()=>{var _=p0(),E=_.firstChild,T=E.firstChild,P=T.nextSibling,F=P.nextSibling,G=F.nextSibling,W=G.firstChild,D=W.nextSibling,B=D.nextSibling,U=B.nextSibling;return U.nextSibling,m(P,C),m(F,()=>k.room),m(G,()=>k.x,D),m(G,()=>k.y,U),I(H=>Y(T,"background",d(k.color))),_})()}),null),v}}),null),I(v=>{var C=f,k=`1px solid ${e()?"#f85149":"#30363d"}`,_=f,E=f;return v.e=J(A,C,v.e),k!==v.t&&Y(M,"border",v.t=k),v.a=J(y,_,v.a),v.o=J(x,E,v.o),v},{e:void 0,t:void 0,a:void 0,o:void 0}),I(()=>M.value=fr().name),p})()}Oe(["input"]);var y0=R("<span style=color:#8b949e>…"),v0=R("<span style=color:#3fb950>✓"),b0=R("<span style=color:#f85149>✗"),w0=R("<div style=font-size:10px;color:#f85149>"),x0=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>'),_0=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>'),$0=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 S0(r){const e=Object.keys(Yn),[t,n]=z("idle"),[i,s]=z("");let o=null;const c=(p,g)=>{const w=Yn[p];return w?Kt()==="empty"&&p==="spawn"?Math.max(w[g]??0,1):w[g]??0:0},l=(p,g)=>{const w=c(p,g);if(w===2500)return 1/0;const L=Hn()[p]??0;return Math.max(0,w-L)},a=()=>ft().structureType==="spawn";fe(ta(()=>ft().structureType,(p,g)=>{if(p!=="spawn"||p===g)return;const w=me();if(!w)return;n("loading"),s("");let L=!1;Be(()=>{L=!0}),w.http.game.genUniqueObjectName("spawn",r.shard).then(A=>{L||(Ut({structureType:"spawn",structureName:A.name}),n("valid"))}).catch(()=>{L||(Ut({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 g=me();g&&g.http.game.checkUniqueObjectName("spawn",p.trim(),r.shard).then(w=>{w.error?(n("invalid"),s(w.error)):(n("valid"),s(""))}).catch(()=>{n("invalid"),s("Could not validate name")})},400)},u=p=>{Ut({structureType:"spawn",structureName:p}),h(p)},d=p=>{Ut({structureType:p,structureName:""}),n("idle"),s("")},f=()=>{switch(t()){case"loading":return y0();case"valid":return v0();case"invalid":return b0();default:return null}};return(()=>{var p=_0(),g=p.firstChild,w=g.firstChild;w.firstChild;var L=w.nextSibling,A=g.nextSibling;A.firstChild;var N=A.nextSibling,M=N.firstChild;return m(w,()=>We()??"?",null),m(L,()=>{const y=Kt();return y==="empty"?"World is empty — place a spawn to claim this room.":y==="lost"?"You lost all your spawns — respawn to continue.":We()!=null?`RCL ${We()} — Select a structure type and click a tile to build.`:"No controller — roads and containers only."}),m(A,b($e,{each:e,children:y=>{const x=()=>We()??0,O=()=>c(y,x()),v=()=>Hn()[y]??0,C=()=>ft().structureType===y,k=()=>O()===2500,_=()=>!k()&&l(y,x())<=0;return b(j,{get when(){return O()>0},get children(){var E=$0(),T=E.firstChild,P=T.nextSibling;return E.$$click=()=>!_()&&d(y),m(T,()=>y.replace(/([A-Z])/g," $1").trim(),null),m(T,()=>C()&&" ✓",null),m(P,(()=>{var F=re(()=>!!k());return()=>F()?`${v()}/∞`:`${v()}/${O()}`})(),null),m(P,()=>_()&&" (Max)",null),I(F=>{var G=C()?"#1f3158":"transparent",W=_()?"default":"pointer",D=_()?.5:1;return G!==F.e&&Y(E,"background",F.e=G),W!==F.t&&Y(E,"cursor",F.t=W),D!==F.a&&Y(E,"opacity",F.a=D),F},{e:void 0,t:void 0,a:void 0}),E}})}}),null),m(p,b(j,{get when(){return a()},get children(){var y=x0(),x=y.firstChild,O=x.nextSibling,v=O.firstChild,C=v.firstChild,k=C.nextSibling;return C.$$input=_=>u(_.currentTarget.value),m(k,f),m(O,b(j,{get when(){return re(()=>t()==="invalid")()&&i()},get children(){var _=w0();return m(_,i),_}}),null),I(_=>Y(C,"border",`1px solid ${t()==="invalid"?"#f85149":t()==="valid"?"#238636":"#30363d"}`)),I(()=>C.value=ft().structureName??""),y}}),N),m(M,()=>ft().structureType?"Click a tile in the room to build.":"Select a structure type, then click a tile."),p})()}Oe(["input","click"]);var C0=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">'),xo=R("<button type=button>"),k0=R("<option>/s");const T0=[.5,1,2,5,10,20],M0=[{delta:-100,label:"-100"},{delta:-10,label:"-10"}],E0=[{delta:10,label:"+10"},{delta:100,label:"+100"}];function _o(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 R0(){const r=()=>{const e=Qr(),t=gt(),n=In()??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=C0(),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 m(i,(()=>{var u=re(()=>!!rt());return()=>u()?"Loading…":`Tick ${gt()}`})()),m(s,r,null),m(o,b($e,{each:M0,children:u=>(()=>{var d=xo();return d.$$click=()=>io(u.delta),m(d,()=>u.label),I(f=>{var p=rt(),g=_o(rt());return p!==f.e&&(d.disabled=f.e=p),f.t=J(d,g,f.t),f},{e:void 0,t:void 0}),d})()}),c),ut(c,"click",ff,!0),m(c,()=>Vr()?"⏸":"▶"),m(o,b($e,{each:E0,children:u=>(()=>{var d=xo();return d.$$click=()=>io(u.delta),m(d,()=>u.label),I(f=>{var p=rt(),g=_o(rt());return p!==f.e&&(d.disabled=f.e=p),f.t=J(d,g,f.t),f},{e:void 0,t:void 0}),d})()}),null),h.addEventListener("change",u=>pf(parseFloat(u.currentTarget.value))),m(h,b($e,{each:T0,children:u=>(()=>{var d=k0(),f=d.firstChild;return d.value=u,m(d,u,f),d})()})),I(u=>{var d=rt()?"#f0883e":"#c9d1d9",f=rt(),p=Vr()?"#1a3a2a":"#161b22",g=Vr()?"#3fb950":"#8b949e",w=rt()?"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),g!==u.o&&Y(c,"color",u.o=g),w!==u.i&&Y(c,"cursor",u.i=w),u},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),I(()=>h.value=ks()),e})()}Oe(["click"]);var P0=R("<div style=padding-bottom:8px;overflow:auto;min-height:0>"),O0=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'),L0=R("<button style=background:transparent;border:none;color:#8b949e;font-size:14px;cursor:pointer;padding:4px>"),A0=R("<button style=background:transparent;border:none;color:#8b949e;font-size:11px;cursor:pointer>Collapse");function I0(r){return b(j,{get when(){return Mt()==="flag"},get fallback(){return b(j,{get when(){return Mt()==="build"},get fallback(){return b(pg,{})},get children(){return b(S0,{get shard(){return r.shard}})}})},get children(){return b(m0,{})}})}function N0(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=O0(),i=n.firstChild,s=i.nextSibling,o=s.firstChild;return o.firstChild,i.$$click=e,m(i,(()=>{var c=re(()=>!!r.onToggle);return()=>c()&&(()=>{var l=L0();return l.$$click=t,m(l,()=>r.isCollapsed?"▶":"◀"),l})()})()),m(o,(()=>{var c=re(()=>!!r.onToggle);return()=>c()&&(()=>{var l=A0();return l.$$click=t,l})()})(),null),m(s,b(j,{get when(){return r.mapMode},get fallback(){return b(kg,{get room(){return r.room??"—"},get shard(){return r.shard??null}})},get children(){return b(Qg,{get zoom(){return r.mapZoom},get subsActive(){return r.mapSubsActive}})}}),null),m(s,b(j,{get when(){return re(()=>!r.mapMode)()&&be()},get children(){return b(R0,{})}}),null),m(s,b(j,{get when(){return r.mapMode},get fallback(){return b(I0,{get shard(){return r.shard}})},get children(){var c=P0();return m(c,b(wo,{label:"Selected",get info(){return r.selectedRoomInfo??null}}),null),m(c,b(wo,{label:"Cursor",get info(){return r.hoveredRoomInfo??null},dim:!0}),null),c}}),null),n})()}Oe(["click"]);var D0=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>CPU:</span><span style=color:#c9d1d9>"),G0=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Memory:</span><span style=color:#c9d1d9>"),F0=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Zoom:</span><span style=color:#c9d1d9>%"),z0=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Subs:</span><span>"),B0=R('<div style="display:flex;gap:16px;padding:6px 16px;font-size:12px;color:#8b949e;align-items:center">');function W0(r){const[e,t]=z(null);tr(()=>{const s=me();if(!s)return;const o=new gs;o.add(s.stores.user.subscribe("cpu")),o.add(s.stores.user.on("user:cpu",c=>{t(c)})),Be(()=>{o.dispose()})});const n=()=>{var c;const s=e();if(!s)return"—";const o=((c=Ue())==null?void 0:c.cpu)??"?";return`${s.cpu.toFixed(0)} / ${o}`},i=()=>{const s=e();return s?`${(s.memory/1024).toFixed(1)} KB`:"—"};return(()=>{var s=B0();return m(s,b(j,{get when(){return e()!==null},get children(){return[(()=>{var o=D0(),c=o.firstChild,l=c.nextSibling;return m(l,n),o})(),(()=>{var o=G0(),c=o.firstChild,l=c.nextSibling;return m(l,i),o})()]}}),null),m(s,b(j,{get when(){return re(()=>r.mapZoom!==null)()&&r.mapZoom!==void 0},get children(){return[(()=>{var o=F0(),c=o.firstChild,l=c.nextSibling,a=l.firstChild;return m(l,()=>(r.mapZoom*100).toFixed(0),a),o})(),(()=>{var o=z0(),c=o.firstChild,l=c.nextSibling;return m(l,()=>r.mapSubsActive===!1?"paused":"active"),I(a=>Y(l,"color",r.mapSubsActive===!1?"#e3b341":"#3fb950")),o})()]}}),null),s})()}var H0=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">'),U0=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>"),V0=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">'),Y0=R("<button style=width:100%;aspect-ratio:1;border-radius:2px;cursor:pointer;padding:0;outline:none>");const jl={};for(let r=1;r<=24;r++){const e=Kn({type:r,color1:"#4a5060",color2:"#7a9ec0",color3:"#c0daf0",param:0,flip:!1});jl[r]=`data:image/svg+xml,${encodeURIComponent(e)}`}function Dt(r){var e;return typeof r=="string"?r:((e=zr[r])==null?void 0:e.rgb)??"#000000"}function Cn(r){return typeof r=="number"?Math.max(0,Math.min(79,r)):r}const X0=[{slot:1,label:"Background"},{slot:2,label:"Primary"},{slot:3,label:"Secondary"}],j0=Array.from({length:24},(r,e)=>e+1),_i=/^#[0-9a-f]{6}$/i;function q0(r){const[e,t]=z(ue(()=>typeof r.badge.type=="number"?r.badge.type:1)),[n,i]=z(ue(()=>Cn(r.badge.color1))),[s,o]=z(ue(()=>Cn(r.badge.color2))),[c,l]=z(ue(()=>Cn(r.badge.color3))),[a,h]=z(ue(()=>r.badge.param??0)),[u,d]=z(ue(()=>r.badge.flip??!1)),[f,p]=z(1),[g,w]=z(!1),[L,A]=z(ue(()=>Dt(Cn(r.badge.color1)))),N=_=>_===1?n():_===2?s():c(),M=_=>{const E=f();E===1?i(_):E===2?o(_):l(_)};fe(()=>{A(Dt(N(f())))});const y=_=>{var T;const E=N(f());return typeof E=="number"?E===_:E.toLowerCase()===(((T=zr[_])==null?void 0:T.rgb)??"").toLowerCase()},x=()=>({type:e(),color1:Dt(n()),color2:Dt(s()),color3:Dt(c()),param:a(),flip:u()}),O=Xr(()=>{const _=Kn(x());return`data:image/svg+xml,${encodeURIComponent(_)}`}),v=_=>{if(A(_),!_i.test(_))return;const E=zr.findIndex(T=>T.rgb.toLowerCase()===_.toLowerCase());M(E>=0?E:_)},C=async()=>{var E;const _=me();if(_){w(!0);try{await _.http.user.badge(x()),await _.stores.user.refreshMe(),r.onClose(),(E=r.onSaved)==null||E.call(r),ke("Badge saved","success",3e3)}catch(T){ke(`Failed to save badge: ${T instanceof Error?T.message:String(T)}`,"error",5e3)}finally{w(!1)}}},k=_=>{_.target===_.currentTarget&&r.onClose()};return(()=>{var _=H0(),E=_.firstChild,T=E.firstChild,P=T.firstChild,F=P.nextSibling,G=T.nextSibling,W=G.firstChild,D=W.firstChild,B=D.firstChild,U=B.nextSibling,H=D.nextSibling,q=H.firstChild,Z=q.nextSibling,X=W.nextSibling,K=X.firstChild,he=K.nextSibling,se=he.nextSibling,ie=se.nextSibling,pe=ie.firstChild,ee=pe.nextSibling,ge=X.nextSibling,Pe=ge.firstChild,Le=Pe.firstChild,je=Le.nextSibling,Je=Pe.nextSibling,Ot=ge.nextSibling,Qe=Ot.firstChild,le=G.nextSibling,oe=le.firstChild,de=oe.nextSibling;return _.$$click=k,F.$$click=()=>r.onClose(),m(F,b(Jt,{size:18})),m(Z,b($e,{each:j0,children:V=>(()=>{var Q=U0(),ne=Q.firstChild;return Q.$$click=()=>t(V),I(xe=>{var Se=e()===V?"#1f3a2a":"#0d1117",qe=`1px solid ${e()===V?"#238636":"#21262d"}`,bt=e()===V?O():jl[V];return Se!==xe.e&&Y(Q,"background",xe.e=Se),qe!==xe.t&&Y(Q,"border",xe.t=qe),bt!==xe.a&&_e(ne,"src",xe.a=bt),xe},{e:void 0,t:void 0,a:void 0}),Q})()})),m(he,b($e,{each:X0,children:({slot:V,label:Q})=>(()=>{var ne=V0(),xe=ne.firstChild;return ne.$$click=()=>p(V),m(ne,Q,null),I(Se=>{var qe=`1px solid ${f()===V?"#58a6ff":"#30363d"}`,bt=f()===V?"#1c2d47":"transparent",Mr=f()===V?"#58a6ff":"#8b949e",Er=Dt(N(V));return qe!==Se.e&&Y(ne,"border",Se.e=qe),bt!==Se.t&&Y(ne,"background",Se.t=bt),Mr!==Se.a&&Y(ne,"color",Se.a=Mr),Er!==Se.o&&Y(xe,"background",Se.o=Er),Se},{e:void 0,t:void 0,a:void 0,o:void 0}),ne})()})),m(se,b($e,{each:zr,children:V=>(()=>{var Q=Y0();return Q.$$click=()=>M(V.index),I(ne=>{var xe=V.rgb,Se=V.rgb,qe=y(V.index)?"2px solid #fff":"1px solid transparent";return xe!==ne.e&&_e(Q,"title",ne.e=xe),Se!==ne.t&&Y(Q,"background",ne.t=Se),qe!==ne.a&&Y(Q,"border",ne.a=qe),ne},{e:void 0,t:void 0,a:void 0}),Q})()})),ee.$$input=V=>v(V.currentTarget.value),m(je,a),Je.$$input=V=>h(+V.currentTarget.value),Qe.addEventListener("change",V=>d(V.currentTarget.checked)),oe.$$click=()=>r.onClose(),de.$$click=C,m(de,()=>g()?"Saving…":"Save Badge"),I(V=>{var Q=O(),ne=_i.test(L())?L():Dt(N(f())),xe=`1px solid ${_i.test(L())?"#30363d":"#f85149"}`,Se=g(),qe=g()?"not-allowed":"pointer",bt=g(),Mr=g()?"not-allowed":"pointer",Er=g()?.7:1;return Q!==V.e&&_e(U,"src",V.e=Q),ne!==V.t&&Y(pe,"background",V.t=ne),xe!==V.a&&Y(ee,"border",V.a=xe),Se!==V.o&&(oe.disabled=V.o=Se),qe!==V.i&&Y(oe,"cursor",V.i=qe),bt!==V.n&&(de.disabled=V.n=bt),Mr!==V.s&&Y(de,"cursor",V.s=Mr),Er!==V.h&&Y(de,"opacity",V.h=Er),V},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0}),I(()=>ee.value=L()),I(()=>Je.value=a()),I(()=>Qe.checked=u()),_})()}Oe(["click","input"]);var Z0=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">'),K0=R("<div style=font-size:11px;color:#8b949e;margin-top:3px>"),J0=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>"),Q0=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>'),em=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)'),tm=R("<img width=40 height=40 style=display:block>"),rm=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">'),nm=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">'),im=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 sm={type:1,color1:"#4a5060",color2:"#7a9ec0",color3:"#c0daf0",param:0,flip:!1};function Ct(r){return(()=>{var e=Z0(),t=e.firstChild,n=t.firstChild,i=t.nextSibling,s=i.firstChild;return m(n,()=>r.label),m(t,(()=>{var o=re(()=>!!r.description);return()=>o()&&(()=>{var c=K0();return m(c,()=>r.description),c})()})(),null),i.$$click=()=>r.onChange(!r.value),I(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 ar(r){return(()=>{var e=J0(),t=e.firstChild;return m(t,()=>r.title),m(e,()=>r.children,null),e})()}function $o(r){return(()=>{var e=Q0(),t=e.firstChild,n=t.nextSibling;return m(t,()=>r.label),m(n,()=>r.value),e})()}function om(r){var a;const e=pc(),t=!Ie()&&!((a=Ue())!=null&&a.badge),[n,i]=z(t),[s,o]=z(!1),c=Xr(()=>{var d;const h=(d=Ue())==null?void 0:d.badge;if(!h)return null;const u=Kn(h);return`data:image/svg+xml,${encodeURIComponent(u)}`});async function l(){o(!0);try{await mc(),ke("All caches cleared. Reloading…","success",2e3),setTimeout(()=>window.location.reload(),1500)}catch{ke("Failed to clear caches.","error"),o(!1)}}return(()=>{var h=im(),u=h.firstChild,d=u.firstChild,f=d.nextSibling,p=u.nextSibling,g=p.firstChild;return f.$$click=()=>r.onClose(),m(f,b(Jt,{size:18})),m(h,b(j,{get when(){return n()},get children(){return b(q0,{get badge(){var w;return((w=Ue())==null?void 0:w.badge)??sm},onClose:()=>i(!1),onSaved:t?()=>r.onClose():void 0})}}),p),m(g,b(ar,{title:"Layout",get children(){return b(Ct,{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 fl()},onChange:Bh})}}),null),m(g,b(ar,{title:"Room View",get children(){return[b(Ct,{label:"Show creep labels",description:"Display each creep's name above its sprite.",get value(){return Bn()},onChange:pl}),b(Ct,{label:"Terrain effects",description:"Swamp glow and wall noise texture overlay.",get value(){return ur()},onChange:Wh}),b(Ct,{label:"Verbose creep details",description:"Show a colour-coded body part breakdown (e.g. 8×MOVE, 4×WORK) in the creep property panel.",get value(){return wl()},onChange:Xh}),b(Ct,{label:"Room decorations",description:"Load player-activated theme decorations (floor, wall, road colors) from the server.",get value(){return ns()},onChange:Hh}),b(Ct,{label:"Dark overlay + lights",description:"Darken the room and add per-object light glows.",get value(){return is()},onChange:Uh}),(()=>{var w=em(),L=w.firstChild,A=L.nextSibling;return A.addEventListener("change",N=>Yh(N.currentTarget.value)),I(()=>A.value=ss()),w})()]}}),null),m(g,b(ar,{title:"Map View",get children(){return[b(Ct,{label:"Show room names",description:"Render a small room name in the top-left corner of each map tile.",get value(){return gl()},onChange:ml}),b(Ct,{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 yl()},onChange:vl})]}}),null),m(g,b(j,{get when(){return!Ie()},get children(){return b(ar,{title:"Player Badge",get children(){var w=rm(),L=w.firstChild,A=L.firstChild,N=L.nextSibling;return m(L,b(j,{get when(){return c()},get children(){var M=tm();return I(()=>_e(M,"src",c())),M}}),A),m(A,()=>{var M;return((M=Ue())==null?void 0:M.username)??""}),N.$$click=()=>i(!0),m(N,()=>c()?"Edit Badge":"Create Badge"),w}})}}),null),m(g,b(ar,{title:"Data",get children(){var w=nm(),L=w.firstChild,A=L.firstChild;A.nextSibling;var N=L.nextSibling;return N.$$click=l,m(N,()=>s()?"Clearing…":"Clear"),I(M=>{var y=s(),x=s()?"#8b949e":"#f85149",O=s()?"default":"pointer",v=s()?.6:1;return y!==M.e&&(N.disabled=M.e=y),x!==M.t&&Y(N,"color",M.t=x),O!==M.a&&Y(N,"cursor",M.a=O),v!==M.o&&Y(N,"opacity",M.o=v),M},{e:void 0,t:void 0,a:void 0,o:void 0}),w}}),null),m(g,b(ar,{title:"About",get children(){return[b($o,{label:"Client version",get value(){return fc()}}),re(()=>e&&b($o,{label:"Mod version",get value(){return`${e.version} (${e.kind})`}}))]}}),null),h})()}Oe(["click"]);var lm=R('<button style="padding:7px;border-radius:4px;cursor:pointer;margin:0 4px;display:flex;align-items:center">'),am=R('<button style="padding:7px;border-radius:4px;border:1px solid #30363d;background:#21262d;margin:0 2px;display:flex;align-items:center">'),cm=R("<div style=flex:1;position:relative;overflow:hidden>"),dm=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>'),um=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>'),hm=R("<div style=display:flex;flex:1;overflow:hidden><div style=display:flex;flex-direction:column;flex:1;overflow:hidden>"),fm=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 style="padding:7px;border-radius:4px;border:none;color:#fff;cursor:pointer;margin:0 16px 0 8px;display:flex;align-items:center">'),pm=R("<div style=display:flex;flex-direction:column;flex:1;overflow:hidden><div style=display:flex;flex:1;overflow:hidden>");const gm=To(()=>ps(()=>import("./CodePanel-Bfbl4rrd.js"),__vite__mapDeps([0,1,2])).then(r=>({default:r.CodePanel}))),mm=To(()=>ps(()=>import("./MapViewer-Bv7oMh47.js"),__vite__mapDeps([3,1,2])).then(r=>({default:r.MapViewer})));function $i(){const r=on(),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(!it(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 Si(r,e){return`${on()}/room/${r}${e?`?shard=${encodeURIComponent(e)}`:""}`}function So(r){return`${on()}/map${r?`?shard=${encodeURIComponent(r)}`:""}`}function Ci(){return window.location.pathname.startsWith(`${on()}/map`)?{shard:new URLSearchParams(window.location.search).get("shard")}:null}function ki(r){return(()=>{var e=lm();return e.$$click=()=>r.onClick(),m(e,()=>r.children),I(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&&_e(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 Co(r){return(()=>{var e=am();return e.$$click=()=>r.onClick(),m(e,()=>r.children),I(t=>{var n=r.title,i=r.disabled,s=r.disabled?"#484f58":"#c9d1d9",o=r.disabled?"default":"pointer";return n!==t.e&&_e(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 ym(){var Qe;const r=$i(),[e,t]=z(r.room??ri(ye.room)??"W1N1"),[n,i]=z(r.shard??ri(ye.shard)),[s,o]=z(Ci()!==null||!r.room),[c,l]=z(!Ie()&&!((Qe=Ue())!=null&&Qe.badge)),[a,h]=z(!1),[u,d]=z(!1);fe(()=>{a(),d(!0),Promise.resolve().then(()=>d(!1))}),fe(()=>{Ie()&&Tt("view")}),fe(()=>{var oe,de,V;if(n()!==null||Yo()!==!1)return;const le=(V=(de=(oe=vs())==null?void 0:oe.serverData)==null?void 0:de.shards)==null?void 0:V[0];le&&i(le)});const[f,p]=z(void 0),[g,w]=z(null),[L,A]=z(null),N=ri(ye.mapZoom),[M,y]=z(r.room&&N?Number(N):null),[x,O]=z(null),[v,C]=z(!1),[k,_]=z(!1);let E=r.tick;fe(()=>{const le=Ee();if(le===null||E===null)return;const oe=E;E=null,Pl(le),Vn(oe)}),fe(()=>{if(ue(s))return;const le=Si(e(),n());be()?history.replaceState(null,"",`${le}#tick=${gt()}`):history.replaceState(null,"",le)});const[T,P]=z(an(ye.sidebarWidth,300)),[F,G]=z(an(ye.sidebarWidth,300)),[W,D]=z(an(ye.consoleHeight,220)),[B,U]=z(an(ye.consoleHeight,220)),[H,q]=z(!1),[Z,X]=z(!1),K=()=>T()<=32,he=()=>W()<=32,se=()=>{T()>32?(G(T()),P(32)):P(F())},ie=()=>{W()>32?(U(W()),D(32)):D(B())},pe=le=>{le.preventDefault(),q(!0);const oe=le.clientX,de=T(),V=ne=>{const xe=ne.clientX-oe;P(Math.max(32,Math.min(500,de-xe)))},Q=()=>{q(!1),ni(ye.sidebarWidth,T()),window.removeEventListener("pointermove",V),window.removeEventListener("pointerup",Q)};window.addEventListener("pointermove",V),window.addEventListener("pointerup",Q)},ee=le=>{le.preventDefault(),X(!0);const oe=le.clientY,de=W(),V=ne=>{const xe=ne.clientY-oe;D(Math.max(32,Math.min(500,de-xe)))},Q=()=>{X(!1),ni(ye.consoleHeight,W()),window.removeEventListener("pointermove",V),window.removeEventListener("pointerup",Q)};window.addEventListener("pointermove",V),window.addEventListener("pointerup",Q)},ge=(le,oe)=>{var de;(de=me())==null||de.stores.navigation.navigateTo(le,oe)},Pe=le=>{p(le),o(!0),history.pushState(null,"",So(n()))},Le=()=>{s()?(o(!1),w(null),A(null),history.pushState(null,"",Si(e(),n()))):Pe(e())};tr(()=>{var V;!$i().room&&!Ci()&&history.replaceState(null,"",So(n()));const le=()=>{const Q=Ci();if(Q){o(!0),Q.shard!==null&&i(Q.shard),ue(be)&&Un();return}const{room:ne,shard:xe,tick:Se}=$i();ne&&(t(ne),i(xe),o(!1),Se!==null?E=Se:ue(be)&&Un())};window.addEventListener("popstate",le),Be(()=>window.removeEventListener("popstate",le));const oe=(V=me())==null?void 0:V.stores.navigation;if(oe){const Q=oe.on("navigation:change",ne=>{ne.room!==null&&(t(ne.room),i(ne.shard),o(!1),w(null),A(null),C(oe.canBack()),_(oe.canForward()),Ds(ye.room,ne.room),ne.shard?Ds(ye.shard,ne.shard):gc(ye.shard),history.pushState(null,"",Si(ne.room,ne.shard)))});Be(()=>Q.dispose())}const de=Q=>{if(!Tl(Q.target)){if(Q.key==="o"||Q.key==="O"){h(ne=>!ne),l(!1);return}(Q.key==="l"||Q.key==="L")&&Nl(),(Q.key==="c"||Q.key==="C")&&Dl(),(Q.key==="y"||Q.key==="Y")&&Gl(),s()||(Q.key==="1"&&Tt("view"),Ie()||(Q.key==="2"&&Tt("flag"),Q.key==="3"&&Tt("build")),Q.key==="m"&&Pe(e()))}};window.addEventListener("keydown",de),Be(()=>window.removeEventListener("keydown",de))});const je=()=>(()=>{var le=cm();return m(le,b(j,{get when(){return c()},get children(){return b(om,{onClose:()=>l(!1)})}}),null),m(le,b(j,{get when(){return a()},get children(){return b(gm,{onClose:()=>h(!1)})}}),null),m(le,b(j,{get when(){return!s()},get fallback(){return b(mm,{get shard(){return n()},get originRoom(){return f()},get initialZoom(){return M()??void 0},onNavigateToRoom:oe=>ge(oe,n()),onHoveredRoomChanged:w,onSelectedRoomChanged:A,onZoomChanged:oe=>{y(oe),ni(ye.mapZoom,oe)},onSubscriptionStateChanged:O})},get children(){return b(Rf,{get room(){return e()},get shard(){return n()},onNavigate:ge})}}),null),le})(),Je=()=>b(j,{get when(){return!Ie()},get children(){var le=dm(),oe=le.firstChild;return oe.$$pointerdown=ee,m(le,b(gp,{get shard(){return n()},get isCollapsed(){return he()},onToggle:ie}),null),I(de=>{var V=`${W()}px`,Q=Z()?"none":"height 0.15s ease";return V!==de.e&&Y(le,"height",de.e=V),Q!==de.t&&Y(le,"transition",de.t=Q),de},{e:void 0,t:void 0}),le}}),Ot=le=>(()=>{var oe=um(),de=oe.firstChild;return de.$$pointerdown=pe,m(oe,b(N0,{get isCollapsed(){return K()},onToggle:se,get mapMode(){return s()},get hoveredRoomInfo(){return g()},get selectedRoomInfo(){return L()},get room(){return e()},get shard(){return n()},get mapZoom(){return M()},get mapSubsActive(){return x()}}),null),I(V=>{var Q=a()?"0":`${T()}px`,ne=le&&!(u()||H())?"width 0.15s ease":"none";return Q!==V.e&&Y(oe,"width",V.e=Q),ne!==V.t&&Y(oe,"transition",V.t=ne),V},{e:void 0,t:void 0}),oe})();return(()=>{var le=fm(),oe=le.firstChild,de=oe.firstChild,V=de.nextSibling;return m(oe,b(wu,{}),de),m(oe,b(j,{get when(){return!Ie()||s()},get children(){return b(W0,{get mapZoom(){return re(()=>!!s())()?M():null},get mapSubsActive(){return re(()=>!!s())()?x():null}})}}),de),m(oe,b(Co,{title:"Back",get disabled(){return!v()},onClick:()=>{var Q;return(Q=me())==null?void 0:Q.stores.navigation.back()},get children(){return b(Uc,{size:16})}}),V),m(oe,b(Co,{title:"Forward",get disabled(){return!k()},onClick:()=>{var Q;return(Q=me())==null?void 0:Q.stores.navigation.forward()},get children(){return b(jo,{size:16})}}),V),m(oe,b(ki,{get title(){return s()?"Room View":"Map"},get active(){return s()},onClick:Le,get children(){return re(()=>!!s())()?b(od,{size:16}):b(vd,{size:16})}}),V),m(oe,b(j,{get when(){return!Ie()},get children(){return b(ki,{title:"Code Editor",get active(){return a()},onClick:()=>{h(Q=>!Q),l(!1)},get children(){return b(Zc,{size:16})}})}}),V),m(oe,b(ki,{title:"Settings",get active(){return c()},onClick:()=>{l(Q=>!Q),h(!1)},get children(){return b(Nd,{size:16})}}),V),ut(V,"click",_c,!0),m(V,(()=>{var Q=re(()=>!!Ie());return()=>Q()?b(hd,{size:16}):b(gd,{size:16})})()),m(le,b(j,{get when(){return fl()},get fallback(){return(()=>{var Q=pm(),ne=Q.firstChild;return m(ne,je,null),m(ne,()=>Ot(!0),null),m(Q,Je,null),Q})()},get children(){var Q=hm(),ne=Q.firstChild;return m(ne,je,null),m(ne,Je,null),m(Q,()=>Ot(!1),null),Q}}),null),m(le,b(Lf,{}),null),I(Q=>{var ne=Ie()?"Login":"Logout",xe=Ie()?"#238636":"#da3633";return ne!==Q.e&&_e(V,"title",Q.e=ne),xe!==Q.t&&Y(V,"background",Q.t=xe),Q},{e:void 0,t:void 0}),le})()}Oe(["click","pointerdown"]);var vm=R("<div style=width:100%;height:100%>");function bm(){const r=new URLSearchParams(window.location.search).get("guest");return r===null?null:r.startsWith("http")?r:kn(He.url)??"https://screeps.com"}function wm(){const r=()=>Vt()==="connected"&&me()!==null;return tr(async()=>{if(Vt()==="idle"&&(await xc().catch(()=>{}),Vt()!=="connected"&&!Jn())){const e=bm();e&&Wt({url:e,auth:"guest",storage:null}).catch(()=>{})}}),(()=>{var e=vm();return m(e,(()=>{var t=re(()=>!!r());return()=>t()?b(ym,{}):b(yu,{})})()),e})()}const ql=document.getElementById("root");if(!ql)throw new Error("Root element not found");ga(()=>b(wm,{}),ql);export{km as M,ke as a,Pt as b,me as c,Oe as d,Sm as e,Ze as f,Cm as g,as as h,m as i,Ho as j,gl as k,jh as l,Tg as m,yl as n,df as o,it as p,Ue as q,Y as s,R as t,pr as u,ii as w};