screeps-client 0.3.0 → 0.3.2

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.
@@ -1,4 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodePanel-BCwhfeJ7.js","assets/vendor-codemirror-BbK0dVBs.js","assets/vendor-pixi-c1qrZX58.js","assets/MapViewer-DoywRdNM.js"])))=>i.map(i=>d[i]);
2
- var ln=Object.defineProperty;var cn=(s,e,t)=>e in s?ln(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var m=(s,e,t)=>cn(s,typeof e!="symbol"?e+"":e,t);import{k as hi,j as H,i as Ns,u as hs,t as dn,s as ge,$ as hn,l as A,f as E,S as q,F as pe,h as he,p as Se,D as un,a as Ke,d as fn,b as Sr,m as Ds,q as Wt,o as ui}from"./vendor-codemirror-BbK0dVBs.js";import{a as xe,G as X,A as fi,P as Ct,R as pn,c as At,T as yt,S as us,b as gn,C as mn,_ as pi}from"./vendor-pixi-c1qrZX58.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const n of i)if(n.type==="childList")for(const a of n.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&r(a)}).observe(document,{childList:!0,subtree:!0});function t(i){const n={};return i.integrity&&(n.integrity=i.integrity),i.referrerPolicy&&(n.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?n.credentials="include":i.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function r(i){if(i.ep)return;i.ep=!0;const n=t(i);fetch(i.href,n)}})();const yn=["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"],wn=new Set(["className","value","readOnly","noValidate","formNoValidate","isMap","noModule","playsInline","adAuctionHeaders","allowFullscreen","browsingTopics","defaultChecked","defaultMuted","defaultSelected","disablePictureInPicture","disableRemotePlayback","preservesPitch","shadowRootClonable","shadowRootCustomElementRegistry","shadowRootDelegatesFocus","shadowRootSerializable","sharedStorageWritable",...yn]),bn=new Set(["innerHTML","textContent","innerText","children"]),vn=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),xn=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 _n(s,e){const t=xn[s];return typeof t=="object"?t[e]?t.$:void 0:t}const $n=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),Sn=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"]),Cn={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},ne=s=>Ns(()=>s());function kn(s,e,t){let r=t.length,i=e.length,n=r,a=0,o=0,l=e[i-1].nextSibling,c=null;for(;a<i||o<n;){if(e[a]===t[o]){a++,o++;continue}for(;e[i-1]===t[n-1];)i--,n--;if(i===a){const d=n<r?o?t[o-1].nextSibling:t[n-o]:l;for(;o<n;)s.insertBefore(t[o++],d)}else if(n===o)for(;a<i;)(!c||!c.has(e[a]))&&e[a].remove(),a++;else if(e[a]===t[n-1]&&t[o]===e[i-1]){const d=e[--i].nextSibling;s.insertBefore(t[o++],e[a++].nextSibling),s.insertBefore(t[--n],d),e[i]=t[n]}else{if(!c){c=new Map;let h=o;for(;h<n;)c.set(t[h],h++)}const d=c.get(e[a]);if(d!=null)if(o<d&&d<n){let h=a,u=1,f;for(;++h<i&&h<n&&!((f=c.get(e[h]))==null||f!==d+u);)u++;if(u>d-o){const p=e[a];for(;o<d;)s.insertBefore(t[o++],p)}else s.replaceChild(t[o++],e[a++])}else a++;else e[a++].remove()}}}const Cr="_$DX_DELEGATE";function Tn(s,e,t,r={}){if(!e)throw new Error("The `element` passed to `render(..., element)` doesn't exist. Make sure `element` exists in the document.");let i;return hi(n=>{i=n,e===document?s():w(e,s(),e.firstChild?null:void 0,t)},r.owner),()=>{i(),e.textContent=""}}function R(s,e,t,r){let i;const n=()=>{if(ze())throw new Error("Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration.");const o=document.createElement("template");return o.innerHTML=s,o.content.firstChild},a=()=>(i||(i=n())).cloneNode(!0);return a.cloneNode=a,a}function _e(s,e=window.document){const t=e[Cr]||(e[Cr]=new Set);for(let r=0,i=s.length;r<i;r++){const n=s[r];t.has(n)||(t.add(n),e.addEventListener(n,Gn))}}function Hs(s,e,t){ze(s)||(t==null?s.removeAttribute(e):s.setAttribute(e,t))}function Mn(s,e,t,r){ze(s)||(r==null?s.removeAttributeNS(e,t):s.setAttributeNS(e,t,r))}function Rn(s,e,t){ze(s)||(t?s.setAttribute(e,""):s.removeAttribute(e))}function En(s,e){ze(s)||(e==null?s.removeAttribute("class"):s.className=e)}function fs(s,e,t,r){if(r)Array.isArray(t)?(s[`$$${e}`]=t[0],s[`$$${e}Data`]=t[1]):s[`$$${e}`]=t;else if(Array.isArray(t)){const i=t[0];s.addEventListener(e,t[0]=n=>i.call(s,t[1],n))}else s.addEventListener(e,t,typeof t!="function"&&t)}function On(s,e,t={}){const r=Object.keys(e||{}),i=Object.keys(t);let n,a;for(n=0,a=i.length;n<a;n++){const o=i[n];!o||o==="undefined"||e[o]||(kr(s,o,!1),delete t[o])}for(n=0,a=r.length;n<a;n++){const o=r[n],l=!!e[o];!o||o==="undefined"||t[o]===l||!l||(kr(s,o,!0),t[o]=l)}return t}function ue(s,e,t){if(!e)return t?Hs(s,"style"):e;const r=s.style;if(typeof e=="string")return r.cssText=e;typeof t=="string"&&(r.cssText=t=void 0),t||(t={}),e||(e={});let i,n;for(n in t)e[n]==null&&r.removeProperty(n),delete t[n];for(n in e)i=e[n],i!==t[n]&&(r.setProperty(n,i),t[n]=i);return t}function U(s,e,t){t!=null?s.style.setProperty(e,t):s.style.removeProperty(e)}function Ln(s,e={},t,r){const i={};return H(()=>i.children=zt(s,e.children,i.children)),H(()=>typeof e.ref=="function"&&Nt(e.ref,s)),H(()=>Pn(s,e,t,!0,i,!0)),i}function Nt(s,e,t){return hs(()=>s(e,t))}function w(s,e,t,r){if(t!==void 0&&!r&&(r=[]),typeof e!="function")return zt(s,e,r,t);H(i=>zt(s,e(),i,t),r)}function Pn(s,e,t,r,i={},n=!1){e||(e={});for(const a in i)if(!(a in e)){if(a==="children")continue;i[a]=Tr(s,a,null,i[a],t,n,e)}for(const a in e){if(a==="children")continue;const o=e[a];i[a]=Tr(s,a,o,i[a],t,n,e)}}function An(s){let e,t,r=ze();if(!r||!(e=ge.registry.get(t=Nn()))){if(r)throw ge.done=!0,new Error(`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${t}
3
- `);return s()}return ge.completed&&ge.completed.add(e),ge.registry.delete(t),e}function ze(s){return!!ge.context&&!ge.done&&(!s||s.isConnected)}function In(s){return s.toLowerCase().replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function kr(s,e,t){const r=e.trim().split(/\s+/);for(let i=0,n=r.length;i<n;i++)s.classList.toggle(r[i],t)}function Tr(s,e,t,r,i,n,a){let o,l,c,d,h;if(e==="style")return ue(s,t,r);if(e==="classList")return On(s,t,r);if(t===r)return r;if(e==="ref")n||t(s);else if(e.slice(0,3)==="on:"){const u=e.slice(3);r&&s.removeEventListener(u,r,typeof r!="function"&&r),t&&s.addEventListener(u,t,typeof t!="function"&&t)}else if(e.slice(0,10)==="oncapture:"){const u=e.slice(10);r&&s.removeEventListener(u,r,!0),t&&s.addEventListener(u,t,!0)}else if(e.slice(0,2)==="on"){const u=e.slice(2).toLowerCase(),f=$n.has(u);if(!f&&r){const p=Array.isArray(r)?r[0]:r;s.removeEventListener(u,p)}(f||t)&&(fs(s,u,t,f),f&&_e([u]))}else if(e.slice(0,5)==="attr:")Hs(s,e.slice(5),t);else if(e.slice(0,5)==="bool:")Rn(s,e.slice(5),t);else if((h=e.slice(0,5)==="prop:")||(c=bn.has(e))||!i&&((d=_n(e,s.tagName))||(l=wn.has(e)))||(o=s.nodeName.includes("-")||"is"in a)){if(h)e=e.slice(5),l=!0;else if(ze(s))return t;e==="class"||e==="className"?En(s,t):o&&!l&&!c?s[In(e)]=t:s[d||e]=t}else{const u=i&&e.indexOf(":")>-1&&Cn[e.split(":")[0]];u?Mn(s,u,e,t):Hs(s,vn[e]||e,t)}return t}function Gn(s){if(ge.registry&&ge.events&&ge.events.find(([l,c])=>c===s))return;let e=s.target;const t=`$$${s.type}`,r=s.target,i=s.currentTarget,n=l=>Object.defineProperty(s,"target",{configurable:!0,value:l}),a=()=>{const l=e[t];if(l&&!e.disabled){const c=e[`${t}Data`];if(c!==void 0?l.call(e,c,s):l.call(e,s),s.cancelBubble)return}return e.host&&typeof e.host!="string"&&!e.host._$host&&e.contains(s.target)&&n(e.host),!0},o=()=>{for(;a()&&(e=e._$host||e.parentNode||e.host););};if(Object.defineProperty(s,"currentTarget",{configurable:!0,get(){return e||document}}),ge.registry&&!ge.done&&(ge.done=_$HY.done=!0),s.composedPath){const l=s.composedPath();n(l[0]);for(let c=0;c<l.length-2&&(e=l[c],!!a());c++){if(e._$host){e=e._$host,o();break}if(e.parentNode===i)break}}else o();n(r)}function zt(s,e,t,r,i){const n=ze(s);if(n){!t&&(t=[...s.childNodes]);let l=[];for(let c=0;c<t.length;c++){const d=t[c];d.nodeType===8&&d.data.slice(0,2)==="!$"?d.remove():l.push(d)}t=l}for(;typeof t=="function";)t=t();if(e===t)return t;const a=typeof e,o=r!==void 0;if(s=o&&t[0]&&t[0].parentNode||s,a==="string"||a==="number"){if(n||a==="number"&&(e=e.toString(),e===t))return t;if(o){let l=t[0];l&&l.nodeType===3?l.data!==e&&(l.data=e):l=document.createTextNode(e),t=st(s,t,r,l)}else t!==""&&typeof t=="string"?t=s.firstChild.data=e:t=s.textContent=e}else if(e==null||a==="boolean"){if(n)return t;t=st(s,t,r)}else{if(a==="function")return H(()=>{let l=e();for(;typeof l=="function";)l=l();t=zt(s,l,t,r)}),()=>t;if(Array.isArray(e)){const l=[],c=t&&Array.isArray(t);if(Bs(l,e,t,i))return H(()=>t=zt(s,l,t,r,!0)),()=>t;if(n){if(!l.length)return t;if(r===void 0)return t=[...s.childNodes];let d=l[0];if(d.parentNode!==s)return t;const h=[d];for(;(d=d.nextSibling)!==r;)h.push(d);return t=h}if(l.length===0){if(t=st(s,t,r),o)return t}else c?t.length===0?Mr(s,l,r):kn(s,t,l):(t&&st(s),Mr(s,l));t=l}else if(e.nodeType){if(n&&e.parentNode)return t=o?[e]:e;if(Array.isArray(t)){if(o)return t=st(s,t,r,e);st(s,t,null,e)}else t==null||t===""||!s.firstChild?s.appendChild(e):s.replaceChild(e,s.firstChild);t=e}else console.warn("Unrecognized value. Skipped inserting",e)}return t}function Bs(s,e,t,r){let i=!1;for(let n=0,a=e.length;n<a;n++){let o=e[n],l=t&&t[s.length],c;if(!(o==null||o===!0||o===!1))if((c=typeof o)=="object"&&o.nodeType)s.push(o);else if(Array.isArray(o))i=Bs(s,o,l)||i;else if(c==="function")if(r){for(;typeof o=="function";)o=o();i=Bs(s,Array.isArray(o)?o:[o],Array.isArray(l)?l:[l])||i}else s.push(o),i=!0;else{const d=String(o);l&&l.nodeType===3&&l.data===d?s.push(l):s.push(document.createTextNode(d))}}return i}function Mr(s,e,t=null){for(let r=0,i=e.length;r<i;r++)s.insertBefore(e[r],t)}function st(s,e,t,r){if(t===void 0)return s.textContent="";const i=r||document.createTextNode("");if(e.length){let n=!1;for(let a=e.length-1;a>=0;a--){const o=e[a];if(i!==o){const l=o.parentNode===s;!n&&!a?l?s.replaceChild(i,o):s.insertBefore(i,t):l&&o.remove()}else n=!0}}else s.insertBefore(i,t);return[i]}function Nn(){return ge.getNextContextId()}const Dn="http://www.w3.org/2000/svg";function Hn(s,e=!1,t=void 0){return e?document.createElementNS(Dn,s):document.createElement(s,{is:t})}function Bn(s,e){const t=Ns(s);return Ns(()=>{const r=t();switch(typeof r){case"function":return Object.assign(r,{[hn]:!0}),hs(()=>r(e));case"string":const i=Sn.has(r),n=ge.context?An():Hn(r,i,hs(()=>e.is));return Ln(n,e,i),n}})}function zn(s){const[,e]=dn(s,["component"]);return Bn(()=>s.component,e)}async function gi(s,e){const t=s.slice(3),r=Uint8Array.from(atob(t),h=>h.charCodeAt(0)),i=new DecompressionStream(e),n=i.writable.getWriter();await n.write(r),await n.close();const a=i.readable.getReader(),o=[];try{for(;;){const{done:h,value:u}=await a.read();if(h)break;o.push(u)}}catch(h){throw a.cancel(),h}let l=0;for(const h of o)l+=h.length;const c=new Uint8Array(l);let d=0;for(const h of o)c.set(h,d),d+=h.length;return JSON.parse(new TextDecoder().decode(c))}function Fn(s){return gi(s,"gzip")}function Un(s){return gi(s,"deflate")}class Le{constructor(e){m(this,"fn");this.fn=e}static create(e){return e===!0?new Le(console.debug.bind(console)):typeof e=="function"?new Le(e):new Le(null)}child(e){if(!this.fn)return this;const t=this.fn;return new Le((...r)=>t(`[screeps:${e}]`,...r))}log(...e){var t;(t=this.fn)==null||t.call(this,...e)}}function Wn(s){return{signin:(e,t)=>s.request("POST","/api/auth/signin",{email:e,password:t}),me:()=>s.request("GET","/api/auth/me"),queryToken:e=>s.request("GET","/api/auth/query-token",{token:e}),steamTicket:(e,t)=>s.request("POST","/api/auth/steam-ticket",{ticket:e,...t!=null?{useNativeAuth:t}:{}}),modInfo:()=>s.request("GET","/api/authmod")}}function Xn(s){return{list:()=>s.request("GET","/api/game/power-creeps/list"),create:(e,t)=>s.request("POST","/api/game/power-creeps/create",{name:e,className:t}),delete:e=>s.request("POST","/api/game/power-creeps/delete",{id:e}),cancelDelete:e=>s.request("POST","/api/game/power-creeps/cancel-delete",{id:e}),upgrade:(e,t)=>s.request("POST","/api/game/power-creeps/upgrade",{id:e,powers:t}),rename:(e,t)=>s.request("POST","/api/game/power-creeps/rename",{id:e,name:t}),experimentation:()=>s.request("POST","/api/game/power-creeps/experimentation")}}function me(s,e){return e&&(s.shard=e),s}function Yn(s){return{roomTerrain:(e,t)=>s.request("GET","/api/game/room-terrain",me({room:e,encoded:1},t)),roomObjects:(e,t)=>s.request("GET","/api/game/room-objects",me({room:e},t)),roomStatus:(e,t)=>s.request("GET","/api/game/room-status",me({room:e},t)),roomOverview:(e,t=8,r)=>s.request("GET","/api/game/room-overview",me({room:e,interval:t},r)),time:e=>s.request("GET","/api/game/time",me({},e)),worldSize:e=>s.request("GET","/api/game/world-size",me({},e)),mapStats:(e,t,r)=>s.request("POST","/api/game/map-stats",me({rooms:e,statName:t},r)),roomsTerrain:(e,t)=>{const r=new URLSearchParams({encoded:"true"});return t&&r.set("shard",t),s.request("POST",`/api/game/rooms?${r}`,{rooms:e})},createFlag:(e,t,r,i,n,a,o)=>s.request("POST","/api/game/create-flag",me({room:e,x:t,y:r,name:i,color:n,secondaryColor:a},o)),genUniqueFlagName:()=>s.request("POST","/api/game/gen-unique-flag-name"),checkUniqueFlagName:e=>s.request("POST","/api/game/check-unique-flag-name",{name:e}),changeFlagColor:(e,t,r,i)=>s.request("POST","/api/game/change-flag-color",{room:e,name:t,color:r,secondaryColor:i}),removeFlag:(e,t)=>s.request("POST","/api/game/remove-flag",{room:e,name:t}),genUniqueObjectName:e=>s.request("POST","/api/game/gen-unique-object-name",{type:e}),checkUniqueObjectName:(e,t)=>s.request("POST","/api/game/check-unique-object-name",{type:e,name:t}),placeSpawn:(e,t,r,i,n)=>s.request("POST","/api/game/place-spawn",me({room:e,x:t,y:r,...i?{name:i}:{}},n)),createConstruction:(e,t,r,i,n,a)=>s.request("POST","/api/game/create-construction",me({room:e,x:t,y:r,structureType:i,...n?{name:n}:{}},a)),removeConstructionSite:(e,t,r)=>s.request("POST","/api/game/add-object-intent",me({_id:"room",room:e,name:"removeConstructionSite",intent:t.map(i=>({id:i,roomName:e}))},r)),addObjectIntent:(e,t,r,i)=>s.request("POST","/api/game/add-object-intent",{_id:e,room:t,name:r,intent:i}),addGlobalIntent:(e,t)=>s.request("POST","/api/game/add-global-intent",{name:e,intent:t}),setNotifyWhenAttacked:(e,t)=>s.request("POST","/api/game/set-notify-when-attacked",{_id:e,enabled:t}),createInvader:(e,t,r,i,n,a)=>s.request("POST","/api/game/create-invader",{room:e,x:t,y:r,size:i,type:n,...a!=null?{boosted:a}:{}}),removeInvader:e=>s.request("POST","/api/game/remove-invader",{_id:e}),tick:()=>s.request("GET","/api/game/tick"),powerCreeps:Xn(s),market:{ordersIndex:e=>s.request("GET","/api/game/market/orders-index",me({},e)),myOrders:()=>s.request("GET","/api/game/market/my-orders"),orders:(e,t)=>s.request("GET","/api/game/market/orders",me({resourceType:e},t)),stats:(e,t)=>s.request("GET","/api/game/market/stats",me({resourceType:e},t))},shards:{info:()=>s.request("GET","/api/game/shards/info")}}}function qn(s){return{send:(e,t)=>s.request("POST","/api/user/messages/send",{respondent:e,text:t}),list:e=>s.request("GET","/api/user/messages/list",{respondent:e}),index:()=>s.request("GET","/api/user/messages/index"),markRead:e=>s.request("POST","/api/user/messages/mark-read",{id:e}),unreadCount:()=>s.request("GET","/api/user/messages/unread-count")}}function rt(s,e){return e&&(s.shard=e),s}function Vn(s){return{branches:()=>s.request("GET","/api/user/branches"),code:{get:e=>s.request("GET","/api/user/code",e?{branch:e}:{}),set:(e,t)=>s.request("POST","/api/user/code",{branch:e,modules:t,_hash:Date.now()})},memory:{get:(e,t)=>s.request("GET","/api/user/memory",rt({path:e},t)),set:(e,t,r)=>s.request("POST","/api/user/memory",rt({path:e,value:t},r)),segment:{get:(e,t)=>s.request("GET","/api/user/memory-segment",rt({segment:e},t)),set:(e,t,r)=>s.request("POST","/api/user/memory-segment",rt({segment:e,data:t},r))}},console:(e,t)=>s.request("POST","/api/user/console",rt({expression:e},t)),stats:e=>s.request("GET","/api/user/stats",{interval:e}),rooms:e=>s.request("GET","/api/user/rooms",{id:e}),overview:(e,t)=>s.request("GET","/api/user/overview",{interval:e,statName:t}),worldStatus:()=>s.request("GET","/api/user/world-status"),worldStartRoom:e=>s.request("GET","/api/user/world-start-room",rt({},e)),find:e=>s.request("GET","/api/user/find",e),moneyHistory:e=>s.request("GET","/api/user/money-history",e!=null?{page:e}:{}),respawn:()=>s.request("POST","/api/user/respawn"),respawnProhibitedRooms:()=>s.request("GET","/api/user/respawn-prohibited-rooms"),badge:e=>s.request("POST","/api/user/badge",{badge:e}),setActiveBranch:(e,t)=>s.request("POST","/api/user/set-active-branch",{activeName:e,branch:t}),cloneBranch:(e,t,r)=>s.request("POST","/api/user/clone-branch",{newName:e,...t?{branch:t}:{},...r!=null?{defaultModules:r}:{}}),deleteBranch:e=>s.request("POST","/api/user/delete-branch",{branch:e}),notifyPrefs:e=>s.request("POST","/api/user/notify-prefs",e),tutorialDone:()=>s.request("POST","/api/user/tutorial-done"),email:e=>s.request("POST","/api/user/email",{email:e}),setSteamVisible:e=>s.request("POST","/api/user/set-steam-visible",{visible:e}),password:(e,t)=>s.request("POST","/api/user/password",{password:e,...t!=null?{oldPassword:t}:{}}),messages:qn(s)}}function jn(s){return{list:(e=10,t="world",r=0,i)=>s.request("GET","/api/leaderboard/list",{limit:e,mode:t,offset:r,season:i}),find:(e,t="world",r="")=>s.request("GET","/api/leaderboard/find",{username:e,mode:t,season:r}),seasons:()=>s.request("GET","/api/leaderboard/seasons")}}function Zn(s){return{pvp:(e=100)=>s.request("GET","/api/experimental/pvp",{interval:e}),nukes:()=>s.request("GET","/api/experimental/nukes")}}function Kn(s){return{checkEmail:e=>s.request("GET","/api/register/check-email",{email:e}),checkUsername:e=>s.request("GET","/api/register/check-username",{username:e}),setUsername:(e,t)=>s.request("POST","/api/register/set-username",{username:e,...t!=null?{email:t}:{}}),submit:(e,t,r,i)=>s.request("POST","/api/register/submit",{username:e,email:t,password:r,...i!=null?{modules:i}:{}})}}class Jn extends EventTarget{constructor(t){super();m(this,"baseUrl");m(this,"authStrategy");m(this,"logger");m(this,"serverPassword");m(this,"token",null);m(this,"rateLimits",new Map);m(this,"authenticating",!1);m(this,"auth");m(this,"register");m(this,"game");m(this,"user");m(this,"leaderboard");m(this,"experimental");this.baseUrl=t.url.endsWith("/")?t.url:`${t.url}/`,this.authStrategy=t.auth,this.logger=t.logger??Le.create(),this.serverPassword=t.serverPassword??null,this.auth=Wn(this),this.register=Kn(this),this.game=Yn(this),this.user=Vn(this),this.leaderboard=jn(this),this.experimental=Zn(this)}emit(t,r){this.dispatchEvent(new CustomEvent(t,{detail:r}))}on(t,r){const i=n=>r(n.detail);return this.addEventListener(t,i),{dispose:()=>{this.removeEventListener(t,i)}}}async authenticate(){this.logger.log("authenticate"),this.authenticating=!0;try{this.token=await this.authStrategy.authenticate(this),this.logger.log("authenticated")}finally{this.authenticating=!1}}setToken(t){this.token=t}async request(t,r,i,n=!1){this.logger.log(t,r);const a=new URL(r.startsWith("/")?r.slice(1):r,this.baseUrl),o={};this.token&&(o["X-Token"]=this.token,o["X-Username"]=this.token),this.serverPassword&&(o["X-Server-Password"]=this.serverPassword);const l={method:t,headers:o};if(t==="GET"&&i)for(const[u,f]of Object.entries(i))f!=null&&a.searchParams.set(u,String(f));else i&&(o["Content-Type"]="application/json",l.body=JSON.stringify(i));const c=await fetch(a.toString(),l),d=c.headers.get("x-token");if(d&&(this.token=d,this.emit("http:tokenRefresh",{token:d})),this.updateRateLimit(r,c),c.status===401&&!n&&!this.authenticating)return await this.authenticate(),this.request(t,r,i,!0);if(!c.ok){let u="";try{u=await c.text()}catch{}const f=new Error(`HTTP ${c.status}: ${u}`);throw this.emit("http:error",{method:t,path:r,status:c.status,error:f}),f}this.emit("http:success",{method:t,path:r,status:c.status});const h=await c.json();if(typeof h.error=="string"){const u=new Error(`Screeps API error: ${h.error}`);throw this.emit("http:error",{method:t,path:r,status:c.status,error:u}),u}return typeof h.data=="string"&&h.data.startsWith("gz:")&&(h.data=await Fn(h.data)),h}updateRateLimit(t,r){const i=r.headers.get("x-ratelimit-limit"),n=r.headers.get("x-ratelimit-remaining"),a=r.headers.get("x-ratelimit-reset");i&&n&&a&&this.rateLimits.set(t,{limit:parseInt(i,10),remaining:parseInt(n,10),reset:parseInt(a,10)})}}async function Qn(s){let e=typeof s=="string"?s:s.data;if(e.startsWith("gz:")&&(e=JSON.stringify(await Un(e))),e.startsWith("[")){const[i,n]=JSON.parse(e);return{kind:"channel",message:{channel:i,data:n}}}const[t,...r]=e.split(" ");switch(t){case"auth":return{kind:"server",command:{type:"auth",status:r[0],token:r[1]}};case"time":return{kind:"server",command:{type:"time",time:parseInt(r[0],10)}};case"protocol":return{kind:"server",command:{type:"protocol",protocol:parseInt(r[0],10)}};case"package":return{kind:"server",command:{type:"package",package:parseInt(r[0],10)}};default:throw new Error(`Unknown server command: ${t}`)}}class eo{constructor(e){m(this,"wsUrl");m(this,"WS");m(this,"logger");m(this,"ws",null);m(this,"token",null);m(this,"authed",!1);m(this,"_connected",!1);m(this,"reconnecting",!1);m(this,"authSub",null);m(this,"queue",[]);m(this,"subs",new Map);m(this,"listeners",new Map);m(this,"MAX_RETRIES",10);m(this,"MAX_DELAY_MS",6e4);m(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??Le.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((r,i)=>{this.ws=new this.WS(this.wsUrl),this.ws.onopen=()=>{this.logger.log("WebSocket opened"),this._connected=!0,this.reconnecting=!1,this.rawSend(`auth ${this.token}`),this.authSub=this.once("auth",n=>{const a=n;if(a.status==="ok"){for(this.logger.log("auth ok"),this.authed=!0,a.token&&(this.token=a.token,this.emit("socket:tokenRefresh",{token:a.token}));this.queue.length;)this.rawSend(this.queue.shift());this.emit("connected",{}),r()}else this.logger.log("auth failed"),i(new Error("WebSocket auth failed"))})},this.ws.onclose=()=>{var n;this.logger.log("WebSocket closed"),this._connected=!1,this.authed=!1,(n=this.authSub)==null||n.dispose(),this.authSub=null,this.emit("disconnected",{willReconnect:this.reconnecting}),this.scheduleReconnect()},this.ws.onerror=n=>{this._connected||i(n)},this.ws.onmessage=n=>{this.handleMessage(n).catch(a=>{this.logger.log("message parse error",a),this.emit("socket:error",a instanceof Error?a:new Error(String(a)))})}})}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 r=this.listeners.get(e);return r||(r=new Set,this.listeners.set(e,r)),r.add(t),{dispose:()=>{var i;(i=this.listeners.get(e))==null||i.delete(t)}}}once(e,t){const r=this.on(e,i=>{r.dispose(),t(i)});return r}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 r;(r=this.listeners.get(e))==null||r.forEach(i=>i(t))}async handleMessage(e){const t=await Qn(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 r=Math.min(Math.pow(2,e)*100,this.MAX_DELAY_MS);if(this.logger.log(`reconnect attempt ${e+1}/${this.MAX_RETRIES} in ${r}ms`),await new Promise(i=>setTimeout(i,r)),!this.reconnecting||this._intentionalClose)return;try{if(await this.connect(this.token),this._intentionalClose){(t=this.ws)==null||t.close(),this.ws=null;return}for(const i of this.subs.keys())this.rawSend(`subscribe ${i}`);return}catch{e++}}this.reconnecting=!1,e>=this.MAX_RETRIES&&!this._intentionalClose&&this.emit("socket:error",new Error(`WebSocket reconnection failed after ${this.MAX_RETRIES} retries`))}}class to{constructor(e,t){m(this,"memory",new Map);m(this,"storage");m(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,r){this.memory.set(this.memKey(e),{data:t,expires:r!==void 0?Date.now()+r: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 xt extends EventTarget{constructor(t){super();m(this,"logger");this.logger=t??Le.create()}emit(t,r){this.dispatchEvent(new CustomEvent(t,{detail:r}))}on(t,r){this.logger.log(`on "${t}"`);const i=n=>r(n.detail);return this.addEventListener(t,i),{dispose:()=>{this.logger.log(`off "${t}"`),this.removeEventListener(t,i)}}}}var Pe=(s=>(s[s.Plain=0]="Plain",s[s.Wall=1]="Wall",s[s.Swamp=2]="Swamp",s))(Pe||{});class ut{constructor(e){m(this,"raw");this.raw=e}static fromEncodedString(e){const t=new Uint8Array(2500);for(let r=0;r<2500;r++){const i=parseInt(e[r],10);t[r]=i===3?1:i}return new ut(t)}get(e,t){return this.raw[t*50+e]}}class so extends xt{constructor(t,r,i,n){super(n);m(this,"http");m(this,"socket");m(this,"cache");m(this,"roomObjects",new Map);m(this,"roomUsers",new Map);m(this,"roomSubCount",new Map);m(this,"lastFlagsString",new Map);this.http=t,this.socket=r,this.cache=i}parseFlagsString(t,r){if(!t||t.length===0)return[];const i=[],n=t.split("|");for(const a of n){const o=a.split("~");if(o.length!==5)continue;const[l,c,d,h,u]=o,f=parseInt(c,10),p=parseInt(d,10),b=parseInt(h,10),_=parseInt(u,10);isNaN(f)||isNaN(p)||isNaN(b)||isNaN(_)||i.push({_id:l,type:"flag",room:r,name:l,x:b,y:_,color:f,secondaryColor:p})}return i}async terrain(t,r){const i=`terrain/${r}/${t}`,n=this.cache.get(i);if(n)return this.logger.log("terrain",t,r,"(memory cache hit)"),n;const a=await this.cache.getPersistent(i);if(a){this.logger.log("terrain",t,r,"(persistent cache hit)");const d=new ut(a);return this.cache.set(i,d),d}this.logger.log("terrain",t,r,"(fetching)");const l=(await this.http.game.roomTerrain(t,r??void 0)).terrain[0];if(!l)throw new Error(`No terrain data for room ${t} shard ${r}`);const c=ut.fromEncodedString(l.terrain);return this.cache.set(i,c),await this.cache.setPersistent(i,c.raw),this.emit("room:terrainavailable",{room:t,shard:r,terrain:c}),c}async terrainBulk(t,r){const i=new Map,n=[];for(const l of t){const c=this.cache.get(`terrain/${r}/${l}`);c?i.set(l,c):n.push(l)}if(n.length===0)return i;const a=[];if(await Promise.all(n.map(async l=>{const c=`terrain/${r}/${l}`,d=await this.cache.getPersistent(c);if(d){const h=new ut(d);this.cache.set(c,h),i.set(l,h)}else a.push(l)})),a.length===0)return i;this.logger.log("terrainBulk",`fetching ${a.length} rooms`,r);const o=await this.http.game.roomsTerrain(a,r??void 0);return await Promise.all(o.rooms.map(async l=>{const c=ut.fromEncodedString(l.terrain),d=`terrain/${r}/${l.room}`;this.cache.set(d,c),await this.cache.setPersistent(d,c.raw),this.emit("room:terrainavailable",{room:l.room,shard:r,terrain:c}),i.set(l.room,c)})),i}objects(t,r){const i=this.roomObjects.get(`${t}/${r}`);return i?{...i}:null}async fetchObjects(t,r){const i=`${t}/${r}`,n=await this.http.game.roomObjects(t,r??void 0),a={};for(const l of n.objects)l&&typeof l=="object"&&"_id"in l&&(a[l._id]=l);this.roomObjects.set(i,a);const o=this.roomUsers.get(i);this.emit("room:update",{room:t,shard:r,gameTime:void 0,objects:a,diff:a,visual:"",users:o})}activeRooms(){return Array.from(this.roomSubCount.entries()).map(([t,r])=>`${t}(${r})`).join(", ")||"(none)"}subscribe(t,r){const i=`${t}/${r}`,n=this.roomSubCount.get(i)??0;this.roomSubCount.set(i,n+1),this.logger.log("subscribe",t,r,`(refs: ${n+1})`,"active:",this.activeRooms());const a=r?`room:${r}/${t}`:`room:${t}`,o=r?`err@room:${r}/${t}`:`err@room:${t}`,l=this.socket.subscribe(a),c=this.socket.on(o,h=>{const u=typeof h=="string"?h:JSON.stringify(h);this.logger.log("room error",t,r,u),this.emit("room:error",{room:t,shard:r,message:u})}),d=this.socket.on(a,h=>{const u=h,f={...this.roomObjects.get(i)??{}};for(const[_,y]of Object.entries(u.objects))y===null?delete f[_]:f[_]?f[_]={...f[_],...y}:f[_]=y;const p={...u.objects};if("flags"in u){const _=u.flags??"",y=this.lastFlagsString.get(i)??"";if(_!==y){this.lastFlagsString.set(i,_);const k=this.parseFlagsString(_,t),T=new Map;for(const $ of k)T.set($.name,$);for(const $ in f){const v=f[$];(v==null?void 0:v.type)==="flag"&&!T.has($)&&(delete f[$],p[$]=null,this.logger.log(`[flag:room] removed ${$} @ ${t}`))}for(const[$,v]of T){const M=f[$];(!M||M.x!==v.x||M.y!==v.y||M.color!==v.color||M.secondaryColor!==v.secondaryColor)&&(f[$]=v,p[$]=v,this.logger.log(`[flag:room] ${M?"changed":"added"} ${$} @ ${t} (${v.x},${v.y})`))}}}u.users&&this.roomUsers.set(i,u.users),this.roomObjects.set(i,f);const b=this.roomUsers.get(i);this.emit("room:update",{room:t,shard:r,gameTime:u.gameTime,objects:f,diff:p,visual:u.visual??"",users:b})});return{dispose:()=>{l.dispose(),d.dispose(),c.dispose();const h=(this.roomSubCount.get(i)??1)-1;h<=0?(this.roomSubCount.delete(i),this.roomObjects.delete(i),this.lastFlagsString.delete(i),this.logger.log("unsubscribe",t,r,"(last ref)","active:",this.activeRooms())):(this.roomSubCount.set(i,h),this.logger.log("unsubscribe",t,r,`(refs: ${h})`,"active:",this.activeRooms()))}}}}class ro extends xt{constructor(t,r,i,n,a=100){super(n);m(this,"http");m(this,"socket");m(this,"cache");m(this,"console",[]);m(this,"maxConsoleSize");m(this,"_cpu",null);m(this,"_userInfo",null);m(this,"_userId",null);m(this,"_worldStatus",null);m(this,"_mePromise",null);this.http=t,this.socket=r,this.cache=i,this.maxConsoleSize=a}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(r=>{const i=r;return this._userId=i._id,this._userInfo=i,this.cache.set("user/me",i,6e4),this.emit("user:me",i),i}).finally(()=>{this._mePromise=null}),this._mePromise)}async refreshMe(){return this.logger.log("refresh me"),this.cache.delete("user/me"),this.me()}async worldStatus(){const t=this.cache.get("user/worldStatus");if(t)return this._worldStatus=t,t;this.logger.log("fetch world status");const r=await this.http.user.worldStatus();return this._worldStatus=r.status,this.cache.set("user/worldStatus",r.status,6e4),this.emit("user:worldStatus",{status:r.status}),r.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 r=null,i=null,n=!1;return(async()=>{try{const o=this._userId??(await this.me())._id;if(n)return;const l=`user:${o}/${t}`;r=this.socket.subscribe(l),i=this.socket.on(l,c=>{var d,h,u;if(t==="cpu")this._cpu=c,this.emit("user:cpu",this._cpu);else if(t==="console"){const f=c,p={log:((d=f.messages)==null?void 0:d.log)??[],results:((h=f.messages)==null?void 0:h.results)??[],error:((u=f.messages)==null?void 0:u.error)??[]};f.error&&p.error.push(f.error),this.console.push(p),this.console.length>this.maxConsoleSize&&this.console.splice(0,this.console.length-this.maxConsoleSize),this.emit("user:console",{messages:p})}else t==="code"&&this.emit("user:code",c)})}catch(o){n||this.dispatchEvent(new ErrorEvent("error",{error:o instanceof Error?o:new Error(String(o))}))}})(),{dispose:()=>{this.logger.log("unsubscribe",t),n=!0,r==null||r.dispose(),i==null||i.dispose()}}}subscribeUserStream(){this.logger.log("subscribe user stream");let t=null,r=null,i=!1;return(async()=>{try{const a=this._userId??(await this.me())._id;if(i)return;const o=`user:${a}`;t=this.socket.subscribe(o),r=this.socket.on(o,l=>{const c=l;if(c&&typeof c=="object"&&"flags"in c){const d=c.flags;if(d&&typeof d=="object")for(const[h,u]of Object.entries(d)){const f=u;if(f&&typeof f=="object"){const p=f.room??"unknown",b=f.x??"?",_=f.y??"?";this.logger.log(`[flag:user] ${h} @ ${p} (${b},${_})`)}}}this.emit("user:stream",c)})}catch(a){i||this.dispatchEvent(new ErrorEvent("error",{error:a instanceof Error?a:new Error(String(a))}))}})(),{dispose:()=>{this.logger.log("unsubscribe user stream"),i=!0,t==null||t.dispose(),r==null||r.dispose()}}}}class io extends xt{constructor(t,r,i,n){super(n);m(this,"http");m(this,"cache");m(this,"socketSubs",[]);m(this,"_version",null);m(this,"_shards",null);this.http=t,this.cache=i,this.socketSubs.push(r.on("connected",()=>{this.emit("server:connected",{})})),this.socketSubs.push(r.on("disconnected",a=>{const o=a;this.emit("server:disconnected",{willReconnect:o.willReconnect})})),this.socketSubs.push(r.on("socket:error",a=>{this.emit("server:error",{error:a instanceof Error?a:new Error(String(a))})}))}get versionInfo(){return this._version}get isPrivateServer(){var t,r;return this._version?(((r=(t=this._version.serverData)==null?void 0:t.shards)==null?void 0:r.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 r=await this.http.request("GET","/api/version");return this._version=r,this.cache.set("server/version",r,5*6e4),this.emit("server:version",r),r}async refreshVersion(){return this.cache.delete("server/version"),this.version()}async shards(){const t=this.cache.get("server/shards");if(t)return t;const r=await this.http.request("GET","/api/game/shards/info");return this._shards=r.shards,this.cache.set("server/shards",r.shards,5*6e4),this.emit("server:shards",r.shards),r.shards}async refreshShards(){return this.cache.delete("server/shards"),this.shards()}async worldInfo(t){const i=`server/world/${t??"default"}`,n=this.cache.get(i);if(n)return n;const a={};t&&(a.shard=t);const o=await this.http.request("GET","/api/game/world-size",a),{width:l,height:c}=o;this.logger.log(`worldInfo shard=${t??"none"} — raw size: ${l}x${c}`);let d=-l,h=-1,u=-c,f=-1;try{const _=(await this.http.request("POST","/api/game/map-stats",{rooms:["W0N0","E0N0","W0S0","E0S0"],statName:"owner0",...a})).stats??{},y=["W0N0","E0N0","W0S0","E0S0"].filter(k=>k in _);this.logger.log(`worldInfo corner probe — found: [${y.length?y.join(", "):"none"}]`),("E0N0"in _||"E0S0"in _)&&(d=-Math.ceil(l/2),h=Math.floor(l/2)-1),("W0S0"in _||"E0S0"in _)&&(u=-Math.ceil(c/2),f=Math.floor(c/2)-1)}catch(b){this.logger.log("worldInfo corner probe failed — keeping W/N defaults:",b)}this.logger.log(`worldInfo computed bounds — x: [${d}, ${h}] y: [${u}, ${f}]`);const p={shard:t??null,width:l,height:c,minX:d,maxX:h,minY:u,maxY:f};return this.cache.set(i,p,10*6e4),p}invalidateWorldInfo(t){this.cache.delete(`server/world/${t??"default"}`)}}class no{constructor(e){m(this,"memory",new Map);m(this,"adapter");m(this,"maxEntries");m(this,"namespace");m(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 r=this.memory.get(this.key(e,t));return r?(r.lastAccess=this.tick(),r.data):null}async get(e,t){const r=this.getMemory(e,t);if(r)return r;if(!this.adapter)return null;const i=this.key(e,t),n=await this.adapter.get(this.adapterKey(i));if(!n)return null;const a=this.deserialize(n);return a?(this.memory.set(i,{data:a.data,lastSeen:a.lastSeen,lastAccess:this.tick()}),a.data):null}async put(e,t,r){const i=this.key(e,t),n={data:r,lastSeen:Date.now(),lastAccess:this.tick()};this.memory.set(i,n),await this.pruneIfNeeded(),this.adapter&&await this.adapter.set(this.adapterKey(i),this.serialize(n))}async pruneIfNeeded(){if(this.memory.size<=this.maxEntries)return;const t=[...this.memory.entries()].sort((r,i)=>r[1].lastAccess-i[1].lastAccess).slice(0,this.memory.size-this.maxEntries);for(const[r]of t)this.memory.delete(r),this.adapter&&await this.adapter.delete(this.adapterKey(r))}}function Rr(s){const e=Object.keys(s).sort(),t={};for(const r of e){const i=s[r];t[r]=i?[...i].sort((n,a)=>n[0]-a[0]||n[1]-a[1]):null}return JSON.stringify(t)}class oo extends xt{constructor(t,r,i={},n){super(n);m(this,"socket");m(this,"storage");m(this,"maxSubscriptions");m(this,"active",new Map);m(this,"waitlist",[]);m(this,"keyStates",new Map);m(this,"warnedAboutWaitlist",!1);this.socket=t,this.storage=r,this.maxSubscriptions=i.maxSubscriptions??500,this.socket.on("connected",()=>this.onReconnect())}map2data(t,r){return this.storage.getMemory(t,r)}subscribeMap2(t,r){const i=`${t}/${r}`,n=this.active.get(i);if(n){n.refCount++,this.logger.log("subscribeMap2",t,r,`(active, refs: ${n.refCount})`);const l=this.getOrCreateKeyState(i,"active");return this.emitWarmStart(t,r),this.makeSubscription(t,r,i,l)}const a=this.waitlist.find(l=>l.key===i);if(a){a.refCount++,this.logger.log("subscribeMap2",t,r,`(pending, refs: ${a.refCount})`);const l=this.getOrCreateKeyState(i,"pending");return this.emitWarmStart(t,r),this.makeSubscription(t,r,i,l)}if(this.active.size<this.maxSubscriptions){this.activateKey(t,r,i,1),this.logger.log("subscribeMap2",t,r,"(new active)");const l=this.getOrCreateKeyState(i,"active");return this.emit("room:map2state",{room:t,shard:r,status:"active"}),this.emitWarmStart(t,r),this.makeSubscription(t,r,i,l)}this.waitlist.push({key:i,room:t,shard:r,refCount:1}),this.logger.log("subscribeMap2",t,r,"(new pending)");const o=this.getOrCreateKeyState(i,"pending");return this.emit("room:map2state",{room:t,shard:r,status:"pending"}),this.emitWarmStart(t,r),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,r,i,o)}activateKey(t,r,i,n){const a=r?`roomMap2:${r}/${t}`:`roomMap2:${t}`,o=this.socket.subscribe(a),l=this.storage.getMemory(t,r),c={room:t,shard:r,refCount:n,socketSub:o,listenerSub:void 0,lastHash:l?Rr(l):null};c.listenerSub=this.socket.on(a,d=>{const h=d,u=Rr(h);c.lastHash!==u&&(c.lastHash=u,this.storage.put(t,r,h),this.emit("room:map2update",{room:t,shard:r,data:h,source:"live"}))}),this.active.set(i,c)}promoteNext(){const t=this.waitlist.shift();if(!t)return;this.activateKey(t.room,t.shard,t.key,t.refCount),this.logger.log("promoteNext",t.room,t.shard,"(promoted from waitlist)");const r=this.keyStates.get(t.key);r&&(r.status="active",r.statusHandlers.forEach(i=>i("active"))),this.emit("room:map2state",{room:t.room,shard:t.shard,status:"active"})}getOrCreateKeyState(t,r){let i=this.keyStates.get(t);return i||(i={status:r,statusHandlers:new Set},this.keyStates.set(t,i)),i}makeSubscription(t,r,i,n){let a=!1;return{status:()=>n.status,cachedData:()=>this.storage.getMemory(t,r),onStatusChange:o=>(n.statusHandlers.add(o),{dispose:()=>{n.statusHandlers.delete(o)}}),dispose:()=>{a||(a=!0,this.disposeSubscription(t,r,i))}}}disposeSubscription(t,r,i){const n=this.waitlist.findIndex(o=>o.key===i);if(n>=0){const o=this.waitlist[n];o.refCount--,this.logger.log("unsubscribeMap2",t,r,`(pending, refs: ${o.refCount})`),o.refCount<=0&&(this.waitlist.splice(n,1),this.keyStates.delete(i),this.logger.log("unsubscribeMap2",t,r,"(removed from waitlist)"));return}const a=this.active.get(i);a&&(a.refCount--,this.logger.log("unsubscribeMap2",t,r,`(active, refs: ${a.refCount})`),a.refCount<=0&&(a.socketSub.dispose(),a.listenerSub.dispose(),this.active.delete(i),this.keyStates.delete(i),this.logger.log("unsubscribeMap2",t,r,"(deactivated, promoting next)"),this.promoteNext()))}emitWarmStart(t,r){const i=`${t}/${r}`,n=this.storage.getMemory(t,r);n?queueMicrotask(()=>{this.isSubscribed(i)&&this.emit("room:map2update",{room:t,shard:r,data:n,source:"cache"})}):this.storage.get(t,r).then(a=>{a&&this.isSubscribed(i)&&this.emit("room:map2update",{room:t,shard:r,data:a,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(r=>r.key===t)}}class ao extends xt{constructor(t,r=100,i=500,n){super(n);m(this,"http");m(this,"debounceMs");m(this,"minIntervalMs");m(this,"pending",new Map);m(this,"timer",null);m(this,"lastFlushTime",0);this.http=t,this.debounceMs=r,this.minIntervalMs=i}request(t,r,i){if(t.length===0)return;const n=JSON.stringify([r,i??"shard0"]);let a=this.pending.get(n);a||(a={rooms:new Set,statName:r,shard:i??"shard0"},this.pending.set(n,a));for(const d of t)a.rooms.add(d);this.timer&&clearTimeout(this.timer);const l=Date.now()-this.lastFlushTime,c=Math.max(this.debounceMs,this.minIntervalMs-l);this.timer=setTimeout(()=>this.flush(),c)}async flush(){const t=new Map(this.pending);this.pending.clear(),this.timer=null,this.lastFlushTime=Date.now();for(const[,r]of t){const i=[...r.rooms];try{const n=await this.http.request("POST","/api/game/map-stats",{rooms:i,statName:r.statName,shard:r.shard}),a=n.users??{};for(const[o,l]of Object.entries(n.stats)){const c=this.buildData(l,a);this.emit("mapStats:room",{room:o,shard:r.shard==="shard0"?null:r.shard,stat:c})}for(const o of i)n.stats[o]||this.emit("mapStats:room",{room:o,shard:r.shard==="shard0"?null:r.shard,stat:{}})}catch(n){this.logger.log("mapStats fetch failed:",n)}}}buildData(t,r){var o,l,c;let i,n;for(let d=0;d<3;d++){const h=`minerals${d}`,u=t[h];if(u){i=u.type,n=u.density;break}}const a=(o=t.own)==null?void 0:o.user;return{own:t.own,mineral:i,density:n,username:a?(l=r[a])==null?void 0:l.username:void 0,safeMode:t.safeMode,badge:a?(c=r[a])==null?void 0:c.badge:void 0,status:t.status}}}class lo extends xt{constructor(t=50,r){super(r);m(this,"_history",[]);m(this,"_index",-1);m(this,"maxHistory");this.maxHistory=t}navigateTo(t,r){this._history=this._history.slice(0,this._index+1),this._history.push({room:t,shard:r}),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,r;return{room:((t=this._history[this._index])==null?void 0:t.room)??null,shard:((r=this._history[this._index])==null?void 0:r.shard)??null,index:this._index,history:[...this._history]}}}class co{constructor(e){m(this,"http");m(this,"socket");m(this,"stores");m(this,"cache");m(this,"logger");m(this,"tokenRefreshIntervalMs");m(this,"tokenSyncSubs",[]);m(this,"tokenRefreshTimer",null);m(this,"lastHttpActivity",0);m(this,"refreshInFlight",!1);var i,n,a;let t;try{t=new URL(e.url).hostname}catch{throw new TypeError(`ScreepsClient: invalid url "${e.url}"`)}this.logger=Le.create(e.debug),this.logger.log(`[screeps:client] init ${e.url}`),this.cache=new to(t,e.storage??null),this.http=new Jn({url:e.url,auth:e.auth,logger:this.logger.child("http"),serverPassword:e.serverPassword}),this.socket=new eo({url:e.url,WebSocket:e.WebSocket,logger:this.logger.child("socket")});const r=new no({adapter:e.storage??null,namespace:t,maxEntries:((i=e.map2)==null?void 0:i.maxCacheEntries)??1e4});this.stores={room:new so(this.http,this.socket,this.cache,this.logger.child("room")),user:new ro(this.http,this.socket,this.cache,this.logger.child("user")),server:new io(this.http,this.socket,this.cache,this.logger.child("server")),map:new oo(this.socket,r,{maxSubscriptions:((n=e.map2)==null?void 0:n.maxSubscriptions)??500},this.logger.child("map")),mapStats:new ao(this.http,100,500,this.logger.child("mapStats")),navigation:new lo(50,this.logger.child("navigation"))},this.tokenRefreshIntervalMs=e.tokenRefresh===!1?null:((a=e.tokenRefresh)==null?void 0:a.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 ho{constructor(e){m(this,"token");this.token=e.token}async authenticate(e){return this.token}}class uo{constructor(e){m(this,"email");m(this,"password");this.email=e.email,this.password=e.password}async authenticate(e){return(await e.auth.signin(this.email,this.password)).token}}class fo{async authenticate(e){return"guest"}}const po=1,Te="data";class go{constructor(e){m(this,"namespace");m(this,"db",null);m(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 r=indexedDB.open(this.dbName,po);r.onupgradeneeded=()=>{r.result.createObjectStore(Te)},r.onsuccess=()=>{this.db=r.result,this.openPromise=null,e(r.result)},r.onerror=()=>t(r.error),r.onblocked=()=>t(new Error(`IndexedDB open blocked: ${this.dbName}`))}),this.openPromise)}async get(e){const t=await this.open();return new Promise((r,i)=>{const a=t.transaction(Te,"readonly").objectStore(Te).get(e);a.onsuccess=()=>r(a.result??null),a.onerror=()=>i(a.error)})}async set(e,t){const r=await this.open();return new Promise((i,n)=>{const o=r.transaction(Te,"readwrite").objectStore(Te).put(t,e);o.onsuccess=()=>i(),o.onerror=()=>n(o.error)})}async delete(e){const t=await this.open();return new Promise((r,i)=>{const a=t.transaction(Te,"readwrite").objectStore(Te).delete(e);a.onsuccess=()=>r(),a.onerror=()=>i(a.error)})}async clear(){const e=await this.open();return new Promise((t,r)=>{const n=e.transaction(Te,"readwrite").objectStore(Te).clear();n.onsuccess=()=>t(),n.onerror=()=>r(n.error)})}}class yr{constructor(){m(this,"subs",[])}add(e){this.subs.push(e)}dispose(){for(const e of this.subs)e.dispose();this.subs.length=0}}const mo=5*6e4;function mi(s,e){try{return`screeps:${s}:${new URL(e).hostname}`}catch{return`screeps:${s}:${e}`}}function yi(s){if(typeof sessionStorage>"u")return null;try{const e=sessionStorage.getItem(s);if(!e)return null;const t=JSON.parse(e);return Date.now()>t.expires?(sessionStorage.removeItem(s),null):t.data}catch{return null}}function wi(s,e){if(!(typeof sessionStorage>"u"))try{sessionStorage.setItem(s,JSON.stringify({data:e,expires:Date.now()+mo}))}catch{}}function Xt(s){return s.endsWith("/")?s:`${s}/`}async function yo(s){const e=mi("version",s),t=yi(e);if(t)return t;const r=await fetch(`${Xt(s)}api/version`);if(!r.ok)throw new Error(`HTTP ${r.status}`);const i=await r.json();return wi(e,i),i}async function wo(s){const e=mi("authmod",s),t=yi(e);if(t)return t;const r=await fetch(`${Xt(s)}api/authmod`);if(!r.ok)return null;const i=await r.json();return i.ok?(wi(e,i),i):null}async function bo(s,e){const t=new URLSearchParams({username:e}),r=await fetch(`${Xt(s)}api/register/check-username?${t}`);if(!r.ok)throw new Error(`HTTP ${r.status}`);return r.json()}async function vo(s,e){const t=new URLSearchParams({email:e}),r=await fetch(`${Xt(s)}api/register/check-email?${t}`);if(!r.ok)throw new Error(`HTTP ${r.status}`);return r.json()}async function xo(s,e,t,r){const i=await fetch(`${Xt(s)}api/register/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,email:t,password:r})});if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}function _o(s,e){return s.serverData.features.find(t=>t.name===e)}function bi(s){return _o(s,"screepsmod-auth")}const Ss={1:{calc(s=0){let e=0,t=0;s>0&&(e=s*30/100),s<0&&(t=-s*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(s=0){let e=0,t=0;s>0&&(e=s*30/100),s<0&&(t=-s*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(s=0){const e=Math.PI/4+Math.PI/4*(s+100)/200,t=-Math.PI/2,r=Math.PI/2+Math.PI/3,i=Math.PI/2-Math.PI/3;this.path1=`M 50 50 L ${50+100*Math.cos(t-e/2)} ${50+100*Math.sin(t-e/2)} L ${50+100*Math.cos(t+e/2)} ${50+100*Math.sin(t+e/2)} Z`,this.path2=`M 50 50 L ${50+100*Math.cos(r-e/2)} ${50+100*Math.sin(r-e/2)} L ${50+100*Math.cos(r+e/2)} ${50+100*Math.sin(r+e/2)} Z M 50 50 L ${50+100*Math.cos(i-e/2)} ${50+100*Math.sin(i-e/2)} L ${50+100*Math.cos(i+e/2)} ${50+100*Math.sin(i+e/2)}`},flip:"rotate180"},4:{calc(s=0){s+=100;const e=50-s*30/200,t=50+s*30/200;this.path1=`M 0 ${t} H 100 V 100 H 0 Z`,this.path2=s>0?`M 0 ${e} H 100 V ${t} H 0 Z`:""},flip:"rotate90"},5:{calc(s=0){s+=100;const e=50-s*10/200-10,t=50+s*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(s=0){const e=5+(s+100)*8/200,t=50,r=20,i=80;this.path1=`M ${t-e} 0 H ${t+e} V 100 H ${t-e}`,this.path2=`M ${r-e} 0 H ${r+e} V 100 H ${r-e} Z M ${i-e} 0 H ${i+e} V 100 H ${i-e} Z`},flip:"rotate90"},7:{calc(s=0){const e=20+s*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(s=0){const e=s*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(s=0){let e=0,t=50;const r=70;s>0&&(e+=s/100*20),s<0&&(t+=s/100*30),this.path1=`M 50 ${e} L 100 ${e+r} V 101 H 0 V ${e+r} Z`,this.path2=`M 50 ${e+t} L 100 ${e+t+r} V 101 H 0 V ${e+t+r} Z`},flip:"rotate180"},10:{calc(s=0){let e=30,t=7;s>0&&(e+=s*50/100),s<0&&(t-=s*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(s=0){let e=30,t=30;const r=50-50*Math.cos(Math.PI/4),i=50-50*Math.sin(Math.PI/4);s>0&&(e+=s*25/100,t+=s*25/100),s<0&&(t-=s*50/100),this.path1=`M ${r} ${i} Q ${e} 50 ${r} ${100-i} H 0 V ${i} Z M ${100-r} ${i} Q ${100-e} 50 ${100-r} ${100-i} H 100 V ${i} Z`,this.path2=`M ${r} ${i} Q 50 ${t} ${100-r} ${i} V 0 H ${r} Z M ${r} ${100-i} Q 50 ${100-t} ${100-r} ${100-i} V 100 H ${r} Z`},flip:"rotate90"},12:{calc(s=0){let e=30,t=35;s>0&&(e+=s*30/100),s<0&&(t+=s*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(s=0){let e=30,t=0;s>0&&(e+=s*50/100),s<0&&(t-=s*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(s=0){let e=Math.PI/4;const t=0;e+=s*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(s=0){const e=13+s*6/100,t=80,r=45,i=10;this.path1=`M ${50-t-e} ${100+i} A ${t+e} ${t+e} 0 0 1 ${50+t+e} ${100+i} H ${50+t-e} A ${t-e} ${t-e} 0 1 0 ${50-t+e} ${100+i}`,this.path2=`M ${50-r-e} ${100+i} A ${r+e} ${r+e} 0 0 1 ${50+r+e} ${100+i} H ${50+r-e} A ${r-e} ${r-e} 0 1 0 ${50-r+e} ${100+i}`},flip:"rotate180"},16:{calc(s=0){let e=30*Math.PI/180,t=25;s>0&&(e+=30*Math.PI/180*s/100),s<0&&(t+=s*25/100),this.path1="";for(let r=0;r<3;r++){const i=r*Math.PI*2/3+e/2-Math.PI/2,n=r*Math.PI*2/3-e/2-Math.PI/2;this.path1+=`M ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} L ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+t*Math.cos(n)} ${50+t*Math.sin(n)} A ${t} ${t} 0 0 1 ${50+t*Math.cos(i)} ${50+t*Math.sin(i)} Z`}this.path2="";for(let r=0;r<3;r++){const i=r*Math.PI*2/3+e/2+Math.PI/2,n=r*Math.PI*2/3-e/2+Math.PI/2;this.path2+=`M ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} L ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+t*Math.cos(n)} ${50+t*Math.sin(n)} A ${t} ${t} 0 0 1 ${50+t*Math.cos(i)} ${50+t*Math.sin(i)} Z`}}},17:{calc(s=0){let e=35,t=45;s>0&&(e+=s*20/100),s<0&&(t-=s*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(s=0){let e=90*Math.PI/180,t=10;s>0&&(e-=60/180*Math.PI*s/100),s<0&&(t-=s*15/100),this.path1="",this.path2="";for(let r=0;r<3;r++){const i=Math.PI*2/3*r+e/2-Math.PI/2,n=Math.PI*2/3*r-e/2-Math.PI/2,a=`M ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} L ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+t*Math.cos((i+n)/2)} ${50+t*Math.sin((i+n)/2)} Z`;r?this.path2+=a:this.path1+=a}},flip:"rotate180"},19:{calc(s=0){let e=20,t=60;t+=s*20/100,e+=s*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(s=0){let e=10,t=20;s>0&&(e+=s*20/100),s<0&&(t+=s*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(s=0){let e=40,t=50;s>0&&(e-=s*20/100),s<0&&(t+=s*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(s=0){let e=20;e+=s*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 r=-4;r<4;r++){const i=(t+r)%2;this.path2+=`M ${50-e-e*2*t} ${50-e-e*2*(r+i)} h ${-e*2} v ${e*2} h ${e*2} Z`}},flip:"rotate45"},23:{calc(s=0){let e=17,t=25;s>0&&(e+=s*35/100),s<0&&(t-=s*23/100),this.path1="";for(let r=-4;r<=4;r++)this.path1+=`M ${50-e*r*2} ${50-t} l ${-e} ${-t} l ${-e} ${t} l ${e} ${t} Z`;this.path2="";for(let r=-4;r<=4;r++)this.path2+=`M ${50-e*r*2} ${50+t} l ${-e} ${-t} l ${-e} ${t} l ${e} ${t} Z`},flip:"rotate90"},24:{calc(s=0){let e=50,t=45;s>0&&(e+=s*60/100),s<0&&(t+=s*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 Cs(s){const e=Math.round(s).toString(16);return e.length<2?"0"+e:e}function Ie(s,e,t){const r=(1-Math.abs(2*t-1))*e,i=s/60,n=r*(1-Math.abs(i%2-1));let a=0,o=0,l=0;!Number.isNaN(s)&&s!==null&&s!==void 0&&(i>=0&&i<1?(a=r,o=n,l=0):i>=1&&i<2?(a=n,o=r,l=0):i>=2&&i<3?(a=0,o=r,l=n):i>=3&&i<4?(a=0,o=n,l=r):i>=4&&i<5?(a=n,o=0,l=r):i>=5&&i<6&&(a=r,o=0,l=n));const c=t-r/2,d=(a+c)*255,h=(o+c)*255,u=(l+c)*255;return"#"+Cs(d)+Cs(h)+Cs(u)}function $o(){const s=[];let e=0;s.push({index:e++,rgb:Ie(0,0,.8)});for(let t=0;t<19;t++)s.push({index:e++,rgb:Ie(t*360/19,.6,.8)});s.push({index:e++,rgb:Ie(0,0,.5)});for(let t=0;t<19;t++)s.push({index:e++,rgb:Ie(t*360/19,.7,.5)});s.push({index:e++,rgb:Ie(0,0,.3)});for(let t=0;t<19;t++)s.push({index:e++,rgb:Ie(t*360/19,.4,.3)});s.push({index:e++,rgb:Ie(0,0,.1)});for(let t=0;t<19;t++)s.push({index:e++,rgb:Ie(t*360/19,.5,.1)});return s}const So=$o();function ks(s){if(typeof s=="string")return s;if(typeof s=="number"){const e=So[s];return e?e.rgb:"#000000"}return"#000000"}function Co(s){const e=ks(s.color1),t=ks(s.color2),r=ks(s.color3),i=s.param??0;if(typeof s.type=="number"){const d=Ss[s.type];d&&d.calc(i)}let n=0;if(s.flip&&typeof s.type=="number"){const d=Ss[s.type];(d==null?void 0:d.flip)==="rotate180"&&(n=180),(d==null?void 0:d.flip)==="rotate90"&&(n=90),(d==null?void 0:d.flip)==="rotate45"&&(n=45)}let a,o;if(typeof s.type=="number"){const d=Ss[s.type];a=(d==null?void 0:d.path1)??"",o=(d==null?void 0:d.path2)??""}else a=s.type.path1,o=s.type.path2;const l=50;let c='<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 100 100" shape-rendering="geometricPrecision">';return c+=`<defs><clipPath id="clip"><circle cx="50" cy="50" r="${l}"/></clipPath></defs>`,c+=`<g transform="rotate(${n} 50 50)">`,c+=`<rect x="0" y="0" width="100" height="100" fill="${e}" clip-path="url(#clip)"/>`,a&&(c+=`<path d="${a}" fill="${t}" clip-path="url(#clip)"/>`),o&&(c+=`<path d="${o}" fill="${r}" clip-path="url(#clip)"/>`),c+='<circle cx="50" cy="50" r="47.5" fill="transparent" stroke="#000" stroke-width="5"/>',c+="</g></svg>",c}const[ko,Er]=A([]);let To=0;function fe(s,e="success",t=4e3){const r=To++;Er(i=>[...i,{id:r,message:s,type:e,duration:t}]),setTimeout(()=>{Er(i=>i.filter(n=>n.id!==r))},t)}const Mo=!1;function vs(){return!0}function Ro(){return Mo}function wr(){return window.location.origin}function xs(){return"/client/".replace(/\/$/,"")}function et(s){const e=`[${s}]`;return{log:()=>{},warn:()=>{},error:(...t)=>console.error(e,...t)}}const ce={room:"screeps:room",shard:"screeps:shard",sidebarWidth:"screeps:sidebarWidth",consoleHeight:"screeps:consoleHeight",consoleSplit:"screeps:consoleSplit",mapZoom:"screeps:mapZoom",widescreenMode:"screeps:settings:widescreenMode",showCreepLabels:"screeps:settings:showCreepLabels",showMapRoomNames:"screeps:settings:showMapRoomNames",showUnclaimableRooms:"screeps:settings:showUnclaimableRooms"},be={url:"screeps:url",token:"screeps:token",serverPassword:"screeps:serverPassword"};function Ts(s){return localStorage.getItem(s)}function Or(s,e){localStorage.setItem(s,e)}function Eo(s){localStorage.removeItem(s)}function It(s,e){const t=localStorage.getItem(s);if(t===null)return e;const r=Number(t);return Number.isFinite(r)&&r!==0?r:e}function ns(s,e){localStorage.setItem(s,String(e))}function os(s){return sessionStorage.getItem(s)}function Zt(s,e){sessionStorage.setItem(s,e)}function Dt(s){sessionStorage.removeItem(s)}const{log:Ce}=et("client"),[de,as]=A(null),[Ve,lt]=A("idle"),[Lr,ls]=A(null),[zs,Fs]=A(null),[rh,Us]=A(null),[ps,Ws]=A(null),[Xs,vi]=A(null),[ft,xi]=A(!1),[Pr,_i]=A(null),[Oo,$i]=A({}),[Je,Si]=A(null);let cs=-1,Ys=-1;const ct=[],Lo=5;function Po(s){if(s===void 0)return;const e=Date.now();if(cs>=0&&s>cs){const t=e-Ys;if(t>0){ct.push(t),ct.length>Lo&&ct.shift();const r=ct.reduce((i,n)=>i+n,0)/ct.length;vi(Math.round(r))}}cs=s,Ys=e}function Ao(){cs=-1,Ys=-1,ct.length=0,vi(null)}async function Ye(s){vs()&&(s={...s,url:wr()}),Ce(`connecting to ${s.url} (auth: ${s.auth})`),lt("connecting"),ls(null);try{let e;if(s.auth==="guest")e=new fo,xi(!0);else if(s.auth==="password"){if(!s.email||!s.password)throw new Error("Email and password are required");e=new uo({email:s.email,password:s.password})}else{if(!s.token)throw new Error("Token is required");e=new ho({token:s.token})}const t=new co({url:s.url,auth:e,storage:s.storage??new go("screeps-client"),debug:!1,serverPassword:s.serverPassword});t.http.on("http:tokenRefresh",({token:r})=>{Ce("token refreshed"),Zt(be.token,r)}),t.http.on("http:error",({method:r,path:i,error:n})=>{Ce("http error:",r,i,n.message),fe(`Request failed: ${r} ${i} — ${n.message}`,"error",6e3)}),t.stores.server.on("server:disconnected",r=>{Ce(`server disconnected (willReconnect: ${r.willReconnect})`),r.willReconnect||(lt("idle"),as(null),Fs(null),Us(null))}),t.stores.server.on("server:error",r=>{Ce("server error:",r.error.message),ls(r.error.message),lt("error")}),t.stores.user.on("user:me",r=>{Ce(`user: ${r.username} (id: ${r._id})`),Fs(r)}),t.stores.server.on("server:version",r=>{Ce(`server version: ${r.package??"unknown"}`),Us(r)}),t.stores.user.on("user:stream",r=>{if(r&&typeof r=="object"&&"flags"in r){const i=r.flags;i&&typeof i=="object"&&$i(i)}}),t.stores.user.on("user:worldStatus",({status:r})=>{Ce(`world status: ${r}`),Si(r)}),await t.connect(),t.stores.user.subscribeUserStream(),as(t),lt("connected"),Ce(`connected to ${s.url}`),t.stores.server.worldInfo().then(r=>{_i(r),Ce(`world: ${r.width}x${r.height} x[${r.minX},${r.maxX}] y[${r.minY},${r.maxY}]`)}).catch(()=>{}),Zt(be.url,s.url),t.http.token&&Zt(be.token,t.http.token),s.serverPassword?Zt(be.serverPassword,s.serverPassword):Dt(be.serverPassword)}catch(e){const t=e instanceof Error?e.message:String(e);throw ls(t),lt("error"),as(null),e}}async function Io(){const s=vs()?wr():os(be.url),e=os(be.token);if(!s||!e)return;const t=os(be.serverPassword)??void 0;try{e==="guest"?await Ye({url:s,auth:"guest",storage:null,serverPassword:t}):await Ye({url:s,auth:"token",token:e,serverPassword:t})}catch{Dt(be.token)}}function Go(){const s=de();s&&s.disconnect(),as(null),lt("idle"),ls(null),Fs(null),Us(null),Ws(null),xi(!1),_i(null),$i({}),Si(null),Ao(),Dt(be.token),Dt(be.url),Dt(be.serverPassword)}var No=R("<span style=font-size:11px>"),Do=R('<div style="color:#3fb950;font-size:14px;text-align:center;padding:8px 0">Account created! Logging you in…'),Ho=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>"),Bo=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>"),zo=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>"),Fo=R("<span style=font-size:11px;color:#f85149>Passwords don't match"),Uo=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>"),Wo=R("<button type=submit style=padding:10px;border-radius:6px;border:none;background:#238636;color:#fff;font-weight:600>"),Xo=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'),Yo=R("<form style=display:flex;flex-direction:column;gap:16px><h2 style=margin:0;font-size:20px>Create Account"),Ci=R("<div style=color:#f85149;font-size:13px>"),qo=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">'),Vo=R("<button type=button style=background:none;border:none;color:#58a6ff;font-size:12px;cursor:pointer;padding:0>Create account"),jo=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'),Zo=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>"),Ko=R("<div style=color:#8b949e;font-size:12px;margin-top:-8px>"),Jo=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>"),Qo=R("<button type=button style=padding:10px;border-radius:6px;border:none;background:#1b2838;color:#c7d5e0;font-weight:600>Login with Steam"),ea=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)'),ta=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>'),sa=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>'),ra=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">'),ia=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>"),na=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>"),oa=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>"),aa=R('<span style="font-size:11px;padding:2px 8px;border-radius:12px;background:#21262d;border:1px solid #30363d;color:#8b949e;font-family:monospace">');const Ee={padding:"8px 12px","border-radius":"6px",border:"1px solid #30363d",background:"#0d1117",color:"#c9d1d9"};function la(s){const[e,t]=A(null),[r,i]=A(null),[n,a]=A(null);return he(()=>{const o=s();t(null),i(null),a(null);let l=!1;const c=setTimeout(async()=>{try{const d=await yo(o);if(l)return;if(t(d),a(null),bi(d)){const h=await wo(o);l||i(h)}}catch{l||(a("Could not reach server"),t(null))}},400);Se(()=>{l=!0,clearTimeout(c)})}),{serverVersion:e,authModInfo:r,serverError:n}}function Ar(s,e,t){const[r,i]=A("idle");return he(()=>{const n=e();if(!n){i("idle");return}i("checking");let a=!1;const o=setTimeout(async()=>{try{const l=await t(s(),n);a||i(l.error?"taken":"available")}catch{a||i("error")}},500);Se(()=>{a=!0,clearTimeout(o)})}),r}function Ir(s){const e={idle:null,checking:{text:"Checking…",color:"#8b949e"},available:{text:"✓ Available",color:"#3fb950"},taken:{text:"✗ Already taken",color:"#f85149"},error:{text:"Could not verify",color:"#d29922"}},t=()=>e[s.state];return E(q,{get when(){return t()},get children(){var r=No();return w(r,()=>t().text),H(i=>U(r,"color",t().color)),r}})}function ca(s){const[e,t]=A(""),[r,i]=A(""),[n,a]=A(""),[o,l]=A(""),[c,d]=A(!1),[h,u]=A(null),[f,p]=A(!1),b=Ar(()=>s.url,e,bo),_=Ar(()=>s.url,r,vo),y=()=>o()!==""&&n()!==o(),k=()=>!c()&&e()!==""&&r()!==""&&n().length>=4&&n()===o()&&b()!=="taken"&&b()!=="checking"&&_()!=="taken"&&_()!=="checking",T=async $=>{if($.preventDefault(),!!k()){d(!0),u(null);try{const v=await xo(s.url,e(),r(),n());if(v.error){u(v.error);return}p(!0),setTimeout(()=>s.onSuccess(r(),n()),1500)}catch(v){u(v instanceof Error?v.message:"Registration failed")}finally{d(!1)}}};return(()=>{var $=Yo();return $.firstChild,$.addEventListener("submit",T),w($,E(q,{get when(){return f()},get children(){return Do()}}),null),w($,E(q,{get when(){return!f()},get children(){return[(()=>{var v=Ho(),M=v.firstChild;M.firstChild;var x=M.nextSibling;return w(M,E(Ir,{get state(){return b()}}),null),x.$$input=S=>t(S.currentTarget.value),H(S=>{var O=Ee,L=c();return S.e=ue(x,O,S.e),L!==S.t&&(x.disabled=S.t=L),S},{e:void 0,t:void 0}),H(()=>x.value=e()),v})(),(()=>{var v=Bo(),M=v.firstChild;M.firstChild;var x=M.nextSibling;return w(M,E(Ir,{get state(){return _()}}),null),x.$$input=S=>i(S.currentTarget.value),H(S=>{var O=Ee,L=c();return S.e=ue(x,O,S.e),L!==S.t&&(x.disabled=S.t=L),S},{e:void 0,t:void 0}),H(()=>x.value=r()),v})(),(()=>{var v=zo(),M=v.firstChild,x=M.nextSibling;return x.$$input=S=>a(S.currentTarget.value),H(S=>{var O=Ee,L=c();return S.e=ue(x,O,S.e),L!==S.t&&(x.disabled=S.t=L),S},{e:void 0,t:void 0}),H(()=>x.value=n()),v})(),(()=>{var v=Uo(),M=v.firstChild;M.firstChild;var x=M.nextSibling;return w(M,E(q,{get when(){return y()},get children(){return Fo()}}),null),x.$$input=S=>l(S.currentTarget.value),H(S=>{var O={...Ee,border:y()?"1px solid #f85149":"1px solid #30363d"},L=c();return S.e=ue(x,O,S.e),L!==S.t&&(x.disabled=S.t=L),S},{e:void 0,t:void 0}),H(()=>x.value=o()),v})(),ne(()=>ne(()=>!!h())()&&(()=>{var v=Ci();return w(v,h),v})()),(()=>{var v=Wo();return w(v,()=>c()?"Creating account…":"Create Account"),H(M=>{var x=!k(),S=k()?"pointer":"not-allowed",O=k()?1:.5;return x!==M.e&&(v.disabled=M.e=x),S!==M.t&&U(v,"cursor",M.t=S),O!==M.a&&U(v,"opacity",M.a=O),M},{e:void 0,t:void 0,a:void 0}),v})(),(()=>{var v=Xo();return v.$$click=()=>s.onCancel(),v})()]}}),null),$})()}function da(){const s=vs(),e=Ro(),[t,r]=A("login"),[i,n]=A("password"),[a,o]=A(s?wr():window.location.origin),[l,c]=A(""),[d,h]=A(""),[u,f]=A(""),[p,b]=A(""),{serverVersion:_,authModInfo:y,serverError:k}=la(a),T=()=>{var G,P;return((P=(G=_())==null?void 0:G.serverData)==null?void 0:P.welcomeText)??null},$=()=>{var G,P;return(((P=(G=_())==null?void 0:G.serverData)==null?void 0:P.features)??[]).filter(C=>C.name!=="auth"&&C.version!=null)},v=()=>{var P,C;const G=_();return G?((C=(P=bi(G))==null?void 0:P.authTypes)==null?void 0:C.includes("steam"))??!0:!0},M=()=>{var G,P,C;return((G=y())==null?void 0:G.allowRegistration)===!0||(((C=(P=_())==null?void 0:P.serverData)==null?void 0:C.features)??[]).some(N=>N.name==="official-like")},x=()=>{const G=a().replace(/\/$/,""),P=window.open(`${G}/api/auth/steam`,"screeps-steam-auth","width=800,height=600,left=200,top=100"),C=z=>{try{const j=JSON.parse(z.data);j.token&&(B(),Ye({url:G,auth:"token",token:j.token,serverPassword:p()||void 0,storage:null}))}catch{}},N=setInterval(()=>{P!=null&&P.closed&&B()},500),B=()=>{clearInterval(N),window.removeEventListener("message",C)};window.addEventListener("message",C),Se(B)},S=async G=>{G.preventDefault(),await Ye({url:a(),auth:i(),email:l()||void 0,password:d()||void 0,token:u()||void 0,serverPassword:p()||void 0,storage:null})},O=async G=>{G.preventDefault(),await Ye({url:a(),auth:"guest",serverPassword:p()||void 0,storage:null})},L=async(G,P)=>{try{await Ye({url:a(),auth:"password",email:G,password:P,serverPassword:p()||void 0,storage:null})}catch{r("login"),n("password"),c(G),h(P)}},I=()=>Ve()==="connecting";return(()=>{var G=ra(),P=G.firstChild;return w(G,E(q,{get when(){return T()},get children(){var C=qo();return H(()=>C.innerHTML=T()),C}}),P),w(P,E(q,{get when(){return t()==="register"},get children(){return E(ca,{get url(){return a()},get serverPassword(){return p()},onSuccess:L,onCancel:()=>r("login")})}}),null),w(P,E(q,{get when(){return t()==="login"},get children(){var C=ta(),N=C.firstChild;N.firstChild;var B=N.nextSibling,z=B.firstChild,j=z.firstChild;j.nextSibling;var se=z.nextSibling,J=B.nextSibling;return C.addEventListener("submit",S),w(N,E(q,{get when(){return M()},get children(){var D=Vo();return D.$$click=()=>r("register"),D}}),null),w(C,E(q,{when:!s,get children(){var D=jo(),F=D.firstChild,Z=F.nextSibling;return F.$$click=()=>n("password"),Z.$$click=()=>n("token"),H(V=>{var te=i()==="password"?"#238636":"transparent",Fe=i()==="token"?"#238636":"transparent";return te!==V.e&&U(F,"background",V.e=te),Fe!==V.t&&U(Z,"background",V.t=Fe),V},{e:void 0,t:void 0}),D}}),B),w(C,E(q,{when:!s,get children(){return[(()=>{var D=Zo(),F=D.firstChild,Z=F.nextSibling;return Z.$$input=V=>o(V.currentTarget.value),H(V=>ue(Z,Ee,V)),H(()=>Z.value=a()),D})(),E(q,{get when(){return k()},get children(){var D=Ko();return w(D,k),D}})]}}),B),w(C,(()=>{var D=ne(()=>i()==="password");return()=>D()?[(()=>{var F=ia(),Z=F.firstChild,V=Z.nextSibling;return V.$$input=te=>c(te.currentTarget.value),H(te=>ue(V,Ee,te)),H(()=>V.value=l()),F})(),(()=>{var F=na(),Z=F.firstChild,V=Z.nextSibling;return V.$$input=te=>h(te.currentTarget.value),H(te=>ue(V,Ee,te)),H(()=>V.value=d()),F})()]:(()=>{var F=oa(),Z=F.firstChild,V=Z.nextSibling;return V.$$input=te=>f(te.currentTarget.value),H(te=>ue(V,Ee,te)),H(()=>V.value=u()),F})()})(),B),se.$$input=D=>b(D.currentTarget.value),w(C,(()=>{var D=ne(()=>!!Lr());return()=>D()&&(()=>{var F=Ci();return w(F,Lr),F})()})(),J),w(J,()=>I()?"Connecting…":"Connect"),w(C,E(q,{get when(){return v()},get children(){return[(()=>{var D=Jo(),F=D.firstChild,Z=F.nextSibling;return Z.nextSibling,D})(),(()=>{var D=Qo();return D.$$click=x,H(F=>{var Z=I(),V=I()?"not-allowed":"pointer",te=I()?.6:1;return Z!==F.e&&(D.disabled=F.e=Z),V!==F.t&&U(D,"cursor",F.t=V),te!==F.a&&U(D,"opacity",F.a=te),F},{e:void 0,t:void 0,a:void 0}),D})()]}}),null),w(C,E(q,{when:!s||e,get children(){var D=ea();return D.addEventListener("mouseleave",F=>{F.currentTarget.style.borderColor="#30363d"}),D.addEventListener("mouseenter",F=>{I()||(F.currentTarget.style.borderColor="#8b949e")}),D.$$click=O,H(F=>{var Z=I(),V=I()?"not-allowed":"pointer",te=I()?.6:1;return Z!==F.e&&(D.disabled=F.e=Z),V!==F.t&&U(D,"cursor",F.t=V),te!==F.a&&U(D,"opacity",F.a=te),F},{e:void 0,t:void 0,a:void 0}),D}}),null),H(D=>{var F=Ee,Z=I(),V=I()?"not-allowed":"pointer",te=I()?.6:1;return D.e=ue(se,F,D.e),Z!==D.t&&(J.disabled=D.t=Z),V!==D.a&&U(J,"cursor",D.a=V),te!==D.o&&U(J,"opacity",D.o=te),D},{e:void 0,t:void 0,a:void 0,o:void 0}),H(()=>se.value=p()),C}}),null),w(G,E(q,{get when(){return $().length>0},get children(){var C=sa(),N=C.firstChild,B=N.nextSibling;return w(B,E(pe,{get each(){return $()},children:z=>(()=>{var j=aa();return w(j,()=>z.name,null),w(j,(()=>{var se=ne(()=>!!z.version);return()=>se()?` ${z.version}`:""})(),null),j})()})),C}}),null),G})()}_e(["input","click"]);var ha=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'),ua=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 fa(){const s=()=>{switch(Ve()){case"connected":return"#238636";case"connecting":return"#d29922";case"error":return"#f85149";default:return"#8b949e"}};return(()=>{var e=ua(),t=e.firstChild,r=t.firstChild,i=r.nextSibling;return w(i,(()=>{var n=ne(()=>Ve()==="connected");return()=>n()?"Online":Ve()})()),w(e,E(q,{get when(){return ft()},get children(){return ha()}}),null),H(n=>U(r,"background-color",s())),e})()}class pa{constructor(e){m(this,"container");m(this,"hoverGraphics");m(this,"pendingGraphics");m(this,"selectionContainer");m(this,"selectionGraphics",new Map);m(this,"selectionTypes",new Map);m(this,"selectionVisuals",new Map);m(this,"ticker",null);m(this,"tickerCallback",null);this.container=new xe,this.container.label="hoverHighlight",this.container.eventMode="none",this.hoverGraphics=new X,this.hoverGraphics.eventMode="none",this.container.addChild(this.hoverGraphics),this.pendingGraphics=new X,this.pendingGraphics.eventMode="none",this.container.addChild(this.pendingGraphics),this.selectionContainer=new xe,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 r=e*g,i=t*g;this.hoverGraphics.rect(r,i,g,g),this.hoverGraphics.stroke({width:1,color:16777215,alpha:.35}),this.hoverGraphics.rect(r,i,g,g),this.hoverGraphics.fill({color:16777215,alpha:.06})}setSelectedObjects(e){this.selectionContainer.removeChildren();for(const t of this.selectionGraphics.values())t.destroy();this.selectionGraphics.clear(),this.selectionTypes.clear(),this.selectionVisuals.clear();for(const{id:t,type:r,visual:i}of e){const n=new X;n.eventMode="none",this.selectionContainer.addChild(n),this.selectionGraphics.set(t,n),this.selectionTypes.set(t,r),this.selectionVisuals.set(t,i),r==="creep"?this.drawCreepRing(n,i.x,i.y):this.drawStructureBox(n,i.x,i.y)}}clearSelection(){this.selectionContainer.removeChildren();for(const e of this.selectionGraphics.values())e.destroy();this.selectionGraphics.clear(),this.selectionTypes.clear(),this.selectionVisuals.clear()}setPendingTile(e,t){if(this.pendingGraphics.clear(),e===null||t===null)return;const r=e*g,i=t*g,n=r+g/2,a=i+g/2,o=g*.35;this.pendingGraphics.moveTo(n-o,a),this.pendingGraphics.lineTo(n+o,a),this.pendingGraphics.moveTo(n,a-o),this.pendingGraphics.lineTo(n,a+o),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.9}),this.pendingGraphics.rect(r+1,i+1,g-2,g-2),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.6})}clearPendingTile(){this.pendingGraphics.clear()}drawCreepRing(e,t,r){e.clear();const i=t+g/2,n=r+g/2,a=g*.48;e.circle(i,n,a),e.stroke({width:1.5,color:16777215,alpha:.9})}drawStructureBox(e,t,r){e.clear();const i=1;e.rect(t+i,r+i,g-i*2,g-i*2),e.stroke({width:1.5,color:16777215,alpha:.9}),e.rect(t+i,r+i,g-i*2,g-i*2),e.fill({color:16777215,alpha:.04})}trackCreepRings(){for(const[e,t]of this.selectionGraphics){if(this.selectionTypes.get(e)!=="creep")continue;const r=this.selectionVisuals.get(e);r&&this.drawCreepRing(t,r.x,r.y)}}destroy(){this.ticker&&this.tickerCallback&&this.ticker.remove(this.tickerCallback),this.ticker=null,this.tickerCallback=null,this.clearSelection(),this.clearPendingTile(),this.pendingGraphics.destroy(),this.hoverGraphics.destroy(),this.container.destroy()}}const g=12,we=50*g,ae=48,kt=128;class br{constructor(e,t){m(this,"app");m(this,"world");m(this,"hoverLayer");m(this,"destroyed",!1);m(this,"canDrag",!1);m(this,"container");m(this,"resizeObserver",null);m(this,"bounceRaf",null);m(this,"wheelTimeout",null);m(this,"navOverlay");m(this,"lastMouseX",0);m(this,"lastMouseY",0);m(this,"onHoverTile",null);m(this,"onClickTile",null);this.app=e,this.container=t,this.world=new xe,this.app.stage.addChild(this.world),this.hoverLayer=new pa(e.ticker),this.world.addChild(this.hoverLayer.container),this.navOverlay=new xe,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 fi;return await t.init({background:"#0d1117",antialias:!1,resolution:window.devicePixelRatio||1,autoDensity:!0}),e.appendChild(t.canvas),new br(t,e)}getMinScale(){const t=this.container.clientWidth,r=this.container.clientHeight;return Math.min(t,r)/(we+64)}clampView(e=!1){const t=this.world.scale.x,r=we*t,i=this.container.clientWidth,n=this.container.clientHeight,a=e?kt:0;if(r<=i){const o=i/2-r/2;e?this.world.x=Math.min(o+kt,Math.max(o-kt,this.world.x)):this.world.x=o}else{const o=i-r-ae-a,l=ae+a;this.world.x=Math.min(l,Math.max(o,this.world.x))}if(r<=n){const o=n/2-r/2;e?this.world.y=Math.min(o+kt,Math.max(o-kt,this.world.y)):this.world.y=o}else{const o=n-r-ae-a,l=ae+a;this.world.y=Math.min(l,Math.max(o,this.world.y))}this.canDrag=!0}getTargetPosition(){const e=this.world.scale.x,t=we*e,r=this.container.clientWidth,i=this.container.clientHeight;let n=null,a=null;if(t<=r)n=r/2-t/2;else{const o=r-t-ae,l=ae;this.world.x<o?n=o:this.world.x>l&&(n=l)}if(t<=i)a=i/2-t/2;else{const o=i-t-ae,l=ae;this.world.y<o?a=o:this.world.y>l&&(a=l)}return n===null&&a===null?null:{x:n??this.world.x,y:a??this.world.y}}springBack(){const e=this.getTargetPosition(),t=this.getTargetScale();if(!e&&t===null)return;const r=this.world.x,i=this.world.y,n=this.world.scale.x,a=performance.now(),o=300,l=this.container.clientWidth/2,c=this.container.clientHeight/2,d=(l-r)/n,h=(c-i)/n,u=f=>{const p=f-a,b=Math.min(1,p/o),_=1-Math.pow(1-b,3);if(t!==null){const y=n+(t-n)*_;this.world.scale.set(y),this.world.x=l-d*y,this.world.y=c-h*y}e&&t===null&&(this.world.x=r+(e.x-r)*_,this.world.y=i+(e.y-i)*_),b<1?this.bounceRaf=requestAnimationFrame(u):(this.bounceRaf=null,this.clampView())};this.cancelBounce(),this.bounceRaf=requestAnimationFrame(u)}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 Ct(0,0),r=new Ct(0,0);const i=this.app.canvas,n=4;i.addEventListener("contextmenu",o=>{o.preventDefault()}),i.addEventListener("pointerdown",o=>{this.cancelBounce(),this.cancelWheelTimeout(),e=this.canDrag,t=new Ct(o.clientX,o.clientY),r=new Ct(o.clientX,o.clientY),this.canDrag&&i.setPointerCapture(o.pointerId)}),i.addEventListener("pointermove",o=>{var u;const l=i.getBoundingClientRect();this.lastMouseX=o.clientX-l.left,this.lastMouseY=o.clientY-l.top;const c=this.screenToTile(this.lastMouseX,this.lastMouseY);if(this.hoverLayer.setHoveredTile((c==null?void 0:c.tx)??null,(c==null?void 0:c.ty)??null),(u=this.onHoverTile)==null||u.call(this,(c==null?void 0:c.tx)??null,(c==null?void 0:c.ty)??null),!e||!this.canDrag)return;const d=o.clientX-t.x,h=o.clientY-t.y;this.world.x+=d,this.world.y+=h,t=new Ct(o.clientX,o.clientY),this.clampView(!0)});const a=o=>{var h;this.canDrag&&i.releasePointerCapture(o.pointerId),e=!1;const l=o.clientX-r.x,c=o.clientY-r.y;if(Math.sqrt(l*l+c*c)<n){const u=i.getBoundingClientRect(),f=o.clientX-u.left,p=o.clientY-u.top,b=this.screenToTile(f,p);b&&((h=this.onClickTile)==null||h.call(this,b.tx,b.ty,o.ctrlKey||o.metaKey))}this.springBack()};i.addEventListener("pointerup",a),i.addEventListener("pointercancel",a),i.addEventListener("pointerleave",()=>{var o;this.hoverLayer.setHoveredTile(null,null),(o=this.onHoverTile)==null||o.call(this,null,null)}),i.addEventListener("wheel",o=>{o.preventDefault();const l=o.deltaY>0?.9:1.1,c=this.getMinScale(),d=5;let h=this.world.scale.x*l;const u=.6;h<c&&(h=c+(h-c)*u),h>d&&(h=d+(h-d)*u);const f=i.getBoundingClientRect(),p=o.clientX-f.left,b=o.clientY-f.top;if(this.cancelBounce(),h<c){const _=this.container.clientWidth/2,y=this.container.clientHeight/2,k=(_-this.world.x)/this.world.scale.x,T=(y-this.world.y)/this.world.scale.y;this.world.scale.set(h),this.world.x=_-k*h,this.world.y=y-T*h}else{const _=(p-this.world.x)/this.world.scale.x,y=(b-this.world.y)/this.world.scale.y;this.world.scale.set(h),this.world.x=p-_*h,this.world.y=b-y*h}this.clampView(),this.cancelWheelTimeout(),this.wheelTimeout=window.setTimeout(()=>{this.wheelTimeout=null,this.springBack()},80)},{passive:!1})}setTileHandlers(e,t){this.onHoverTile=e,this.onClickTile=t}screenToTile(e,t){const r=(e-this.world.x)/this.world.scale.x,i=(t-this.world.y)/this.world.scale.y,n=Math.floor(r/g),a=Math.floor(i/g);return n<0||n>=50||a<0||a>=50?null:{tx:n,ty:a}}centerView(){const e=this.container.clientWidth/2,t=this.container.clientHeight/2,r=this.world.scale.x;this.world.x=e-we*r/2,this.world.y=t-we*r/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(r=>{const{width:i,height:n}=r[0].contentRect;this.app.renderer.resize(i,n),this.clampView()}),this.resizeObserver.observe(this.container)}setupNavigationZones(e){this.navOverlay.removeChildren();const t=(a,o,l,c,d,h)=>{if(!h)return;const u=new X;u.x=a,u.y=o,u.hitArea=new pn(0,0,l,c),u.fill({color:16777215,alpha:.12}),u.poly(d),u.fill(),u.eventMode="static",u.cursor="pointer",u.alpha=1,u.on("pointerover",()=>{u.clear(),u.fill({color:16777215,alpha:.06}),u.rect(0,0,l,c),u.fill(),u.fill({color:16777215,alpha:.35}),u.poly(d),u.fill()}),u.on("pointerout",()=>{u.clear(),u.fill({color:16777215,alpha:.12}),u.poly(d),u.fill()}),u.on("pointerdown",h),this.navOverlay.addChild(u)},r=we/2,i=we/2,n=18;t(-ae,0,ae,we,[18,i,ae-6,i-n,ae-6,i+n],e.west),t(we,0,ae,we,[ae-18,i,6,i-n,6,i+n],e.east),t(0,-ae,we,ae,[r,18,r-n,ae-6,r+n,ae-6],e.north),t(0,we,we,ae,[r,ae-18,r-n,6,r+n,6],e.south);for(const a of this.navOverlay.children){const o=a,l=o.hitArea,c=this.world.x+o.x*this.world.scale.x,d=this.world.y+o.y*this.world.scale.y,h=l.width*this.world.scale.x,u=l.height*this.world.scale.y;this.lastMouseX>=c&&this.lastMouseX<=c+h&&this.lastMouseY>=d&&this.lastMouseY<=d+u&&o.emit("pointerover",new Event("pointerover"))}}clear(){for(let e=this.world.children.length-1;e>=0;e--){const t=this.world.children[e];t!==this.navOverlay&&t!==this.hoverLayer.container&&this.world.removeChild(t)}this.navOverlay.removeChildren(),this.hoverLayer.clearSelection(),this.hoverLayer.setHoveredTile(null,null),this.world.scale.set(1),this.cancelBounce(),this.cancelWheelTimeout(),this.clampView()}destroy(){var e;this.destroyed||(this.destroyed=!0,this.cancelBounce(),this.cancelWheelTimeout(),(e=this.resizeObserver)==null||e.disconnect(),this.resizeObserver=null,this.hoverLayer.destroy(),this.app.destroy(!0,{children:!0}))}}const ki=856343,ga=1448738,ma=1843496,ya=3421243,wa=ya,ba=ki,vr=7039337,Ti=3159613,va=1579032,xa=0,_a=2632986,$a=2500383,Sa=5000268,Ca=11122630,ka=16770413,Ta=7829367,Ma=16332866,Ra=6127794,Ea=6684002,Oa=12164347,Kt={tough:Sa,move:Ca,work:ka,carry:Ta,attack:Ma,ranged_attack:Ra,heal:Ea,claim:Oa},Ms=5809919,je=7979263,La=4176208,Rs=9147550,Jt=13801762,Gr=10711543,Pa=16218298,Nr=16273737,Ht=15763518,Aa=2172461,Mi=vr,Ia=13226457,it=12283502,pt=[16777215,16711680,8388736,255,65535,32768,16776960,16753920,10824234,8421504,16777215],Ga={creep:Ht,spawn:Ms,extension:je,tower:La,container:Rs,storage:Jt,link:Gr,rampart:Ms,road:Mi,wall:Aa,extractor:Rs,lab:Pa,terminal:Jt,observer:je,powerSpawn:Ht,nuker:Nr,factory:Rs,invaderCore:Nr,source:Jt,mineral:je,deposit:Jt,controller:Ms,powerBank:Ht,portal:Gr},Yt=16771195,Na=Yt,Da=je,Ha=Yt,Bt=9419667,Ba=7245682,za=12116924,Fa=12283502,Ua=9787480,Wa=14721184,Dr=ma,Xa=13684944,le=1579032,Ue=5592405,ds=11184810,Ya=9419667,ke=16771195,qa=16069959,Hr=4410435,Va=g*.05,ja=g*.2;function Qt(s,e,t,r){const i=g,n=i/2;for(let a=0;a<50;a++)for(let o=0;o<50;o++){const l=e.get(o,a)===t,c=a>0&&e.get(o,a-1)===t,d=a<49&&e.get(o,a+1)===t,h=o>0&&e.get(o-1,a)===t,u=o<49&&e.get(o+1,a)===t,f=o*i+n,p=a*i+n;l?!c&&!h&&a>0&&o>0?(s.moveTo(f,a*i),s.arc(f,p,n,-Math.PI/2,Math.PI,!0),s.lineTo(f,p),s.closePath(),r(s)):(s.rect(o*i,a*i,n,n),r(s)):c&&h&&e.get(o-1,a-1)===t&&(s.moveTo(f,a*i),s.lineTo(o*i,a*i),s.lineTo(o*i,p),s.arc(f,p,n,Math.PI,-Math.PI/2,!1),s.closePath(),r(s)),l?!c&&!u&&a>0&&o<49?(s.moveTo(f,a*i),s.arc(f,p,n,-Math.PI/2,0,!1),s.lineTo(f,p),s.closePath(),r(s)):(s.rect(f,a*i,n,n),r(s)):c&&u&&e.get(o+1,a-1)===t&&(s.moveTo(f,a*i),s.lineTo(o*i+i,a*i),s.lineTo(o*i+i,p),s.arc(f,p,n,0,-Math.PI/2,!0),s.closePath(),r(s)),l?!d&&!h&&a<49&&o>0?(s.moveTo(o*i,p),s.arc(f,p,n,Math.PI,Math.PI/2,!0),s.lineTo(f,p),s.closePath(),r(s)):(s.rect(o*i,p,n,n),r(s)):d&&h&&e.get(o-1,a+1)===t&&(s.moveTo(o*i,p),s.lineTo(o*i,a*i+i),s.lineTo(f,a*i+i),s.arc(f,p,n,Math.PI/2,Math.PI,!1),s.closePath(),r(s)),l?!d&&!u&&a<49&&o<49?(s.moveTo(f,a*i+i),s.arc(f,p,n,Math.PI/2,0,!0),s.lineTo(f,p),s.closePath(),r(s)):(s.rect(f,p,n,n),r(s)):d&&u&&e.get(o+1,a+1)===t&&(s.moveTo(f,a*i+i),s.lineTo(o*i+i,a*i+i),s.lineTo(o*i+i,p),s.arc(f,p,n,0,Math.PI/2,!1),s.closePath(),r(s))}}function Za(s,e){const t=vr,r=g,i=(n,a,o)=>{const l=n*r+r/2,c=a*r+r/2,d=r*.3;s.moveTo(l,c),o==="up"?(s.moveTo(l,c-d),s.lineTo(l+d,c+d),s.lineTo(l-d,c+d)):o==="down"?(s.moveTo(l,c+d),s.lineTo(l+d,c-d),s.lineTo(l-d,c-d)):o==="left"?(s.moveTo(l-d,c),s.lineTo(l+d,c-d),s.lineTo(l+d,c+d)):o==="right"&&(s.moveTo(l+d,c),s.lineTo(l-d,c-d),s.lineTo(l-d,c+d)),s.fill(t)};for(let n=0;n<50;n++)e.get(n,0)!==Pe.Wall&&i(n,0,"up"),e.get(n,49)!==Pe.Wall&&i(n,49,"down");for(let n=0;n<50;n++)e.get(0,n)!==Pe.Wall&&i(0,n,"left"),e.get(49,n)!==Pe.Wall&&i(49,n,"right")}function Br(s){const e=new X;e.rect(0,0,50*g,50*g),e.fill(wa);const t={color:$a,width:ja,alignment:0,cap:"round",join:"round"};Qt(e,s,Pe.Swamp,i=>i.stroke(t)),Qt(e,s,Pe.Swamp,i=>i.fill(_a));const r={color:xa,width:Va,alignment:0,cap:"round",join:"round"};return Qt(e,s,Pe.Wall,i=>i.stroke(r)),Qt(e,s,Pe.Wall,i=>i.fill(va)),Za(e,s),e.rect(0,0,50*g,50*g),e.stroke({width:1,color:Ti}),e}function Ka(s){return new Promise((e,t)=>{const r=new Image;r.onload=()=>e(r),r.onerror=t,r.src=s})}class Ri{constructor(){m(this,"cache",new Map);m(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),r=this.cache.get(t);if(r)return Promise.resolve(r);const i=this.pending.get(t);if(i)return i;const n=this.buildTexture(e,t);return this.pending.set(t,n),n.then(()=>{this.pending.delete(t)}).catch(()=>{this.pending.delete(t)}),n}async buildTexture(e,t){const r=Co(e),i=new Blob([r],{type:"image/svg+xml;charset=utf-8"}),n=URL.createObjectURL(i);try{const a=await Ka(n),o=At.from(a);return this.cache.set(t,o),o}finally{URL.revokeObjectURL(n)}}destroy(){for(const e of this.cache.values())e.destroyed||e.destroy(!0);this.cache.clear(),this.pending.clear()}}const Ja=new Ri,Ne=g*.44,Oe=g*.28,Tt=50,qs=32,Vs=12/qs,Ei=g/2-g*.44,Oi=2,zr=g*.42,Li=g*.3,Qa=Math.max(1,g*.08),el={H:13421772,O:16777215,U:5822457,L:62626,K:10514943,Z:16631694,X:11568379},tl={H:2236962,O:2236962},sl=g*.42,Pi=32,rl=9/Pi,js=g-4,Fr=g*.28,Ur=1600,il=16776428;function Zs(s,e){if(e<=0)return js;const t=Math.max(0,Math.min(1,s/e));return Fr+(js-Fr)*t}function xr(s,e,t=ke){const r=e/2,i=g/2,n=g/2,a=e*.25;s.clear(),s.roundRect(i-r,n-r,e,e,a),s.fill(t)}function nl(s,e){const t=s.__sourceGraphics;t&&(s.__sourceSize=e,xr(t,e,_r(performance.now())))}function _r(s){const e=s%Ur/Ur,t=.5-.5*Math.cos(e*Math.PI*2);return Gi(ke,il,t)}function Ks(s){const e=typeof s.energy=="number"?s.energy:0,t=typeof s.energyCapacity=="number"?s.energyCapacity:3e3;return{energy:e,capacity:t}}const Ai=g*.3,Ii=Math.max(1,g*.12),Js=Ai-Ii/2,ol=g*.42,al=1500;function Gi(s,e,t){const r=s>>16&255,i=s>>8&255,n=s&255,a=e>>16&255,o=e>>8&255,l=e&255,c=Math.round(r+(a-r)*t),d=Math.round(i+(o-i)*t),h=Math.round(n+(l-n)*t);return c<<16|d<<8|h}function Ni(s,e){s.clear(),s.circle(g/2,g/2,Ai),s.stroke({width:Ii,color:e,alpha:.95})}function Qs(s,e,t,r,i,n,a){if(s.clear(),n<=0||i<=0)return;const o=Math.min(1,i/n);if(o>=1){s.circle(e,t,r),s.fill({color:a,alpha:.55});return}const l=-Math.PI/2,c=l+o*Math.PI*2;s.moveTo(e,t),s.lineTo(e+r*Math.cos(l),t+r*Math.sin(l)),s.arc(e,t,r,l,c),s.closePath(),s.fill({color:a,alpha:.55})}function Ge(s,e,t){return t.flatMap(([r,i])=>[s+r*g,e+i*g])}function nt(s,e,t,r){t-e<.001||(s.moveTo(Ne*Math.cos(e),Ne*Math.sin(e)),s.arc(0,0,Ne,e,t),s.lineTo(Oe*Math.cos(t),Oe*Math.sin(t)),s.arc(0,0,Oe,t,e,!0),s.closePath(),s.fill(r))}function er(s){let e=0;if(typeof s.storeCapacity=="number")e=s.storeCapacity;else{const r=s.body;r&&(e=r.filter(i=>i.type==="carry").length*50)}if(e===0)return{used:0,capacity:0};let t=0;if(s.store&&typeof s.store=="object"){const r=s.store;for(const i in r){const n=r[i];typeof n=="number"&&(t+=n)}}else typeof s.energy=="number"&&(t=s.energy);return{used:t,capacity:e}}function tr(s,e){return e<=0||s<=0?0:Oe*.8*Math.min(1,s/e)}function ll(s,e){const t=s.__creepFillGraphics;t&&(t.clear(),e>0&&(t.circle(0,0,e),t.fill(Yt)))}function cl(s){return Ga[s]??Ia}function gt(s){const e=typeof s.energyCapacity=="number"?s.energyCapacity:typeof s.storeCapacity=="number"?s.storeCapacity:50;let t=0;return typeof s.energy=="number"?t=s.energy:s.store&&typeof s.store=="object"&&(t=s.store.energy??0),{energy:t,capacity:e}}function Di(s){return s<100?.7:1}function sr(s,e){return e<=0||s<=0?0:Li*Di(e)*Math.min(1,s/e)}function dl(s,e,t,r){const i=g/2,n=g/2,a=Di(t),o=new X;o.circle(i,n,zr*a),o.fill(le),o.circle(i,n,zr*a),o.stroke({width:Qa*a,color:r}),o.circle(i,n,Li*a),o.fill(ds),s.addChild(o);const l=new X,c=sr(e,t);c>0&&(l.circle(i,n,c),l.fill(ke)),s.addChild(l),s.__fillGraphics=l}function hl(s,e){const t=g/2,r=g/2,i=s.__fillGraphics;i&&(i.clear(),e>0&&(i.circle(t,r,e),i.fill(ke)))}const rr=-g*.4,ir=-g*.3,nr=g*.8,gs=g*.6;function or(s,e){return e<=0||s<=0?0:gs*Math.min(1,s/e)}function Hi(s,e){const t=s.__towerFillGraphics;if(t&&(t.clear(),e>0)){const r=Math.max(.5,g*.02);t.rect(rr+r,ir+gs-e+r,nr-r*2,e-r*2),t.fill(ke)}}const ar=g*.65,lr=ar,Me=g*.42;function cr(s,e,t,r,i,n,a,o){s.clear();const l=8,c=.1,d=2*Math.PI/l-c;for(let h=0;h<l;h++){const u=-Math.PI/2+h*(2*Math.PI/l)+c/2,f=u+d,p=e+i*Math.cos(u),b=t+i*Math.sin(u);if(h<n)s.moveTo(p,b),s.arc(e,t,r,u,f),s.arc(e,t,i,f,u,!0),s.closePath(),s.fill({color:14540253,alpha:.9});else if(h===n&&o>0){if(s.moveTo(p,b),s.arc(e,t,r,u,f),s.arc(e,t,i,f,u,!0),s.closePath(),s.fill({color:1973790,alpha:.85}),a>0){const _=Math.min(1,a/o),y=u+d*_;s.moveTo(p,b),s.arc(e,t,r,u,y),s.arc(e,t,i,y,u,!0),s.closePath(),s.fill({color:14540253,alpha:.9})}}else s.moveTo(p,b),s.arc(e,t,r,u,f),s.arc(e,t,i,f,u,!0),s.closePath(),s.fill({color:1973790,alpha:.6})}}function dr(s,e){const t=s.user;return typeof t!="string"||!e?!1:t!==e}function es(s,e=!0,t,r,i,n){var p,b,_;const a=new xe,o=new X,l=cl(s.type),c=g/2,d=g/2,h=typeof s.user=="string"?s.user:void 0,f=h!==void 0&&t!==void 0&&h!==t?it:Ya;switch(s.type){case"creep":{const y=2*Math.PI,k=new xe;k.position.set(c,d),k.rotation=-Math.PI/2;const T=dr(s,t);if(T){const Q=new X;Q.circle(0,0,Ne+.75),Q.stroke({width:1.5,color:it}),k.addChild(Q)}const $=new X;$.circle(0,0,Ne),$.fill(ki),k.addChild($);const v=s.body??[];let M=0,x=0,S=0;const O=[],L={};for(const Q of v)Q.type==="work"?M++:Q.type==="move"?x++:(L[Q.type]===void 0&&(O.push(Q.type),L[Q.type]=0),L[Q.type]++,S++);const I=M/Tt*y,G=x/Tt*y,P=S/Tt*y,C=I/2,N=C+P/2,B=Math.PI-G/2,z=Math.PI+G/2,j=y-I/2-P/2,se=y-I/2,J=new X;I>0&&nt(J,-I/2,C,Kt.work);let D=C;for(const Q of O){const $e=(L[Q]??0)/Tt*y/2;nt(J,D,D+$e,Kt[Q]??7829367),D+=$e}nt(J,N,B,Dr),G>0&&nt(J,B,z,Kt.move),nt(J,z,j,Dr);let F=se;for(const Q of O){const $e=(L[Q]??0)/Tt*y/2;nt(J,F-$e,F,Kt[Q]??7829367),F-=$e}k.addChild(J);const Z=new X;Z.circle(0,0,Oe),Z.fill(ga),k.addChild(Z);const V=typeof s.user=="string"?s.user:void 0,te=V?(p=n==null?void 0:n[V])==null?void 0:p.badge:void 0;if(te&&i){const Q=new us;Q.anchor.set(.5,.5);const $e=Oe*2;Q.width=$e,Q.height=$e,Q.rotation=Math.PI/2,k.addChild(Q),i.getOrCreate(te).then(jt=>{Q.destroyed||(Q.texture=jt)}).catch(()=>{})}else if(T){const Q=new X;Q.circle(0,0,Oe*.82),Q.fill({color:it,alpha:.9}),k.addChild(Q)}const{used:Fe,capacity:qt}=er(s),Vt=tr(Fe,qt),tt=new X;Vt>0&&(tt.circle(0,0,Vt),tt.fill(Yt)),k.addChild(tt),a.__creepFillGraphics=tt,a.__creepUsed=Fe,a.__creepCapacity=qt;const _t=(Ne+Oe)/2,$t=(Ne-Oe)*.45,Ae=new X;Ae.moveTo(Ne,0),Ae.lineTo(_t,-$t),Ae.lineTo(_t,$t),Ae.closePath(),Ae.fill(Xa),k.addChild(Ae),a.addChild(k),a.__bodyContainer=k;break}case"extension":{const{energy:y,capacity:k}=gt(s);dl(a,y,k,f),a.__extEnergy=y,a.__extCapacity=k;break}case"spawn":{o.circle(c,d,g*.65),o.fill(le),o.circle(c,d,g*.65),o.stroke({width:g*.1,color:13421772}),o.circle(c,d,g*.4),o.fill(ke);break}case"powerSpawn":{o.circle(c,d,g*.65),o.fill(le),o.circle(c,d,g*.65),o.stroke({width:g*.1,color:qa}),o.circle(c,d,g*.4),o.fill(ke);break}case"source":{const{energy:y,capacity:k}=Ks(s),T=Zs(y,k),$=new X;xr($,T,_r(performance.now())),a.addChild($),a.__sourceGraphics=$,a.__sourceEnergy=y,a.__sourceCapacity=k,a.__sourceSize=T;break}case"constructionSite":{const y=typeof s.user=="string"?s.user:void 0,k=y!==void 0&&y===t,T=k?Bt:Fa,$=k?Ba:Ua,v=k?za:Wa,M=typeof s.progress=="number"?s.progress:0,x=typeof s.progressTotal=="number"?s.progressTotal:1,S=new X;a.addChild(S),a.__csBuildGlow=S;const O=new X;Qs(O,c,d,Js,M,x,T),a.addChild(O),a.__csFillGraphics=O;const L=new X;Ni(L,T),a.addChild(L),a.__csRingGraphics=L,a.__csProgress=M,a.__csProgressTotal=x,a.__csUser=y,a.__csColor=T,a.__csColorDark=$,a.__csColorLight=v;break}case"mineral":{const y=typeof s.mineralType=="string"?s.mineralType:"?",k=el[y]??je,T=tl[y]??16777215,$=new X;$.circle(c,d,sl),$.fill(k),a.addChild($);const v=new yt({text:y,style:{fontSize:Pi,fill:T,fontWeight:"bold"}});v.anchor.set(.5,.5),v.scale.set(rl),v.position.set(c,d),a.addChild(v);break}case"deposit":{o.rect(2,2,g-4,g-4),o.fill(l);break}case"controller":{const y=typeof s.level=="number"?s.level:0,k=typeof s.progress=="number"?s.progress:0,T=typeof s.progressTotal=="number"?s.progressTotal:0,$=typeof s.user=="string"?s.user:void 0,v=$?(b=n==null?void 0:n[$])==null?void 0:b.badge:void 0,M=new X,x=[];for(let L=0;L<8;L++){const I=-Math.PI/2+L*Math.PI/4;x.push(c+ar*Math.cos(I),d+ar*Math.sin(I))}M.poly(x),M.fill(2238513),M.poly(x),M.stroke({width:g*.07,color:8027781}),a.addChild(M);const S=new X;cr(S,c,d,lr,Me,y,k,T),a.addChild(S),a.__ctrlSegGraphics=S,a.__ctrlLevel=y,a.__ctrlProgress=k,a.__ctrlProgressTotal=T;const O=new X;if(v?(O.circle(c,d,Me),O.fill(le)):(O.circle(c,d,Me),O.fill(3028031),O.circle(c,d,Me),O.stroke({width:g*.04,color:8027781}),O.circle(c,d,g*.16),O.fill(10133672)),a.addChild(O),v&&i){const L=new us;L.anchor.set(.5,.5),L.width=Me*2,L.height=Me*2,L.position.set(c,d);const I=new X;I.circle(c,d,Me),I.fill(16777215),a.addChild(L),L.mask=I,a.addChild(I),i.getOrCreate(v).then(G=>{L.destroyed||(L.texture=G)}).catch(()=>{})}break}case"energy":{o.circle(c,d,g*.2),o.fill(ke);break}case"road":break;case"wall":{o.circle(c,d,g*.4),o.fill(le),o.circle(c,d,g*.4),o.stroke({width:g*.05,color:ds});break}case"rampart":break;case"tower":{const{energy:y,capacity:k}=gt(s),T=new X;T.circle(c,d,g*.6),T.fill(le),T.circle(c,d,g*.6),T.stroke({width:g*.05,color:f}),a.addChild(T);const $=new xe;$.position.set(c,d);const v=new X;v.rect(rr,ir,nr,gs),v.fill(le),$.addChild(v);const M=new X;$.addChild(M),a.__towerFillGraphics=M,a.__towerEnergy=y,a.__towerCapacity=k,Hi(a,or(y,k));const x=new X;x.rect(rr,ir,nr,gs),x.stroke({width:1,color:Ue}),$.addChild(x);const S=new X;S.rect(-g*.2,-g*.9,g*.4,g*.5),S.fill(ds),S.rect(-g*.2,-g*.9,g*.4,g*.5),S.stroke({width:g*.07,color:le}),$.addChild(S),a.addChild($),a.__barrelContainer=$;break}case"storage":{const y=Ge(c,d,[[-.6,-.7],[0,-.8],[.6,-.7],[.65,0],[.6,.7],[0,.8],[-.6,.7],[-.65,0],[-.6,-.7]]);o.poly(y),o.fill(le),o.poly(y),o.stroke({width:g*.05,color:f}),o.rect(c-g*.5,d-g*.6,g*1,g*1.2),o.fill(Ue),o.rect(c-g*.5,d-g*.6,g*1,g*1.2),o.stroke({width:g*.1,color:le});break}case"terminal":{const y=Ge(c,d,[[0,-.8],[.55,-.55],[.8,0],[.55,.55],[0,.8],[-.55,.55],[-.8,0],[-.55,-.55],[0,-.8]]),k=Ge(c,d,[[0,-.65],[.45,-.45],[.65,0],[.45,.45],[0,.65],[-.45,.45],[-.65,0],[-.45,-.45],[0,-.65]]);o.poly(y),o.fill(le),o.poly(y),o.stroke({width:g*.05,color:f}),o.poly(k),o.fill(ds),o.rect(c-g*.45,d-g*.45,g*.9,g*.9),o.fill(Ue),o.rect(c-g*.45,d-g*.45,g*.9,g*.9),o.stroke({width:g*.1,color:le});break}case"link":{const y=Ge(c,d,[[0,-.5],[.4,0],[0,.5],[-.4,0],[0,-.5]]),k=Ge(c,d,[[0,-.3],[.25,0],[0,.3],[-.25,0],[0,-.3]]);o.poly(y),o.fill(le),o.poly(y),o.stroke({width:g*.05,color:f}),o.poly(k),o.fill(Ue);break}case"lab":{const y=d-g*.025;o.circle(c,y,g*.55),o.fill(le),o.circle(c,y,g*.55),o.stroke({width:g*.05,color:f}),o.circle(c,y,g*.4),o.fill(Ue),o.rect(c-g*.45,d+g*.3,g*.9,g*.25),o.fill(le),o.poly(Ge(c,d,[[-.45,.3],[-.45,.55],[.45,.55],[.45,.3]])),o.stroke({width:g*.05,color:f});break}case"container":{o.rect(c-g*.225,d-g*.3,g*.45,g*.6),o.fill(ke),o.rect(c-g*.225,d-g*.3,g*.45,g*.6),o.stroke({width:g*.1,color:le});break}case"observer":{o.circle(c,d,g*.45),o.fill(le),o.circle(c,d,g*.45),o.stroke({width:g*.05,color:f}),o.circle(c+g*.225,d,g*.2),o.fill(f);break}case"nuker":{const y=Ge(c,d,[[0,-1],[-.47,.2],[-.5,.5],[.5,.5],[.47,.2],[0,-1]]),k=Ge(c,d,[[0,-.8],[-.4,.2],[.4,.2],[0,-.8]]);o.poly(y),o.fill(le),o.poly(y),o.stroke({width:g*.05,color:f}),o.poly(k),o.fill(Ue),o.poly(k),o.stroke({width:g*.01,color:f});break}case"factory":case"extractor":case"invaderCore":{o.circle(c,d,g*.45),o.fill(le),o.circle(c,d,g*.45),o.stroke({width:g*.05,color:f}),o.circle(c,d,g*.35),o.fill(Ue);break}case"flag":{const y=typeof s.color=="number"?s.color:0,k=typeof s.secondaryColor=="number"?s.secondaryColor:0,T=pt[y]??pt[0],$=pt[k]??pt[0],v=1.5,M=g*.08*v,x=g*.7*v,S=c-M/2,O=d-g*.25*v;o.rect(S,O,M,x),o.fill(8947848);const L=S+M,I=O,G=L+g*.45*v,P=I,C=I+g*.44*v,N=(P+C)/2,B=N;if(o.moveTo(L,P),o.lineTo(G,N),o.lineTo(L,B),o.closePath(),o.fill(T),o.moveTo(L,B),o.lineTo(G,N),o.lineTo(L,C),o.closePath(),o.fill($),a.addChild(o),a.__flagColor=y,a.__flagSecondaryColor=k,typeof s.name=="string"){const z=new yt({text:s.name,style:{fontSize:qs,fill:16777215}});z.scale.set(Vs),z.anchor.set(.5,0),z.x=c,z.y=d+g*.55,z.visible=e,a.__nameLabel=z,a.addChild(z)}break}case"ruin":{const y=typeof s.user=="string"?s.user:void 0,T=y!==void 0&&y===t?Bt:it,$=g*.42,v=6,M=Math.PI/5,x=new X;for(let L=0;L<v;L++){const I=L*Math.PI*2/v,G=I-M/2,P=I+M/2,C=c+$*Math.cos(G),N=d+$*Math.sin(G);x.moveTo(C,N),x.arc(c,d,$,G,P),x.stroke({width:g*.09,color:T,alpha:.75,cap:"round"})}a.addChild(x);const S=g*.18,O=new X;O.moveTo(c-S,d-S),O.lineTo(c+S,d+S),O.moveTo(c+S,d-S),O.lineTo(c-S,d+S),O.stroke({width:g*.11,color:T,cap:"round"}),a.addChild(O);break}case"tombstone":{const y=typeof s.user=="string"?s.user:void 0,T=y!==void 0&&y===t?Bt:it,$=g*.62,v=g*.82,M=c-$/2,x=d-v/2,S=$/2,O=new X;O.moveTo(M,x+S),O.arc(c,x+S,S,Math.PI,0,!1),O.lineTo(M+$,x+v),O.lineTo(M,x+v),O.closePath(),O.fill(le),O.moveTo(M,x+S),O.arc(c,x+S,S,Math.PI,0,!1),O.lineTo(M+$,x+v),O.lineTo(M,x+v),O.closePath(),O.stroke({width:g*.07,color:T,alpha:.9}),a.addChild(O);const L=g*.18,I=new X;I.moveTo(c-L,d-L*.6),I.lineTo(c+L,d+L*.6),I.moveTo(c+L,d-L*.6),I.lineTo(c-L,d+L*.6),I.stroke({width:g*.09,color:T,cap:"round"}),a.addChild(I);break}default:{const y=g-2;o.rect(1,1,y,y),o.fill(l)}}if(s.type!=="extension"&&s.type!=="road"&&s.type!=="creep"&&s.type!=="tower"&&s.type!=="controller"&&s.type!=="flag"&&s.type!=="source"&&s.type!=="constructionSite"&&s.type!=="mineral"&&s.type!=="tombstone"&&s.type!=="ruin"&&a.addChild(o),s.type==="creep"&&typeof s.name=="string"){const y=dr(s,t);let k;if(y){const v=typeof s.user=="string"?s.user:void 0;k=v?((_=n==null?void 0:n[v])==null?void 0:_.username)??v:"Hostile"}else k=s.name;const T=y?it:16777215,$=new yt({text:k,style:{fontSize:qs,fill:T}});$.scale.set(Vs),$.anchor.set(.5,1),$.x=c,$.y=Ei-Oi,$.visible=e,a.__nameLabel=$,a.addChild($)}return s.type==="creep"&&(a.zIndex=1),s.type==="flag"&&(a.zIndex=10),a.position.set(s.x*g,s.y*g),a}function Mt(s){s.destroy({children:!0})}class ul{constructor(e,t=!0,r,i,n){m(this,"container");m(this,"objects",new Map);m(this,"rawObjects",new Map);m(this,"roadGraphics");m(this,"rampartGraphics");m(this,"ticker",null);m(this,"tickerCallback",null);m(this,"extAnimations",new Map);m(this,"creepFillAnimations",new Map);m(this,"towerFillAnimations",new Map);m(this,"sourceAnimations",new Map);m(this,"buildGlowAnimations",new Map);m(this,"EXT_ANIM_DURATION",300);m(this,"lastWorldScale",1);m(this,"showLabels");m(this,"currentUserId");m(this,"badge");m(this,"badgeCache",Ja);m(this,"users");this.showLabels=t,this.currentUserId=r,this.badge=i,this.users=n,this.container=new xe,this.container.sortableChildren=!0,this.rampartGraphics=new X,this.rampartGraphics.zIndex=-1,this.container.addChild(this.rampartGraphics),this.roadGraphics=new X,this.container.addChild(this.roadGraphics),e&&(this.ticker=e,this.tickerCallback=()=>this.tick(),e.add(this.tickerCallback))}tick(){var a;for(const o of this.objects.values()){const l=o.__targetX,c=o.__targetY;if(l!==void 0&&c!==void 0){const d=l-o.x,h=c-o.y;Math.abs(d)<.5&&Math.abs(h)<.5?(o.position.set(l,c),o.__targetX=void 0,o.__targetY=void 0):(o.x+=d*.15,o.y+=h*.15)}}const e=((a=this.container.parent)==null?void 0:a.scale.x)??1;if(e!==this.lastWorldScale){this.lastWorldScale=e;for(const o of this.objects.values())this.applyLabelScale(o)}const t=performance.now(),r=t/1e3,i=.5+.5*Math.sin(t*2*Math.PI/al);for(const o of this.objects.values())o.__barrelContainer&&(o.__barrelContainer.rotation=r*.4),o.__csRingGraphics&&o.__csColorDark!==void 0&&o.__csColorLight!==void 0&&Ni(o.__csRingGraphics,Gi(o.__csColorDark,o.__csColorLight,i));for(const[o,l]of this.extAnimations){const c=t-l.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),h=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;hl(l.visual,l.fromRadius+(l.toRadius-l.fromRadius)*h),d>=1&&this.extAnimations.delete(o)}for(const[o,l]of this.creepFillAnimations){const c=t-l.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),h=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;ll(l.visual,l.fromRadius+(l.toRadius-l.fromRadius)*h),d>=1&&this.creepFillAnimations.delete(o)}for(const[o,l]of this.towerFillAnimations){const c=t-l.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),h=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;Hi(l.visual,l.fromRadius+(l.toRadius-l.fromRadius)*h),d>=1&&this.towerFillAnimations.delete(o)}for(const[o,l]of this.sourceAnimations){const c=t-l.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),h=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;nl(l.visual,l.fromRadius+(l.toRadius-l.fromRadius)*h),d>=1&&this.sourceAnimations.delete(o)}const n=_r(t);for(const o of this.objects.values()){const l=o.__sourceGraphics;l&&xr(l,o.__sourceSize??js,n)}for(const[o,l]of this.buildGlowAnimations){const c=this.objects.get(o),d=c==null?void 0:c.__csBuildGlow;if(!c||!d){this.buildGlowAnimations.delete(o);continue}const h=(t-l.startTime)/l.duration;let u;h<=0?u=0:h<.5?u=h/.5:h<.7?u=1:h<1?u=1-(h-.7)/.3:u=0,d.clear(),u>0&&(d.circle(g/2,g/2,ol),d.fill({color:ke,alpha:u*.75})),h>=1&&this.buildGlowAnimations.delete(o)}}startExtAnimation(e,t,r,i,n,a){const o=sr(r,i),l=sr(n,a);o!==l&&this.extAnimations.set(e,{visual:t,fromRadius:o,toRadius:l,startTime:performance.now()})}startCreepFillAnimation(e,t,r,i,n,a){const o=tr(r,i),l=tr(n,a);o!==l&&this.creepFillAnimations.set(e,{visual:t,fromRadius:o,toRadius:l,startTime:performance.now()})}startTowerFillAnimation(e,t,r,i,n,a){const o=or(r,i),l=or(n,a);o!==l&&this.towerFillAnimations.set(e,{visual:t,fromRadius:o,toRadius:l,startTime:performance.now()})}startSourceAnimation(e,t,r,i,n,a){const o=Zs(r,i),l=Zs(n,a);o!==l&&this.sourceAnimations.set(e,{visual:t,fromRadius:o,toRadius:l,startTime:performance.now()})}update(e,t,r){r&&(this.users=r);let i=!1;if(t)for(const n in t)if(t[n]===null){const o=this.rawObjects.get(n);o&&o.type==="road"&&(i=!0);const l=this.objects.get(n);l&&(this.container.removeChild(l),Mt(l),this.objects.delete(n),this.rawObjects.delete(n),this.extAnimations.delete(n),this.creepFillAnimations.delete(n),this.towerFillAnimations.delete(n),this.sourceAnimations.delete(n),this.buildGlowAnimations.delete(n))}else{const o=e[n];if(!o)continue;if(o.type==="road"){const c=this.rawObjects.get(n);(!c||c.x!==o.x||c.y!==o.y)&&(i=!0)}this.rawObjects.set(n,o);const l=this.objects.get(n);if(l){const c=o.x*g,d=o.y*g;if(o.type==="creep"){const h=o.x-(l.__tileX??o.x),u=o.y-(l.__tileY??o.y);(h!==0||u!==0)&&(l.__angle=Math.atan2(u,h),l.__bodyContainer&&(l.__bodyContainer.rotation=l.__angle)),l.__tileX=o.x,l.__tileY=o.y,(l.x!==c||l.y!==d)&&(l.__targetX=c,l.__targetY=d);const{used:f,capacity:p}=er(o);(l.__creepUsed!==f||l.__creepCapacity!==p)&&(this.startCreepFillAnimation(n,l,l.__creepUsed??0,l.__creepCapacity??p,f,p),l.__creepUsed=f,l.__creepCapacity=p)}else if(o.type==="flag"){const h=typeof o.color=="number"?o.color:0,u=typeof o.secondaryColor=="number"?o.secondaryColor:0;if(l.__flagColor!==h||l.__flagSecondaryColor!==u){this.container.removeChild(l),Mt(l),this.objects.delete(n);const p=es(o,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);p.__tileX=o.x,p.__tileY=o.y,this.applyLabelScale(p),this.objects.set(n,p),this.container.addChild(p)}else l.position.set(c,d)}else l.position.set(c,d);if(o.type==="extension"){const{energy:h,capacity:u}=gt(o),f=l;(f.__extEnergy!==h||f.__extCapacity!==u)&&(this.startExtAnimation(n,l,f.__extEnergy??0,f.__extCapacity??u,h,u),f.__extEnergy=h,f.__extCapacity=u)}if(o.type==="tower"){const{energy:h,capacity:u}=gt(o);(l.__towerEnergy!==h||l.__towerCapacity!==u)&&(this.startTowerFillAnimation(n,l,l.__towerEnergy??0,l.__towerCapacity??u,h,u),l.__towerEnergy=h,l.__towerCapacity=u)}if(o.type==="controller"){const h=typeof o.level=="number"?o.level:0,u=typeof o.progress=="number"?o.progress:0,f=typeof o.progressTotal=="number"?o.progressTotal:0;(l.__ctrlLevel!==h||l.__ctrlProgress!==u||l.__ctrlProgressTotal!==f)&&(l.__ctrlSegGraphics&&cr(l.__ctrlSegGraphics,g/2,g/2,lr,Me,h,u,f),l.__ctrlLevel=h,l.__ctrlProgress=u,l.__ctrlProgressTotal=f)}if(o.type==="source"){const{energy:h,capacity:u}=Ks(o);(l.__sourceEnergy!==h||l.__sourceCapacity!==u)&&(this.startSourceAnimation(n,l,l.__sourceEnergy??0,l.__sourceCapacity??u,h,u),l.__sourceEnergy=h,l.__sourceCapacity=u)}if(o.type==="constructionSite"){const h=typeof o.progress=="number"?o.progress:0,u=typeof o.progressTotal=="number"?o.progressTotal:1;(l.__csProgress!==h||l.__csProgressTotal!==u)&&(l.__csFillGraphics&&Qs(l.__csFillGraphics,g/2,g/2,Js,h,u,l.__csColor??Bt),l.__csProgress=h,l.__csProgressTotal=u)}}else{const c=es(o,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);c.__tileX=o.x,c.__tileY=o.y,this.applyLabelScale(c),this.objects.set(n,c),this.container.addChild(c)}}else{const n=new Set;for(const a in e){const o=e[a];if(!o)continue;n.add(a),this.rawObjects.set(a,o);const l=this.objects.get(a);if(l){const c=o.x*g,d=o.y*g;if(o.type==="creep"){const h=o.x-(l.__tileX??o.x),u=o.y-(l.__tileY??o.y);(h!==0||u!==0)&&(l.__angle=Math.atan2(u,h),l.__bodyContainer&&(l.__bodyContainer.rotation=l.__angle)),l.__tileX=o.x,l.__tileY=o.y,(l.x!==c||l.y!==d)&&(l.__targetX=c,l.__targetY=d);const{used:f,capacity:p}=er(o);(l.__creepUsed!==f||l.__creepCapacity!==p)&&(this.startCreepFillAnimation(a,l,l.__creepUsed??0,l.__creepCapacity??p,f,p),l.__creepUsed=f,l.__creepCapacity=p)}else if(o.type==="flag"){const h=typeof o.color=="number"?o.color:0,u=typeof o.secondaryColor=="number"?o.secondaryColor:0;if(l.__flagColor!==h||l.__flagSecondaryColor!==u){this.container.removeChild(l),Mt(l),this.objects.delete(a);const p=es(o,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);p.__tileX=o.x,p.__tileY=o.y,this.applyLabelScale(p),this.objects.set(a,p),this.container.addChild(p)}else l.position.set(c,d)}else l.position.set(c,d);if(o.type==="extension"){const{energy:h,capacity:u}=gt(o),f=l;(f.__extEnergy!==h||f.__extCapacity!==u)&&(this.startExtAnimation(a,l,f.__extEnergy??0,f.__extCapacity??u,h,u),f.__extEnergy=h,f.__extCapacity=u)}if(o.type==="tower"){const{energy:h,capacity:u}=gt(o);(l.__towerEnergy!==h||l.__towerCapacity!==u)&&(this.startTowerFillAnimation(a,l,l.__towerEnergy??0,l.__towerCapacity??u,h,u),l.__towerEnergy=h,l.__towerCapacity=u)}if(o.type==="controller"){const h=typeof o.level=="number"?o.level:0,u=typeof o.progress=="number"?o.progress:0,f=typeof o.progressTotal=="number"?o.progressTotal:0;(l.__ctrlLevel!==h||l.__ctrlProgress!==u||l.__ctrlProgressTotal!==f)&&(l.__ctrlSegGraphics&&cr(l.__ctrlSegGraphics,g/2,g/2,lr,Me,h,u,f),l.__ctrlLevel=h,l.__ctrlProgress=u,l.__ctrlProgressTotal=f)}if(o.type==="source"){const{energy:h,capacity:u}=Ks(o);(l.__sourceEnergy!==h||l.__sourceCapacity!==u)&&(this.startSourceAnimation(a,l,l.__sourceEnergy??0,l.__sourceCapacity??u,h,u),l.__sourceEnergy=h,l.__sourceCapacity=u)}if(o.type==="constructionSite"){const h=typeof o.progress=="number"?o.progress:0,u=typeof o.progressTotal=="number"?o.progressTotal:1;(l.__csProgress!==h||l.__csProgressTotal!==u)&&(l.__csFillGraphics&&Qs(l.__csFillGraphics,g/2,g/2,Js,h,u,l.__csColor??Bt),l.__csProgress=h,l.__csProgressTotal=u)}}else{const c=es(o,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);c.__tileX=o.x,c.__tileY=o.y,this.applyLabelScale(c),this.objects.set(a,c),this.container.addChild(c)}}for(const[a,o]of this.objects)n.has(a)||(this.container.removeChild(o),Mt(o),this.objects.delete(a),this.rawObjects.delete(a),this.extAnimations.delete(a),this.creepFillAnimations.delete(a),this.towerFillAnimations.delete(a),this.sourceAnimations.delete(a),this.buildGlowAnimations.delete(a));i=!0}this.redrawRamparts(),i&&this.redrawRoads(),this.refreshForeignCreepLabels()}redrawRoads(){this.roadGraphics.clear();const e=Mi,t=Array.from({length:50},()=>new Array(50).fill(!1)),r=[];for(const l of this.rawObjects.values())l.type==="road"&&(r.push(l),l.x>=0&&l.x<50&&l.y>=0&&l.y<50&&(t[l.x][l.y]=!0));if(r.length===0)return;const i=g/2,n=g/2,a=g*.125;for(const l of r)this.roadGraphics.circle(l.x*g+i,l.y*g+n,a);this.roadGraphics.fill(e);const o=[[1,0],[1,1],[0,1],[-1,1]];for(const l of r){const c=l.x*g+i,d=l.y*g+n;for(const[h,u]of o){const f=l.x+h,p=l.y+u;if(f>=0&&f<50&&p>=0&&p<50&&t[f][p]){const b=f*g+i,_=p*g+n;this.roadGraphics.moveTo(c,d),this.roadGraphics.lineTo(b,_)}}}this.roadGraphics.stroke({width:a*2,color:e})}redrawRamparts(){this.rampartGraphics.clear();const e=g,t=e/2,r=Array.from({length:50},()=>new Array(50).fill(void 0));for(const n of this.rawObjects.values())n.type==="rampart"&&n.x>=0&&n.x<50&&n.y>=0&&n.y<50&&(r[n.x][n.y]=typeof n.user=="string"?n.user:void 0);const i=n=>!n||!this.currentUserId?{color:Hr,alpha:.7}:n===this.currentUserId?{color:Hr,alpha:.7}:{color:7807522,alpha:.5};for(let n=0;n<50;n++)for(let a=0;a<50;a++){const o=r[a][n],l=o!==void 0,c=n>0&&r[a][n-1]!==void 0,d=n<49&&r[a][n+1]!==void 0,h=a>0&&r[a-1][n]!==void 0,u=a<49&&r[a+1][n]!==void 0,f=a*e+t,p=n*e+t;if(l){const b=i(o);!c&&!h&&n>0&&a>0?(this.rampartGraphics.moveTo(f,n*e),this.rampartGraphics.arc(f,p,t,-Math.PI/2,Math.PI,!0),this.rampartGraphics.lineTo(f,p),this.rampartGraphics.fill(b)):(this.rampartGraphics.rect(a*e,n*e,t,t),this.rampartGraphics.fill(b))}else if(c&&h&&r[a-1][n-1]!==void 0){const b=i(r[a-1][n-1]);this.rampartGraphics.moveTo(f,n*e),this.rampartGraphics.lineTo(a*e,n*e),this.rampartGraphics.lineTo(a*e,p),this.rampartGraphics.arc(f,p,t,Math.PI,-Math.PI/2,!1),this.rampartGraphics.fill(b)}if(l){const b=i(o);!c&&!u&&n>0&&a<49?(this.rampartGraphics.moveTo(f,n*e),this.rampartGraphics.arc(f,p,t,-Math.PI/2,0,!1),this.rampartGraphics.lineTo(f,p),this.rampartGraphics.fill(b)):(this.rampartGraphics.rect(f,n*e,t,t),this.rampartGraphics.fill(b))}else if(c&&u&&r[a+1][n-1]!==void 0){const b=i(r[a+1][n-1]);this.rampartGraphics.moveTo(f,n*e),this.rampartGraphics.lineTo(a*e+e,n*e),this.rampartGraphics.lineTo(a*e+e,p),this.rampartGraphics.arc(f,p,t,0,-Math.PI/2,!0),this.rampartGraphics.fill(b)}if(l){const b=i(o);!d&&!h&&n<49&&a>0?(this.rampartGraphics.moveTo(a*e,p),this.rampartGraphics.arc(f,p,t,Math.PI,Math.PI/2,!0),this.rampartGraphics.lineTo(f,p),this.rampartGraphics.fill(b)):(this.rampartGraphics.rect(a*e,p,t,t),this.rampartGraphics.fill(b))}else if(d&&h&&r[a-1][n+1]!==void 0){const b=i(r[a-1][n+1]);this.rampartGraphics.moveTo(a*e,p),this.rampartGraphics.lineTo(a*e,n*e+e),this.rampartGraphics.lineTo(f,n*e+e),this.rampartGraphics.arc(f,p,t,Math.PI/2,Math.PI,!1),this.rampartGraphics.fill(b)}if(l){const b=i(o);!d&&!u&&n<49&&a<49?(this.rampartGraphics.moveTo(f,n*e+e),this.rampartGraphics.arc(f,p,t,Math.PI/2,0,!0),this.rampartGraphics.lineTo(f,p),this.rampartGraphics.fill(b)):(this.rampartGraphics.rect(f,p,t,t),this.rampartGraphics.fill(b))}else if(d&&u&&r[a+1][n+1]!==void 0){const b=i(r[a+1][n+1]);this.rampartGraphics.moveTo(f,n*e+e),this.rampartGraphics.lineTo(a*e+e,n*e+e),this.rampartGraphics.lineTo(a*e+e,p),this.rampartGraphics.arc(f,p,t,0,Math.PI/2,!1),this.rampartGraphics.fill(b)}}}getObjectsAtTile(e,t){const r=[];for(const[i,n]of this.objects){const a=this.rawObjects.get(i);a&&a.x===e&&a.y===t&&r.push({id:i,obj:a,visual:n})}return r}applyLabelScale(e){if(!e.__nameLabel)return;const t=this.lastWorldScale||1;e.__nameLabel.scale.set(Vs/t),e.__nameLabel.anchor.y===0?e.__nameLabel.y=g/2+g*.55:e.__nameLabel.y=Ei-Oi/t}refreshForeignCreepLabels(){var e,t;if(this.currentUserId)for(const[r,i]of this.objects){const n=this.rawObjects.get(r);if(!n||n.type!=="creep"||!i.__nameLabel||!dr(n,this.currentUserId))continue;const a=typeof n.user=="string"?n.user:void 0,o=a?((t=(e=this.users)==null?void 0:e[a])==null?void 0:t.username)??a:"Hostile";i.__nameLabel.text!==o&&(i.__nameLabel.text=o)}}triggerBuildAt(e,t,r){for(const[i,n]of this.objects){const a=this.rawObjects.get(i);if(!(!a||a.type!=="constructionSite")&&!(a.x!==e||a.y!==t)&&n.__csBuildGlow){this.buildGlowAnimations.set(i,{startTime:performance.now(),duration:r});return}}}setShowLabels(e){this.showLabels=e;for(const t of this.objects.values())t.__nameLabel&&(t.__nameLabel.visible=e)}getVisualById(e){return this.objects.get(e)}clear(){for(const e of this.objects.values())Mt(e);this.objects.clear(),this.rawObjects.clear(),this.extAnimations.clear(),this.creepFillAnimations.clear(),this.towerFillAnimations.clear(),this.sourceAnimations.clear(),this.buildGlowAnimations.clear(),this.roadGraphics.clear(),this.rampartGraphics.clear(),this.container.removeChildren()}destroy(){this.clear(),this.ticker&&this.tickerCallback&&this.ticker.remove(this.tickerCallback),this.ticker=null,this.tickerCallback=null}}const Es=2;function ot(s,e){return{cx:s*g+g/2,cy:e*g+g/2}}class fl{constructor(e){m(this,"container");m(this,"graphics");m(this,"animations",[]);m(this,"ticker",null);m(this,"tickerCallback",null);this.container=new xe,this.graphics=new X,this.container.addChild(this.graphics),e&&(this.ticker=e,this.tickerCallback=()=>this.animate(),e.add(this.tickerCallback))}addHarvest(e,t,r,i,n){const a=ot(e,t),o=ot(r,i);this.animations.push({fromX:a.cx,fromY:a.cy,toX:o.cx,toY:o.cy,startTime:performance.now(),duration:n,color:Na,width:Es})}addUpgradeController(e,t,r,i,n){const a=ot(e,t),o=ot(r,i);this.animations.push({fromX:a.cx,fromY:a.cy,toX:o.cx,toY:o.cy,startTime:performance.now(),duration:n,color:Da,width:Es})}addBuild(e,t,r,i,n){const a=ot(e,t),o=ot(r,i);this.animations.push({fromX:a.cx,fromY:a.cy,toX:o.cx,toY:o.cy,startTime:performance.now(),duration:n,color:Ha,width:Es})}animate(){this.graphics.clear();const e=performance.now();let t=!1;for(let r=this.animations.length-1;r>=0;r--){const i=this.animations[r],n=e-i.startTime,a=Math.min(1,n/i.duration);let o,l,c,d;const h=.5,u=.2;if(a<h){const f=a/h;o=i.fromX,l=i.fromY,c=i.fromX+(i.toX-i.fromX)*f,d=i.fromY+(i.toY-i.fromY)*f}else if(a<h+u)o=i.fromX,l=i.fromY,c=i.toX,d=i.toY;else{const f=(a-h-u)/(1-h-u);o=i.fromX+(i.toX-i.fromX)*f,l=i.fromY+(i.toY-i.fromY)*f,c=i.toX,d=i.toY}this.graphics.moveTo(o,l),this.graphics.lineTo(c,d),this.graphics.stroke({width:i.width,color:i.color}),t=!0,a>=1&&this.animations.splice(r,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 ye=s=>(s+.5)*g,Rt=4,ts={dashed:[.4*g,.4*g],dotted:[.1*g,.3*g]};function ss(s,e,t,r){let i=!0,n=t;for(let a=0;a<e.length-1;a++){const[o,l]=e[a],[c,d]=e[a+1],h=c-o,u=d-l,f=Math.sqrt(h*h+u*u);if(f<.001)continue;const p=h/f,b=u/f;let _=0;for(;_<f;){const y=Math.min(n,f-_);if(i){const k=o+p*_,T=l+b*_;s.moveTo(k,T),s.lineTo(k+p*y,T+b*y)}_+=y,n-=y,n<.001&&(i=!i,n=i?t:r)}}}function pl(s,e,t){const r=Math.max(32,Math.ceil(2*Math.PI*t/2)),i=[];for(let n=0;n<=r;n++){const a=n/r*2*Math.PI;i.push([s+Math.cos(a)*t,e+Math.sin(a)*t])}return i}function gl(s){if(s==null)return .7;if(typeof s=="number")return s;const e=s.match(/^([0-9.]+)(px)?/);if(!e)return .7;const t=parseFloat(e[1]);return e[2]?t/g:t}function ml(s){if(typeof s!="string")return"Arial";const e=s.match(/^[0-9.]+(px)?\s+(.+)$/);return e?e[2]:"Arial"}class yl{constructor(){m(this,"container");m(this,"g");this.container=new xe,this.container.label="visuals",this.g=new X,this.container.addChild(this.g)}update(e){const t=this.container.removeChildren();for(const i of t)i!==this.g&&i.destroy();if(this.g.clear(),this.container.addChild(this.g),!e)return;const r=this.g;for(const i of e.split(`
4
- `)){if(!i.trim())continue;let n;try{n=JSON.parse(i)}catch{continue}const a=n.s??{},o=a.opacity??1;switch(n.t){case"l":this.drawLine(r,n,a,o);break;case"c":this.drawCircle(r,n,a,o);break;case"r":this.drawRect(r,n,a,o);break;case"p":this.drawPoly(r,n,a,o);break;case"t":this.drawText(n,a,o);break}}}drawLine(e,t,r,i){const n=ye(t.x1),a=ye(t.y1),o=ye(t.x2),l=ye(t.y2),c=r.color??"#ffffff",d=(r.width??.1)*g;if(r.lineStyle&&r.lineStyle!=="solid"){const[h,u]=ts[r.lineStyle];ss(e,[[n,a],[o,l]],h,u)}else e.moveTo(n,a),e.lineTo(o,l);e.stroke({color:c,width:d,alpha:i})}drawCircle(e,t,r,i){const n=ye(t.x),a=ye(t.y),o=(r.radius??.5)*g,l=!!(r.fill&&r.fill!=="transparent"),c=!!(r.stroke&&r.strokeWidth),d=r.lineStyle&&r.lineStyle!=="solid";if(l&&(e.circle(n,a,o),e.fill({color:r.fill,alpha:i})),c){const h=r.strokeWidth*g;if(d){const[u,f]=ts[r.lineStyle];ss(e,pl(n,a,o),u,f)}else e.circle(n,a,o);e.stroke({color:r.stroke,width:h,alpha:i})}}drawRect(e,t,r,i){const n=ye(t.x),a=ye(t.y),o=t.w*g,l=t.h*g,c=!!(r.fill&&r.fill!=="transparent"),d=!!(r.stroke&&r.strokeWidth),h=r.lineStyle&&r.lineStyle!=="solid";if(c&&(e.rect(n,a,o,l),e.fill({color:r.fill,alpha:i})),d){const u=r.strokeWidth*g;if(h){const[f,p]=ts[r.lineStyle],b=[[n,a],[n+o,a],[n+o,a+l],[n,a+l],[n,a]];ss(e,b,f,p)}else e.rect(n,a,o,l);e.stroke({color:r.stroke,width:u,alpha:i})}}drawPoly(e,t,r,i){if(!t.points||t.points.length===0)return;const n=!!(r.fill&&r.fill!=="transparent"),a=!!(r.stroke&&r.strokeWidth);if(!n&&!a)return;const o=r.lineStyle&&r.lineStyle!=="solid",l=new Array(t.points.length*2);let c;a&&o&&(c=new Array(t.points.length));for(let d=0;d<t.points.length;d++){const[h,u]=t.points[d],f=ye(h),p=ye(u);l[d*2]=f,l[d*2+1]=p,c&&(c[d]=[f,p])}if(n&&(e.poly(l,!0),e.fill({color:r.fill,alpha:i})),a){const d=r.strokeWidth*g;if(o&&c){const[h,u]=ts[r.lineStyle],f=c[0],p=c[c.length-1],b=f[0]===p[0]&&f[1]===p[1];ss(e,b?c:[...c,f],h,u)}else e.poly(l,!0);e.stroke({color:r.stroke,width:d,alpha:i})}}drawText(e,t,r){const i=gl(t.font),n=ml(t.font),a=t.align??"left",o=new gn({fill:t.color??"#ffffff",fontSize:Math.round(i*g*Rt),fontFamily:n,align:a,...t.stroke&&t.strokeWidth?{stroke:{color:t.stroke,width:t.strokeWidth*g*Rt}}:{}});if(t.backgroundColor&&t.backgroundColor!=="transparent"){const c=mn.measureText(e.text,o),d=c.width/Rt,h=c.height/Rt,u=(t.backgroundPadding??.3)*g,f=a==="center"?.5:a==="right"?1:0,p=ye(e.x)-f*d-u,b=ye(e.y)-h/2-u,_=new X;_.rect(p,b,d+u*2,h+u*2),_.fill({color:t.backgroundColor,alpha:r}),this.container.addChild(_)}const l=new yt({text:e.text,style:o});l.scale.set(1/Rt),l.anchor.x=a==="center"?.5:a==="right"?1:0,l.anchor.y=.5,l.position.set(ye(e.x),ye(e.y)),l.alpha=r,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 _s(s,e){const t=localStorage.getItem(s),[r,i]=A(t!==null?t==="true":e);return[r,n=>{i(n),localStorage.setItem(s,String(n))}]}const[Bi,wl]=_s(ce.widescreenMode,!0),[hr,bl]=_s(ce.showCreepLabels,!0),[zi,Fi]=_s(ce.showMapRoomNames,!1),[Ui,Wi]=_s(ce.showUnclaimableRooms,!0),ur=Symbol("store-raw"),wt=Symbol("store-node"),Re=Symbol("store-has"),Xi=Symbol("store-self");function Yi(s){let e=s[Ke];if(!e&&(Object.defineProperty(s,Ke,{value:e=new Proxy(s,_l)}),!Array.isArray(s))){const t=Object.keys(s),r=Object.getOwnPropertyDescriptors(s),i=Object.getPrototypeOf(s),n=i!==null&&s!==null&&typeof s=="object"&&!Array.isArray(s)&&i!==Object.prototype;if(n){const a=Object.getOwnPropertyDescriptors(i);t.push(...Object.keys(a)),Object.assign(r,a)}for(let a=0,o=t.length;a<o;a++){const l=t[a];n&&l==="constructor"||r[l].get&&Object.defineProperty(s,l,{configurable:!0,enumerable:r[l].enumerable,get:r[l].get.bind(e)})}}return e}function Be(s){let e;return s!=null&&typeof s=="object"&&(s[Ke]||!(e=Object.getPrototypeOf(s))||e===Object.prototype||Array.isArray(s))}function bt(s,e=new Set){let t,r,i,n;if(t=s!=null&&s[ur])return t;if(!Be(s)||e.has(s))return s;if(Array.isArray(s)){Object.isFrozen(s)?s=s.slice(0):e.add(s);for(let a=0,o=s.length;a<o;a++)i=s[a],(r=bt(i,e))!==i&&(s[a]=r)}else{Object.isFrozen(s)?s=Object.assign({},s):e.add(s);const a=Object.keys(s),o=Object.getOwnPropertyDescriptors(s);for(let l=0,c=a.length;l<c;l++)n=a[l],!o[n].get&&(i=s[n],(r=bt(i,e))!==i&&(s[n]=r))}return s}function ms(s,e){let t=s[e];return t||Object.defineProperty(s,e,{value:t=Object.create(null)}),t}function Ft(s,e,t){if(s[e])return s[e];const[r,i]=A(t,{equals:!1,internal:!0});return r.$=i,s[e]=r}function vl(s,e){const t=Reflect.getOwnPropertyDescriptor(s,e);return!t||t.get||!t.configurable||e===Ke||e===wt||(delete t.value,delete t.writable,t.get=()=>s[Ke][e]),t}function qi(s){Ds()&&Ft(ms(s,wt),Xi)()}function xl(s){return qi(s),Reflect.ownKeys(s)}const _l={get(s,e,t){if(e===ur)return s;if(e===Ke)return t;if(e===Sr)return qi(s),t;const r=ms(s,wt),i=r[e];let n=i?i():s[e];if(e===wt||e===Re||e==="__proto__")return n;if(!i){const a=Object.getOwnPropertyDescriptor(s,e);Ds()&&(typeof n!="function"||s.hasOwnProperty(e))&&!(a&&a.get)&&(n=Ft(r,e,n)())}return Be(n)?Yi(n):n},has(s,e){return e===ur||e===Ke||e===Sr||e===wt||e===Re||e==="__proto__"?!0:(Ds()&&Ft(ms(s,Re),e)(),e in s)},set(){return console.warn("Cannot mutate a Store directly"),!0},deleteProperty(){return console.warn("Cannot mutate a Store directly"),!0},ownKeys:xl,getOwnPropertyDescriptor:vl};function ve(s,e,t,r=!1){if(e==="__proto__"){console.warn('Refusing to set "__proto__" on a store.');return}if(!r&&s[e]===t)return;const i=s[e],n=s.length;t===void 0?(delete s[e],s[Re]&&s[Re][e]&&i!==void 0&&s[Re][e].$()):(s[e]=t,s[Re]&&s[Re][e]&&i===void 0&&s[Re][e].$());let a=ms(s,wt),o;if((o=Ft(a,e,i))&&o.$(()=>t),Array.isArray(s)&&s.length!==n){for(let l=s.length;l<n;l++)(o=a[l])&&o.$();(o=Ft(a,"length",n))&&o.$(s.length)}(o=a[Xi])&&o.$()}function Vi(s,e){const t=Object.keys(e);for(let r=0;r<t.length;r+=1){const i=t[r];ji(i)||ve(s,i,e[i])}}function ji(s){return s==="__proto__"||s==="constructor"||s==="prototype"}function $l(s,e){if(typeof e=="function"&&(e=e(s)),e=bt(e),Array.isArray(e)){if(s===e)return;let t=0,r=e.length;for(;t<r;t++){const i=e[t];s[t]!==i&&ve(s,t,i)}ve(s,"length",r)}else Vi(s,e)}function Gt(s,e,t=[]){let r,i=s;if(e.length>1){r=e.shift();const a=typeof r,o=Array.isArray(s);if(a==="string"&&(r==="__proto__"||e.length>1&&ji(r))){console.warn(`Refusing to traverse unsafe key "${r}" on a store.`);return}if(Array.isArray(r)){for(let l=0;l<r.length;l++)Gt(s,[r[l]].concat(e),t);return}else if(o&&a==="function"){for(let l=0;l<s.length;l++)r(s[l],l)&&Gt(s,[l].concat(e),t);return}else if(o&&a==="object"){const{from:l=0,to:c=s.length-1,by:d=1}=r;for(let h=l;h<=c;h+=d)Gt(s,[h].concat(e),t);return}else if(e.length>1){Gt(s[r],e,[r].concat(t));return}i=s[r],t=[r].concat(t)}let n=e[0];typeof n=="function"&&(n=n(i,t),n===i)||r===void 0&&n==null||(n=bt(n),r===void 0||Be(i)&&Be(n)&&!Array.isArray(n)?Vi(i,n):ve(s,r,n))}function Sl(...[s,e]){const t=bt(s||{}),r=Array.isArray(t);if(typeof t!="object"&&typeof t!="function")throw new Error(`Unexpected type ${typeof t} received when initializing 'createStore'. Expected an object.`);const i=Yi(t);un.registerGraph({value:t,name:e&&e.name});function n(...a){fn(()=>{r&&a.length===1?$l(t,a[0]):Gt(t,a)})}return[i,n]}const fr=Symbol("store-root");function Wr(s){return s==="__proto__"||s==="constructor"||s==="prototype"}function dt(s,e,t,r,i){if(Wr(t))return;const n=e[t];if(s===n)return;const a=Array.isArray(s);if(t!==fr&&(!Be(s)||!Be(n)||a!==Array.isArray(n)||i&&s[i]!==n[i])){ve(e,t,s);return}if(a){if(s.length&&n.length&&(!r||i&&s[0]&&s[0][i]!=null)){let c,d,h,u,f,p,b,_;for(h=0,u=Math.min(n.length,s.length);h<u&&(n[h]===s[h]||i&&n[h]&&s[h]&&n[h][i]&&n[h][i]===s[h][i]);h++)dt(s[h],n,h,r,i);const y=new Array(s.length),k=new Map;for(u=n.length-1,f=s.length-1;u>=h&&f>=h&&(n[u]===s[f]||i&&n[u]&&s[f]&&n[u][i]&&n[u][i]===s[f][i]);u--,f--)y[f]=n[u];if(h>f||h>u){for(d=h;d<=f;d++)ve(n,d,s[d]);for(;d<s.length;d++)ve(n,d,y[d]),dt(s[d],n,d,r,i);n.length>s.length&&ve(n,"length",s.length);return}for(b=new Array(f+1),d=f;d>=h;d--)p=s[d],_=i&&p?p[i]:p,c=k.get(_),b[d]=c===void 0?-1:c,k.set(_,d);for(c=h;c<=u;c++)p=n[c],_=i&&p?p[i]:p,d=k.get(_),d!==void 0&&d!==-1&&(y[d]=n[c],d=b[d],k.set(_,d));for(d=h;d<s.length;d++)d in y?(ve(n,d,y[d]),dt(s[d],n,d,r,i)):ve(n,d,s[d])}else for(let c=0,d=s.length;c<d;c++)dt(s[c],n,c,r,i);n.length>s.length&&ve(n,"length",s.length);return}const o=Object.keys(s);for(let c=0,d=o.length;c<d;c++)Wr(o[c])||dt(s[o[c]],n,o[c],r,i);const l=Object.keys(n);for(let c=0,d=l.length;c<d;c++)s[l[c]]===void 0&&ve(n,l[c],void 0)}function Cl(s,e={}){const{merge:t,key:r="id"}=e,i=bt(s);return n=>{if(!Be(n)||!Be(i))return i;const a=dt(i,{[fr]:n},fr,t,r);return a===void 0?n:a}}const Zi=new WeakMap;function Xr(s,e){const[t,r]=Sl(e),i={id:s,type:e.type,raw:t};return Zi.set(i,n=>r(Cl(n,{key:"_id",merge:!1}))),i}const[ys,Ut]=A([]);function kl(){Ut([])}function Ki(s){Ut(e=>e.filter(t=>t.id!==s))}function Tl(s,e){const t=ys();let r=!1;const i=[];for(const n of t){const a=s[n.id];if(a===null){r=!0;continue}if(a!==void 0){const o=e[n.id];if(o){const l=Zi.get(n);l==null||l(o)}}i.push(n)}r&&Ut(i)}const[Ml,Yr]=A(null),[Rl,qr]=A(null),[mt,Vr]=A(null),[ws,jr]=A({});function Ji(s,e,t){return isNaN(t.minX)||isNaN(t.maxX)||isNaN(t.minY)||isNaN(t.maxY)?!0:s>=t.minX&&s<=t.maxX&&e>=t.minY&&e<=t.maxY}function De(s){const e=s.match(/^([WE])(\d+)([NS])(\d+)$/);if(!e)return null;const[,t,r,i,n]=e,a=t==="W"?-(parseInt(r,10)+1):parseInt(r,10),o=i==="N"?-(parseInt(n,10)+1):parseInt(n,10);return{x:a,y:o}}function Xe(s,e){const t=s<0?"W":"E",r=e<0?"N":"S",i=s<0?-s-1:s,n=e<0?-e-1:e;return`${t}${i}${r}${n}`}function Zr(s){return s===0||s<0&&(s+1)%10===0||s>0&&s%10===0}function ih(s,e){return Zr(s)||Zr(e)}function nh(s,e){const t=s<0?Math.abs(s+1)%10:Math.abs(s)%10,r=e<0?Math.abs(e+1)%10:Math.abs(e)%10;return t>=4&&t<=6&&r>=4&&r<=6}function Qi(s){const e=s;if(!e)return!1;const t=e.tagName??"";return t==="INPUT"||t==="TEXTAREA"?!0:e.isContentEditable===!0}function El(s){const e=t=>{if(Qi(t.target))return;const r=s.currentRoom(),i=r?De(r):null;if(!i)return;const n=s.worldBounds(),a=(o,l)=>!n||Ji(o,l,n);switch(t.key){case"ArrowLeft":t.preventDefault(),a(i.x-1,i.y)&&s.onMove(i.x-1,i.y);break;case"ArrowRight":t.preventDefault(),a(i.x+1,i.y)&&s.onMove(i.x+1,i.y);break;case"ArrowUp":t.preventDefault(),a(i.x,i.y-1)&&s.onMove(i.x,i.y-1);break;case"ArrowDown":t.preventDefault(),a(i.x,i.y+1)&&s.onMove(i.x,i.y+1);break}};window.addEventListener("keydown",e),Se(()=>window.removeEventListener("keydown",e))}var Ol=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'),Ll=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'),Pl=R("<span>Choose new flag position"),Os=R("<span>"),Al=R("<span>Select structure type, then click to build — Ctrl+click to remove construction sites");const{log:Kr,warn:Il,error:Jr}=et("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},bs={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}},[Qe,qe]=A("view"),[ht,en]=A({name:"",color:"COLOR_WHITE",secondaryColor:"COLOR_WHITE"}),[Ze,pr]=A(null),[$r,gr]=A(null),[vt,$s]=A({structureType:"",structureName:""});hi(()=>{he(()=>{const s=vt().structureType;if(!s)return;const e=mt()??0,t=bs[s];if(!t)return;const r=Je()==="empty"&&s==="spawn"?Math.max(t[e]??0,1):t[e]??0;if(r===2500)return;(ws()[s]??0)>=r&&($s({structureType:"",structureName:""}),He())})});function He(){pr(null)}function mr(){gr(null)}function Gl(){$s({structureType:"",structureName:""})}function Nl(s,e){const t=de(),r=vt(),i=Ze();if(!t||!r.structureType||!i){Il("missing requirements",{hasClient:!!t,structureType:r.structureType,pending:i});return}if(Je()==="empty"&&r.structureType==="spawn"){Kr("placing spawn",{room:s,x:i.tx,y:i.ty,name:r.structureName||void 0,shard:e??void 0}),t.http.game.placeSpawn(s,i.tx,i.ty,r.structureName||"Spawn 1",e??void 0).then(()=>(fe("Spawn placed successfully","success"),He(),t.stores.user.refreshWorldStatus())).catch(n=>{Jr("place spawn failed:",n),fe(`Failed to place spawn: ${n.message}`,"error")});return}Kr("creating construction site",{room:s,x:i.tx,y:i.ty,structureType:r.structureType,name:r.structureName||void 0,shard:e??void 0}),t.http.game.createConstruction(s,i.tx,i.ty,r.structureType,r.structureName||void 0,e??void 0).then(()=>{fe(`Construction site for ${r.structureType} created`,"success"),He()}).catch(n=>{Jr("create construction failed:",n),fe(`Failed to create construction site: ${n.message}`,"error")})}function Dl(){qe("view"),He(),mr(),Gl()}function ei(){const s=Qe(),e=Ze(),t=$r(),r=Je();if(r==="empty")return(()=>{var i=Ol(),n=i.firstChild,a=n.nextSibling;return a.$$click=()=>{qe("build"),$s({structureType:"spawn",structureName:""})},i})();if(r==="lost")return(()=>{var i=Ll(),n=i.firstChild,a=n.nextSibling;return a.$$click=()=>{const o=de();o&&o.http.user.respawn().then(()=>{fe("Respawn successful","success"),o.stores.user.refreshWorldStatus()}).catch(l=>{fe(`Respawn failed: ${l.message}`,"error")})},i})();if((t==null?void 0:t.type)==="moveFlag")return Pl();if(s==="flag")return(()=>{var i=Os();return w(i,e?"Confirm position":"Choose position"),i})();if(s==="build"){const i=vt(),n=mt(),a=ws(),o=i.structureType,l=" — Ctrl+click to remove construction sites";if(!o)return Al();const c=bs[o],d=(c==null?void 0:c[n??0])??0,h=a[o]??0,u=o.replace(/([A-Z])/g," $1").trim();return d===2500?(()=>{var f=Os();return w(f,`Click to build ${u} (${h}/∞)${l}`),f})():(()=>{var f=Os();return w(f,`Click to build ${u} (${h}/${d})${l}`),f})()}return null}_e(["click"]);var Hl=R("<div style=width:100%;height:100%;position:relative><div style=width:100%;height:100%>"),Bl=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">'),zl=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:Et,error:Ot}=et("room");function Fl(s){let e,t=null,r=null,i=null,n=null;const[a,o]=A(null),[l,c]=A(null),[d,h]=A(null),[u,f]=A("");return Wt(async()=>{if(!e)return;const p=await br.create(e);o(p)}),Se(()=>{t==null||t.destroy(),t=null,r==null||r.destroy(),r=null,i==null||i.destroy(),i=null;const p=a();p&&p.destroy()}),he(()=>{const p=de();if(!p)return;const b=s.room,_=s.shard;c(null),h(null),f(""),Ws(null),kl(),Yr(null),qr(null),Vr(null),jr({});const y=new yr;let k=!1;p.stores.room.terrain(b,_).then(T=>{k||c({room:b,data:T})}).catch(T=>{k||Ot(`terrain load failed for ${b}:`,T)}),y.add(p.stores.room.subscribe(b,_)),y.add(p.stores.room.on("room:error",T=>{fe(`Room subscription error (${T.room}): ${T.message}`,"error",8e3)})),y.add(p.stores.room.on("room:update",T=>{var S,O;let $=0;const v={};let M=0,x=null;for(const L in T.objects){$++;const I=T.objects[L];if(!I)continue;const G=I.type;if(typeof G=="string")if(G==="constructionSite"){const P=I.structureType;typeof P=="string"&&(v[P]=(v[P]||0)+1)}else v[G]=(v[G]||0)+1;if(G==="controller"&&typeof I.user=="string"){const P=I.user,C=((O=(S=T.users)==null?void 0:S[P])==null?void 0:O.username)??P;x={userId:P,username:C},typeof I.level=="number"&&(M=I.level)}}T.diff||Et(`objects loaded — ${b}: ${$} objects, tick=${T.gameTime}`),h({objects:T.objects,diff:T.diff,users:T.users}),f(T.visual),Ws(T.gameTime??null),Po(T.gameTime),Yr($),qr(x),Vr(M||null),jr(v)})),Se(()=>{k=!0,y.dispose()})}),he(()=>{const p=a();if(!p)return;s.room,s.shard,Dl(),p.hoverLayer.clearPendingTile(),n==null||n.destroy(),n=null,p.clear(),p.resetView(),t==null||t.destroy(),t=null,r==null||r.destroy(),r=null,i==null||i.destroy(),i=null;const b=hs(l);b&&b.room===s.room&&(Et(`terrain applied immediately (pre-loaded) — ${s.room}`),n=Br(b.data),p.world.addChildAt(n,0),p.bringNavOverlayToTop())}),he(()=>{const p=a();if(!p)return;const b=s.room,_=s.shard,y=De(b);if(y&&s.onNavigate){const k=s.onNavigate,T=Pr(),$=(M,x)=>!T||Ji(M,x,T),v=M=>{k(M,_)};El({currentRoom:()=>s.room,worldBounds:Pr,onMove:(M,x)=>v(Xe(M,x))}),p.setupNavigationZones({west:$(y.x-1,y.y)?()=>v(Xe(y.x-1,y.y)):void 0,east:$(y.x+1,y.y)?()=>v(Xe(y.x+1,y.y)):void 0,north:$(y.x,y.y-1)?()=>v(Xe(y.x,y.y-1)):void 0,south:$(y.x,y.y+1)?()=>v(Xe(y.x,y.y+1)):void 0})}}),he(()=>{const p=Qe(),b=a();p==="view"&&b&&(He(),b.hoverLayer.clearPendingTile())}),he(()=>{const p=a(),b=Ze();p&&(b?p.hoverLayer.setPendingTile(b.tx,b.ty):p.hoverLayer.clearPendingTile())}),he(()=>{const p=a(),b=l();if(!(!p||!b||b.room!==s.room)){if(n!=null&&n.parent){Et(`terrain already in scene, skipping — ${s.room}`);return}Et(`terrain applied (async) — ${s.room}`),n=Br(b.data),p.world.addChildAt(n,0),p.bringNavOverlayToTop()}}),he(()=>{var T,$;const p=a(),b=d();if(!p||!b)return;const{objects:_,diff:y,users:k}=b;if(t||(Et(`object layer created — ${s.room}`),t=new ul(p.app.ticker,hr(),(T=zs())==null?void 0:T._id,($=zs())==null?void 0:$.badge,k),t.container.label="objects",p.world.addChild(t.container),p.bringNavOverlayToTop(),r=new fl(p.app.ticker),r.container.label="animations",p.world.addChild(r.container),i=new yl,p.world.addChild(i.container),p.bringNavOverlayToTop(),p.setTileHandlers((v,M)=>{},(v,M,x)=>{const S=s.room,O=s.shard,L=Qe(),I=$r();if((I==null?void 0:I.type)==="moveFlag"){const N=de();if(!N)return;const{name:B,room:z,color:j,secondaryColor:se}=I;N.http.game.removeFlag(z,B).then(()=>N.http.game.createFlag(S,v,M,B,j,se,O??void 0)).then(()=>{fe(`Flag "${B}" moved`,"success"),mr()}).catch(J=>{Ot("move flag failed:",J),fe(`Failed to move flag "${B}"`,"error"),mr()});return}if(L==="flag"){const N=Ze();if(!N||N.tx!==v||N.ty!==M){pr({tx:v,ty:M}),p.hoverLayer.setPendingTile(v,M);return}const B=de();if(!B)return;const z=ht(),j=z.name.trim();if(!j){fe("Flag name is required","error");return}const se=Qr[z.color]??0,J=Qr[z.secondaryColor]??0;B.http.game.createFlag(S,v,M,j,se,J,O??void 0).then(()=>{fe(`Flag "${j}" created`,"success"),He(),p.hoverLayer.clearPendingTile(),B.http.game.genUniqueFlagName().then(D=>en(F=>({...F,name:D.name}))).catch(D=>Ot("gen unique flag name failed:",D))}).catch(D=>Ot("create flag failed:",D));return}if(L==="build"){if(!x&&!vt().structureType){fe("Select a structure type first","error");return}if(x){if(!t)return;const B=t.getObjectsAtTile(v,M).filter(({obj:j})=>j.type==="constructionSite");if(B.length===0){fe("No construction sites on this tile","error");return}const z=de();if(!z)return;z.http.game.removeConstructionSite(S,B.map(({id:j})=>j),O??void 0).then(()=>{fe(`Removed ${B.length} construction site${B.length>1?"s":""}`,"success"),He(),p.hoverLayer.clearPendingTile()}).catch(j=>{Ot("remove construction sites failed:",j),fe(`Failed to remove construction sites: ${j.message}`,"error")});return}pr({tx:v,ty:M}),p.hoverLayer.setPendingTile(v,M),Nl(S,O);return}if(He(),p.hoverLayer.clearPendingTile(),!t)return;const G=t.getObjectsAtTile(v,M);if(G.length===0){x||(Ut([]),p.hoverLayer.clearSelection());return}let P=[...ys()];if(x){const N=new Set(G.map(z=>z.id));if(P.some(z=>N.has(z.id)))P=P.filter(z=>!N.has(z.id));else{const z=G.filter(({id:j})=>!P.some(se=>se.id===j)).map(({id:j,obj:se})=>Xr(j,se));P=[...P,...z]}}else P=G.map(({id:N,obj:B})=>Xr(N,B));Ut(P);const C=P.map(({id:N,type:B})=>({id:N,type:B,visual:t.getVisualById(N)})).filter(N=>N.visual!=null);p.hoverLayer.setSelectedObjects(C)})),y&&Tl(y,_),t.update(_,y,k),r){r.clear();const v=(Xs()??2e3)*.6;for(const M in _){const x=_[M];if(!x||x.type!=="creep")continue;const S=x.actionLog;if(S){if(S.harvest){const O=S.harvest;r.addHarvest(O.x,O.y,x.x,x.y,v)}if(S.upgradeController){const O=S.upgradeController;r.addUpgradeController(x.x,x.y,O.x,O.y,v)}if(S.build){const O=S.build;r.addBuild(x.x,x.y,O.x,O.y,v),t==null||t.triggerBuildAt(O.x,O.y,v)}}}}}),he(()=>{const p=u();i==null||i.update(p)}),he(()=>{t==null||t.setShowLabels(hr())}),(()=>{var p=Hl(),b=p.firstChild;return Nt(_=>e=_,b),w(p,(()=>{var _=ne(()=>!!ei());return()=>_()&&(()=>{var y=Bl();return w(y,ei),H(k=>U(y,"pointer-events",Je()==="empty"||Je()==="lost"?"auto":"none")),y})()})(),null),w(p,(()=>{var _=ne(()=>ps()!==null);return()=>_()&&(()=>{var y=zl();return y.firstChild,w(y,ps,null),y})()})(),null),p})()}var Ul=R("<div style=position:fixed;bottom:16px;right:16px;display:flex;flex-direction:column;gap:8px;z-index:9999;pointer-events:none>"),Wl=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 Xl(){return(()=>{var s=Ul();return w(s,E(pe,{get each(){return ko()},children:e=>(()=>{var t=Wl();return w(t,()=>e.message),H(r=>U(t,"background",e.type==="error"?"#da3633":"#238636")),t})()})),s})()}const[Lt,Yl]=A(!0),[at,ql]=A(!0);function tn(){Yl(s=>!s)}function sn(){ql(s=>!s)}var Vl=R("<div style=overflow:auto;padding:8px>"),jl=R("<div style=width:4px;flex-shrink:0;cursor:col-resize>"),Zl=R('<div style=flex:1;display:flex;flex-direction:column;overflow:hidden><div style=flex:1;overflow:auto;padding:8px></div><form style="display:flex;gap:6px;padding:8px;border-top:1px solid #30363d"><span style=color:#8b949e;font-size:13px;line-height:28px>&gt;</span><input type=text placeholder="Game.creeps.Harvester1.moveTo(10, 10)"style="flex:1;padding:6px 8px;border-radius:4px;border:1px solid #30363d;background:#161b22;color:#c9d1d9;font-size:12px;font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace"><button type=submit style="padding:6px 12px;border-radius:4px;border:none;background:#238636;color:#fff;font-size:12px;cursor:pointer">Run'),Kl=R("<div style=flex:1;display:flex;overflow:hidden>"),Jl=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><div style=margin-left:auto><button style=background:transparent;border:none;color:#8b949e;font-size:11px;cursor:pointer>Clear'),Ql=R("<div style=color:#484f58;font-style:italic>No log output yet…"),ec=R("<div style=margin-bottom:4px;color:#f85149;white-space:pre-wrap;word-break:break-word>"),tc=R("<div style=margin-bottom:4px;color:#c9d1d9;white-space:pre-wrap;word-break:break-word>"),sc=R("<div style=color:#484f58;font-style:italic>No command results yet…"),rc=R("<div style=margin-bottom:4px;color:#58a6ff;white-space:pre-wrap;word-break:break-word>");const{error:ic}=et("console");function nc(s){const[e,t]=A([]),[r,i]=A(""),[n,a]=A(!0),[o,l]=A(It(ce.consoleSplit,50)),[c,d]=A(!1);let h,u,f,p=0;Wt(()=>{const x=de();if(!x)return;const S=new yr;S.add(x.stores.user.subscribe("console")),S.add(x.stores.user.on("user:console",O=>{const L=O.messages,I={id:p++,log:L.log??[],results:L.results??[],error:L.error??[]};t(G=>{const P=[...G,I];return P.length>200?P.slice(P.length-200):P})})),Se(()=>S.dispose())}),he(()=>{e(),n()&&requestAnimationFrame(()=>{Lt()&&h&&(h.scrollTop=h.scrollHeight),at()&&u&&(u.scrollTop=u.scrollHeight)})});const b=(x,S)=>{var L,I;const O=!x&&!S;O&&!s.isCollapsed&&((L=s.onToggle)==null||L.call(s)),!O&&s.isCollapsed&&((I=s.onToggle)==null||I.call(s))};he(()=>{b(Lt(),at())});const _=x=>{x.preventDefault(),d(!0);const O=f.getBoundingClientRect(),L=G=>{const P=(G.clientX-O.left)/O.width*100,C=Math.max(15,Math.min(85,P));l(C),ns(ce.consoleSplit,C)},I=()=>{d(!1),window.removeEventListener("pointermove",L),window.removeEventListener("pointerup",I)};window.addEventListener("pointermove",L),window.addEventListener("pointerup",I)},y=async x=>{x.preventDefault();const S=de();if(!(!S||!r().trim()))try{await S.http.user.console(r().trim(),s.shard??"shard0"),i("")}catch(O){ic("command failed:",O)}},k=x=>({background:x?"#30363d":"transparent",border:`1px solid ${x?"#58a6ff":"transparent"}`,color:x?"#c9d1d9":"#8b949e","font-size":"12px",cursor:"pointer",padding:"2px 10px","border-radius":"4px"}),T=()=>e().flatMap(x=>x.log),$=()=>e().flatMap(x=>x.error),v=()=>e().flatMap(x=>x.results),M={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"};return(()=>{var x=Jl(),S=x.firstChild,O=S.firstChild,L=O.nextSibling,I=L.nextSibling,G=I.firstChild;return fs(O,"click",tn,!0),fs(L,"click",sn,!0),G.$$click=()=>t([]),w(x,E(q,{get when(){return!s.isCollapsed},get children(){var P=Kl();return Nt(C=>f=C,P),w(P,E(q,{get when(){return Lt()},get children(){var C=Vl();C.addEventListener("scroll",()=>{h&&a(h.scrollHeight-h.scrollTop-h.clientHeight<20)});var N=h;return typeof N=="function"?Nt(N,C):h=C,w(C,(()=>{var B=ne(()=>T().length===0&&$().length===0);return()=>B()&&Ql()})(),null),w(C,E(pe,{get each(){return $()},children:B=>(()=>{var z=ec();return z.innerHTML=B,z})()}),null),w(C,E(pe,{get each(){return T()},children:B=>(()=>{var z=tc();return z.innerHTML=B,z})()}),null),H(B=>ue(C,{...at()?{width:`${o()}%`,"flex-shrink":0}:{flex:1},...M},B)),C}}),null),w(P,E(q,{get when(){return ne(()=>!!Lt())()&&at()},get children(){var C=jl();return C.$$pointerdown=_,H(N=>U(C,"background",c()?"#388bfd":"#21262d")),C}}),null),w(P,E(q,{get when(){return at()},get children(){var C=Zl(),N=C.firstChild,B=N.nextSibling,z=B.firstChild,j=z.nextSibling;j.nextSibling,N.addEventListener("scroll",()=>{u&&a(u.scrollHeight-u.scrollTop-u.clientHeight<20)});var se=u;return typeof se=="function"?Nt(se,N):u=N,w(N,(()=>{var J=ne(()=>v().length===0);return()=>J()&&sc()})(),null),w(N,E(pe,{get each(){return v()},children:J=>(()=>{var D=rc();return D.innerHTML=J,D})()}),null),B.addEventListener("submit",y),j.$$input=J=>i(J.currentTarget.value),H(J=>ue(N,{...M},J)),H(()=>j.value=r()),C}}),null),H(C=>U(P,"user-select",c()?"none":"auto")),P}}),null),H(P=>{var C=k(Lt()),N=k(at());return P.e=ue(O,C,P.e),P.t=ue(L,N,P.t),P},{e:void 0,t:void 0}),x})()}_e(["click","pointerdown","input"]);var oc=R('<div style="display:grid;grid-template-columns:1fr 1fr;gap:1px;background:#21262d;font-size:10px">'),ac=R('<div style="padding:3px 8px;background:#0d1117;color:#8b949e;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">'),lc=R('<div style="padding:3px 8px;background:#0d1117;color:#c9d1d9;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-variant-numeric:tabular-nums">'),cc=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">Store Contents</div><div style="display:grid;grid-template-columns:1fr 1fr;gap:1px;background:#21262d">'),dc=R('<div style="padding:3px 8px;background:#0d1117;color:#8b949e">'),hc=R('<div style="padding:3px 8px;background:#0d1117;color:#c9d1d9;font-variant-numeric:tabular-nums">'),uc=R('<div style=padding:8px;display:flex;flex-direction:column;gap:8px;background:#0d1117><label>Primary color<select></select></label><label>Secondary color<select></select></label><button style="color:#fff;border:none;border-radius:4px;padding:6px 8px;font-size:12px;transition:opacity 150ms ease, background 150ms ease">Apply color</button><button style="color:#fff;border:none;border-radius:4px;padding:6px 8px;font-size:12px;cursor:pointer;transition:background 150ms ease"></button><button style="color:#fff;border:none;border-radius:4px;padding:6px 8px;font-size:12px;cursor:pointer;margin-top:4px;transition:background 150ms ease">'),ti=R("<option>"),fc=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:#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">×'),pc=R("<span style=font-weight:400;color:#8b949e;margin-left:5px>"),gc=R("<div style=flex:1;overflow:auto;min-height:0;padding:8px>"),mc=R("<div style=color:#484f58;font-style:italic;font-size:12px>Click a tile to select objects…");const{log:si,error:yc}=et("SelectionList"),wc={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"},bc={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"},vc=new Set(["x","y","type","id","name","user","_id","room","hitsMax","energyCapacity"]),ri=new Set(["hits","energy","energyCapacity","store","progress","progressTotal","nextDecayTime"]);function xc(s){return typeof s=="number"?String(s):typeof s=="string"?s:typeof s=="boolean"?s?"yes":"no":null}function rn(s){const e=()=>{const t=s.item.raw,r=[];for(const i in t){if(vc.has(i))continue;const n=t[i],a=i;let o=xc(n);if(i==="hits"&&typeof t.hitsMax=="number"&&(o=`${n} / ${t.hitsMax}`),i==="energy"&&typeof t.energyCapacity=="number"&&(o=`${n} / ${t.energyCapacity}`),i==="nextDecayTime"&&typeof n=="number"){const l=ps();l!==null&&(o=String(n-l))}o!==null&&r.push({key:a,value:o})}return r.sort((i,n)=>{const a=ri.has(i.key)?0:1,o=ri.has(n.key)?0:1;return a-o}),r};return E(q,{get when(){return e().length>0},get children(){var t=oc();return w(t,E(pe,{get each(){return e()},children:r=>[(()=>{var i=ac();return w(i,()=>r.key),i})(),(()=>{var i=lc();return w(i,()=>r.value),i})()]})),t}})}function _c(s){const e=()=>{const t=s.store||{},r=[];for(const i in t)r.push([i,t[i]]);return r};return E(q,{get when(){return e().length>0},get children(){var t=cc(),r=t.firstChild,i=r.nextSibling;return w(i,E(pe,{get each(){return e()},children:([n,a])=>[(()=>{var o=dc();return w(o,n),o})(),(()=>{var o=hc();return w(o,a),o})()]})),t}})}function $c(s){const e=()=>s.item.raw.store;return[E(rn,{get item(){return s.item}}),E(_c,{get store(){return e()}})]}const ii=[{label:"Red",value:1},{label:"Purple",value:2},{label:"Blue",value:3},{label:"Cyan",value:4},{label:"Green",value:5},{label:"Yellow",value:6},{label:"Orange",value:7},{label:"Brown",value:8},{label:"Grey",value:9},{label:"White",value:10}];function Sc(s){const e=()=>s.item.raw,t=()=>typeof e().name=="string"?e().name:"",r=()=>typeof e().room=="string"?e().room:"",i=()=>typeof e().color=="number"?e().color:1,n=()=>typeof e().secondaryColor=="number"?e().secondaryColor:1,[a,o]=A(i()),[l,c]=A(n());he(()=>{o(i()),c(n())});const d=()=>a()!==i()||l()!==n(),h=()=>{const $=de();if(!$)return;const v=a(),M=l();si(`changeFlagColor: name="${t()}" room=${r()} primary=${v} secondary=${M}`),$.http.game.changeFlagColor(r(),t(),v,M).then(()=>si("changeFlagColor OK")).catch(x=>yc("changeFlagColor FAILED:",x))},u=()=>{const $=$r();return($==null?void 0:$.type)==="moveFlag"&&$.id===s.item.id},f=()=>{if(u()){gr(null);return}gr({type:"moveFlag",id:s.item.id,name:t(),room:r(),color:a(),secondaryColor:l()})},[p,b]=A(!1);let _=null;const y=()=>{if(!p()){b(!0),_=setTimeout(()=>{b(!1)},3e3);return}_&&(clearTimeout(_),_=null),b(!1);const $=de();if(!$)return;const v=s.item.id;$.http.game.removeFlag(r(),t()).then(()=>{Ki(v)}).catch(()=>{})},k={background:"#010409",color:"#c9d1d9",border:"1px solid #30363d","border-radius":"4px",padding:"5px 6px","font-size":"12px",width:"100%"},T={display:"flex","flex-direction":"column",gap:"4px","font-size":"11px",color:"#8b949e"};return(()=>{var $=uc(),v=$.firstChild,M=v.firstChild,x=M.nextSibling,S=v.nextSibling,O=S.firstChild,L=O.nextSibling,I=S.nextSibling,G=I.nextSibling,P=G.nextSibling;return x.addEventListener("change",C=>o(Number(C.currentTarget.value))),w(x,E(pe,{each:ii,children:C=>(()=>{var N=ti();return w(N,()=>C.label),H(()=>N.value=C.value),N})()})),L.addEventListener("change",C=>c(Number(C.currentTarget.value))),w(L,E(pe,{each:ii,children:C=>(()=>{var N=ti();return w(N,()=>C.label),H(()=>N.value=C.value),N})()})),I.addEventListener("mouseleave",C=>{d()&&(C.currentTarget.style.background="#238636")}),I.addEventListener("mouseenter",C=>{d()&&(C.currentTarget.style.background="#2ea043")}),I.$$click=h,G.addEventListener("mouseleave",C=>{u()||(C.currentTarget.style.background="#d29922")}),G.addEventListener("mouseenter",C=>{u()||(C.currentTarget.style.background="#e3b341")}),G.$$click=f,w(G,()=>u()?"Abort":"Move flag"),P.addEventListener("mouseleave",C=>{p()||(C.currentTarget.style.background="#f85149")}),P.addEventListener("mouseenter",C=>{p()||(C.currentTarget.style.background="#da3633")}),P.$$click=y,w(P,()=>p()?"Confirm deletion":"Delete flag"),H(C=>{var N=T,B=k,z=T,j=k,se=!d(),J=d()?"#238636":"#1f6feb",D=d()?"pointer":"not-allowed",F=d()?1:.6,Z=u()?"#8b949e":"#d29922",V=p()?"#da3633":"#f85149";return C.e=ue(v,N,C.e),C.t=ue(x,B,C.t),C.a=ue(S,z,C.a),C.o=ue(L,j,C.o),se!==C.i&&(I.disabled=C.i=se),J!==C.n&&U(I,"background",C.n=J),D!==C.s&&U(I,"cursor",C.s=D),F!==C.h&&U(I,"opacity",C.h=F),Z!==C.r&&U(G,"background",C.r=Z),V!==C.d&&U(P,"background",C.d=V),C},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0}),H(()=>x.value=a()),H(()=>L.value=l()),$})()}const Cc={creep:$c,flag:Sc};function kc(s){const e=()=>wc[s.item.type]??"#c9d1d9",t=()=>bc[s.item.type]??s.item.type,r=()=>Cc[s.item.type]||rn;return(()=>{var i=fc(),n=i.firstChild,a=n.firstChild,o=a.nextSibling,l=o.nextSibling,c=l.firstChild,d=c.nextSibling,h=d.nextSibling,u=h.nextSibling;u.nextSibling;var f=l.nextSibling;return w(o,t,null),w(o,E(q,{get when(){return ne(()=>typeof s.item.raw.name=="string")()&&s.item.raw.name},children:p=>(()=>{var b=pc();return w(b,()=>p()),b})()}),null),w(l,()=>s.item.raw.x,d),w(l,()=>s.item.raw.y,u),f.addEventListener("mouseleave",p=>p.currentTarget.style.color="#8b949e"),f.addEventListener("mouseenter",p=>p.currentTarget.style.color="#fff"),f.$$click=()=>Ki(s.item.id),w(i,E(zn,{get component(){return r()},get item(){return s.item}}),null),H(p=>U(a,"background",e())),i})()}function Tc(){return(()=>{var s=gc();return w(s,E(q,{get when(){return ys().length>0},get fallback(){return mc()},get children(){return E(pe,{get each(){return ys()},children:e=>E(kc,{item:e})})}})),s})()}_e(["click"]);var Mc=R('<div style="display:grid;grid-template-columns:repeat(3, 1fr);gap:4px;margin-top:8px">'),Rc=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">'),Ec=R('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;font-size:11px;font-weight:600">');const Oc=[{mode:"view",label:"View"},{mode:"flag",label:"Flag"},{mode:"build",label:"Build"}];function Lc(s){return(()=>{var e=Rc(),t=e.firstChild,r=t.firstChild,i=r.nextSibling,n=i.nextSibling,a=n.firstChild,o=a.nextSibling,l=o.nextSibling,c=l.nextSibling,d=c.nextSibling,h=d.nextSibling,u=h.nextSibling,f=u.nextSibling,p=f.nextSibling,b=p.nextSibling;return w(i,()=>s.room),w(o,()=>s.shard??"—"),w(c,()=>ps()??"—"),w(h,(()=>{var _=ne(()=>!!Xs());return()=>_()?`${Xs()}ms`:"—"})()),w(f,()=>Ml()??"—"),w(b,()=>{var _;return((_=Rl())==null?void 0:_.username)??"—"}),w(e,E(q,{get when(){return!ft()},get children(){var _=Mc();return w(_,E(pe,{each:Oc,children:y=>{const k=()=>Qe()===y.mode;return(()=>{var T=Ec();return T.$$click=()=>qe(y.mode),w(T,()=>y.label),H($=>{var v=`1px solid ${k()?"#58a6ff":"#30363d"}`,M=k()?"#1f6feb33":"#161b22",x=k()?"#c9d1d9":"#8b949e";return v!==$.e&&U(T,"border",$.e=v),M!==$.t&&U(T,"background",$.t=M),x!==$.a&&U(T,"color",$.a=x),$},{e:void 0,t:void 0,a:void 0}),T})()}})),_}}),null),e})()}_e(["click"]);const[Pc,Ac]=A("owner"),nn="screeps-terrain-v1";async function Ic(s,e,t){try{const r=await caches.open(nn),i=`/terrain/${s}_${e}_z${t}.webp`,n=new Request(i),a=await r.match(n);if(a)return await a.blob()}catch{}return null}async function Gc(s,e,t,r){try{const i=await caches.open(nn),n=`/terrain/${s}_${e}_z${t}.webp`,a=new Request(n),o=new Response(r);await i.put(a,o)}catch{}}async function Nc(s){const e=new OffscreenCanvas(s.width,s.height),t=e.getContext("2d");if(!t)throw new Error("OffscreenCanvas 2D context not available");return t.drawImage(s,0,0),await e.convertToBlob({type:"image/webp"})}async function Dc(s){return await createImageBitmap(s)}function Hc(s){return new Worker("/client/assets/terrain.worker-D9zNeJfz.js",{name:s==null?void 0:s.name})}const{warn:Bc}=et("MapRenderer"),on=3,Y=on*50,zc=[50,60,70,80,90,100,110],Pt=1,We=.5,rs=50,Fc=2600,Uc=5,ni=.2,oi=5,Wc=Yt,Xc=16777215,Yc=je,qc=Ht,Vc=4491519,jc=new Set(["w","r","pb","p","s","c","m","k"]),Zc={H:13421772,O:13421772,U:5809919,L:4176208,K:10711543,Z:13801762,X:16273737},Kc=[16,24,32,40];class oh{constructor(e){m(this,"app");m(this,"world");m(this,"boundsGraphics",null);m(this,"selectionGraphics",null);m(this,"safeModeGraphics",null);m(this,"safeModeRooms",new Set);m(this,"activeRooms",new Map);m(this,"roomPool",[]);m(this,"terrainBaked",new Set);m(this,"terrainData",new Map);m(this,"worker");m(this,"pendingBakes",new Map);m(this,"nextBakeId",0);m(this,"currentShard","shard0");m(this,"callbacks");m(this,"resizeObserver",null);m(this,"_destroyed",!1);m(this,"showRoomNames",!1);m(this,"worldBoundsSet",null);m(this,"lastVisibleBounds",null);m(this,"animTargetX",0);m(this,"animTargetY",0);m(this,"isAnimating",!1);m(this,"overlayMode","owner");m(this,"showUnclaimableOverlay",!0);m(this,"isDragging",!1);m(this,"hasDragged",!1);m(this,"dragStartX",0);m(this,"dragStartY",0);m(this,"dragWorldX",0);m(this,"dragWorldY",0);m(this,"lastVisibleKey","");m(this,"visibleDebounceTimer",null);m(this,"selectedRoom",null);m(this,"currentUserId",null);m(this,"badgeCache",new Ri);m(this,"lastCheckX",0);m(this,"lastCheckY",0);m(this,"lastCheckScale",0);this.app=new fi,this.callbacks=e,this.worker=new Hc,this.worker.onmessage=t=>{const{id:r,bitmap:i}=t.data,n=this.pendingBakes.get(r);n&&(this.pendingBakes.delete(r),n.resolve(i))}}async init(e){const t=e.parentElement??e,{width:r,height:i}=t.getBoundingClientRect();await this.app.init({canvas:e,width:r,height:i,background:ba,antialias:!1,preference:"webgl"}),this.resizeObserver=new ResizeObserver(n=>{const{width:a,height:o}=n[0].contentRect,l=this.app.screen.width,c=this.app.screen.height;this.app.renderer.resize(a,o),this.world.x+=(a-l)/2,this.world.y+=(o-c)/2}),this.resizeObserver.observe(t),this.world=new xe,this.app.stage.addChild(this.world),this.boundsGraphics=new X,this.world.addChild(this.boundsGraphics),this.selectionGraphics=new X,this.world.addChild(this.selectionGraphics),this.safeModeGraphics=new X,this.world.addChild(this.safeModeGraphics),this.setupInteraction(),this.app.ticker.add(()=>{if(this.isAnimating){const n=this.animTargetX-this.world.x,a=this.animTargetY-this.world.y;Math.abs(n)<.5&&Math.abs(a)<.5?(this.world.x=this.animTargetX,this.world.y=this.animTargetY,this.isAnimating=!1):(this.world.x+=n*.2,this.world.y+=a*.2)}this.checkVisibleRooms()})}get zoom(){var e;return((e=this.world)==null?void 0:e.scale.x)??1}setZoom(e){var d,h;if(!this.world)return;e=Math.max(ni,Math.min(oi,e));const t=this.world.scale.x;if(e===t)return;const r=this.app.screen.width/2,i=this.app.screen.height/2,n=(r-this.world.x)/t,a=(i-this.world.y)/t,o=this.getLOD(),l=this.zoom>=Pt,c=this.zoom>=We;this.world.scale.set(e),this.world.x=r-n*e,this.world.y=i-a*e,this.getLOD()!==o&&this.applyLOD(),(e>=Pt!==l||e>=We!==c)&&this.updateAllNameLabels(),this.updateAllRoomScales(e),(h=(d=this.callbacks).onZoomChanged)==null||h.call(d,e),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode()}centerOn(e,t,r=!1){const i=e*Y+Y/2,n=t*Y+Y/2,a=this.world.scale.x,o=this.app.screen.width/2-i*a,l=this.app.screen.height/2-n*a;r?(this.animTargetX=o,this.animTargetY=l,this.isAnimating=!0):(this.isAnimating=!1,this.world.x=o,this.world.y=l)}async getTerrainBitmap(e,t,r){const i=this.currentShard;try{const n=await Ic(i,e,t);if(n)return await Dc(n);const a=this.nextBakeId++,o=new Promise((c,d)=>{this.pendingBakes.set(a,{roomName:e,lod:t,resolve:c,reject:d})});this.worker.postMessage({id:a,roomName:e,lod:t,raw:r});const l=await o;return Nc(l).then(c=>{Gc(i,e,t,c)}).catch(c=>Bc("failed to save to terrainCache:",c)),l}catch{return null}}async setRoomTerrain(e,t){const r=t.raw;let i=!1;for(let c=0;c<r.length;c++)if(r[c]!==0){i=!0;break}if(!i){this.terrainBaked.add(e);return}const n=this.getOrCreate(e),a=this.getLOD();a===0&&this.terrainData.set(e,r);const o=await this.getTerrainBitmap(e,a,r);if(!o)return;if(!this.activeRooms.has(e)){o.close();return}const l=At.from(o);a===0?(n.texLo&&!n.texLo.destroyed&&n.texLo.destroy(!0),n.texLo=l,this.getLOD()===0&&n.texLo&&(n.terrainSprite.texture=n.texLo)):(n.texHi&&!n.texHi.destroyed&&n.texHi.destroy(!0),n.texHi=l,this.getLOD()===1&&n.texHi&&(n.terrainSprite.texture=n.texHi)),n.terrainSprite.width=Y,n.terrainSprite.height=Y,this.terrainBaked.add(e)}getLOD(){return this.zoom<Pt?0:1}async applyLOD(){const e=this.getLOD()===1,t=[];for(const[r,i]of this.activeRooms)if(this.terrainBaked.has(r))if(e&&!i.texHi){const n=this.terrainData.get(r);n&&(this.terrainData.delete(r),t.push(this.getTerrainBitmap(r,1,n).then(a=>{a&&this.activeRooms.has(r)?(i.texHi=At.from(a),this.getLOD()===1&&(i.terrainSprite.texture=i.texHi)):a&&a.close()})))}else{const n=e?i.texHi:i.texLo;n&&!n.destroyed&&(i.terrainSprite.texture=n)}await Promise.all(t)}setRoomMap2(e,t,r="live"){const n=this.getOrCreate(e).map2Graphics;n.alpha=r==="cache"?.6:1;const a=on;n.clear();const o=t.r??[];for(const[b,_]of o)n.rect(b*a,_*a,a,a);o.length&&n.fill(vr);const l=t.w??[];for(const[b,_]of l)n.rect(b*a+.5,_*a+.5,a-1,a-1);l.length&&n.fill(4486980);const c=t.s??[];for(const[b,_]of c)n.circle((b+.5)*a,(_+.5)*a,2.5);c.length&&n.fill(Wc);const d=t.c??[];for(const[b,_]of d)n.circle((b+.5)*a,(_+.5)*a,2);d.length&&n.fill(Xc);const h=t.m??[];for(const[b,_]of h)n.circle((b+.5)*a,(_+.5)*a,2);h.length&&n.fill(Yc);const u=t.k??[];for(const[b,_]of u)n.circle((b+.5)*a,(_+.5)*a,2);u.length&&n.fill(qc);const f=t.pb??[];for(const[b,_]of f)n.circle((b+.5)*a,(_+.5)*a,1.5);f.length&&n.fill(Ht);const p=t;for(const b in p){if(jc.has(b))continue;const _=p[b];if(!Array.isArray(_)||_.length===0)continue;for(const[k,T]of _)n.circle((k+.5)*a,(T+.5)*a,1);const y=b===this.currentUserId?Vc:16711680;n.fill(y)}}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 r=this.activeRooms.get(e);if(!r)return;const i=r.ownerOverlay;i.clear(),t&&(i.rect(0,0,Y,Y),i.fill({color:10027008,alpha:.18})),i.visible=this.showUnclaimableOverlay}setUnclaimableOverlayVisible(e){if(this.showUnclaimableOverlay!==e){this.showUnclaimableOverlay=e;for(const t of this.activeRooms.values())t.ownerOverlay.visible=e}}async setRoomBadge(e,t,r){const i=this.activeRooms.get(e);if(i){if(!t){i.badgeSprite&&(i.container.removeChild(i.badgeSprite),i.badgeSprite.destroy(),i.badgeSprite=void 0),i.badgeLevel=void 0;return}try{const n=await this.badgeCache.getOrCreate(t);if(!this.activeRooms.has(e))return;if(i.badgeSprite){if(i.badgeSprite.texture===n){i.badgeLevel=r,this.applyBadgeSize(i,this.zoom),this.applyOverlayMode(i);return}i.badgeSprite.texture=n}else{const a=new us(n);a.anchor.set(.5),a.x=Y/2,a.y=Y/2;const o=i.container.getChildIndex(i.nameLabel);i.container.addChildAt(a,o),i.badgeSprite=a}i.badgeLevel=r,this.applyBadgeSize(i,this.zoom),this.applyOverlayMode(i)}catch{}}}applyBadgeSize(e,t){if(!e.badgeSprite||e.badgeLevel===void 0)return;const i=(zc[e.badgeLevel-1]??24)*Math.min(1,t);e.badgeSprite.width=i/t,e.badgeSprite.height=i/t}setOverlayMode(e){if(this.overlayMode!==e){this.overlayMode=e;for(const t of this.activeRooms.values())this.applyOverlayMode(t)}}setRoomMineral(e,t,r){const i=this.activeRooms.get(e);if(!i)return;if(!t||!r){i.mineralCircle&&(i.container.removeChild(i.mineralCircle),i.mineralCircle.destroy(),i.mineralCircle=void 0),i.mineralLabel&&(i.container.removeChild(i.mineralLabel),i.mineralLabel.destroy(),i.mineralLabel=void 0),i.mineralDensity=void 0;return}const n=Zc[t]??je;if(i.mineralDensity=r,i.mineralColor=n,!i.mineralCircle){const a=new X;a.x=Y/2,a.y=Y/2;const o=i.container.getChildIndex(i.nameLabel);i.container.addChildAt(a,o),i.mineralCircle=a}if(i.mineralLabel)i.mineralLabel.text=t;else{const a=new yt({text:t,style:{fontSize:36,fill:16777215,fontFamily:"ui-monospace, monospace",fontWeight:"bold"}});a.anchor.set(.5),a.x=Y/2,a.y=Y/2,i.container.addChild(a),i.mineralLabel=a}this.applyMineralSize(i,this.zoom),this.applyOverlayMode(i)}applyOverlayMode(e){e.badgeSprite&&(e.badgeSprite.visible=this.overlayMode==="owner"),e.mineralCircle&&(e.mineralCircle.visible=this.overlayMode==="mineral"),e.mineralLabel&&(e.mineralLabel.visible=this.overlayMode==="mineral")}applyMineralSize(e,t){if(!e.mineralCircle||!e.mineralLabel||e.mineralDensity===void 0||e.mineralColor===void 0)return;const r=Math.max(.5,Math.min(1.5,t)),i=(Kc[e.mineralDensity-1]??24)*r,n=i/2/t;e.mineralCircle.clear(),e.mineralCircle.circle(0,0,1),e.mineralCircle.fill(e.mineralColor);const o=2/t;e.mineralCircle.stroke({color:0,width:o/n}),e.mineralCircle.scale.set(n);const c=i*.55/36/t;e.mineralLabel.scale.set(c)}updateNameLabelScale(e,t){const i=.3/Math.sqrt(t),n=12/(36*t);e.nameLabel.scale.set(Math.max(i,n))}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=De(e);if(!t)return;const r=t.x*Y,i=t.y*Y;this.selectionGraphics.rect(r,i,Y,Y);const n=Math.max(2,Math.ceil(2/this.zoom));this.selectionGraphics.stroke({color:16777215,width:n,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 r=De(t);if(!r)continue;const i=r.x*Y,n=r.y*Y;this.safeModeGraphics.rect(i,n,Y,Y),this.safeModeGraphics.stroke({color:16776960,width:e,alignment:1,alpha:.5})}this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)}setBounds(e,t,r,i){if(!this.boundsGraphics)return;this.worldBoundsSet={minX:e,maxX:t,minY:r,maxY:i},this.boundsGraphics.clear();const n=e*Y,a=r*Y,o=(t-e+1)*Y,l=(i-r+1)*Y;this.boundsGraphics.rect(n,a,o,l),this.boundsGraphics.stroke({color:Ti,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)}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=At.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<Fc?this.roomPool.push(t):(this.world.removeChild(t.container),t.container.destroy({children:!0,context:!0})))}clearInvisibleRooms(e){const t=this.lastVisibleBounds;for(const r of[...this.activeRooms.keys()])if(!e.has(r)){if(t){const i=De(r);if(i&&i.x>=t.rxMin-rs&&i.x<=t.rxMax+rs&&i.y>=t.ryMin-rs&&i.y<=t.ryMax+rs)continue}this.clearRoom(r)}}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 r=De(e);if(!r)throw new Error(`MapRenderer: invalid room "${e}"`);let i;if(this.roomPool.length>0)i=this.roomPool.pop();else{const n=new xe;n.cullable=!0;const a=new us(At.EMPTY),o=new X,l=new X;n.addChild(a),n.addChild(o),n.addChild(l);const c=new yt({text:"",style:{fontSize:36,fill:9147550,fontFamily:"ui-monospace, monospace"}});c.scale.set(.25),c.x=2,c.y=2,n.addChild(c),this.world.addChild(n),i={container:n,terrainSprite:a,texLo:null,texHi:null,map2Graphics:o,ownerOverlay:l,nameLabel:c}}return i.container.x=r.x*Y,i.container.y=r.y*Y,i.container.visible=!0,i.nameLabel.text=e,i.nameLabel.visible=this.showRoomNames&&this.zoom>=We&&this.nameLabelShouldShow(r.x,r.y),this.updateNameLabelScale(i,this.zoom),i.badgeSprite&&(i.container.removeChild(i.badgeSprite),i.badgeSprite.destroy(),i.badgeSprite=void 0),i.mineralCircle&&(i.container.removeChild(i.mineralCircle),i.mineralCircle.destroy(),i.mineralCircle=void 0),i.mineralLabel&&(i.container.removeChild(i.mineralLabel),i.mineralLabel.destroy(),i.mineralLabel=void 0),i.mineralDensity=void 0,i.mineralColor=void 0,this.safeModeGraphics&&(this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)),this.selectionGraphics&&(this.world.removeChild(this.selectionGraphics),this.world.addChild(this.selectionGraphics)),this.activeRooms.set(e,i),i}nameLabelShouldShow(e,t){const r=this.worldBoundsSet;return!(r&&(e<r.minX||e>r.maxX||t<r.minY||t>r.maxY))}updateAllNameLabels(){const e=this.showRoomNames&&this.zoom>=We;for(const[t,r]of this.activeRooms){if(!e){r.nameLabel.visible=!1;continue}const i=De(t);i&&(r.nameLabel.visible=this.nameLabelShouldShow(i.x,i.y))}}setupInteraction(){const e=this.app.canvas;e.style.touchAction="none",e.style.userSelect="none",e.addEventListener("pointermove",t=>{if(this.isDragging)return;const r=e.getBoundingClientRect();this.emitHover(t.clientX-r.left,t.clientY-r.top)}),e.addEventListener("pointerleave",()=>{this.isDragging||this.callbacks.onRoomHover(null)}),e.addEventListener("pointerdown",t=>{t.preventDefault(),this.isAnimating=!1,this.isDragging=!0,this.hasDragged=!1,this.dragStartX=t.clientX,this.dragStartY=t.clientY,this.dragWorldX=this.world.x,this.dragWorldY=this.world.y;const r=a=>{const o=a.clientX-this.dragStartX,l=a.clientY-this.dragStartY;(Math.abs(o)>3||Math.abs(l)>3)&&(this.hasDragged=!0);const c=this.worldBoundsSet;if(c){const d=this.world.scale.x,h=50,u=h-(c.maxX+1)*Y*d,f=this.app.screen.width-h-c.minX*Y*d,p=h-(c.maxY+1)*Y*d,b=this.app.screen.height-h-c.minY*Y*d;this.world.x=this.rubberBand(this.dragWorldX+o,u,f),this.world.y=this.rubberBand(this.dragWorldY+l,p,b)}else this.world.x=this.dragWorldX+o,this.world.y=this.dragWorldY+l},i=a=>{if(!this.hasDragged){const o=e.getBoundingClientRect(),l=this.screenToRoom(a.clientX-o.left,a.clientY-o.top);l&&this.callbacks.onRoomClick(l)}n()},n=()=>{this.isDragging=!1,this.springBack(),window.removeEventListener("pointermove",r),window.removeEventListener("pointerup",i),window.removeEventListener("pointercancel",n)};window.addEventListener("pointermove",r),window.addEventListener("pointerup",i),window.addEventListener("pointercancel",n)}),e.addEventListener("wheel",t=>{var h,u;if(t.preventDefault(),this.isDragging)return;this.isAnimating=!1;const r=this.world.scale.x,i=t.deltaY<0?1.1:.9,n=Math.max(ni,Math.min(oi,r*i)),a=(t.offsetX-this.world.x)/r,o=(t.offsetY-this.world.y)/r,l=this.getLOD(),c=this.zoom>=Pt,d=this.zoom>=We;this.world.scale.set(n),this.world.x=t.offsetX-a*n,this.world.y=t.offsetY-o*n,this.getLOD()!==l&&this.applyLOD(),(n>=Pt!==c||n>=We!==d)&&this.updateAllNameLabels(),this.updateAllRoomScales(n),(u=(h=this.callbacks).onZoomChanged)==null||u.call(h,n),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode()},{passive:!1})}rubberBand(e,t,r){const i=r-t;if(i<=0||e>=t&&e<=r)return e;const n=.55;if(e<t){const o=t-e;return t-(1-1/(o*n/i+1))*i*n}const a=e-r;return r+(1-1/(a*n/i+1))*i*n}springBack(){const e=this.worldBoundsSet;if(!e)return;const t=this.world.scale.x,r=this.app.screen.width,i=this.app.screen.height,n=50,a=this.world.x+e.minX*Y*t,o=this.world.x+(e.maxX+1)*Y*t,l=this.world.y+e.minY*Y*t,c=this.world.y+(e.maxY+1)*Y*t;let d=this.world.x,h=this.world.y;o<n?d+=n-o:a>r-n&&(d-=a-(r-n)),c<n?h+=n-c:l>i-n&&(h-=l-(i-n)),(d!==this.world.x||h!==this.world.y)&&(this.animTargetX=d,this.animTargetY=h,this.isAnimating=!0)}screenToRoom(e,t){const r=this.world.scale.x,i=(e-this.world.x)/r,n=(t-this.world.y)/r,a=Math.floor(i/Y),o=Math.floor(n/Y);return Xe(a,o)}emitHover(e,t){this.callbacks.onRoomHover(this.screenToRoom(e,t))}checkVisibleRooms(){const e=this.world.scale.x,t=this.world.x,r=this.world.y;if(this.lastCheckX===t&&this.lastCheckY===r&&this.lastCheckScale===e)return;this.lastCheckX=t,this.lastCheckY=r,this.lastCheckScale=e;const i=-t/e,n=-r/e,a=(this.app.screen.width-t)/e,o=(this.app.screen.height-r)/e,l=Math.floor(i/Y)-1,c=Math.ceil(a/Y),d=Math.floor(n/Y)-1,h=Math.ceil(o/Y);this.lastVisibleBounds={rxMin:l,rxMax:c,ryMin:d,ryMax:h};const u=[];for(let p=l;p<=c;p++)for(let b=d;b<=h;b++){const _=Xe(p,b);_&&u.push(_)}const f=`${l},${d},${c},${h}`;f!==this.lastVisibleKey&&(this.lastVisibleKey=f,this.visibleDebounceTimer!==null&&clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=setTimeout(()=>{this.visibleDebounceTimer=null,this.callbacks.onVisibleRoomsChanged(u)},Uc))}}var Jc=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">'),Qc=R('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;font-size:11px;font-weight:600">');const ed=[{mode:"owner",label:"Owner"},{mode:"mineral",label:"Mineral"},{mode:"none",label:"None"}];function td(s){const e=()=>(s.zoom??1)>=We;return(()=>{var t=Jc(),r=t.firstChild,i=r.firstChild,n=i.nextSibling,a=n.firstChild,o=a.nextSibling,l=o.nextSibling,c=l.nextSibling,d=n.nextSibling,h=d.firstChild,u=h.nextSibling,f=d.nextSibling,p=f.firstChild,b=p.nextSibling,_=r.nextSibling;return w(o,()=>{var y;return((y=s.zoom)==null?void 0:y.toFixed(2))??"—"}),w(c,()=>s.subsActive?"Yes":"No"),u.addEventListener("change",y=>Fi(y.currentTarget.checked)),b.addEventListener("change",y=>Wi(y.currentTarget.checked)),w(_,E(pe,{each:ed,children:y=>{const k=()=>Pc()===y.mode;return(()=>{var T=Qc();return T.$$click=()=>Ac(y.mode),w(T,()=>y.label),H($=>{var v=`1px solid ${k()?"#58a6ff":"#30363d"}`,M=k()?"#1f6feb33":"#161b22",x=k()?"#c9d1d9":"#8b949e";return v!==$.e&&U(T,"border",$.e=v),M!==$.t&&U(T,"background",$.t=M),x!==$.a&&U(T,"color",$.a=x),$},{e:void 0,t:void 0,a:void 0}),T})()}})),H(y=>{var k=e()?"#c9d1d9":"#484f58",T=e()?"pointer":"default",$=!e();return k!==y.e&&U(d,"color",y.e=k),T!==y.t&&U(d,"cursor",y.t=T),$!==y.a&&(u.disabled=y.a=$),y},{e:void 0,t:void 0,a:void 0}),H(()=>u.checked=zi()),H(()=>b.checked=Ui()),t})()}_e(["click"]);var sd=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">'),rd=R('<div style="padding:6px 8px;font-size:11px;color:#484f58;font-style:italic">None'),id=R('<div style="padding:3px 8px;color:#8b949e">Mineral'),nd=R('<div style="padding:3px 8px;color:#79c0ff">'),od=R('<div style="padding:3px 8px;color:#8b949e">Density'),ad=R('<div style="padding:3px 8px;color:#c9d1d9">'),ld=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 cd=["Low","Medium","High","Ultra"];function dd(s){return cd[s-1]??String(s)}function ai(s){return(()=>{var e=sd(),t=e.firstChild;return w(t,()=>s.label),w(e,E(q,{get when(){return s.info},get fallback(){return rd()},children:r=>(()=>{var i=ld(),n=i.firstChild,a=n.nextSibling,o=a.firstChild,l=o.nextSibling;return w(n,()=>r().room),w(l,()=>r().owner??"None"),w(a,E(q,{get when(){return r().mineral},get children(){return[id(),(()=>{var c=nd();return w(c,()=>r().mineral),c})(),od(),(()=>{var c=ad();return w(c,()=>dd(r().density??0)),c})()]}}),null),i})()}),null),H(r=>{var i=`1px solid ${s.dim?"#21262d":"#30363d"}`,n=s.dim?.6:1;return i!==r.e&&U(e,"border",r.e=i),n!==r.t&&U(e,"opacity",r.t=n),r},{e:void 0,t:void 0}),e})()}var hd=R("<span style=color:#8b949e;font-size:11px>Checking…"),ud=R('<div style=margin-top:8px><div style="padding:6px 8px;font-size:11px;font-weight:600;color:#c9d1d9;margin-bottom:6px">Your flags'),fd=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 style=display:flex;flex-direction:column;gap:4px;font-size:11px;color:#8b949e>Name<input placeholder="Flag name"style="background:#010409;color:#c9d1d9;border-radius:4px;padding:5px 6px;font-size:12px"></label><label style=display:flex;flex-direction:column;gap:4px;font-size:11px;color:#8b949e>Primary color<select style="background:#010409;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:5px 6px;font-size:12px"></select></label><label style=display:flex;flex-direction:column;gap:4px;font-size:11px;color:#8b949e>Secondary color<select style="background:#010409;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:5px 6px;font-size:12px"></select></label><div style=color:#484f58;font-size:11px;line-height:1.4>'),pd=R("<span style=color:#f85149;font-size:11px>"),li=R("<option>"),gd=R("<div style=margin-top:8px;color:#484f58;font-style:italic;font-size:12px>No flags."),md=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:yd}=et("flag"),ci=["COLOR_WHITE","COLOR_GREY","COLOR_RED","COLOR_PURPLE","COLOR_BLUE","COLOR_CYAN","COLOR_GREEN","COLOR_YELLOW","COLOR_ORANGE","COLOR_BROWN"];function wd(){const s=c=>{en({...ht(),...c})},[e,t]=A(null),[r,i]=A(!1);let n=null;he(()=>{if(Qe()!=="flag"||ht().name.trim()!=="")return;const c=de();c&&c.http.game.genUniqueFlagName().then(d=>{s({name:d.name}),t(null)}).catch(d=>{yd("gen unique name failed:",d)})});const a=c=>{s({name:c}),t(null),n&&clearTimeout(n);const d=c.trim();if(!d){i(!1);return}i(!0),n=setTimeout(()=>{const h=de();if(!h){i(!1);return}h.http.game.checkUniqueFlagName(d).then(()=>{t(null)}).catch(u=>{t(u.message)}).finally(()=>{i(!1)})},300)},o=()=>{const c=Oo(),d=[];for(const[h,u]of Object.entries(c))u&&typeof u=="object"&&"room"in u&&"x"in u&&"y"in u&&d.push([h,u]);return d},l=c=>c===void 0||c<0||c>=pt.length?"#8b949e":`#${pt[c].toString(16).padStart(6,"0")}`;return(()=>{var c=fd(),d=c.firstChild,h=d.firstChild,u=h.nextSibling,f=u.firstChild,p=f.firstChild,b=p.nextSibling,_=f.nextSibling,y=_.firstChild,k=y.nextSibling,T=_.nextSibling,$=T.firstChild,v=$.nextSibling,M=T.nextSibling;return b.$$input=x=>a(x.currentTarget.value),w(f,E(q,{get when(){return e()},children:x=>(()=>{var S=pd();return w(S,x),S})()}),null),w(f,E(q,{get when(){return r()},get children(){return hd()}}),null),k.addEventListener("change",x=>s({color:x.currentTarget.value})),w(k,E(pe,{each:ci,children:x=>(()=>{var S=li();return S.value=x,w(S,()=>x.replace("COLOR_","")),S})()})),v.addEventListener("change",x=>s({secondaryColor:x.currentTarget.value})),w(v,E(pe,{each:ci,children:x=>(()=>{var S=li();return S.value=x,w(S,()=>x.replace("COLOR_","")),S})()})),w(M,(()=>{var x=ne(()=>!!Ze());return()=>x()?`Marked at x=${Ze().tx}, y=${Ze().ty}. Click again to create the flag, or click elsewhere to move the mark.`:"Click a position in the room to mark it."})()),w(c,E(q,{get when(){return o().length>0},get fallback(){return gd()},get children(){var x=ud();return x.firstChild,w(x,E(pe,{get each(){return o()},children:([S,O])=>(()=>{var L=md(),I=L.firstChild,G=I.firstChild,P=G.nextSibling,C=P.nextSibling,N=C.nextSibling,B=N.firstChild,z=B.nextSibling,j=z.nextSibling,se=j.nextSibling;return se.nextSibling,w(P,S),w(C,()=>O.room),w(N,()=>O.x,z),w(N,()=>O.y,se),H(J=>U(G,"background",l(O.color))),L})()}),null),x}}),null),H(x=>U(b,"border",`1px solid ${e()?"#f85149":"#30363d"}`)),H(()=>b.value=ht().name),H(()=>k.value=ht().color),H(()=>v.value=ht().secondaryColor),c})()}_e(["input"]);var bd=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>'),vd=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 xd(){const s=Object.keys(bs),e=(i,n)=>{const a=bs[i];return a?Je()==="empty"&&i==="spawn"?Math.max(a[n]??0,1):a[n]??0:0},t=(i,n)=>{const a=e(i,n);if(a===2500)return 1/0;const o=ws()[i]??0;return Math.max(0,a-o)},r=i=>{$s({structureType:i,structureName:""})};return(()=>{var i=bd(),n=i.firstChild,a=n.firstChild;a.firstChild;var o=a.nextSibling,l=n.nextSibling;l.firstChild;var c=l.nextSibling,d=c.firstChild;return w(a,()=>mt()??"?",null),w(o,()=>{const h=Je();return h==="empty"?"World is empty — place a spawn to claim this room.":h==="lost"?"You lost all your spawns — respawn to continue.":mt()!=null?`RCL ${mt()} — Select a structure type and click a tile to build.`:"No controller — roads and containers only."}),w(l,E(pe,{each:s,children:h=>{const u=()=>mt()??0,f=()=>e(h,u()),p=()=>ws()[h]??0,b=()=>vt().structureType===h,_=()=>f()===2500,y=()=>!_()&&t(h,u())<=0;return E(q,{get when(){return f()>0},get children(){var k=vd(),T=k.firstChild,$=T.nextSibling;return k.$$click=()=>!y()&&r(h),w(T,()=>h.replace(/([A-Z])/g," $1").trim(),null),w(T,()=>b()&&" ✓",null),w($,(()=>{var v=ne(()=>!!_());return()=>v()?`${p()}/∞`:`${p()}/${f()}`})(),null),w($,()=>y()&&" (Max)",null),H(v=>{var M=b()?"#1f3158":"transparent",x=y()?"default":"pointer",S=y()?.5:1;return M!==v.e&&U(k,"background",v.e=M),x!==v.t&&U(k,"cursor",v.t=x),S!==v.a&&U(k,"opacity",v.a=S),v},{e:void 0,t:void 0,a:void 0}),k}})}}),null),w(d,()=>vt().structureType?"Click a tile in the room to build.":"Select a structure type, then click a tile."),i})()}_e(["click"]);var _d=R("<div style=padding-bottom:8px;overflow:auto;min-height:0>"),$d=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'),Sd=R("<button style=background:transparent;border:none;color:#8b949e;font-size:14px;cursor:pointer;padding:4px>"),Cd=R("<button style=background:transparent;border:none;color:#8b949e;font-size:11px;cursor:pointer>Collapse");function kd(){return E(q,{get when(){return Qe()==="flag"},get fallback(){return E(q,{get when(){return Qe()==="build"},get fallback(){return E(Tc,{})},get children(){return E(xd,{})}})},get children(){return E(wd,{})}})}function Td(s){const e=()=>{var r;(r=s.onToggle)==null||r.call(s)},t=r=>{var i;r.stopPropagation(),(i=s.onToggle)==null||i.call(s)};return(()=>{var r=$d(),i=r.firstChild,n=i.nextSibling,a=n.firstChild;return a.firstChild,i.$$click=e,w(i,(()=>{var o=ne(()=>!!s.onToggle);return()=>o()&&(()=>{var l=Sd();return l.$$click=t,w(l,()=>s.isCollapsed?"▶":"◀"),l})()})()),w(a,(()=>{var o=ne(()=>!!s.onToggle);return()=>o()&&(()=>{var l=Cd();return l.$$click=t,l})()})(),null),w(n,E(q,{get when(){return s.mapMode},get fallback(){return E(Lc,{get room(){return s.room??"—"},get shard(){return s.shard??null}})},get children(){return E(td,{get zoom(){return s.mapZoom},get subsActive(){return s.mapSubsActive}})}}),null),w(n,E(q,{get when(){return s.mapMode},get fallback(){return E(kd,{})},get children(){var o=_d();return w(o,E(ai,{label:"Selected",get info(){return s.selectedRoomInfo??null}}),null),w(o,E(ai,{label:"Cursor",get info(){return s.hoveredRoomInfo??null},dim:!0}),null),o}}),null),r})()}_e(["click"]);var Md=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>CPU:</span><span style=color:#c9d1d9>"),Rd=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Memory:</span><span style=color:#c9d1d9>"),Ed=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Zoom:</span><span style=color:#c9d1d9>%"),Od=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Subs:</span><span>"),Ld=R('<div style="display:flex;gap:16px;padding:6px 16px;font-size:12px;color:#8b949e;align-items:center">');function Pd(s){const[e,t]=A(null);Wt(()=>{const n=de();if(!n)return;const a=new yr;a.add(n.stores.user.subscribe("cpu")),a.add(n.stores.user.on("user:cpu",o=>{t(o)})),Se(()=>{a.dispose()})});const r=()=>{var o;const n=e();if(!n)return"—";const a=((o=zs())==null?void 0:o.cpu)??"?";return`${n.cpu.toFixed(1)} / ${a}`},i=()=>{const n=e();return n?`${(n.memory/1024).toFixed(1)} KB`:"—"};return(()=>{var n=Ld();return w(n,E(q,{get when(){return e()!==null},get children(){return[(()=>{var a=Md(),o=a.firstChild,l=o.nextSibling;return w(l,r),a})(),(()=>{var a=Rd(),o=a.firstChild,l=o.nextSibling;return w(l,i),a})()]}}),null),w(n,E(q,{get when(){return ne(()=>s.mapZoom!==null)()&&s.mapZoom!==void 0},get children(){return[(()=>{var a=Ed(),o=a.firstChild,l=o.nextSibling,c=l.firstChild;return w(l,()=>(s.mapZoom*100).toFixed(0),c),a})(),(()=>{var a=Od(),o=a.firstChild,l=o.nextSibling;return w(l,()=>s.mapSubsActive===!1?"paused":"active"),H(c=>U(l,"color",s.mapSubsActive===!1?"#e3b341":"#3fb950")),a})()]}}),null),n})()}var Ad=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">'),Id=R("<div style=font-size:11px;color:#8b949e;margin-top:3px>"),Gd=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>"),Nd=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;font-size:18px;cursor:pointer;line-height:1;padding:2px 6px">✕</button></div><div style="overflow:auto;flex:1;padding:20px 24px"><div style=max-width:480px>');function is(s){return(()=>{var e=Ad(),t=e.firstChild,r=t.firstChild,i=t.nextSibling,n=i.firstChild;return w(r,()=>s.label),w(t,(()=>{var a=ne(()=>!!s.description);return()=>a()&&(()=>{var o=Id();return w(o,()=>s.description),o})()})(),null),i.$$click=()=>s.onChange(!s.value),H(a=>{var o=s.value?"#238636":"#30363d",l=s.value?"22px":"2px";return o!==a.e&&U(i,"background",a.e=o),l!==a.t&&U(n,"left",a.t=l),a},{e:void 0,t:void 0}),e})()}function Ls(s){return(()=>{var e=Gd(),t=e.firstChild;return w(t,()=>s.title),w(e,()=>s.children,null),e})()}function Dd(s){return(()=>{var e=Nd(),t=e.firstChild,r=t.firstChild,i=r.nextSibling,n=t.nextSibling,a=n.firstChild;return i.$$click=()=>s.onClose(),w(a,E(Ls,{title:"Layout",get children(){return E(is,{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 Bi()},onChange:wl})}}),null),w(a,E(Ls,{title:"Room View",get children(){return E(is,{label:"Show creep labels",description:"Display each creep's name above its sprite.",get value(){return hr()},onChange:bl})}}),null),w(a,E(Ls,{title:"Map View",get children(){return[E(is,{label:"Show room names",description:"Render a small room name in the top-left corner of each map tile.",get value(){return zi()},onChange:Fi}),E(is,{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 Ui()},onChange:Wi})]}}),null),e})()}_e(["click"]);var Hd=R('<button style="padding:6px 14px;border-radius:4px;font-size:13px;cursor:pointer;margin:0 4px">'),Bd=R('<button style="padding:6px 10px;border-radius:4px;border:1px solid #30363d;background:#21262d;font-size:14px;margin:0 2px">'),zd=R("<div style=flex:1;position:relative;overflow:hidden>"),Fd=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>'),Ud=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>'),Wd=R("<div style=display:flex;flex:1;overflow:hidden><div style=display:flex;flex-direction:column;flex:1;overflow:hidden>"),Xd=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:6px 14px;border-radius:4px;border:none;background:#da3633;color:#fff;font-size:13px;cursor:pointer;margin:0 16px 0 8px">Logout'),Yd=R("<div style=display:flex;flex-direction:column;flex:1;overflow:hidden><div style=display:flex;flex:1;overflow:hidden>");const qd=ui(()=>pi(()=>import("./CodePanel-BCwhfeJ7.js"),__vite__mapDeps([0,1,2])).then(s=>({default:s.CodePanel}))),Vd=ui(()=>pi(()=>import("./MapViewer-DoywRdNM.js"),__vite__mapDeps([3,1,2])).then(s=>({default:s.MapViewer})));function Ps(){const s=xs(),e=window.location.pathname.match(new RegExp(`^${s}/room/([A-Za-z0-9]+)`));if(!e)return{room:null,shard:null};const t=e[1].toUpperCase();if(!De(t))return{room:null,shard:null};const r=new URLSearchParams(window.location.search).get("shard");return{room:t,shard:r}}function As(s,e){return`${xs()}/room/${s}${e?`?shard=${encodeURIComponent(e)}`:""}`}function jd(s){return`${xs()}/map${s?`?shard=${encodeURIComponent(s)}`:""}`}function Is(){return window.location.pathname.startsWith(`${xs()}/map`)?{shard:new URLSearchParams(window.location.search).get("shard")}:null}function Gs(s){return(()=>{var e=Hd();return e.$$click=()=>s.onClick(),w(e,()=>s.children),H(t=>{var r=`1px solid ${s.active?"#388bfd":"#30363d"}`,i=s.active?"#1f3158":"#21262d",n=s.active?"#58a6ff":"#c9d1d9";return r!==t.e&&U(e,"border",t.e=r),i!==t.t&&U(e,"background",t.t=i),n!==t.a&&U(e,"color",t.a=n),t},{e:void 0,t:void 0,a:void 0}),e})()}function di(s){return(()=>{var e=Bd();return e.$$click=()=>s.onClick(),w(e,()=>s.children),H(t=>{var r=s.disabled,i=s.disabled?"#484f58":"#c9d1d9",n=s.disabled?"default":"pointer";return r!==t.e&&(e.disabled=t.e=r),i!==t.t&&U(e,"color",t.t=i),n!==t.a&&U(e,"cursor",t.a=n),t},{e:void 0,t:void 0,a:void 0}),e})()}function Zd(){const s=Ps(),[e,t]=A(s.room??Ts(ce.room)??"W1N1"),[r,i]=A(s.shard??Ts(ce.shard)),[n,a]=A(Is()!==null),[o,l]=A(!1),[c,d]=A(!1),[h,u]=A(!1);he(()=>{c(),u(!0),Promise.resolve().then(()=>u(!1))}),he(()=>{ft()&&qe("view")});const[f,p]=A(void 0),[b,_]=A(null),[y,k]=A(null),T=Ts(ce.mapZoom),[$,v]=A(T?Number(T):null),[M,x]=A(null),[S,O]=A(!1),[L,I]=A(!1),[G,P]=A(It(ce.sidebarWidth,260)),[C,N]=A(It(ce.sidebarWidth,260)),[B,z]=A(It(ce.consoleHeight,220)),[j,se]=A(It(ce.consoleHeight,220)),[J,D]=A(!1),[F,Z]=A(!1),V=()=>G()<=32,te=()=>B()<=32,Fe=()=>{G()>32?(N(G()),P(32)):P(C())},qt=()=>{B()>32?(se(B()),z(32)):z(j())},Vt=ee=>{ee.preventDefault(),D(!0);const K=ee.clientX,oe=G(),ie=re=>{const St=re.clientX-K;P(Math.max(32,Math.min(500,oe-St)))},W=()=>{D(!1),ns(ce.sidebarWidth,G()),window.removeEventListener("pointermove",ie),window.removeEventListener("pointerup",W)};window.addEventListener("pointermove",ie),window.addEventListener("pointerup",W)},tt=ee=>{ee.preventDefault(),Z(!0);const K=ee.clientY,oe=B(),ie=re=>{const St=re.clientY-K;z(Math.max(32,Math.min(500,oe-St)))},W=()=>{Z(!1),ns(ce.consoleHeight,B()),window.removeEventListener("pointermove",ie),window.removeEventListener("pointerup",W)};window.addEventListener("pointermove",ie),window.addEventListener("pointerup",W)},_t=(ee,K)=>{var oe;(oe=de())==null||oe.stores.navigation.navigateTo(ee,K)},$t=ee=>{p(ee),a(!0),history.pushState(null,"",jd(r()))},Ae=()=>{n()?(a(!1),_(null),k(null),history.pushState(null,"",As(e(),r()))):$t(e())};Wt(()=>{var ie;!Ps().room&&!Is()&&history.replaceState(null,"",As(e(),r()));const ee=()=>{const W=Is();if(W){a(!0),W.shard!==null&&i(W.shard);return}const{room:re,shard:St}=Ps();re&&(t(re),i(St),a(!1))};window.addEventListener("popstate",ee),Se(()=>window.removeEventListener("popstate",ee));const K=(ie=de())==null?void 0:ie.stores.navigation;if(K){const W=K.on("navigation:change",re=>{re.room!==null&&(t(re.room),i(re.shard),a(!1),_(null),k(null),O(K.canBack()),I(K.canForward()),Or(ce.room,re.room),re.shard?Or(ce.shard,re.shard):Eo(ce.shard),history.pushState(null,"",As(re.room,re.shard)))});Se(()=>W.dispose())}const oe=W=>{if(!Qi(W.target)){if(W.key==="o"||W.key==="O"){d(re=>!re),l(!1);return}(W.key==="l"||W.key==="L")&&tn(),(W.key==="c"||W.key==="C")&&sn(),n()||(W.key==="1"&&qe("view"),ft()||(W.key==="2"&&qe("flag"),W.key==="3"&&qe("build")),W.key==="m"&&$t(e()))}};window.addEventListener("keydown",oe),Se(()=>window.removeEventListener("keydown",oe))});const Q=()=>(()=>{var ee=zd();return w(ee,E(q,{get when(){return o()},get children(){return E(Dd,{onClose:()=>l(!1)})}}),null),w(ee,E(q,{get when(){return c()},get children(){return E(qd,{onClose:()=>d(!1)})}}),null),w(ee,E(q,{get when(){return!n()},get fallback(){return E(Vd,{get shard(){return r()},get originRoom(){return f()},get initialZoom(){return $()??void 0},onNavigateToRoom:K=>_t(K,r()),onHoveredRoomChanged:_,onSelectedRoomChanged:k,onZoomChanged:K=>{v(K),ns(ce.mapZoom,K)},onSubscriptionStateChanged:x})},get children(){return E(Fl,{get room(){return e()},get shard(){return r()},onNavigate:_t})}}),null),ee})(),$e=()=>E(q,{get when(){return!ft()},get children(){var ee=Fd(),K=ee.firstChild;return K.$$pointerdown=tt,w(ee,E(nc,{get shard(){return r()},get isCollapsed(){return te()},onToggle:qt}),null),H(oe=>{var ie=`${B()}px`,W=F()?"none":"height 0.15s ease";return ie!==oe.e&&U(ee,"height",oe.e=ie),W!==oe.t&&U(ee,"transition",oe.t=W),oe},{e:void 0,t:void 0}),ee}}),jt=ee=>(()=>{var K=Ud(),oe=K.firstChild;return oe.$$pointerdown=Vt,w(K,E(Td,{get isCollapsed(){return V()},onToggle:Fe,get mapMode(){return n()},get hoveredRoomInfo(){return b()},get selectedRoomInfo(){return y()},get room(){return e()},get shard(){return r()},get mapZoom(){return $()},get mapSubsActive(){return M()}}),null),H(ie=>{var W=c()?"0":`${G()}px`,re=ee&&!(h()||J())?"width 0.15s ease":"none";return W!==ie.e&&U(K,"width",ie.e=W),re!==ie.t&&U(K,"transition",ie.t=re),ie},{e:void 0,t:void 0}),K})();return(()=>{var ee=Xd(),K=ee.firstChild,oe=K.firstChild,ie=oe.nextSibling;return w(K,E(fa,{}),oe),w(K,E(q,{get when(){return!ft()||n()},get children(){return E(Pd,{get mapZoom(){return ne(()=>!!n())()?$():null},get mapSubsActive(){return ne(()=>!!n())()?M():null}})}}),oe),w(K,E(di,{get disabled(){return!S()},onClick:()=>{var W;return(W=de())==null?void 0:W.stores.navigation.back()},children:"←"}),ie),w(K,E(di,{get disabled(){return!L()},onClick:()=>{var W;return(W=de())==null?void 0:W.stores.navigation.forward()},children:"→"}),ie),w(K,E(Gs,{get active(){return n()},onClick:Ae,get children(){return n()?"Room View":"Map"}}),ie),w(K,E(Gs,{get active(){return c()},onClick:()=>{d(W=>!W),l(!1)},children:"Code"}),ie),w(K,E(Gs,{get active(){return o()},onClick:()=>{l(W=>!W),d(!1)},children:"Settings"}),ie),fs(ie,"click",Go,!0),w(ee,E(q,{get when(){return Bi()},get fallback(){return(()=>{var W=Yd(),re=W.firstChild;return w(re,Q,null),w(re,()=>jt(!0),null),w(W,$e,null),W})()},get children(){var W=Wd(),re=W.firstChild;return w(re,Q,null),w(re,$e,null),w(W,()=>jt(!1),null),W}}),null),w(ee,E(Xl,{}),null),ee})()}_e(["click","pointerdown"]);var Kd=R("<div style=width:100%;height:100%>");function Jd(){const s=new URLSearchParams(window.location.search).get("guest");return s===null?null:s.startsWith("http")?s:os(be.url)??"https://screeps.com"}function Qd(){const s=()=>Ve()==="connected"&&de()!==null;return Wt(async()=>{if(Ve()==="idle"&&(await Io().catch(()=>{}),Ve()!=="connected"&&!vs())){const e=Jd();e&&Ye({url:e,auth:"guest",storage:null}).catch(()=>{})}}),(()=>{var e=Kd();return w(e,(()=>{var t=ne(()=>!!s());return()=>t()?E(Zd,{}):E(da,{})})()),e})()}const an=document.getElementById("root");if(!an)throw new Error("Root element not found");Tn(()=>E(Qd,{}),an);export{oh as M,fe as a,et as b,de as c,_e as d,ih as e,Xe as f,nh as g,Ji as h,w as i,_i as j,zi as k,Ui as l,Pc as m,El as n,zs as o,De as p,U as s,R as t,Nt as u,Pr as w};