screeps-client 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/embedded/_client/{CodePanel-GQOhmg-I.js → CodePanel-KBQ78175.js} +1 -1
  2. package/dist/{standalone/_client/MapViewer-CFzJVSsf.js → embedded/_client/MapViewer-BL7mzGWw.js} +1 -1
  3. package/dist/embedded/_client/index-KFumkHjd.js +24 -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-C-DMhyuw.js → CodePanel-sM0UkfOw.js} +1 -1
  9. package/dist/{embedded/_client/MapViewer-qJGNT0CU.js → standalone/_client/MapViewer-B-eI44Qx.js} +1 -1
  10. package/dist/standalone/_client/index-CHCJvDO3.js +24 -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-C4wZSlgU.js → CodePanel-Bfi6k72H.js} +1 -1
  16. package/dist/xxscreeps-mod/_client/{MapViewer-DdHdvydQ.js → MapViewer-CKPZHZAs.js} +1 -1
  17. package/dist/xxscreeps-mod/_client/index-04hhqfkD.js +24 -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/index-DH5qlAud.js +0 -24
  24. package/dist/embedded/_client/vendor-pixi-D-Qjltr2.js +0 -1215
  25. package/dist/standalone/_client/index-RbsPr76e.js +0 -24
  26. package/dist/standalone/_client/vendor-pixi-CVMJwxeR.js +0 -1215
  27. package/dist/xxscreeps-mod/_client/index-BlhT0eYc.js +0 -24
  28. package/dist/xxscreeps-mod/_client/vendor-pixi-DOKo__Ml.js +0 -1215
@@ -0,0 +1,24 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_client/CodePanel-KBQ78175.js","_client/vendor-codemirror-D3PB7yT8.js","_client/vendor-pixi-CWBnI4gg.js","_client/MapViewer-BL7mzGWw.js"])))=>i.map(i=>d[i]);
2
+ var Cl=Object.defineProperty;var kl=(r,e,t)=>e in r?Cl(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var $=(r,e,t)=>kl(r,typeof e!="symbol"?e+"":e,t);import{k as qn,j as N,i as Fr,v as to,w as de,$ as Tl,u as Ie,l as B,p as ve,f as b,F as $e,S as q,h as he,r as Ge,D as Ml,a as jt,d as El,b as cs,m as pn,s as Kt,q as Rl,o as ro}from"./vendor-codemirror-D3PB7yT8.js";import{_ as Zn,b as Ne,G as re,A as io,P as Cr,S as ze,d as Ae,R as no,a as gn,e as ds,N as Ol,B as Pl,T as Bt,c as Ll,C as Al}from"./vendor-pixi-CWBnI4gg.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))i(n);new MutationObserver(n=>{for(const s of n)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&i(o)}).observe(document,{childList:!0,subtree:!0});function t(n){const s={};return n.integrity&&(s.integrity=n.integrity),n.referrerPolicy&&(s.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?s.credentials="include":n.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function i(n){if(n.ep)return;n.ep=!0;const s=t(n);fetch(n.href,s)}})();const Il=["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"],Nl=new Set(["className","value","readOnly","noValidate","formNoValidate","isMap","noModule","playsInline","adAuctionHeaders","allowFullscreen","browsingTopics","defaultChecked","defaultMuted","defaultSelected","disablePictureInPicture","disableRemotePlayback","preservesPitch","shadowRootClonable","shadowRootCustomElementRegistry","shadowRootDelegatesFocus","shadowRootSerializable","sharedStorageWritable",...Il]),Dl=new Set(["innerHTML","textContent","innerText","children"]),zl=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),Gl=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 Bl(r,e){const t=Gl[r];return typeof t=="object"?t[e]?t.$:void 0:t}const Fl=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),Hl=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"]),Wl={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},te=r=>Fr(()=>r());function Ul(r,e,t){let i=t.length,n=e.length,s=i,o=0,c=0,l=e[n-1].nextSibling,a=null;for(;o<n||c<s;){if(e[o]===t[c]){o++,c++;continue}for(;e[n-1]===t[s-1];)n--,s--;if(n===o){const u=s<i?c?t[c-1].nextSibling:t[s-c]:l;for(;c<s;)r.insertBefore(t[c++],u)}else if(s===c)for(;o<n;)(!a||!a.has(e[o]))&&e[o].remove(),o++;else if(e[o]===t[s-1]&&t[c]===e[n-1]){const u=e[--n].nextSibling;r.insertBefore(t[c++],e[o++].nextSibling),r.insertBefore(t[--s],u),e[n]=t[s]}else{if(!a){a=new Map;let h=c;for(;h<s;)a.set(t[h],h++)}const u=a.get(e[o]);if(u!=null)if(c<u&&u<s){let h=o,d=1,f;for(;++h<n&&h<s&&!((f=a.get(e[h]))==null||f!==u+d);)d++;if(d>u-c){const p=e[o];for(;c<u;)r.insertBefore(t[c++],p)}else r.replaceChild(t[c++],e[o++])}else o++;else e[o++].remove()}}}const us="_$DX_DELEGATE";function Yl(r,e,t,i={}){if(!e)throw new Error("The `element` passed to `render(..., element)` doesn't exist. Make sure `element` exists in the document.");let n;return qn(s=>{n=s,e===document?r():m(e,r(),e.firstChild?null:void 0,t)},i.owner),()=>{n(),e.textContent=""}}function R(r,e,t,i){let n;const s=()=>{if(kt())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=()=>(n||(n=s())).cloneNode(!0);return o.cloneNode=o,o}function Re(r,e=window.document){const t=e[us]||(e[us]=new Set);for(let i=0,n=r.length;i<n;i++){const s=r[i];t.has(s)||(t.add(s),e.addEventListener(s,Ql))}}function _e(r,e,t){kt(r)||(t==null?r.removeAttribute(e):r.setAttribute(e,t))}function Xl(r,e,t,i){kt(r)||(i==null?r.removeAttributeNS(e,t):r.setAttributeNS(e,t,i))}function jl(r,e,t){kt(r)||(t?r.setAttribute(e,""):r.removeAttribute(e))}function Vl(r,e){kt(r)||(e==null?r.removeAttribute("class"):r.className=e)}function lt(r,e,t,i){if(i)Array.isArray(t)?(r[`$$${e}`]=t[0],r[`$$${e}Data`]=t[1]):r[`$$${e}`]=t;else if(Array.isArray(t)){const n=t[0];r.addEventListener(e,t[0]=s=>n.call(r,t[1],s))}else r.addEventListener(e,t,typeof t!="function"&&t)}function ql(r,e,t={}){const i=Object.keys(e||{}),n=Object.keys(t);let s,o;for(s=0,o=n.length;s<o;s++){const c=n[s];!c||c==="undefined"||e[c]||(hs(r,c,!1),delete t[c])}for(s=0,o=i.length;s<o;s++){const c=i[s],l=!!e[c];!c||c==="undefined"||t[c]===l||!l||(hs(r,c,!0),t[c]=l)}return t}function Q(r,e,t){if(!e)return t?_e(r,"style"):e;const i=r.style;if(typeof e=="string")return i.cssText=e;typeof t=="string"&&(i.cssText=t=void 0),t||(t={}),e||(e={});let n,s;for(s in t)e[s]==null&&i.removeProperty(s),delete t[s];for(s in e)n=e[s],n!==t[s]&&(i.setProperty(s,n),t[s]=n);return t}function X(r,e,t){t!=null?r.style.setProperty(e,t):r.style.removeProperty(e)}function so(r,e={},t,i){const n={};return i||N(()=>n.children=Hr(r,e.children,n.children)),N(()=>typeof e.ref=="function"&&dr(e.ref,r)),N(()=>Zl(r,e,t,!0,n,!0)),n}function dr(r,e,t){return de(()=>r(e,t))}function m(r,e,t,i){if(t!==void 0&&!i&&(i=[]),typeof e!="function")return Hr(r,e,i,t);N(n=>Hr(r,e(),n,t),i)}function Zl(r,e,t,i,n={},s=!1){e||(e={});for(const o in n)if(!(o in e)){if(o==="children")continue;n[o]=fs(r,o,null,n[o],t,s,e)}for(const o in e){if(o==="children")continue;const c=e[o];n[o]=fs(r,o,c,n[o],t,s,e)}}function Kl(r){let e,t,i=kt();if(!i||!(e=Ie.registry.get(t=ea()))){if(i)throw Ie.done=!0,new Error(`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${t}
3
+ `);return r()}return Ie.completed&&Ie.completed.add(e),Ie.registry.delete(t),e}function kt(r){return!!Ie.context&&!Ie.done&&(!r||r.isConnected)}function Jl(r){return r.toLowerCase().replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function hs(r,e,t){const i=e.trim().split(/\s+/);for(let n=0,s=i.length;n<s;n++)r.classList.toggle(i[n],t)}function fs(r,e,t,i,n,s,o){let c,l,a,u,h;if(e==="style")return Q(r,t,i);if(e==="classList")return ql(r,t,i);if(t===i)return i;if(e==="ref")s||t(r);else if(e.slice(0,3)==="on:"){const d=e.slice(3);i&&r.removeEventListener(d,i,typeof i!="function"&&i),t&&r.addEventListener(d,t,typeof t!="function"&&t)}else if(e.slice(0,10)==="oncapture:"){const d=e.slice(10);i&&r.removeEventListener(d,i,!0),t&&r.addEventListener(d,t,!0)}else if(e.slice(0,2)==="on"){const d=e.slice(2).toLowerCase(),f=Fl.has(d);if(!f&&i){const p=Array.isArray(i)?i[0]:i;r.removeEventListener(d,p)}(f||t)&&(lt(r,d,t,f),f&&Re([d]))}else if(e.slice(0,5)==="attr:")_e(r,e.slice(5),t);else if(e.slice(0,5)==="bool:")jl(r,e.slice(5),t);else if((h=e.slice(0,5)==="prop:")||(a=Dl.has(e))||!n&&((u=Bl(e,r.tagName))||(l=Nl.has(e)))||(c=r.nodeName.includes("-")||"is"in o)){if(h)e=e.slice(5),l=!0;else if(kt(r))return t;e==="class"||e==="className"?Vl(r,t):c&&!l&&!a?r[Jl(e)]=t:r[u||e]=t}else{const d=n&&e.indexOf(":")>-1&&Wl[e.split(":")[0]];d?Xl(r,d,e,t):_e(r,zl[e]||e,t)}return t}function Ql(r){if(Ie.registry&&Ie.events&&Ie.events.find(([l,a])=>a===r))return;let e=r.target;const t=`$$${r.type}`,i=r.target,n=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}}),Ie.registry&&!Ie.done&&(Ie.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===n)break}}else c();s(i)}function Hr(r,e,t,i,n){const s=kt(r);if(s){!t&&(t=[...r.childNodes]);let l=[];for(let a=0;a<t.length;a++){const u=t[a];u.nodeType===8&&u.data.slice(0,2)==="!$"?u.remove():l.push(u)}t=l}for(;typeof t=="function";)t=t();if(e===t)return t;const o=typeof e,c=i!==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=Jt(r,t,i,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=Jt(r,t,i)}else{if(o==="function")return N(()=>{let l=e();for(;typeof l=="function";)l=l();t=Hr(r,l,t,i)}),()=>t;if(Array.isArray(e)){const l=[],a=t&&Array.isArray(t);if(mn(l,e,t,n))return N(()=>t=Hr(r,l,t,i,!0)),()=>t;if(s){if(!l.length)return t;if(i===void 0)return t=[...r.childNodes];let u=l[0];if(u.parentNode!==r)return t;const h=[u];for(;(u=u.nextSibling)!==i;)h.push(u);return t=h}if(l.length===0){if(t=Jt(r,t,i),c)return t}else a?t.length===0?ps(r,l,i):Ul(r,t,l):(t&&Jt(r),ps(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=Jt(r,t,i,e);Jt(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 mn(r,e,t,i){let n=!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))n=mn(r,c,l)||n;else if(a==="function")if(i){for(;typeof c=="function";)c=c();n=mn(r,Array.isArray(c)?c:[c],Array.isArray(l)?l:[l])||n}else r.push(c),n=!0;else{const u=String(c);l&&l.nodeType===3&&l.data===u?r.push(l):r.push(document.createTextNode(u))}}return n}function ps(r,e,t=null){for(let i=0,n=e.length;i<n;i++)r.insertBefore(e[i],t)}function Jt(r,e,t,i){if(t===void 0)return r.textContent="";const n=i||document.createTextNode("");if(e.length){let s=!1;for(let o=e.length-1;o>=0;o--){const c=e[o];if(n!==c){const l=c.parentNode===r;!s&&!o?l?r.replaceChild(n,c):r.insertBefore(n,t):l&&c.remove()}else s=!0}}else r.insertBefore(n,t);return[n]}function ea(){return Ie.getNextContextId()}const ta="http://www.w3.org/2000/svg";function ra(r,e=!1,t=void 0){return e?document.createElementNS(ta,r):document.createElement(r,{is:t})}function ia(r,e){const t=Fr(r);return Fr(()=>{const i=t();switch(typeof i){case"function":return Object.assign(i,{[Tl]:!0}),de(()=>i(e));case"string":const n=Hl.has(i),s=Ie.context?Kl():ra(i,n,de(()=>e.is));return so(s,e,n),s}})}function oo(r){const[,e]=to(r,["component"]);return ia(()=>r.component,e)}async function lo(r,e){const t=r.slice(3),i=Uint8Array.from(atob(t),o=>o.charCodeAt(0)),n=new Blob([i]).stream().pipeThrough(new DecompressionStream(e)),s=await new Response(n).text();try{return JSON.parse(s)}catch{return s}}function ao(r){return lo(r,"gzip")}function co(r){return lo(r,"deflate")}const na=Object.freeze(Object.defineProperty({__proto__:null,decompressGzip:ao,decompressZlib:co},Symbol.toStringTag,{value:"Module"}));class ut{constructor(e){$(this,"fn");this.fn=e}static create(e){return e===!0?new ut(console.debug.bind(console)):typeof e=="function"?new ut(e):new ut(null)}child(e){if(!this.fn)return this;const t=this.fn;return new ut((...i)=>t(`[screeps:${e}]`,...i))}log(...e){var t;(t=this.fn)==null||t.call(this,...e)}}function sa(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 oa(r){return{list:()=>r.request("GET","/api/game/power-creeps/list"),create:(e,t)=>r.request("POST","/api/game/power-creeps/create",{name:e,className:t}),delete:e=>r.request("POST","/api/game/power-creeps/delete",{id:e}),cancelDelete:e=>r.request("POST","/api/game/power-creeps/cancel-delete",{id:e}),upgrade:(e,t)=>r.request("POST","/api/game/power-creeps/upgrade",{id:e,powers:t}),rename:(e,t)=>r.request("POST","/api/game/power-creeps/rename",{id:e,name:t}),experimentation:()=>r.request("POST","/api/game/power-creeps/experimentation")}}function Me(r,e){return e&&(r.shard=e),r}function la(r,e){return{roomTerrain:(t,i)=>r.request("GET","/api/game/room-terrain",Me({room:t,encoded:1},i)),roomObjects:(t,i)=>r.request("GET","/api/game/room-objects",Me({room:t},i)),roomDecorations:e?()=>Promise.resolve(e):(t,i)=>r.request("GET","/api/game/room-decorations",Me({room:t},i)),roomStatus:(t,i)=>r.request("GET","/api/game/room-status",Me({room:t},i)),roomOverview:(t,i=8,n)=>r.request("GET","/api/game/room-overview",Me({room:t,interval:i},n)),time:t=>r.request("GET","/api/game/time",Me({},t)),worldSize:t=>r.request("GET","/api/game/world-size",Me({},t)),mapStats:(t,i,n)=>r.request("POST","/api/game/map-stats",Me({rooms:t,statName:i},n)),roomsTerrain:(t,i)=>{const n=new URLSearchParams({encoded:"true"});return i&&n.set("shard",i),r.request("POST",`/api/game/rooms?${n}`,{rooms:t})},createFlag:(t,i,n,s,o,c,l)=>r.request("POST","/api/game/create-flag",Me({room:t,x:i,y:n,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,i,n,s)=>r.request("POST","/api/game/change-flag-color",{room:t,name:i,color:n,secondaryColor:s}),removeFlag:(t,i)=>r.request("POST","/api/game/remove-flag",{room:t,name:i}),genUniqueObjectName:(t,i)=>r.request("POST","/api/game/gen-unique-object-name",Me({type:t},i)),checkUniqueObjectName:(t,i,n)=>r.request("POST","/api/game/check-unique-object-name",Me({type:t,name:i},n)),placeSpawn:(t,i,n,s,o)=>r.request("POST","/api/game/place-spawn",Me({room:t,x:i,y:n,...s?{name:s}:{}},o)),createConstruction:(t,i,n,s,o,c)=>r.request("POST","/api/game/create-construction",Me({room:t,x:i,y:n,structureType:s,...o?{name:o}:{}},c)),removeConstructionSite:(t,i,n)=>r.request("POST","/api/game/add-object-intent",Me({_id:"room",room:t,name:"removeConstructionSite",intent:i.map(s=>({id:s,roomName:t}))},n)),addObjectIntent:(t,i,n,s,o)=>r.request("POST","/api/game/add-object-intent",Me({_id:t,room:i,name:n,intent:s},o)),addGlobalIntent:(t,i)=>r.request("POST","/api/game/add-global-intent",{name:t,intent:i}),roomHistory:(t,i,n)=>n?r.request("GET",`/room-history/${encodeURIComponent(n)}/${encodeURIComponent(t)}/${i}.json`):r.request("GET","/room-history",{room:t,time:i}),setNotifyWhenAttacked:(t,i)=>r.request("POST","/api/game/set-notify-when-attacked",{_id:t,enabled:i}),createInvader:(t,i,n,s,o,c)=>r.request("POST","/api/game/create-invader",{room:t,x:i,y:n,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:oa(r),market:{ordersIndex:t=>r.request("GET","/api/game/market/orders-index",Me({},t)),myOrders:()=>r.request("GET","/api/game/market/my-orders"),orders:(t,i)=>r.request("GET","/api/game/market/orders",Me({resourceType:t},i)),stats:(t,i)=>r.request("GET","/api/game/market/stats",Me({resourceType:t},i))},shards:{info:()=>r.request("GET","/api/game/shards/info")}}}function aa(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 Qt(r,e){return e&&(r.shard=e),r}function ca(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",Qt({path:e},t)),set:(e,t,i)=>r.request("POST","/api/user/memory",Qt({path:e,value:t},i)),segment:{get:(e,t)=>r.request("GET","/api/user/memory-segment",Qt({segment:e},t)),set:(e,t,i)=>r.request("POST","/api/user/memory-segment",Qt({segment:e,data:t},i))}},console:(e,t)=>r.request("POST","/api/user/console",Qt({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",Qt({},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,i)=>r.request("POST","/api/user/clone-branch",{newName:e,...t?{branch:t}:{},...i!=null?{defaultModules:i}:{}}),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:aa(r)}}function da(r){return{list:(e=10,t="world",i=0,n)=>r.request("GET","/api/leaderboard/list",{limit:e,mode:t,offset:i,season:n}),find:(e,t="world",i="")=>r.request("GET","/api/leaderboard/find",{username:e,mode:t,season:i}),seasons:()=>r.request("GET","/api/leaderboard/seasons")}}function ua(r){return{pvp:(e=100)=>r.request("GET","/api/experimental/pvp",{interval:e}),nukes:()=>r.request("GET","/api/experimental/nukes")}}function ha(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,i,n)=>r.request("POST","/api/register/submit",{username:e,email:t,password:i,...n!=null?{modules:n}:{}})}}class fa extends EventTarget{constructor(t){super();$(this,"baseUrl");$(this,"authStrategy");$(this,"logger");$(this,"serverPassword");$(this,"token",null);$(this,"rateLimits",new Map);$(this,"authenticating",!1);$(this,"auth");$(this,"register");$(this,"game");$(this,"user");$(this,"leaderboard");$(this,"experimental");this.baseUrl=t.url.endsWith("/")?t.url:`${t.url}/`,this.authStrategy=t.auth,this.logger=t.logger??ut.create(),this.serverPassword=t.serverPassword??null,this.auth=sa(this),this.register=ha(this),this.game=la(this,t.decorationsMock),this.user=ca(this),this.leaderboard=da(this),this.experimental=ua(this)}emit(t,i){this.dispatchEvent(new CustomEvent(t,{detail:i}))}on(t,i){const n=s=>i(s.detail);return this.addEventListener(t,n),{dispose:()=>{this.removeEventListener(t,n)}}}async authenticate(){this.logger.log("authenticate"),this.authenticating=!0;try{this.token=await this.authStrategy.authenticate(this),this.logger.log("authenticated")}finally{this.authenticating=!1}}setToken(t){this.token=t}async request(t,i,n,s=!1){this.logger.log(t,i);const o=new URL(i.startsWith("/")?i.slice(1):i,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"&&n)for(const[d,f]of Object.entries(n))f!=null&&o.searchParams.set(d,String(f));else n&&(c["Content-Type"]="application/json",l.body=JSON.stringify(n));const a=await fetch(o.toString(),l),u=a.headers.get("x-token");if(u&&(this.token=u,this.emit("http:tokenRefresh",{token:u})),this.updateRateLimit(i,a),a.status===401&&!s&&!this.authenticating)return await this.authenticate(),this.request(t,i,n,!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:i,status:a.status,error:f}),f}this.emit("http:success",{method:t,path:i,status:a.status});const h=await a.json();if(typeof h.error=="string"){const d=new Error(`Screeps API error: ${h.error}`);throw this.emit("http:error",{method:t,path:i,status:a.status,error:d}),d}return typeof h.data=="string"&&h.data.startsWith("gz:")&&(h.data=await ao(h.data)),h}updateRateLimit(t,i){const n=i.headers.get("x-ratelimit-limit"),s=i.headers.get("x-ratelimit-remaining"),o=i.headers.get("x-ratelimit-reset");n&&s&&o&&this.rateLimits.set(t,{limit:parseInt(n,10),remaining:parseInt(s,10),reset:parseInt(o,10)})}}async function pa(r){let e=typeof r=="string"?r:r.data;if(e.startsWith("gz:")&&(e=JSON.stringify(await co(e))),e.startsWith("[")){const[n,s]=JSON.parse(e);return{kind:"channel",message:{channel:n,data:s}}}const[t,...i]=e.split(" ");switch(t){case"auth":return{kind:"server",command:{type:"auth",status:i[0],token:i[1]}};case"time":return{kind:"server",command:{type:"time",time:parseInt(i[0],10)}};case"protocol":return{kind:"server",command:{type:"protocol",protocol:parseInt(i[0],10)}};case"package":return{kind:"server",command:{type:"package",package:parseInt(i[0],10)}};default:throw new Error(`Unknown server command: ${t}`)}}class ga{constructor(e){$(this,"wsUrl");$(this,"WS");$(this,"logger");$(this,"ws",null);$(this,"token",null);$(this,"authed",!1);$(this,"_connected",!1);$(this,"reconnecting",!1);$(this,"authSub",null);$(this,"queue",[]);$(this,"subs",new Map);$(this,"listeners",new Map);$(this,"MAX_RETRIES",10);$(this,"MAX_DELAY_MS",6e4);$(this,"_intentionalClose",!1);const t=e.url.replace(/^http/,"ws").replace(/\/$/,"");this.wsUrl=`${t}/socket/websocket`,this.WS=e.WebSocket??globalThis.WebSocket,this.logger=e.logger??ut.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((i,n)=>{this.ws=new this.WS(this.wsUrl),this.ws.onopen=()=>{this.logger.log("WebSocket opened"),this._connected=!0,this.reconnecting=!1,this.rawSend(`auth ${this.token}`),this.authSub=this.once("auth",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",{}),i()}else this.logger.log("auth failed"),n(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||n(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 i=this.listeners.get(e);return i||(i=new Set,this.listeners.set(e,i)),i.add(t),{dispose:()=>{var n;(n=this.listeners.get(e))==null||n.delete(t)}}}once(e,t){const i=this.on(e,n=>{i.dispose(),t(n)});return i}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 i;(i=this.listeners.get(e))==null||i.forEach(n=>{try{n(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 pa(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 i=Math.min(Math.pow(2,e)*100,this.MAX_DELAY_MS);if(this.logger.log(`reconnect attempt ${e+1}/${this.MAX_RETRIES} in ${i}ms`),await new Promise(n=>setTimeout(n,i)),!this.reconnecting||this._intentionalClose)return;try{if(await this.connect(this.token),this._intentionalClose){(t=this.ws)==null||t.close(),this.ws=null;return}for(const n of this.subs.keys())this.rawSend(`subscribe ${n}`);return}catch{e++}}this.reconnecting=!1,e>=this.MAX_RETRIES&&!this._intentionalClose&&this.emit("socket:error",new Error(`WebSocket reconnection failed after ${this.MAX_RETRIES} retries`))}}class ma{constructor(e,t){$(this,"memory",new Map);$(this,"storage");$(this,"namespace");this.namespace=e,this.storage=t}memKey(e){return`${this.namespace}/${e}`}get(e){const t=this.memory.get(this.memKey(e));if(t){if(t.expires!==void 0&&Date.now()>t.expires){this.memory.delete(this.memKey(e));return}return t.data}}set(e,t,i){this.memory.set(this.memKey(e),{data:t,expires:i!==void 0?Date.now()+i: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 xr extends EventTarget{constructor(t){super();$(this,"logger");this.logger=t??ut.create()}emit(t,i){this.dispatchEvent(new CustomEvent(t,{detail:i}))}on(t,i){this.logger.log(`on "${t}"`);const n=s=>i(s.detail);return this.addEventListener(t,n),{dispose:()=>{this.logger.log(`off "${t}"`),this.removeEventListener(t,n)}}}}var Xe=(r=>(r[r.Plain=0]="Plain",r[r.Wall=1]="Wall",r[r.Swamp=2]="Swamp",r))(Xe||{});class ur{constructor(e){$(this,"raw");this.raw=e}static fromEncodedString(e){const t=new Uint8Array(2500);for(let i=0;i<2500;i++){const n=parseInt(e[i],10);t[i]=n===3?1:n}return new ur(t)}get(e,t){return this.raw[t*50+e]}}class ya extends xr{constructor(t,i,n,s){super(s);$(this,"http");$(this,"socket");$(this,"cache");$(this,"roomObjects",new Map);$(this,"roomUsers",new Map);$(this,"roomSubCount",new Map);$(this,"lastFlagsString",new Map);this.http=t,this.socket=i,this.cache=n}parseFlagsString(t,i){if(!t||t.length===0)return[];const n=[],s=t.split("|");for(const o of s){const c=o.split("~");if(c.length!==5)continue;const[l,a,u,h,d]=c,f=parseInt(a,10),p=parseInt(u,10),g=parseInt(h,10),S=parseInt(d,10);isNaN(f)||isNaN(p)||isNaN(g)||isNaN(S)||n.push({_id:l,type:"flag",room:i,name:l,x:g,y:S,color:f,secondaryColor:p})}return n}async terrain(t,i){const n=`terrain/${i}/${t}`,s=this.cache.get(n);if(s)return this.logger.log("terrain",t,i,"(memory cache hit)"),s;const o=await this.cache.getPersistent(n);if(o){this.logger.log("terrain",t,i,"(persistent cache hit)");const u=new ur(o);return this.cache.set(n,u),u}this.logger.log("terrain",t,i,"(fetching)");const l=(await this.http.game.roomTerrain(t,i??void 0)).terrain[0];if(!l)throw new Error(`No terrain data for room ${t} shard ${i}`);const a=ur.fromEncodedString(l.terrain);return this.cache.set(n,a),await this.cache.setPersistent(n,a.raw),this.emit("room:terrainavailable",{room:t,shard:i,terrain:a}),a}async terrainBulk(t,i){const n=new Map,s=[];for(const l of t){const a=this.cache.get(`terrain/${i}/${l}`);a?n.set(l,a):s.push(l)}if(s.length===0)return n;const o=[];if(await Promise.all(s.map(async l=>{const a=`terrain/${i}/${l}`,u=await this.cache.getPersistent(a);if(u){const h=new ur(u);this.cache.set(a,h),n.set(l,h)}else o.push(l)})),o.length===0)return n;this.logger.log("terrainBulk",`fetching ${o.length} rooms`,i);const c=await this.http.game.roomsTerrain(o,i??void 0);return await Promise.all(c.rooms.map(async l=>{const a=ur.fromEncodedString(l.terrain),u=`terrain/${i}/${l.room}`;this.cache.set(u,a),await this.cache.setPersistent(u,a.raw),this.emit("room:terrainavailable",{room:l.room,shard:i,terrain:a}),n.set(l.room,a)})),n}objects(t,i){const n=this.roomObjects.get(`${t}/${i}`);return n?{...n}:null}async fetchObjects(t,i){const n=`${t}/${i}`,s=await this.http.game.roomObjects(t,i??void 0),o={};for(const l of s.objects)l&&typeof l=="object"&&"_id"in l&&(o[l._id]=l);this.roomObjects.set(n,o);const c=this.roomUsers.get(n);this.emit("room:update",{room:t,shard:i,gameTime:void 0,objects:o,diff:o,visual:"",users:c})}activeRooms(){return Array.from(this.roomSubCount.entries()).map(([t,i])=>`${t}(${i})`).join(", ")||"(none)"}subscribe(t,i){const n=`${t}/${i}`,s=this.roomSubCount.get(n)??0;this.roomSubCount.set(n,s+1),this.logger.log("subscribe",t,i,`(refs: ${s+1})`,"active:",this.activeRooms());const o=i?`room:${i}/${t}`:`room:${t}`,c=i?`err@room:${i}/${t}`:`err@room:${t}`,l=this.socket.subscribe(o),a=this.socket.on(c,h=>{const d=typeof h=="string"?h:JSON.stringify(h);this.logger.log("room error",t,i,d),this.emit("room:error",{room:t,shard:i,message:d})}),u=this.socket.on(o,h=>{const d=h,f={...this.roomObjects.get(n)??{}};if(d.objects==null)d.objects===null&&this.logger.log("room update has null objects field",t,i,`gameTime: ${d.gameTime}`);else for(const[S,P]of Object.entries(d.objects))P===null?delete f[S]:f[S]?f[S]={...f[S],...P}:f[S]=P;const p={...d.objects??{}};if("flags"in d){const S=d.flags??"",P=this.lastFlagsString.get(n)??"";if(S!==P){this.lastFlagsString.set(n,S);const z=this.parseFlagsString(S,t),U=new Map;for(const O of z)U.set(O.name,O);for(const O in f){const y=f[O];(y==null?void 0:y.type)==="flag"&&!U.has(O)&&(delete f[O],p[O]=null,this.logger.log(`[flag:room] removed ${O} @ ${t}`))}for(const[O,y]of U){const x=f[O];(!x||x.x!==y.x||x.y!==y.y||x.color!==y.color||x.secondaryColor!==y.secondaryColor)&&(f[O]=y,p[O]=y,this.logger.log(`[flag:room] ${x?"changed":"added"} ${O} @ ${t} (${y.x},${y.y})`))}}}if(d.users){const S=this.roomUsers.get(n)??{};this.roomUsers.set(n,{...S,...d.users})}this.roomObjects.set(n,f);const g=this.roomUsers.get(n);this.emit("room:update",{room:t,shard:i,gameTime:d.gameTime,objects:f,diff:p,visual:d.visual??"",users:g})});return{dispose:()=>{l.dispose(),u.dispose(),a.dispose();const h=(this.roomSubCount.get(n)??1)-1;h<=0?(this.roomSubCount.delete(n),this.roomObjects.delete(n),this.roomUsers.delete(n),this.lastFlagsString.delete(n),this.logger.log("unsubscribe",t,i,"(last ref)","active:",this.activeRooms())):(this.roomSubCount.set(n,h),this.logger.log("unsubscribe",t,i,`(refs: ${h})`,"active:",this.activeRooms()))}}}}class va extends xr{constructor(t,i,n,s,o=100){super(s);$(this,"http");$(this,"socket");$(this,"cache");$(this,"console",[]);$(this,"maxConsoleSize");$(this,"_cpu",null);$(this,"_userInfo",null);$(this,"_userId",null);$(this,"_worldStatus",null);$(this,"_mePromise",null);this.http=t,this.socket=i,this.cache=n,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(i=>{const n=i;return this._userId=n._id,this._userInfo=n,this.cache.set("user/me",n,6e4),this.emit("user:me",n),n}).finally(()=>{this._mePromise=null}),this._mePromise)}async refreshMe(){return this.logger.log("refresh me"),this.cache.delete("user/me"),this.me()}async worldStatus(){const t=this.cache.get("user/worldStatus");if(t)return this._worldStatus=t,t;this.logger.log("fetch world status");const i=await this.http.user.worldStatus();return this._worldStatus=i.status,this.cache.set("user/worldStatus",i.status,6e4),this.emit("user:worldStatus",{status:i.status}),i.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 i=null,n=null,s=!1;return(async()=>{try{const c=this._userId??(await this.me())._id;if(s)return;const l=`user:${c}/${t}`;i=this.socket.subscribe(l),n=this.socket.on(l,a=>{var u,h,d;if(t==="cpu")this._cpu=a,this.emit("user:cpu",this._cpu);else if(t==="console"){const f=a,p={log:((u=f.messages)==null?void 0:u.log)??[],results:((h=f.messages)==null?void 0:h.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,i==null||i.dispose(),n==null||n.dispose()}}}subscribeMemory(t,i){this.logger.log("subscribe memory",t);let n=null,s=null,o=!1;return(async()=>{try{const l=this._userId??(await this.me())._id;if(o)return;const a=i?`${i}/`:"",u=`user:${l}/memory/${a}${t}`;n=this.socket.subscribe(u),s=this.socket.on(u,h=>{if(typeof h=="string"&&h.startsWith("gz:")){(async()=>{try{const{decompressZlib:f}=await Zn(async()=>{const{decompressZlib:g}=await Promise.resolve().then(()=>na);return{decompressZlib:g}},void 0),p=await f(h);this.emit("user:memory",{path:t,shard:i??null,value:p})}catch(f){this.logger.log("memory decompress failed",f)}})();return}if(h==="[object Object]"){this.logger.log("memory object placeholder",t),this.emit("user:memory",{path:t,shard:i??null,value:{__screeps_object__:!0}});return}let d=h;if(h==="undefined")d=void 0;else if(typeof h=="string")try{d=JSON.parse(h)}catch{}this.logger.log("memory value received",t,d),this.emit("user:memory",{path:t,shard:i??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,n==null||n.dispose(),s==null||s.dispose()}}}subscribeUserStream(){this.logger.log("subscribe user stream");let t=null,i=null,n=!1;return(async()=>{try{const o=this._userId??(await this.me())._id;if(n)return;const c=`user:${o}`;t=this.socket.subscribe(c),i=this.socket.on(c,l=>{const a=l;if(a&&typeof a=="object"&&"flags"in a){const u=a.flags;if(u&&typeof u=="object")for(const[h,d]of Object.entries(u)){const f=d;if(f&&typeof f=="object"){const p=f.room??"unknown",g=f.x??"?",S=f.y??"?";this.logger.log(`[flag:user] ${h} @ ${p} (${g},${S})`)}}}this.emit("user:stream",a)})}catch(o){n||this.dispatchEvent(new ErrorEvent("error",{error:o instanceof Error?o:new Error(String(o))}))}})(),{dispose:()=>{this.logger.log("unsubscribe user stream"),n=!0,t==null||t.dispose(),i==null||i.dispose()}}}}class ba extends xr{constructor(t,i,n,s){super(s);$(this,"http");$(this,"cache");$(this,"socketSubs",[]);$(this,"_version",null);$(this,"_shards",null);this.http=t,this.cache=n,this.socketSubs.push(i.on("connected",()=>{this.emit("server:connected",{})})),this.socketSubs.push(i.on("disconnected",o=>{const c=o;this.emit("server:disconnected",{willReconnect:c.willReconnect})})),this.socketSubs.push(i.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,i;return this._version?(((i=(t=this._version.serverData)==null?void 0:t.shards)==null?void 0:i.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 i=await this.http.request("GET","/api/version");return this._version=i,this.cache.set("server/version",i,5*6e4),this.emit("server:version",i),i}async refreshVersion(){return this.cache.delete("server/version"),this.version()}async shards(){const t=this.cache.get("server/shards");if(t)return t;const i=await this.http.request("GET","/api/game/shards/info");return this._shards=i.shards,this.cache.set("server/shards",i.shards,5*6e4),this.emit("server:shards",i.shards),i.shards}async refreshShards(){return this.cache.delete("server/shards"),this.shards()}async worldInfo(t){const n=`server/world/${t??"default"}`,s=this.cache.get(n);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 u=-l,h=-1,d=-a,f=-1;try{const S=(await this.http.request("POST","/api/game/map-stats",{rooms:["W0N0","E0N0","W0S0","E0S0"],statName:"owner0",...o})).stats??{},P=["W0N0","E0N0","W0S0","E0S0"].filter(z=>z in S);this.logger.log(`worldInfo corner probe — found: [${P.length?P.join(", "):"none"}]`),("E0N0"in S||"E0S0"in S)&&(u=-Math.ceil(l/2),h=Math.floor(l/2)-1),("W0S0"in S||"E0S0"in S)&&(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: [${u}, ${h}] y: [${d}, ${f}]`);const p={shard:t??null,width:l,height:a,minX:u,maxX:h,minY:d,maxY:f};return this.cache.set(n,p,10*6e4),p}invalidateWorldInfo(t){this.cache.delete(`server/world/${t??"default"}`)}}class wa{constructor(e){$(this,"memory",new Map);$(this,"adapter");$(this,"maxEntries");$(this,"namespace");$(this,"accessSeq",0);this.adapter=e.adapter,this.maxEntries=e.maxEntries,this.namespace=e.namespace}key(e,t){return`${t??"_"}/${e}`}adapterKey(e){return`map2/${e}`}tick(){return++this.accessSeq}serialize(e){const t={data:e.data,lastSeen:e.lastSeen,lastAccess:e.lastAccess};return new TextEncoder().encode(JSON.stringify(t))}deserialize(e){try{return JSON.parse(new TextDecoder().decode(e))}catch{return null}}getMemory(e,t){const i=this.memory.get(this.key(e,t));return i?(i.lastAccess=this.tick(),i.data):null}async get(e,t){const i=this.getMemory(e,t);if(i)return i;if(!this.adapter)return null;const n=this.key(e,t),s=await this.adapter.get(this.adapterKey(n));if(!s)return null;const o=this.deserialize(s);return o?(this.memory.set(n,{data:o.data,lastSeen:o.lastSeen,lastAccess:this.tick()}),o.data):null}async put(e,t,i){const n=this.key(e,t),s={data:i,lastSeen:Date.now(),lastAccess:this.tick()};this.memory.set(n,s),await this.pruneIfNeeded(),this.adapter&&await this.adapter.set(this.adapterKey(n),this.serialize(s))}async pruneIfNeeded(){if(this.memory.size<=this.maxEntries)return;const t=[...this.memory.entries()].sort((i,n)=>i[1].lastAccess-n[1].lastAccess).slice(0,this.memory.size-this.maxEntries);for(const[i]of t)this.memory.delete(i),this.adapter&&await this.adapter.delete(this.adapterKey(i))}}function gs(r){const e=Object.keys(r).sort(),t={};for(const i of e){const n=r[i];t[i]=n?[...n].sort((s,o)=>s[0]-o[0]||s[1]-o[1]):null}return JSON.stringify(t)}class xa extends xr{constructor(t,i,n={},s){super(s);$(this,"socket");$(this,"storage");$(this,"maxSubscriptions");$(this,"active",new Map);$(this,"waitlist",[]);$(this,"keyStates",new Map);$(this,"warnedAboutWaitlist",!1);this.socket=t,this.storage=i,this.maxSubscriptions=n.maxSubscriptions??500,this.socket.on("connected",()=>this.onReconnect())}map2data(t,i){return this.storage.getMemory(t,i)}subscribeMap2(t,i){const n=`${t}/${i}`,s=this.active.get(n);if(s){s.refCount++,this.logger.log("subscribeMap2",t,i,`(active, refs: ${s.refCount})`);const l=this.getOrCreateKeyState(n,"active");return this.emitWarmStart(t,i),this.makeSubscription(t,i,n,l)}const o=this.waitlist.find(l=>l.key===n);if(o){o.refCount++,this.logger.log("subscribeMap2",t,i,`(pending, refs: ${o.refCount})`);const l=this.getOrCreateKeyState(n,"pending");return this.emitWarmStart(t,i),this.makeSubscription(t,i,n,l)}if(this.active.size<this.maxSubscriptions){this.activateKey(t,i,n,1),this.logger.log("subscribeMap2",t,i,"(new active)");const l=this.getOrCreateKeyState(n,"active");return this.emit("room:map2state",{room:t,shard:i,status:"active"}),this.emitWarmStart(t,i),this.makeSubscription(t,i,n,l)}this.waitlist.push({key:n,room:t,shard:i,refCount:1}),this.logger.log("subscribeMap2",t,i,"(new pending)");const c=this.getOrCreateKeyState(n,"pending");return this.emit("room:map2state",{room:t,shard:i,status:"pending"}),this.emitWarmStart(t,i),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,i,n,c)}activateKey(t,i,n,s){const o=i?`roomMap2:${i}/${t}`:`roomMap2:${t}`,c=this.socket.subscribe(o),l=this.storage.getMemory(t,i),a={room:t,shard:i,refCount:s,socketSub:c,listenerSub:void 0,lastHash:l?gs(l):null};a.listenerSub=this.socket.on(o,u=>{const h=u,d=gs(h);a.lastHash!==d&&(a.lastHash=d,this.storage.put(t,i,h),this.emit("room:map2update",{room:t,shard:i,data:h,source:"live"}))}),this.active.set(n,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 i=this.keyStates.get(t.key);i&&(i.status="active",i.statusHandlers.forEach(n=>n("active"))),this.emit("room:map2state",{room:t.room,shard:t.shard,status:"active"})}getOrCreateKeyState(t,i){let n=this.keyStates.get(t);return n||(n={status:i,statusHandlers:new Set},this.keyStates.set(t,n)),n}makeSubscription(t,i,n,s){let o=!1;return{status:()=>s.status,cachedData:()=>this.storage.getMemory(t,i),onStatusChange:c=>(s.statusHandlers.add(c),{dispose:()=>{s.statusHandlers.delete(c)}}),dispose:()=>{o||(o=!0,this.disposeSubscription(t,i,n))}}}disposeSubscription(t,i,n){const s=this.waitlist.findIndex(c=>c.key===n);if(s>=0){const c=this.waitlist[s];c.refCount--,this.logger.log("unsubscribeMap2",t,i,`(pending, refs: ${c.refCount})`),c.refCount<=0&&(this.waitlist.splice(s,1),this.keyStates.delete(n),this.logger.log("unsubscribeMap2",t,i,"(removed from waitlist)"));return}const o=this.active.get(n);o&&(o.refCount--,this.logger.log("unsubscribeMap2",t,i,`(active, refs: ${o.refCount})`),o.refCount<=0&&(o.socketSub.dispose(),o.listenerSub.dispose(),this.active.delete(n),this.keyStates.delete(n),this.logger.log("unsubscribeMap2",t,i,"(deactivated, promoting next)"),this.promoteNext()))}emitWarmStart(t,i){const n=`${t}/${i}`,s=this.storage.getMemory(t,i);s?queueMicrotask(()=>{this.isSubscribed(n)&&this.emit("room:map2update",{room:t,shard:i,data:s,source:"cache"})}):this.storage.get(t,i).then(o=>{o&&this.isSubscribed(n)&&this.emit("room:map2update",{room:t,shard:i,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(i=>i.key===t)}}class _a extends xr{constructor(t,i=100,n=500,s){super(s);$(this,"http");$(this,"debounceMs");$(this,"minIntervalMs");$(this,"pending",new Map);$(this,"timer",null);$(this,"lastFlushTime",0);this.http=t,this.debounceMs=i,this.minIntervalMs=n}request(t,i,n){if(t.length===0)return;const s=JSON.stringify([i,n??"shard0"]);let o=this.pending.get(s);o||(o={rooms:new Set,statName:i,shard:n??"shard0"},this.pending.set(s,o));for(const u of t)o.rooms.add(u);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[,i]of t){const n=[...i.rooms];try{const s=await this.http.request("POST","/api/game/map-stats",{rooms:n,statName:i.statName,shard:i.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:i.shard==="shard0"?null:i.shard,stat:a})}for(const c of n)s.stats[c]||this.emit("mapStats:room",{room:c,shard:i.shard==="shard0"?null:i.shard,stat:{}})}catch(s){this.logger.log("mapStats fetch failed:",s)}}}buildData(t,i){var c,l,a;let n,s;for(let u=0;u<3;u++){const h=`minerals${u}`,d=t[h];if(d){n=d.type,s=d.density;break}}const o=(c=t.own)==null?void 0:c.user;return{own:t.own,mineral:n,density:s,username:o?(l=i[o])==null?void 0:l.username:void 0,safeMode:t.safeMode,badge:o?(a=i[o])==null?void 0:a.badge:void 0,status:t.status}}}class $a extends xr{constructor(t=50,i){super(i);$(this,"_history",[]);$(this,"_index",-1);$(this,"maxHistory");this.maxHistory=t}navigateTo(t,i){this._history=this._history.slice(0,this._index+1),this._history.push({room:t,shard:i}),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,i;return{room:((t=this._history[this._index])==null?void 0:t.room)??null,shard:((i=this._history[this._index])==null?void 0:i.shard)??null,index:this._index,history:[...this._history]}}}class Sa{constructor(e){$(this,"http");$(this,"socket");$(this,"stores");$(this,"cache");$(this,"logger");$(this,"tokenRefreshIntervalMs");$(this,"tokenSyncSubs",[]);$(this,"tokenRefreshTimer",null);$(this,"lastHttpActivity",0);$(this,"refreshInFlight",!1);var n,s,o;let t;try{t=new URL(e.url).hostname}catch{throw new TypeError(`ScreepsClient: invalid url "${e.url}"`)}this.logger=ut.create(e.debug),this.logger.log(`[screeps:client] init ${e.url}`),this.cache=new ma(t,e.storage??null),this.http=new fa({url:e.url,auth:e.auth,logger:this.logger.child("http"),serverPassword:e.serverPassword,decorationsMock:e.decorationsMock}),this.socket=new ga({url:e.url,WebSocket:e.WebSocket,logger:this.logger.child("socket")});const i=new wa({adapter:e.storage??null,namespace:t,maxEntries:((n=e.map2)==null?void 0:n.maxCacheEntries)??1e4});this.stores={room:new ya(this.http,this.socket,this.cache,this.logger.child("room")),user:new va(this.http,this.socket,this.cache,this.logger.child("user")),server:new ba(this.http,this.socket,this.cache,this.logger.child("server")),map:new xa(this.socket,i,{maxSubscriptions:((s=e.map2)==null?void 0:s.maxSubscriptions)??500},this.logger.child("map")),mapStats:new _a(this.http,100,500,this.logger.child("mapStats")),navigation:new $a(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 Ca{constructor(e){$(this,"token");this.token=e.token}async authenticate(e){return this.token}}class ka{constructor(e){$(this,"email");$(this,"password");this.email=e.email,this.password=e.password}async authenticate(e){return(await e.auth.signin(this.email,this.password)).token}}class Ta{async authenticate(e){return"guest"}}const Ma=1,it="data";class Ea{constructor(e){$(this,"namespace");$(this,"db",null);$(this,"openPromise",null);this.namespace=e}get dbName(){return`screeps:${this.namespace}`}open(){return this.db?Promise.resolve(this.db):this.openPromise?this.openPromise:(this.openPromise=new Promise((e,t)=>{const i=indexedDB.open(this.dbName,Ma);i.onupgradeneeded=()=>{i.result.createObjectStore(it)},i.onsuccess=()=>{this.db=i.result,this.openPromise=null,e(i.result)},i.onerror=()=>t(i.error),i.onblocked=()=>t(new Error(`IndexedDB open blocked: ${this.dbName}`))}),this.openPromise)}async get(e){const t=await this.open();return new Promise((i,n)=>{const o=t.transaction(it,"readonly").objectStore(it).get(e);o.onsuccess=()=>i(o.result??null),o.onerror=()=>n(o.error)})}async set(e,t){const i=await this.open();return new Promise((n,s)=>{const c=i.transaction(it,"readwrite").objectStore(it).put(t,e);c.onsuccess=()=>n(),c.onerror=()=>s(c.error)})}async delete(e){const t=await this.open();return new Promise((i,n)=>{const o=t.transaction(it,"readwrite").objectStore(it).delete(e);o.onsuccess=()=>i(),o.onerror=()=>n(o.error)})}async clear(){const e=await this.open();return new Promise((t,i)=>{const s=e.transaction(it,"readwrite").objectStore(it).clear();s.onsuccess=()=>t(),s.onerror=()=>i(s.error)})}}class Kn{constructor(){$(this,"subs",[])}add(e){this.subs.push(e)}dispose(){for(const e of this.subs)e.dispose();this.subs.length=0}}const Ra=5*6e4;function uo(r,e){try{return`screeps:${r}:${new URL(e).hostname}`}catch{return`screeps:${r}:${e}`}}function ho(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 fo(r,e){if(!(typeof sessionStorage>"u"))try{sessionStorage.setItem(r,JSON.stringify({data:e,expires:Date.now()+Ra}))}catch{}}function Kr(r){return r.endsWith("/")?r:`${r}/`}async function Oa(r){const e=uo("version",r),t=ho(e);if(t)return t;const i=await fetch(`${Kr(r)}api/version`);if(!i.ok)throw new Error(`HTTP ${i.status}`);const n=await i.json();return fo(e,n),n}async function Pa(r){const e=uo("authmod",r),t=ho(e);if(t)return t;const i=await fetch(`${Kr(r)}api/authmod`);if(!i.ok)return null;const n=await i.json();return n.ok?(fo(e,n),n):null}async function La(r,e){const t=new URLSearchParams({username:e}),i=await fetch(`${Kr(r)}api/register/check-username?${t}`);if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}async function Aa(r,e){const t=new URLSearchParams({email:e}),i=await fetch(`${Kr(r)}api/register/check-email?${t}`);if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}async function Ia(r,e,t,i){const n=await fetch(`${Kr(r)}api/register/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,email:t,password:i})});if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json()}function Na(r,e){return r.serverData.features.find(t=>t.name===e)}function po(r){return Na(r,"screepsmod-auth")}const Da={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"}}}]},Bi={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,i=Math.PI/2+Math.PI/3,n=Math.PI/2-Math.PI/3;this.path1=`M 50 50 L ${50+100*Math.cos(t-e/2)} ${50+100*Math.sin(t-e/2)} L ${50+100*Math.cos(t+e/2)} ${50+100*Math.sin(t+e/2)} Z`,this.path2=`M 50 50 L ${50+100*Math.cos(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)} Z M 50 50 L ${50+100*Math.cos(n-e/2)} ${50+100*Math.sin(n-e/2)} L ${50+100*Math.cos(n+e/2)} ${50+100*Math.sin(n+e/2)}`},flip:"rotate180"},4:{calc(r=0){r+=100;const e=50-r*30/200,t=50+r*30/200;this.path1=`M 0 ${t} H 100 V 100 H 0 Z`,this.path2=r>0?`M 0 ${e} H 100 V ${t} H 0 Z`:""},flip:"rotate90"},5:{calc(r=0){r+=100;const e=50-r*10/200-10,t=50+r*10/200+10;this.path1=`M ${e} 0 H ${t} V 100 H ${e} Z`,this.path2=`M 0 ${e} H 100 V ${t} H 0 Z`},flip:"rotate45"},6:{calc(r=0){const e=5+(r+100)*8/200,t=50,i=20,n=80;this.path1=`M ${t-e} 0 H ${t+e} V 100 H ${t-e}`,this.path2=`M ${i-e} 0 H ${i+e} V 100 H ${i-e} Z M ${n-e} 0 H ${n+e} V 100 H ${n-e} Z`},flip:"rotate90"},7:{calc(r=0){const e=20+r*10/100;this.path1="M 0 50 Q 25 30 50 50 T 100 50 V 100 H 0 Z",this.path2=`M 0 ${50-e} Q 25 ${30-e} 50 ${50-e} T 100 ${50-e} V ${50+e} Q 75 ${70+e} 50 ${50+e} T 0 ${50+e} Z`},flip:"rotate90"},8:{calc(r=0){const e=r*20/100;this.path1="M 0 50 H 100 V 100 H 0 Z",this.path2=`M 0 50 Q 50 ${e} 100 50 Q 50 ${100-e} 0 50 Z`},flip:"rotate90"},9:{calc(r=0){let e=0,t=50;const i=70;r>0&&(e+=r/100*20),r<0&&(t+=r/100*30),this.path1=`M 50 ${e} L 100 ${e+i} V 101 H 0 V ${e+i} Z`,this.path2=`M 50 ${e+t} L 100 ${e+t+i} V 101 H 0 V ${e+t+i} 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 i=50-50*Math.cos(Math.PI/4),n=50-50*Math.sin(Math.PI/4);r>0&&(e+=r*25/100,t+=r*25/100),r<0&&(t-=r*50/100),this.path1=`M ${i} ${n} Q ${e} 50 ${i} ${100-n} H 0 V ${n} Z M ${100-i} ${n} Q ${100-e} 50 ${100-i} ${100-n} H 100 V ${n} Z`,this.path2=`M ${i} ${n} Q 50 ${t} ${100-i} ${n} V 0 H ${i} Z M ${i} ${100-n} Q 50 ${100-t} ${100-i} ${100-n} V 100 H ${i} 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,i=45,n=10;this.path1=`M ${50-t-e} ${100+n} A ${t+e} ${t+e} 0 0 1 ${50+t+e} ${100+n} H ${50+t-e} A ${t-e} ${t-e} 0 1 0 ${50-t+e} ${100+n}`,this.path2=`M ${50-i-e} ${100+n} A ${i+e} ${i+e} 0 0 1 ${50+i+e} ${100+n} H ${50+i-e} A ${i-e} ${i-e} 0 1 0 ${50-i+e} ${100+n}`},flip:"rotate180"},16:{calc(r=0){let e=30*Math.PI/180,t=25;r>0&&(e+=30*Math.PI/180*r/100),r<0&&(t+=r*25/100),this.path1="";for(let i=0;i<3;i++){const n=i*Math.PI*2/3+e/2-Math.PI/2,s=i*Math.PI*2/3-e/2-Math.PI/2;this.path1+=`M ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+100*Math.cos(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(n)} ${50+t*Math.sin(n)} Z`}this.path2="";for(let i=0;i<3;i++){const n=i*Math.PI*2/3+e/2+Math.PI/2,s=i*Math.PI*2/3-e/2+Math.PI/2;this.path2+=`M ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+100*Math.cos(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(n)} ${50+t*Math.sin(n)} Z`}}},17:{calc(r=0){let e=35,t=45;r>0&&(e+=r*20/100),r<0&&(t-=r*30/100),this.path1=`M 50 45 L ${50-e} ${t+45} H ${50+e} Z`,this.path2=`M 50 0 L ${50-e} ${t} H ${50+e} Z`}},18:{calc(r=0){let e=90*Math.PI/180,t=10;r>0&&(e-=60/180*Math.PI*r/100),r<0&&(t-=r*15/100),this.path1="",this.path2="";for(let i=0;i<3;i++){const n=Math.PI*2/3*i+e/2-Math.PI/2,s=Math.PI*2/3*i-e/2-Math.PI/2,o=`M ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+100*Math.cos(s)} ${50+100*Math.sin(s)} L ${50+t*Math.cos((n+s)/2)} ${50+t*Math.sin((n+s)/2)} Z`;i?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 i=-4;i<4;i++){const n=(t+i)%2;this.path2+=`M ${50-e-e*2*t} ${50-e-e*2*(i+n)} h ${-e*2} v ${e*2} h ${e*2} Z`}},flip:"rotate45"},23:{calc(r=0){let e=17,t=25;r>0&&(e+=r*35/100),r<0&&(t-=r*23/100),this.path1="";for(let i=-4;i<=4;i++)this.path1+=`M ${50-e*i*2} ${50-t} l ${-e} ${-t} l ${-e} ${t} l ${e} ${t} Z`;this.path2="";for(let i=-4;i<=4;i++)this.path2+=`M ${50-e*i*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 Fi(r){const e=Math.round(r).toString(16);return e.length<2?"0"+e:e}function mt(r,e,t){const i=(1-Math.abs(2*t-1))*e,n=r/60,s=i*(1-Math.abs(n%2-1));let o=0,c=0,l=0;!Number.isNaN(r)&&r!==null&&r!==void 0&&(n>=0&&n<1?(o=i,c=s,l=0):n>=1&&n<2?(o=s,c=i,l=0):n>=2&&n<3?(o=0,c=i,l=s):n>=3&&n<4?(o=0,c=s,l=i):n>=4&&n<5?(o=s,c=0,l=i):n>=5&&n<6&&(o=i,c=0,l=s));const a=t-i/2,u=(o+a)*255,h=(c+a)*255,d=(l+a)*255;return"#"+Fi(u)+Fi(h)+Fi(d)}function za(){const r=[];let e=0;r.push({index:e++,rgb:mt(0,0,.8)});for(let t=0;t<19;t++)r.push({index:e++,rgb:mt(t*360/19,.6,.8)});r.push({index:e++,rgb:mt(0,0,.5)});for(let t=0;t<19;t++)r.push({index:e++,rgb:mt(t*360/19,.7,.5)});r.push({index:e++,rgb:mt(0,0,.3)});for(let t=0;t<19;t++)r.push({index:e++,rgb:mt(t*360/19,.4,.3)});r.push({index:e++,rgb:mt(0,0,.1)});for(let t=0;t<19;t++)r.push({index:e++,rgb:mt(t*360/19,.5,.1)});return r}const Ir=za();function Hi(r){if(typeof r=="string")return r;if(typeof r=="number"){const e=Ir[r];return e?e.rgb:"#000000"}return"#000000"}function Di(r){const e=Hi(r.color1),t=Hi(r.color2),i=Hi(r.color3),n=r.param??0;if(typeof r.type=="number"){const u=Bi[r.type];u&&u.calc(n)}let s=0;if(r.flip&&typeof r.type=="number"){const u=Bi[r.type];(u==null?void 0:u.flip)==="rotate180"&&(s=180),(u==null?void 0:u.flip)==="rotate90"&&(s=90),(u==null?void 0:u.flip)==="rotate45"&&(s=45)}let o,c;if(typeof r.type=="number"){const u=Bi[r.type];o=(u==null?void 0:u.path1)??"",c=(u==null?void 0:u.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="${i}" 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[Ga,ms]=B([]);let Ba=0;function Ce(r,e="success",t=4e3){const i=Ba++;ms(n=>[...n,{id:i,message:r,type:e,duration:t}]),setTimeout(()=>{ms(n=>n.filter(s=>s.id!==i))},t)}const Fa=!1;function zi(){return!0}function Ha(){return Fa}function Jn(){return window.location.origin}function Wa(){return"0.6.0"}function Ua(){return typeof window>"u"?null:window.__SCREEPS_CLIENT_EMBEDDED__??null}function Gi(){const r="/client/";return r.startsWith(".")?"":r.replace(/\/$/,"")}function Tt(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"},He={url:"screeps:url",token:"screeps:token",serverPassword:"screeps:serverPassword"};function Wi(r){return localStorage.getItem(r)}function ys(r,e){localStorage.setItem(r,e)}function Ya(r){localStorage.removeItem(r)}function Qr(r,e){const t=localStorage.getItem(r);if(t===null)return e;const i=Number(t);return Number.isFinite(i)&&i!==0?i:e}function Ui(r,e){localStorage.setItem(r,String(e))}function go(r,e){const t=localStorage.getItem(r);if(t===null)return e;try{return JSON.parse(t)}catch{return e}}function Qn(r,e){localStorage.setItem(r,JSON.stringify(e))}function ui(r){return sessionStorage.getItem(r)}function ei(r,e){sessionStorage.setItem(r,e)}function Nr(r){sessionStorage.removeItem(r)}async function Xa(){if(localStorage.clear(),indexedDB.databases){const r=await indexedDB.databases();await Promise.all(r.map(e=>e.name?new Promise(t=>{const i=indexedDB.deleteDatabase(e.name);i.onsuccess=()=>t(),i.onerror=()=>t(),i.onblocked=()=>t()}):Promise.resolve()))}if("caches"in window){const r=await caches.keys();await Promise.all(r.map(e=>caches.delete(e)))}}const{log:Qe}=Tt("client"),[ge,hi]=B(null),[Ft,sr]=B("idle"),[vs,fi]=B(null),[We,yn]=B(null),[es,vn]=B(null),[Fe,pi]=B(null),[xi,mo]=B(null),[Le,yo]=B(!1),[Yi,vo]=B(null),[ja,bo]=B({}),[Vt,wo]=B(null);let gi=-1,bn=-1;const or=[],Va=5;function qa(r){if(r===void 0)return;const e=Date.now();if(gi>=0&&r>gi){const t=e-bn;if(t>0){or.push(t),or.length>Va&&or.shift();const i=or.reduce((n,s)=>n+s,0)/or.length;mo(Math.round(i))}}gi=r,bn=e}function Za(){gi=-1,bn=-1,or.length=0,mo(null)}const xo=()=>{var e,t;const r=es();return r?(((t=(e=r.serverData)==null?void 0:e.shards)==null?void 0:t.length)??0)===0:null};async function zt(r){zi()&&(r={...r,url:Jn()}),Qe(`connecting to ${r.url} (auth: ${r.auth})`),sr("connecting"),fi(null);try{let e;if(r.auth==="guest")e=new Ta,yo(!0);else if(r.auth==="password"){if(!r.email||!r.password)throw new Error("Email and password are required");e=new ka({email:r.email,password:r.password})}else{if(!r.token)throw new Error("Token is required");e=new Ca({token:r.token})}const t=new Sa({url:r.url,auth:e,storage:r.storage??new Ea("screeps-client"),debug:!1,serverPassword:r.serverPassword,decorationsMock:Da});t.http.on("http:tokenRefresh",({token:i})=>{Qe("token refreshed"),ei(He.token,i)}),t.http.on("http:error",({method:i,path:n,error:s})=>{Qe("http error:",i,n,s.message),Ce(`Request failed: ${i} ${n} — ${s.message}`,"error",6e3)}),t.stores.server.on("server:disconnected",i=>{Qe(`server disconnected (willReconnect: ${i.willReconnect})`),i.willReconnect||(sr("idle"),hi(null),yn(null),vn(null))}),t.stores.server.on("server:error",i=>{Qe("server error:",i.error.message),fi(i.error.message),sr("error")}),t.stores.user.on("user:me",i=>{Qe(`user: ${i.username} (id: ${i._id})`),yn(i)}),t.stores.server.on("server:version",i=>{Qe(`server version: ${i.package??"unknown"}`),vn(i)}),t.stores.user.on("user:stream",i=>{if(i&&typeof i=="object"&&"flags"in i){const n=i.flags;n&&typeof n=="object"&&bo(n)}}),t.stores.user.on("user:worldStatus",({status:i})=>{Qe(`world status: ${i}`),wo(i)}),await t.connect(),t.stores.user.subscribeUserStream(),hi(t),sr("connected"),Qe(`connected to ${r.url}`),t.stores.server.worldInfo().then(i=>{vo(i),Qe(`world: ${i.width}x${i.height} x[${i.minX},${i.maxX}] y[${i.minY},${i.maxY}]`)}).catch(()=>{}),ei(He.url,r.url),t.http.token&&ei(He.token,t.http.token),r.serverPassword?ei(He.serverPassword,r.serverPassword):Nr(He.serverPassword)}catch(e){const t=e instanceof Error?e.message:String(e);throw fi(t),sr("error"),hi(null),e}}async function Ka(){const r=zi()?Jn():ui(He.url),e=ui(He.token);if(!r||!e)return;const t=ui(He.serverPassword)??void 0;try{e==="guest"?await zt({url:r,auth:"guest",storage:null,serverPassword:t}):await zt({url:r,auth:"token",token:e,serverPassword:t})}catch{Nr(He.token)}}function Ja(){const r=ge();r&&r.disconnect(),hi(null),sr("idle"),fi(null),yn(null),vn(null),pi(null),yo(!1),vo(null),bo({}),wo(null),Za(),Nr(He.token),Nr(He.url),Nr(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 Qa={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"},er=Qa,ec=R("<svg>"),bs=r=>r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),tc=r=>r.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,i)=>i?i.toUpperCase():t.toLowerCase()),rc=r=>{const e=tc(r);return e.charAt(0).toUpperCase()+e.slice(1)},ic=(...r)=>r.filter((e,t,i)=>!!e&&e.trim()!==""&&i.indexOf(e)===t).join(" ").trim(),nc=r=>{const[e,t]=to(r,["color","size","strokeWidth","children","class","name","iconNode","absoluteStrokeWidth"]);return(()=>{var i=ec();return so(i,ve(er,{get width(){return e.size??er.width},get height(){return e.size??er.height},get stroke(){return e.color??er.stroke},get"stroke-width"(){return te(()=>!!e.absoluteStrokeWidth)()?Number(e.strokeWidth??er["stroke-width"])*24/Number(e.size):Number(e.strokeWidth??er["stroke-width"])},get class(){return ic("lucide","lucide-icon",...e.name!=null?[`lucide-${bs(rc(e.name))}`,`lucide-${bs(e.name)}`]:[],e.class!=null?e.class:"")}},t),!0,!0),m(i,b($e,{get each(){return e.iconNode},children:([n,s])=>b(oo,ve({component:n},s))})),i})()},we=nc,sc=[["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"}]],oc=r=>b(we,ve(r,{iconNode:sc,name:"bell-off"})),lc=oc,ac=[["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"}]],cc=r=>b(we,ve(r,{iconNode:ac,name:"bell"})),dc=cc,uc=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],hc=r=>b(we,ve(r,{iconNode:uc,name:"check"})),_o=hc,fc=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],pc=r=>b(we,ve(r,{iconNode:fc,name:"chevron-down"})),gc=pc,mc=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],yc=r=>b(we,ve(r,{iconNode:mc,name:"chevron-right"})),$o=yc,vc=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],bc=r=>b(we,ve(r,{iconNode:vc,name:"chevron-left"})),wc=bc,xc=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]],_c=r=>b(we,ve(r,{iconNode:xc,name:"clock"})),$c=_c,Sc=[["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"}]],Cc=r=>b(we,ve(r,{iconNode:Sc,name:"code-xml"})),kc=Cc,Tc=[["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"}]],Mc=r=>b(we,ve(r,{iconNode:Tc,name:"eye"})),So=Mc,Ec=[["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"}]],Rc=r=>b(we,ve(r,{iconNode:Ec,name:"flag"})),Co=Rc,Oc=[["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"}]],Pc=r=>b(we,ve(r,{iconNode:Oc,name:"hammer"})),Lc=Pc,Ac=[["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"}]],Ic=r=>b(we,ve(r,{iconNode:Ac,name:"layout-grid"})),Nc=Ic,Dc=[["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"}]],zc=r=>b(we,ve(r,{iconNode:Dc,name:"loader"})),Gc=zc,Bc=[["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"}]],Fc=r=>b(we,ve(r,{iconNode:Bc,name:"log-in"})),Hc=Fc,Wc=[["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"}]],Uc=r=>b(we,ve(r,{iconNode:Wc,name:"log-out"})),Yc=Uc,Xc=[["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"}]],jc=r=>b(we,ve(r,{iconNode:Xc,name:"map"})),Vc=jc,qc=[["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"}]],Zc=r=>b(we,ve(r,{iconNode:qc,name:"move"})),Kc=Zc,Jc=[["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"}]],Qc=r=>b(we,ve(r,{iconNode:Jc,name:"pause"})),ed=Qc,td=[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]],rd=r=>b(we,ve(r,{iconNode:td,name:"play"})),id=rd,nd=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],sd=r=>b(we,ve(r,{iconNode:nd,name:"plus"})),od=sd,ld=[["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"}]],ad=r=>b(we,ve(r,{iconNode:ld,name:"refresh-cw"})),cd=ad,dd=[["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"}]],ud=r=>b(we,ve(r,{iconNode:dd,name:"settings"})),hd=ud,fd=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],pd=r=>b(we,ve(r,{iconNode:fd,name:"terminal"})),gd=pd,md=[["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"}]],yd=r=>b(we,ve(r,{iconNode:md,name:"trash-2"})),mi=yd,vd=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],bd=r=>b(we,ve(r,{iconNode:vd,name:"x"})),qt=bd,wd=R("<span style=font-size:11px;display:inline-flex;align-items:center;gap:3px>"),xd=R('<div style="color:#3fb950;font-size:14px;text-align:center;padding:8px 0">Account created! Logging you in…'),_d=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>"),$d=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>"),Sd=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>"),Cd=R("<span style=font-size:11px;color:#f85149>Passwords don't match"),kd=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>"),Td=R("<button type=submit style=padding:10px;border-radius:6px;border:none;background:#238636;color:#fff;font-weight:600>"),Md=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'),Ed=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>"),Rd=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">'),Od=R("<button type=button style=background:none;border:none;color:#58a6ff;font-size:12px;cursor:pointer;padding:0>Create account"),Pd=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'),Ld=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>"),Ad=R("<div style=color:#8b949e;font-size:12px;margin-top:-8px>"),Id=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>"),Nd=R("<button type=button style=padding:10px;border-radius:6px;border:none;background:#1b2838;color:#c7d5e0;font-weight:600>Login with Steam"),Dd=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)'),zd=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>'),Gd=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>'),Bd=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">'),Fd=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>"),Hd=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>"),Wd=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>"),Ud=R('<span style="font-size:11px;padding:2px 8px;border-radius:12px;background:#21262d;border:1px solid #30363d;color:#8b949e;font-family:monospace">');const at={padding:"8px 12px","border-radius":"6px",border:"1px solid #30363d",background:"#0d1117",color:"#c9d1d9"};function Yd(r){const[e,t]=B(null),[i,n]=B(null),[s,o]=B(null);return he(()=>{const c=r();t(null),n(null),o(null);let l=!1;const a=setTimeout(async()=>{try{const u=await Oa(c);if(l)return;if(t(u),o(null),po(u)){const h=await Pa(c);l||n(h)}}catch{l||(o("Could not reach server"),t(null))}},400);Ge(()=>{l=!0,clearTimeout(a)})}),{serverVersion:e,authModInfo:i,serverError:s}}function ws(r,e,t){const[i,n]=B("idle");return he(()=>{const s=e();if(!s){n("idle");return}n("checking");let o=!1;const c=setTimeout(async()=>{try{const l=await t(r(),s);o||n(l.error?"taken":"available")}catch{o||n("error")}},500);Ge(()=>{o=!0,clearTimeout(c)})}),i}function xs(r){const e={idle:null,checking:{children:"Checking…",color:"#8b949e"},available:{children:[b(_o,{size:12})," Available"],color:"#3fb950"},taken:{children:[b(qt,{size:12})," Already taken"],color:"#f85149"},error:{children:"Could not verify",color:"#d29922"}},t=()=>e[r.state];return b(q,{get when(){return t()},get children(){var i=wd();return m(i,()=>t().children),N(n=>X(i,"color",t().color)),i}})}function Xd(r){const[e,t]=B(""),[i,n]=B(""),[s,o]=B(""),[c,l]=B(""),[a,u]=B(!1),[h,d]=B(null),[f,p]=B(!1),g=ws(()=>r.url,e,La),S=ws(()=>r.url,i,Aa),P=()=>c()!==""&&s()!==c(),z=()=>!a()&&e()!==""&&i()!==""&&s().length>=4&&s()===c()&&g()!=="taken"&&g()!=="checking"&&S()!=="taken"&&S()!=="checking",U=async O=>{if(O.preventDefault(),!!z()){u(!0),d(null);try{const y=await Ia(r.url,e(),i(),s());if(y.error){d(y.error);return}p(!0),setTimeout(()=>r.onSuccess(i(),s()),1500)}catch(y){d(y instanceof Error?y.message:"Registration failed")}finally{u(!1)}}};return(()=>{var O=Ed();return O.firstChild,O.addEventListener("submit",U),m(O,b(q,{get when(){return f()},get children(){return xd()}}),null),m(O,b(q,{get when(){return!f()},get children(){return[(()=>{var y=_d(),x=y.firstChild;x.firstChild;var L=x.nextSibling;return m(x,b(xs,{get state(){return g()}}),null),L.$$input=v=>t(v.currentTarget.value),N(v=>{var C=at,T=a();return v.e=Q(L,C,v.e),T!==v.t&&(L.disabled=v.t=T),v},{e:void 0,t:void 0}),N(()=>L.value=e()),y})(),(()=>{var y=$d(),x=y.firstChild;x.firstChild;var L=x.nextSibling;return m(x,b(xs,{get state(){return S()}}),null),L.$$input=v=>n(v.currentTarget.value),N(v=>{var C=at,T=a();return v.e=Q(L,C,v.e),T!==v.t&&(L.disabled=v.t=T),v},{e:void 0,t:void 0}),N(()=>L.value=i()),y})(),(()=>{var y=Sd(),x=y.firstChild,L=x.nextSibling;return L.$$input=v=>o(v.currentTarget.value),N(v=>{var C=at,T=a();return v.e=Q(L,C,v.e),T!==v.t&&(L.disabled=v.t=T),v},{e:void 0,t:void 0}),N(()=>L.value=s()),y})(),(()=>{var y=kd(),x=y.firstChild;x.firstChild;var L=x.nextSibling;return m(x,b(q,{get when(){return P()},get children(){return Cd()}}),null),L.$$input=v=>l(v.currentTarget.value),N(v=>{var C={...at,border:P()?"1px solid #f85149":"1px solid #30363d"},T=a();return v.e=Q(L,C,v.e),T!==v.t&&(L.disabled=v.t=T),v},{e:void 0,t:void 0}),N(()=>L.value=c()),y})(),te(()=>te(()=>!!h())()&&(()=>{var y=ko();return m(y,h),y})()),(()=>{var y=Td();return m(y,()=>a()?"Creating account…":"Create Account"),N(x=>{var L=!z(),v=z()?"pointer":"not-allowed",C=z()?1:.5;return L!==x.e&&(y.disabled=x.e=L),v!==x.t&&X(y,"cursor",x.t=v),C!==x.a&&X(y,"opacity",x.a=C),x},{e:void 0,t:void 0,a:void 0}),y})(),(()=>{var y=Md();return y.$$click=()=>r.onCancel(),y})()]}}),null),O})()}function jd(){const r=zi(),e=Ha(),[t,i]=B("login"),[n,s]=B("password"),[o,c]=B(r?Jn():window.location.origin),[l,a]=B(""),[u,h]=B(""),[d,f]=B(""),[p,g]=B(""),{serverVersion:S,authModInfo:P,serverError:z}=Yd(o),U=()=>{var M,k;return((k=(M=S())==null?void 0:M.serverData)==null?void 0:k.welcomeText)??null},O=()=>{var M,k;return(((k=(M=S())==null?void 0:M.serverData)==null?void 0:k.features)??[]).filter(E=>E.name!=="auth"&&E.version!=null)},y=()=>{var k,E;const M=S();return M?((E=(k=po(M))==null?void 0:k.authTypes)==null?void 0:E.includes("steam"))??!0:!0},x=()=>{var M,k,E;return((M=P())==null?void 0:M.allowRegistration)===!0||(((E=(k=S())==null?void 0:k.serverData)==null?void 0:E.features)??[]).some(D=>D.name==="official-like")},L=()=>{const M=o().replace(/\/$/,""),k=window.open(`${M}/api/auth/steam`,"screeps-steam-auth","width=800,height=600,left=200,top=100"),E=H=>{try{const A=JSON.parse(H.data);A.token&&(I(),zt({url:M,auth:"token",token:A.token,serverPassword:p()||void 0,storage:null}))}catch{}},D=setInterval(()=>{k!=null&&k.closed&&I()},500),I=()=>{clearInterval(D),window.removeEventListener("message",E)};window.addEventListener("message",E),Ge(I)},v=async M=>{M.preventDefault(),await zt({url:o(),auth:n(),email:l()||void 0,password:u()||void 0,token:d()||void 0,serverPassword:p()||void 0,storage:null})},C=async M=>{M.preventDefault(),await zt({url:o(),auth:"guest",serverPassword:p()||void 0,storage:null})},T=async(M,k)=>{try{await zt({url:o(),auth:"password",email:M,password:k,serverPassword:p()||void 0,storage:null})}catch{i("login"),s("password"),a(M),h(k)}},w=()=>Ft()==="connecting";return(()=>{var M=Bd(),k=M.firstChild;return m(M,b(q,{get when(){return U()},get children(){var E=Rd();return N(()=>E.innerHTML=U()),E}}),k),m(k,b(q,{get when(){return t()==="register"},get children(){return b(Xd,{get url(){return o()},get serverPassword(){return p()},onSuccess:T,onCancel:()=>i("login")})}}),null),m(k,b(q,{get when(){return t()==="login"},get children(){var E=zd(),D=E.firstChild;D.firstChild;var I=D.nextSibling,H=I.firstChild,A=H.firstChild;A.nextSibling;var G=H.nextSibling,V=I.nextSibling;return E.addEventListener("submit",v),m(D,b(q,{get when(){return x()},get children(){var F=Od();return F.$$click=()=>i("register"),F}}),null),m(E,b(q,{when:!r,get children(){var F=Pd(),Z=F.firstChild,j=Z.nextSibling;return Z.$$click=()=>s("password"),j.$$click=()=>s("token"),N(W=>{var J=n()==="password"?"#238636":"transparent",ue=n()==="token"?"#238636":"transparent";return J!==W.e&&X(Z,"background",W.e=J),ue!==W.t&&X(j,"background",W.t=ue),W},{e:void 0,t:void 0}),F}}),I),m(E,b(q,{when:!r,get children(){return[(()=>{var F=Ld(),Z=F.firstChild,j=Z.nextSibling;return j.$$input=W=>c(W.currentTarget.value),N(W=>Q(j,at,W)),N(()=>j.value=o()),F})(),b(q,{get when(){return z()},get children(){var F=Ad();return m(F,z),F}})]}}),I),m(E,(()=>{var F=te(()=>n()==="password");return()=>F()?[(()=>{var Z=Fd(),j=Z.firstChild,W=j.nextSibling;return W.$$input=J=>a(J.currentTarget.value),N(J=>Q(W,at,J)),N(()=>W.value=l()),Z})(),(()=>{var Z=Hd(),j=Z.firstChild,W=j.nextSibling;return W.$$input=J=>h(J.currentTarget.value),N(J=>Q(W,at,J)),N(()=>W.value=u()),Z})()]:(()=>{var Z=Wd(),j=Z.firstChild,W=j.nextSibling;return W.$$input=J=>f(J.currentTarget.value),N(J=>Q(W,at,J)),N(()=>W.value=d()),Z})()})(),I),G.$$input=F=>g(F.currentTarget.value),m(E,(()=>{var F=te(()=>!!vs());return()=>F()&&(()=>{var Z=ko();return m(Z,vs),Z})()})(),V),m(V,()=>w()?"Connecting…":"Connect"),m(E,b(q,{get when(){return y()},get children(){return[(()=>{var F=Id(),Z=F.firstChild,j=Z.nextSibling;return j.nextSibling,F})(),(()=>{var F=Nd();return F.$$click=L,N(Z=>{var j=w(),W=w()?"not-allowed":"pointer",J=w()?.6:1;return j!==Z.e&&(F.disabled=Z.e=j),W!==Z.t&&X(F,"cursor",Z.t=W),J!==Z.a&&X(F,"opacity",Z.a=J),Z},{e:void 0,t:void 0,a:void 0}),F})()]}}),null),m(E,b(q,{when:!r||e,get children(){var F=Dd();return F.addEventListener("mouseleave",Z=>{Z.currentTarget.style.borderColor="#30363d"}),F.addEventListener("mouseenter",Z=>{w()||(Z.currentTarget.style.borderColor="#8b949e")}),F.$$click=C,N(Z=>{var j=w(),W=w()?"not-allowed":"pointer",J=w()?.6:1;return j!==Z.e&&(F.disabled=Z.e=j),W!==Z.t&&X(F,"cursor",Z.t=W),J!==Z.a&&X(F,"opacity",Z.a=J),Z},{e:void 0,t:void 0,a:void 0}),F}}),null),N(F=>{var Z=at,j=w(),W=w()?"not-allowed":"pointer",J=w()?.6:1;return F.e=Q(G,Z,F.e),j!==F.t&&(V.disabled=F.t=j),W!==F.a&&X(V,"cursor",F.a=W),J!==F.o&&X(V,"opacity",F.o=J),F},{e:void 0,t:void 0,a:void 0,o:void 0}),N(()=>G.value=p()),E}}),null),m(M,b(q,{get when(){return O().length>0},get children(){var E=Gd(),D=E.firstChild,I=D.nextSibling;return m(I,b($e,{get each(){return O()},children:H=>(()=>{var A=Ud();return m(A,()=>H.name,null),m(A,(()=>{var G=te(()=>!!H.version);return()=>G()?` ${H.version}`:""})(),null),A})()})),E}}),null),M})()}Re(["input","click"]);var Vd=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'),qd=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 Zd(){const r=()=>{switch(Ft()){case"connected":return"#238636";case"connecting":return"#d29922";case"error":return"#f85149";default:return"#8b949e"}};return(()=>{var e=qd(),t=e.firstChild,i=t.firstChild,n=i.nextSibling;return m(n,(()=>{var s=te(()=>Ft()==="connected");return()=>s()?"Online":Ft()})()),m(e,b(q,{get when(){return Le()},get children(){return Vd()}}),null),N(s=>X(i,"background-color",r())),e})()}class Kd{constructor(e){$(this,"container");$(this,"hoverGraphics");$(this,"pendingGraphics");$(this,"selectionContainer");$(this,"selectionGraphics",new Map);$(this,"selectionTypes",new Map);$(this,"selectionVisuals",new Map);$(this,"ticker",null);$(this,"tickerCallback",null);this.container=new Ne,this.container.label="hoverHighlight",this.container.eventMode="none",this.hoverGraphics=new re,this.hoverGraphics.eventMode="none",this.container.addChild(this.hoverGraphics),this.pendingGraphics=new re,this.pendingGraphics.eventMode="none",this.container.addChild(this.pendingGraphics),this.selectionContainer=new Ne,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 i=e*_,n=t*_;this.hoverGraphics.rect(i,n,_,_),this.hoverGraphics.stroke({width:1,color:16777215,alpha:.35}),this.hoverGraphics.rect(i,n,_,_),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:i,visual:n}of e){const s=new re;s.eventMode="none",this.selectionContainer.addChild(s),this.selectionGraphics.set(t,s),this.selectionTypes.set(t,i),this.selectionVisuals.set(t,n),i==="creep"?this.drawCreepRing(s,n.x,n.y):this.drawStructureBox(s,n.x,n.y)}}clearSelection(){this.selectionContainer.removeChildren();for(const e of this.selectionGraphics.values())e.destroy();this.selectionGraphics.clear(),this.selectionTypes.clear(),this.selectionVisuals.clear()}setPendingTile(e,t){if(this.pendingGraphics.clear(),e===null||t===null)return;const i=e*_,n=t*_,s=i+_/2,o=n+_/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(i+1,n+1,_-2,_-2),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.6})}clearPendingTile(){this.pendingGraphics.clear()}drawCreepRing(e,t,i){e.clear();const n=t+_/2,s=i+_/2,o=_*.48;e.circle(n,s,o),e.stroke({width:1.5,color:16777215,alpha:.9})}drawStructureBox(e,t,i){e.clear();const n=1;e.rect(t+n,i+n,_-n*2,_-n*2),e.stroke({width:1.5,color:16777215,alpha:.9}),e.rect(t+n,i+n,_-n*2,_-n*2),e.fill({color:16777215,alpha:.04})}trackCreepRings(){for(const[e,t]of this.selectionGraphics){if(this.selectionTypes.get(e)!=="creep")continue;const i=this.selectionVisuals.get(e);!i||i.destroyed||this.drawCreepRing(t,i.x,i.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,Pe=50*_,ke=48,kr=128,_t={terrain:0,objects:10,animations:20,darkOverlay:30,light:31,visuals:40,hover:50,nav:60},Jd=new Set(["road","constructedWall","rampart"]);class ts{constructor(e,t){$(this,"app");$(this,"world");$(this,"hoverLayer");$(this,"darkOverlay");$(this,"lightLayer");$(this,"lightTexture",null);$(this,"lightPool",[]);$(this,"activeLights",[]);$(this,"destroyed",!1);$(this,"canDrag",!1);$(this,"container");$(this,"resizeObserver",null);$(this,"bounceRaf",null);$(this,"wheelTimeout",null);$(this,"navOverlay");$(this,"lastMouseX",0);$(this,"lastMouseY",0);$(this,"onHoverTile",null);$(this,"onClickTile",null);$(this,"onRightClick",null);this.app=e,this.container=t,this.world=new Ne({sortableChildren:!0}),this.app.stage.addChild(this.world),this.darkOverlay=new re,this.darkOverlay.label="darkOverlay",this.darkOverlay.rect(0,0,Pe,Pe).fill({color:0,alpha:.4}),this.darkOverlay.zIndex=_t.darkOverlay,this.world.addChild(this.darkOverlay),this.lightLayer=new Ne,this.lightLayer.label="lightLayer",this.lightLayer.zIndex=_t.light,this.world.addChild(this.lightLayer),this.hoverLayer=new Kd(e.ticker),this.hoverLayer.container.zIndex=_t.hover,this.world.addChild(this.hoverLayer.container),this.navOverlay=new Ne,this.navOverlay.zIndex=_t.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 io;return await t.init({background:"#0d1117",antialias:!0,resolution:window.devicePixelRatio||1,autoDensity:!0}),e.appendChild(t.canvas),new ts(t,e)}getMinScale(){const t=this.container.clientWidth,i=this.container.clientHeight;return Math.min(t,i)/(Pe+64)}clampView(e=!1){const t=this.world.scale.x,i=Pe*t,n=this.container.clientWidth,s=this.container.clientHeight,o=e?kr:0;if(i<=n){const c=n/2-i/2;e?this.world.x=Math.min(c+kr,Math.max(c-kr,this.world.x)):this.world.x=c}else{const c=n-i-ke-o,l=ke+o;this.world.x=Math.min(l,Math.max(c,this.world.x))}if(i<=s){const c=s/2-i/2;e?this.world.y=Math.min(c+kr,Math.max(c-kr,this.world.y)):this.world.y=c}else{const c=s-i-ke-o,l=ke+o;this.world.y=Math.min(l,Math.max(c,this.world.y))}this.canDrag=!0}getTargetPosition(){const e=this.world.scale.x,t=Pe*e,i=this.container.clientWidth,n=this.container.clientHeight;let s=null,o=null;if(t<=i)s=i/2-t/2;else{const c=i-t-ke,l=ke;this.world.x<c?s=c:this.world.x>l&&(s=l)}if(t<=n)o=n/2-t/2;else{const c=n-t-ke,l=ke;this.world.y<c?o=c:this.world.y>l&&(o=l)}return s===null&&o===null?null:{x:s??this.world.x,y:o??this.world.y}}springBack(){const e=this.getTargetPosition(),t=this.getTargetScale();if(!e&&t===null)return;const i=this.world.x,n=this.world.y,s=this.world.scale.x,o=performance.now(),c=300,l=this.container.clientWidth/2,a=this.container.clientHeight/2,u=(l-i)/s,h=(a-n)/s,d=f=>{const p=f-o,g=Math.min(1,p/c),S=1-Math.pow(1-g,3);if(t!==null){const P=s+(t-s)*S;this.world.scale.set(P),this.world.x=l-u*P,this.world.y=a-h*P}e&&t===null&&(this.world.x=i+(e.x-i)*S,this.world.y=n+(e.y-n)*S),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 Cr(0,0),i=new Cr(0,0);const n=this.app.canvas,s=4;n.style.touchAction="none",n.style.userSelect="none";const o=new Map;let c=!1,l=0,a=0,u=0,h=0;n.addEventListener("pointerdown",f=>{if(this.cancelBounce(),this.cancelWheelTimeout(),o.set(f.pointerId,{x:f.clientX,y:f.clientY}),n.setPointerCapture(f.pointerId),o.size>=2){e=!1,c=!0;const p=[...o.values()],g=n.getBoundingClientRect(),S=(p[0].x+p[1].x)/2-g.left,P=(p[0].y+p[1].y)/2-g.top;u=Math.hypot(p[1].x-p[0].x,p[1].y-p[0].y),h=this.world.scale.x,l=(S-this.world.x)/h,a=(P-this.world.y)/h}else c=!1,e=this.canDrag,t=new Cr(f.clientX,f.clientY),i=new Cr(f.clientX,f.clientY)}),n.addEventListener("pointermove",f=>{var P;const p=n.getBoundingClientRect();if(this.lastMouseX=f.clientX-p.left,this.lastMouseY=f.clientY-p.top,o.has(f.pointerId)&&o.set(f.pointerId,{x:f.clientX,y:f.clientY}),c&&o.size===2){const z=[...o.values()],U=(z[0].x+z[1].x)/2-p.left,O=(z[0].y+z[1].y)/2-p.top,y=Math.hypot(z[1].x-z[0].x,z[1].y-z[0].y),x=this.getMinScale(),L=5,v=.6;let C=h*(y/u);C<x&&(C=x+(C-x)*v),C>L&&(C=L+(C-L)*v),this.cancelBounce(),this.world.scale.set(C),this.world.x=U-l*C,this.world.y=O-a*C,this.clampView(!0);return}if(!c){const z=this.screenToTile(this.lastMouseX,this.lastMouseY);this.hoverLayer.setHoveredTile((z==null?void 0:z.tx)??null,(z==null?void 0:z.ty)??null),(P=this.onHoverTile)==null||P.call(this,(z==null?void 0:z.tx)??null,(z==null?void 0:z.ty)??null)}if(!e||!this.canDrag)return;const g=f.clientX-t.x,S=f.clientY-t.y;this.world.x+=g,this.world.y+=S,t=new Cr(f.clientX,f.clientY),this.clampView(!0)});const d=f=>{var P;if(n.releasePointerCapture(f.pointerId),o.delete(f.pointerId),c){o.size<2&&(c=!1,e=!1,this.springBack());return}e=!1;const p=f.clientX-i.x,g=f.clientY-i.y;if(Math.sqrt(p*p+g*g)<s){const z=n.getBoundingClientRect(),U=f.clientX-z.left,O=f.clientY-z.top,y=this.screenToTile(U,O);y&&((P=this.onClickTile)==null||P.call(this,y.tx,y.ty,f.ctrlKey||f.metaKey))}this.springBack()};n.addEventListener("pointerup",d),n.addEventListener("pointercancel",d),n.addEventListener("contextmenu",f=>{var p;f.preventDefault(),f.button===2&&((p=this.onRightClick)==null||p.call(this))}),n.addEventListener("pointerleave",()=>{var f;this.hoverLayer.setHoveredTile(null,null),(f=this.onHoverTile)==null||f.call(this,null,null)}),n.addEventListener("wheel",f=>{f.preventDefault();const p=f.deltaY>0?.9:1.1,g=this.getMinScale(),S=5;let P=this.world.scale.x*p;const z=.6;P<g&&(P=g+(P-g)*z),P>S&&(P=S+(P-S)*z);const U=n.getBoundingClientRect(),O=f.clientX-U.left,y=f.clientY-U.top;if(this.cancelBounce(),P<g){const x=this.container.clientWidth/2,L=this.container.clientHeight/2,v=(x-this.world.x)/this.world.scale.x,C=(L-this.world.y)/this.world.scale.y;this.world.scale.set(P),this.world.x=x-v*P,this.world.y=L-C*P}else{const x=(O-this.world.x)/this.world.scale.x,L=(y-this.world.y)/this.world.scale.y;this.world.scale.set(P),this.world.x=O-x*P,this.world.y=y-L*P}this.clampView(),this.cancelWheelTimeout(),this.wheelTimeout=window.setTimeout(()=>{this.wheelTimeout=null,this.springBack()},80)},{passive:!1})}setTileHandlers(e,t,i){this.onHoverTile=e,this.onClickTile=t,this.onRightClick=i??null}screenToTile(e,t){const i=(e-this.world.x)/this.world.scale.x,n=(t-this.world.y)/this.world.scale.y,s=Math.floor(i/_),o=Math.floor(n/_);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,i=this.world.scale.x;this.world.x=e-Pe*i/2,this.world.y=t-Pe*i/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(i=>{const{width:n,height:s}=i[0].contentRect;this.app.renderer.resize(n,s),this.clampView()}),this.resizeObserver.observe(this.container)}setupNavigationZones(e){this.navOverlay.removeChildren();const t=(o,c,l,a,u,h)=>{if(!h)return;const d=new re;d.x=o,d.y=c,d.hitArea=new no(0,0,l,a),d.fill({color:16777215,alpha:.12}),d.poly(u),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(u),d.fill()}),d.on("pointerout",()=>{d.clear(),d.fill({color:16777215,alpha:.12}),d.poly(u),d.fill()}),d.on("pointerdown",h),this.navOverlay.addChild(d)},i=Pe/2,n=Pe/2,s=18;t(-ke,0,ke,Pe,[18,n,ke-6,n-s,ke-6,n+s],e.west),t(Pe,0,ke,Pe,[ke-18,n,6,n-s,6,n+s],e.east),t(0,-ke,Pe,ke,[i,18,i-s,ke-6,i+s,ke-6],e.north),t(0,Pe,Pe,ke,[i,ke-18,i-s,6,i+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,u=this.world.y+c.y*this.world.scale.y,h=l.width*this.world.scale.x,d=l.height*this.world.scale.y;this.lastMouseX>=a&&this.lastMouseX<=a+h&&this.lastMouseY>=u&&this.lastMouseY<=u+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&&t!==this.lightLayer&&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(){for(const e of this.activeLights)this.lightLayer.removeChild(e),this.lightPool.push(e);this.activeLights.length=0}updateLighting(e){this.clearLighting(),this.lightTexture||(this.lightTexture=this.createLightTexture());for(const t of Object.values(e)){if(typeof t.type=="string"&&Jd.has(t.type)||typeof t.x!="number"||typeof t.y!="number")continue;let i=this.lightPool.pop();i||(i=new ze(this.lightTexture),i.anchor.set(.5),i.blendMode="add",i.alpha=.02),i.x=(t.x+.5)*_,i.y=(t.y+.5)*_,this.lightLayer.addChild(i),this.activeLights.push(i)}}createLightTexture(){const e=3*_,t=e*2,i=document.createElement("canvas");i.width=t,i.height=t;const n=i.getContext("2d"),s=n.createRadialGradient(e,e,0,e,e,e);return s.addColorStop(0,"rgba(255,255,255,1)"),s.addColorStop(1,"rgba(255,255,255,0)"),n.fillStyle=s,n.fillRect(0,0,t,t),Ae.from(i)}destroy(){var e,t;this.destroyed||(this.destroyed=!0,this.cancelBounce(),this.cancelWheelTimeout(),(e=this.resizeObserver)==null||e.disconnect(),this.resizeObserver=null,this.hoverLayer.destroy(),(t=this.lightTexture)==null||t.destroy(!0),this.lightTexture=null,this.app.destroy(!0,{children:!0}))}}const To=856343,Qd=1448738,eu=1843496,tu=3421243,ru=tu,iu=To,rs=7039337,Mo=3159613,nu=1579032,su=0,ou=2631720,lu=2632986,au=2500383,cu=2771488,du=5000268,uu=11122630,hu=16770413,fu=7829367,pu=16332866,gu=6127794,mu=6684002,yu=12164347,ti={tough:du,move:uu,work:hu,carry:fu,attack:pu,ranged_attack:gu,heal:mu,claim:yu},Xi=5809919,Ht=7979263,Eo=4176208,ji=9147550,ri=13801762,_s=10711543,vu=16218298,$s=16273737,Dr=15763518,bu=2172461,is=rs,wu=13226457,At=12283502,hr=[16777215,16711680,8388736,255,65535,32768,16776960,16753920,10824234,8421504,16777215],xu={creep:Dr,spawn:Xi,extension:Ht,tower:Eo,container:ji,storage:ri,link:_s,rampart:Xi,road:is,wall:bu,extractor:ji,lab:vu,terminal:ri,observer:Ht,powerSpawn:Dr,nuker:$s,factory:ji,invaderCore:$s,source:ri,mineral:Ht,deposit:ri,controller:Xi,powerBank:Dr,portal:_s},_r=16771195,_u=_r,$u=Ht,Su=_r,Cu=_r,zr=9419667,ku=7245682,Tu=12116924,Mu=12283502,Eu=9787480,Ru=14721184,Ss=eu,Ou=13684944,Te=1579032,Et=5592405,yi=11184810,Pu=9419667,Ze=16771195,Lu=16069959,Cs=4410435;function Au(r){return{floorColor:(r==null?void 0:r.floorColor)??ru,swampFillColor:(r==null?void 0:r.swampFillColor)??lu,swampBorderColor:(r==null?void 0:r.swampBorderColor)??au,swampBorderWidth:(r==null?void 0:r.swampBorderWidth)??.2,swampGlowColor:(r==null?void 0:r.swampGlowColor)??cu,wallFillColor:(r==null?void 0:r.wallFillColor)??nu,wallBorderColor:(r==null?void 0:r.wallBorderColor)??su,wallBorderWidth:(r==null?void 0:r.wallBorderWidth)??.05,wallNoiseColor:(r==null?void 0:r.wallNoiseColor)??ou}}function Zt(r,e,t,i){const n=_,s=n/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,u=c>0&&e.get(l,c-1)===t,h=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*n+s,g=c*n+s;a?(o=!0,!u&&!d&&c>0&&l>0?(r.moveTo(p,c*n),r.arc(p,g,s,-Math.PI/2,Math.PI,!0),r.lineTo(p,g),r.closePath()):r.rect(l*n,c*n,s,s)):u&&d&&e.get(l-1,c-1)===t&&(o=!0,r.moveTo(p,c*n),r.lineTo(l*n,c*n),r.lineTo(l*n,g),r.arc(p,g,s,Math.PI,-Math.PI/2,!1),r.closePath()),a?!u&&!f&&c>0&&l<49?(r.moveTo(p,c*n),r.arc(p,g,s,-Math.PI/2,0,!1),r.lineTo(p,g),r.closePath()):r.rect(p,c*n,s,s):u&&f&&e.get(l+1,c-1)===t&&(o=!0,r.moveTo(p,c*n),r.lineTo(l*n+n,c*n),r.lineTo(l*n+n,g),r.arc(p,g,s,0,-Math.PI/2,!0),r.closePath()),a?!h&&!d&&c<49&&l>0?(r.moveTo(l*n,g),r.arc(p,g,s,Math.PI,Math.PI/2,!0),r.lineTo(p,g),r.closePath()):r.rect(l*n,g,s,s):h&&d&&e.get(l-1,c+1)===t&&(o=!0,r.moveTo(l*n,g),r.lineTo(l*n,c*n+n),r.lineTo(p,c*n+n),r.arc(p,g,s,Math.PI/2,Math.PI,!1),r.closePath()),a?!h&&!f&&c<49&&l<49?(r.moveTo(p,c*n+n),r.arc(p,g,s,Math.PI/2,0,!0),r.lineTo(p,g),r.closePath()):r.rect(p,g,s,s):h&&f&&e.get(l+1,c+1)===t&&(o=!0,r.moveTo(p,c*n+n),r.lineTo(l*n+n,c*n+n),r.lineTo(l*n+n,g),r.arc(p,g,s,0,Math.PI/2,!1),r.closePath())}o&&i(r)}function Iu(r,e){const t=rs,i=_,n=(s,o,c)=>{const l=s*i+i/2,a=o*i+i/2,u=i*.3;c==="up"?(r.moveTo(l,a-u),r.lineTo(l+u,a+u),r.lineTo(l-u,a+u)):c==="down"?(r.moveTo(l,a+u),r.lineTo(l+u,a-u),r.lineTo(l-u,a-u)):c==="left"?(r.moveTo(l-u,a),r.lineTo(l+u,a-u),r.lineTo(l+u,a+u)):c==="right"&&(r.moveTo(l+u,a),r.lineTo(l-u,a-u),r.lineTo(l-u,a+u)),r.fill(t)};for(let s=0;s<50;s++)e.get(s,0)!==Xe.Wall&&n(s,0,"up"),e.get(s,49)!==Xe.Wall&&n(s,49,"down");for(let s=0;s<50;s++)e.get(0,s)!==Xe.Wall&&n(0,s,"left"),e.get(49,s)!==Xe.Wall&&n(49,s,"right")}function Nu(r){const e=new re;return e.rect(0,0,50*_,50*_),e.fill(r.floorColor),e}function Du(r,e){const t=new re,i={color:e.swampBorderColor,width:_*e.swampBorderWidth,alignment:0,cap:"round",join:"round"};return Zt(t,r,Xe.Swamp,n=>n.stroke(i)),Zt(t,r,Xe.Swamp,n=>n.fill(e.swampFillColor)),t}function zu(r,e){const t=new re,i={color:e.wallBorderColor,width:_*e.wallBorderWidth,alignment:0,cap:"round",join:"round"};return Zt(t,r,Xe.Wall,n=>n.stroke(i)),Zt(t,r,Xe.Wall,n=>n.fill(e.wallFillColor)),Iu(t,r),t.rect(0,0,50*_,50*_),t.stroke({width:1,color:Mo}),t}function Gu(r,e){const t=new re;return t.label="swampGlow",Zt(t,r,Xe.Swamp,i=>i.fill(e.swampGlowColor)),t.alpha=.45,t.filters=[new Pl({strength:5,quality:3})],t}function Bu(r,e,t){const i=new re;Zt(i,r,Xe.Wall,o=>o.fill(t.wallNoiseColor)),i.alpha=.5,i.filters=[new Ol({noise:.12,seed:1})],i.filterArea=new no(0,0,50*_,50*_);const n=e.generateTexture({target:i,frame:i.filterArea});i.filters=null,i.destroy();const s=new ze(n);return s.label="wallNoise",s}function ii(r,e,t){const i=Au(t),n=new Ne,s=Bu(r,e,i),o=n.destroy.bind(n);n.destroy=l=>{s.destroyed||(s.removeFromParent(),s.destroy({texture:!0,textureSource:!0})),o(l)},n.addChild(Nu(i)),n.addChild(Du(r,i)),n.addChild(zu(r,i)),n.addChild(Gu(r,i)),n.addChild(s),t!=null&&t.wallTextureUrl&&(s.visible=!1);const c=50*_;if(t!=null&&t.floorTextureUrl){const{floorTextureUrl:l,floorTextureTint:a=16777215,floorTextureAlpha:u=1,floorTextureTileScale:h=1}=t;gn.load(l).then(d=>{if(n.destroyed)return;const f=new ds({texture:d,width:c,height:c});f.tint=a,f.alpha=u,f.tileScale.set(h),n.addChildAt(f,2)}).catch(()=>{})}if(t!=null&&t.wallTextureUrl){const{wallTextureUrl:l,wallTextureTint:a=16777215,wallTextureAlpha:u=1,wallTextureTileScale:h=1}=t;gn.load(l).then(d=>{if(n.destroyed)return;const f=new ds({texture:d,width:c,height:c});f.tint=a,f.alpha=u,f.tileScale.set(h);const p=new re;Zt(p,r,Xe.Wall,g=>g.fill(16777215)),n.addChild(p),f.mask=p,n.addChild(f)}).catch(()=>{})}return n}function Tr(r,e){r.getChildByLabel("swampGlow").visible=e,r.getChildByLabel("wallNoise").visible=e}function pr(r,e){const t=parseInt(r.replace("#",""),16),i=Math.min(255,Math.round((t>>16&255)*e)),n=Math.min(255,Math.round((t>>8&255)*e)),s=Math.min(255,Math.round((t&255)*e));return i<<16|n<<8|s}function ks(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 Fu(r,e,t){const i=t.terrain??{};r.floorBackgroundColor&&(i.floorColor=pr(r.floorBackgroundColor,Ye(r.floorBackgroundBrightness,1))),r.swampColor&&(i.swampFillColor=ks(r.swampColor)),r.swampStrokeColor&&(i.swampBorderColor=ks(r.swampStrokeColor)),r.swampStrokeWidth!=null&&(i.swampBorderWidth=Ye(r.swampStrokeWidth,50)/250),r.roadsColor&&(t.roadColor=pr(r.roadsColor,Ye(r.roadsBrightness,1))),e.floorForegroundUrl&&(i.floorTextureUrl=e.floorForegroundUrl,r.floorForegroundColor&&(i.floorTextureTint=pr(r.floorForegroundColor,Ye(r.floorForegroundBrightness,1))),i.floorTextureAlpha=Ye(r.floorForegroundAlpha,1),i.floorTextureTileScale=Ye(r.tileScale??e.tileScale,1)),t.terrain=i}function Hu(r,e,t){const i=t.terrain??{};r.backgroundColor&&(i.wallFillColor=pr(r.backgroundColor,Ye(r.backgroundBrightness,1))),r.strokeColor&&(i.wallBorderColor=pr(r.strokeColor,Ye(r.strokeBrightness,1))),r.strokeWidth!=null&&(i.wallBorderWidth=Ye(r.strokeWidth,10)/250),e.foregroundUrl&&(i.wallTextureUrl=e.foregroundUrl,r.foregroundColor&&(i.wallTextureTint=pr(r.foregroundColor,Ye(r.foregroundBrightness,1))),i.wallTextureAlpha=Ye(r.foregroundAlpha,1),i.wallTextureTileScale=Ye(r.tileScale??e.tileScale,1)),t.terrain=i}function Wu(r){const e={};for(const t of r.decorations){const i=t.decoration.type;i==="floorLandscape"?Fu(t.active,t.decoration,e):i==="wallLandscape"&&Hu(t.active,t.decoration,e)}return e}function Uu(r){return new Promise((e,t)=>{const i=new Image;i.onload=()=>e(i),i.onerror=t,i.src=r})}class Ro{constructor(){$(this,"cache",new Map);$(this,"pending",new Map)}getKey(e){return JSON.stringify(e)}has(e){return this.cache.has(this.getKey(e))}getOrCreate(e){const t=this.getKey(e),i=this.cache.get(t);if(i)return Promise.resolve(i);const n=this.pending.get(t);if(n)return n;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 i=Di(e),n=new Blob([i],{type:"image/svg+xml;charset=utf-8"}),s=URL.createObjectURL(n);try{const o=window.devicePixelRatio||1,c=128*Math.max(2,o),l=await Uu(s),a=document.createElement("canvas");a.width=c,a.height=c,a.getContext("2d").drawImage(l,0,0,c,c);const h=Ae.from(a);return this.cache.set(t,h),h}finally{URL.revokeObjectURL(s)}}destroy(){for(const e of this.cache.values())e.destroyed||e.destroy(!0);this.cache.clear(),this.pending.clear()}}const Oo={1:200,2:45e3,3:135e3,4:405e3,5:1215e3,6:3645e3,7:10935e3},Po={1:2e4,2:1e4,3:2e4,4:4e4,5:8e4,6:12e4,7:15e4,8:2e5},Yu=new Ro,xt=_*.44,rt=_*.28,Mr=50,Wr=32,wn=12/Wr,xn=_/2-_*.44,Lo=2,Xu=12*1.2/Wr,ju=5,Vu=2.5,ni=2,Vi=2.6,qu=2,Ts=12,Ms=15790320,Zu=1710618,Es=_*.42,Ao=_*.3,Ku=Math.max(1,_*.08),Ju={H:13421772,O:16777215,U:5822457,L:62626,K:10514943,Z:16631694,X:11568379},Qu={H:2236962,O:2236962},eh=_*.42,Io=32,th=9/Io,_n=_-4,Rs=_*.28,Os=1600,rh=16776428;function $n(r,e){if(e<=0)return _n;const t=Math.max(0,Math.min(1,r/e));return Rs+(_n-Rs)*t}function ns(r,e,t=Ze){const i=e/2,n=_/2,s=_/2,o=e*.25;r.clear(),r.roundRect(n-i,s-i,e,e,o),r.fill(t)}function qi(r,e){const t=r.__sourceGraphics;t&&(r.__sourceSize=e,ns(t,e,ss(performance.now())))}function ss(r){const e=r%Os/Os,t=.5-.5*Math.cos(e*Math.PI*2);return vi(Ze,rh,t)}function Sn(r){const e=typeof r.energy=="number"?r.energy:0,t=typeof r.energyCapacity=="number"?r.energyCapacity:3e3;return{energy:e,capacity:t}}const No=_*.3,Do=Math.max(1,_*.12),Cn=No-Do/2,ih=_*.42,nh=1500;function vi(r,e,t){const i=r>>16&255,n=r>>8&255,s=r&255,o=e>>16&255,c=e>>8&255,l=e&255,a=Math.round(i+(o-i)*t),u=Math.round(n+(c-n)*t),h=Math.round(s+(l-s)*t);return a<<16|u<<8|h}function zo(r,e){r.clear(),r.circle(_/2,_/2,No),r.stroke({width:Do,color:e,alpha:.95})}function kn(r,e,t,i,n,s,o){if(r.clear(),s<=0||n<=0)return;const c=Math.min(1,n/s);if(c>=1){r.circle(e,t,i),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+i*Math.cos(l),t+i*Math.sin(l)),r.arc(e,t,i,l,a),r.closePath(),r.fill({color:o,alpha:.55})}function yt(r,e,t){return t.flatMap(([i,n])=>[r+i*_,e+n*_])}function tr(r,e,t,i){t-e<.001||(r.moveTo(xt*Math.cos(e),xt*Math.sin(e)),r.arc(0,0,xt,e,t),r.lineTo(rt*Math.cos(t),rt*Math.sin(t)),r.arc(0,0,rt,t,e,!0),r.closePath(),r.fill(i))}function Tn(r){let e=0;if(typeof r.storeCapacity=="number")e=r.storeCapacity;else{const i=r.body;i&&(e=i.filter(n=>n.type==="carry").length*50)}if(e===0)return{used:0,capacity:0};let t=0;if(r.store&&typeof r.store=="object"){const i=r.store;for(const n in i){const s=i[n];typeof s=="number"&&(t+=s)}}else typeof r.energy=="number"&&(t=r.energy);return{used:t,capacity:e}}function Mn(r,e){return e<=0||r<=0?0:rt*.8*Math.min(1,r/e)}function Zi(r,e){const t=r.__creepFillGraphics;t&&(t.clear(),e>0&&(t.circle(0,0,e),t.fill(_r)))}function sh(r){return xu[r]??wu}function fr(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 Go(r){return r>=200?1.15:r>=100?.85:.7}function En(r,e){return e<=0||r<=0?0:Ao*Go(e)*Math.min(1,r/e)}function oh(r,e,t,i){const n=_/2,s=_/2,o=Go(t),c=new re;c.circle(n,s,Es*o),c.fill(Te),c.circle(n,s,Es*o),c.stroke({width:Ku*o,color:i}),c.circle(n,s,Ao*o),c.fill(yi),r.addChild(c);const l=new re,a=En(e,t);a>0&&(l.circle(n,s,a),l.fill(Ze)),r.addChild(l),r.__fillGraphics=l}function Ki(r,e){const t=_/2,i=_/2,n=r.__fillGraphics;n&&(n.clear(),e>0&&(n.circle(t,i,e),n.fill(Ze)))}const Rn=-_*.4,On=-_*.3,Pn=_*.8,_i=_*.6;function Ln(r,e){return e<=0||r<=0?0:_i*Math.min(1,r/e)}function bi(r,e){const t=r.__towerFillGraphics;if(t&&(t.clear(),e>0)){const i=Math.max(.5,_*.02);t.rect(Rn+i,On+_i-e+i,Pn-i*2,e-i*2),t.fill(Ze)}}const lh=0,ah=-_*.1,ch=_*1,Bo=_*1.2;function An(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 i=r.store;for(const n in i){const s=i[n];typeof s=="number"&&(t+=s)}}return{used:t,capacity:e}}function $i(r,e){return e<=0||r<=0?0:Bo*Math.min(1,r/e)}function Si(r,e){const t=r.__storageFillG;t&&(t.clear(),e>0&&(t.rect(lh,ah+Bo-e,ch,e),t.fill(Ze)))}const In=_*.65,Nn=In,st=_*.42;function Dn(r,e,t,i,n,s,o,c){r.clear();const l=8,a=.1,u=2*Math.PI/l-a;for(let h=0;h<l;h++){const d=-Math.PI/2+h*(2*Math.PI/l)+a/2,f=d+u,p=e+n*Math.cos(d),g=t+n*Math.sin(d);if(h<s)r.moveTo(p,g),r.arc(e,t,i,d,f),r.arc(e,t,n,f,d,!0),r.closePath(),r.fill({color:14540253,alpha:.9});else if(h===s&&c>0){if(r.moveTo(p,g),r.arc(e,t,i,d,f),r.arc(e,t,n,f,d,!0),r.closePath(),r.fill({color:1973790,alpha:.85}),o>0){const S=Math.min(1,o/c),P=d+u*S;r.moveTo(p,g),r.arc(e,t,i,d,P),r.arc(e,t,n,P,d,!0),r.closePath(),r.fill({color:14540253,alpha:.9})}}else r.moveTo(p,g),r.arc(e,t,i,d,f),r.arc(e,t,n,f,d,!0),r.closePath(),r.fill({color:1973790,alpha:.6})}}function zn(r,e,t,i){const n=r.__ctrlSegSprites;if(n)for(let s=0;s<n.length;s++)s<e?n[s].alpha=1:s===e&&i>0?n[s].alpha=Math.max(.15,t/i):n[s].alpha=.15}function Ci(r,e){const t=r.user;return typeof t!="string"||!e?!1:t!==e}function rr(r,e=!0,t,i,n,s,o,c){var z,U,O,y,x,L,v;const l=new Ne,a=new re,u=sh(r.type),h=_/2,d=_/2,f=typeof r.user=="string"?r.user:void 0,g=f!==void 0&&t!==void 0&&f!==t?At:Pu;switch(r.type){case"creep":{const C=2*Math.PI,T=new Ne;T.position.set(h,d),T.rotation=-Math.PI/2;const w=Ci(r,t);if(w){const Y=new re;Y.circle(0,0,xt+.75),Y.stroke({width:1.5,color:At}),T.addChild(Y)}const M=new re;M.circle(0,0,xt),M.fill(To),T.addChild(M);const k=r.body??[];let E=0,D=0,I=0;const H=[],A={};for(const Y of k)Y.type==="work"?E++:Y.type==="move"?D++:(A[Y.type]===void 0&&(H.push(Y.type),A[Y.type]=0),A[Y.type]++,I++);const G=E/Mr*C,V=D/Mr*C,F=I/Mr*C,Z=G/2,j=Z+F/2,W=Math.PI-V/2,J=Math.PI+V/2,ue=C-G/2-F/2,ae=C-G/2,se=new re;G>0&&tr(se,-G/2,Z,ti.work);let me=Z;for(const Y of H){const K=(A[Y]??0)/Mr*C/2;tr(se,me,me+K,ti[Y]??7829367),me+=K}tr(se,j,W,Ss),V>0&&tr(se,W,J,ti.move),tr(se,J,ue,Ss);let ee=ae;for(const Y of H){const K=(A[Y]??0)/Mr*C/2;tr(se,ee-K,ee,ti[Y]??7829367),ee-=K}T.addChild(se);const fe=new re;fe.circle(0,0,rt),fe.fill(Qd),T.addChild(fe);const Ee=typeof r.user=="string"?r.user:void 0,Oe=Ee?(z=s==null?void 0:s[Ee])==null?void 0:z.badge:void 0;if(Oe&&n){const Y=new ze;Y.anchor.set(.5,.5);const K=rt*2;Y.width=K,Y.height=K,Y.rotation=Math.PI/2,T.addChild(Y),l.__creepBadgeSprite=Y,n.getOrCreate(Oe).then(ie=>{Y.destroyed||(Y.texture=ie)}).catch(()=>{})}else if(w){const Y=new re;Y.circle(0,0,rt*.82),Y.fill({color:At,alpha:.9}),T.addChild(Y),l.__creepForeignMark=Y}const{used:je,capacity:Ke}=Tn(r),Mt=Mn(je,Ke),Je=new re;Mt>0&&(Je.circle(0,0,Mt),Je.fill(_r)),T.addChild(Je),l.__creepFillGraphics=Je,l.__creepUsed=je,l.__creepCapacity=Ke;const oe=(xt+rt)/2,ne=(xt-rt)*.45,ce=new re;ce.moveTo(xt,0),ce.lineTo(oe,-ne),ce.lineTo(oe,ne),ce.closePath(),ce.fill(Ou),T.addChild(ce),l.addChild(T),l.__bodyContainer=T;break}case"extension":{const{energy:C,capacity:T}=fr(r);oh(l,C,T,g),l.__extEnergy=C,l.__extCapacity=T;break}case"spawn":{a.circle(h,d,_*.65),a.fill(Te),a.circle(h,d,_*.65),a.stroke({width:_*.1,color:13421772}),a.circle(h,d,_*.4),a.fill(Ze);break}case"powerSpawn":{a.circle(h,d,_*.65),a.fill(Te),a.circle(h,d,_*.65),a.stroke({width:_*.1,color:Lu}),a.circle(h,d,_*.4),a.fill(Ze);break}case"source":{const{energy:C,capacity:T}=Sn(r),w=$n(C,T),M=new re;ns(M,w,ss(performance.now())),l.addChild(M),l.__sourceGraphics=M,l.__sourceEnergy=C,l.__sourceCapacity=T,l.__sourceSize=w;break}case"constructionSite":{const C=typeof r.user=="string"?r.user:void 0,T=C!==void 0&&C===t,w=T?zr:Mu,M=T?ku:Eu,k=T?Tu:Ru,E=typeof r.progress=="number"?r.progress:0,D=typeof r.progressTotal=="number"?r.progressTotal:1,I=new re;l.addChild(I),l.__csBuildGlow=I;const H=new re;kn(H,h,d,Cn,E,D,w),l.addChild(H),l.__csFillGraphics=H;const A=new re;zo(A,w),l.addChild(A),l.__csRingGraphics=A,l.__csProgress=E,l.__csProgressTotal=D,l.__csUser=C,l.__csColor=w,l.__csColorDark=M,l.__csColorLight=k;break}case"mineral":{const C=typeof r.mineralType=="string"?r.mineralType:"?",T=Ju[C]??Ht,w=Qu[C]??16777215,M=new re;M.circle(h,d,eh),M.fill(T),l.addChild(M);const k=new Bt({text:C,style:{fontSize:Io,fill:w,fontWeight:"bold"}});k.anchor.set(.5,.5),k.scale.set(th),k.position.set(h,d),l.addChild(k);break}case"deposit":{a.rect(2,2,_-4,_-4),a.fill(u);break}case"controller":{const C=typeof r.level=="number"?r.level:0,T=typeof r.progress=="number"?r.progress:0,w=typeof r.progressTotal=="number"?r.progressTotal:0,M=typeof r.user=="string"?r.user:void 0,k=M?(U=s==null?void 0:s[M])==null?void 0:U.badge:void 0,E=o==null?void 0:o.controller;if(E&&c){const I=_*E.tileScale,H=I/600,A=new ze;A.anchor.set(.5,.5),A.x=h,A.y=d,A.width=I,A.height=I,l.addChild(A);const G=[];for(let j=0;j<8;j++){const W=new ze;W.anchor.set(.5,.5),W.x=h,W.y=d,W.scale.set(H),W.rotation=j*(Math.PI/4),l.addChild(W),G.push(W)}l.__ctrlSegSprites=G,zn(l,C,T,w);const V=()=>c.getOrLoad(o.atlasUrl),F=c.getTexture(o.atlasUrl,E.backgroundFrame);F?A.texture=F:V().then(j=>{A.destroyed||(A.texture=j.textures[E.backgroundFrame]??Ae.EMPTY)}).catch(()=>{});const Z=c.getTexture(o.atlasUrl,E.segmentFrame);if(Z)for(const j of G)j.texture=Z;else V().then(j=>{const W=j.textures[E.segmentFrame]??Ae.EMPTY;for(const J of G)J.destroyed||(J.texture=W)}).catch(()=>{})}else{const I=new re,H=[];for(let G=0;G<8;G++){const V=-Math.PI/2+G*Math.PI/4;H.push(h+In*Math.cos(V),d+In*Math.sin(V))}I.poly(H),I.fill(2238513),I.poly(H),I.stroke({width:_*.07,color:8027781}),l.addChild(I);const A=new re;Dn(A,h,d,Nn,st,C,T,w),l.addChild(A),l.__ctrlSegGraphics=A}l.__ctrlLevel=C,l.__ctrlProgress=T,l.__ctrlProgressTotal=w,l.__ctrlDowngradeTime=typeof r.downgradeTime=="number"?r.downgradeTime:void 0,l.__ctrlUserId=M;const D=new re;if(k?(D.circle(h,d,st),D.fill(Te)):(D.circle(h,d,st),D.fill(3028031),D.circle(h,d,st),D.stroke({width:_*.04,color:8027781}),D.circle(h,d,_*.16),D.fill(10133672)),l.addChild(D),k&&n){const I=new ze;I.anchor.set(.5,.5),I.width=st*2,I.height=st*2,I.position.set(h,d);const H=new re;H.circle(h,d,st),H.fill(16777215),l.addChild(I),I.mask=H,l.addChild(H),n.getOrCreate(k).then(A=>{I.destroyed||(I.texture=A)}).catch(()=>{})}break}case"energy":{a.circle(h,d,_*.2),a.fill(Ze);break}case"road":break;case"wall":{a.circle(h,d,_*.4),a.fill(Te),a.circle(h,d,_*.4),a.stroke({width:_*.05,color:yi});break}case"rampart":break;case"tower":{const{energy:C,capacity:T}=fr(r),w=new re;w.circle(h,d,_*.6),w.fill(Te),w.circle(h,d,_*.6),w.stroke({width:_*.05,color:g}),l.addChild(w);const M=new Ne;M.position.set(h,d);const k=new re;k.rect(Rn,On,Pn,_i),k.fill(Te),M.addChild(k);const E=new re;M.addChild(E),l.__towerFillGraphics=E,l.__towerEnergy=C,l.__towerCapacity=T,bi(l,Ln(C,T));const D=new re;D.rect(Rn,On,Pn,_i),D.stroke({width:1,color:Et}),M.addChild(D);const I=new re;I.rect(-_*.2,-_*.9,_*.4,_*.5),I.fill(yi),I.rect(-_*.2,-_*.9,_*.4,_*.5),I.stroke({width:_*.07,color:Te}),M.addChild(I),l.addChild(M),l.__barrelContainer=M;break}case"storage":{const C=o==null?void 0:o.sprites.storage;if(C&&c){const{used:D,capacity:I}=An(r),H=_*C.tileScale,A=(V,F)=>{V.texture=F,V.width=H,V.height=H};for(const V of C.layers){const F=new ze;F.anchor.set(.5,.5),F.x=h,F.y=d,V.tint==="owner"&&(F.tint=g),l.addChild(F);const Z=c.getTexture(o.atlasUrl,V.frame);Z?A(F,Z):c.getOrLoad(o.atlasUrl).then(j=>{F.destroyed||A(F,j.textures[V.frame]??Ae.EMPTY)}).catch(()=>{})}const G=new re;l.addChild(G),l.__storageFillG=G,l.__storageUsed=D,l.__storageCapacity=I,Si(l,$i(D,I));break}const{used:T,capacity:w}=An(r),M=yt(h,d,[[-.6,-.7],[0,-.8],[.6,-.7],[.65,0],[.6,.7],[0,.8],[-.6,.7],[-.65,0],[-.6,-.7]]);a.poly(M),a.fill(Te),a.poly(M),a.stroke({width:_*.05,color:g}),a.rect(h-_*.5,d-_*.6,_*1,_*1.2),a.fill(Et),l.addChild(a);const k=new re;l.addChild(k),l.__storageFillG=k,l.__storageUsed=T,l.__storageCapacity=w,Si(l,$i(T,w));const E=new re;E.rect(h-_*.5,d-_*.6,_*1,_*1.2),E.stroke({width:_*.1,color:Te}),l.addChild(E);break}case"terminal":{const C=yt(h,d,[[0,-.8],[.55,-.55],[.8,0],[.55,.55],[0,.8],[-.55,.55],[-.8,0],[-.55,-.55],[0,-.8]]),T=yt(h,d,[[0,-.65],[.45,-.45],[.65,0],[.45,.45],[0,.65],[-.45,.45],[-.65,0],[-.45,-.45],[0,-.65]]);a.poly(C),a.fill(Te),a.poly(C),a.stroke({width:_*.05,color:g}),a.poly(T),a.fill(yi),a.rect(h-_*.45,d-_*.45,_*.9,_*.9),a.fill(Et),a.rect(h-_*.45,d-_*.45,_*.9,_*.9),a.stroke({width:_*.1,color:Te});break}case"link":{const C=yt(h,d,[[0,-.5],[.4,0],[0,.5],[-.4,0],[0,-.5]]),T=yt(h,d,[[0,-.3],[.25,0],[0,.3],[-.25,0],[0,-.3]]);a.poly(C),a.fill(Te),a.poly(C),a.stroke({width:_*.05,color:g}),a.poly(T),a.fill(Et);break}case"lab":{const C=d-_*.025;a.circle(h,C,_*.55),a.fill(Te),a.circle(h,C,_*.55),a.stroke({width:_*.05,color:g}),a.circle(h,C,_*.4),a.fill(Et),a.rect(h-_*.45,d+_*.3,_*.9,_*.25),a.fill(Te),a.poly(yt(h,d,[[-.45,.3],[-.45,.55],[.45,.55],[.45,.3]])),a.stroke({width:_*.05,color:g});break}case"container":{a.rect(h-_*.225,d-_*.3,_*.45,_*.6),a.fill(Ze),a.rect(h-_*.225,d-_*.3,_*.45,_*.6),a.stroke({width:_*.1,color:Te});break}case"observer":{a.circle(h,d,_*.45),a.fill(Te),a.circle(h,d,_*.45),a.stroke({width:_*.05,color:g}),a.circle(h+_*.225,d,_*.2),a.fill(g);break}case"nuker":{const C=yt(h,d,[[0,-1],[-.47,.2],[-.5,.5],[.5,.5],[.47,.2],[0,-1]]),T=yt(h,d,[[0,-.8],[-.4,.2],[.4,.2],[0,-.8]]);a.poly(C),a.fill(Te),a.poly(C),a.stroke({width:_*.05,color:g}),a.poly(T),a.fill(Et),a.poly(T),a.stroke({width:_*.01,color:g});break}case"factory":case"extractor":case"invaderCore":{a.circle(h,d,_*.45),a.fill(Te),a.circle(h,d,_*.45),a.stroke({width:_*.05,color:g}),a.circle(h,d,_*.35),a.fill(Et);break}case"flag":{const C=typeof r.color=="number"?r.color:0,T=typeof r.secondaryColor=="number"?r.secondaryColor:0,w=hr[C]??hr[0],M=hr[T]??hr[0],k=o==null?void 0:o.flag;if(k&&c){const E=_*k.tileScale,D=()=>c.getOrLoad(o.atlasUrl),I=(G,V)=>{G.texture=V,G.width=E,G.height=E},H=new ze;H.anchor.set(.5,.5),H.x=h,H.y=d,H.tint=w,l.addChild(H);const A=c.getTexture(o.atlasUrl,k.mainFrame);if(A?I(H,A):D().then(G=>{H.destroyed||I(H,G.textures[k.mainFrame]??Ae.EMPTY)}).catch(()=>{}),T!==C){const G=new ze;G.anchor.set(.5,.5),G.x=h,G.y=d,G.tint=M,l.addChild(G);const V=c.getTexture(o.atlasUrl,k.secondFrame);V?I(G,V):D().then(F=>{G.destroyed||I(G,F.textures[k.secondFrame]??Ae.EMPTY)}).catch(()=>{})}}else{const D=_*.08*1.5,I=_*.7*1.5,H=h-D/2,A=d-_*.25*1.5;a.rect(H,A,D,I),a.fill(8947848);const G=H+D,V=A,F=G+_*.45*1.5,Z=V,j=V+_*.44*1.5,W=(Z+j)/2,J=W;a.moveTo(G,Z),a.lineTo(F,W),a.lineTo(G,J),a.closePath(),a.fill(w),a.moveTo(G,J),a.lineTo(F,W),a.lineTo(G,j),a.closePath(),a.fill(M),l.addChild(a)}if(l.__flagColor=C,l.__flagSecondaryColor=T,typeof r.name=="string"){const E=new Bt({text:r.name,style:{fontSize:Wr,fill:16777215}});E.scale.set(wn),E.anchor.set(.5,0),E.x=h,E.y=d+_*.55,E.visible=e,l.__nameLabel=E,l.addChild(E)}break}case"ruin":{const C=typeof r.user=="string"?r.user:void 0,w=C!==void 0&&C===t?zr:At,M=_*.42,k=6,E=Math.PI/5,D=new re;for(let A=0;A<k;A++){const G=A*Math.PI*2/k,V=G-E/2,F=G+E/2,Z=h+M*Math.cos(V),j=d+M*Math.sin(V);D.moveTo(Z,j),D.arc(h,d,M,V,F),D.stroke({width:_*.09,color:w,alpha:.75,cap:"round"})}l.addChild(D);const I=_*.18,H=new re;H.moveTo(h-I,d-I),H.lineTo(h+I,d+I),H.moveTo(h+I,d-I),H.lineTo(h-I,d+I),H.stroke({width:_*.11,color:w,cap:"round"}),l.addChild(H);break}case"tombstone":{const C=typeof r.user=="string"?r.user:void 0,w=C!==void 0&&C===t?zr:At,M=o==null?void 0:o.tombstone;if(M&&c){const k=_*M.tileScale,E=()=>c.getOrLoad(o.atlasUrl),D=new ze;D.anchor.set(.5,.5),D.x=h,D.y=d,D.width=k,D.height=k,l.addChild(D);const I=new ze;I.anchor.set(.5,.5),I.x=h,I.y=d,I.width=k,I.height=k,I.tint=w,l.addChild(I);const H=c.getTexture(o.atlasUrl,M.shellFrame);H?D.texture=H:E().then(G=>{D.destroyed||(D.texture=G.textures[M.shellFrame]??Ae.EMPTY)}).catch(()=>{});const A=c.getTexture(o.atlasUrl,M.crossFrame);A?I.texture=A:E().then(G=>{I.destroyed||(I.texture=G.textures[M.crossFrame]??Ae.EMPTY)}).catch(()=>{})}else{const k=_*.62,E=_*.82,D=h-k/2,I=d-E/2,H=k/2,A=new re;A.moveTo(D,I+H),A.arc(h,I+H,H,Math.PI,0,!1),A.lineTo(D+k,I+E),A.lineTo(D,I+E),A.closePath(),A.fill(Te),A.moveTo(D,I+H),A.arc(h,I+H,H,Math.PI,0,!1),A.lineTo(D+k,I+E),A.lineTo(D,I+E),A.closePath(),A.stroke({width:_*.07,color:w,alpha:.9}),l.addChild(A);const G=_*.18,V=new re;V.moveTo(h-G,d-G*.6),V.lineTo(h+G,d+G*.6),V.moveTo(h+G,d-G*.6),V.lineTo(h-G,d+G*.6),V.stroke({width:_*.09,color:w,cap:"round"}),l.addChild(V)}break}default:{const C=_-2;a.rect(1,1,C,C),a.fill(u)}}if(r.type!=="extension"&&r.type!=="road"&&r.type!=="creep"&&r.type!=="tower"&&r.type!=="controller"&&r.type!=="flag"&&r.type!=="source"&&r.type!=="constructionSite"&&r.type!=="mineral"&&r.type!=="tombstone"&&r.type!=="ruin"&&r.type!=="storage"&&l.addChild(a),r.type==="creep"&&typeof r.name=="string"){const C=Ci(r,t);let T;if(C){const k=typeof r.user=="string"?r.user:void 0;T=k?((O=s==null?void 0:s[k])==null?void 0:O.username)??k:"Hostile"}else T=r.name;const w=C?At:16777215,M=new Bt({text:T,style:{fontSize:Wr,fill:w}});M.scale.set(wn),M.anchor.set(.5,1),M.x=h,M.y=xn-Lo,M.visible=e,l.__nameLabel=M,l.addChild(M)}const S=r.type==="creep"?100:r.type==="flag"?200:0,P=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"?((L=o==null?void 0:o.tombstone)==null?void 0:L.zIndex)??0:((v=o==null?void 0:o.sprites[r.type])==null?void 0:v.zIndex)??0;return l.zIndex=S+P,l.position.set(r.x*_,r.y*_),l}function Rt(r){r.destroy({children:!0})}function dh(r){const e=r.length>Ts?r.slice(0,Ts):r,t=new Bt({text:e,style:{fontSize:Wr,fill:Zu,fontWeight:"600"}});t.scale.set(Xu),t.anchor.set(.5,.5);const i=t.width,n=t.height,s=i+ju*2,o=n+Vu*2,c=o/2,l=new re;l.roundRect(-s/2,-o/2,s,o,c),l.fill(Ms),l.roundRect(-s/2,-o/2,s,o,c),l.stroke({width:.4,color:1118481,alpha:.55}),l.moveTo(-ni,o/2-.1),l.lineTo(0,o/2+Vi),l.lineTo(ni,o/2-.1),l.closePath(),l.fill(Ms),l.moveTo(-ni,o/2-.1),l.lineTo(0,o/2+Vi),l.lineTo(ni,o/2-.1),l.stroke({width:.4,color:1118481,alpha:.55});const a=new Ne;return a.addChild(l),a.addChild(t),a.pivot.set(0,o/2+Vi),a}class uh{constructor(e,t=!0,i,n,s){$(this,"container");$(this,"objects",new Map);$(this,"rawObjects",new Map);$(this,"roadGraphics");$(this,"rampartGraphics");$(this,"ticker",null);$(this,"tickerCallback",null);$(this,"extAnimations",new Map);$(this,"creepFillAnimations",new Map);$(this,"towerFillAnimations",new Map);$(this,"storageFillAnimations",new Map);$(this,"sourceAnimations",new Map);$(this,"buildGlowAnimations",new Map);$(this,"ctrlFlashAnimations",new Map);$(this,"currentGameTime",0);$(this,"sayBubbles",new Set);$(this,"moveDuration",600);$(this,"EXT_ANIM_DURATION",300);$(this,"instantMode",!1);$(this,"lastWorldScale",1);$(this,"showLabels");$(this,"currentUserId");$(this,"badge");$(this,"badgeCache",Yu);$(this,"users");$(this,"activeTheme",null);$(this,"atlasCache",null);$(this,"roadColor",is);this.showLabels=t,this.currentUserId=i,this.badge=n,this.users=s,this.container=new Ne,this.container.sortableChildren=!0,this.rampartGraphics=new re,this.rampartGraphics.zIndex=-1,this.container.addChild(this.rampartGraphics),this.roadGraphics=new re,this.container.addChild(this.roadGraphics),e&&(this.ticker=e,this.tickerCallback=()=>this.tick(),e.add(this.tickerCallback))}setTheme(e,t){this.activeTheme=e,this.atlasCache=t}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,u=l.__moveStartT??e,h=e-u;if(a<=0||h>=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=h/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 i=performance.now(),n=i/1e3,s=.5+.5*Math.sin(i*2*Math.PI/nh);for(const l of this.objects.values())l.__barrelContainer&&(l.__barrelContainer.rotation=n*.4),l.__csRingGraphics&&l.__csColorDark!==void 0&&l.__csColorLight!==void 0&&zo(l.__csRingGraphics,vi(l.__csColorDark,l.__csColorLight,s));for(const[l,a]of this.extAnimations){const u=i-a.startTime,h=Math.min(1,u/this.EXT_ANIM_DURATION),d=h<.5?2*h*h:1-Math.pow(-2*h+2,2)/2;Ki(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*d),h>=1&&this.extAnimations.delete(l)}for(const[l,a]of this.creepFillAnimations){const u=i-a.startTime,h=Math.min(1,u/this.EXT_ANIM_DURATION),d=h<.5?2*h*h:1-Math.pow(-2*h+2,2)/2;Zi(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*d),h>=1&&this.creepFillAnimations.delete(l)}for(const[l,a]of this.towerFillAnimations){const u=i-a.startTime,h=Math.min(1,u/this.EXT_ANIM_DURATION),d=h<.5?2*h*h:1-Math.pow(-2*h+2,2)/2;bi(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*d),h>=1&&this.towerFillAnimations.delete(l)}for(const[l,a]of this.storageFillAnimations){const u=i-a.startTime,h=Math.min(1,u/this.EXT_ANIM_DURATION),d=h<.5?2*h*h:1-Math.pow(-2*h+2,2)/2;Si(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*d),h>=1&&this.storageFillAnimations.delete(l)}for(const[l,a]of this.sourceAnimations){const u=i-a.startTime,h=Math.min(1,u/this.EXT_ANIM_DURATION),d=h<.5?2*h*h:1-Math.pow(-2*h+2,2)/2;qi(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*d),h>=1&&this.sourceAnimations.delete(l)}const o=ss(i);for(const l of this.objects.values()){const a=l.__sourceGraphics;a&&ns(a,l.__sourceSize??_n,o)}for(const[l,a]of this.buildGlowAnimations){const u=this.objects.get(l),h=u==null?void 0:u.__csBuildGlow;if(!u||!h){this.buildGlowAnimations.delete(l);continue}const d=(i-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,h.clear(),f>0&&(h.circle(_/2,_/2,ih),h.fill({color:Ze,alpha:f*.75})),d>=1&&this.buildGlowAnimations.delete(l)}for(const[l,a]of this.ctrlFlashAnimations){const u=this.objects.get(l),h=u==null?void 0:u.__ctrlSegSprites;if(!u||!h){this.ctrlFlashAnimations.delete(l);continue}const d=Math.min(1,(i-a.startTime)/a.duration),f=1-(1-d)*(1-d),p=h[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,u=l.__ctrlSegSprites;if(!a||!u)continue;const h=l.__ctrlDowngradeTime;if(!h){for(let O=0;O<a;O++){const y=u[O];y&&!y.destroyed&&(y.tint=16777215)}continue}const d=Po[a]??2e4,p=1-Math.max(0,h-this.currentGameTime)/d;if(p<=.2){for(let O=0;O<a;O++){const y=u[O];y&&!y.destroyed&&(y.tint=16777215)}continue}const g=(p-.2)/.8,S=.3+g*1.5,P=.5+.5*Math.sin(2*Math.PI*S*i/1e3),z=vi(16768477,16720418,g),U=vi(16777215,z,g*P);for(let O=0;O<a;O++){const y=u[O];y&&!y.destroyed&&(y.tint=U)}}}startExtAnimation(e,t,i,n,s,o){const c=En(s,o);if(this.instantMode){Ki(t,c);return}const l=En(i,n);l!==c&&this.extAnimations.set(e,{visual:t,fromRadius:l,toRadius:c,startTime:performance.now()})}startCreepFillAnimation(e,t,i,n,s,o){const c=Mn(s,o);if(this.instantMode){Zi(t,c);return}const l=Mn(i,n);l!==c&&this.creepFillAnimations.set(e,{visual:t,fromRadius:l,toRadius:c,startTime:performance.now()})}startTowerFillAnimation(e,t,i,n,s,o){const c=Ln(s,o);if(this.instantMode){bi(t,c);return}const l=Ln(i,n);l!==c&&this.towerFillAnimations.set(e,{visual:t,fromRadius:l,toRadius:c,startTime:performance.now()})}startStorageFillAnimation(e,t,i,n,s,o){const c=$i(s,o);if(this.instantMode){Si(t,c);return}const l=$i(i,n);l!==c&&this.storageFillAnimations.set(e,{visual:t,fromRadius:l,toRadius:c,startTime:performance.now()})}startSourceAnimation(e,t,i,n,s,o){const c=$n(s,o);if(this.instantMode){qi(t,c);return}const l=$n(i,n);l!==c&&this.sourceAnimations.set(e,{visual:t,fromRadius:l,toRadius:c,startTime:performance.now()})}update(e,t,i,n){i&&(this.users=i),n!==void 0&&(this.currentGameTime=n);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),Rt(a),this.objects.delete(o),this.rawObjects.delete(o),this.extAnimations.delete(o),this.creepFillAnimations.delete(o),this.towerFillAnimations.delete(o),this.storageFillAnimations.delete(o),this.sourceAnimations.delete(o),this.buildGlowAnimations.delete(o),this.ctrlFlashAnimations.delete(o),this.sayBubbles.delete(o))}else{const l=e[o];if(!l)continue;if(l.type==="road"){const u=this.rawObjects.get(o);(!u||u.x!==l.x||u.y!==l.y)&&(s=!0)}this.rawObjects.set(o,l);const a=this.objects.get(o);if(a){const u=l.x*_,h=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(u,h),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!==u||a.y!==h)&&(a.__targetX=u,a.__targetY=h,a.__moveStartX=a.x,a.__moveStartY=a.y,a.__moveStartT=performance.now(),a.__moveDur=this.moveDuration);const{used:p,capacity:g}=Tn(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),Rt(a),this.objects.delete(o);const g=rr(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(u,h)}else a.position.set(u,h);if(l.type==="extension"){const{energy:d,capacity:f}=fr(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}=fr(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}=An(l);(a.__storageUsed!==d||a.__storageCapacity!==f)&&(this.startStorageFillAnimation(o,a,a.__storageUsed??0,a.__storageCapacity??f,d,f),a.__storageUsed=d,a.__storageCapacity=f)}if(l.type==="controller"){const d=typeof l.level=="number"?l.level:0,f=typeof l.progress=="number"?l.progress:0,p=typeof l.progressTotal=="number"?l.progressTotal:0,g=typeof l.user=="string"?l.user:void 0;if(a.__ctrlUserId!==g){this.container.removeChild(a),Rt(a),this.objects.delete(o);const P=rr(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users,this.activeTheme,this.atlasCache);P.__tileX=l.x,P.__tileY=l.y,this.applyLabelScale(P),this.objects.set(o,P),this.container.addChild(P);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}),zn(a,d,f,p)):a.__ctrlSegGraphics&&Dn(a.__ctrlSegGraphics,_/2,_/2,Nn,st,d,f,p),a.__ctrlLevel=d,a.__ctrlProgress=f,a.__ctrlProgressTotal=p);const S=typeof l.downgradeTime=="number"?l.downgradeTime:void 0;a.__ctrlDowngradeTime!==S&&(a.__ctrlDowngradeTime=S)}if(l.type==="source"){const{energy:d,capacity:f}=Sn(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&&kn(a.__csFillGraphics,_/2,_/2,Cn,d,f,a.__csColor??zr),a.__csProgress=d,a.__csProgressTotal=f)}}else{const u=rr(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users,this.activeTheme,this.atlasCache);u.__tileX=l.x,u.__tileY=l.y,this.applyLabelScale(u),this.objects.set(o,u),this.container.addChild(u)}}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 u=l.x*_,h=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(u,h),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!==u||a.y!==h)&&(a.__targetX=u,a.__targetY=h,a.__moveStartX=a.x,a.__moveStartY=a.y,a.__moveStartT=performance.now(),a.__moveDur=this.moveDuration);const{used:p,capacity:g}=Tn(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),Rt(a),this.objects.delete(c);const g=rr(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(u,h)}else a.position.set(u,h);if(l.type==="extension"){const{energy:d,capacity:f}=fr(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}=fr(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=typeof l.user=="string"?l.user:void 0;if(a.__ctrlUserId!==g){this.container.removeChild(a),Rt(a),this.objects.delete(c);const P=rr(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users,this.activeTheme,this.atlasCache);P.__tileX=l.x,P.__tileY=l.y,this.applyLabelScale(P),this.objects.set(c,P),this.container.addChild(P);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}),zn(a,d,f,p)):a.__ctrlSegGraphics&&Dn(a.__ctrlSegGraphics,_/2,_/2,Nn,st,d,f,p),a.__ctrlLevel=d,a.__ctrlProgress=f,a.__ctrlProgressTotal=p);const S=typeof l.downgradeTime=="number"?l.downgradeTime:void 0;a.__ctrlDowngradeTime!==S&&(a.__ctrlDowngradeTime=S)}if(l.type==="source"){const{energy:d,capacity:f}=Sn(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&&kn(a.__csFillGraphics,_/2,_/2,Cn,d,f,a.__csColor??zr),a.__csProgress=d,a.__csProgressTotal=f)}}else{const u=rr(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users,this.activeTheme,this.atlasCache);u.__tileX=l.x,u.__tileY=l.y,this.applyLabelScale(u),this.objects.set(c,u),this.container.addChild(u)}}for(const[c,l]of this.objects)o.has(c)||(this.container.removeChild(l),Rt(l),this.objects.delete(c),this.rawObjects.delete(c),this.extAnimations.delete(c),this.creepFillAnimations.delete(c),this.towerFillAnimations.delete(c),this.sourceAnimations.delete(c),this.buildGlowAnimations.delete(c),this.ctrlFlashAnimations.delete(c),this.sayBubbles.delete(c));s=!0}this.redrawRamparts(),s&&this.redrawRoads(),this.refreshForeignCreepLabels(),this.refreshForeignCreepBadges()}redrawRoads(){this.roadGraphics.clear();const e=this.roadColor,t=Array.from({length:50},()=>new Array(50).fill(!1)),i=[];for(const l of this.rawObjects.values())l.type==="road"&&(i.push(l),l.x>=0&&l.x<50&&l.y>=0&&l.y<50&&(t[l.x][l.y]=!0));if(i.length===0)return;const n=_/2,s=_/2,o=_*.125;for(const l of i)this.roadGraphics.circle(l.x*_+n,l.y*_+s,o);this.roadGraphics.fill(e);const c=[[1,0],[1,1],[0,1],[-1,1]];for(const l of i){const a=l.x*_+n,u=l.y*_+s;for(const[h,d]of c){const f=l.x+h,p=l.y+d;if(f>=0&&f<50&&p>=0&&p<50&&t[f][p]){const g=f*_+n,S=p*_+s;this.roadGraphics.moveTo(a,u),this.roadGraphics.lineTo(g,S)}}}this.roadGraphics.stroke({width:o*2,color:e})}redrawRamparts(){this.rampartGraphics.clear();const e=_,t=e/2,i=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&&(i[s.x][s.y]=typeof s.user=="string"?s.user:void 0);const n=s=>!s||!this.currentUserId?{color:Cs,alpha:.7}:s===this.currentUserId?{color:Cs,alpha:.7}:{color:7807522,alpha:.5};for(let s=0;s<50;s++)for(let o=0;o<50;o++){const c=i[o][s],l=c!==void 0,a=s>0&&i[o][s-1]!==void 0,u=s<49&&i[o][s+1]!==void 0,h=o>0&&i[o-1][s]!==void 0,d=o<49&&i[o+1][s]!==void 0,f=o*e+t,p=s*e+t;if(l){const g=n(c);!a&&!h&&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&&h&&i[o-1][s-1]!==void 0){const g=n(i[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=n(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&&i[o+1][s-1]!==void 0){const g=n(i[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=n(c);!u&&!h&&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(u&&h&&i[o-1][s+1]!==void 0){const g=n(i[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=n(c);!u&&!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(u&&d&&i[o+1][s+1]!==void 0){const g=n(i[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 i=[];for(const[n,s]of this.objects){const o=this.rawObjects.get(n);o&&o.x===e&&o.y===t&&i.push({id:n,obj:o,visual:s})}return i}applyLabelScale(e){const t=this.lastWorldScale||1;e.__nameLabel&&(e.__nameLabel.scale.set(wn/t),e.__nameLabel.anchor.y===0?e.__nameLabel.y=_/2+_*.55:e.__nameLabel.y=xn-Lo/t),e.__sayBubble&&!e.__sayBubble.destroyed&&(e.__sayBubble.scale.set(1/t),e.__sayBubble.position.set(_/2,xn-qu/t))}refreshForeignCreepLabels(){var e,t;if(this.currentUserId)for(const[i,n]of this.objects){const s=this.rawObjects.get(i);if(!s||s.type!=="creep"||!n.__nameLabel||!Ci(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";n.__nameLabel.text!==c&&(n.__nameLabel.text=c)}}refreshForeignCreepBadges(){var e,t;if(this.currentUserId)for(const[i,n]of this.objects){const s=this.rawObjects.get(i);if(!s||s.type!=="creep"||!Ci(s,this.currentUserId)||n.__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=n.__bodyContainer;if(!l)continue;n.__creepForeignMark&&!n.__creepForeignMark.destroyed&&(l.removeChild(n.__creepForeignMark),n.__creepForeignMark.destroy(),n.__creepForeignMark=void 0);const a=new ze;a.anchor.set(.5,.5);const u=rt*2;a.width=u,a.height=u,a.rotation=Math.PI/2,l.addChild(a),n.__creepBadgeSprite=a,this.badgeCache.getOrCreate(c).then(h=>{a.destroyed||(a.texture=h)}).catch(()=>{a.destroyed||(l.removeChild(a),a.destroy()),n.__creepBadgeSprite=void 0})}}triggerBuildAt(e,t,i){if(!this.instantMode)for(const[n,s]of this.objects){const o=this.rawObjects.get(n);if(!(!o||o.type!=="constructionSite")&&!(o.x!==e||o.y!==t)&&s.__csBuildGlow){this.buildGlowAnimations.set(n,{startTime:performance.now(),duration:i});return}}}triggerSay(e,t){const i=this.objects.get(e);if(!i||i.__sayMessage===t&&i.__sayBubble&&!i.__sayBubble.destroyed)return;i.__sayBubble&&!i.__sayBubble.destroyed&&(i.removeChild(i.__sayBubble),i.__sayBubble.destroy({children:!0}));const n=dh(t);i.addChild(n),i.__sayBubble=n,i.__sayMessage=t,this.applyLabelScale(i),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 i=this.objects.get(t);i!=null&&i.__sayBubble&&!i.__sayBubble.destroyed&&(i.removeChild(i.__sayBubble),i.__sayBubble.destroy({children:!0})),i&&(i.__sayBubble=void 0,i.__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())Ki(t.visual,t.toRadius);this.extAnimations.clear();for(const t of this.creepFillAnimations.values())Zi(t.visual,t.toRadius);this.creepFillAnimations.clear();for(const t of this.towerFillAnimations.values())bi(t.visual,t.toRadius);this.towerFillAnimations.clear();for(const t of this.sourceAnimations.values())qi(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())Rt(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 si=2;function vt(r,e){return{cx:r*_+_/2,cy:e*_+_/2}}class hh{constructor(e){$(this,"container");$(this,"graphics");$(this,"animations",[]);$(this,"ticker",null);$(this,"tickerCallback",null);this.container=new Ne,this.graphics=new re,this.container.addChild(this.graphics),e&&(this.ticker=e,this.tickerCallback=()=>this.animate(),e.add(this.tickerCallback))}addHarvest(e,t,i,n,s){const o=vt(e,t),c=vt(i,n);this.animations.push({fromX:o.cx,fromY:o.cy,toX:c.cx,toY:c.cy,startTime:performance.now(),duration:s,color:_u,width:si})}addUpgradeController(e,t,i,n,s){const o=vt(e,t),c=vt(i,n);this.animations.push({fromX:o.cx,fromY:o.cy,toX:c.cx,toY:c.cy,startTime:performance.now(),duration:s,color:$u,width:si})}addTransfer(e,t,i,n,s){const o=vt(e,t),c=vt(i,n);this.animations.push({fromX:o.cx,fromY:o.cy,toX:c.cx,toY:c.cy,startTime:performance.now(),duration:s,color:Cu,width:si})}addBuild(e,t,i,n,s){const o=vt(e,t),c=vt(i,n);this.animations.push({fromX:o.cx,fromY:o.cy,toX:c.cx,toY:c.cy,startTime:performance.now(),duration:s,color:Su,width:si})}animate(){this.graphics.clear();const e=performance.now();let t=!1;for(let i=this.animations.length-1;i>=0;i--){const n=this.animations[i],s=e-n.startTime,o=Math.min(1,s/n.duration);let c,l,a,u;const h=.5,d=.2;if(o<h){const f=o/h;c=n.fromX,l=n.fromY,a=n.fromX+(n.toX-n.fromX)*f,u=n.fromY+(n.toY-n.fromY)*f}else if(o<h+d)c=n.fromX,l=n.fromY,a=n.toX,u=n.toY;else{const f=(o-h-d)/(1-h-d);c=n.fromX+(n.toX-n.fromX)*f,l=n.fromY+(n.toY-n.fromY)*f,a=n.toX,u=n.toY}this.graphics.moveTo(c,l),this.graphics.lineTo(a,u),this.graphics.stroke({width:n.width,color:n.color}),t=!0,o>=1&&this.animations.splice(i,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 De=r=>(r+.5)*_,Er=4,oi={dashed:[.4*_,.4*_],dotted:[.1*_,.3*_]};function li(r,e,t,i){let n=!0,s=t;for(let o=0;o<e.length-1;o++){const[c,l]=e[o],[a,u]=e[o+1],h=a-c,d=u-l,f=Math.sqrt(h*h+d*d);if(f<.001)continue;const p=h/f,g=d/f;let S=0;for(;S<f;){const P=Math.min(s,f-S);if(n){const z=c+p*S,U=l+g*S;r.moveTo(z,U),r.lineTo(z+p*P,U+g*P)}S+=P,s-=P,s<.001&&(n=!n,s=n?t:i)}}}function fh(r,e,t){const i=Math.max(32,Math.ceil(2*Math.PI*t/2)),n=[];for(let s=0;s<=i;s++){const o=s/i*2*Math.PI;n.push([r+Math.cos(o)*t,e+Math.sin(o)*t])}return n}function ph(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 mh{constructor(){$(this,"container");$(this,"g");this.container=new Ne,this.container.label="visuals",this.g=new re,this.container.addChild(this.g)}update(e){const t=this.container.removeChildren();for(const n of t)n!==this.g&&n.destroy();if(this.g.clear(),this.container.addChild(this.g),!e)return;const i=this.g;for(const n of e.split(`
9
+ `)){if(!n.trim())continue;let s;try{s=JSON.parse(n)}catch{continue}const o=s.s??{},c=o.opacity??1;switch(s.t){case"l":this.drawLine(i,s,o,c);break;case"c":this.drawCircle(i,s,o,c);break;case"r":this.drawRect(i,s,o,c);break;case"p":this.drawPoly(i,s,o,c);break;case"t":this.drawText(s,o,c);break}}}drawLine(e,t,i,n){const s=De(t.x1),o=De(t.y1),c=De(t.x2),l=De(t.y2),a=i.color??"#ffffff",u=(i.width??.1)*_;if(i.lineStyle&&i.lineStyle!=="solid"){const[h,d]=oi[i.lineStyle];li(e,[[s,o],[c,l]],h,d)}else e.moveTo(s,o),e.lineTo(c,l);e.stroke({color:a,width:u,alpha:n})}drawCircle(e,t,i,n){const s=De(t.x),o=De(t.y),c=(i.radius??.5)*_,l=!!(i.fill&&i.fill!=="transparent"),a=!!(i.stroke&&i.strokeWidth),u=i.lineStyle&&i.lineStyle!=="solid";if(l&&(e.circle(s,o,c),e.fill({color:i.fill,alpha:n})),a){const h=i.strokeWidth*_;if(u){const[d,f]=oi[i.lineStyle];li(e,fh(s,o,c),d,f)}else e.circle(s,o,c);e.stroke({color:i.stroke,width:h,alpha:n})}}drawRect(e,t,i,n){const s=De(t.x),o=De(t.y),c=t.w*_,l=t.h*_,a=!!(i.fill&&i.fill!=="transparent"),u=!!(i.stroke&&i.strokeWidth),h=i.lineStyle&&i.lineStyle!=="solid";if(a&&(e.rect(s,o,c,l),e.fill({color:i.fill,alpha:n})),u){const d=i.strokeWidth*_;if(h){const[f,p]=oi[i.lineStyle],g=[[s,o],[s+c,o],[s+c,o+l],[s,o+l],[s,o]];li(e,g,f,p)}else e.rect(s,o,c,l);e.stroke({color:i.stroke,width:d,alpha:n})}}drawPoly(e,t,i,n){if(!t.points||t.points.length===0)return;const s=!!(i.fill&&i.fill!=="transparent"),o=!!(i.stroke&&i.strokeWidth);if(!s&&!o)return;const c=i.lineStyle&&i.lineStyle!=="solid",l=new Array(t.points.length*2);let a;o&&c&&(a=new Array(t.points.length));for(let u=0;u<t.points.length;u++){const[h,d]=t.points[u],f=De(h),p=De(d);l[u*2]=f,l[u*2+1]=p,a&&(a[u]=[f,p])}if(s&&(e.poly(l,!0),e.fill({color:i.fill,alpha:n})),o){const u=i.strokeWidth*_;if(c&&a){const[h,d]=oi[i.lineStyle],f=a[0],p=a[a.length-1],g=f[0]===p[0]&&f[1]===p[1];li(e,g?a:[...a,f],h,d)}else e.poly(l,!0);e.stroke({color:i.stroke,width:u,alpha:n})}}drawText(e,t,i){const n=ph(t.font),s=gh(t.font),o=t.align??"left",c=new Ll({fill:t.color??"#ffffff",fontSize:Math.round(n*_*Er),fontFamily:s,align:o,...t.stroke&&t.strokeWidth?{stroke:{color:t.stroke,width:t.strokeWidth*_*Er}}:{}});if(t.backgroundColor&&t.backgroundColor!=="transparent"){const a=Al.measureText(e.text,c),u=a.width/Er,h=a.height/Er,d=(t.backgroundPadding??.3)*_,f=o==="center"?.5:o==="right"?1:0,p=De(e.x)-f*u-d,g=De(e.y)-h/2-d,S=new re;S.rect(p,g,u+d*2,h+d*2),S.fill({color:t.backgroundColor,alpha:i}),this.container.addChild(S)}const l=new Bt({text:e.text,style:c});l.scale.set(1/Er),l.anchor.x=o==="center"?.5:o==="right"?1:0,l.anchor.y=.5,l.position.set(De(e.x),De(e.y)),l.alpha=i,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 pt(r,e){const t=localStorage.getItem(r),[i,n]=B(t!==null?t==="true":e);return[i,s=>{n(s),localStorage.setItem(r,String(s))}]}function yh(r,e){const t=localStorage.getItem(r),[i,n]=B(t??e);return[i,s=>{n(s),localStorage.setItem(r,s)}]}const[Fo,vh]=pt(ye.widescreenMode,!0),[ki,Ho]=pt(ye.showCreepLabels,!0),[Wo,Uo]=pt(ye.showMapRoomNames,!1),[Yo,Xo]=pt(ye.showUnclaimableRooms,!0),[lr,bh]=pt(ye.terrainEffects,!0),[Gn,wh]=pt(ye.showRoomDecorations,!1),[Bn,xh]=pt(ye.roomDarkOverlay,!0),[jo,_h]=pt(ye.showRoomVisuals,!0),[Fn,$h]=yh(ye.spriteTheme,"default"),[Vo,Sh]=pt(ye.verboseCreepDetails,!1),Ch={id:"default",name:"Default",atlasUrl:"/themes/default/test.json",sprites:{storage:{layers:[{frame:"storage/shell",tint:"owner"},{frame:"storage/fill"}],tileScale:1.75}},controller:{backgroundFrame:"controller/background",segmentFrame:"controller/segment",tileScale:2},flag:{mainFrame:"flag/main",secondFrame:"flag/second",tileScale:3,zIndex:5},tombstone:{shellFrame:"grave/shell",crossFrame:"grave/cross",tileScale:1,zIndex:4}};class kh{constructor(){$(this,"cache",new Map);$(this,"pending",new Map)}getOrLoad(e){const t=this.cache.get(e);if(t)return Promise.resolve(t);const i=this.pending.get(e);if(i)return i;const n=gn.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,n),n}getTexture(e,t){var i,n;return(n=(i=this.cache.get(e))==null?void 0:i.textures)==null?void 0:n[t]}destroy(){for(const[,e]of this.cache)e.destroy(!0);this.cache.clear(),this.pending.clear()}}const Ps=new kh,Hn=Symbol("store-raw"),gr=Symbol("store-node"),ot=Symbol("store-has"),qo=Symbol("store-self");function Zo(r){let e=r[jt];if(!e&&(Object.defineProperty(r,jt,{value:e=new Proxy(r,Eh)}),!Array.isArray(r))){const t=Object.keys(r),i=Object.getOwnPropertyDescriptors(r),n=Object.getPrototypeOf(r),s=n!==null&&r!==null&&typeof r=="object"&&!Array.isArray(r)&&n!==Object.prototype;if(s){const o=Object.getOwnPropertyDescriptors(n);t.push(...Object.keys(o)),Object.assign(i,o)}for(let o=0,c=t.length;o<c;o++){const l=t[o];s&&l==="constructor"||i[l].get&&Object.defineProperty(r,l,{configurable:!0,enumerable:i[l].enumerable,get:i[l].get.bind(e)})}}return e}function Ct(r){let e;return r!=null&&typeof r=="object"&&(r[jt]||!(e=Object.getPrototypeOf(r))||e===Object.prototype||Array.isArray(r))}function yr(r,e=new Set){let t,i,n,s;if(t=r!=null&&r[Hn])return t;if(!Ct(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++)n=r[o],(i=yr(n,e))!==n&&(r[o]=i)}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&&(n=r[s],(i=yr(n,e))!==n&&(r[s]=i))}return r}function Ti(r,e){let t=r[e];return t||Object.defineProperty(r,e,{value:t=Object.create(null)}),t}function Ur(r,e,t){if(r[e])return r[e];const[i,n]=B(t,{equals:!1,internal:!0});return i.$=n,r[e]=i}function Th(r,e){const t=Reflect.getOwnPropertyDescriptor(r,e);return!t||t.get||!t.configurable||e===jt||e===gr||(delete t.value,delete t.writable,t.get=()=>r[jt][e]),t}function Ko(r){pn()&&Ur(Ti(r,gr),qo)()}function Mh(r){return Ko(r),Reflect.ownKeys(r)}const Eh={get(r,e,t){if(e===Hn)return r;if(e===jt)return t;if(e===cs)return Ko(r),t;const i=Ti(r,gr),n=i[e];let s=n?n():r[e];if(e===gr||e===ot||e==="__proto__")return s;if(!n){const o=Object.getOwnPropertyDescriptor(r,e);pn()&&(typeof s!="function"||r.hasOwnProperty(e))&&!(o&&o.get)&&(s=Ur(i,e,s)())}return Ct(s)?Zo(s):s},has(r,e){return e===Hn||e===jt||e===cs||e===gr||e===ot||e==="__proto__"?!0:(pn()&&Ur(Ti(r,ot),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:Mh,getOwnPropertyDescriptor:Th};function Ue(r,e,t,i=!1){if(e==="__proto__"){console.warn('Refusing to set "__proto__" on a store.');return}if(!i&&r[e]===t)return;const n=r[e],s=r.length;t===void 0?(delete r[e],r[ot]&&r[ot][e]&&n!==void 0&&r[ot][e].$()):(r[e]=t,r[ot]&&r[ot][e]&&n===void 0&&r[ot][e].$());let o=Ti(r,gr),c;if((c=Ur(o,e,n))&&c.$(()=>t),Array.isArray(r)&&r.length!==s){for(let l=r.length;l<s;l++)(c=o[l])&&c.$();(c=Ur(o,"length",s))&&c.$(r.length)}(c=o[qo])&&c.$()}function Jo(r,e){const t=Object.keys(e);for(let i=0;i<t.length;i+=1){const n=t[i];Qo(n)||Ue(r,n,e[n])}}function Qo(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function Rh(r,e){if(typeof e=="function"&&(e=e(r)),e=yr(e),Array.isArray(e)){if(r===e)return;let t=0,i=e.length;for(;t<i;t++){const n=e[t];r[t]!==n&&Ue(r,t,n)}Ue(r,"length",i)}else Jo(r,e)}function Ar(r,e,t=[]){let i,n=r;if(e.length>1){i=e.shift();const o=typeof i,c=Array.isArray(r);if(o==="string"&&(i==="__proto__"||e.length>1&&Qo(i))){console.warn(`Refusing to traverse unsafe key "${i}" on a store.`);return}if(Array.isArray(i)){for(let l=0;l<i.length;l++)Ar(r,[i[l]].concat(e),t);return}else if(c&&o==="function"){for(let l=0;l<r.length;l++)i(r[l],l)&&Ar(r,[l].concat(e),t);return}else if(c&&o==="object"){const{from:l=0,to:a=r.length-1,by:u=1}=i;for(let h=l;h<=a;h+=u)Ar(r,[h].concat(e),t);return}else if(e.length>1){Ar(r[i],e,[i].concat(t));return}n=r[i],t=[i].concat(t)}let s=e[0];typeof s=="function"&&(s=s(n,t),s===n)||i===void 0&&s==null||(s=yr(s),i===void 0||Ct(n)&&Ct(s)&&!Array.isArray(s)?Jo(n,s):Ue(r,i,s))}function el(...[r,e]){const t=yr(r||{}),i=Array.isArray(t);if(typeof t!="object"&&typeof t!="function")throw new Error(`Unexpected type ${typeof t} received when initializing 'createStore'. Expected an object.`);const n=Zo(t);Ml.registerGraph({value:t,name:e&&e.name});function s(...o){El(()=>{i&&o.length===1?Rh(t,o[0]):Ar(t,o)})}return[n,s]}const Wn=Symbol("store-root");function Ls(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function ar(r,e,t,i,n){if(Ls(t))return;const s=e[t];if(r===s)return;const o=Array.isArray(r);if(t!==Wn&&(!Ct(r)||!Ct(s)||o!==Array.isArray(s)||n&&r[n]!==s[n])){Ue(e,t,r);return}if(o){if(r.length&&s.length&&(!i||n&&r[0]&&r[0][n]!=null)){let a,u,h,d,f,p,g,S;for(h=0,d=Math.min(s.length,r.length);h<d&&(s[h]===r[h]||n&&s[h]&&r[h]&&s[h][n]&&s[h][n]===r[h][n]);h++)ar(r[h],s,h,i,n);const P=new Array(r.length),z=new Map;for(d=s.length-1,f=r.length-1;d>=h&&f>=h&&(s[d]===r[f]||n&&s[d]&&r[f]&&s[d][n]&&s[d][n]===r[f][n]);d--,f--)P[f]=s[d];if(h>f||h>d){for(u=h;u<=f;u++)Ue(s,u,r[u]);for(;u<r.length;u++)Ue(s,u,P[u]),ar(r[u],s,u,i,n);s.length>r.length&&Ue(s,"length",r.length);return}for(g=new Array(f+1),u=f;u>=h;u--)p=r[u],S=n&&p?p[n]:p,a=z.get(S),g[u]=a===void 0?-1:a,z.set(S,u);for(a=h;a<=d;a++)p=s[a],S=n&&p?p[n]:p,u=z.get(S),u!==void 0&&u!==-1&&(P[u]=s[a],u=g[u],z.set(S,u));for(u=h;u<r.length;u++)u in P?(Ue(s,u,P[u]),ar(r[u],s,u,i,n)):Ue(s,u,r[u])}else for(let a=0,u=r.length;a<u;a++)ar(r[a],s,a,i,n);s.length>r.length&&Ue(s,"length",r.length);return}const c=Object.keys(r);for(let a=0,u=c.length;a<u;a++)Ls(c[a])||ar(r[c[a]],s,c[a],i,n);const l=Object.keys(s);for(let a=0,u=l.length;a<u;a++)r[l[a]]===void 0&&Ue(s,l[a],void 0)}function Oh(r,e={}){const{merge:t,key:i="id"}=e,n=yr(r);return s=>{if(!Ct(s)||!Ct(n))return n;const o=ar(n,{[Wn]:s},Wn,t,i);return o===void 0?s:o}}const os=new WeakMap;function As(r,e){const[t,i]=el(e),n={id:r,type:e.type,raw:t};return os.set(n,s=>i(Oh(s,{key:"_id",merge:!1}))),n}const[vr,br]=B([]);function Ph(){br([])}function Rr(r){br(e=>e.filter(t=>t.id!==r))}function Lh(r,e){const t=vr();let i=!1;const n=[];for(const s of t){const o=r[s.id];if(o===null){i=!0;continue}if(o!==void 0){const c=e[s.id];if(c){const l=os.get(s);l==null||l(c)}}n.push(s)}i&&br(n)}function Ah(r){var n;const e=vr();if(e.length===0)return;let t=!1;const i=[];for(const s of e){const o=r[s.id];if(!o){t=!0;continue}(n=os.get(s))==null||n(o),i.push(s)}t&&br(i)}const[Ih,Ji]=B(null),[Mi,Qi]=B(null),[Be,en]=B(null),[Is,tn]=B(null),[Ei,rn]=B({}),[tl,Ns]=B(null),[mr,Nh]=B(null),[Yr,Dh]=B(null);function Un(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 ct(r){const e=r.match(/^([WE])(\d+)([NS])(\d+)$/);if(!e)return null;const[,t,i,n,s]=e,o=t==="W"?-(parseInt(i,10)+1):parseInt(i,10),c=n==="N"?-(parseInt(s,10)+1):parseInt(s,10);return{x:o,y:c}}function qe(r,e){const t=r<0?"W":"E",i=e<0?"N":"S",n=r<0?-r-1:r,s=e<0?-e-1:e;return`${t}${n}${i}${s}`}function Ds(r){return r===0||r<0&&(r+1)%10===0||r>0&&r%10===0}function q0(r,e){return Ds(r)||Ds(e)}function Z0(r,e){const t=r<0?Math.abs(r+1)%10:Math.abs(r)%10,i=e<0?Math.abs(e+1)%10:Math.abs(e)%10;return t>=4&&t<=6&&i>=4&&i<=6}function rl(r){const e=r;if(!e)return!1;const t=e.tagName??"";return t==="INPUT"||t==="TEXTAREA"?!0:e.isContentEditable===!0}function zh(r){const e=t=>{if(rl(t.target))return;const i=r.currentRoom(),n=i?ct(i):null;if(!n)return;const s=r.worldBounds(),o=(c,l)=>!s||Un(c,l,s);switch(t.key){case"ArrowLeft":t.preventDefault(),o(n.x-1,n.y)&&r.onMove(n.x-1,n.y);break;case"ArrowRight":t.preventDefault(),o(n.x+1,n.y)&&r.onMove(n.x+1,n.y);break;case"ArrowUp":t.preventDefault(),o(n.x,n.y-1)&&r.onMove(n.x,n.y-1);break;case"ArrowDown":t.preventDefault(),o(n.x,n.y+1)&&r.onMove(n.x,n.y+1);break}};window.addEventListener("keydown",e),Ge(()=>window.removeEventListener("keydown",e))}const[be,il]=B(!1),[ht,ls]=B(0),[Yn,Gh]=B(0),[Xr,nl]=B(0),[Gr,jr]=B(!1),[as,Bh]=B(1),[tt,nn]=B(!1);let wi=null;function Vr(){wi!==null&&(clearInterval(wi),wi=null)}function sl(){Vr(),wi=setInterval(()=>{const r=ht()+1;r>Xr()?(Vr(),jr(!1)):ls(r)},Math.max(50,Math.round(1e3/as())))}function ol(r){const e=r,t=Math.max(0,e-2e5);nl(e),Gh(t),ls(r),jr(!1),Vr(),il(!0)}function Ri(){Vr(),jr(!1),il(!1)}function Oi(r){const e=Math.max(Yn(),Math.min(Xr(),r));ls(e)}function zs(r){Oi(ht()+r)}function Fh(){Gr()?(Vr(),jr(!1)):(jr(!0),sl())}function Hh(r){Bh(r),Gr()&&sl()}class Wh{constructor(e,t,i,n){$(this,"chunkCache",new Map);$(this,"inflight",new Map);this.room=e,this.shard=t,this.http=i,this.chunkSize=n}chunkBase(e){return e-e%this.chunkSize}loadChunk(e){const t=this.chunkCache.get(e);if(t)return Promise.resolve(t);const i=this.inflight.get(e);if(i)return i;const n=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,n),n}applyDiff(e,t){const i={...e};for(const n in t){const s=t[n];s===null?delete i[n]:i[n]?i[n]={...i[n],...s}:i[n]=s}return i}async getStateAtTick(e){let t=this.chunkBase(e),i,n;try{i=await this.loadChunk(t)}catch{const c=t-this.chunkSize;if(c<0)throw new Error(`No history data available before tick ${t}`);i=await this.loadChunk(c),t=c;const l=Object.keys(i.ticks).map(Number).filter(u=>u>=t),a=l.length>0?Math.max(...l):t;n=a,e=a}const s=i.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=i.ticks[String(c)];l&&Object.keys(l).length>0&&(o=this.applyDiff(o,l))}return{objects:o,diff:i.ticks[String(e)]??{},gameTime:e,clampedTo:n}}}var Uh=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'),Yh=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'),Xh=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'),jh=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"),Vh=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"),qh=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:Gs,warn:Zh,error:Bs}=Tt("build"),qr={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},Pi={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}},[St,$t]=B("view"),[cr,ll]=B({name:"",color:"COLOR_WHITE",secondaryColor:"COLOR_WHITE"}),[Wt,Xn]=B(null),[Ut,Br]=B(null),[dt,Gt]=B({structureType:"",structureName:""});qn(()=>{he(()=>{const r=dt().structureType;if(!r)return;const e=Be()??0,t=Pi[r];if(!t)return;const i=Vt()==="empty"&&r==="spawn"?Math.max(t[e]??0,1):t[e]??0;if(i===2500)return;(Ei()[r]??0)>=i&&(Gt({structureType:"",structureName:""}),ft())})});function ft(){Xn(null)}function Li(){Br(null)}function al(){Gt({structureType:"",structureName:""})}function Kh(r,e){const t=ge(),i=dt(),n=Wt();if(!t||!i.structureType||!n){Zh("missing requirements",{hasClient:!!t,structureType:i.structureType,pending:n});return}if(Vt()==="empty"&&i.structureType==="spawn"){Gs("placing spawn",{room:r,x:n.tx,y:n.ty,name:i.structureName||void 0,shard:e??void 0}),t.http.game.placeSpawn(r,n.tx,n.ty,i.structureName||void 0,e??void 0).then(()=>(Ce("Spawn placed successfully","success"),ft(),t.stores.user.refreshWorldStatus())).catch(s=>{Bs("place spawn failed:",s),Ce(`Failed to place spawn: ${s.message}`,"error")});return}Gs("creating construction site",{room:r,x:n.tx,y:n.ty,structureType:i.structureType,name:i.structureName||void 0,shard:e??void 0}),t.http.game.createConstruction(r,n.tx,n.ty,i.structureType,i.structureName||void 0,e??void 0).then(()=>{Ce(`Construction site for ${i.structureType} created`,"success"),ft()}).catch(s=>{Bs("create construction failed:",s),Ce(`Failed to create construction site: ${s.message}`,"error")})}function Jh(){$t("view"),ft(),Li(),al()}function Qh(){var r;$t("view"),ft(),((r=de(Ut))==null?void 0:r.type)!=="moveFlag"&&Li(),al()}function Fs(){const r=St(),e=Wt(),t=Ut(),i=Vt();if(i==="empty")return(()=>{var n=Uh(),s=n.firstChild,o=s.nextSibling;return o.$$click=()=>{$t("build"),Gt({structureType:"spawn",structureName:""})},n})();if(i==="lost")return(()=>{var n=Yh(),s=n.firstChild,o=s.nextSibling;return o.$$click=()=>{const c=ge();c&&c.http.user.respawn().then(()=>{Ce("Respawn successful","success"),c.stores.user.refreshWorldStatus()}).catch(l=>{Ce(`Respawn failed: ${l.message}`,"error")})},n})();if((t==null?void 0:t.type)==="moveFlag")return(()=>{var n=Xh(),s=n.firstChild,o=s.firstChild,c=o.nextSibling;return c.nextSibling,s.nextSibling,m(s,()=>t.name,c),m(s,()=>t.targetRoom,null),n})();if(r==="flag")return(()=>{var n=jh(),s=n.firstChild;return s.nextSibling,m(s,e?"Click again to confirm position":"Click to choose flag position"),n})();if(r==="build"){const n=dt(),s=Be(),o=Ei(),c=n.structureType;if(!c)return(()=>{var f=Vh(),p=f.firstChild,g=p.nextSibling;return g.nextSibling,f})();const l=Pi[c],a=(l==null?void 0:l[s??0])??0,u=o[c]??0,h=c.replace(/([A-Z])/g," $1").trim(),d=a===2500?`${u}/∞`:`${u}/${a}`;return(()=>{var f=qh(),p=f.firstChild,g=p.nextSibling;return g.nextSibling,m(p,`Click to build ${h} (${d})`),f})()}return null}Re(["click"]);var ef=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%>"),rf=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">'),nf=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:Ot,error:Or}=Tt("room");function sf(r){const e=y=>y==="default"?Ch:null;let t,i=null,n=null,s=null,o=null,c=null;const[l,a]=B(null),[u,h]=B(null),[d,f]=B(null),[p,g]=B(null),[S,P]=B(""),[z,U]=B(ht());he(()=>U(ht()));let O=null;return Kt(async()=>{if(!t)return;const y=await ts.create(t);a(y)}),Ge(()=>{O!==null&&clearTimeout(O),i==null||i.destroy(),i=null,s==null||s.destroy(),s=null,o==null||o.destroy(),o=null;const y=l();y&&y.destroy()}),he(()=>{const y=ge();if(!y||be())return;const x=r.room,L=r.shard;h(null),f(null),g(null),P(""),pi(null),Ph(),Dh(x),Nh(L),Ji(null),Qi(null),en(null),tn(null),rn({}),Ns(null);const v=new Kn;let C=!1;y.stores.room.terrain(x,L).then(T=>{C||h({room:x,data:T})}).catch(T=>{C||Or(`terrain load failed for ${x}:`,T)}),de(Gn)&&y.http.game.roomDecorations(x,L).then(T=>{C||(Ot(`decorations loaded — ${x}: ${T.decorations.length} item(s)`),f({room:x,decoration:Wu(T)}))}).catch(T=>{}),v.add(y.stores.room.subscribe(x,L)),v.add(y.stores.room.on("room:error",T=>{Ce(`Room subscription error (${T.room}): ${T.message}`,"error",8e3)})),v.add(y.stores.room.on("room:update",T=>{var I,H;let w=0;const M={};let k=0,E=null,D=null;for(const A in T.objects){w++;const G=T.objects[A];if(!G)continue;const V=G.type;if(typeof V=="string")if(V==="constructionSite"){const F=G.structureType;typeof F=="string"&&(M[F]=(M[F]||0)+1)}else M[V]=(M[V]||0)+1;if(V==="controller"&&typeof G.user=="string"){const F=G.user,Z=((H=(I=T.users)==null?void 0:I[F])==null?void 0:H.username)??F;D={userId:F,username:Z},typeof G.level=="number"&&(k=G.level),typeof G.progress=="number"&&(E=G.progress)}}T.diff||Ot(`objects loaded — ${x}: ${w} objects, tick=${T.gameTime}`),g({objects:T.objects,diff:T.diff,users:T.users}),P(T.visual),pi(T.gameTime??null),qa(T.gameTime),Ji(w),Qi(D),en(k||null),tn(E),rn(M),Ns(T.users??null)})),Ge(()=>{C=!0,v.dispose()})}),he(()=>{var M,k;const y=ge();if(!y||!be())return;P("");const x=r.room,L=r.shard,v=xo()??!0,C=((k=(M=es())==null?void 0:M.serverData)==null?void 0:k.historyChunkSize)??(v?20:100),T=de(tl)??void 0,w=new Wh(x,L,y.http,C);he(()=>{const E=ht();let D=!1;nn(!0),w.getStateAtTick(E).then(I=>{var Z;if(D)return;if(nn(!1),I.clampedTo!==void 0){nl(I.clampedTo),Oi(I.clampedTo);return}g({objects:I.objects,diff:void 0,users:T}),pi(I.gameTime);let H=0;const A={};let G=0,V=null,F=null;for(const j in I.objects){H++;const W=I.objects[j];if(!W)continue;const J=W.type;if(typeof J=="string")if(J==="constructionSite"){const ue=W.structureType;typeof ue=="string"&&(A[ue]=(A[ue]||0)+1)}else A[J]=(A[J]||0)+1;if(J==="controller"&&typeof W.user=="string"){const ue=W.user,ae=((Z=T==null?void 0:T[ue])==null?void 0:Z.username)??ue;F={userId:ue,username:ae},typeof W.level=="number"&&(G=W.level),typeof W.progress=="number"&&(V=W.progress)}}Ji(H),Qi(F),en(G||null),tn(V),rn(A)}).catch(I=>{D||(nn(!1),Ce(`History load failed for tick ${E}: ${I.message}`,"error",5e3))}),Ge(()=>{D=!0})})}),he(()=>{const y=l();if(!y)return;r.room,r.shard,Qh(),y.hoverLayer.clearPendingTile();const x=de(Ut);(x==null?void 0:x.type)==="moveFlag"?Br({...x,targetRoom:r.room}):y.resetView(),c==null||c.destroy(),c=null,y.clear(),y.resetView(),i==null||i.destroy(),i=null,s==null||s.destroy(),s=null,o==null||o.destroy(),o=null;const L=de(u);if(L&&L.room===r.room){Ot(`terrain applied immediately (pre-loaded) — ${r.room}`);const k=de(d);c=ii(L.data,y.app.renderer,(k==null?void 0:k.room)===r.room?k.decoration.terrain:void 0),Tr(c,de(lr)),c.zIndex=_t.terrain,y.world.addChild(c),y.bringNavOverlayToTop()}const v=r.room,C=r.shard,T=ct(v),w=de(()=>r.onNavigate),M=de(Yi);if(T&&w){const k=(D,I)=>!M||Un(D,I,M),E=D=>{w(D,C)};y.setupNavigationZones({west:k(T.x-1,T.y)?()=>E(qe(T.x-1,T.y)):void 0,east:k(T.x+1,T.y)?()=>E(qe(T.x+1,T.y)):void 0,north:k(T.x,T.y-1)?()=>E(qe(T.x,T.y-1)):void 0,south:k(T.x,T.y+1)?()=>E(qe(T.x,T.y+1)):void 0})}}),he(()=>{const y=l();if(!y)return;const x=de(()=>r.room),L=de(()=>r.shard),v=ct(x);if(v&&r.onNavigate){const C=r.onNavigate,T=Yi(),w=(k,E)=>!T||Un(k,E,T),M=k=>{C(k,L)};zh({currentRoom:()=>r.room,worldBounds:Yi,onMove:(k,E)=>M(qe(k,E))}),y.setupNavigationZones({west:w(v.x-1,v.y)?()=>M(qe(v.x-1,v.y)):void 0,east:w(v.x+1,v.y)?()=>M(qe(v.x+1,v.y)):void 0,north:w(v.x,v.y-1)?()=>M(qe(v.x,v.y-1)):void 0,south:w(v.x,v.y+1)?()=>M(qe(v.x,v.y+1)):void 0})}}),he(()=>{const y=St(),x=l();y==="view"&&x&&(ft(),x.hoverLayer.clearPendingTile())}),he(()=>{const y=l(),x=Wt();y&&(x?y.hoverLayer.setPendingTile(x.tx,x.ty):y.hoverLayer.clearPendingTile())}),he(()=>{const y=l(),x=u();if(!y||!x||x.room!==r.room)return;if(c!=null&&c.parent){Ot(`terrain already in scene, skipping — ${r.room}`);return}Ot(`terrain applied (async) — ${r.room}`);const L=de(d);c=ii(x.data,y.app.renderer,(L==null?void 0:L.room)===r.room?L.decoration.terrain:void 0),Tr(c,de(lr)),y.world.addChildAt(c,0),y.bringNavOverlayToTop()}),he(()=>{if(Gn())return;f(null);const y=de(l),x=de(u);!y||!x||x.room!==r.room||c!=null&&c.parent&&(c.destroy(),c=ii(x.data,y.app.renderer),Tr(c,de(lr)),y.world.addChildAt(c,0),y.bringNavOverlayToTop(),i==null||i.setRoadColor(is))}),he(()=>{const y=l(),x=d(),L=de(u);!y||!x||x.room!==r.room||!L||L.room!==r.room||c!=null&&c.parent&&(Ot(`decoration arrived, rebuilding terrain layer — ${r.room}`),c.destroy(),c=ii(L.data,y.app.renderer,x.decoration.terrain),Tr(c,de(lr)),y.world.addChildAt(c,0),y.bringNavOverlayToTop(),i&&x.decoration.roadColor!=null&&i.setRoadColor(x.decoration.roadColor))}),he(()=>{var E,D;const y=l(),x=p();if(!y)return;if(!x){i==null||i.clear(),s==null||s.clear(),y.clearLighting();return}const{objects:L,diff:v,users:C}=x;if(!i){Ot(`object layer created — ${r.room}`),i=new uh(y.app.ticker,ki(),(E=We())==null?void 0:E._id,(D=We())==null?void 0:D.badge,C),i.setTheme(e(de(Fn)),Ps),i.setInstantMode(de(be));const I=de(d);(I==null?void 0:I.room)===r.room&&I.decoration.roadColor!=null&&i.setRoadColor(I.decoration.roadColor),i.container.label="objects",i.container.zIndex=_t.objects,y.world.addChild(i.container),s=new hh(y.app.ticker),s.container.label="animations",s.container.zIndex=_t.animations,y.world.addChild(s.container),o=new mh,o.container.zIndex=_t.visuals,y.world.addChild(o.container),y.setTileHandlers((H,A)=>{},(H,A,G)=>{const V=r.room,F=r.shard,Z=St(),j=Ut();if((j==null?void 0:j.type)==="moveFlag"){const ae=ge();if(!ae)return;const{name:se,room:me,color:ee,secondaryColor:fe,targetRoom:Ee}=j;ae.http.game.removeFlag(me,se).then(()=>ae.http.game.createFlag(Ee,H,A,se,ee,fe,F??void 0)).then(()=>{Ce(`Flag "${se}" moved`,"success"),Li()}).catch(Oe=>{Or("move flag failed:",Oe),Ce(`Failed to move flag "${se}"`,"error"),Li()});return}if(Z==="flag"){const ae=Wt();if(!ae||ae.tx!==H||ae.ty!==A){Xn({tx:H,ty:A}),y.hoverLayer.setPendingTile(H,A);return}const se=ge();if(!se)return;const me=cr(),ee=me.name.trim();if(!ee){Ce("Flag name is required","error");return}const fe=qr[me.color]??0,Ee=qr[me.secondaryColor]??0;se.http.game.createFlag(V,H,A,ee,fe,Ee,F??void 0).then(()=>{Ce(`Flag "${ee}" created`,"success"),ft(),y.hoverLayer.clearPendingTile(),se.http.game.genUniqueFlagName().then(Oe=>ll(je=>({...je,name:Oe.name}))).catch(Oe=>Or("gen unique flag name failed:",Oe))}).catch(Oe=>Or("create flag failed:",Oe));return}if(Z==="build"){if(!G&&!dt().structureType){Ce("Select a structure type first","error");return}if(G){if(!i)return;const se=i.getObjectsAtTile(H,A).filter(({obj:ee})=>ee.type==="constructionSite");if(se.length===0){Ce("No construction sites on this tile","error");return}const me=ge();if(!me)return;me.http.game.removeConstructionSite(V,se.map(({id:ee})=>ee),F??void 0).then(()=>{Ce(`Removed ${se.length} construction site${se.length>1?"s":""}`,"success"),ft(),y.hoverLayer.clearPendingTile()}).catch(ee=>{Or("remove construction sites failed:",ee),Ce(`Failed to remove construction sites: ${ee.message}`,"error")});return}Xn({tx:H,ty:A}),y.hoverLayer.setPendingTile(H,A),Kh(V,F);return}if(ft(),y.hoverLayer.clearPendingTile(),!i)return;const W=i.getObjectsAtTile(H,A);if(W.length===0){G||(br([]),y.hoverLayer.clearSelection());return}let J=[...vr()];if(G){const ae=new Set(W.map(me=>me.id));if(J.some(me=>ae.has(me.id)))J=J.filter(me=>!ae.has(me.id));else{const me=W.filter(({id:ee})=>!J.some(fe=>fe.id===ee)).map(({id:ee,obj:fe})=>As(ee,fe));J=[...J,...me]}}else J=W.map(({id:ae,obj:se})=>As(ae,se));br(J);const ue=J.map(({id:ae,type:se})=>({id:ae,type:se,visual:i.getVisualById(ae)})).filter(ae=>ae.visual!=null);y.hoverLayer.setSelectedObjects(ue)},()=>{var A;const H=St();(H==="build"||H==="flag"||((A=Ut())==null?void 0:A.type)==="moveFlag")&&(Jh(),y.hoverLayer.clearPendingTile())})}v?Lh(v,L):Ah(L);const T=be()?Math.round(1e3/de(as)):xi()??2e3,w=T*.6,M=Math.round(T*.9);i.setMoveDuration(M),n={objects:L,users:C},i.update(L,v,C,Fe()??void 0),i.setShowLabels(de(ki));const k=new Set;if(s){s.clear();for(const I in L){const H=L[I];if(!H||H.type!=="creep")continue;const A=H.actionLog;if(!A)continue;const G=A.harvest;G&&s.addHarvest(G.x,G.y,H.x,H.y,w);const V=A.upgradeController;V&&s.addUpgradeController(H.x,H.y,V.x,V.y,w);const F=A.build;F&&(s.addBuild(H.x,H.y,F.x,F.y,w),i==null||i.triggerBuildAt(F.x,F.y,w));const Z=A.transfer;Z&&s.addTransfer(H.x,H.y,Z.x,Z.y,w);const j=A.say;j&&typeof j.message=="string"&&j.message.length>0&&(i==null||i.triggerSay(I,j.message),k.add(I))}}i.pruneSayBubblesExcept(k),de(Bn)&&y.updateLighting(L)}),he(()=>{const y=S();o==null||o.update(jo()?y:"")}),he(()=>{i==null||i.setInstantMode(be())}),he(()=>{const y=lr();c&&Tr(c,y)}),he(()=>{const y=l();if(!y)return;const x=Bn();y.darkOverlay.visible=x,y.lightLayer.visible=x,x||y.clearLighting()}),he(()=>{const y=e(Fn());i&&(i.setTheme(y,Ps),n&&(i.clear(),i.update(n.objects,void 0,n.users)))}),(()=>{var y=tf(),x=y.firstChild;return dr(L=>t=L,x),m(y,(()=>{var L=te(()=>!!Fs());return()=>L()&&(()=>{var v=rf();return m(v,Fs),N(C=>X(v,"pointer-events",Vt()==="empty"||Vt()==="lost"?"auto":"none")),v})()})(),null),m(y,(()=>{var L=te(()=>!be()&&Fe()!==null);return()=>L()&&(()=>{var v=nf();return v.firstChild,m(v,Fe,null),v})()})(),null),m(y,b(q,{get when(){return be()},get children(){var L=ef(),v=L.firstChild,C=v.nextSibling,T=C.firstChild,w=T.nextSibling,M=w.nextSibling;return v.$$input=k=>{const E=parseInt(k.currentTarget.value,10);U(E),O!==null&&clearTimeout(O),O=setTimeout(()=>{O=null,Oi(E)},150)},m(T,Yn),m(w,(()=>{var k=te(()=>!!tt());return()=>k()?"Loading…":`Tick ${ht()}`})()),m(M,Xr),N(k=>{var E=Yn(),D=Xr(),I=tt()?"#f0883e":"#8b949e";return E!==k.e&&_e(v,"min",k.e=E),D!==k.t&&_e(v,"max",k.t=D),I!==k.a&&X(w,"color",k.a=I),k},{e:void 0,t:void 0,a:void 0}),N(()=>v.value=z()),L}}),null),y})()}Re(["input"]);var of=R("<div style=position:fixed;bottom:16px;right:16px;display:flex;flex-direction:column;gap:8px;z-index:9999;pointer-events:none>"),lf=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 af(){return(()=>{var r=of();return m(r,b($e,{get each(){return Ga()},children:e=>(()=>{var t=lf();return m(t,()=>e.message),N(i=>X(t,"background",e.type==="error"?"#da3633":"#238636")),t})()})),r})()}const[bt,cf]=B(!0),[nt,cl]=B(!0),[ir,dl]=B(!1),[sn,It]=B("");let Nt;function df(r){Nt=r}function uf(r){It(r),cl(!0),requestAnimationFrame(()=>{Nt==null||Nt.focus();const e=r.length;Nt==null||Nt.setSelectionRange(e,e)})}function ul(){cf(r=>!r)}function hl(){cl(r=>!r)}function fl(){dl(r=>!r)}const[wr,pl]=B(go(ye.memoryWatches,[])),[Zr,gl]=B(null),[jn,hf]=el({});function ff(r){const e=r.trim();e&&(pl(t=>t.includes(e)?t:[...t,e]),Qn(ye.memoryWatches,wr()))}function pf(r){pl(e=>e.filter(t=>t!==r)),Qn(ye.memoryWatches,wr())}function ml(){gl(null)}function gf(r,e){gl({creepId:r,name:e})}function mf(r,e){const t=[...e];if(r){const i=`creeps.${r.name}`;t.includes(i)||t.push(i)}return t}function yf(r){const e=new Map,t=()=>{const s=ge();if(!s)return;const o=new Set(mf(Zr(),wr()));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))};he(()=>{wr(),Zr(),t()});const i=ge();let n=null;return i?n=i.stores.user.on("user:memory",s=>{console.log("[memoryStore] user:memory received",s.path,s.value),hf(s.path,s.value),console.log("[memoryStore] memoryValues after set:",JSON.stringify(jn))}):console.warn("[memoryStore] no client available when initMemorySubscriptions called"),Ge(()=>{for(const s of e.values())s.dispose();e.clear(),n==null||n.dispose()}),t(),()=>{for(const s of e.values())s.dispose();e.clear(),n==null||n.dispose()}}qn(()=>{he(()=>{const r=Zr();if(!r)return;vr().some(t=>t.id===r.creepId)||ml()})});var vf=R("<button style=color:#8b949e>"),bf=R("<span style=width:18px;flex-shrink:0>"),wf=R("<span style=color:#484f58;font-style:italic>{…}"),xf=R("<span style=color:#484f58;font-style:italic>"),_f=R("<button title=Reload>"),$f=R('<span title="Click to edit"style=cursor:text;flex:1>'),Sf=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">'),Cf=R("<button title=Save style=color:#3fb950>"),kf=R("<button title=Discard style=color:#f85149>"),Tf=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:Hs}=Tt("MemoryTree");function et(r){return r!==null&&typeof r=="object"&&"__screeps_object__"in r}const Mf={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"},Pr={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 ai(r){return r.replace(/^Memory\.?/,"")}function yl(r){const[e,t]=B((r.depth??0)<2),i=()=>r.depth??0,[n,s]=B(!1),[o,c]=B(""),[l,a]=B(!1),[u,h]=B(void 0),d=()=>et(r.value)&&u()!==void 0?u():r.value,f=()=>{const x=d();return!et(x)&&x!==null&&typeof x=="object"},p=()=>f()?Object.entries(d()):[],g=()=>p().length,S=async()=>{a(!0);try{const x=ge();if(!x)return;const L=ai(r.path),v=await x.http.user.memory.get(L,r.shard),C=v.data==="[object Object]"?{__screeps_object__:!0}:v.data;h(C)}catch(x){Hs("fetch memory failed",x)}finally{a(!1)}},P=()=>{h(void 0),S()};Kt(()=>{e()&&et(r.value)&&u()===void 0&&S()});const z=async()=>{if(et(r.value)&&u()===void 0){await S(),t(!0);return}e()&&h(void 0),t(x=>!x)},U=async()=>{var T;const x=o().trim();let L;if(x==="null")L=null;else if(x==="true")L=!0;else if(x==="false")L=!1;else{const w=Number(x);if(!Number.isNaN(w)&&x!=="")L=w;else try{L=JSON.parse(x)}catch{L=x}}const v=ge();if(!v)return;const C=ai(r.path);try{await v.http.user.memory.set(C,L,r.shard)}catch(w){Hs("set memory failed",w),s(!1);return}s(!1),(T=r.onRefresh)==null||T.call(r)},O=()=>{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=Tf(),L=x.firstChild,v=L.firstChild,C=v.nextSibling,T=C.nextSibling;return m(L,b(q,{get when(){return f()||et(d())},get children(){var w=vf();return w.$$click=()=>void z(),m(w,b(q,{get when(){return l()},get children(){return b(Gc,{size:12,style:{animation:"spin 1s linear infinite"}})}}),null),m(w,b(q,{get when(){return!l()},get children(){return b(q,{get when(){return e()},get fallback(){return b($o,{size:12})},get children(){return b(gc,{size:12})}})}}),null),N(M=>{var k={...Pr},E=e()?"Collapse":"Expand",D=l();return M.e=Q(w,k,M.e),E!==M.t&&_e(w,"title",M.t=E),D!==M.a&&(w.disabled=M.a=D),M},{e:void 0,t:void 0,a:void 0}),w}}),v),m(L,b(q,{get when(){return te(()=>!f())()&&!et(d())},get children(){return bf()}}),v),m(v,()=>r.label),m(L,b(q,{get when(){return et(d())},get children(){return wf()}}),T),m(L,b(q,{get when(){return f()},get children(){var w=xf();return m(w,(()=>{var M=te(()=>!!Array.isArray(d()));return()=>M()?`[${g()}]`:`{${g()}}`})()),w}}),T),m(L,b(q,{get when(){return te(()=>!!et(r.value))()&&!l()},get children(){var w=_f();return w.$$click=()=>P(),m(w,b(cd,{size:11})),N(M=>Q(w,Pr,M)),w}}),T),m(L,b(q,{get when(){return te(()=>!f())()&&!et(d())},get children(){return[b(q,{get when(){return!n()},get children(){var w=$f();return w.$$click=()=>{c(y()),s(!0)},m(w,y),N(M=>X(w,"color",O())),w}}),b(q,{get when(){return n()},get children(){return[(()=>{var w=Sf();return w.$$keydown=M=>{M.key==="Enter"&&U(),M.key==="Escape"&&s(!1)},w.$$input=M=>c(M.currentTarget.value),N(()=>w.value=o()),w})(),(()=>{var w=Cf();return w.$$mousedown=M=>{M.preventDefault(),U()},m(w,b(_o,{size:12})),N(M=>Q(w,{...Pr},M)),w})(),(()=>{var w=kf();return w.$$mousedown=M=>{M.preventDefault(),s(!1)},m(w,b(qt,{size:12})),N(M=>Q(w,{...Pr},M)),w})()]}})]}}),T),T.$$click=()=>uf(`Memory.${ai(r.path)} = `),m(T,b(gd,{size:11})),m(x,b(q,{get when(){return te(()=>!!f())()&&e()},get children(){return b($e,{get each(){return p()},children:([w,M])=>{const k=Array.isArray(d())?`${r.path}[${w}]`:`${r.path}.${w}`;return b(yl,{value:M,path:k,label:w,get shard(){return r.shard},get depth(){return i()+1},get onRefresh(){return te(()=>!!et(r.value))()?P:r.onRefresh}})}})}}),null),N(w=>{var M={"padding-left":i()>0?"14px":"0",...Mf},k=Pr,E=`Insert Memory.${ai(r.path)} = into console`;return w.e=Q(x,M,w.e),w.t=Q(T,k,w.t),E!==w.a&&_e(T,"title",w.a=E),w},{e:void 0,t:void 0,a:void 0}),x})()}function Ws(r){return b(yl,{get value(){return r.value},get path(){return r.path},get label(){return r.label},get shard(){return r.shard},depth:0})}Re(["click","input","keydown","mousedown"]);var Ef=R("<div style=color:#484f58;font-style:italic>No paths watched — add one below."),Rf=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'),Of=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">'),Pf=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">'),Lf=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>'),Us=R("<div style=width:4px;flex-shrink:0;cursor:col-resize>"),Af=R('<div style=flex-shrink:0;display:flex;flex-direction:column;overflow:hidden><div class=console-scroll style=flex:1;overflow:auto;padding:8px></div><form style="display:flex;gap:6px;padding:8px;border-top:1px solid #30363d"><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'),If=R("<div style=flex:1;display:flex;overflow:hidden>"),Nf=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
+ `),Df=R("<div style=color:#484f58;font-style:italic>No log output yet…"),zf=R("<div style=margin-bottom:4px;color:#f85149;white-space:pre-wrap;word-break:break-word>"),Gf=R("<div style=margin-bottom:4px;color:#c9d1d9;white-space:pre-wrap;word-break:break-word>"),Bf=R("<div style=color:#484f58;font-style:italic>No command results yet…"),Ff=R("<div style=margin-bottom:4px;color:#58a6ff;white-space:pre-wrap;word-break:break-word>");const{error:Hf}=Tt("console");function Wf(r){const[e,t]=B(""),i=()=>r.shard??mr();Kt(()=>{yf(i())});const n={"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=Rf(),c=o.firstChild,l=c.nextSibling,a=l.firstChild,u=a.nextSibling,h=u.firstChild;return m(c,b(q,{get when(){return Zr()},children:d=>{const f=`creeps.${d().name}`;return(()=>{var p=Of(),g=p.firstChild,S=g.firstChild,P=S.nextSibling,z=P.nextSibling;return m(S,f),lt(z,"click",ml,!0),m(z,b(qt,{size:12})),m(p,b(Ws,{get value(){return jn[f]},path:`Memory.${f}`,label:f,get shard(){return i()}}),null),N(U=>Q(z,s,U)),p})()}}),null),m(c,b($e,{get each(){return wr()},children:d=>(()=>{var f=Pf(),p=f.firstChild,g=p.firstChild,S=g.nextSibling;return m(g,d),S.$$click=()=>pf(d),m(S,b(qt,{size:12})),m(f,b(Ws,{get value(){return jn[d]},path:`Memory.${d}`,label:d,get shard(){return i()}}),null),N(P=>Q(S,s,P)),f})()}),null),m(c,b(q,{get when(){return te(()=>wr().length===0)()&&!Zr()},get children(){return Ef()}}),null),l.addEventListener("submit",d=>{d.preventDefault(),ff(e()),t("")}),a.$$input=d=>t(d.currentTarget.value),m(u,b(od,{size:14}),h),N(d=>{var f=`${r.width*100}%`,p={...n};return f!==d.e&&X(o,"width",d.e=f),d.t=Q(c,p,d.t),d},{e:void 0,t:void 0}),N(()=>a.value=e()),o})()}function Uf(r){const[e,t]=B([]),[i,n]=B(!0),s=[1,1,1],[o,c]=B(go(ye.consoleWeights,[...s])),[l,a]=B(null);let u,h,d,f=0;Kt(()=>{const A=ge();if(!A)return;const G=new Kn;G.add(A.stores.user.subscribe("console")),G.add(A.stores.user.on("user:console",V=>{const F=V.messages,Z={id:f++,log:F.log??[],results:F.results??[],error:F.error??[]};t(j=>{const W=[...j,Z];return W.length>200?W.slice(W.length-200):W})})),Ge(()=>G.dispose())}),he(()=>{e(),i()&&requestAnimationFrame(()=>{bt()&&u&&(u.scrollTop=u.scrollHeight),nt()&&h&&(h.scrollTop=h.scrollHeight)})});const p=(A,G,V)=>{var Z,j;const F=!A&&!G&&!V;F&&!r.isCollapsed&&((Z=r.onToggle)==null||Z.call(r)),!F&&r.isCollapsed&&((j=r.onToggle)==null||j.call(r))};he(()=>{p(bt(),nt(),ir())});const g=()=>{const A=o(),G=[bt(),nt(),ir()],V=G.filter(Boolean).length;if(V===0)return[0,0,0];if(V===1){const j=G.findIndex(Boolean);return[0,0,0].map((W,J)=>J===j?1:0)}const Z=G.map((j,W)=>j?A[W]:0).reduce((j,W)=>j+W,0);if(Z===0){const j=1/V;return[0,0,0].map((W,J)=>G[J]?j:0)}return G.map((j,W)=>j?A[W]/Z:0)};he(()=>{Qn(ye.consoleWeights,o())});const S=A=>G=>{G.preventDefault(),G.stopPropagation(),a(A),document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("pointermove",P),window.addEventListener("pointerup",z,{once:!0})},P=A=>{const G=l();if(G===null)return;const V=d;if(!V)return;const F=V.getBoundingClientRect(),Z=Math.max(.02,Math.min(.98,(A.clientX-F.left)/F.width)),j=[...o()],W=[bt(),nt(),ir()];if(G===0){const J=W[0],ue=W[1];if(!J||!ue)return;const ae=Z/(1-Z);j[0]=ae,j[1]=1,c(j)}else{const J=W[1],ue=W[2];if(!J||!ue)return;const ae=Z/(1-Z);j[1]=ae,j[2]=1,c(j)}},z=()=>{a(null),document.body.style.cursor="",document.body.style.userSelect="",window.removeEventListener("pointermove",P)},[U,O]=B([]),[y,x]=B(null),[L,v]=B(""),C=A=>{const G=U();if(G.length!==0){if(A.key==="ArrowUp"){A.preventDefault();const V=y();V===null?(v(sn()),x(G.length-1),It(G[G.length-1])):V>0&&(x(V-1),It(G[V-1]))}else if(A.key==="ArrowDown"){A.preventDefault();const V=y();if(V===null)return;V<G.length-1?(x(V+1),It(G[V+1])):(x(null),It(L()))}}},T=async A=>{A.preventDefault();const G=ge(),V=sn().trim();if(!(!G||!V))try{await G.http.user.console(V,r.shard??"shard0"),O(F=>[...F,V]),x(null),v(""),It("")}catch(F){Hf("command failed:",F)}},w=A=>({background:A?"#30363d":"transparent",border:`1px solid ${A?"#58a6ff":"transparent"}`,color:A?"#c9d1d9":"#8b949e","font-size":"12px",cursor:"pointer",padding:"2px 10px","border-radius":"4px"}),M=()=>e().flatMap(A=>A.log),k=()=>e().flatMap(A=>A.error),E=()=>e().flatMap(A=>A.results),D={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"},I={background:"transparent",border:"none",color:"#8b949e",cursor:"pointer",padding:"4px","border-radius":"4px",display:"flex","align-items":"center","justify-content":"center"},H=()=>{n(!0),requestAnimationFrame(()=>{bt()&&u&&(u.scrollTop=u.scrollHeight),nt()&&h&&(h.scrollTop=h.scrollHeight)})};return(()=>{var A=Nf(),G=A.firstChild,V=G.firstChild,F=V.nextSibling,Z=F.nextSibling;return G.nextSibling,lt(V,"click",ul,!0),lt(F,"click",hl,!0),lt(Z,"click",fl,!0),m(A,b(q,{get when(){return!r.isCollapsed},get children(){var j=If();return dr(W=>d=W,j),m(j,b(q,{get when(){return bt()},get children(){var W=Lf(),J=W.firstChild,ue=J.firstChild,ae=ue.nextSibling,se=J.nextSibling;ue.$$click=()=>i()?n(!1):H(),m(ue,(()=>{var ee=te(()=>!!i());return()=>ee()?b(ed,{size:16}):b(id,{size:16})})()),ae.$$click=()=>t([]),m(ae,b(mi,{size:16})),se.addEventListener("scroll",()=>{u&&n(u.scrollHeight-u.scrollTop-u.clientHeight<20)});var me=u;return typeof me=="function"?dr(me,se):u=se,m(se,(()=>{var ee=te(()=>M().length===0&&k().length===0);return()=>ee()&&Df()})(),null),m(se,b($e,{get each(){return k()},children:ee=>(()=>{var fe=zf();return fe.innerHTML=ee,fe})()}),null),m(se,b($e,{get each(){return M()},children:ee=>(()=>{var fe=Gf();return fe.innerHTML=ee,fe})()}),null),N(ee=>{var fe=`${g()[0]*100}%`,Ee=i()?"Pause scrolling":"Resume scrolling",Oe=I,je=I,Ke={...D};return fe!==ee.e&&X(W,"width",ee.e=fe),Ee!==ee.t&&_e(ue,"title",ee.t=Ee),ee.a=Q(ue,Oe,ee.a),ee.o=Q(ae,je,ee.o),ee.i=Q(se,Ke,ee.i),ee},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),W}}),null),m(j,b(q,{get when(){return te(()=>!!bt())()&&nt()},get children(){var W=Us();return lt(W,"pointerdown",S(0),!0),N(J=>X(W,"background",l()===0?"#388bfd":"#21262d")),W}}),null),m(j,b(q,{get when(){return nt()},get children(){var W=Af(),J=W.firstChild,ue=J.nextSibling,ae=ue.firstChild,se=ae.nextSibling;se.nextSibling,J.addEventListener("scroll",()=>{h&&n(h.scrollHeight-h.scrollTop-h.clientHeight<20)});var me=h;return typeof me=="function"?dr(me,J):h=J,m(J,(()=>{var ee=te(()=>E().length===0);return()=>ee()&&Bf()})(),null),m(J,b($e,{get each(){return E()},children:ee=>(()=>{var fe=Ff();return fe.innerHTML=ee,fe})()}),null),ue.addEventListener("submit",T),se.$$keydown=C,se.$$input=ee=>{x(null),It(ee.currentTarget.value)},dr(ee=>df(ee),se),N(ee=>{var fe=`${g()[1]*100}%`,Ee={...D};return fe!==ee.e&&X(W,"width",ee.e=fe),ee.t=Q(J,Ee,ee.t),ee},{e:void 0,t:void 0}),N(()=>se.value=sn()),W}}),null),m(j,b(q,{get when(){return te(()=>!!nt())()&&ir()},get children(){var W=Us();return lt(W,"pointerdown",S(1),!0),N(J=>X(W,"background",l()===1?"#388bfd":"#21262d")),W}}),null),m(j,b(q,{get when(){return ir()},get children(){return b(Wf,{get shard(){return r.shard??null},get width(){return g()[2]}})}}),null),N(W=>X(j,"user-select",l()!==null?"none":"auto")),j}}),null),N(j=>{var W=w(bt()),J=w(nt()),ue=w(ir());return j.e=Q(V,W,j.e),j.t=Q(F,J,j.t),j.a=Q(Z,ue,j.a),j},{e:void 0,t:void 0,a:void 0}),A})()}Re(["input","click","pointerdown","keydown"]);var Yf=R("<div style=display:flex;gap:5px;flex-wrap:wrap>"),Xf=R("<div style=width:18px;height:18px;border-radius:50%;cursor:pointer;flex-shrink:0>");const jf=[{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 Ai(r){return(()=>{var e=Yf();return m(e,b($e,{each:jf,children:t=>(()=>{var i=Xf();return i.$$click=()=>r.onChange(t.value),N(n=>{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!==n.e&&_e(i,"title",n.e=s),o!==n.t&&X(i,"background",n.t=o),c!==n.a&&X(i,"box-shadow",n.a=c),n},{e:void 0,t:void 0,a:void 0}),i})()})),e})()}Re(["click"]);var Yt=R("<div>"),Ii=R("<div style=font-variant-numeric:tabular-nums>"),Vf=R("<span style=font-variant-numeric:tabular-nums;font-weight:400> / "),qf=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">'),Zf=R('<div style="padding:3px 8px;background:#0d1117;color:#8b949e">'),Kf=R('<div style="padding:3px 8px;background:#0d1117;color:#c9d1d9;font-variant-numeric:tabular-nums">'),Jf=R("<div>Owner"),vl=R("<div>Hits"),bl=R("<div style=font-variant-numeric:tabular-nums> / "),Qf=R("<div>Time to live"),ep=R("<div>Fatigue"),tp=R('<div style="display:flex;flex-wrap:wrap;gap:2px 10px;padding:0 8px 8px;background:#0d1117">'),rp=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>'),ip=R("<div><div>"),np=R("<div style=width:11px;height:11px;border-radius:50%;flex-shrink:0>"),sp=R("<span style=font-size:10px;font-variant-numeric:tabular-nums><span style=color:#8b949e>×</span><span>"),op=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">'),lp=R("<div style=padding:8px;display:flex;flex-direction:column;gap:8px;background:#0d1117><label>Primary color</label><label>Secondary color"),ap=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'),cp=R("<div>Level"),dp=R("<div>Safe modes"),up=R("<div>Power"),hp=R("<div>Downgrade in"),fp=R("<div>Safe mode active"),pp=R("<div style=font-variant-numeric:tabular-nums> ticks"),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>'),mp=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">'),yp=R("<div><div><div>Owner</div><div>"),vp=R("<div>Reserved"),bp=R("<div> (<!>)"),wp=R("<div>Notify when attacked"),xp=R("<div style=display:flex;align-items:center><button style=background:transparent;border:none;cursor:pointer;padding:0;display:flex;align-items:center>"),_p=R("<div><div>Energy</div><div style=font-variant-numeric:tabular-nums> / "),$p=R("<div><div>Hits</div><div style=font-variant-numeric:tabular-nums> / "),Sp=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>'),Cp=R("<div style=width:8px;height:8px;border-radius:50%;flex-shrink:0>"),on=R('<button style="background:transparent;border:none;cursor:pointer;padding:0 2px;display:flex;align-items:center;justify-content:center;flex-shrink:0">'),kp=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">'),Tp=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">×'),Mp=R("<span style=font-weight:400;color:#8b949e>"),Ep=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">'),Rp=R("<div style=flex:1;overflow:auto;min-height:0;padding:8px>"),Op=R("<div style=color:#484f58;font-style:italic;font-size:12px>Click a tile to select objects…");const{log:Ys,error:Xt}=Tt("SelectionList"),Pp={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"},Lp={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"},Ap=new Set(["x","y","type","id","name","user","_id","room","hitsMax","energyCapacity","body","storeCapacity","storeCapacityResource"]),Xs=new Set(["hits","energy","energyCapacity","store","progress","progressTotal","nextDecayTime"]),js={hits:"Hits",energy:"Energy",progress:"Progress",progressTotal:"Progress total",ticksToLive:"Ticks to live",ticksToRegeneration:"Ticks to regen",ticksToDecay:"Ticks to decay",nextDecayTime:"Decays in",fatigue:"Fatigue",cooldown:"Cooldown",mineralType:"Mineral type",mineralAmount:"Mineral amount",density:"Density",notifyWhenAttacked:"Notify when attacked",isPublic:"Public",structureType:"Structure type",level:"Level",power:"Power",powerCapacity:"Power capacity",depositType:"Deposit type",lastCooldown:"Last cooldown",resourceType:"Resource type",amount:"Amount",decay:"Decay in",mode:"Mode",actionLog:"Action log",store:"Store"};function Ip(r){return js[r]?js[r]:r.replace(/([A-Z])/g," $1").replace(/^./,e=>e.toUpperCase()).trim()}function Np(r){return typeof r=="number"?String(r):typeof r=="string"?r:typeof r=="boolean"?r?"Yes":"No":null}function Ni(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 pe=(r=!1)=>({padding:"3px 8px",background:"#0d1117",color:r?"#8b949e":"#c9d1d9",overflow:"hidden","text-overflow":"ellipsis","white-space":"nowrap"}),Jr={display:"grid","grid-template-columns":"1fr 1fr",gap:"1px",background:"#21262d","font-size":"10px"};function Dp(r){const e=()=>{const t=r.item.raw,i=[];for(const n in t){if(Ap.has(n))continue;const s=t[n];let o=Np(s);if(!(n==="notifyWhenAttacked"&&s===!1)&&!(n==="off"&&s===!1)){if(n==="hits"&&typeof t.hitsMax=="number"&&(o=`${s} / ${t.hitsMax}`),n==="energy"&&typeof t.energyCapacity=="number"&&(o=`${s} / ${t.energyCapacity}`),n==="nextDecayTime"&&typeof s=="number"){const c=Fe();c!==null&&(o=String(s-c))}o!==null&&i.push({key:n,label:Ip(n),value:o})}}return i.sort((n,s)=>{const o=Xs.has(n.key)?0:1,c=Xs.has(s.key)?0:1;return o-c}),i};return b(q,{get when(){return e().length>0},get children(){var t=Yt();return m(t,b($e,{get each(){return e()},children:i=>[(()=>{var n=Yt();return m(n,()=>i.label),N(s=>Q(n,pe(!0),s)),n})(),(()=>{var n=Ii();return m(n,()=>i.value),N(s=>Q(n,{...pe()},s)),n})()]})),N(i=>Q(t,Jr,i)),t}})}function wl(r){const e=()=>{const i=r.store||{},n=[];for(const s in i)n.push([s,i[s]]);return n},t=()=>{const i=r.store||{};let n=0;for(const s in i)n+=i[s];return n};return b(q,{get when(){return e().length>0},get children(){var i=qf(),n=i.firstChild;n.firstChild;var s=n.nextSibling;return m(n,b(q,{get when(){return r.capacity!=null},get children(){var o=Vf(),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=Zf();return m(l,o),l})(),(()=>{var l=Kf();return m(l,c),l})()]})),i}})}const Vs={tough:"#4c4c4c",move:"#a9b7c6",work:"#ffe56d",carry:"#777777",attack:"#f93842",ranged_attack:"#5d80b2",heal:"#65fd62",claim:"#b99cfb"};function zp(r){const e=()=>r.item.raw,t=()=>typeof e().user=="string"?e().user:null,i=()=>{var f,p;const d=t();return d?((p=(f=tl())==null?void 0:f[d])==null?void 0:p.username)??d:null},n=()=>typeof e().hits=="number"?e().hits:null,s=()=>typeof e().hitsMax=="number"?e().hitsMax:null,o=()=>{const d=e().ageTime,f=Fe();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,u=()=>e().body??[],h=()=>{const d=new Map;for(const f of u())d.set(f.type,(d.get(f.type)??0)+1);return[...d.entries()].map(([f,p])=>({type:f,count:p}))};return(()=>{var d=ip(),f=d.firstChild;return m(f,b(q,{get when(){return i()},get children(){return[(()=>{var p=Jf();return N(g=>Q(p,pe(!0),g)),p})(),(()=>{var p=Yt();return m(p,i),N(g=>Q(p,pe(),g)),p})()]}}),null),m(f,b(q,{get when(){return te(()=>n()!==null)()&&s()!==null},get children(){return[(()=>{var p=vl();return N(g=>Q(p,pe(!0),g)),p})(),(()=>{var p=bl(),g=p.firstChild;return m(p,n,g),m(p,s,null),N(S=>Q(p,{...pe()},S)),p})()]}}),null),m(f,b(q,{get when(){return o()!==null},get children(){return[(()=>{var p=Qf();return N(g=>Q(p,pe(!0),g)),p})(),(()=>{var p=Ii();return m(p,o),N(g=>Q(p,{...pe()},g)),p})()]}}),null),m(f,b(q,{get when(){return c()!==null},get children(){return[(()=>{var p=ep();return N(g=>Q(p,pe(!0),g)),p})(),(()=>{var p=Ii();return m(p,c),N(g=>Q(p,{...pe(),color:c()>0?"#e3b341":void 0},g)),p})()]}}),null),m(d,b(wl,{get store(){return l()},get capacity(){return a()}}),null),m(d,b(q,{get when(){return u().length>0},get children(){var p=rp(),g=p.firstChild,S=g.firstChild,P=S.nextSibling;P.nextSibling;var z=g.nextSibling;return m(g,()=>u().length,P),m(z,b($e,{get each(){return u()},children:U=>(()=>{var O=np();return N(y=>{var x=U.type.replace("_"," "),L=Vs[U.type]??"#484f58",v=U.hits===0?.25:1;return x!==y.e&&_e(O,"title",y.e=x),L!==y.t&&X(O,"background",y.t=L),v!==y.a&&X(O,"opacity",y.a=v),y},{e:void 0,t:void 0,a:void 0}),O})()})),m(p,b(q,{get when(){return Vo()},get children(){var U=tp();return m(U,b($e,{get each(){return h()},children:({type:O,count:y})=>(()=>{var x=sp(),L=x.firstChild,v=L.firstChild,C=L.nextSibling;return m(L,y,v),m(C,()=>O.replace("_"," ").toUpperCase()),N(T=>X(C,"color",Vs[O]??"#484f58")),x})()})),U}}),null),p}}),null),N(p=>Q(f,Jr,p)),d})()}function Gp(r){const e=()=>r.item.raw,t=()=>typeof e().name=="string"?e().name:"",i=()=>typeof e().room=="string"?e().room:"",n=()=>typeof e().color=="number"?e().color:1,s=()=>typeof e().secondaryColor=="number"?e().secondaryColor:1,[o,c]=B(n()),[l,a]=B(s());he(()=>{c(n()),a(s())});const u=()=>o()!==n()||l()!==s(),h=()=>{const S=ge();if(!S)return;const P=o(),z=l();Ys(`changeFlagColor: name="${t()}" room=${i()} primary=${P} secondary=${z}`),S.http.game.changeFlagColor(i(),t(),P,z).then(()=>Ys("changeFlagColor OK")).catch(U=>Xt("changeFlagColor FAILED:",U))},d=()=>{const S=Ut();return(S==null?void 0:S.type)==="moveFlag"&&S.id===r.item.id},f=()=>{if(d()){Br(null);return}Br({type:"moveFlag",id:r.item.id,name:t(),room:i(),color:o(),secondaryColor:l(),targetRoom:Yr()??i()})},p=()=>{const S=Ut();return(S==null?void 0:S.type)==="moveFlag"&&S.id===r.item.id?S:null},g={display:"flex","flex-direction":"column",gap:"5px","font-size":"11px",color:"#8b949e"};return(()=>{var S=lp(),P=S.firstChild;P.firstChild;var z=P.nextSibling;return z.firstChild,m(P,b(Ai,{get value(){return o()},onChange:c}),null),m(z,b(Ai,{get value(){return l()},onChange:a}),null),m(S,b(q,{get when(){return!be()},get children(){return[(()=>{var U=op(),O=U.firstChild,y=O.nextSibling;return O.addEventListener("mouseleave",x=>{u()&&(x.currentTarget.style.background="#238636")}),O.addEventListener("mouseenter",x=>{u()&&(x.currentTarget.style.background="#2ea043")}),O.$$click=h,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=te(()=>!!d());return()=>x()?b(qt,{size:13}):b(Kc,{size:13})})()),N(x=>{var L=!u(),v=u()?"#238636":"#161b22",C=u()?"#fff":"#484f58",T=`1px solid ${u()?"#238636":"#30363d"}`,w=u()?"pointer":"not-allowed",M=d()?"Abort move":"Move flag",k=d()?"#30363d":"#21262d",E=d()?"#c9d1d9":"#8b949e",D=`1px solid ${d()?"#8b949e":"#30363d"}`;return L!==x.e&&(O.disabled=x.e=L),v!==x.t&&X(O,"background",x.t=v),C!==x.a&&X(O,"color",x.a=C),T!==x.o&&X(O,"border",x.o=T),w!==x.i&&X(O,"cursor",x.i=w),M!==x.n&&_e(y,"title",x.n=M),k!==x.s&&X(y,"background",x.s=k),E!==x.h&&X(y,"color",x.h=E),D!==x.r&&X(y,"border",x.r=D),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}),U})(),b(q,{get when(){return p()},children:U=>(()=>{var O=ap(),y=O.firstChild,x=y.nextSibling;return x.nextSibling,x.$$input=L=>Br({...U(),targetRoom:L.currentTarget.value.toUpperCase()}),N(L=>Q(O,g,L)),N(()=>x.value=U().targetRoom),O})()})]}}),null),N(U=>{var O=g,y=g;return U.e=Q(P,O,U.e),U.t=Q(z,y,U.t),U},{e:void 0,t:void 0}),S})()}function Bp(r){const e=()=>r.item.raw,t=()=>typeof e().level=="number"?e().level:0,i=()=>typeof e().progress=="number"?e().progress:null,n=()=>typeof e().progressTotal=="number"?e().progressTotal:Oo[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,u=()=>typeof e().user=="string"?e().user:null,h=()=>{var y;const O=u();return O?((y=Mi())==null?void 0:y.username)??O:null},d=()=>{const O=s(),y=Fe();return O!==null&&y!==null?Math.max(0,O-y):null},f=()=>{const O=d();if(O===null)return"—";const y=Po[t()];return y!==void 0&&O>=y?"Max":String(O)},p=()=>{var O;return u()!==null&&u()===((O=We())==null?void 0:O._id)},[g,S]=B(!1);let P=null;const z=()=>{const O=ge();O&&O.http.game.addObjectIntent(r.item.id,Yr()??e().room??"","activateSafeMode",{id:r.item.id},mr()).catch(y=>Xt("activateSafeMode failed:",y))},U=()=>{if(!g()){S(!0),P=setTimeout(()=>S(!1),3e3);return}P&&(clearTimeout(P),P=null),S(!1);const O=ge();O&&O.http.game.addObjectIntent(r.item.id,Yr()??e().room??"","unclaim",{id:r.item.id},mr()).catch(y=>Xt("unclaim failed:",y))};return(()=>{var O=yp(),y=O.firstChild,x=y.firstChild,L=x.nextSibling;return m(L,()=>h()??"None"),m(y,b(q,{get when(){return a()},children:v=>[(()=>{var C=vp();return N(T=>Q(C,pe(!0),T)),C})(),(()=>{var C=bp(),T=C.firstChild,w=T.nextSibling;return w.nextSibling,m(C,()=>v().username,T),m(C,()=>v().ticksToEnd,w),N(M=>Q(C,pe(),M)),C})()]}),null),m(y,b(q,{get when(){return t()>0},get children(){return[(()=>{var v=cp();return N(C=>Q(v,pe(!0),C)),v})(),(()=>{var v=Yt();return m(v,t),N(C=>Q(v,pe(),C)),v})(),(()=>{var v=dp();return N(C=>Q(v,pe(!0),C)),v})(),(()=>{var v=Yt();return m(v,o),N(C=>Q(v,pe(),C)),v})(),(()=>{var v=up();return N(C=>Q(v,pe(!0),C)),v})(),(()=>{var v=Yt();return m(v,()=>l()?"Enabled":"Disabled"),N(C=>Q(v,pe(),C)),v})(),(()=>{var v=hp();return N(C=>Q(v,pe(!0),C)),v})(),(()=>{var v=Ii();return m(v,f),N(C=>Q(v,{...pe(),color:f()==="Max"?"#3fb950":void 0},C)),v})()]}}),null),m(y,b(q,{get when(){return c()!==null},get children(){return[(()=>{var v=fp();return N(C=>Q(v,pe(!0),C)),v})(),(()=>{var v=pp(),C=v.firstChild;return m(v,c,C),N(T=>Q(v,{...pe()},T)),v})()]}}),null),m(O,b(q,{get when(){return te(()=>t()>0&&t()<8&&i()!==null)()&&n()!==null},get children(){var v=gp(),C=v.firstChild,T=C.firstChild,w=T.firstChild,M=w.nextSibling;M.nextSibling;var k=T.nextSibling,E=k.firstChild,D=E.nextSibling,I=D.nextSibling,H=I.nextSibling;H.nextSibling;var A=C.nextSibling,G=A.firstChild;return m(T,t,M),m(T,()=>t()+1,null),m(k,()=>Ni(i()),E),m(k,()=>Ni(n()),D),m(k,()=>(i()/n()*100).toFixed(1),H),N(V=>X(G,"width",`${Math.min(100,i()/n()*100)}%`)),v}}),null),m(O,b(q,{get when(){return te(()=>!!p())()&&!be()},get children(){var v=mp(),C=v.firstChild,T=C.nextSibling;return C.addEventListener("mouseleave",w=>{o()>0&&(w.currentTarget.style.background="#1f6feb")}),C.addEventListener("mouseenter",w=>{o()>0&&(w.currentTarget.style.background="#388bfd")}),C.$$click=z,T.addEventListener("mouseleave",w=>{g()||(w.currentTarget.style.background="#f85149")}),T.addEventListener("mouseenter",w=>{g()||(w.currentTarget.style.background="#da3633")}),T.$$click=U,m(T,()=>g()?"Confirm unclaim":"Unclaim"),N(w=>{var M=o()===0,k=o()>0?"#1f6feb":"#161b22",E=o()>0?"pointer":"not-allowed",D=o()>0?1:.5,I=g()?"#da3633":"#f85149";return M!==w.e&&(C.disabled=w.e=M),k!==w.t&&X(C,"background",w.t=k),E!==w.a&&X(C,"cursor",w.a=E),D!==w.o&&X(C,"opacity",w.o=D),I!==w.i&&X(T,"background",w.i=I),w},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),v}}),null),N(v=>{var C=Jr,T=pe(!0),w=pe();return v.e=Q(y,C,v.e),v.t=Q(x,T,v.t),v.a=Q(L,w,v.a),v},{e:void 0,t:void 0,a:void 0}),O})()}function Fp(r){const e=()=>r.item.raw,t=()=>{const u=e().store;return(u==null?void 0:u.energy)??0},i=()=>{const u=e().storeCapacityResource;return(u==null?void 0:u.energy)??0},n=()=>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 u;return c()!==null&&c()===((u=We())==null?void 0:u._id)},a=()=>{const u=ge();u&&u.http.game.addObjectIntent(r.item.id,e().room,"notifyWhenAttacked",{enabled:!o()}).catch(h=>Xt("notifyWhenAttacked failed:",h))};return(()=>{var u=_p(),h=u.firstChild,d=h.nextSibling,f=d.firstChild;return m(d,t,f),m(d,i,null),m(u,b(q,{get when(){return te(()=>n()!==null)()&&s()!==null},get children(){return[(()=>{var p=vl();return N(g=>Q(p,pe(!0),g)),p})(),(()=>{var p=bl(),g=p.firstChild;return m(p,n,g),m(p,s,null),N(S=>Q(p,{...pe()},S)),p})()]}}),null),m(u,b(q,{get when(){return te(()=>!!l())()&&!be()},get children(){return[(()=>{var p=wp();return N(g=>Q(p,pe(!0),g)),p})(),(()=>{var p=xp(),g=p.firstChild;return g.addEventListener("mouseleave",S=>{S.currentTarget.style.color=o()?"#3fb950":"#484f58"}),g.addEventListener("mouseenter",S=>{S.currentTarget.style.color=o()?"#56d364":"#8b949e"}),g.$$click=a,m(g,(()=>{var S=te(()=>!!o());return()=>S()?b(dc,{size:12}):b(lc,{size:12})})()),N(S=>{var P={...pe()},z=o()?"Notifications on — click to disable":"Notifications off — click to enable",U=o()?"#3fb950":"#484f58";return S.e=Q(p,P,S.e),z!==S.t&&_e(g,"title",S.t=z),U!==S.a&&X(g,"color",S.a=U),S},{e:void 0,t:void 0,a:void 0}),p})()]}}),null),N(p=>{var g=Jr,S=pe(!0),P={...pe()};return p.e=Q(u,g,p.e),p.t=Q(h,S,p.t),p.a=Q(d,P,p.a),p},{e:void 0,t:void 0,a:void 0}),u})()}function Pt(r){const e=()=>r.item.raw,t=()=>typeof e().hits=="number"?e().hits:null,i=()=>typeof e().hitsMax=="number"?e().hitsMax:null,n=()=>e().store,s=()=>{if(typeof e().storeCapacity=="number")return e().storeCapacity;const l=e().storeCapacityResource;if(l){let a=0;for(const u in l)a+=l[u];return a}return null},o=()=>{const l=n();if(!l)return 0;let a=0;for(const u in l)a+=l[u];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(q,{get when(){return te(()=>t()!==null)()&&i()!==null},get children(){var a=$p(),u=a.firstChild,h=u.nextSibling,d=h.firstChild;return m(h,t,d),m(h,i,null),N(f=>{var p=Jr,g=pe(!0),S={...pe()};return f.e=Q(a,p,f.e),f.t=Q(u,g,f.t),f.a=Q(h,S,f.a),f},{e:void 0,t:void 0,a:void 0}),a}}),null),m(l,b(q,{get when(){return s()!==null},get children(){var a=Sp(),u=a.firstChild,h=u.firstChild,d=h.nextSibling,f=d.firstChild,p=f.nextSibling,g=p.nextSibling,S=g.nextSibling;S.nextSibling;var P=u.nextSibling,z=P.firstChild;return m(d,()=>Ni(o()),f),m(d,()=>Ni(s()),p),m(d,()=>c().toFixed(1),S),N(U=>X(z,"width",`${c()}%`)),a}}),null),m(l,b(wl,{get store(){return n()},capacity:null}),null),l})()}const Hp={creep:zp,flag:Gp,controller:Bp,extension:Fp,storage:Pt,terminal:Pt,container:Pt,lab:Pt,factory:Pt,nuker:Pt,powerSpawn:Pt};function Wp(r){const e=()=>Pp[r.item.type]??"#c9d1d9",t=()=>Lp[r.item.type]??r.item.type,i=()=>r.item.type==="creep",n=()=>r.item.type==="flag",s=()=>{var x;if(!i())return!1;const O=r.item.raw,y=typeof O.user=="string"?O.user:null;return y!==null&&y===((x=We())==null?void 0:x._id)},o=()=>{var x,L,v;if(i()||n()||r.item.type==="controller")return!1;const O=r.item.raw,y=typeof O.user=="string"?O.user:null;return y!==null?y===((x=We())==null?void 0:x._id):((L=Mi())==null?void 0:L.userId)===((v=We())==null?void 0:v._id)},c=()=>Hp[r.item.type]||Dp,[l,a]=B(!1);let u=null;const[h,d]=B(!1);let f=null;const[p,g]=B(!1);let S=null;const P=O=>{if(O.stopPropagation(),!p()){g(!0),S=setTimeout(()=>g(!1),3e3);return}S&&(clearTimeout(S),S=null),g(!1);const y=ge();if(!y)return;const x=r.item.id,L=r.item.raw;y.http.game.removeFlag(L.room,L.name).then(()=>Rr(x)).catch(()=>{})},z=O=>{var C;if(O.stopPropagation(),!h()){d(!0),f=setTimeout(()=>d(!1),3e3);return}f&&(clearTimeout(f),f=null),d(!1);const y=ge();if(!y)return;const x=r.item.id,L=r.item.raw,v=(typeof L.room=="string"?L.room:null)??Yr()??"";if(r.item.type==="constructionSite")y.http.game.removeConstructionSite(v,[x],mr()??void 0).then(()=>Rr(x)).catch(T=>Xt("removeConstructionSite failed:",T));else{const T=typeof L.user=="string"?L.user:((C=Mi())==null?void 0:C.userId)??"";y.http.game.addObjectIntent("room",v,"destroyStructure",[{id:x,roomName:v,user:T}],mr()).then(()=>Rr(x)).catch(w=>Xt("destroyStructure failed:",w))}},U=O=>{if(O.stopPropagation(),!l()){a(!0),u=setTimeout(()=>a(!1),3e3);return}u&&(clearTimeout(u),u=null),a(!1);const y=ge();if(!y)return;const x=r.item.id;y.http.game.addObjectIntent(x,Yr()??r.item.raw.room??"","suicide",{id:x},mr()).then(()=>Rr(x)).catch(L=>Xt("suicide failed:",L))};return(()=>{var O=Tp(),y=O.firstChild,x=y.firstChild,L=x.nextSibling,v=L.firstChild,C=v.nextSibling,T=C.nextSibling,w=T.nextSibling;w.nextSibling;var M=L.nextSibling;return m(y,b(q,{get when(){return te(()=>!i())()&&!n()},get children(){var k=Cp();return N(E=>X(k,"background",e())),k}}),x),m(x,b(q,{get when(){return n()},get fallback(){return te(t)},get children(){return b(Co,{size:12})}}),null),m(x,b(q,{get when(){return te(()=>typeof r.item.raw.name=="string")()&&r.item.raw.name},children:k=>(()=>{var E=Mp();return m(E,()=>k()),E})()}),null),m(L,()=>r.item.raw.x,C),m(L,()=>r.item.raw.y,w),m(y,b(q,{get when(){return te(()=>!!s())()&&!be()},get children(){return[(()=>{var k=on();return k.addEventListener("mouseleave",E=>{l()||(E.currentTarget.style.color="#8b949e")}),k.addEventListener("mouseenter",E=>{l()||(E.currentTarget.style.color="#f85149")}),k.$$click=U,m(k,b(mi,{size:13})),N(E=>{var D=l()?"Click again to confirm suicide":"Suicide",I=l()?"#f85149":"#8b949e";return D!==E.e&&_e(k,"title",E.e=D),I!==E.t&&X(k,"color",E.t=I),E},{e:void 0,t:void 0}),k})(),(()=>{var k=kp();return k.addEventListener("mouseleave",E=>E.currentTarget.style.color="#8b949e"),k.addEventListener("mouseenter",E=>E.currentTarget.style.color="#58a6ff"),k.$$click=()=>{gf(r.item.id,r.item.raw.name),dl(!0)},m(k,b(So,{size:13})),k})()]}}),M),m(y,b(q,{get when(){return te(()=>!!o())()&&!be()},get children(){var k=on();return k.addEventListener("mouseleave",E=>{h()||(E.currentTarget.style.color="#8b949e")}),k.addEventListener("mouseenter",E=>{h()||(E.currentTarget.style.color="#f85149")}),k.$$click=z,m(k,b(mi,{size:13})),N(E=>{var D=h()?"Click again to confirm":r.item.type==="constructionSite"?"Remove construction site":"Destroy structure",I=h()?"#f85149":"#8b949e";return D!==E.e&&_e(k,"title",E.e=D),I!==E.t&&X(k,"color",E.t=I),E},{e:void 0,t:void 0}),k}}),M),m(y,b(q,{get when(){return te(()=>!!n())()&&!be()},get children(){var k=on();return k.addEventListener("mouseleave",E=>{p()||(E.currentTarget.style.color="#8b949e")}),k.addEventListener("mouseenter",E=>{p()||(E.currentTarget.style.color="#f85149")}),k.$$click=P,m(k,b(mi,{size:13})),N(E=>{var D=p()?"Click again to confirm deletion":"Delete flag",I=p()?"#f85149":"#8b949e";return D!==E.e&&_e(k,"title",E.e=D),I!==E.t&&X(k,"color",E.t=I),E},{e:void 0,t:void 0}),k}}),M),M.addEventListener("mouseleave",k=>k.currentTarget.style.color="#8b949e"),M.addEventListener("mouseenter",k=>k.currentTarget.style.color="#fff"),M.$$click=()=>Rr(r.item.id),m(O,b(oo,{get component(){return c()},get item(){return r.item}}),null),m(O,b(q,{get when(){return r.item.id},children:k=>(()=>{var E=Ep();return E.$$click=()=>{var D;return(D=navigator.clipboard)==null?void 0:D.writeText(k())},m(E,k),N(()=>_e(E,"title",k())),E})()}),null),N(k=>X(O,"border",`1px solid ${s()&&l()||h()||p()?"#f85149":"#30363d"}`)),O})()}function Up(){return(()=>{var r=Rp();return m(r,b(q,{get when(){return vr().length>0},get fallback(){return Op()},get children(){return b($e,{get each(){return vr()},children:e=>b(Wp,{item:e})})}})),r})()}Re(["click","input"]);var Yp=R('<div style="padding:3px 0;color:#8b949e">RCL'),Xp=R("<span style=color:#8b949e>(<!>%)"),jp=R('<div style="padding:3px 0;color:#c9d1d9;font-variant-numeric:tabular-nums">'),Vp=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">'),qp=R("<span>"),Zp=R('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;display:flex;align-items:center;justify-content:center">');const Kp=[{mode:"view",label:"View",icon:()=>b(So,{size:14})},{mode:"flag",label:"Flag",icon:()=>b(Co,{size:14})},{mode:"build",label:"Build",icon:()=>b(Lc,{size:14})}];function Jp(r){return(()=>{var e=Vp(),t=e.firstChild,i=t.firstChild,n=i.nextSibling,s=n.nextSibling,o=s.firstChild,c=o.nextSibling,l=c.nextSibling,a=l.nextSibling,u=a.nextSibling,h=u.nextSibling,d=h.nextSibling,f=d.nextSibling,p=f.nextSibling,g=p.nextSibling,S=s.nextSibling,P=S.firstChild,z=P.nextSibling,U=S.nextSibling,O=U.firstChild,y=O.nextSibling,x=t.nextSibling,L=x.firstChild;return m(n,()=>r.room),m(c,()=>r.shard??"—"),m(a,()=>Fe()??"—"),m(h,(()=>{var v=te(()=>!!xi());return()=>v()?`${xi()}ms`:"—"})()),m(f,()=>Ih()??"—"),m(g,()=>{var v;return((v=Mi())==null?void 0:v.username)??"—"}),m(s,b(q,{get when(){return te(()=>Be()!==null)()&&Be()>0},get children(){return[Yp(),(()=>{var v=jp();return m(v,b(q,{get when(){return te(()=>Be()<8)()&&Is()!==null},get fallback(){return(()=>{var C=qp();return m(C,Be),C})()},get children(){return[te(()=>Be())," → ",te(()=>Be()+1)," ",(()=>{var C=Xp(),T=C.firstChild,w=T.nextSibling;return w.nextSibling,m(C,()=>(Is()/(Oo[Be()]??1)*100).toFixed(1),w),C})()]}})),v})()]}}),null),z.addEventListener("change",v=>Ho(v.currentTarget.checked)),y.addEventListener("change",v=>_h(v.currentTarget.checked)),m(x,b(q,{get when(){return!Le()},get children(){return b($e,{each:Kp,children:v=>{const C=()=>!be()&&St()===v.mode;return(()=>{var T=Zp();return T.$$click=()=>{be()&&Ri(),$t(v.mode)},m(T,()=>v.icon()),N(w=>{var M=v.label,k=`1px solid ${C()?"#58a6ff":"#30363d"}`,E=C()?"#1f6feb33":"#161b22",D=C()?"#c9d1d9":"#8b949e";return M!==w.e&&_e(T,"title",w.e=M),k!==w.t&&X(T,"border",w.t=k),E!==w.a&&X(T,"background",w.a=E),D!==w.o&&X(T,"color",w.o=D),w},{e:void 0,t:void 0,a:void 0,o:void 0}),T})()}})}}),L),L.$$click=()=>be()?Ri():Fe()!==null&&ol(Fe()),m(L,b($c,{size:14})),N(v=>{var C=`repeat(${Le()?2:4}, 1fr)`,T=!be()&&Fe()===null,w=Le()?"span 2":void 0,M=`1px solid ${be()?"#58a6ff":"#30363d"}`,k=be()?"#1f6feb33":"#161b22",E=be()?"#c9d1d9":"#8b949e",D=!be()&&Fe()===null?"not-allowed":"pointer",I=!be()&&Fe()===null?.4:1;return C!==v.e&&X(x,"grid-template-columns",v.e=C),T!==v.t&&(L.disabled=v.t=T),w!==v.a&&X(L,"grid-column",v.a=w),M!==v.o&&X(L,"border",v.o=M),k!==v.i&&X(L,"background",v.i=k),E!==v.n&&X(L,"color",v.n=E),D!==v.s&&X(L,"cursor",v.s=D),I!==v.h&&X(L,"opacity",v.h=I),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}),N(()=>z.checked=ki()),N(()=>y.checked=jo()),e})()}Re(["click"]);const[Qp,eg]=B("owner"),xl="screeps-terrain-v1";async function tg(r,e,t){try{const i=await caches.open(xl),n=`/terrain/${r}_${e}_z${t}.webp`,s=new Request(n),o=await i.match(s);if(o)return await o.blob()}catch{}return null}async function rg(r,e,t,i){try{const n=await caches.open(xl),s=`/terrain/${r}_${e}_z${t}.webp`,o=new Request(s),c=new Response(i);await n.put(o,c)}catch{}}async function ig(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 ng(r){return await createImageBitmap(r)}function sg(r){return new Worker("/client/_client/terrain.worker-D9zNeJfz.js",{name:r==null?void 0:r.name})}const{warn:og}=Tt("MapRenderer"),_l=3,le=_l*50,lg=[50,60,70,80,90,100,110],Lr=1,Dt=.5,ci=50,ag=2600,cg=5,ln=.2,an=5,dg=_r,ug=16777215,hg=Ht,fg=Dr,pg=Eo,gg=At,mg=4486980,yg=8921634,vg=new Set(["w","r","pb","p","s","c","m","k"]),bg={H:13421772,O:13421772,U:5809919,L:4176208,K:10711543,Z:13801762,X:16273737},wg=[16,24,32,40];class K0{constructor(e){$(this,"app");$(this,"world");$(this,"boundsGraphics",null);$(this,"selectionGraphics",null);$(this,"safeModeGraphics",null);$(this,"safeModeRooms",new Set);$(this,"activeRooms",new Map);$(this,"roomPool",[]);$(this,"terrainBaked",new Set);$(this,"terrainData",new Map);$(this,"worker");$(this,"pendingBakes",new Map);$(this,"nextBakeId",0);$(this,"currentShard","shard0");$(this,"callbacks");$(this,"resizeObserver",null);$(this,"_destroyed",!1);$(this,"showRoomNames",!1);$(this,"worldBoundsSet",null);$(this,"lastVisibleBounds",null);$(this,"animTargetX",0);$(this,"animTargetY",0);$(this,"isAnimating",!1);$(this,"overlayMode","owner");$(this,"showUnclaimableOverlay",!0);$(this,"isDragging",!1);$(this,"hasDragged",!1);$(this,"dragStartX",0);$(this,"dragStartY",0);$(this,"dragWorldX",0);$(this,"dragWorldY",0);$(this,"isPinching",!1);$(this,"pinchPivotWorldX",0);$(this,"pinchPivotWorldY",0);$(this,"pinchStartDist",0);$(this,"pinchStartScale",0);$(this,"lastVisibleKey","");$(this,"visibleDebounceTimer",null);$(this,"selectedRoom",null);$(this,"currentUserId",null);$(this,"badgeCache",new Ro);$(this,"lastCheckX",0);$(this,"lastCheckY",0);$(this,"lastCheckScale",0);this.app=new io,this.callbacks=e,this.worker=new sg,this.worker.onmessage=t=>{const{id:i,bitmap:n}=t.data,s=this.pendingBakes.get(i);s&&(this.pendingBakes.delete(i),s.resolve(n))}}async init(e){const t=e.parentElement??e,{width:i,height:n}=t.getBoundingClientRect();await this.app.init({canvas:e,width:i,height:n,background:iu,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 Ne,this.app.stage.addChild(this.world),this.boundsGraphics=new re,this.world.addChild(this.boundsGraphics),this.selectionGraphics=new re,this.world.addChild(this.selectionGraphics),this.safeModeGraphics=new re,this.world.addChild(this.safeModeGraphics),this.setupInteraction(),this.app.ticker.add(()=>{if(this.isAnimating){const s=this.animTargetX-this.world.x,o=this.animTargetY-this.world.y;Math.abs(s)<.5&&Math.abs(o)<.5?(this.world.x=this.animTargetX,this.world.y=this.animTargetY,this.isAnimating=!1):(this.world.x+=s*.2,this.world.y+=o*.2)}this.checkVisibleRooms()})}get zoom(){var e;return((e=this.world)==null?void 0:e.scale.x)??1}setZoom(e){if(!this.world||(e=Math.max(ln,Math.min(an,e)),e===this.world.scale.x))return;const t=this.app.screen.width/2,i=this.app.screen.height/2;this.applyZoomAt(e,t,i)}applyZoomAt(e,t,i){var u,h;const n=this.world.scale.x,s=this.getLOD(),o=this.zoom>=Lr,c=this.zoom>=Dt,l=(t-this.world.x)/n,a=(i-this.world.y)/n;this.world.scale.set(e),this.world.x=t-l*e,this.world.y=i-a*e,this.getLOD()!==s&&this.applyLOD(),(e>=Lr!==o||e>=Dt!==c)&&this.updateAllNameLabels(),this.updateAllRoomScales(e),(h=(u=this.callbacks).onZoomChanged)==null||h.call(u,e),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode()}centerOn(e,t,i=!1){const n=e*le+le/2,s=t*le+le/2,o=this.world.scale.x,c=this.app.screen.width/2-n*o,l=this.app.screen.height/2-s*o;i?(this.animTargetX=c,this.animTargetY=l,this.isAnimating=!0):(this.isAnimating=!1,this.world.x=c,this.world.y=l)}async getTerrainBitmap(e,t,i){const n=this.currentShard;try{const s=await tg(n,e,t);if(s)return await ng(s);const o=this.nextBakeId++,c=new Promise((a,u)=>{this.pendingBakes.set(o,{roomName:e,lod:t,resolve:a,reject:u})});this.worker.postMessage({id:o,roomName:e,lod:t,raw:i});const l=await c;return ig(l).then(a=>{rg(n,e,t,a)}).catch(a=>og("failed to save to terrainCache:",a)),l}catch{return null}}async setRoomTerrain(e,t){const i=t.raw;let n=!1;for(let a=0;a<i.length;a++)if(i[a]!==0){n=!0;break}if(!n){this.terrainBaked.add(e);return}const s=this.getOrCreate(e),o=this.getLOD();o===0&&this.terrainData.set(e,i);const c=await this.getTerrainBitmap(e,o,i);if(!c)return;if(!this.activeRooms.has(e)){c.close();return}const l=Ae.from(c);o===0?(s.texLo&&!s.texLo.destroyed&&(s.terrainSprite.texture===s.texLo&&(s.terrainSprite.texture=Ae.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=Ae.EMPTY),s.texHi.destroy(!0)),s.texHi=l,this.getLOD()===1&&(s.terrainSprite.texture=l)),s.terrainSprite.width=le,s.terrainSprite.height=le,this.terrainBaked.add(e)}getLOD(){return this.zoom<Lr?0:1}async applyLOD(){const e=this.getLOD()===1,t=[];for(const[i,n]of this.activeRooms)if(this.terrainBaked.has(i))if(e&&!n.texHi){const s=this.terrainData.get(i);s&&(this.terrainData.delete(i),t.push(this.getTerrainBitmap(i,1,s).then(o=>{o&&this.activeRooms.has(i)?(n.texHi=Ae.from(o),this.getLOD()===1&&(n.terrainSprite.texture=n.texHi)):o&&o.close()})))}else{const s=e?n.texHi:n.texLo;s&&!s.destroyed&&(n.terrainSprite.texture=s)}await Promise.all(t)}setRoomMap2(e,t,i="live"){const n=this.getOrCreate(e);n.lastMap2Data=t,n.lastMap2Source=i,this.drawMap2(n,t,i)}drawMap2(e,t,i){const n=e.map2Graphics;n.alpha=i==="cache"?.6:1;const s=_l;n.clear();const o=t.r??[];for(const[p,g]of o)n.rect(p*s,g*s,s,s);o.length&&n.fill(rs);const c=t.w??[];for(const[p,g]of c)n.rect(p*s+.5,g*s+.5,s-1,s-1);c.length&&n.fill(e.ownerState==="other"?yg:mg);const l=t.s??[];for(const[p,g]of l)n.circle((p+.5)*s,(g+.5)*s,2.5);l.length&&n.fill(dg);const a=t.c??[];for(const[p,g]of a)n.circle((p+.5)*s,(g+.5)*s,2);a.length&&n.fill(ug);const u=t.m??[];for(const[p,g]of u)n.circle((p+.5)*s,(g+.5)*s,2);u.length&&n.fill(hg);const h=t.k??[];for(const[p,g]of h)n.circle((p+.5)*s,(g+.5)*s,2);h.length&&n.fill(fg);const d=t.pb??[];for(const[p,g]of d)n.circle((p+.5)*s,(g+.5)*s,1.5);d.length&&n.fill(Dr);const f=t;for(const p in f){if(vg.has(p))continue;const g=f[p];if(!Array.isArray(g)||g.length===0)continue;for(const[P,z]of g)n.circle((P+.5)*s,(z+.5)*s,1);const S=p===this.currentUserId?pg:gg;n.fill(S)}}clearRoomMap2(e){var t;(t=this.activeRooms.get(e))==null||t.map2Graphics.clear()}clearAllMap2(){for(const e of this.activeRooms.values())e.map2Graphics.clear()}setRoomOwned(e,t){const i=this.activeRooms.get(e);if(!i)return;i.ownerState!==t&&(i.ownerState=t,i.lastMap2Data&&this.drawMap2(i,i.lastMap2Data,i.lastMap2Source??"live"));const n=i.ownerOverlay;n.clear(),t==="other"?(n.rect(0,0,le,le),n.fill({color:10027008,alpha:.18})):t==="own"&&(n.rect(0,0,le,le),n.fill({color:102,alpha:.35})),n.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,i){const n=this.activeRooms.get(e);if(n){if(!t){n.badgeSprite&&(n.container.removeChild(n.badgeSprite),n.badgeSprite.destroy(),n.badgeSprite=void 0),n.badgeLevel=void 0;return}try{const s=await this.badgeCache.getOrCreate(t);if(!this.activeRooms.has(e))return;if(n.badgeSprite){if(n.badgeSprite.texture===s){n.badgeLevel=i,this.applyBadgeSize(n,this.zoom),this.applyOverlayMode(n);return}n.badgeSprite.texture=s}else{const o=new ze(s);o.anchor.set(.5),o.x=le/2,o.y=le/2;const c=n.container.getChildIndex(n.nameLabel);n.container.addChildAt(o,c),n.badgeSprite=o}n.badgeLevel=i,this.applyBadgeSize(n,this.zoom),this.applyOverlayMode(n)}catch{}}}applyBadgeSize(e,t){if(!e.badgeSprite||e.badgeLevel===void 0)return;const n=(lg[e.badgeLevel-1]??24)*Math.min(1,t);e.badgeSprite.width=n/t,e.badgeSprite.height=n/t}setOverlayMode(e){if(this.overlayMode!==e){this.overlayMode=e;for(const t of this.activeRooms.values())this.applyOverlayMode(t)}}setRoomMineral(e,t,i){const n=this.activeRooms.get(e);if(!n)return;if(!t||!i){n.mineralCircle&&(n.container.removeChild(n.mineralCircle),n.mineralCircle.destroy(),n.mineralCircle=void 0),n.mineralLabel&&(n.container.removeChild(n.mineralLabel),n.mineralLabel.destroy(),n.mineralLabel=void 0),n.mineralDensity=void 0;return}const s=bg[t]??Ht;if(n.mineralDensity=i,n.mineralColor=s,!n.mineralCircle){const o=new re;o.x=le/2,o.y=le/2;const c=n.container.getChildIndex(n.nameLabel);n.container.addChildAt(o,c),n.mineralCircle=o}if(n.mineralLabel)n.mineralLabel.text=t;else{const o=new Bt({text:t,style:{fontSize:36,fill:16777215,fontFamily:"ui-monospace, monospace",fontWeight:"bold"}});o.anchor.set(.5),o.x=le/2,o.y=le/2,n.container.addChild(o),n.mineralLabel=o}this.applyMineralSize(n,this.zoom),this.applyOverlayMode(n)}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 i=Math.max(.5,Math.min(1.5,t)),n=(wg[e.mineralDensity-1]??24)*i,s=n/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=n*.55/36/t;e.mineralLabel.scale.set(a)}updateNameLabelScale(e,t){const n=.3/Math.sqrt(t),s=12/(36*t);e.nameLabel.scale.set(Math.max(n,s))}updateAllRoomScales(e){for(const t of this.activeRooms.values())this.applyBadgeSize(t,e),this.updateNameLabelScale(t,e),this.applyMineralSize(t,e)}setCurrentUser(e){this.currentUserId=e}setSelectedRoom(e){if(this.selectedRoom=e,!this.selectionGraphics||(this.selectionGraphics.clear(),this.world.removeChild(this.selectionGraphics),this.world.addChild(this.selectionGraphics),!e))return;const t=ct(e);if(!t)return;const i=t.x*le,n=t.y*le;this.selectionGraphics.rect(i,n,le,le);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 i=ct(t);if(!i)continue;const n=i.x*le,s=i.y*le;this.safeModeGraphics.rect(n,s,le,le),this.safeModeGraphics.stroke({color:16776960,width:e,alignment:1,alpha:.5})}this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)}setBounds(e,t,i,n){if(!this.boundsGraphics)return;this.worldBoundsSet={minX:e,maxX:t,minY:i,maxY:n},this.boundsGraphics.clear();const s=e*le,o=i*le,c=(t-e+1)*le,l=(n-i+1)*le;this.boundsGraphics.rect(s,o,c,l),this.boundsGraphics.stroke({color:Mo,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=Ae.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<ag?this.roomPool.push(t):(this.world.removeChild(t.container),t.container.destroy({children:!0,context:!0})))}clearInvisibleRooms(e){const t=this.lastVisibleBounds;for(const i of[...this.activeRooms.keys()])if(!e.has(i)){if(t){const n=ct(i);if(n&&n.x>=t.rxMin-ci&&n.x<=t.rxMax+ci&&n.y>=t.ryMin-ci&&n.y<=t.ryMax+ci)continue}this.clearRoom(i)}}destroy(){var e;if(!this._destroyed){this._destroyed=!0,(e=this.resizeObserver)==null||e.disconnect(),this.resizeObserver=null,this.visibleDebounceTimer!==null&&(clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=null);for(const[,t]of this.activeRooms)t.texLo&&!t.texLo.destroyed&&t.texLo.destroy(!0),t.texHi&&!t.texHi.destroyed&&t.texHi.destroy(!0);this.activeRooms.clear(),this.safeModeRooms.clear();for(const t of this.roomPool)t.texLo&&!t.texLo.destroyed&&t.texLo.destroy(!0),t.texHi&&!t.texHi.destroyed&&t.texHi.destroy(!0);this.roomPool.length=0,this.terrainBaked.clear(),this.terrainData.clear(),this.worker.terminate(),this.pendingBakes.clear(),this.badgeCache.destroy();try{this.app.destroy(!1,{children:!0,texture:!0,context:!0})}catch{}}}getOrCreate(e){const t=this.activeRooms.get(e);if(t)return t;const i=ct(e);if(!i)throw new Error(`MapRenderer: invalid room "${e}"`);let n;if(this.roomPool.length>0)n=this.roomPool.pop();else{const s=new Ne;s.cullable=!0;const o=new ze(Ae.EMPTY),c=new re,l=new re;s.addChild(o),s.addChild(c),s.addChild(l);const a=new Bt({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),n={container:s,terrainSprite:o,texLo:null,texHi:null,map2Graphics:c,ownerOverlay:l,ownerState:"none",nameLabel:a}}return n.container.x=i.x*le,n.container.y=i.y*le,n.container.visible=!0,n.nameLabel.text=e,n.nameLabel.visible=this.showRoomNames&&this.zoom>=Dt&&this.nameLabelShouldShow(i.x,i.y),this.updateNameLabelScale(n,this.zoom),n.badgeSprite&&(n.container.removeChild(n.badgeSprite),n.badgeSprite.destroy(),n.badgeSprite=void 0),n.mineralCircle&&(n.container.removeChild(n.mineralCircle),n.mineralCircle.destroy(),n.mineralCircle=void 0),n.mineralLabel&&(n.container.removeChild(n.mineralLabel),n.mineralLabel.destroy(),n.mineralLabel=void 0),n.mineralDensity=void 0,n.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,n),n}nameLabelShouldShow(e,t){const i=this.worldBoundsSet;return!(i&&(e<i.minX||e>i.maxX||t<i.minY||t>i.maxY))}updateAllNameLabels(){const e=this.showRoomNames&&this.zoom>=Dt;for(const[t,i]of this.activeRooms){if(!e){i.nameLabel.visible=!1;continue}const n=ct(t);n&&(i.nameLabel.visible=this.nameLabelShouldShow(n.x,n.y))}}setupInteraction(){const e=this.app.canvas;e.style.touchAction="none",e.style.userSelect="none";const t=new Map;e.addEventListener("pointermove",i=>{var n,s;if(!t.has(i.pointerId)){if(!this.isDragging&&!this.isPinching){const o=e.getBoundingClientRect();this.emitHover(i.clientX-o.left,i.clientY-o.top)}return}if(t.set(i.pointerId,{x:i.clientX,y:i.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,u=Math.hypot(o[1].x-o[0].x,o[1].y-o[0].y),h=Math.max(ln,Math.min(an,this.pinchStartScale*(u/this.pinchStartDist))),d=this.getLOD(),f=this.zoom>=Lr,p=this.zoom>=Dt;this.world.scale.set(h),this.world.x=l-this.pinchPivotWorldX*h,this.world.y=a-this.pinchPivotWorldY*h,this.getLOD()!==d&&this.applyLOD(),(h>=Lr!==f||h>=Dt!==p)&&this.updateAllNameLabels(),this.updateAllRoomScales(h),(s=(n=this.callbacks).onZoomChanged)==null||s.call(n,h),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode();return}if(this.isDragging){const o=i.clientX-this.dragStartX,c=i.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,u=50,h=u-(l.maxX+1)*le*a,d=this.app.screen.width-u-l.minX*le*a,f=u-(l.maxY+1)*le*a,p=this.app.screen.height-u-l.minY*le*a;this.world.x=this.rubberBand(this.dragWorldX+o,h,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",i=>{if(i.preventDefault(),this.isAnimating=!1,t.set(i.pointerId,{x:i.clientX,y:i.clientY}),e.setPointerCapture(i.pointerId),t.size>=2){this.isDragging=!1,this.isPinching=!0;const n=[...t.values()],s=e.getBoundingClientRect(),o=(n[0].x+n[1].x)/2-s.left,c=(n[0].y+n[1].y)/2-s.top;this.pinchStartDist=Math.hypot(n[1].x-n[0].x,n[1].y-n[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=i.clientX,this.dragStartY=i.clientY,this.dragWorldX=this.world.x,this.dragWorldY=this.world.y}),e.addEventListener("pointerup",i=>{if(t.delete(i.pointerId),e.releasePointerCapture(i.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 n=e.getBoundingClientRect(),s=this.screenToRoom(i.clientX-n.left,i.clientY-n.top);s&&this.callbacks.onRoomClick(s)}this.springBack()}}),e.addEventListener("pointercancel",i=>{t.delete(i.pointerId),e.releasePointerCapture(i.pointerId),(this.isPinching||this.isDragging)&&(this.isPinching=!1,this.isDragging=!1,this.springBack())}),e.addEventListener("wheel",i=>{if(i.preventDefault(),this.isDragging||this.isPinching)return;this.isAnimating=!1;const n=this.world.scale.x,s=i.deltaY<0?1.1:.9,o=Math.max(ln,Math.min(an,n*s));this.applyZoomAt(o,i.offsetX,i.offsetY)},{passive:!1})}rubberBand(e,t,i){const n=i-t;if(n<=0||e>=t&&e<=i)return e;const s=.55;if(e<t){const c=t-e;return t-(1-1/(c*s/n+1))*n*s}const o=e-i;return i+(1-1/(o*s/n+1))*n*s}springBack(){const e=this.worldBoundsSet;if(!e)return;const t=this.world.scale.x,i=this.app.screen.width,n=this.app.screen.height,s=50,o=this.world.x+e.minX*le*t,c=this.world.x+(e.maxX+1)*le*t,l=this.world.y+e.minY*le*t,a=this.world.y+(e.maxY+1)*le*t;let u=this.world.x,h=this.world.y;c<s?u+=s-c:o>i-s&&(u-=o-(i-s)),a<s?h+=s-a:l>n-s&&(h-=l-(n-s)),(u!==this.world.x||h!==this.world.y)&&(this.animTargetX=u,this.animTargetY=h,this.isAnimating=!0)}screenToRoom(e,t){const i=this.world.scale.x,n=(e-this.world.x)/i,s=(t-this.world.y)/i,o=Math.floor(n/le),c=Math.floor(s/le);return qe(o,c)}emitHover(e,t){this.callbacks.onRoomHover(this.screenToRoom(e,t))}checkVisibleRooms(){const e=this.world.scale.x,t=this.world.x,i=this.world.y;if(this.lastCheckX===t&&this.lastCheckY===i&&this.lastCheckScale===e)return;this.lastCheckX=t,this.lastCheckY=i,this.lastCheckScale=e;const n=-t/e,s=-i/e,o=(this.app.screen.width-t)/e,c=(this.app.screen.height-i)/e,l=Math.floor(n/le)-1,a=Math.ceil(o/le),u=Math.floor(s/le)-1,h=Math.ceil(c/le);this.lastVisibleBounds={rxMin:l,rxMax:a,ryMin:u,ryMax:h};const d=[],f=this.worldBoundsSet,p=f?Math.max(l,f.minX):l,g=f?Math.min(a,f.maxX):a,S=f?Math.max(u,f.minY):u,P=f?Math.min(h,f.maxY):h;for(let U=p;U<=g;U++)for(let O=S;O<=P;O++){const y=qe(U,O);y&&d.push(y)}const z=`${l},${u},${a},${h}`;z!==this.lastVisibleKey&&(this.lastVisibleKey=z,this.visibleDebounceTimer!==null&&clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=setTimeout(()=>{this.visibleDebounceTimer=null,this.callbacks.onVisibleRoomsChanged(d)},cg))}}var xg=R('<div style="padding:8px;border-bottom:1px solid #30363d;flex-shrink:0"><div style="padding:4px 8px;background:#161b22;border-radius:6px;border:1px solid #30363d"><div style=font-size:10px;font-weight:600;color:#8b949e;text-transform:uppercase;letter-spacing:0.04em;margin-bottom:4px>Map</div><div style="display:grid;grid-template-columns:auto 1fr;row-gap:1px;font-size:11px;margin-bottom:8px"><div style="padding:3px 0;color:#8b949e">Zoom</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Live</div><div style="padding:3px 0;color:#c9d1d9"></div></div><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px><span>Show room names</span><input type=checkbox></label><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px;color:#c9d1d9;cursor:pointer;margin-top:4px><span>Show unclaimable rooms</span><input type=checkbox></label></div><div style="display:grid;grid-template-columns:repeat(3, 1fr);gap:4px;margin-top:8px">'),_g=R('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;font-size:11px;font-weight:600">');const $g=[{mode:"owner",label:"Owner"},{mode:"mineral",label:"Mineral"},{mode:"none",label:"None"}];function Sg(r){const e=()=>(r.zoom??1)>=Dt;return(()=>{var t=xg(),i=t.firstChild,n=i.firstChild,s=n.nextSibling,o=s.firstChild,c=o.nextSibling,l=c.nextSibling,a=l.nextSibling,u=s.nextSibling,h=u.firstChild,d=h.nextSibling,f=u.nextSibling,p=f.firstChild,g=p.nextSibling,S=i.nextSibling;return m(c,()=>{var P;return((P=r.zoom)==null?void 0:P.toFixed(2))??"—"}),m(a,()=>r.subsActive?"Yes":"No"),d.addEventListener("change",P=>Uo(P.currentTarget.checked)),g.addEventListener("change",P=>Xo(P.currentTarget.checked)),m(S,b($e,{each:$g,children:P=>{const z=()=>Qp()===P.mode;return(()=>{var U=_g();return U.$$click=()=>eg(P.mode),m(U,()=>P.label),N(O=>{var y=`1px solid ${z()?"#58a6ff":"#30363d"}`,x=z()?"#1f6feb33":"#161b22",L=z()?"#c9d1d9":"#8b949e";return y!==O.e&&X(U,"border",O.e=y),x!==O.t&&X(U,"background",O.t=x),L!==O.a&&X(U,"color",O.a=L),O},{e:void 0,t:void 0,a:void 0}),U})()}})),N(P=>{var z=e()?"#c9d1d9":"#484f58",U=e()?"pointer":"default",O=!e();return z!==P.e&&X(u,"color",P.e=z),U!==P.t&&X(u,"cursor",P.t=U),O!==P.a&&(d.disabled=P.a=O),P},{e:void 0,t:void 0,a:void 0}),N(()=>d.checked=Wo()),N(()=>g.checked=Yo()),t})()}Re(["click"]);var Cg=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">'),kg=R('<div style="padding:6px 8px;font-size:11px;color:#484f58;font-style:italic">None'),Tg=R('<div style="padding:3px 8px;color:#8b949e">Mineral'),Mg=R('<div style="padding:3px 8px;color:#79c0ff">'),Eg=R('<div style="padding:3px 8px;color:#8b949e">Density'),Rg=R('<div style="padding:3px 8px;color:#c9d1d9">'),Og=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 Pg=["Low","Medium","High","Ultra"];function Lg(r){return Pg[r-1]??String(r)}function qs(r){return(()=>{var e=Cg(),t=e.firstChild;return m(t,()=>r.label),m(e,b(q,{get when(){return r.info},get fallback(){return kg()},children:i=>(()=>{var n=Og(),s=n.firstChild,o=s.nextSibling,c=o.firstChild,l=c.nextSibling;return m(s,()=>i().room),m(l,()=>i().owner??"None"),m(o,b(q,{get when(){return i().mineral},get children(){return[Tg(),(()=>{var a=Mg();return m(a,()=>i().mineral),a})(),Eg(),(()=>{var a=Rg();return m(a,()=>Lg(i().density??0)),a})()]}}),null),n})()}),null),N(i=>{var n=`1px solid ${r.dim?"#21262d":"#30363d"}`,s=r.dim?.6:1;return n!==i.e&&X(e,"border",i.e=n),s!==i.t&&X(e,"opacity",i.t=s),i},{e:void 0,t:void 0}),e})()}var Ag=R("<span style=color:#8b949e;font-size:11px>Checking…"),Ig=R('<div style=margin-top:8px><div style="padding:6px 8px;font-size:11px;font-weight:600;color:#c9d1d9;margin-bottom:6px">Your flags'),Ng=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>'),Dg=R("<span style=color:#f85149;font-size:11px>"),zg=R("<div style=margin-top:8px;color:#484f58;font-style:italic;font-size:12px>No flags."),Gg=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:Bg}=Tt("flag"),Vn={};for(const[r,e]of Object.entries(qr))Vn[e]=r;function Fg(){const r=p=>{ll({...cr(),...p})},[e,t]=B(null),[i,n]=B(!1);let s=null;he(()=>{if(St()!=="flag"||cr().name.trim()!=="")return;const p=ge();p&&p.http.game.genUniqueFlagName().then(g=>{r({name:g.name}),t(null)}).catch(g=>{Bg("gen unique name failed:",g)})});const o=p=>{r({name:p}),t(null),s&&clearTimeout(s);const g=p.trim();if(!g){n(!1);return}n(!0),s=setTimeout(()=>{const S=ge();if(!S){n(!1);return}S.http.game.checkUniqueFlagName(g).then(()=>{t(null)}).catch(P=>{t(P.message)}).finally(()=>{n(!1)})},300)},c=()=>qr[cr().color]??1,l=()=>qr[cr().secondaryColor]??1,a=p=>{r({color:Vn[p]??"COLOR_WHITE"})},u=p=>{r({secondaryColor:Vn[p]??"COLOR_WHITE"})},h=()=>{const p=ja(),g=[];for(const[S,P]of Object.entries(p))P&&typeof P=="object"&&"room"in P&&"x"in P&&"y"in P&&g.push([S,P]);return g},d=p=>p===void 0||p<0||p>=hr.length?"#8b949e":`#${hr[p].toString(16).padStart(6,"0")}`,f={display:"flex","flex-direction":"column",gap:"5px","font-size":"11px",color:"#8b949e"};return(()=>{var p=Ng(),g=p.firstChild,S=g.firstChild,P=S.nextSibling,z=P.firstChild,U=z.firstChild,O=U.nextSibling,y=z.nextSibling;y.firstChild;var x=y.nextSibling;x.firstChild;var L=x.nextSibling;return O.$$input=v=>o(v.currentTarget.value),m(z,b(q,{get when(){return e()},children:v=>(()=>{var C=Dg();return m(C,v),C})()}),null),m(z,b(q,{get when(){return i()},get children(){return Ag()}}),null),m(y,b(Ai,{get value(){return c()},onChange:a}),null),m(x,b(Ai,{get value(){return l()},onChange:u}),null),m(L,(()=>{var v=te(()=>!!Wt());return()=>v()?`Marked at x=${Wt().tx}, y=${Wt().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(q,{get when(){return h().length>0},get fallback(){return zg()},get children(){var v=Ig();return v.firstChild,m(v,b($e,{get each(){return h()},children:([C,T])=>(()=>{var w=Gg(),M=w.firstChild,k=M.firstChild,E=k.nextSibling,D=E.nextSibling,I=D.nextSibling,H=I.firstChild,A=H.nextSibling,G=A.nextSibling,V=G.nextSibling;return V.nextSibling,m(E,C),m(D,()=>T.room),m(I,()=>T.x,A),m(I,()=>T.y,V),N(F=>X(k,"background",d(T.color))),w})()}),null),v}}),null),N(v=>{var C=f,T=`1px solid ${e()?"#f85149":"#30363d"}`,w=f,M=f;return v.e=Q(z,C,v.e),T!==v.t&&X(O,"border",v.t=T),v.a=Q(y,w,v.a),v.o=Q(x,M,v.o),v},{e:void 0,t:void 0,a:void 0,o:void 0}),N(()=>O.value=cr().name),p})()}Re(["input"]);var Hg=R("<span style=color:#8b949e>…"),Wg=R("<span style=color:#3fb950>✓"),Ug=R("<span style=color:#f85149>✗"),Yg=R("<div style=font-size:10px;color:#f85149>"),Xg=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>'),jg=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>'),Vg=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 qg(r){const e=Object.keys(Pi),[t,i]=B("idle"),[n,s]=B("");let o=null;const c=(p,g)=>{const S=Pi[p];return S?Vt()==="empty"&&p==="spawn"?Math.max(S[g]??0,1):S[g]??0:0},l=(p,g)=>{const S=c(p,g);if(S===2500)return 1/0;const P=Ei()[p]??0;return Math.max(0,S-P)},a=()=>dt().structureType==="spawn";he(Rl(()=>dt().structureType,(p,g)=>{if(p!=="spawn"||p===g)return;const S=ge();if(!S)return;i("loading"),s("");let P=!1;Ge(()=>{P=!0}),S.http.game.genUniqueObjectName("spawn",r.shard).then(z=>{P||(Gt({structureType:"spawn",structureName:z.name}),i("valid"))}).catch(()=>{P||(Gt({structureType:"spawn",structureName:"Spawn1"}),i("idle"))})}));const u=p=>{if(o&&clearTimeout(o),!p.trim()){i("invalid"),s("Name cannot be empty");return}i("loading"),s(""),o=setTimeout(()=>{const g=ge();g&&g.http.game.checkUniqueObjectName("spawn",p.trim(),r.shard).then(S=>{S.error?(i("invalid"),s(S.error)):(i("valid"),s(""))}).catch(()=>{i("invalid"),s("Could not validate name")})},400)},h=p=>{Gt({structureType:"spawn",structureName:p}),u(p)},d=p=>{Gt({structureType:p,structureName:""}),i("idle"),s("")},f=()=>{switch(t()){case"loading":return Hg();case"valid":return Wg();case"invalid":return Ug();default:return null}};return(()=>{var p=jg(),g=p.firstChild,S=g.firstChild;S.firstChild;var P=S.nextSibling,z=g.nextSibling;z.firstChild;var U=z.nextSibling,O=U.firstChild;return m(S,()=>Be()??"?",null),m(P,()=>{const y=Vt();return y==="empty"?"World is empty — place a spawn to claim this room.":y==="lost"?"You lost all your spawns — respawn to continue.":Be()!=null?`RCL ${Be()} — Select a structure type and click a tile to build.`:"No controller — roads and containers only."}),m(z,b($e,{each:e,children:y=>{const x=()=>Be()??0,L=()=>c(y,x()),v=()=>Ei()[y]??0,C=()=>dt().structureType===y,T=()=>L()===2500,w=()=>!T()&&l(y,x())<=0;return b(q,{get when(){return L()>0},get children(){var M=Vg(),k=M.firstChild,E=k.nextSibling;return M.$$click=()=>!w()&&d(y),m(k,()=>y.replace(/([A-Z])/g," $1").trim(),null),m(k,()=>C()&&" ✓",null),m(E,(()=>{var D=te(()=>!!T());return()=>D()?`${v()}/∞`:`${v()}/${L()}`})(),null),m(E,()=>w()&&" (Max)",null),N(D=>{var I=C()?"#1f3158":"transparent",H=w()?"default":"pointer",A=w()?.5:1;return I!==D.e&&X(M,"background",D.e=I),H!==D.t&&X(M,"cursor",D.t=H),A!==D.a&&X(M,"opacity",D.a=A),D},{e:void 0,t:void 0,a:void 0}),M}})}}),null),m(p,b(q,{get when(){return a()},get children(){var y=Xg(),x=y.firstChild,L=x.nextSibling,v=L.firstChild,C=v.firstChild,T=C.nextSibling;return C.$$input=w=>h(w.currentTarget.value),m(T,f),m(L,b(q,{get when(){return te(()=>t()==="invalid")()&&n()},get children(){var w=Yg();return m(w,n),w}}),null),N(w=>X(C,"border",`1px solid ${t()==="invalid"?"#f85149":t()==="valid"?"#238636":"#30363d"}`)),N(()=>C.value=dt().structureName??""),y}}),U),m(O,()=>dt().structureType?"Click a tile in the room to build.":"Select a structure type, then click a tile."),p})()}Re(["input","click"]);var Zg=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">'),Zs=R("<button type=button>"),Kg=R("<option>/s");const Jg=[.5,1,2,5,10,20],Qg=[{delta:-100,label:"-100"},{delta:-10,label:"-10"}],e0=[{delta:10,label:"+10"},{delta:100,label:"+100"}];function Ks(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 t0(){const r=()=>{const e=Xr(),t=ht(),i=xi()??3e3,n=(e-t)*i;return new Date(Date.now()-n).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})};return(()=>{var e=Zg(),t=e.firstChild,i=t.firstChild,n=i.firstChild,s=n.nextSibling;s.firstChild;var o=i.nextSibling,c=o.firstChild,l=o.nextSibling,a=l.firstChild,u=a.nextSibling;return m(n,(()=>{var h=te(()=>!!tt());return()=>h()?"Loading…":`Tick ${ht()}`})()),m(s,r,null),m(o,b($e,{each:Qg,children:h=>(()=>{var d=Zs();return d.$$click=()=>zs(h.delta),m(d,()=>h.label),N(f=>{var p=tt(),g=Ks(tt());return p!==f.e&&(d.disabled=f.e=p),f.t=Q(d,g,f.t),f},{e:void 0,t:void 0}),d})()}),c),lt(c,"click",Fh,!0),m(c,()=>Gr()?"⏸":"▶"),m(o,b($e,{each:e0,children:h=>(()=>{var d=Zs();return d.$$click=()=>zs(h.delta),m(d,()=>h.label),N(f=>{var p=tt(),g=Ks(tt());return p!==f.e&&(d.disabled=f.e=p),f.t=Q(d,g,f.t),f},{e:void 0,t:void 0}),d})()}),null),u.addEventListener("change",h=>Hh(parseFloat(h.currentTarget.value))),m(u,b($e,{each:Jg,children:h=>(()=>{var d=Kg(),f=d.firstChild;return d.value=h,m(d,h,f),d})()})),N(h=>{var d=tt()?"#f0883e":"#c9d1d9",f=tt(),p=Gr()?"#1a3a2a":"#161b22",g=Gr()?"#3fb950":"#8b949e",S=tt()?"not-allowed":"pointer";return d!==h.e&&X(n,"color",h.e=d),f!==h.t&&(c.disabled=h.t=f),p!==h.a&&X(c,"background",h.a=p),g!==h.o&&X(c,"color",h.o=g),S!==h.i&&X(c,"cursor",h.i=S),h},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),N(()=>u.value=as()),e})()}Re(["click"]);var r0=R("<div style=padding-bottom:8px;overflow:auto;min-height:0>"),i0=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'),n0=R("<button style=background:transparent;border:none;color:#8b949e;font-size:14px;cursor:pointer;padding:4px>"),s0=R("<button style=background:transparent;border:none;color:#8b949e;font-size:11px;cursor:pointer>Collapse");function o0(r){return b(q,{get when(){return St()==="flag"},get fallback(){return b(q,{get when(){return St()==="build"},get fallback(){return b(Up,{})},get children(){return b(qg,{get shard(){return r.shard}})}})},get children(){return b(Fg,{})}})}function l0(r){const e=()=>{var i;(i=r.onToggle)==null||i.call(r)},t=i=>{var n;i.stopPropagation(),(n=r.onToggle)==null||n.call(r)};return(()=>{var i=i0(),n=i.firstChild,s=n.nextSibling,o=s.firstChild;return o.firstChild,n.$$click=e,m(n,(()=>{var c=te(()=>!!r.onToggle);return()=>c()&&(()=>{var l=n0();return l.$$click=t,m(l,()=>r.isCollapsed?"▶":"◀"),l})()})()),m(o,(()=>{var c=te(()=>!!r.onToggle);return()=>c()&&(()=>{var l=s0();return l.$$click=t,l})()})(),null),m(s,b(q,{get when(){return r.mapMode},get fallback(){return b(Jp,{get room(){return r.room??"—"},get shard(){return r.shard??null}})},get children(){return b(Sg,{get zoom(){return r.mapZoom},get subsActive(){return r.mapSubsActive}})}}),null),m(s,b(q,{get when(){return te(()=>!r.mapMode)()&&be()},get children(){return b(t0,{})}}),null),m(s,b(q,{get when(){return r.mapMode},get fallback(){return b(o0,{get shard(){return r.shard}})},get children(){var c=r0();return m(c,b(qs,{label:"Selected",get info(){return r.selectedRoomInfo??null}}),null),m(c,b(qs,{label:"Cursor",get info(){return r.hoveredRoomInfo??null},dim:!0}),null),c}}),null),i})()}Re(["click"]);var a0=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>CPU:</span><span style=color:#c9d1d9>"),c0=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Memory:</span><span style=color:#c9d1d9>"),d0=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Zoom:</span><span style=color:#c9d1d9>%"),u0=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Subs:</span><span>"),h0=R('<div style="display:flex;gap:16px;padding:6px 16px;font-size:12px;color:#8b949e;align-items:center">');function f0(r){const[e,t]=B(null);Kt(()=>{const s=ge();if(!s)return;const o=new Kn;o.add(s.stores.user.subscribe("cpu")),o.add(s.stores.user.on("user:cpu",c=>{t(c)})),Ge(()=>{o.dispose()})});const i=()=>{var c;const s=e();if(!s)return"—";const o=((c=We())==null?void 0:c.cpu)??"?";return`${s.cpu.toFixed(1)} / ${o}`},n=()=>{const s=e();return s?`${(s.memory/1024).toFixed(1)} KB`:"—"};return(()=>{var s=h0();return m(s,b(q,{get when(){return e()!==null},get children(){return[(()=>{var o=a0(),c=o.firstChild,l=c.nextSibling;return m(l,i),o})(),(()=>{var o=c0(),c=o.firstChild,l=c.nextSibling;return m(l,n),o})()]}}),null),m(s,b(q,{get when(){return te(()=>r.mapZoom!==null)()&&r.mapZoom!==void 0},get children(){return[(()=>{var o=d0(),c=o.firstChild,l=c.nextSibling,a=l.firstChild;return m(l,()=>(r.mapZoom*100).toFixed(0),a),o})(),(()=>{var o=u0(),c=o.firstChild,l=c.nextSibling;return m(l,()=>r.mapSubsActive===!1?"paused":"active"),N(a=>X(l,"color",r.mapSubsActive===!1?"#e3b341":"#3fb950")),o})()]}}),null),s})()}var p0=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">'),g0=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>"),m0=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 $l={};for(let r=1;r<=24;r++){const e=Di({type:r,color1:"#4a5060",color2:"#7a9ec0",color3:"#c0daf0",param:0,flip:!1});$l[r]=`data:image/svg+xml,${encodeURIComponent(e)}`}function Lt(r){var e;return typeof r=="string"?r:((e=Ir[r])==null?void 0:e.rgb)??"#000000"}function di(r){return typeof r=="number"?Math.max(0,Math.min(79,r)):r}const v0=[{slot:1,label:"Background"},{slot:2,label:"Primary"},{slot:3,label:"Secondary"}],b0=Array.from({length:24},(r,e)=>e+1),cn=/^#[0-9a-f]{6}$/i;function w0(r){const[e,t]=B(de(()=>typeof r.badge.type=="number"?r.badge.type:1)),[i,n]=B(de(()=>di(r.badge.color1))),[s,o]=B(de(()=>di(r.badge.color2))),[c,l]=B(de(()=>di(r.badge.color3))),[a,u]=B(de(()=>r.badge.param??0)),[h,d]=B(de(()=>r.badge.flip??!1)),[f,p]=B(1),[g,S]=B(!1),[P,z]=B(de(()=>Lt(di(r.badge.color1)))),U=w=>w===1?i():w===2?s():c(),O=w=>{const M=f();M===1?n(w):M===2?o(w):l(w)};he(()=>{z(Lt(U(f())))});const y=w=>{var k;const M=U(f());return typeof M=="number"?M===w:M.toLowerCase()===(((k=Ir[w])==null?void 0:k.rgb)??"").toLowerCase()},x=()=>({type:e(),color1:Lt(i()),color2:Lt(s()),color3:Lt(c()),param:a(),flip:h()}),L=Fr(()=>{const w=Di(x());return`data:image/svg+xml,${encodeURIComponent(w)}`}),v=w=>{if(z(w),!cn.test(w))return;const M=Ir.findIndex(k=>k.rgb.toLowerCase()===w.toLowerCase());O(M>=0?M:w)},C=async()=>{var M;const w=ge();if(w){S(!0);try{await w.http.user.badge(x()),await w.stores.user.refreshMe(),r.onClose(),(M=r.onSaved)==null||M.call(r),Ce("Badge saved","success",3e3)}catch(k){Ce(`Failed to save badge: ${k instanceof Error?k.message:String(k)}`,"error",5e3)}finally{S(!1)}}},T=w=>{w.target===w.currentTarget&&r.onClose()};return(()=>{var w=p0(),M=w.firstChild,k=M.firstChild,E=k.firstChild,D=E.nextSibling,I=k.nextSibling,H=I.firstChild,A=H.firstChild,G=A.firstChild,V=G.nextSibling,F=A.nextSibling,Z=F.firstChild,j=Z.nextSibling,W=H.nextSibling,J=W.firstChild,ue=J.nextSibling,ae=ue.nextSibling,se=ae.nextSibling,me=se.firstChild,ee=me.nextSibling,fe=W.nextSibling,Ee=fe.firstChild,Oe=Ee.firstChild,je=Oe.nextSibling,Ke=Ee.nextSibling,Mt=fe.nextSibling,Je=Mt.firstChild,oe=I.nextSibling,ne=oe.firstChild,ce=ne.nextSibling;return w.$$click=T,D.$$click=()=>r.onClose(),m(D,b(qt,{size:18})),m(j,b($e,{each:b0,children:Y=>(()=>{var K=g0(),ie=K.firstChild;return K.$$click=()=>t(Y),N(xe=>{var Se=e()===Y?"#1f3a2a":"#0d1117",Ve=`1px solid ${e()===Y?"#238636":"#21262d"}`,gt=e()===Y?L():$l[Y];return Se!==xe.e&&X(K,"background",xe.e=Se),Ve!==xe.t&&X(K,"border",xe.t=Ve),gt!==xe.a&&_e(ie,"src",xe.a=gt),xe},{e:void 0,t:void 0,a:void 0}),K})()})),m(ue,b($e,{each:v0,children:({slot:Y,label:K})=>(()=>{var ie=m0(),xe=ie.firstChild;return ie.$$click=()=>p(Y),m(ie,K,null),N(Se=>{var Ve=`1px solid ${f()===Y?"#58a6ff":"#30363d"}`,gt=f()===Y?"#1c2d47":"transparent",$r=f()===Y?"#58a6ff":"#8b949e",Sr=Lt(U(Y));return Ve!==Se.e&&X(ie,"border",Se.e=Ve),gt!==Se.t&&X(ie,"background",Se.t=gt),$r!==Se.a&&X(ie,"color",Se.a=$r),Sr!==Se.o&&X(xe,"background",Se.o=Sr),Se},{e:void 0,t:void 0,a:void 0,o:void 0}),ie})()})),m(ae,b($e,{each:Ir,children:Y=>(()=>{var K=y0();return K.$$click=()=>O(Y.index),N(ie=>{var xe=Y.rgb,Se=Y.rgb,Ve=y(Y.index)?"2px solid #fff":"1px solid transparent";return xe!==ie.e&&_e(K,"title",ie.e=xe),Se!==ie.t&&X(K,"background",ie.t=Se),Ve!==ie.a&&X(K,"border",ie.a=Ve),ie},{e:void 0,t:void 0,a:void 0}),K})()})),ee.$$input=Y=>v(Y.currentTarget.value),m(je,a),Ke.$$input=Y=>u(+Y.currentTarget.value),Je.addEventListener("change",Y=>d(Y.currentTarget.checked)),ne.$$click=()=>r.onClose(),ce.$$click=C,m(ce,()=>g()?"Saving…":"Save Badge"),N(Y=>{var K=L(),ie=cn.test(P())?P():Lt(U(f())),xe=`1px solid ${cn.test(P())?"#30363d":"#f85149"}`,Se=g(),Ve=g()?"not-allowed":"pointer",gt=g(),$r=g()?"not-allowed":"pointer",Sr=g()?.7:1;return K!==Y.e&&_e(V,"src",Y.e=K),ie!==Y.t&&X(me,"background",Y.t=ie),xe!==Y.a&&X(ee,"border",Y.a=xe),Se!==Y.o&&(ne.disabled=Y.o=Se),Ve!==Y.i&&X(ne,"cursor",Y.i=Ve),gt!==Y.n&&(ce.disabled=Y.n=gt),$r!==Y.s&&X(ce,"cursor",Y.s=$r),Sr!==Y.h&&X(ce,"opacity",Y.h=Sr),Y},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0}),N(()=>ee.value=P()),N(()=>Ke.value=a()),N(()=>Je.checked=h()),w})()}Re(["click","input"]);var x0=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">'),_0=R("<div style=font-size:11px;color:#8b949e;margin-top:3px>"),$0=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>"),S0=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>'),C0=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)'),k0=R("<img width=40 height=40 style=display:block>"),T0=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">'),M0=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">'),E0=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 R0={type:1,color1:"#4a5060",color2:"#7a9ec0",color3:"#c0daf0",param:0,flip:!1};function wt(r){return(()=>{var e=x0(),t=e.firstChild,i=t.firstChild,n=t.nextSibling,s=n.firstChild;return m(i,()=>r.label),m(t,(()=>{var o=te(()=>!!r.description);return()=>o()&&(()=>{var c=_0();return m(c,()=>r.description),c})()})(),null),n.$$click=()=>r.onChange(!r.value),N(o=>{var c=r.value?"#238636":"#30363d",l=r.value?"22px":"2px";return c!==o.e&&X(n,"background",o.e=c),l!==o.t&&X(s,"left",o.t=l),o},{e:void 0,t:void 0}),e})()}function nr(r){return(()=>{var e=$0(),t=e.firstChild;return m(t,()=>r.title),m(e,()=>r.children,null),e})()}function Js(r){return(()=>{var e=S0(),t=e.firstChild,i=t.nextSibling;return m(t,()=>r.label),m(i,()=>r.value),e})()}function O0(r){var a;const e=Ua(),t=!Le()&&!((a=We())!=null&&a.badge),[i,n]=B(t),[s,o]=B(!1),c=Fr(()=>{var d;const u=(d=We())==null?void 0:d.badge;if(!u)return null;const h=Di(u);return`data:image/svg+xml,${encodeURIComponent(h)}`});async function l(){o(!0);try{await Xa(),Ce("All caches cleared. Reloading…","success",2e3),setTimeout(()=>window.location.reload(),1500)}catch{Ce("Failed to clear caches.","error"),o(!1)}}return(()=>{var u=E0(),h=u.firstChild,d=h.firstChild,f=d.nextSibling,p=h.nextSibling,g=p.firstChild;return f.$$click=()=>r.onClose(),m(f,b(qt,{size:18})),m(u,b(q,{get when(){return i()},get children(){return b(w0,{get badge(){var S;return((S=We())==null?void 0:S.badge)??R0},onClose:()=>n(!1),onSaved:t?()=>r.onClose():void 0})}}),p),m(g,b(nr,{title:"Layout",get children(){return b(wt,{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 Fo()},onChange:vh})}}),null),m(g,b(nr,{title:"Room View",get children(){return[b(wt,{label:"Show creep labels",description:"Display each creep's name above its sprite.",get value(){return ki()},onChange:Ho}),b(wt,{label:"Terrain effects",description:"Swamp glow and wall noise texture overlay.",get value(){return lr()},onChange:bh}),b(wt,{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 Vo()},onChange:Sh}),b(wt,{label:"Room decorations",description:"Load player-activated theme decorations (floor, wall, road colors) from the server.",get value(){return Gn()},onChange:wh}),b(wt,{label:"Dark overlay + lights",description:"Darken the room and add per-object light glows.",get value(){return Bn()},onChange:xh}),(()=>{var S=C0(),P=S.firstChild,z=P.nextSibling;return z.addEventListener("change",U=>$h(U.currentTarget.value)),N(()=>z.value=Fn()),S})()]}}),null),m(g,b(nr,{title:"Map View",get children(){return[b(wt,{label:"Show room names",description:"Render a small room name in the top-left corner of each map tile.",get value(){return Wo()},onChange:Uo}),b(wt,{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 Yo()},onChange:Xo})]}}),null),m(g,b(q,{get when(){return!Le()},get children(){return b(nr,{title:"Player Badge",get children(){var S=T0(),P=S.firstChild,z=P.firstChild,U=P.nextSibling;return m(P,b(q,{get when(){return c()},get children(){var O=k0();return N(()=>_e(O,"src",c())),O}}),z),m(z,()=>{var O;return((O=We())==null?void 0:O.username)??""}),U.$$click=()=>n(!0),m(U,()=>c()?"Edit Badge":"Create Badge"),S}})}}),null),m(g,b(nr,{title:"Data",get children(){var S=M0(),P=S.firstChild,z=P.firstChild;z.nextSibling;var U=P.nextSibling;return U.$$click=l,m(U,()=>s()?"Clearing…":"Clear"),N(O=>{var y=s(),x=s()?"#8b949e":"#f85149",L=s()?"default":"pointer",v=s()?.6:1;return y!==O.e&&(U.disabled=O.e=y),x!==O.t&&X(U,"color",O.t=x),L!==O.a&&X(U,"cursor",O.a=L),v!==O.o&&X(U,"opacity",O.o=v),O},{e:void 0,t:void 0,a:void 0,o:void 0}),S}}),null),m(g,b(nr,{title:"About",get children(){return[b(Js,{label:"Client version",get value(){return Wa()}}),te(()=>e&&b(Js,{label:"Mod version",get value(){return`${e.version} (${e.kind})`}}))]}}),null),u})()}Re(["click"]);var P0=R('<button style="padding:7px;border-radius:4px;cursor:pointer;margin:0 4px;display:flex;align-items:center">'),L0=R('<button style="padding:7px;border-radius:4px;border:1px solid #30363d;background:#21262d;margin:0 2px;display:flex;align-items:center">'),A0=R("<div style=flex:1;position:relative;overflow:hidden>"),I0=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>'),N0=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>'),D0=R("<div style=display:flex;flex:1;overflow:hidden><div style=display:flex;flex-direction:column;flex:1;overflow:hidden>"),z0=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">'),G0=R("<div style=display:flex;flex-direction:column;flex:1;overflow:hidden><div style=display:flex;flex:1;overflow:hidden>");const B0=ro(()=>Zn(()=>import("./CodePanel-KBQ78175.js"),__vite__mapDeps([0,1,2])).then(r=>({default:r.CodePanel}))),F0=ro(()=>Zn(()=>import("./MapViewer-BL7mzGWw.js"),__vite__mapDeps([3,1,2])).then(r=>({default:r.MapViewer})));function dn(){const r=Gi(),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(!ct(t))return{room:null,shard:null,tick:null};const i=new URLSearchParams(window.location.search).get("shard"),n=window.location.hash.match(/tick=(\d+)/),s=n?parseInt(n[1],10):null;return{room:t,shard:i,tick:s}}function un(r,e){return`${Gi()}/room/${r}${e?`?shard=${encodeURIComponent(e)}`:""}`}function Qs(r){return`${Gi()}/map${r?`?shard=${encodeURIComponent(r)}`:""}`}function hn(){return window.location.pathname.startsWith(`${Gi()}/map`)?{shard:new URLSearchParams(window.location.search).get("shard")}:null}function fn(r){return(()=>{var e=P0();return e.$$click=()=>r.onClick(),m(e,()=>r.children),N(t=>{var i=r.title,n=`1px solid ${r.active?"#388bfd":"#30363d"}`,s=r.active?"#1f3158":"#21262d",o=r.active?"#58a6ff":"#c9d1d9";return i!==t.e&&_e(e,"title",t.e=i),n!==t.t&&X(e,"border",t.t=n),s!==t.a&&X(e,"background",t.a=s),o!==t.o&&X(e,"color",t.o=o),t},{e:void 0,t:void 0,a:void 0,o:void 0}),e})()}function eo(r){return(()=>{var e=L0();return e.$$click=()=>r.onClick(),m(e,()=>r.children),N(t=>{var i=r.title,n=r.disabled,s=r.disabled?"#484f58":"#c9d1d9",o=r.disabled?"default":"pointer";return i!==t.e&&_e(e,"title",t.e=i),n!==t.t&&(e.disabled=t.t=n),s!==t.a&&X(e,"color",t.a=s),o!==t.o&&X(e,"cursor",t.o=o),t},{e:void 0,t:void 0,a:void 0,o:void 0}),e})()}function H0(){var Je;const r=dn(),[e,t]=B(r.room??Wi(ye.room)??"W1N1"),[i,n]=B(r.shard??Wi(ye.shard)),[s,o]=B(hn()!==null||!r.room),[c,l]=B(!Le()&&!((Je=We())!=null&&Je.badge)),[a,u]=B(!1),[h,d]=B(!1);he(()=>{a(),d(!0),Promise.resolve().then(()=>d(!1))}),he(()=>{Le()&&$t("view")}),he(()=>{var ne,ce,Y;if(i()!==null||xo()!==!1)return;const oe=(Y=(ce=(ne=es())==null?void 0:ne.serverData)==null?void 0:ce.shards)==null?void 0:Y[0];oe&&n(oe)});const[f,p]=B(void 0),[g,S]=B(null),[P,z]=B(null),U=Wi(ye.mapZoom),[O,y]=B(r.room&&U?Number(U):null),[x,L]=B(null),[v,C]=B(!1),[T,w]=B(!1);let M=r.tick;he(()=>{const oe=Fe();if(oe===null||M===null)return;const ne=M;M=null,ol(oe),Oi(ne)}),he(()=>{if(de(s))return;const oe=un(e(),i());be()?history.replaceState(null,"",`${oe}#tick=${ht()}`):history.replaceState(null,"",oe)});const[k,E]=B(Qr(ye.sidebarWidth,300)),[D,I]=B(Qr(ye.sidebarWidth,300)),[H,A]=B(Qr(ye.consoleHeight,220)),[G,V]=B(Qr(ye.consoleHeight,220)),[F,Z]=B(!1),[j,W]=B(!1),J=()=>k()<=32,ue=()=>H()<=32,ae=()=>{k()>32?(I(k()),E(32)):E(D())},se=()=>{H()>32?(V(H()),A(32)):A(G())},me=oe=>{oe.preventDefault(),Z(!0);const ne=oe.clientX,ce=k(),Y=ie=>{const xe=ie.clientX-ne;E(Math.max(32,Math.min(500,ce-xe)))},K=()=>{Z(!1),Ui(ye.sidebarWidth,k()),window.removeEventListener("pointermove",Y),window.removeEventListener("pointerup",K)};window.addEventListener("pointermove",Y),window.addEventListener("pointerup",K)},ee=oe=>{oe.preventDefault(),W(!0);const ne=oe.clientY,ce=H(),Y=ie=>{const xe=ie.clientY-ne;A(Math.max(32,Math.min(500,ce-xe)))},K=()=>{W(!1),Ui(ye.consoleHeight,H()),window.removeEventListener("pointermove",Y),window.removeEventListener("pointerup",K)};window.addEventListener("pointermove",Y),window.addEventListener("pointerup",K)},fe=(oe,ne)=>{var ce;(ce=ge())==null||ce.stores.navigation.navigateTo(oe,ne)},Ee=oe=>{p(oe),o(!0),history.pushState(null,"",Qs(i()))},Oe=()=>{s()?(o(!1),S(null),z(null),history.pushState(null,"",un(e(),i()))):Ee(e())};Kt(()=>{var Y;!dn().room&&!hn()&&history.replaceState(null,"",Qs(i()));const oe=()=>{const K=hn();if(K){o(!0),K.shard!==null&&n(K.shard),de(be)&&Ri();return}const{room:ie,shard:xe,tick:Se}=dn();ie&&(t(ie),n(xe),o(!1),Se!==null?M=Se:de(be)&&Ri())};window.addEventListener("popstate",oe),Ge(()=>window.removeEventListener("popstate",oe));const ne=(Y=ge())==null?void 0:Y.stores.navigation;if(ne){const K=ne.on("navigation:change",ie=>{ie.room!==null&&(t(ie.room),n(ie.shard),o(!1),S(null),z(null),C(ne.canBack()),w(ne.canForward()),ys(ye.room,ie.room),ie.shard?ys(ye.shard,ie.shard):Ya(ye.shard),history.pushState(null,"",un(ie.room,ie.shard)))});Ge(()=>K.dispose())}const ce=K=>{if(!rl(K.target)){if(K.key==="o"||K.key==="O"){u(ie=>!ie),l(!1);return}(K.key==="l"||K.key==="L")&&ul(),(K.key==="c"||K.key==="C")&&hl(),(K.key==="y"||K.key==="Y")&&fl(),s()||(K.key==="1"&&$t("view"),Le()||(K.key==="2"&&$t("flag"),K.key==="3"&&$t("build")),K.key==="m"&&Ee(e()))}};window.addEventListener("keydown",ce),Ge(()=>window.removeEventListener("keydown",ce))});const je=()=>(()=>{var oe=A0();return m(oe,b(q,{get when(){return c()},get children(){return b(O0,{onClose:()=>l(!1)})}}),null),m(oe,b(q,{get when(){return a()},get children(){return b(B0,{onClose:()=>u(!1)})}}),null),m(oe,b(q,{get when(){return!s()},get fallback(){return b(F0,{get shard(){return i()},get originRoom(){return f()},get initialZoom(){return O()??void 0},onNavigateToRoom:ne=>fe(ne,i()),onHoveredRoomChanged:S,onSelectedRoomChanged:z,onZoomChanged:ne=>{y(ne),Ui(ye.mapZoom,ne)},onSubscriptionStateChanged:L})},get children(){return b(sf,{get room(){return e()},get shard(){return i()},onNavigate:fe})}}),null),oe})(),Ke=()=>b(q,{get when(){return!Le()},get children(){var oe=I0(),ne=oe.firstChild;return ne.$$pointerdown=ee,m(oe,b(Uf,{get shard(){return i()},get isCollapsed(){return ue()},onToggle:se}),null),N(ce=>{var Y=`${H()}px`,K=j()?"none":"height 0.15s ease";return Y!==ce.e&&X(oe,"height",ce.e=Y),K!==ce.t&&X(oe,"transition",ce.t=K),ce},{e:void 0,t:void 0}),oe}}),Mt=oe=>(()=>{var ne=N0(),ce=ne.firstChild;return ce.$$pointerdown=me,m(ne,b(l0,{get isCollapsed(){return J()},onToggle:ae,get mapMode(){return s()},get hoveredRoomInfo(){return g()},get selectedRoomInfo(){return P()},get room(){return e()},get shard(){return i()},get mapZoom(){return O()},get mapSubsActive(){return x()}}),null),N(Y=>{var K=a()?"0":`${k()}px`,ie=oe&&!(h()||F())?"width 0.15s ease":"none";return K!==Y.e&&X(ne,"width",Y.e=K),ie!==Y.t&&X(ne,"transition",Y.t=ie),Y},{e:void 0,t:void 0}),ne})();return(()=>{var oe=z0(),ne=oe.firstChild,ce=ne.firstChild,Y=ce.nextSibling;return m(ne,b(Zd,{}),ce),m(ne,b(q,{get when(){return!Le()||s()},get children(){return b(f0,{get mapZoom(){return te(()=>!!s())()?O():null},get mapSubsActive(){return te(()=>!!s())()?x():null}})}}),ce),m(ne,b(eo,{title:"Back",get disabled(){return!v()},onClick:()=>{var K;return(K=ge())==null?void 0:K.stores.navigation.back()},get children(){return b(wc,{size:16})}}),Y),m(ne,b(eo,{title:"Forward",get disabled(){return!T()},onClick:()=>{var K;return(K=ge())==null?void 0:K.stores.navigation.forward()},get children(){return b($o,{size:16})}}),Y),m(ne,b(fn,{get title(){return s()?"Room View":"Map"},get active(){return s()},onClick:Oe,get children(){return te(()=>!!s())()?b(Nc,{size:16}):b(Vc,{size:16})}}),Y),m(ne,b(q,{get when(){return!Le()},get children(){return b(fn,{title:"Code Editor",get active(){return a()},onClick:()=>{u(K=>!K),l(!1)},get children(){return b(kc,{size:16})}})}}),Y),m(ne,b(fn,{title:"Settings",get active(){return c()},onClick:()=>{l(K=>!K),u(!1)},get children(){return b(hd,{size:16})}}),Y),lt(Y,"click",Ja,!0),m(Y,(()=>{var K=te(()=>!!Le());return()=>K()?b(Hc,{size:16}):b(Yc,{size:16})})()),m(oe,b(q,{get when(){return Fo()},get fallback(){return(()=>{var K=G0(),ie=K.firstChild;return m(ie,je,null),m(ie,()=>Mt(!0),null),m(K,Ke,null),K})()},get children(){var K=D0(),ie=K.firstChild;return m(ie,je,null),m(ie,Ke,null),m(K,()=>Mt(!1),null),K}}),null),m(oe,b(af,{}),null),N(K=>{var ie=Le()?"Login":"Logout",xe=Le()?"#238636":"#da3633";return ie!==K.e&&_e(Y,"title",K.e=ie),xe!==K.t&&X(Y,"background",K.t=xe),K},{e:void 0,t:void 0}),oe})()}Re(["click","pointerdown"]);var W0=R("<div style=width:100%;height:100%>");function U0(){const r=new URLSearchParams(window.location.search).get("guest");return r===null?null:r.startsWith("http")?r:ui(He.url)??"https://screeps.com"}function Y0(){const r=()=>Ft()==="connected"&&ge()!==null;return Kt(async()=>{if(Ft()==="idle"&&(await Ka().catch(()=>{}),Ft()!=="connected"&&!zi())){const e=U0();e&&zt({url:e,auth:"guest",storage:null}).catch(()=>{})}}),(()=>{var e=W0();return m(e,(()=>{var t=te(()=>!!r());return()=>t()?b(H0,{}):b(jd,{})})()),e})()}const Sl=document.getElementById("root");if(!Sl)throw new Error("Root element not found");Yl(()=>b(Y0,{}),Sl);export{K0 as M,Ce as a,Tt as b,ge as c,Re as d,q0 as e,qe as f,Z0 as g,Un as h,m as i,vo as j,Wo as k,Yo as l,Qp as m,zh as n,We as o,ct as p,X as s,R as t,dr as u,Yi as w};