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