screeps-client 0.3.3 → 0.3.4
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-BPalm7GH.js → CodePanel-B6VbFrxV.js} +1 -1
- package/dist/embedded/assets/MapViewer-DF2eqHW3.js +1 -0
- package/dist/embedded/assets/index-DFoX_3cK.js +24 -0
- package/dist/embedded/index.html +1 -1
- package/dist/{xxscreeps-mod/assets/CodePanel-CT25L3sq.js → standalone/assets/CodePanel-CBhC-97J.js} +1 -1
- package/dist/standalone/assets/MapViewer-TlyktL4n.js +1 -0
- package/dist/standalone/assets/index-BamYuP7w.js +24 -0
- package/dist/standalone/index.html +1 -1
- package/dist/{standalone/assets/CodePanel-CRqfH48W.js → xxscreeps-mod/assets/CodePanel-DUTSZ5g0.js} +1 -1
- package/dist/xxscreeps-mod/assets/MapViewer-DaGsI6Fg.js +1 -0
- package/dist/xxscreeps-mod/assets/index-CJKRry5L.js +24 -0
- package/dist/xxscreeps-mod/index.html +1 -1
- package/package.json +1 -1
- package/dist/embedded/assets/MapViewer-sspEY1OS.js +0 -1
- package/dist/embedded/assets/index-AMOP6Cjq.js +0 -9
- package/dist/standalone/assets/MapViewer-CY4zWpjR.js +0 -1
- package/dist/standalone/assets/index-Ct25GErL.js +0 -9
- package/dist/xxscreeps-mod/assets/MapViewer-BPHjWJtJ.js +0 -1
- package/dist/xxscreeps-mod/assets/index-BvL-GrqB.js +0 -9
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodePanel-CT25L3sq.js","assets/vendor-codemirror-D3PB7yT8.js","assets/vendor-pixi-CXkRT4gi.js","assets/MapViewer-BPHjWJtJ.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
var Ys=Object.defineProperty;var qs=(r,e,t)=>e in r?Ys(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var _=(r,e,t)=>qs(r,typeof e!="symbol"?e+"":e,t);import{k as Un,j as I,i as fr,v as Xn,w as we,$ as Vs,u as Se,l as G,p as ve,f as C,F as ye,S as H,h as he,r as Ge,D as js,a as vt,d as Zs,b as nn,m as yi,s as vr,q as Ks,o as Yn}from"./vendor-codemirror-D3PB7yT8.js";import{a as Ee,G as q,A as qn,P as jt,R as Vn,N as Js,S as Ht,B as Qs,c as sr,T as zt,b as eo,C as to,_ as jn}from"./vendor-pixi-CXkRT4gi.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))i(n);new MutationObserver(n=>{for(const s of n)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&i(o)}).observe(document,{childList:!0,subtree:!0});function t(n){const s={};return n.integrity&&(s.integrity=n.integrity),n.referrerPolicy&&(s.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?s.credentials="include":n.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function i(n){if(n.ep)return;n.ep=!0;const s=t(n);fetch(n.href,s)}})();const ro=["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"],io=new Set(["className","value","readOnly","noValidate","formNoValidate","isMap","noModule","playsInline","adAuctionHeaders","allowFullscreen","browsingTopics","defaultChecked","defaultMuted","defaultSelected","disablePictureInPicture","disableRemotePlayback","preservesPitch","shadowRootClonable","shadowRootCustomElementRegistry","shadowRootDelegatesFocus","shadowRootSerializable","sharedStorageWritable",...ro]),no=new Set(["innerHTML","textContent","innerText","children"]),so=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),oo=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 ao(r,e){const t=oo[r];return typeof t=="object"?t[e]?t.$:void 0:t}const lo=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),co=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"]),ho={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},ee=r=>fr(()=>r());function uo(r,e,t){let i=t.length,n=e.length,s=i,o=0,a=0,l=e[n-1].nextSibling,c=null;for(;o<n||a<s;){if(e[o]===t[a]){o++,a++;continue}for(;e[n-1]===t[s-1];)n--,s--;if(n===o){const d=s<i?a?t[a-1].nextSibling:t[s-a]:l;for(;a<s;)r.insertBefore(t[a++],d)}else if(s===a)for(;o<n;)(!c||!c.has(e[o]))&&e[o].remove(),o++;else if(e[o]===t[s-1]&&t[a]===e[n-1]){const d=e[--n].nextSibling;r.insertBefore(t[a++],e[o++].nextSibling),r.insertBefore(t[--s],d),e[n]=t[s]}else{if(!c){c=new Map;let u=a;for(;u<s;)c.set(t[u],u++)}const d=c.get(e[o]);if(d!=null)if(a<d&&d<s){let u=o,p=1,f;for(;++u<n&&u<s&&!((f=c.get(e[u]))==null||f!==d+p);)p++;if(p>d-a){const h=e[o];for(;a<d;)r.insertBefore(t[a++],h)}else r.replaceChild(t[a++],e[o++])}else o++;else e[o++].remove()}}}const sn="_$DX_DELEGATE";function fo(r,e,t,i={}){if(!e)throw new Error("The `element` passed to `render(..., element)` doesn't exist. Make sure `element` exists in the document.");let n;return Un(s=>{n=s,e===document?r():v(e,r(),e.firstChild?null:void 0,t)},i.owner),()=>{n(),e.textContent=""}}function R(r,e,t,i){let n;const s=()=>{if(st())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=r,a.content.firstChild},o=()=>(n||(n=s())).cloneNode(!0);return o.cloneNode=o,o}function ke(r,e=window.document){const t=e[sn]||(e[sn]=new Set);for(let i=0,n=r.length;i<n;i++){const s=r[i];t.has(s)||(t.add(s),e.addEventListener(s,xo))}}function be(r,e,t){st(r)||(t==null?r.removeAttribute(e):r.setAttribute(e,t))}function po(r,e,t,i){st(r)||(i==null?r.removeAttributeNS(e,t):r.setAttributeNS(e,t,i))}function go(r,e,t){st(r)||(t?r.setAttribute(e,""):r.removeAttribute(e))}function mo(r,e){st(r)||(e==null?r.removeAttribute("class"):r.className=e)}function Dr(r,e,t,i){if(i)Array.isArray(t)?(r[`$$${e}`]=t[0],r[`$$${e}Data`]=t[1]):r[`$$${e}`]=t;else if(Array.isArray(t)){const n=t[0];r.addEventListener(e,t[0]=s=>n.call(r,t[1],s))}else r.addEventListener(e,t,typeof t!="function"&&t)}function yo(r,e,t={}){const i=Object.keys(e||{}),n=Object.keys(t);let s,o;for(s=0,o=n.length;s<o;s++){const a=n[s];!a||a==="undefined"||e[a]||(on(r,a,!1),delete t[a])}for(s=0,o=i.length;s<o;s++){const a=i[s],l=!!e[a];!a||a==="undefined"||t[a]===l||!l||(on(r,a,!0),t[a]=l)}return t}function X(r,e,t){if(!e)return t?be(r,"style"):e;const i=r.style;if(typeof e=="string")return i.cssText=e;typeof t=="string"&&(i.cssText=t=void 0),t||(t={}),e||(e={});let n,s;for(s in t)e[s]==null&&i.removeProperty(s),delete t[s];for(s in e)n=e[s],n!==t[s]&&(i.setProperty(s,n),t[s]=n);return t}function B(r,e,t){t!=null?r.style.setProperty(e,t):r.style.removeProperty(e)}function Zn(r,e={},t,i){const n={};return i||I(()=>n.children=pr(r,e.children,n.children)),I(()=>typeof e.ref=="function"&&lr(e.ref,r)),I(()=>vo(r,e,t,!0,n,!0)),n}function lr(r,e,t){return we(()=>r(e,t))}function v(r,e,t,i){if(t!==void 0&&!i&&(i=[]),typeof e!="function")return pr(r,e,i,t);I(n=>pr(r,e(),n,t),i)}function vo(r,e,t,i,n={},s=!1){e||(e={});for(const o in n)if(!(o in e)){if(o==="children")continue;n[o]=an(r,o,null,n[o],t,s,e)}for(const o in e){if(o==="children")continue;const a=e[o];n[o]=an(r,o,a,n[o],t,s,e)}}function wo(r){let e,t,i=st();if(!i||!(e=Se.registry.get(t=_o()))){if(i)throw Se.done=!0,new Error(`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${t}
|
|
3
|
-
`);return r()}return Se.completed&&Se.completed.add(e),Se.registry.delete(t),e}function st(r){return!!Se.context&&!Se.done&&(!r||r.isConnected)}function bo(r){return r.toLowerCase().replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function on(r,e,t){const i=e.trim().split(/\s+/);for(let n=0,s=i.length;n<s;n++)r.classList.toggle(i[n],t)}function an(r,e,t,i,n,s,o){let a,l,c,d,u;if(e==="style")return X(r,t,i);if(e==="classList")return yo(r,t,i);if(t===i)return i;if(e==="ref")s||t(r);else if(e.slice(0,3)==="on:"){const p=e.slice(3);i&&r.removeEventListener(p,i,typeof i!="function"&&i),t&&r.addEventListener(p,t,typeof t!="function"&&t)}else if(e.slice(0,10)==="oncapture:"){const p=e.slice(10);i&&r.removeEventListener(p,i,!0),t&&r.addEventListener(p,t,!0)}else if(e.slice(0,2)==="on"){const p=e.slice(2).toLowerCase(),f=lo.has(p);if(!f&&i){const h=Array.isArray(i)?i[0]:i;r.removeEventListener(p,h)}(f||t)&&(Dr(r,p,t,f),f&&ke([p]))}else if(e.slice(0,5)==="attr:")be(r,e.slice(5),t);else if(e.slice(0,5)==="bool:")go(r,e.slice(5),t);else if((u=e.slice(0,5)==="prop:")||(c=no.has(e))||!n&&((d=ao(e,r.tagName))||(l=io.has(e)))||(a=r.nodeName.includes("-")||"is"in o)){if(u)e=e.slice(5),l=!0;else if(st(r))return t;e==="class"||e==="className"?mo(r,t):a&&!l&&!c?r[bo(e)]=t:r[d||e]=t}else{const p=n&&e.indexOf(":")>-1&&ho[e.split(":")[0]];p?po(r,p,e,t):be(r,so[e]||e,t)}return t}function xo(r){if(Se.registry&&Se.events&&Se.events.find(([l,c])=>c===r))return;let e=r.target;const t=`$$${r.type}`,i=r.target,n=r.currentTarget,s=l=>Object.defineProperty(r,"target",{configurable:!0,value:l}),o=()=>{const l=e[t];if(l&&!e.disabled){const c=e[`${t}Data`];if(c!==void 0?l.call(e,c,r):l.call(e,r),r.cancelBubble)return}return e.host&&typeof e.host!="string"&&!e.host._$host&&e.contains(r.target)&&s(e.host),!0},a=()=>{for(;o()&&(e=e._$host||e.parentNode||e.host););};if(Object.defineProperty(r,"currentTarget",{configurable:!0,get(){return e||document}}),Se.registry&&!Se.done&&(Se.done=_$HY.done=!0),r.composedPath){const l=r.composedPath();s(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===n)break}}else a();s(i)}function pr(r,e,t,i,n){const s=st(r);if(s){!t&&(t=[...r.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=i!==void 0;if(r=a&&t[0]&&t[0].parentNode||r,o==="string"||o==="number"){if(s||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=$t(r,t,i,l)}else t!==""&&typeof t=="string"?t=r.firstChild.data=e:t=r.textContent=e}else if(e==null||o==="boolean"){if(s)return t;t=$t(r,t,i)}else{if(o==="function")return I(()=>{let l=e();for(;typeof l=="function";)l=l();t=pr(r,l,t,i)}),()=>t;if(Array.isArray(e)){const l=[],c=t&&Array.isArray(t);if(vi(l,e,t,n))return I(()=>t=pr(r,l,t,i,!0)),()=>t;if(s){if(!l.length)return t;if(i===void 0)return t=[...r.childNodes];let d=l[0];if(d.parentNode!==r)return t;const u=[d];for(;(d=d.nextSibling)!==i;)u.push(d);return t=u}if(l.length===0){if(t=$t(r,t,i),a)return t}else c?t.length===0?ln(r,l,i):uo(r,t,l):(t&&$t(r),ln(r,l));t=l}else if(e.nodeType){if(s&&e.parentNode)return t=a?[e]:e;if(Array.isArray(t)){if(a)return t=$t(r,t,i,e);$t(r,t,null,e)}else t==null||t===""||!r.firstChild?r.appendChild(e):r.replaceChild(e,r.firstChild);t=e}else console.warn("Unrecognized value. Skipped inserting",e)}return t}function vi(r,e,t,i){let n=!1;for(let s=0,o=e.length;s<o;s++){let a=e[s],l=t&&t[r.length],c;if(!(a==null||a===!0||a===!1))if((c=typeof a)=="object"&&a.nodeType)r.push(a);else if(Array.isArray(a))n=vi(r,a,l)||n;else if(c==="function")if(i){for(;typeof a=="function";)a=a();n=vi(r,Array.isArray(a)?a:[a],Array.isArray(l)?l:[l])||n}else r.push(a),n=!0;else{const d=String(a);l&&l.nodeType===3&&l.data===d?r.push(l):r.push(document.createTextNode(d))}}return n}function ln(r,e,t=null){for(let i=0,n=e.length;i<n;i++)r.insertBefore(e[i],t)}function $t(r,e,t,i){if(t===void 0)return r.textContent="";const n=i||document.createTextNode("");if(e.length){let s=!1;for(let o=e.length-1;o>=0;o--){const a=e[o];if(n!==a){const l=a.parentNode===r;!s&&!o?l?r.replaceChild(n,a):r.insertBefore(n,t):l&&a.remove()}else s=!0}}else r.insertBefore(n,t);return[n]}function _o(){return Se.getNextContextId()}const $o="http://www.w3.org/2000/svg";function So(r,e=!1,t=void 0){return e?document.createElementNS($o,r):document.createElement(r,{is:t})}function Co(r,e){const t=fr(r);return fr(()=>{const i=t();switch(typeof i){case"function":return Object.assign(i,{[Vs]:!0}),we(()=>i(e));case"string":const n=co.has(i),s=Se.context?wo():So(i,n,we(()=>e.is));return Zn(s,e,n),s}})}function Kn(r){const[,e]=Xn(r,["component"]);return Co(()=>r.component,e)}async function Jn(r,e){const t=r.slice(3),i=Uint8Array.from(atob(t),u=>u.charCodeAt(0)),n=new DecompressionStream(e),s=n.writable.getWriter();await s.write(i),await s.close();const o=n.readable.getReader(),a=[];try{for(;;){const{done:u,value:p}=await o.read();if(u)break;a.push(p)}}catch(u){throw o.cancel(),u}let l=0;for(const u of a)l+=u.length;const c=new Uint8Array(l);let d=0;for(const u of a)c.set(u,d),d+=u.length;return JSON.parse(new TextDecoder().decode(c))}function ko(r){return Jn(r,"gzip")}function To(r){return Jn(r,"deflate")}class Ke{constructor(e){_(this,"fn");this.fn=e}static create(e){return e===!0?new Ke(console.debug.bind(console)):typeof e=="function"?new Ke(e):new Ke(null)}child(e){if(!this.fn)return this;const t=this.fn;return new Ke((...i)=>t(`[screeps:${e}]`,...i))}log(...e){var t;(t=this.fn)==null||t.call(this,...e)}}function Mo(r){return{signin:(e,t)=>r.request("POST","/api/auth/signin",{email:e,password:t}),me:()=>r.request("GET","/api/auth/me"),queryToken:e=>r.request("GET","/api/auth/query-token",{token:e}),steamTicket:(e,t)=>r.request("POST","/api/auth/steam-ticket",{ticket:e,...t!=null?{useNativeAuth:t}:{}}),modInfo:()=>r.request("GET","/api/authmod")}}function Eo(r){return{list:()=>r.request("GET","/api/game/power-creeps/list"),create:(e,t)=>r.request("POST","/api/game/power-creeps/create",{name:e,className:t}),delete:e=>r.request("POST","/api/game/power-creeps/delete",{id:e}),cancelDelete:e=>r.request("POST","/api/game/power-creeps/cancel-delete",{id:e}),upgrade:(e,t)=>r.request("POST","/api/game/power-creeps/upgrade",{id:e,powers:t}),rename:(e,t)=>r.request("POST","/api/game/power-creeps/rename",{id:e,name:t}),experimentation:()=>r.request("POST","/api/game/power-creeps/experimentation")}}function xe(r,e){return e&&(r.shard=e),r}function Ro(r){return{roomTerrain:(e,t)=>r.request("GET","/api/game/room-terrain",xe({room:e,encoded:1},t)),roomObjects:(e,t)=>r.request("GET","/api/game/room-objects",xe({room:e},t)),roomStatus:(e,t)=>r.request("GET","/api/game/room-status",xe({room:e},t)),roomOverview:(e,t=8,i)=>r.request("GET","/api/game/room-overview",xe({room:e,interval:t},i)),time:e=>r.request("GET","/api/game/time",xe({},e)),worldSize:e=>r.request("GET","/api/game/world-size",xe({},e)),mapStats:(e,t,i)=>r.request("POST","/api/game/map-stats",xe({rooms:e,statName:t},i)),roomsTerrain:(e,t)=>{const i=new URLSearchParams({encoded:"true"});return t&&i.set("shard",t),r.request("POST",`/api/game/rooms?${i}`,{rooms:e})},createFlag:(e,t,i,n,s,o,a)=>r.request("POST","/api/game/create-flag",xe({room:e,x:t,y:i,name:n,color:s,secondaryColor:o},a)),genUniqueFlagName:()=>r.request("POST","/api/game/gen-unique-flag-name"),checkUniqueFlagName:e=>r.request("POST","/api/game/check-unique-flag-name",{name:e}),changeFlagColor:(e,t,i,n)=>r.request("POST","/api/game/change-flag-color",{room:e,name:t,color:i,secondaryColor:n}),removeFlag:(e,t)=>r.request("POST","/api/game/remove-flag",{room:e,name:t}),genUniqueObjectName:(e,t)=>r.request("POST","/api/game/gen-unique-object-name",xe({type:e},t)),checkUniqueObjectName:(e,t,i)=>r.request("POST","/api/game/check-unique-object-name",xe({type:e,name:t},i)),placeSpawn:(e,t,i,n,s)=>r.request("POST","/api/game/place-spawn",xe({room:e,x:t,y:i,...n?{name:n}:{}},s)),createConstruction:(e,t,i,n,s,o)=>r.request("POST","/api/game/create-construction",xe({room:e,x:t,y:i,structureType:n,...s?{name:s}:{}},o)),removeConstructionSite:(e,t,i)=>r.request("POST","/api/game/add-object-intent",xe({_id:"room",room:e,name:"removeConstructionSite",intent:t.map(n=>({id:n,roomName:e}))},i)),addObjectIntent:(e,t,i,n)=>r.request("POST","/api/game/add-object-intent",{_id:e,room:t,name:i,intent:n}),addGlobalIntent:(e,t)=>r.request("POST","/api/game/add-global-intent",{name:e,intent:t}),setNotifyWhenAttacked:(e,t)=>r.request("POST","/api/game/set-notify-when-attacked",{_id:e,enabled:t}),createInvader:(e,t,i,n,s,o)=>r.request("POST","/api/game/create-invader",{room:e,x:t,y:i,size:n,type:s,...o!=null?{boosted:o}:{}}),removeInvader:e=>r.request("POST","/api/game/remove-invader",{_id:e}),tick:()=>r.request("GET","/api/game/tick"),powerCreeps:Eo(r),market:{ordersIndex:e=>r.request("GET","/api/game/market/orders-index",xe({},e)),myOrders:()=>r.request("GET","/api/game/market/my-orders"),orders:(e,t)=>r.request("GET","/api/game/market/orders",xe({resourceType:e},t)),stats:(e,t)=>r.request("GET","/api/game/market/stats",xe({resourceType:e},t))},shards:{info:()=>r.request("GET","/api/game/shards/info")}}}function Po(r){return{send:(e,t)=>r.request("POST","/api/user/messages/send",{respondent:e,text:t}),list:e=>r.request("GET","/api/user/messages/list",{respondent:e}),index:()=>r.request("GET","/api/user/messages/index"),markRead:e=>r.request("POST","/api/user/messages/mark-read",{id:e}),unreadCount:()=>r.request("GET","/api/user/messages/unread-count")}}function St(r,e){return e&&(r.shard=e),r}function Oo(r){return{branches:()=>r.request("GET","/api/user/branches"),code:{get:e=>r.request("GET","/api/user/code",e?{branch:e}:{}),set:(e,t)=>r.request("POST","/api/user/code",{branch:e,modules:t,_hash:Date.now()})},memory:{get:(e,t)=>r.request("GET","/api/user/memory",St({path:e},t)),set:(e,t,i)=>r.request("POST","/api/user/memory",St({path:e,value:t},i)),segment:{get:(e,t)=>r.request("GET","/api/user/memory-segment",St({segment:e},t)),set:(e,t,i)=>r.request("POST","/api/user/memory-segment",St({segment:e,data:t},i))}},console:(e,t)=>r.request("POST","/api/user/console",St({expression:e},t)),stats:e=>r.request("GET","/api/user/stats",{interval:e}),rooms:e=>r.request("GET","/api/user/rooms",{id:e}),overview:(e,t)=>r.request("GET","/api/user/overview",{interval:e,statName:t}),worldStatus:()=>r.request("GET","/api/user/world-status"),worldStartRoom:e=>r.request("GET","/api/user/world-start-room",St({},e)),find:e=>r.request("GET","/api/user/find",e),moneyHistory:e=>r.request("GET","/api/user/money-history",e!=null?{page:e}:{}),respawn:()=>r.request("POST","/api/user/respawn"),respawnProhibitedRooms:()=>r.request("GET","/api/user/respawn-prohibited-rooms"),badge:e=>r.request("POST","/api/user/badge",{badge:e}),setActiveBranch:(e,t)=>r.request("POST","/api/user/set-active-branch",{activeName:e,branch:t}),cloneBranch:(e,t,i)=>r.request("POST","/api/user/clone-branch",{newName:e,...t?{branch:t}:{},...i!=null?{defaultModules:i}:{}}),deleteBranch:e=>r.request("POST","/api/user/delete-branch",{branch:e}),notifyPrefs:e=>r.request("POST","/api/user/notify-prefs",e),tutorialDone:()=>r.request("POST","/api/user/tutorial-done"),email:e=>r.request("POST","/api/user/email",{email:e}),setSteamVisible:e=>r.request("POST","/api/user/set-steam-visible",{visible:e}),password:(e,t)=>r.request("POST","/api/user/password",{password:e,...t!=null?{oldPassword:t}:{}}),messages:Po(r)}}function Lo(r){return{list:(e=10,t="world",i=0,n)=>r.request("GET","/api/leaderboard/list",{limit:e,mode:t,offset:i,season:n}),find:(e,t="world",i="")=>r.request("GET","/api/leaderboard/find",{username:e,mode:t,season:i}),seasons:()=>r.request("GET","/api/leaderboard/seasons")}}function Ao(r){return{pvp:(e=100)=>r.request("GET","/api/experimental/pvp",{interval:e}),nukes:()=>r.request("GET","/api/experimental/nukes")}}function Io(r){return{checkEmail:e=>r.request("GET","/api/register/check-email",{email:e}),checkUsername:e=>r.request("GET","/api/register/check-username",{username:e}),setUsername:(e,t)=>r.request("POST","/api/register/set-username",{username:e,...t!=null?{email:t}:{}}),submit:(e,t,i,n)=>r.request("POST","/api/register/submit",{username:e,email:t,password:i,...n!=null?{modules:n}:{}})}}class No extends EventTarget{constructor(t){super();_(this,"baseUrl");_(this,"authStrategy");_(this,"logger");_(this,"serverPassword");_(this,"token",null);_(this,"rateLimits",new Map);_(this,"authenticating",!1);_(this,"auth");_(this,"register");_(this,"game");_(this,"user");_(this,"leaderboard");_(this,"experimental");this.baseUrl=t.url.endsWith("/")?t.url:`${t.url}/`,this.authStrategy=t.auth,this.logger=t.logger??Ke.create(),this.serverPassword=t.serverPassword??null,this.auth=Mo(this),this.register=Io(this),this.game=Ro(this),this.user=Oo(this),this.leaderboard=Lo(this),this.experimental=Ao(this)}emit(t,i){this.dispatchEvent(new CustomEvent(t,{detail:i}))}on(t,i){const n=s=>i(s.detail);return this.addEventListener(t,n),{dispose:()=>{this.removeEventListener(t,n)}}}async authenticate(){this.logger.log("authenticate"),this.authenticating=!0;try{this.token=await this.authStrategy.authenticate(this),this.logger.log("authenticated")}finally{this.authenticating=!1}}setToken(t){this.token=t}async request(t,i,n,s=!1){this.logger.log(t,i);const o=new URL(i.startsWith("/")?i.slice(1):i,this.baseUrl),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"&&n)for(const[p,f]of Object.entries(n))f!=null&&o.searchParams.set(p,String(f));else n&&(a["Content-Type"]="application/json",l.body=JSON.stringify(n));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(i,c),c.status===401&&!s&&!this.authenticating)return await this.authenticate(),this.request(t,i,n,!0);if(!c.ok){let p="";try{p=await c.text()}catch{}const f=new Error(`HTTP ${c.status}: ${p}`);throw this.emit("http:error",{method:t,path:i,status:c.status,error:f}),f}this.emit("http:success",{method:t,path:i,status:c.status});const u=await c.json();if(typeof u.error=="string"){const p=new Error(`Screeps API error: ${u.error}`);throw this.emit("http:error",{method:t,path:i,status:c.status,error:p}),p}return typeof u.data=="string"&&u.data.startsWith("gz:")&&(u.data=await ko(u.data)),u}updateRateLimit(t,i){const n=i.headers.get("x-ratelimit-limit"),s=i.headers.get("x-ratelimit-remaining"),o=i.headers.get("x-ratelimit-reset");n&&s&&o&&this.rateLimits.set(t,{limit:parseInt(n,10),remaining:parseInt(s,10),reset:parseInt(o,10)})}}async function Go(r){let e=typeof r=="string"?r:r.data;if(e.startsWith("gz:")&&(e=JSON.stringify(await To(e))),e.startsWith("[")){const[n,s]=JSON.parse(e);return{kind:"channel",message:{channel:n,data:s}}}const[t,...i]=e.split(" ");switch(t){case"auth":return{kind:"server",command:{type:"auth",status:i[0],token:i[1]}};case"time":return{kind:"server",command:{type:"time",time:parseInt(i[0],10)}};case"protocol":return{kind:"server",command:{type:"protocol",protocol:parseInt(i[0],10)}};case"package":return{kind:"server",command:{type:"package",package:parseInt(i[0],10)}};default:throw new Error(`Unknown server command: ${t}`)}}class Do{constructor(e){_(this,"wsUrl");_(this,"WS");_(this,"logger");_(this,"ws",null);_(this,"token",null);_(this,"authed",!1);_(this,"_connected",!1);_(this,"reconnecting",!1);_(this,"authSub",null);_(this,"queue",[]);_(this,"subs",new Map);_(this,"listeners",new Map);_(this,"MAX_RETRIES",10);_(this,"MAX_DELAY_MS",6e4);_(this,"_intentionalClose",!1);const t=e.url.replace(/^http/,"ws").replace(/\/$/,"");this.wsUrl=`${t}/socket/websocket`,this.WS=e.WebSocket??globalThis.WebSocket,this.logger=e.logger??Ke.create()}get isConnected(){return this._connected}setToken(e){this.token=e}connect(e){var t;return this.logger.log("connect",this.wsUrl),this.reconnecting||(this._intentionalClose=!1),this.token=e,(t=this.authSub)==null||t.dispose(),this.authSub=null,new Promise((i,n)=>{this.ws=new this.WS(this.wsUrl),this.ws.onopen=()=>{this.logger.log("WebSocket opened"),this._connected=!0,this.reconnecting=!1,this.rawSend(`auth ${this.token}`),this.authSub=this.once("auth",s=>{const o=s;if(o.status==="ok"){for(this.logger.log("auth ok"),this.authed=!0,o.token&&(this.token=o.token,this.emit("socket:tokenRefresh",{token:o.token}));this.queue.length;)this.rawSend(this.queue.shift());this.emit("connected",{}),i()}else this.logger.log("auth failed"),n(new Error("WebSocket auth failed"))})},this.ws.onclose=()=>{var s;this.logger.log("WebSocket closed"),this._connected=!1,this.authed=!1,(s=this.authSub)==null||s.dispose(),this.authSub=null,this.emit("disconnected",{willReconnect:this.reconnecting}),this.scheduleReconnect()},this.ws.onerror=s=>{this._connected||n(s)},this.ws.onmessage=s=>{this.handleMessage(s).catch(o=>{const a=typeof s.data=="string"?s.data.slice(0,200):"(binary)";this.logger.log("message parse error",o instanceof Error?o.stack??o.message:String(o),"raw:",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 i=this.listeners.get(e);return i||(i=new Set,this.listeners.set(e,i)),i.add(t),{dispose:()=>{var n;(n=this.listeners.get(e))==null||n.delete(t)}}}once(e,t){const i=this.on(e,n=>{i.dispose(),t(n)});return i}doUnsubscribe(e){const t=this.subs.get(e)??0;t<=1?(this.subs.delete(e),this.authed&&this.rawSend(`unsubscribe ${e}`),this.logger.log("unsubscribe",e,"active:",this.activeSubs())):(this.subs.set(e,t-1),this.logger.log("unsubscribe",e,`(refs: ${t-1})`,"active:",this.activeSubs()))}rawSend(e){var t;(t=this.ws)==null||t.send(e)}sendOrQueue(e){this.authed?this.rawSend(e):this.queue.push(e)}emit(e,t){var i;(i=this.listeners.get(e))==null||i.forEach(n=>{try{n(t)}catch(s){this.logger.log("listener error on channel",e,s instanceof Error?s.stack??s.message:String(s))}})}async handleMessage(e){const t=await Go(e);t.kind==="server"?this.emit(t.command.type,t.command):this.emit(t.message.channel,t.message.data)}async scheduleReconnect(){var t;if(this.reconnecting||this._intentionalClose)return;if(!this.token){this.reconnecting=!1;return}this.reconnecting=!0;let e=0;for(;e<this.MAX_RETRIES&&this.reconnecting&&!this._intentionalClose;){const i=Math.min(Math.pow(2,e)*100,this.MAX_DELAY_MS);if(this.logger.log(`reconnect attempt ${e+1}/${this.MAX_RETRIES} in ${i}ms`),await new Promise(n=>setTimeout(n,i)),!this.reconnecting||this._intentionalClose)return;try{if(await this.connect(this.token),this._intentionalClose){(t=this.ws)==null||t.close(),this.ws=null;return}for(const n of this.subs.keys())this.rawSend(`subscribe ${n}`);return}catch{e++}}this.reconnecting=!1,e>=this.MAX_RETRIES&&!this._intentionalClose&&this.emit("socket:error",new Error(`WebSocket reconnection failed after ${this.MAX_RETRIES} retries`))}}class zo{constructor(e,t){_(this,"memory",new Map);_(this,"storage");_(this,"namespace");this.namespace=e,this.storage=t}memKey(e){return`${this.namespace}/${e}`}get(e){const t=this.memory.get(this.memKey(e));if(t){if(t.expires!==void 0&&Date.now()>t.expires){this.memory.delete(this.memKey(e));return}return t.data}}set(e,t,i){this.memory.set(this.memKey(e),{data:t,expires:i!==void 0?Date.now()+i:void 0})}delete(e){this.memory.delete(this.memKey(e))}async getPersistent(e){return this.storage?this.storage.get(`${this.namespace}/${e}`):null}async setPersistent(e,t){this.storage&&await this.storage.set(`${this.namespace}/${e}`,t)}async deletePersistent(e){this.storage&&await this.storage.delete(`${this.namespace}/${e}`)}clearMemory(){this.memory.clear()}async clearPersistent(){this.storage&&await this.storage.clear()}async clearAll(){this.clearMemory(),await this.clearPersistent()}}class Yt extends EventTarget{constructor(t){super();_(this,"logger");this.logger=t??Ke.create()}emit(t,i){this.dispatchEvent(new CustomEvent(t,{detail:i}))}on(t,i){this.logger.log(`on "${t}"`);const n=s=>i(s.detail);return this.addEventListener(t,n),{dispose:()=>{this.logger.log(`off "${t}"`),this.removeEventListener(t,n)}}}}var Ne=(r=>(r[r.Plain=0]="Plain",r[r.Wall=1]="Wall",r[r.Swamp=2]="Swamp",r))(Ne||{});class At{constructor(e){_(this,"raw");this.raw=e}static fromEncodedString(e){const t=new Uint8Array(2500);for(let i=0;i<2500;i++){const n=parseInt(e[i],10);t[i]=n===3?1:n}return new At(t)}get(e,t){return this.raw[t*50+e]}}class Bo extends Yt{constructor(t,i,n,s){super(s);_(this,"http");_(this,"socket");_(this,"cache");_(this,"roomObjects",new Map);_(this,"roomUsers",new Map);_(this,"roomSubCount",new Map);_(this,"lastFlagsString",new Map);this.http=t,this.socket=i,this.cache=n}parseFlagsString(t,i){if(!t||t.length===0)return[];const n=[],s=t.split("|");for(const o of s){const a=o.split("~");if(a.length!==5)continue;const[l,c,d,u,p]=a,f=parseInt(c,10),h=parseInt(d,10),g=parseInt(u,10),$=parseInt(p,10);isNaN(f)||isNaN(h)||isNaN(g)||isNaN($)||n.push({_id:l,type:"flag",room:i,name:l,x:g,y:$,color:f,secondaryColor:h})}return n}async terrain(t,i){const n=`terrain/${i}/${t}`,s=this.cache.get(n);if(s)return this.logger.log("terrain",t,i,"(memory cache hit)"),s;const o=await this.cache.getPersistent(n);if(o){this.logger.log("terrain",t,i,"(persistent cache hit)");const d=new At(o);return this.cache.set(n,d),d}this.logger.log("terrain",t,i,"(fetching)");const l=(await this.http.game.roomTerrain(t,i??void 0)).terrain[0];if(!l)throw new Error(`No terrain data for room ${t} shard ${i}`);const c=At.fromEncodedString(l.terrain);return this.cache.set(n,c),await this.cache.setPersistent(n,c.raw),this.emit("room:terrainavailable",{room:t,shard:i,terrain:c}),c}async terrainBulk(t,i){const n=new Map,s=[];for(const l of t){const c=this.cache.get(`terrain/${i}/${l}`);c?n.set(l,c):s.push(l)}if(s.length===0)return n;const o=[];if(await Promise.all(s.map(async l=>{const c=`terrain/${i}/${l}`,d=await this.cache.getPersistent(c);if(d){const u=new At(d);this.cache.set(c,u),n.set(l,u)}else o.push(l)})),o.length===0)return n;this.logger.log("terrainBulk",`fetching ${o.length} rooms`,i);const a=await this.http.game.roomsTerrain(o,i??void 0);return await Promise.all(a.rooms.map(async l=>{const c=At.fromEncodedString(l.terrain),d=`terrain/${i}/${l.room}`;this.cache.set(d,c),await this.cache.setPersistent(d,c.raw),this.emit("room:terrainavailable",{room:l.room,shard:i,terrain:c}),n.set(l.room,c)})),n}objects(t,i){const n=this.roomObjects.get(`${t}/${i}`);return n?{...n}:null}async fetchObjects(t,i){const n=`${t}/${i}`,s=await this.http.game.roomObjects(t,i??void 0),o={};for(const l of s.objects)l&&typeof l=="object"&&"_id"in l&&(o[l._id]=l);this.roomObjects.set(n,o);const a=this.roomUsers.get(n);this.emit("room:update",{room:t,shard:i,gameTime:void 0,objects:o,diff:o,visual:"",users:a})}activeRooms(){return Array.from(this.roomSubCount.entries()).map(([t,i])=>`${t}(${i})`).join(", ")||"(none)"}subscribe(t,i){const n=`${t}/${i}`,s=this.roomSubCount.get(n)??0;this.roomSubCount.set(n,s+1),this.logger.log("subscribe",t,i,`(refs: ${s+1})`,"active:",this.activeRooms());const o=i?`room:${i}/${t}`:`room:${t}`,a=i?`err@room:${i}/${t}`:`err@room:${t}`,l=this.socket.subscribe(o),c=this.socket.on(a,u=>{const p=typeof u=="string"?u:JSON.stringify(u);this.logger.log("room error",t,i,p),this.emit("room:error",{room:t,shard:i,message:p})}),d=this.socket.on(o,u=>{const p=u,f={...this.roomObjects.get(n)??{}};if(p.objects==null)p.objects===null&&this.logger.log("room update has null objects field",t,i,`gameTime: ${p.gameTime}`);else for(const[$,y]of Object.entries(p.objects))y===null?delete f[$]:f[$]?f[$]={...f[$],...y}:f[$]=y;const h={...p.objects??{}};if("flags"in p){const $=p.flags??"",y=this.lastFlagsString.get(n)??"";if($!==y){this.lastFlagsString.set(n,$);const S=this.parseFlagsString($,t),E=new Map;for(const x of S)E.set(x.name,x);for(const x in f){const m=f[x];(m==null?void 0:m.type)==="flag"&&!E.has(x)&&(delete f[x],h[x]=null,this.logger.log(`[flag:room] removed ${x} @ ${t}`))}for(const[x,m]of E){const M=f[x];(!M||M.x!==m.x||M.y!==m.y||M.color!==m.color||M.secondaryColor!==m.secondaryColor)&&(f[x]=m,h[x]=m,this.logger.log(`[flag:room] ${M?"changed":"added"} ${x} @ ${t} (${m.x},${m.y})`))}}}if(p.users){const $=this.roomUsers.get(n)??{};this.roomUsers.set(n,{...$,...p.users})}this.roomObjects.set(n,f);const g=this.roomUsers.get(n);this.emit("room:update",{room:t,shard:i,gameTime:p.gameTime,objects:f,diff:h,visual:p.visual??"",users:g})});return{dispose:()=>{l.dispose(),d.dispose(),c.dispose();const u=(this.roomSubCount.get(n)??1)-1;u<=0?(this.roomSubCount.delete(n),this.roomObjects.delete(n),this.roomUsers.delete(n),this.lastFlagsString.delete(n),this.logger.log("unsubscribe",t,i,"(last ref)","active:",this.activeRooms())):(this.roomSubCount.set(n,u),this.logger.log("unsubscribe",t,i,`(refs: ${u})`,"active:",this.activeRooms()))}}}}class Fo extends Yt{constructor(t,i,n,s,o=100){super(s);_(this,"http");_(this,"socket");_(this,"cache");_(this,"console",[]);_(this,"maxConsoleSize");_(this,"_cpu",null);_(this,"_userInfo",null);_(this,"_userId",null);_(this,"_worldStatus",null);_(this,"_mePromise",null);this.http=t,this.socket=i,this.cache=n,this.maxConsoleSize=o}get cpu(){return this._cpu}get userInfo(){return this._userInfo}get userId(){return this._userId}get worldStatusValue(){return this._worldStatus}async me(){const t=this.cache.get("user/me");return t?(this._userId=t._id,this._userInfo=t,t):this._mePromise?this._mePromise:(this.logger.log("fetch me"),this._mePromise=this.http.auth.me().then(i=>{const n=i;return this._userId=n._id,this._userInfo=n,this.cache.set("user/me",n,6e4),this.emit("user:me",n),n}).finally(()=>{this._mePromise=null}),this._mePromise)}async refreshMe(){return this.logger.log("refresh me"),this.cache.delete("user/me"),this.me()}async worldStatus(){const t=this.cache.get("user/worldStatus");if(t)return this._worldStatus=t,t;this.logger.log("fetch world status");const i=await this.http.user.worldStatus();return this._worldStatus=i.status,this.cache.set("user/worldStatus",i.status,6e4),this.emit("user:worldStatus",{status:i.status}),i.status}async refreshWorldStatus(){return this.logger.log("refresh world status"),this.cache.delete("user/worldStatus"),this.worldStatus()}subscribe(t){this.logger.log("subscribe",t);let i=null,n=null,s=!1;return(async()=>{try{const a=this._userId??(await this.me())._id;if(s)return;const l=`user:${a}/${t}`;i=this.socket.subscribe(l),n=this.socket.on(l,c=>{var d,u,p;if(t==="cpu")this._cpu=c,this.emit("user:cpu",this._cpu);else if(t==="console"){const f=c,h={log:((d=f.messages)==null?void 0:d.log)??[],results:((u=f.messages)==null?void 0:u.results)??[],error:((p=f.messages)==null?void 0:p.error)??[]};f.error&&h.error.push(f.error),this.console.push(h),this.console.length>this.maxConsoleSize&&this.console.splice(0,this.console.length-this.maxConsoleSize),this.emit("user:console",{messages:h})}else t==="code"&&this.emit("user:code",c)})}catch(a){s||this.dispatchEvent(new ErrorEvent("error",{error:a instanceof Error?a:new Error(String(a))}))}})(),{dispose:()=>{this.logger.log("unsubscribe",t),s=!0,i==null||i.dispose(),n==null||n.dispose()}}}subscribeUserStream(){this.logger.log("subscribe user stream");let t=null,i=null,n=!1;return(async()=>{try{const o=this._userId??(await this.me())._id;if(n)return;const a=`user:${o}`;t=this.socket.subscribe(a),i=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[u,p]of Object.entries(d)){const f=p;if(f&&typeof f=="object"){const h=f.room??"unknown",g=f.x??"?",$=f.y??"?";this.logger.log(`[flag:user] ${u} @ ${h} (${g},${$})`)}}}this.emit("user:stream",c)})}catch(o){n||this.dispatchEvent(new ErrorEvent("error",{error:o instanceof Error?o:new Error(String(o))}))}})(),{dispose:()=>{this.logger.log("unsubscribe user stream"),n=!0,t==null||t.dispose(),i==null||i.dispose()}}}}class Ho extends Yt{constructor(t,i,n,s){super(s);_(this,"http");_(this,"cache");_(this,"socketSubs",[]);_(this,"_version",null);_(this,"_shards",null);this.http=t,this.cache=n,this.socketSubs.push(i.on("connected",()=>{this.emit("server:connected",{})})),this.socketSubs.push(i.on("disconnected",o=>{const a=o;this.emit("server:disconnected",{willReconnect:a.willReconnect})})),this.socketSubs.push(i.on("socket:error",o=>{this.emit("server:error",{error:o instanceof Error?o:new Error(String(o))})}))}get versionInfo(){return this._version}get isPrivateServer(){var t,i;return this._version?(((i=(t=this._version.serverData)==null?void 0:t.shards)==null?void 0:i.length)??0)===0:null}get shardList(){return this._shards}destroy(){for(const t of this.socketSubs)t.dispose();this.socketSubs.length=0}async version(){const t=this.cache.get("server/version");if(t)return t;const i=await this.http.request("GET","/api/version");return this._version=i,this.cache.set("server/version",i,5*6e4),this.emit("server:version",i),i}async refreshVersion(){return this.cache.delete("server/version"),this.version()}async shards(){const t=this.cache.get("server/shards");if(t)return t;const i=await this.http.request("GET","/api/game/shards/info");return this._shards=i.shards,this.cache.set("server/shards",i.shards,5*6e4),this.emit("server:shards",i.shards),i.shards}async refreshShards(){return this.cache.delete("server/shards"),this.shards()}async worldInfo(t){const n=`server/world/${t??"default"}`,s=this.cache.get(n);if(s)return s;const o={};t&&(o.shard=t);const 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,u=-1,p=-c,f=-1;try{const $=(await this.http.request("POST","/api/game/map-stats",{rooms:["W0N0","E0N0","W0S0","E0S0"],statName:"owner0",...o})).stats??{},y=["W0N0","E0N0","W0S0","E0S0"].filter(S=>S in $);this.logger.log(`worldInfo corner probe — found: [${y.length?y.join(", "):"none"}]`),("E0N0"in $||"E0S0"in $)&&(d=-Math.ceil(l/2),u=Math.floor(l/2)-1),("W0S0"in $||"E0S0"in $)&&(p=-Math.ceil(c/2),f=Math.floor(c/2)-1)}catch(g){this.logger.log("worldInfo corner probe failed — keeping W/N defaults:",g)}this.logger.log(`worldInfo computed bounds — x: [${d}, ${u}] y: [${p}, ${f}]`);const h={shard:t??null,width:l,height:c,minX:d,maxX:u,minY:p,maxY:f};return this.cache.set(n,h,10*6e4),h}invalidateWorldInfo(t){this.cache.delete(`server/world/${t??"default"}`)}}class Wo{constructor(e){_(this,"memory",new Map);_(this,"adapter");_(this,"maxEntries");_(this,"namespace");_(this,"accessSeq",0);this.adapter=e.adapter,this.maxEntries=e.maxEntries,this.namespace=e.namespace}key(e,t){return`${t??"_"}/${e}`}adapterKey(e){return`map2/${e}`}tick(){return++this.accessSeq}serialize(e){const t={data:e.data,lastSeen:e.lastSeen,lastAccess:e.lastAccess};return new TextEncoder().encode(JSON.stringify(t))}deserialize(e){try{return JSON.parse(new TextDecoder().decode(e))}catch{return null}}getMemory(e,t){const i=this.memory.get(this.key(e,t));return i?(i.lastAccess=this.tick(),i.data):null}async get(e,t){const i=this.getMemory(e,t);if(i)return i;if(!this.adapter)return null;const n=this.key(e,t),s=await this.adapter.get(this.adapterKey(n));if(!s)return null;const o=this.deserialize(s);return o?(this.memory.set(n,{data:o.data,lastSeen:o.lastSeen,lastAccess:this.tick()}),o.data):null}async put(e,t,i){const n=this.key(e,t),s={data:i,lastSeen:Date.now(),lastAccess:this.tick()};this.memory.set(n,s),await this.pruneIfNeeded(),this.adapter&&await this.adapter.set(this.adapterKey(n),this.serialize(s))}async pruneIfNeeded(){if(this.memory.size<=this.maxEntries)return;const t=[...this.memory.entries()].sort((i,n)=>i[1].lastAccess-n[1].lastAccess).slice(0,this.memory.size-this.maxEntries);for(const[i]of t)this.memory.delete(i),this.adapter&&await this.adapter.delete(this.adapterKey(i))}}function cn(r){const e=Object.keys(r).sort(),t={};for(const i of e){const n=r[i];t[i]=n?[...n].sort((s,o)=>s[0]-o[0]||s[1]-o[1]):null}return JSON.stringify(t)}class Uo extends Yt{constructor(t,i,n={},s){super(s);_(this,"socket");_(this,"storage");_(this,"maxSubscriptions");_(this,"active",new Map);_(this,"waitlist",[]);_(this,"keyStates",new Map);_(this,"warnedAboutWaitlist",!1);this.socket=t,this.storage=i,this.maxSubscriptions=n.maxSubscriptions??500,this.socket.on("connected",()=>this.onReconnect())}map2data(t,i){return this.storage.getMemory(t,i)}subscribeMap2(t,i){const n=`${t}/${i}`,s=this.active.get(n);if(s){s.refCount++,this.logger.log("subscribeMap2",t,i,`(active, refs: ${s.refCount})`);const l=this.getOrCreateKeyState(n,"active");return this.emitWarmStart(t,i),this.makeSubscription(t,i,n,l)}const o=this.waitlist.find(l=>l.key===n);if(o){o.refCount++,this.logger.log("subscribeMap2",t,i,`(pending, refs: ${o.refCount})`);const l=this.getOrCreateKeyState(n,"pending");return this.emitWarmStart(t,i),this.makeSubscription(t,i,n,l)}if(this.active.size<this.maxSubscriptions){this.activateKey(t,i,n,1),this.logger.log("subscribeMap2",t,i,"(new active)");const l=this.getOrCreateKeyState(n,"active");return this.emit("room:map2state",{room:t,shard:i,status:"active"}),this.emitWarmStart(t,i),this.makeSubscription(t,i,n,l)}this.waitlist.push({key:n,room:t,shard:i,refCount:1}),this.logger.log("subscribeMap2",t,i,"(new pending)");const a=this.getOrCreateKeyState(n,"pending");return this.emit("room:map2state",{room:t,shard:i,status:"pending"}),this.emitWarmStart(t,i),this.warnedAboutWaitlist||(this.logger.log(`subscription limit (${this.maxSubscriptions}) reached — `,"some rooms are on a waitlist and will be promoted as slots free up."),this.warnedAboutWaitlist=!0),this.makeSubscription(t,i,n,a)}activateKey(t,i,n,s){const o=i?`roomMap2:${i}/${t}`:`roomMap2:${t}`,a=this.socket.subscribe(o),l=this.storage.getMemory(t,i),c={room:t,shard:i,refCount:s,socketSub:a,listenerSub:void 0,lastHash:l?cn(l):null};c.listenerSub=this.socket.on(o,d=>{const u=d,p=cn(u);c.lastHash!==p&&(c.lastHash=p,this.storage.put(t,i,u),this.emit("room:map2update",{room:t,shard:i,data:u,source:"live"}))}),this.active.set(n,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 i=this.keyStates.get(t.key);i&&(i.status="active",i.statusHandlers.forEach(n=>n("active"))),this.emit("room:map2state",{room:t.room,shard:t.shard,status:"active"})}getOrCreateKeyState(t,i){let n=this.keyStates.get(t);return n||(n={status:i,statusHandlers:new Set},this.keyStates.set(t,n)),n}makeSubscription(t,i,n,s){let o=!1;return{status:()=>s.status,cachedData:()=>this.storage.getMemory(t,i),onStatusChange:a=>(s.statusHandlers.add(a),{dispose:()=>{s.statusHandlers.delete(a)}}),dispose:()=>{o||(o=!0,this.disposeSubscription(t,i,n))}}}disposeSubscription(t,i,n){const s=this.waitlist.findIndex(a=>a.key===n);if(s>=0){const a=this.waitlist[s];a.refCount--,this.logger.log("unsubscribeMap2",t,i,`(pending, refs: ${a.refCount})`),a.refCount<=0&&(this.waitlist.splice(s,1),this.keyStates.delete(n),this.logger.log("unsubscribeMap2",t,i,"(removed from waitlist)"));return}const o=this.active.get(n);o&&(o.refCount--,this.logger.log("unsubscribeMap2",t,i,`(active, refs: ${o.refCount})`),o.refCount<=0&&(o.socketSub.dispose(),o.listenerSub.dispose(),this.active.delete(n),this.keyStates.delete(n),this.logger.log("unsubscribeMap2",t,i,"(deactivated, promoting next)"),this.promoteNext()))}emitWarmStart(t,i){const n=`${t}/${i}`,s=this.storage.getMemory(t,i);s?queueMicrotask(()=>{this.isSubscribed(n)&&this.emit("room:map2update",{room:t,shard:i,data:s,source:"cache"})}):this.storage.get(t,i).then(o=>{o&&this.isSubscribed(n)&&this.emit("room:map2update",{room:t,shard:i,data:o,source:"cache"})})}onReconnect(){this.logger.log("onReconnect —",this.active.size,"active,",this.waitlist.length,"pending");for(const t of this.active.values())t.lastHash=null,this.emit("room:map2state",{room:t.room,shard:t.shard,status:"active"});for(const t of this.waitlist)this.emit("room:map2state",{room:t.room,shard:t.shard,status:"pending"})}isSubscribed(t){return this.active.has(t)||this.waitlist.some(i=>i.key===t)}}class Xo extends Yt{constructor(t,i=100,n=500,s){super(s);_(this,"http");_(this,"debounceMs");_(this,"minIntervalMs");_(this,"pending",new Map);_(this,"timer",null);_(this,"lastFlushTime",0);this.http=t,this.debounceMs=i,this.minIntervalMs=n}request(t,i,n){if(t.length===0)return;const s=JSON.stringify([i,n??"shard0"]);let o=this.pending.get(s);o||(o={rooms:new Set,statName:i,shard:n??"shard0"},this.pending.set(s,o));for(const 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[,i]of t){const n=[...i.rooms];try{const s=await this.http.request("POST","/api/game/map-stats",{rooms:n,statName:i.statName,shard:i.shard}),o=s.users??{};for(const[a,l]of Object.entries(s.stats)){const c=this.buildData(l,o);this.emit("mapStats:room",{room:a,shard:i.shard==="shard0"?null:i.shard,stat:c})}for(const a of n)s.stats[a]||this.emit("mapStats:room",{room:a,shard:i.shard==="shard0"?null:i.shard,stat:{}})}catch(s){this.logger.log("mapStats fetch failed:",s)}}}buildData(t,i){var a,l,c;let n,s;for(let d=0;d<3;d++){const u=`minerals${d}`,p=t[u];if(p){n=p.type,s=p.density;break}}const o=(a=t.own)==null?void 0:a.user;return{own:t.own,mineral:n,density:s,username:o?(l=i[o])==null?void 0:l.username:void 0,safeMode:t.safeMode,badge:o?(c=i[o])==null?void 0:c.badge:void 0,status:t.status}}}class Yo extends Yt{constructor(t=50,i){super(i);_(this,"_history",[]);_(this,"_index",-1);_(this,"maxHistory");this.maxHistory=t}navigateTo(t,i){this._history=this._history.slice(0,this._index+1),this._history.push({room:t,shard:i}),this._history.length>this.maxHistory?this._history.shift():this._index++,this.emit("navigation:change",this.current())}back(){return this.canBack()?(this._index--,this.emit("navigation:change",this.current()),!0):!1}forward(){return this.canForward()?(this._index++,this.emit("navigation:change",this.current()),!0):!1}canBack(){return this._index>0}canForward(){return this._index<this._history.length-1}current(){var t,i;return{room:((t=this._history[this._index])==null?void 0:t.room)??null,shard:((i=this._history[this._index])==null?void 0:i.shard)??null,index:this._index,history:[...this._history]}}}class qo{constructor(e){_(this,"http");_(this,"socket");_(this,"stores");_(this,"cache");_(this,"logger");_(this,"tokenRefreshIntervalMs");_(this,"tokenSyncSubs",[]);_(this,"tokenRefreshTimer",null);_(this,"lastHttpActivity",0);_(this,"refreshInFlight",!1);var n,s,o;let t;try{t=new URL(e.url).hostname}catch{throw new TypeError(`ScreepsClient: invalid url "${e.url}"`)}this.logger=Ke.create(e.debug),this.logger.log(`[screeps:client] init ${e.url}`),this.cache=new zo(t,e.storage??null),this.http=new No({url:e.url,auth:e.auth,logger:this.logger.child("http"),serverPassword:e.serverPassword}),this.socket=new Do({url:e.url,WebSocket:e.WebSocket,logger:this.logger.child("socket")});const i=new Wo({adapter:e.storage??null,namespace:t,maxEntries:((n=e.map2)==null?void 0:n.maxCacheEntries)??1e4});this.stores={room:new Bo(this.http,this.socket,this.cache,this.logger.child("room")),user:new Fo(this.http,this.socket,this.cache,this.logger.child("user")),server:new Ho(this.http,this.socket,this.cache,this.logger.child("server")),map:new Uo(this.socket,i,{maxSubscriptions:((s=e.map2)==null?void 0:s.maxSubscriptions)??500},this.logger.child("map")),mapStats:new Xo(this.http,100,500,this.logger.child("mapStats")),navigation:new Yo(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 Vo{constructor(e){_(this,"token");this.token=e.token}async authenticate(e){return this.token}}class jo{constructor(e){_(this,"email");_(this,"password");this.email=e.email,this.password=e.password}async authenticate(e){return(await e.auth.signin(this.email,this.password)).token}}class Zo{async authenticate(e){return"guest"}}const Ko=1,Ue="data";class Jo{constructor(e){_(this,"namespace");_(this,"db",null);_(this,"openPromise",null);this.namespace=e}get dbName(){return`screeps:${this.namespace}`}open(){return this.db?Promise.resolve(this.db):this.openPromise?this.openPromise:(this.openPromise=new Promise((e,t)=>{const i=indexedDB.open(this.dbName,Ko);i.onupgradeneeded=()=>{i.result.createObjectStore(Ue)},i.onsuccess=()=>{this.db=i.result,this.openPromise=null,e(i.result)},i.onerror=()=>t(i.error),i.onblocked=()=>t(new Error(`IndexedDB open blocked: ${this.dbName}`))}),this.openPromise)}async get(e){const t=await this.open();return new Promise((i,n)=>{const o=t.transaction(Ue,"readonly").objectStore(Ue).get(e);o.onsuccess=()=>i(o.result??null),o.onerror=()=>n(o.error)})}async set(e,t){const i=await this.open();return new Promise((n,s)=>{const a=i.transaction(Ue,"readwrite").objectStore(Ue).put(t,e);a.onsuccess=()=>n(),a.onerror=()=>s(a.error)})}async delete(e){const t=await this.open();return new Promise((i,n)=>{const o=t.transaction(Ue,"readwrite").objectStore(Ue).delete(e);o.onsuccess=()=>i(),o.onerror=()=>n(o.error)})}async clear(){const e=await this.open();return new Promise((t,i)=>{const s=e.transaction(Ue,"readwrite").objectStore(Ue).clear();s.onsuccess=()=>t(),s.onerror=()=>i(s.error)})}}class ji{constructor(){_(this,"subs",[])}add(e){this.subs.push(e)}dispose(){for(const e of this.subs)e.dispose();this.subs.length=0}}const Qo=5*6e4;function Qn(r,e){try{return`screeps:${r}:${new URL(e).hostname}`}catch{return`screeps:${r}:${e}`}}function es(r){if(typeof sessionStorage>"u")return null;try{const e=sessionStorage.getItem(r);if(!e)return null;const t=JSON.parse(e);return Date.now()>t.expires?(sessionStorage.removeItem(r),null):t.data}catch{return null}}function ts(r,e){if(!(typeof sessionStorage>"u"))try{sessionStorage.setItem(r,JSON.stringify({data:e,expires:Date.now()+Qo}))}catch{}}function wr(r){return r.endsWith("/")?r:`${r}/`}async function ea(r){const e=Qn("version",r),t=es(e);if(t)return t;const i=await fetch(`${wr(r)}api/version`);if(!i.ok)throw new Error(`HTTP ${i.status}`);const n=await i.json();return ts(e,n),n}async function ta(r){const e=Qn("authmod",r),t=es(e);if(t)return t;const i=await fetch(`${wr(r)}api/authmod`);if(!i.ok)return null;const n=await i.json();return n.ok?(ts(e,n),n):null}async function ra(r,e){const t=new URLSearchParams({username:e}),i=await fetch(`${wr(r)}api/register/check-username?${t}`);if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}async function ia(r,e){const t=new URLSearchParams({email:e}),i=await fetch(`${wr(r)}api/register/check-email?${t}`);if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}async function na(r,e,t,i){const n=await fetch(`${wr(r)}api/register/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,email:t,password:i})});if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json()}function sa(r,e){return r.serverData.features.find(t=>t.name===e)}function rs(r){return sa(r,"screepsmod-auth")}const Jr={1:{calc(r=0){let e=0,t=0;r>0&&(e=r*30/100),r<0&&(t=-r*30/100),this.path1=`M 50 ${100-e} L ${t} 50 H ${100-t} Z`,this.path2=`M ${t} 50 H ${100-t} L 50 ${e} Z`}},2:{calc(r=0){let e=0,t=0;r>0&&(e=r*30/100),r<0&&(t=-r*30/100),this.path1=`M ${e} ${t} L 50 50 L ${100-e} ${t} V -1 H -1 Z`,this.path2=`M ${e} ${100-t} L 50 50 L ${100-e} ${100-t} V 101 H -1 Z`}},3:{calc(r=0){const e=Math.PI/4+Math.PI/4*(r+100)/200,t=-Math.PI/2,i=Math.PI/2+Math.PI/3,n=Math.PI/2-Math.PI/3;this.path1=`M 50 50 L ${50+100*Math.cos(t-e/2)} ${50+100*Math.sin(t-e/2)} L ${50+100*Math.cos(t+e/2)} ${50+100*Math.sin(t+e/2)} Z`,this.path2=`M 50 50 L ${50+100*Math.cos(i-e/2)} ${50+100*Math.sin(i-e/2)} L ${50+100*Math.cos(i+e/2)} ${50+100*Math.sin(i+e/2)} Z M 50 50 L ${50+100*Math.cos(n-e/2)} ${50+100*Math.sin(n-e/2)} L ${50+100*Math.cos(n+e/2)} ${50+100*Math.sin(n+e/2)}`},flip:"rotate180"},4:{calc(r=0){r+=100;const e=50-r*30/200,t=50+r*30/200;this.path1=`M 0 ${t} H 100 V 100 H 0 Z`,this.path2=r>0?`M 0 ${e} H 100 V ${t} H 0 Z`:""},flip:"rotate90"},5:{calc(r=0){r+=100;const e=50-r*10/200-10,t=50+r*10/200+10;this.path1=`M ${e} 0 H ${t} V 100 H ${e} Z`,this.path2=`M 0 ${e} H 100 V ${t} H 0 Z`},flip:"rotate45"},6:{calc(r=0){const e=5+(r+100)*8/200,t=50,i=20,n=80;this.path1=`M ${t-e} 0 H ${t+e} V 100 H ${t-e}`,this.path2=`M ${i-e} 0 H ${i+e} V 100 H ${i-e} Z M ${n-e} 0 H ${n+e} V 100 H ${n-e} Z`},flip:"rotate90"},7:{calc(r=0){const e=20+r*10/100;this.path1="M 0 50 Q 25 30 50 50 T 100 50 V 100 H 0 Z",this.path2=`M 0 ${50-e} Q 25 ${30-e} 50 ${50-e} T 100 ${50-e} V ${50+e} Q 75 ${70+e} 50 ${50+e} T 0 ${50+e} Z`},flip:"rotate90"},8:{calc(r=0){const e=r*20/100;this.path1="M 0 50 H 100 V 100 H 0 Z",this.path2=`M 0 50 Q 50 ${e} 100 50 Q 50 ${100-e} 0 50 Z`},flip:"rotate90"},9:{calc(r=0){let e=0,t=50;const i=70;r>0&&(e+=r/100*20),r<0&&(t+=r/100*30),this.path1=`M 50 ${e} L 100 ${e+i} V 101 H 0 V ${e+i} Z`,this.path2=`M 50 ${e+t} L 100 ${e+t+i} V 101 H 0 V ${e+t+i} Z`},flip:"rotate180"},10:{calc(r=0){let e=30,t=7;r>0&&(e+=r*50/100),r<0&&(t-=r*20/100),this.path1=`M ${50+t+e} ${50-e} A ${e} ${e} 0 0 0 ${50+t+e} ${50+e} H 101 V ${50-e} Z`,this.path2=`M ${50-t-e} ${50-e} A ${e} ${e} 0 0 1 ${50-t-e} ${50+e} H -1 V ${50-e} Z`},flip:"rotate90"},11:{calc(r=0){let e=30,t=30;const i=50-50*Math.cos(Math.PI/4),n=50-50*Math.sin(Math.PI/4);r>0&&(e+=r*25/100,t+=r*25/100),r<0&&(t-=r*50/100),this.path1=`M ${i} ${n} Q ${e} 50 ${i} ${100-n} H 0 V ${n} Z M ${100-i} ${n} Q ${100-e} 50 ${100-i} ${100-n} H 100 V ${n} Z`,this.path2=`M ${i} ${n} Q 50 ${t} ${100-i} ${n} V 0 H ${i} Z M ${i} ${100-n} Q 50 ${100-t} ${100-i} ${100-n} V 100 H ${i} Z`},flip:"rotate90"},12:{calc(r=0){let e=30,t=35;r>0&&(e+=r*30/100),r<0&&(t+=r*15/100),this.path1=`M 0 ${e} H 100 V 100 H 0 Z`,this.path2=`M 0 ${e} H ${t} V 100 H 0 Z M 100 ${e} H ${100-t} V 100 H 100 Z`},flip:"rotate180"},13:{calc(r=0){let e=30,t=0;r>0&&(e+=r*50/100),r<0&&(t-=r*20/100),this.path1="M 0 0 H 50 V 100 H 0 Z",this.path2=`M ${50-e} ${50-t-e} A ${e} ${e} 0 0 0 ${50+e} ${50-e-t} V 0 H ${50-e} Z`},flip:"rotate180"},14:{calc(r=0){let e=Math.PI/4;const t=0;e+=r*Math.PI/4/100,this.path1=`M 50 0 Q 50 ${50+t} ${50+50*Math.cos(e)} ${50+50*Math.sin(e)} H 100 V 0 H 50 Z`,this.path2=`M 50 0 Q 50 ${50+t} ${50-50*Math.cos(e)} ${50+50*Math.sin(e)} H 0 V 0 H 50 Z`},flip:"rotate180"},15:{calc(r=0){const e=13+r*6/100,t=80,i=45,n=10;this.path1=`M ${50-t-e} ${100+n} A ${t+e} ${t+e} 0 0 1 ${50+t+e} ${100+n} H ${50+t-e} A ${t-e} ${t-e} 0 1 0 ${50-t+e} ${100+n}`,this.path2=`M ${50-i-e} ${100+n} A ${i+e} ${i+e} 0 0 1 ${50+i+e} ${100+n} H ${50+i-e} A ${i-e} ${i-e} 0 1 0 ${50-i+e} ${100+n}`},flip:"rotate180"},16:{calc(r=0){let e=30*Math.PI/180,t=25;r>0&&(e+=30*Math.PI/180*r/100),r<0&&(t+=r*25/100),this.path1="";for(let i=0;i<3;i++){const n=i*Math.PI*2/3+e/2-Math.PI/2,s=i*Math.PI*2/3-e/2-Math.PI/2;this.path1+=`M ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+100*Math.cos(s)} ${50+100*Math.sin(s)} L ${50+t*Math.cos(s)} ${50+t*Math.sin(s)} A ${t} ${t} 0 0 1 ${50+t*Math.cos(n)} ${50+t*Math.sin(n)} Z`}this.path2="";for(let i=0;i<3;i++){const n=i*Math.PI*2/3+e/2+Math.PI/2,s=i*Math.PI*2/3-e/2+Math.PI/2;this.path2+=`M ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+100*Math.cos(s)} ${50+100*Math.sin(s)} L ${50+t*Math.cos(s)} ${50+t*Math.sin(s)} A ${t} ${t} 0 0 1 ${50+t*Math.cos(n)} ${50+t*Math.sin(n)} Z`}}},17:{calc(r=0){let e=35,t=45;r>0&&(e+=r*20/100),r<0&&(t-=r*30/100),this.path1=`M 50 45 L ${50-e} ${t+45} H ${50+e} Z`,this.path2=`M 50 0 L ${50-e} ${t} H ${50+e} Z`}},18:{calc(r=0){let e=90*Math.PI/180,t=10;r>0&&(e-=60/180*Math.PI*r/100),r<0&&(t-=r*15/100),this.path1="",this.path2="";for(let i=0;i<3;i++){const n=Math.PI*2/3*i+e/2-Math.PI/2,s=Math.PI*2/3*i-e/2-Math.PI/2,o=`M ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+100*Math.cos(s)} ${50+100*Math.sin(s)} L ${50+t*Math.cos((n+s)/2)} ${50+t*Math.sin((n+s)/2)} Z`;i?this.path2+=o:this.path1+=o}},flip:"rotate180"},19:{calc(r=0){let e=20,t=60;t+=r*20/100,e+=r*20/100,this.path1=`M 50 -10 L ${50-t} 100 H ${50+t} Z`,this.path2="",e>0&&(this.path2=`M 50 0 L ${50-e} 100 H ${50+e} Z`)},flip:"rotate180"},20:{calc(r=0){let e=10,t=20;r>0&&(e+=r*20/100),r<0&&(t+=r*40/100),this.path1=`M 0 ${50-t} H ${50-e} V 100 H 0 Z`,this.path2=`M ${50+e} 0 V ${50+t} H 100 V 0 Z`},flip:"rotate90"},21:{calc(r=0){let e=40,t=50;r>0&&(e-=r*20/100),r<0&&(t+=r*20/100),this.path1=`M 50 ${t} Q ${50+e} 0 50 0 T 50 ${t} Z M 50 ${100-t} Q ${50+e} 100 50 100 T 50 ${100-t} Z`,this.path2=`M ${t} 50 Q 0 ${50+e} 0 50 T ${t} 50 Z M ${100-t} 50 Q 100 ${50+e} 100 50 T ${100-t} 50 Z`},flip:"rotate45"},22:{calc(r=0){let e=20;e+=r*10/100,this.path1=`M ${50-e} ${50-e} H ${50+e} V ${50+e} H ${50-e} Z`,this.path2="";for(let t=-4;t<4;t++)for(let i=-4;i<4;i++){const n=(t+i)%2;this.path2+=`M ${50-e-e*2*t} ${50-e-e*2*(i+n)} h ${-e*2} v ${e*2} h ${e*2} Z`}},flip:"rotate45"},23:{calc(r=0){let e=17,t=25;r>0&&(e+=r*35/100),r<0&&(t-=r*23/100),this.path1="";for(let i=-4;i<=4;i++)this.path1+=`M ${50-e*i*2} ${50-t} l ${-e} ${-t} l ${-e} ${t} l ${e} ${t} Z`;this.path2="";for(let i=-4;i<=4;i++)this.path2+=`M ${50-e*i*2} ${50+t} l ${-e} ${-t} l ${-e} ${t} l ${e} ${t} Z`},flip:"rotate90"},24:{calc(r=0){let e=50,t=45;r>0&&(e+=r*60/100),r<0&&(t+=r*30/100),this.path1=`M 0 ${t} L 50 70 L 100 ${t} V 100 H 0 Z`,this.path2=`M 50 0 L ${50+e} 100 H 100 V ${t} L 50 70 L 0 ${t} V 100 H ${50-e} Z`},flip:"rotate180"}};function Qr(r){const e=Math.round(r).toString(16);return e.length<2?"0"+e:e}function et(r,e,t){const i=(1-Math.abs(2*t-1))*e,n=r/60,s=i*(1-Math.abs(n%2-1));let o=0,a=0,l=0;!Number.isNaN(r)&&r!==null&&r!==void 0&&(n>=0&&n<1?(o=i,a=s,l=0):n>=1&&n<2?(o=s,a=i,l=0):n>=2&&n<3?(o=0,a=i,l=s):n>=3&&n<4?(o=0,a=s,l=i):n>=4&&n<5?(o=s,a=0,l=i):n>=5&&n<6&&(o=i,a=0,l=s));const c=t-i/2,d=(o+c)*255,u=(a+c)*255,p=(l+c)*255;return"#"+Qr(d)+Qr(u)+Qr(p)}function oa(){const r=[];let e=0;r.push({index:e++,rgb:et(0,0,.8)});for(let t=0;t<19;t++)r.push({index:e++,rgb:et(t*360/19,.6,.8)});r.push({index:e++,rgb:et(0,0,.5)});for(let t=0;t<19;t++)r.push({index:e++,rgb:et(t*360/19,.7,.5)});r.push({index:e++,rgb:et(0,0,.3)});for(let t=0;t<19;t++)r.push({index:e++,rgb:et(t*360/19,.4,.3)});r.push({index:e++,rgb:et(0,0,.1)});for(let t=0;t<19;t++)r.push({index:e++,rgb:et(t*360/19,.5,.1)});return r}const cr=oa();function ei(r){if(typeof r=="string")return r;if(typeof r=="number"){const e=cr[r];return e?e.rgb:"#000000"}return"#000000"}function qr(r){const e=ei(r.color1),t=ei(r.color2),i=ei(r.color3),n=r.param??0;if(typeof r.type=="number"){const d=Jr[r.type];d&&d.calc(n)}let s=0;if(r.flip&&typeof r.type=="number"){const d=Jr[r.type];(d==null?void 0:d.flip)==="rotate180"&&(s=180),(d==null?void 0:d.flip)==="rotate90"&&(s=90),(d==null?void 0:d.flip)==="rotate45"&&(s=45)}let o,a;if(typeof r.type=="number"){const d=Jr[r.type];o=(d==null?void 0:d.path1)??"",a=(d==null?void 0:d.path2)??""}else o=r.type.path1,a=r.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(${s} 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="${i}" 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[aa,dn]=G([]);let la=0;function ge(r,e="success",t=4e3){const i=la++;dn(n=>[...n,{id:i,message:r,type:e,duration:t}]),setTimeout(()=>{dn(n=>n.filter(s=>s.id!==i))},t)}const ca=!0;function Zi(){return!0}function da(){return ca}function Vr(){return window.location.origin}function ha(){return"0.3.3"}function ua(){return typeof window>"u"?null:window.__SCREEPS_CLIENT_EMBEDDED__??null}function jr(){return"/".replace(/\/$/,"")}function xt(r){const e=`[${r}]`;return{log:()=>{},warn:()=>{},error:(...t)=>console.error(e,...t)}}const pe={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",terrainEffects:"screeps:settings:terrainEffects"},Pe={url:"screeps:url",token:"screeps:token",serverPassword:"screeps:serverPassword"};function ti(r){return localStorage.getItem(r)}function hn(r,e){localStorage.setItem(r,e)}function fa(r){localStorage.removeItem(r)}function or(r,e){const t=localStorage.getItem(r);if(t===null)return e;const i=Number(t);return Number.isFinite(i)&&i!==0?i:e}function Or(r,e){localStorage.setItem(r,String(e))}function ri(r){return sessionStorage.getItem(r)}function $r(r,e){sessionStorage.setItem(r,e)}function dr(r){sessionStorage.removeItem(r)}async function pa(){if(localStorage.clear(),indexedDB.databases){const r=await indexedDB.databases();await Promise.all(r.map(e=>e.name?new Promise(t=>{const i=indexedDB.deleteDatabase(e.name);i.onsuccess=()=>t(),i.onerror=()=>t(),i.onblocked=()=>t()}):Promise.resolve()))}if("caches"in window){const r=await caches.keys();await Promise.all(r.map(e=>caches.delete(e)))}}const{log:ze}=xt("client"),[ae,Lr]=G(null),[gt,Rt]=G("idle"),[un,Ar]=G(null),[Oe,wi]=G(null),[If,bi]=G(null),[Wt,xi]=G(null),[_i,is]=G(null),[qe,ns]=G(!1),[ii,ss]=G(null),[ga,os]=G({}),[wt,as]=G(null);let Ir=-1,$i=-1;const Pt=[],ma=5;function ya(r){if(r===void 0)return;const e=Date.now();if(Ir>=0&&r>Ir){const t=e-$i;if(t>0){Pt.push(t),Pt.length>ma&&Pt.shift();const i=Pt.reduce((n,s)=>n+s,0)/Pt.length;is(Math.round(i))}}Ir=r,$i=e}function va(){Ir=-1,$i=-1,Pt.length=0,is(null)}async function ut(r){Zi()&&(r={...r,url:Vr()}),ze(`connecting to ${r.url} (auth: ${r.auth})`),Rt("connecting"),Ar(null);try{let e;if(r.auth==="guest")e=new Zo,ns(!0);else if(r.auth==="password"){if(!r.email||!r.password)throw new Error("Email and password are required");e=new jo({email:r.email,password:r.password})}else{if(!r.token)throw new Error("Token is required");e=new Vo({token:r.token})}const t=new qo({url:r.url,auth:e,storage:r.storage??new Jo("screeps-client"),debug:!1,serverPassword:r.serverPassword});t.http.on("http:tokenRefresh",({token:i})=>{ze("token refreshed"),$r(Pe.token,i)}),t.http.on("http:error",({method:i,path:n,error:s})=>{ze("http error:",i,n,s.message),ge(`Request failed: ${i} ${n} — ${s.message}`,"error",6e3)}),t.stores.server.on("server:disconnected",i=>{ze(`server disconnected (willReconnect: ${i.willReconnect})`),i.willReconnect||(Rt("idle"),Lr(null),wi(null),bi(null))}),t.stores.server.on("server:error",i=>{ze("server error:",i.error.message),Ar(i.error.message),Rt("error")}),t.stores.user.on("user:me",i=>{ze(`user: ${i.username} (id: ${i._id})`),wi(i)}),t.stores.server.on("server:version",i=>{ze(`server version: ${i.package??"unknown"}`),bi(i)}),t.stores.user.on("user:stream",i=>{if(i&&typeof i=="object"&&"flags"in i){const n=i.flags;n&&typeof n=="object"&&os(n)}}),t.stores.user.on("user:worldStatus",({status:i})=>{ze(`world status: ${i}`),as(i)}),await t.connect(),t.stores.user.subscribeUserStream(),Lr(t),Rt("connected"),ze(`connected to ${r.url}`),t.stores.server.worldInfo().then(i=>{ss(i),ze(`world: ${i.width}x${i.height} x[${i.minX},${i.maxX}] y[${i.minY},${i.maxY}]`)}).catch(()=>{}),$r(Pe.url,r.url),t.http.token&&$r(Pe.token,t.http.token),r.serverPassword?$r(Pe.serverPassword,r.serverPassword):dr(Pe.serverPassword)}catch(e){const t=e instanceof Error?e.message:String(e);throw Ar(t),Rt("error"),Lr(null),e}}async function wa(){const r=Zi()?Vr():ri(Pe.url),e=ri(Pe.token);if(!r||!e)return;const t=ri(Pe.serverPassword)??void 0;try{e==="guest"?await ut({url:r,auth:"guest",storage:null,serverPassword:t}):await ut({url:r,auth:"token",token:e,serverPassword:t})}catch{dr(Pe.token)}}function ba(){const r=ae();r&&r.disconnect(),Lr(null),Rt("idle"),Ar(null),wi(null),bi(null),xi(null),ns(!1),ss(null),os({}),as(null),va(),dr(Pe.token),dr(Pe.url),dr(Pe.serverPassword)}/**
|
|
4
|
-
* @license lucide-solid v0.513.0 - ISC
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the ISC license.
|
|
7
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
8
|
-
*/var xa={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"},Ct=xa,_a=R("<svg>"),fn=r=>r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),$a=r=>r.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,i)=>i?i.toUpperCase():t.toLowerCase()),Sa=r=>{const e=$a(r);return e.charAt(0).toUpperCase()+e.slice(1)},Ca=(...r)=>r.filter((e,t,i)=>!!e&&e.trim()!==""&&i.indexOf(e)===t).join(" ").trim(),ka=r=>{const[e,t]=Xn(r,["color","size","strokeWidth","children","class","name","iconNode","absoluteStrokeWidth"]);return(()=>{var i=_a();return Zn(i,ve(Ct,{get width(){return e.size??Ct.width},get height(){return e.size??Ct.height},get stroke(){return e.color??Ct.stroke},get"stroke-width"(){return ee(()=>!!e.absoluteStrokeWidth)()?Number(e.strokeWidth??Ct["stroke-width"])*24/Number(e.size):Number(e.strokeWidth??Ct["stroke-width"])},get class(){return Ca("lucide","lucide-icon",...e.name!=null?[`lucide-${fn(Sa(e.name))}`,`lucide-${fn(e.name)}`]:[],e.class!=null?e.class:"")}},t),!0,!0),v(i,C(ye,{get each(){return e.iconNode},children:([n,s])=>C(Kn,ve({component:n},s))})),i})()},_e=ka,Ta=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742",key:"178tsu"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05",key:"1hqiys"}]],Ma=r=>C(_e,ve(r,{iconNode:Ta,name:"bell-off"})),Ea=Ma,Ra=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],Pa=r=>C(_e,ve(r,{iconNode:Ra,name:"bell"})),Oa=Pa,La=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],Aa=r=>C(_e,ve(r,{iconNode:La,name:"check"})),Ia=Aa,Na=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Ga=r=>C(_e,ve(r,{iconNode:Na,name:"chevron-right"})),Da=Ga,za=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Ba=r=>C(_e,ve(r,{iconNode:za,name:"chevron-left"})),Fa=Ba,Ha=[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]],Wa=r=>C(_e,ve(r,{iconNode:Ha,name:"code-xml"})),Ua=Wa,Xa=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],Ya=r=>C(_e,ve(r,{iconNode:Xa,name:"eye"})),qa=Ya,Va=[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]],ja=r=>C(_e,ve(r,{iconNode:Va,name:"flag"})),ls=ja,Za=[["path",{d:"m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9",key:"eefl8a"}],["path",{d:"m18 15 4-4",key:"16gjal"}],["path",{d:"m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172V7l-2.26-2.26a6 6 0 0 0-4.202-1.756L9 2.96l.92.82A6.18 6.18 0 0 1 12 8.4V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5",key:"b7pghm"}]],Ka=r=>C(_e,ve(r,{iconNode:Za,name:"hammer"})),Ja=Ka,Qa=[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]],el=r=>C(_e,ve(r,{iconNode:Qa,name:"layout-grid"})),tl=el,rl=[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]],il=r=>C(_e,ve(r,{iconNode:rl,name:"log-out"})),nl=il,sl=[["path",{d:"M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z",key:"169xi5"}],["path",{d:"M15 5.764v15",key:"1pn4in"}],["path",{d:"M9 3.236v15",key:"1uimfh"}]],ol=r=>C(_e,ve(r,{iconNode:sl,name:"map"})),al=ol,ll=[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m19 9 3 3-3 3",key:"1mg7y2"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m5 9-3 3 3 3",key:"j64kie"}],["path",{d:"m9 5 3-3 3 3",key:"l8vdw6"}]],cl=r=>C(_e,ve(r,{iconNode:ll,name:"move"})),dl=cl,hl=[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],ul=r=>C(_e,ve(r,{iconNode:hl,name:"settings"})),fl=ul,pl=[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]],gl=r=>C(_e,ve(r,{iconNode:pl,name:"trash-2"})),ni=gl,ml=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],yl=r=>C(_e,ve(r,{iconNode:ml,name:"x"})),Zr=yl,vl=R("<span style=font-size:11px;display:inline-flex;align-items:center;gap:3px>"),wl=R('<div style="color:#3fb950;font-size:14px;text-align:center;padding:8px 0">Account created! Logging you in…'),bl=R("<label style=display:flex;flex-direction:column;gap:4px><div style=display:flex;align-items:baseline;gap:8px><span style=font-size:12px;color:#8b949e>Username</span></div><input type=text name=username autocomplete=username>"),xl=R("<label style=display:flex;flex-direction:column;gap:4px><div style=display:flex;align-items:baseline;gap:8px><span style=font-size:12px;color:#8b949e>Email</span></div><input type=email name=email autocomplete=email>"),_l=R("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Password</span><input type=password name=new-password autocomplete=new-password>"),$l=R("<span style=font-size:11px;color:#f85149>Passwords don't match"),Sl=R("<label style=display:flex;flex-direction:column;gap:4px><div style=display:flex;align-items:baseline;gap:8px><span style=font-size:12px;color:#8b949e>Confirm Password</span></div><input type=password name=confirm-password autocomplete=new-password>"),Cl=R("<button type=submit style=padding:10px;border-radius:6px;border:none;background:#238636;color:#fff;font-weight:600>"),kl=R('<button type=button style="padding:8px;border-radius:6px;border:1px solid #30363d;background:transparent;color:#8b949e;font-size:12px;cursor:pointer">Back to Login'),Tl=R("<form style=display:flex;flex-direction:column;gap:16px><h2 style=margin:0;font-size:20px>Create Account"),cs=R("<div style=color:#f85149;font-size:13px>"),Ml=R('<div style="width:360px;padding:16px 20px;border-radius:8px;background:#161b22;border:1px solid #30363d;color:#c9d1d9;font-size:13px;line-height:1.6">'),El=R("<button type=button style=background:none;border:none;color:#58a6ff;font-size:12px;cursor:pointer;padding:0>Create account"),Rl=R('<div style=display:flex;gap:8px><button type=button style="flex:1;padding:8px;border-radius:6px;border:1px solid #30363d;color:#fff;cursor:pointer">Password</button><button type=button style="flex:1;padding:8px;border-radius:6px;border:1px solid #30363d;color:#fff;cursor:pointer">Token'),Pl=R("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Server URL</span><input type=url name=url autocomplete=url inputmode=url>"),Ol=R("<div style=color:#8b949e;font-size:12px;margin-top:-8px>"),Ll=R("<div style=display:flex;align-items:center;gap:8px;color:#484f58;font-size:12px><div style=flex:1;height:1px;background:#30363d></div>or<div style=flex:1;height:1px;background:#30363d>"),Al=R("<button type=button style=padding:10px;border-radius:6px;border:none;background:#1b2838;color:#c7d5e0;font-weight:600>Login with Steam"),Il=R('<button type=button style="padding:8px;border-radius:6px;border:1px solid #30363d;background:transparent;color:#8b949e;font-size:12px">Connect as Guest (read-only)'),Nl=R('<form style=display:flex;flex-direction:column;gap:16px><div style=display:flex;align-items:baseline;justify-content:space-between><h2 style=margin:0;font-size:20px>Connect to Screeps</h2></div><label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Server Password <span style=color:#484f58>(optional)</span></span><input type=password name=server-password autocomplete=off data-1p-ignore data-lpignore=true placeholder="Leave empty if not required"></label><button type=submit style=padding:10px;border-radius:6px;border:none;background:#238636;color:#fff;font-weight:600>'),Gl=R('<div style="width:360px;padding:12px 20px;border-radius:8px;background:#161b22;border:1px solid #30363d"><div style=font-size:11px;color:#484f58;margin-bottom:8px;text-transform:uppercase;letter-spacing:0.05em>Server Mods</div><div style=display:flex;flex-wrap:wrap;gap:6px>'),Dl=R('<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;gap:16px;width:100%;height:100%;overflow:auto;padding:24px 0;box-sizing:border-box"><div style="display:flex;flex-direction:column;gap:16px;width:360px;padding:32px;border-radius:8px;background:#161b22;border:1px solid #30363d">'),zl=R("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Email or Username</span><input type=text id=username name=username autocomplete=username>"),Bl=R("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Password</span><input type=password id=password name=password autocomplete=current-password>"),Fl=R("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Auth Token</span><input type=password name=token autocomplete=off>"),Hl=R('<span style="font-size:11px;padding:2px 8px;border-radius:12px;background:#21262d;border:1px solid #30363d;color:#8b949e;font-family:monospace">');const Ve={padding:"8px 12px","border-radius":"6px",border:"1px solid #30363d",background:"#0d1117",color:"#c9d1d9"};function Wl(r){const[e,t]=G(null),[i,n]=G(null),[s,o]=G(null);return he(()=>{const a=r();t(null),n(null),o(null);let l=!1;const c=setTimeout(async()=>{try{const d=await ea(a);if(l)return;if(t(d),o(null),rs(d)){const u=await ta(a);l||n(u)}}catch{l||(o("Could not reach server"),t(null))}},400);Ge(()=>{l=!0,clearTimeout(c)})}),{serverVersion:e,authModInfo:i,serverError:s}}function pn(r,e,t){const[i,n]=G("idle");return he(()=>{const s=e();if(!s){n("idle");return}n("checking");let o=!1;const a=setTimeout(async()=>{try{const l=await t(r(),s);o||n(l.error?"taken":"available")}catch{o||n("error")}},500);Ge(()=>{o=!0,clearTimeout(a)})}),i}function gn(r){const e={idle:null,checking:{children:"Checking…",color:"#8b949e"},available:{children:[C(Ia,{size:12})," Available"],color:"#3fb950"},taken:{children:[C(Zr,{size:12})," Already taken"],color:"#f85149"},error:{children:"Could not verify",color:"#d29922"}},t=()=>e[r.state];return C(H,{get when(){return t()},get children(){var i=vl();return v(i,()=>t().children),I(n=>B(i,"color",t().color)),i}})}function Ul(r){const[e,t]=G(""),[i,n]=G(""),[s,o]=G(""),[a,l]=G(""),[c,d]=G(!1),[u,p]=G(null),[f,h]=G(!1),g=pn(()=>r.url,e,ra),$=pn(()=>r.url,i,ia),y=()=>a()!==""&&s()!==a(),S=()=>!c()&&e()!==""&&i()!==""&&s().length>=4&&s()===a()&&g()!=="taken"&&g()!=="checking"&&$()!=="taken"&&$()!=="checking",E=async x=>{if(x.preventDefault(),!!S()){d(!0),p(null);try{const m=await na(r.url,e(),i(),s());if(m.error){p(m.error);return}h(!0),setTimeout(()=>r.onSuccess(i(),s()),1500)}catch(m){p(m instanceof Error?m.message:"Registration failed")}finally{d(!1)}}};return(()=>{var x=Tl();return x.firstChild,x.addEventListener("submit",E),v(x,C(H,{get when(){return f()},get children(){return wl()}}),null),v(x,C(H,{get when(){return!f()},get children(){return[(()=>{var m=bl(),M=m.firstChild;M.firstChild;var T=M.nextSibling;return v(M,C(gn,{get state(){return g()}}),null),T.$$input=b=>t(b.currentTarget.value),I(b=>{var k=Ve,A=c();return b.e=X(T,k,b.e),A!==b.t&&(T.disabled=b.t=A),b},{e:void 0,t:void 0}),I(()=>T.value=e()),m})(),(()=>{var m=xl(),M=m.firstChild;M.firstChild;var T=M.nextSibling;return v(M,C(gn,{get state(){return $()}}),null),T.$$input=b=>n(b.currentTarget.value),I(b=>{var k=Ve,A=c();return b.e=X(T,k,b.e),A!==b.t&&(T.disabled=b.t=A),b},{e:void 0,t:void 0}),I(()=>T.value=i()),m})(),(()=>{var m=_l(),M=m.firstChild,T=M.nextSibling;return T.$$input=b=>o(b.currentTarget.value),I(b=>{var k=Ve,A=c();return b.e=X(T,k,b.e),A!==b.t&&(T.disabled=b.t=A),b},{e:void 0,t:void 0}),I(()=>T.value=s()),m})(),(()=>{var m=Sl(),M=m.firstChild;M.firstChild;var T=M.nextSibling;return v(M,C(H,{get when(){return y()},get children(){return $l()}}),null),T.$$input=b=>l(b.currentTarget.value),I(b=>{var k={...Ve,border:y()?"1px solid #f85149":"1px solid #30363d"},A=c();return b.e=X(T,k,b.e),A!==b.t&&(T.disabled=b.t=A),b},{e:void 0,t:void 0}),I(()=>T.value=a()),m})(),ee(()=>ee(()=>!!u())()&&(()=>{var m=cs();return v(m,u),m})()),(()=>{var m=Cl();return v(m,()=>c()?"Creating account…":"Create Account"),I(M=>{var T=!S(),b=S()?"pointer":"not-allowed",k=S()?1:.5;return T!==M.e&&(m.disabled=M.e=T),b!==M.t&&B(m,"cursor",M.t=b),k!==M.a&&B(m,"opacity",M.a=k),M},{e:void 0,t:void 0,a:void 0}),m})(),(()=>{var m=kl();return m.$$click=()=>r.onCancel(),m})()]}}),null),x})()}function Xl(){const r=Zi(),e=da(),[t,i]=G("login"),[n,s]=G("password"),[o,a]=G(r?Vr():window.location.origin),[l,c]=G(""),[d,u]=G(""),[p,f]=G(""),[h,g]=G(""),{serverVersion:$,authModInfo:y,serverError:S}=Wl(o),E=()=>{var N,O;return((O=(N=$())==null?void 0:N.serverData)==null?void 0:O.welcomeText)??null},x=()=>{var N,O;return(((O=(N=$())==null?void 0:N.serverData)==null?void 0:O.features)??[]).filter(L=>L.name!=="auth"&&L.version!=null)},m=()=>{var O,L;const N=$();return N?((L=(O=rs(N))==null?void 0:O.authTypes)==null?void 0:L.includes("steam"))??!0:!0},M=()=>{var N,O,L;return((N=y())==null?void 0:N.allowRegistration)===!0||(((L=(O=$())==null?void 0:O.serverData)==null?void 0:L.features)??[]).some(z=>z.name==="official-like")},T=()=>{const N=o().replace(/\/$/,""),O=window.open(`${N}/api/auth/steam`,"screeps-steam-auth","width=800,height=600,left=200,top=100"),L=U=>{try{const Z=JSON.parse(U.data);Z.token&&(F(),ut({url:N,auth:"token",token:Z.token,serverPassword:h()||void 0,storage:null}))}catch{}},z=setInterval(()=>{O!=null&&O.closed&&F()},500),F=()=>{clearInterval(z),window.removeEventListener("message",L)};window.addEventListener("message",L),Ge(F)},b=async N=>{N.preventDefault(),await ut({url:o(),auth:n(),email:l()||void 0,password:d()||void 0,token:p()||void 0,serverPassword:h()||void 0,storage:null})},k=async N=>{N.preventDefault(),await ut({url:o(),auth:"guest",serverPassword:h()||void 0,storage:null})},A=async(N,O)=>{try{await ut({url:o(),auth:"password",email:N,password:O,serverPassword:h()||void 0,storage:null})}catch{i("login"),s("password"),c(N),u(O)}},P=()=>gt()==="connecting";return(()=>{var N=Dl(),O=N.firstChild;return v(N,C(H,{get when(){return E()},get children(){var L=Ml();return I(()=>L.innerHTML=E()),L}}),O),v(O,C(H,{get when(){return t()==="register"},get children(){return C(Ul,{get url(){return o()},get serverPassword(){return h()},onSuccess:A,onCancel:()=>i("login")})}}),null),v(O,C(H,{get when(){return t()==="login"},get children(){var L=Nl(),z=L.firstChild;z.firstChild;var F=z.nextSibling,U=F.firstChild,Z=U.firstChild;Z.nextSibling;var de=U.nextSibling,re=F.nextSibling;return L.addEventListener("submit",b),v(z,C(H,{get when(){return M()},get children(){var W=El();return W.$$click=()=>i("register"),W}}),null),v(L,C(H,{when:!r,get children(){var W=Rl(),Y=W.firstChild,ie=Y.nextSibling;return Y.$$click=()=>s("password"),ie.$$click=()=>s("token"),I(K=>{var oe=n()==="password"?"#238636":"transparent",De=n()==="token"?"#238636":"transparent";return oe!==K.e&&B(Y,"background",K.e=oe),De!==K.t&&B(ie,"background",K.t=De),K},{e:void 0,t:void 0}),W}}),F),v(L,C(H,{when:!r,get children(){return[(()=>{var W=Pl(),Y=W.firstChild,ie=Y.nextSibling;return ie.$$input=K=>a(K.currentTarget.value),I(K=>X(ie,Ve,K)),I(()=>ie.value=o()),W})(),C(H,{get when(){return S()},get children(){var W=Ol();return v(W,S),W}})]}}),F),v(L,(()=>{var W=ee(()=>n()==="password");return()=>W()?[(()=>{var Y=zl(),ie=Y.firstChild,K=ie.nextSibling;return K.$$input=oe=>c(oe.currentTarget.value),I(oe=>X(K,Ve,oe)),I(()=>K.value=l()),Y})(),(()=>{var Y=Bl(),ie=Y.firstChild,K=ie.nextSibling;return K.$$input=oe=>u(oe.currentTarget.value),I(oe=>X(K,Ve,oe)),I(()=>K.value=d()),Y})()]:(()=>{var Y=Fl(),ie=Y.firstChild,K=ie.nextSibling;return K.$$input=oe=>f(oe.currentTarget.value),I(oe=>X(K,Ve,oe)),I(()=>K.value=p()),Y})()})(),F),de.$$input=W=>g(W.currentTarget.value),v(L,(()=>{var W=ee(()=>!!un());return()=>W()&&(()=>{var Y=cs();return v(Y,un),Y})()})(),re),v(re,()=>P()?"Connecting…":"Connect"),v(L,C(H,{get when(){return m()},get children(){return[(()=>{var W=Ll(),Y=W.firstChild,ie=Y.nextSibling;return ie.nextSibling,W})(),(()=>{var W=Al();return W.$$click=T,I(Y=>{var ie=P(),K=P()?"not-allowed":"pointer",oe=P()?.6:1;return ie!==Y.e&&(W.disabled=Y.e=ie),K!==Y.t&&B(W,"cursor",Y.t=K),oe!==Y.a&&B(W,"opacity",Y.a=oe),Y},{e:void 0,t:void 0,a:void 0}),W})()]}}),null),v(L,C(H,{when:!r||e,get children(){var W=Il();return W.addEventListener("mouseleave",Y=>{Y.currentTarget.style.borderColor="#30363d"}),W.addEventListener("mouseenter",Y=>{P()||(Y.currentTarget.style.borderColor="#8b949e")}),W.$$click=k,I(Y=>{var ie=P(),K=P()?"not-allowed":"pointer",oe=P()?.6:1;return ie!==Y.e&&(W.disabled=Y.e=ie),K!==Y.t&&B(W,"cursor",Y.t=K),oe!==Y.a&&B(W,"opacity",Y.a=oe),Y},{e:void 0,t:void 0,a:void 0}),W}}),null),I(W=>{var Y=Ve,ie=P(),K=P()?"not-allowed":"pointer",oe=P()?.6:1;return W.e=X(de,Y,W.e),ie!==W.t&&(re.disabled=W.t=ie),K!==W.a&&B(re,"cursor",W.a=K),oe!==W.o&&B(re,"opacity",W.o=oe),W},{e:void 0,t:void 0,a:void 0,o:void 0}),I(()=>de.value=h()),L}}),null),v(N,C(H,{get when(){return x().length>0},get children(){var L=Gl(),z=L.firstChild,F=z.nextSibling;return v(F,C(ye,{get each(){return x()},children:U=>(()=>{var Z=Hl();return v(Z,()=>U.name,null),v(Z,(()=>{var de=ee(()=>!!U.version);return()=>de()?` ${U.version}`:""})(),null),Z})()})),L}}),null),N})()}ke(["input","click"]);var Yl=R('<span style="padding:2px 8px;border-radius:4px;background:#21262d;border:1px solid #30363d;color:#8b949e;font-size:11px;font-weight:600;letter-spacing:0.05em;text-transform:uppercase">Guest'),ql=R('<div style="display:flex;align-items:center;gap:12px;padding:8px 16px;border-bottom:1px solid #30363d;font-size:13px"><div style=display:flex;align-items:center;gap:6px><span style=width:8px;height:8px;border-radius:50%;display:inline-block></span><span style=color:#8b949e>');function Vl(){const r=()=>{switch(gt()){case"connected":return"#238636";case"connecting":return"#d29922";case"error":return"#f85149";default:return"#8b949e"}};return(()=>{var e=ql(),t=e.firstChild,i=t.firstChild,n=i.nextSibling;return v(n,(()=>{var s=ee(()=>gt()==="connected");return()=>s()?"Online":gt()})()),v(e,C(H,{get when(){return qe()},get children(){return Yl()}}),null),I(s=>B(i,"background-color",r())),e})()}class jl{constructor(e){_(this,"container");_(this,"hoverGraphics");_(this,"pendingGraphics");_(this,"selectionContainer");_(this,"selectionGraphics",new Map);_(this,"selectionTypes",new Map);_(this,"selectionVisuals",new Map);_(this,"ticker",null);_(this,"tickerCallback",null);this.container=new Ee,this.container.label="hoverHighlight",this.container.eventMode="none",this.hoverGraphics=new q,this.hoverGraphics.eventMode="none",this.container.addChild(this.hoverGraphics),this.pendingGraphics=new q,this.pendingGraphics.eventMode="none",this.container.addChild(this.pendingGraphics),this.selectionContainer=new Ee,this.selectionContainer.eventMode="none",this.container.addChild(this.selectionContainer),e&&(this.ticker=e,this.tickerCallback=()=>this.trackCreepRings(),e.add(this.tickerCallback))}setHoveredTile(e,t){if(this.hoverGraphics.clear(),e===null||t===null)return;const i=e*w,n=t*w;this.hoverGraphics.rect(i,n,w,w),this.hoverGraphics.stroke({width:1,color:16777215,alpha:.35}),this.hoverGraphics.rect(i,n,w,w),this.hoverGraphics.fill({color:16777215,alpha:.06})}setSelectedObjects(e){this.selectionContainer.removeChildren();for(const t of this.selectionGraphics.values())t.destroy();this.selectionGraphics.clear(),this.selectionTypes.clear(),this.selectionVisuals.clear();for(const{id:t,type:i,visual:n}of e){const s=new q;s.eventMode="none",this.selectionContainer.addChild(s),this.selectionGraphics.set(t,s),this.selectionTypes.set(t,i),this.selectionVisuals.set(t,n),i==="creep"?this.drawCreepRing(s,n.x,n.y):this.drawStructureBox(s,n.x,n.y)}}clearSelection(){this.selectionContainer.removeChildren();for(const e of this.selectionGraphics.values())e.destroy();this.selectionGraphics.clear(),this.selectionTypes.clear(),this.selectionVisuals.clear()}setPendingTile(e,t){if(this.pendingGraphics.clear(),e===null||t===null)return;const i=e*w,n=t*w,s=i+w/2,o=n+w/2,a=w*.35;this.pendingGraphics.moveTo(s-a,o),this.pendingGraphics.lineTo(s+a,o),this.pendingGraphics.moveTo(s,o-a),this.pendingGraphics.lineTo(s,o+a),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.9}),this.pendingGraphics.rect(i+1,n+1,w-2,w-2),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.6})}clearPendingTile(){this.pendingGraphics.clear()}drawCreepRing(e,t,i){e.clear();const n=t+w/2,s=i+w/2,o=w*.48;e.circle(n,s,o),e.stroke({width:1.5,color:16777215,alpha:.9})}drawStructureBox(e,t,i){e.clear();const n=1;e.rect(t+n,i+n,w-n*2,w-n*2),e.stroke({width:1.5,color:16777215,alpha:.9}),e.rect(t+n,i+n,w-n*2,w-n*2),e.fill({color:16777215,alpha:.04})}trackCreepRings(){for(const[e,t]of this.selectionGraphics){if(this.selectionTypes.get(e)!=="creep")continue;const i=this.selectionVisuals.get(e);i&&this.drawCreepRing(t,i.x,i.y)}}destroy(){this.ticker&&this.tickerCallback&&this.ticker.remove(this.tickerCallback),this.ticker=null,this.tickerCallback=null,this.clearSelection(),this.clearPendingTile(),this.pendingGraphics.destroy(),this.hoverGraphics.destroy(),this.container.destroy()}}const w=12,Me=50*w,ue=48,Zt=128;class Ki{constructor(e,t){_(this,"app");_(this,"world");_(this,"hoverLayer");_(this,"destroyed",!1);_(this,"canDrag",!1);_(this,"container");_(this,"resizeObserver",null);_(this,"bounceRaf",null);_(this,"wheelTimeout",null);_(this,"navOverlay");_(this,"lastMouseX",0);_(this,"lastMouseY",0);_(this,"onHoverTile",null);_(this,"onClickTile",null);this.app=e,this.container=t,this.world=new Ee,this.app.stage.addChild(this.world),this.hoverLayer=new jl(e.ticker),this.world.addChild(this.hoverLayer.container),this.navOverlay=new Ee,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 qn;return await t.init({background:"#0d1117",antialias:!0,resolution:window.devicePixelRatio||1,autoDensity:!0}),e.appendChild(t.canvas),new Ki(t,e)}getMinScale(){const t=this.container.clientWidth,i=this.container.clientHeight;return Math.min(t,i)/(Me+64)}clampView(e=!1){const t=this.world.scale.x,i=Me*t,n=this.container.clientWidth,s=this.container.clientHeight,o=e?Zt:0;if(i<=n){const a=n/2-i/2;e?this.world.x=Math.min(a+Zt,Math.max(a-Zt,this.world.x)):this.world.x=a}else{const a=n-i-ue-o,l=ue+o;this.world.x=Math.min(l,Math.max(a,this.world.x))}if(i<=s){const a=s/2-i/2;e?this.world.y=Math.min(a+Zt,Math.max(a-Zt,this.world.y)):this.world.y=a}else{const a=s-i-ue-o,l=ue+o;this.world.y=Math.min(l,Math.max(a,this.world.y))}this.canDrag=!0}getTargetPosition(){const e=this.world.scale.x,t=Me*e,i=this.container.clientWidth,n=this.container.clientHeight;let s=null,o=null;if(t<=i)s=i/2-t/2;else{const a=i-t-ue,l=ue;this.world.x<a?s=a:this.world.x>l&&(s=l)}if(t<=n)o=n/2-t/2;else{const a=n-t-ue,l=ue;this.world.y<a?o=a:this.world.y>l&&(o=l)}return s===null&&o===null?null:{x:s??this.world.x,y:o??this.world.y}}springBack(){const e=this.getTargetPosition(),t=this.getTargetScale();if(!e&&t===null)return;const i=this.world.x,n=this.world.y,s=this.world.scale.x,o=performance.now(),a=300,l=this.container.clientWidth/2,c=this.container.clientHeight/2,d=(l-i)/s,u=(c-n)/s,p=f=>{const h=f-o,g=Math.min(1,h/a),$=1-Math.pow(1-g,3);if(t!==null){const y=s+(t-s)*$;this.world.scale.set(y),this.world.x=l-d*y,this.world.y=c-u*y}e&&t===null&&(this.world.x=i+(e.x-i)*$,this.world.y=n+(e.y-n)*$),g<1?this.bounceRaf=requestAnimationFrame(p):(this.bounceRaf=null,this.clampView())};this.cancelBounce(),this.bounceRaf=requestAnimationFrame(p)}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 jt(0,0),i=new jt(0,0);const n=this.app.canvas,s=4;n.style.touchAction="none",n.style.userSelect="none";const o=new Map;let a=!1,l=0,c=0,d=0,u=0;n.addEventListener("contextmenu",f=>{f.preventDefault()}),n.addEventListener("pointerdown",f=>{if(this.cancelBounce(),this.cancelWheelTimeout(),o.set(f.pointerId,{x:f.clientX,y:f.clientY}),n.setPointerCapture(f.pointerId),o.size>=2){e=!1,a=!0;const h=[...o.values()],g=n.getBoundingClientRect(),$=(h[0].x+h[1].x)/2-g.left,y=(h[0].y+h[1].y)/2-g.top;d=Math.hypot(h[1].x-h[0].x,h[1].y-h[0].y),u=this.world.scale.x,l=($-this.world.x)/u,c=(y-this.world.y)/u}else a=!1,e=this.canDrag,t=new jt(f.clientX,f.clientY),i=new jt(f.clientX,f.clientY)}),n.addEventListener("pointermove",f=>{var y;const h=n.getBoundingClientRect();if(this.lastMouseX=f.clientX-h.left,this.lastMouseY=f.clientY-h.top,o.has(f.pointerId)&&o.set(f.pointerId,{x:f.clientX,y:f.clientY}),a&&o.size===2){const S=[...o.values()],E=(S[0].x+S[1].x)/2-h.left,x=(S[0].y+S[1].y)/2-h.top,m=Math.hypot(S[1].x-S[0].x,S[1].y-S[0].y),M=this.getMinScale(),T=5,b=.6;let k=u*(m/d);k<M&&(k=M+(k-M)*b),k>T&&(k=T+(k-T)*b),this.cancelBounce(),this.world.scale.set(k),this.world.x=E-l*k,this.world.y=x-c*k,this.clampView(!0);return}if(!a){const S=this.screenToTile(this.lastMouseX,this.lastMouseY);this.hoverLayer.setHoveredTile((S==null?void 0:S.tx)??null,(S==null?void 0:S.ty)??null),(y=this.onHoverTile)==null||y.call(this,(S==null?void 0:S.tx)??null,(S==null?void 0:S.ty)??null)}if(!e||!this.canDrag)return;const g=f.clientX-t.x,$=f.clientY-t.y;this.world.x+=g,this.world.y+=$,t=new jt(f.clientX,f.clientY),this.clampView(!0)});const p=f=>{var y;if(n.releasePointerCapture(f.pointerId),o.delete(f.pointerId),a){o.size<2&&(a=!1,e=!1,this.springBack());return}e=!1;const h=f.clientX-i.x,g=f.clientY-i.y;if(Math.sqrt(h*h+g*g)<s){const S=n.getBoundingClientRect(),E=f.clientX-S.left,x=f.clientY-S.top,m=this.screenToTile(E,x);m&&((y=this.onClickTile)==null||y.call(this,m.tx,m.ty,f.ctrlKey||f.metaKey))}this.springBack()};n.addEventListener("pointerup",p),n.addEventListener("pointercancel",p),n.addEventListener("pointerleave",()=>{var f;this.hoverLayer.setHoveredTile(null,null),(f=this.onHoverTile)==null||f.call(this,null,null)}),n.addEventListener("wheel",f=>{f.preventDefault();const h=f.deltaY>0?.9:1.1,g=this.getMinScale(),$=5;let y=this.world.scale.x*h;const S=.6;y<g&&(y=g+(y-g)*S),y>$&&(y=$+(y-$)*S);const E=n.getBoundingClientRect(),x=f.clientX-E.left,m=f.clientY-E.top;if(this.cancelBounce(),y<g){const M=this.container.clientWidth/2,T=this.container.clientHeight/2,b=(M-this.world.x)/this.world.scale.x,k=(T-this.world.y)/this.world.scale.y;this.world.scale.set(y),this.world.x=M-b*y,this.world.y=T-k*y}else{const M=(x-this.world.x)/this.world.scale.x,T=(m-this.world.y)/this.world.scale.y;this.world.scale.set(y),this.world.x=x-M*y,this.world.y=m-T*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 i=(e-this.world.x)/this.world.scale.x,n=(t-this.world.y)/this.world.scale.y,s=Math.floor(i/w),o=Math.floor(n/w);return s<0||s>=50||o<0||o>=50?null:{tx:s,ty:o}}centerView(){const e=this.container.clientWidth/2,t=this.container.clientHeight/2,i=this.world.scale.x;this.world.x=e-Me*i/2,this.world.y=t-Me*i/2}resetView(){this.cancelBounce(),this.cancelWheelTimeout(),this.world.scale.set(this.getMinScale()),this.centerView(),this.clampView()}setupResizeObserver(){const{width:e,height:t}=this.container.getBoundingClientRect();this.app.renderer.resize(e,t),this.resizeObserver=new ResizeObserver(i=>{const{width:n,height:s}=i[0].contentRect;this.app.renderer.resize(n,s),this.clampView()}),this.resizeObserver.observe(this.container)}setupNavigationZones(e){this.navOverlay.removeChildren();const t=(o,a,l,c,d,u)=>{if(!u)return;const p=new q;p.x=o,p.y=a,p.hitArea=new Vn(0,0,l,c),p.fill({color:16777215,alpha:.12}),p.poly(d),p.fill(),p.eventMode="static",p.cursor="pointer",p.alpha=1,p.on("pointerover",()=>{p.clear(),p.fill({color:16777215,alpha:.06}),p.rect(0,0,l,c),p.fill(),p.fill({color:16777215,alpha:.35}),p.poly(d),p.fill()}),p.on("pointerout",()=>{p.clear(),p.fill({color:16777215,alpha:.12}),p.poly(d),p.fill()}),p.on("pointerdown",u),this.navOverlay.addChild(p)},i=Me/2,n=Me/2,s=18;t(-ue,0,ue,Me,[18,n,ue-6,n-s,ue-6,n+s],e.west),t(Me,0,ue,Me,[ue-18,n,6,n-s,6,n+s],e.east),t(0,-ue,Me,ue,[i,18,i-s,ue-6,i+s,ue-6],e.north),t(0,Me,Me,ue,[i,ue-18,i-s,6,i+s,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,u=l.width*this.world.scale.x,p=l.height*this.world.scale.y;this.lastMouseX>=c&&this.lastMouseX<=c+u&&this.lastMouseY>=d&&this.lastMouseY<=d+p&&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 ds=856343,Zl=1448738,Kl=1843496,Jl=3421243,Ql=Jl,ec=ds,Ji=7039337,hs=3159613,tc=1579032,rc=0,ic=2631720,nc=2632986,sc=2500383,oc=2771488,ac=5000268,lc=11122630,cc=16770413,dc=7829367,hc=16332866,uc=6127794,fc=6684002,pc=12164347,Sr={tough:ac,move:lc,work:cc,carry:dc,attack:hc,ranged_attack:uc,heal:fc,claim:pc},si=5809919,mt=7979263,us=4176208,oi=9147550,Cr=13801762,mn=10711543,gc=16218298,yn=16273737,hr=15763518,mc=2172461,fs=Ji,yc=13226457,dt=12283502,It=[16777215,16711680,8388736,255,65535,32768,16776960,16753920,10824234,8421504,16777215],vc={creep:hr,spawn:si,extension:mt,tower:us,container:oi,storage:Cr,link:mn,rampart:si,road:fs,wall:mc,extractor:oi,lab:gc,terminal:Cr,observer:mt,powerSpawn:hr,nuker:yn,factory:oi,invaderCore:yn,source:Cr,mineral:mt,deposit:Cr,controller:si,powerBank:hr,portal:mn},br=16771195,wc=br,bc=mt,xc=br,ur=9419667,_c=7245682,$c=12116924,Sc=12283502,Cc=9787480,kc=14721184,vn=Kl,Tc=13684944,fe=1579032,lt=5592405,Nr=11184810,Mc=9419667,Fe=16771195,Ec=16069959,wn=4410435,Rc=w*.05,Pc=w*.2;function Nt(r,e,t,i){const n=w,s=n/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,u=a<49&&e.get(l,a+1)===t,p=l>0&&e.get(l-1,a)===t,f=l<49&&e.get(l+1,a)===t,h=l*n+s,g=a*n+s;c?(o=!0,!d&&!p&&a>0&&l>0?(r.moveTo(h,a*n),r.arc(h,g,s,-Math.PI/2,Math.PI,!0),r.lineTo(h,g),r.closePath()):r.rect(l*n,a*n,s,s)):d&&p&&e.get(l-1,a-1)===t&&(o=!0,r.moveTo(h,a*n),r.lineTo(l*n,a*n),r.lineTo(l*n,g),r.arc(h,g,s,Math.PI,-Math.PI/2,!1),r.closePath()),c?!d&&!f&&a>0&&l<49?(r.moveTo(h,a*n),r.arc(h,g,s,-Math.PI/2,0,!1),r.lineTo(h,g),r.closePath()):r.rect(h,a*n,s,s):d&&f&&e.get(l+1,a-1)===t&&(o=!0,r.moveTo(h,a*n),r.lineTo(l*n+n,a*n),r.lineTo(l*n+n,g),r.arc(h,g,s,0,-Math.PI/2,!0),r.closePath()),c?!u&&!p&&a<49&&l>0?(r.moveTo(l*n,g),r.arc(h,g,s,Math.PI,Math.PI/2,!0),r.lineTo(h,g),r.closePath()):r.rect(l*n,g,s,s):u&&p&&e.get(l-1,a+1)===t&&(o=!0,r.moveTo(l*n,g),r.lineTo(l*n,a*n+n),r.lineTo(h,a*n+n),r.arc(h,g,s,Math.PI/2,Math.PI,!1),r.closePath()),c?!u&&!f&&a<49&&l<49?(r.moveTo(h,a*n+n),r.arc(h,g,s,Math.PI/2,0,!0),r.lineTo(h,g),r.closePath()):r.rect(h,g,s,s):u&&f&&e.get(l+1,a+1)===t&&(o=!0,r.moveTo(h,a*n+n),r.lineTo(l*n+n,a*n+n),r.lineTo(l*n+n,g),r.arc(h,g,s,0,Math.PI/2,!1),r.closePath())}o&&i(r)}function Oc(r,e){const t=Ji,i=w,n=(s,o,a)=>{const l=s*i+i/2,c=o*i+i/2,d=i*.3;a==="up"?(r.moveTo(l,c-d),r.lineTo(l+d,c+d),r.lineTo(l-d,c+d)):a==="down"?(r.moveTo(l,c+d),r.lineTo(l+d,c-d),r.lineTo(l-d,c-d)):a==="left"?(r.moveTo(l-d,c),r.lineTo(l+d,c-d),r.lineTo(l+d,c+d)):a==="right"&&(r.moveTo(l+d,c),r.lineTo(l-d,c-d),r.lineTo(l-d,c+d)),r.fill(t)};for(let s=0;s<50;s++)e.get(s,0)!==Ne.Wall&&n(s,0,"up"),e.get(s,49)!==Ne.Wall&&n(s,49,"down");for(let s=0;s<50;s++)e.get(0,s)!==Ne.Wall&&n(0,s,"left"),e.get(49,s)!==Ne.Wall&&n(49,s,"right")}function Lc(r){const e=new q;e.rect(0,0,50*w,50*w),e.fill(Ql);const t={color:sc,width:Pc,alignment:0,cap:"round",join:"round"};Nt(e,r,Ne.Swamp,n=>n.stroke(t)),Nt(e,r,Ne.Swamp,n=>n.fill(nc));const i={color:rc,width:Rc,alignment:0,cap:"round",join:"round"};return Nt(e,r,Ne.Wall,n=>n.stroke(i)),Nt(e,r,Ne.Wall,n=>n.fill(tc)),Oc(e,r),e.rect(0,0,50*w,50*w),e.stroke({width:1,color:hs}),e}function Ac(r){const e=new q;return e.label="swampGlow",Nt(e,r,Ne.Swamp,t=>t.fill(oc)),e.alpha=.45,e.filters=[new Qs({strength:5,quality:3})],e}function Ic(r,e){const t=new q;Nt(t,r,Ne.Wall,s=>s.fill(ic)),t.alpha=.5,t.filters=[new Js({noise:.12,seed:1})],t.filterArea=new Vn(0,0,50*w,50*w);const i=e.generateTexture({target:t,frame:t.filterArea});t.filters=null,t.destroy();const n=new Ht(i);return n.label="wallNoise",n}function bn(r,e){const t=new Ee,i=Ic(r,e),n=t.destroy.bind(t);return t.destroy=s=>{i.destroyed||(i.removeFromParent(),i.destroy({texture:!0,textureSource:!0})),n(s)},t.addChild(Lc(r)),t.addChild(Ac(r)),t.addChild(i),t}function ai(r,e){r.getChildByLabel("swampGlow").visible=e,r.getChildByLabel("wallNoise").visible=e}function Nc(r){return new Promise((e,t)=>{const i=new Image;i.onload=()=>e(i),i.onerror=t,i.src=r})}class ps{constructor(){_(this,"cache",new Map);_(this,"pending",new Map)}getKey(e){return JSON.stringify(e)}has(e){return this.cache.has(this.getKey(e))}getOrCreate(e){const t=this.getKey(e),i=this.cache.get(t);if(i)return Promise.resolve(i);const n=this.pending.get(t);if(n)return n;const s=this.buildTexture(e,t);return this.pending.set(t,s),s.then(()=>{this.pending.delete(t)}).catch(()=>{this.pending.delete(t)}),s}async buildTexture(e,t){const i=qr(e),n=new Blob([i],{type:"image/svg+xml;charset=utf-8"}),s=URL.createObjectURL(n);try{const o=window.devicePixelRatio||1,a=128*Math.max(2,o),l=await Nc(s),c=document.createElement("canvas");c.width=a,c.height=a,c.getContext("2d").drawImage(l,0,0,a,a);const u=sr.from(c);return this.cache.set(t,u),u}finally{URL.revokeObjectURL(s)}}destroy(){for(const e of this.cache.values())e.destroyed||e.destroy(!0);this.cache.clear(),this.pending.clear()}}const Gc=new ps,rt=w*.44,Be=w*.28,Kt=50,Si=32,Ci=12/Si,gs=w/2-w*.44,ms=2,xn=w*.42,ys=w*.3,Dc=Math.max(1,w*.08),zc={H:13421772,O:16777215,U:5822457,L:62626,K:10514943,Z:16631694,X:11568379},Bc={H:2236962,O:2236962},Fc=w*.42,vs=32,Hc=9/vs,ki=w-4,_n=w*.28,$n=1600,Wc=16776428;function Ti(r,e){if(e<=0)return ki;const t=Math.max(0,Math.min(1,r/e));return _n+(ki-_n)*t}function Qi(r,e,t=Fe){const i=e/2,n=w/2,s=w/2,o=e*.25;r.clear(),r.roundRect(n-i,s-i,e,e,o),r.fill(t)}function Uc(r,e){const t=r.__sourceGraphics;t&&(r.__sourceSize=e,Qi(t,e,en(performance.now())))}function en(r){const e=r%$n/$n,t=.5-.5*Math.cos(e*Math.PI*2);return xs(Fe,Wc,t)}function Mi(r){const e=typeof r.energy=="number"?r.energy:0,t=typeof r.energyCapacity=="number"?r.energyCapacity:3e3;return{energy:e,capacity:t}}const ws=w*.3,bs=Math.max(1,w*.12),Ei=ws-bs/2,Xc=w*.42,Yc=1500;function xs(r,e,t){const i=r>>16&255,n=r>>8&255,s=r&255,o=e>>16&255,a=e>>8&255,l=e&255,c=Math.round(i+(o-i)*t),d=Math.round(n+(a-n)*t),u=Math.round(s+(l-s)*t);return c<<16|d<<8|u}function _s(r,e){r.clear(),r.circle(w/2,w/2,ws),r.stroke({width:bs,color:e,alpha:.95})}function Ri(r,e,t,i,n,s,o){if(r.clear(),s<=0||n<=0)return;const a=Math.min(1,n/s);if(a>=1){r.circle(e,t,i),r.fill({color:o,alpha:.55});return}const l=-Math.PI/2,c=l+a*Math.PI*2;r.moveTo(e,t),r.lineTo(e+i*Math.cos(l),t+i*Math.sin(l)),r.arc(e,t,i,l,c),r.closePath(),r.fill({color:o,alpha:.55})}function tt(r,e,t){return t.flatMap(([i,n])=>[r+i*w,e+n*w])}function kt(r,e,t,i){t-e<.001||(r.moveTo(rt*Math.cos(e),rt*Math.sin(e)),r.arc(0,0,rt,e,t),r.lineTo(Be*Math.cos(t),Be*Math.sin(t)),r.arc(0,0,Be,t,e,!0),r.closePath(),r.fill(i))}function Pi(r){let e=0;if(typeof r.storeCapacity=="number")e=r.storeCapacity;else{const i=r.body;i&&(e=i.filter(n=>n.type==="carry").length*50)}if(e===0)return{used:0,capacity:0};let t=0;if(r.store&&typeof r.store=="object"){const i=r.store;for(const n in i){const s=i[n];typeof s=="number"&&(t+=s)}}else typeof r.energy=="number"&&(t=r.energy);return{used:t,capacity:e}}function Oi(r,e){return e<=0||r<=0?0:Be*.8*Math.min(1,r/e)}function qc(r,e){const t=r.__creepFillGraphics;t&&(t.clear(),e>0&&(t.circle(0,0,e),t.fill(br)))}function Vc(r){return vc[r]??yc}function Gt(r){let e=50;typeof r.energyCapacity=="number"?e=r.energyCapacity:typeof r.storeCapacity=="number"?e=r.storeCapacity:r.storeCapacityResource&&typeof r.storeCapacityResource=="object"&&(e=r.storeCapacityResource.energy??50);let t=0;return typeof r.energy=="number"?t=r.energy:r.store&&typeof r.store=="object"&&(t=r.store.energy??0),{energy:t,capacity:e}}function $s(r){return r>=200?1.15:r>=100?.85:.7}function Li(r,e){return e<=0||r<=0?0:ys*$s(e)*Math.min(1,r/e)}function jc(r,e,t,i){const n=w/2,s=w/2,o=$s(t),a=new q;a.circle(n,s,xn*o),a.fill(fe),a.circle(n,s,xn*o),a.stroke({width:Dc*o,color:i}),a.circle(n,s,ys*o),a.fill(Nr),r.addChild(a);const l=new q,c=Li(e,t);c>0&&(l.circle(n,s,c),l.fill(Fe)),r.addChild(l),r.__fillGraphics=l}function Zc(r,e){const t=w/2,i=w/2,n=r.__fillGraphics;n&&(n.clear(),e>0&&(n.circle(t,i,e),n.fill(Fe)))}const Ai=-w*.4,Ii=-w*.3,Ni=w*.8,zr=w*.6;function Gi(r,e){return e<=0||r<=0?0:zr*Math.min(1,r/e)}function Ss(r,e){const t=r.__towerFillGraphics;if(t&&(t.clear(),e>0)){const i=Math.max(.5,w*.02);t.rect(Ai+i,Ii+zr-e+i,Ni-i*2,e-i*2),t.fill(Fe)}}const Di=w*.65,zi=Di,Xe=w*.42;function Bi(r,e,t,i,n,s,o,a){r.clear();const l=8,c=.1,d=2*Math.PI/l-c;for(let u=0;u<l;u++){const p=-Math.PI/2+u*(2*Math.PI/l)+c/2,f=p+d,h=e+n*Math.cos(p),g=t+n*Math.sin(p);if(u<s)r.moveTo(h,g),r.arc(e,t,i,p,f),r.arc(e,t,n,f,p,!0),r.closePath(),r.fill({color:14540253,alpha:.9});else if(u===s&&a>0){if(r.moveTo(h,g),r.arc(e,t,i,p,f),r.arc(e,t,n,f,p,!0),r.closePath(),r.fill({color:1973790,alpha:.85}),o>0){const $=Math.min(1,o/a),y=p+d*$;r.moveTo(h,g),r.arc(e,t,i,p,y),r.arc(e,t,n,y,p,!0),r.closePath(),r.fill({color:14540253,alpha:.9})}}else r.moveTo(h,g),r.arc(e,t,i,p,f),r.arc(e,t,n,f,p,!0),r.closePath(),r.fill({color:1973790,alpha:.6})}}function Br(r,e){const t=r.user;return typeof t!="string"||!e?!1:t!==e}function kr(r,e=!0,t,i,n,s){var h,g,$;const o=new Ee,a=new q,l=Vc(r.type),c=w/2,d=w/2,u=typeof r.user=="string"?r.user:void 0,f=u!==void 0&&t!==void 0&&u!==t?dt:Mc;switch(r.type){case"creep":{const y=2*Math.PI,S=new Ee;S.position.set(c,d),S.rotation=-Math.PI/2;const E=Br(r,t);if(E){const J=new q;J.circle(0,0,rt+.75),J.stroke({width:1.5,color:dt}),S.addChild(J)}const x=new q;x.circle(0,0,rt),x.fill(ds),S.addChild(x);const m=r.body??[];let M=0,T=0,b=0;const k=[],A={};for(const J of m)J.type==="work"?M++:J.type==="move"?T++:(A[J.type]===void 0&&(k.push(J.type),A[J.type]=0),A[J.type]++,b++);const P=M/Kt*y,N=T/Kt*y,O=b/Kt*y,L=P/2,z=L+O/2,F=Math.PI-N/2,U=Math.PI+N/2,Z=y-P/2-O/2,de=y-P/2,re=new q;P>0&&kt(re,-P/2,L,Sr.work);let W=L;for(const J of k){const Te=(A[J]??0)/Kt*y/2;kt(re,W,W+Te,Sr[J]??7829367),W+=Te}kt(re,z,F,vn),N>0&&kt(re,F,U,Sr.move),kt(re,U,Z,vn);let Y=de;for(const J of k){const Te=(A[J]??0)/Kt*y/2;kt(re,Y-Te,Y,Sr[J]??7829367),Y-=Te}S.addChild(re);const ie=new q;ie.circle(0,0,Be),ie.fill(Zl),S.addChild(ie);const K=typeof r.user=="string"?r.user:void 0,oe=K?(h=s==null?void 0:s[K])==null?void 0:h.badge:void 0;if(oe&&n){const J=new Ht;J.anchor.set(.5,.5);const Te=Be*2;J.width=Te,J.height=Te,J.rotation=Math.PI/2,S.addChild(J),o.__creepBadgeSprite=J,n.getOrCreate(oe).then(at=>{J.destroyed||(J.texture=at)}).catch(()=>{})}else if(E){const J=new q;J.circle(0,0,Be*.82),J.fill({color:dt,alpha:.9}),S.addChild(J),o.__creepForeignMark=J}const{used:De,capacity:ot}=Pi(r),_t=Oi(De,ot),He=new q;_t>0&&(He.circle(0,0,_t),He.fill(br)),S.addChild(He),o.__creepFillGraphics=He,o.__creepUsed=De,o.__creepCapacity=ot;const We=(rt+Be)/2,Je=(rt-Be)*.45,Le=new q;Le.moveTo(rt,0),Le.lineTo(We,-Je),Le.lineTo(We,Je),Le.closePath(),Le.fill(Tc),S.addChild(Le),o.addChild(S),o.__bodyContainer=S;break}case"extension":{const{energy:y,capacity:S}=Gt(r);jc(o,y,S,f),o.__extEnergy=y,o.__extCapacity=S;break}case"spawn":{a.circle(c,d,w*.65),a.fill(fe),a.circle(c,d,w*.65),a.stroke({width:w*.1,color:13421772}),a.circle(c,d,w*.4),a.fill(Fe);break}case"powerSpawn":{a.circle(c,d,w*.65),a.fill(fe),a.circle(c,d,w*.65),a.stroke({width:w*.1,color:Ec}),a.circle(c,d,w*.4),a.fill(Fe);break}case"source":{const{energy:y,capacity:S}=Mi(r),E=Ti(y,S),x=new q;Qi(x,E,en(performance.now())),o.addChild(x),o.__sourceGraphics=x,o.__sourceEnergy=y,o.__sourceCapacity=S,o.__sourceSize=E;break}case"constructionSite":{const y=typeof r.user=="string"?r.user:void 0,S=y!==void 0&&y===t,E=S?ur:Sc,x=S?_c:Cc,m=S?$c:kc,M=typeof r.progress=="number"?r.progress:0,T=typeof r.progressTotal=="number"?r.progressTotal:1,b=new q;o.addChild(b),o.__csBuildGlow=b;const k=new q;Ri(k,c,d,Ei,M,T,E),o.addChild(k),o.__csFillGraphics=k;const A=new q;_s(A,E),o.addChild(A),o.__csRingGraphics=A,o.__csProgress=M,o.__csProgressTotal=T,o.__csUser=y,o.__csColor=E,o.__csColorDark=x,o.__csColorLight=m;break}case"mineral":{const y=typeof r.mineralType=="string"?r.mineralType:"?",S=zc[y]??mt,E=Bc[y]??16777215,x=new q;x.circle(c,d,Fc),x.fill(S),o.addChild(x);const m=new zt({text:y,style:{fontSize:vs,fill:E,fontWeight:"bold"}});m.anchor.set(.5,.5),m.scale.set(Hc),m.position.set(c,d),o.addChild(m);break}case"deposit":{a.rect(2,2,w-4,w-4),a.fill(l);break}case"controller":{const y=typeof r.level=="number"?r.level:0,S=typeof r.progress=="number"?r.progress:0,E=typeof r.progressTotal=="number"?r.progressTotal:0,x=typeof r.user=="string"?r.user:void 0,m=x?(g=s==null?void 0:s[x])==null?void 0:g.badge:void 0,M=new q,T=[];for(let A=0;A<8;A++){const P=-Math.PI/2+A*Math.PI/4;T.push(c+Di*Math.cos(P),d+Di*Math.sin(P))}M.poly(T),M.fill(2238513),M.poly(T),M.stroke({width:w*.07,color:8027781}),o.addChild(M);const b=new q;Bi(b,c,d,zi,Xe,y,S,E),o.addChild(b),o.__ctrlSegGraphics=b,o.__ctrlLevel=y,o.__ctrlProgress=S,o.__ctrlProgressTotal=E;const k=new q;if(m?(k.circle(c,d,Xe),k.fill(fe)):(k.circle(c,d,Xe),k.fill(3028031),k.circle(c,d,Xe),k.stroke({width:w*.04,color:8027781}),k.circle(c,d,w*.16),k.fill(10133672)),o.addChild(k),m&&n){const A=new Ht;A.anchor.set(.5,.5),A.width=Xe*2,A.height=Xe*2,A.position.set(c,d);const P=new q;P.circle(c,d,Xe),P.fill(16777215),o.addChild(A),A.mask=P,o.addChild(P),n.getOrCreate(m).then(N=>{A.destroyed||(A.texture=N)}).catch(()=>{})}break}case"energy":{a.circle(c,d,w*.2),a.fill(Fe);break}case"road":break;case"wall":{a.circle(c,d,w*.4),a.fill(fe),a.circle(c,d,w*.4),a.stroke({width:w*.05,color:Nr});break}case"rampart":break;case"tower":{const{energy:y,capacity:S}=Gt(r),E=new q;E.circle(c,d,w*.6),E.fill(fe),E.circle(c,d,w*.6),E.stroke({width:w*.05,color:f}),o.addChild(E);const x=new Ee;x.position.set(c,d);const m=new q;m.rect(Ai,Ii,Ni,zr),m.fill(fe),x.addChild(m);const M=new q;x.addChild(M),o.__towerFillGraphics=M,o.__towerEnergy=y,o.__towerCapacity=S,Ss(o,Gi(y,S));const T=new q;T.rect(Ai,Ii,Ni,zr),T.stroke({width:1,color:lt}),x.addChild(T);const b=new q;b.rect(-w*.2,-w*.9,w*.4,w*.5),b.fill(Nr),b.rect(-w*.2,-w*.9,w*.4,w*.5),b.stroke({width:w*.07,color:fe}),x.addChild(b),o.addChild(x),o.__barrelContainer=x;break}case"storage":{const y=tt(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(fe),a.poly(y),a.stroke({width:w*.05,color:f}),a.rect(c-w*.5,d-w*.6,w*1,w*1.2),a.fill(lt),a.rect(c-w*.5,d-w*.6,w*1,w*1.2),a.stroke({width:w*.1,color:fe});break}case"terminal":{const y=tt(c,d,[[0,-.8],[.55,-.55],[.8,0],[.55,.55],[0,.8],[-.55,.55],[-.8,0],[-.55,-.55],[0,-.8]]),S=tt(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(fe),a.poly(y),a.stroke({width:w*.05,color:f}),a.poly(S),a.fill(Nr),a.rect(c-w*.45,d-w*.45,w*.9,w*.9),a.fill(lt),a.rect(c-w*.45,d-w*.45,w*.9,w*.9),a.stroke({width:w*.1,color:fe});break}case"link":{const y=tt(c,d,[[0,-.5],[.4,0],[0,.5],[-.4,0],[0,-.5]]),S=tt(c,d,[[0,-.3],[.25,0],[0,.3],[-.25,0],[0,-.3]]);a.poly(y),a.fill(fe),a.poly(y),a.stroke({width:w*.05,color:f}),a.poly(S),a.fill(lt);break}case"lab":{const y=d-w*.025;a.circle(c,y,w*.55),a.fill(fe),a.circle(c,y,w*.55),a.stroke({width:w*.05,color:f}),a.circle(c,y,w*.4),a.fill(lt),a.rect(c-w*.45,d+w*.3,w*.9,w*.25),a.fill(fe),a.poly(tt(c,d,[[-.45,.3],[-.45,.55],[.45,.55],[.45,.3]])),a.stroke({width:w*.05,color:f});break}case"container":{a.rect(c-w*.225,d-w*.3,w*.45,w*.6),a.fill(Fe),a.rect(c-w*.225,d-w*.3,w*.45,w*.6),a.stroke({width:w*.1,color:fe});break}case"observer":{a.circle(c,d,w*.45),a.fill(fe),a.circle(c,d,w*.45),a.stroke({width:w*.05,color:f}),a.circle(c+w*.225,d,w*.2),a.fill(f);break}case"nuker":{const y=tt(c,d,[[0,-1],[-.47,.2],[-.5,.5],[.5,.5],[.47,.2],[0,-1]]),S=tt(c,d,[[0,-.8],[-.4,.2],[.4,.2],[0,-.8]]);a.poly(y),a.fill(fe),a.poly(y),a.stroke({width:w*.05,color:f}),a.poly(S),a.fill(lt),a.poly(S),a.stroke({width:w*.01,color:f});break}case"factory":case"extractor":case"invaderCore":{a.circle(c,d,w*.45),a.fill(fe),a.circle(c,d,w*.45),a.stroke({width:w*.05,color:f}),a.circle(c,d,w*.35),a.fill(lt);break}case"flag":{const y=typeof r.color=="number"?r.color:0,S=typeof r.secondaryColor=="number"?r.secondaryColor:0,E=It[y]??It[0],x=It[S]??It[0],m=1.5,M=w*.08*m,T=w*.7*m,b=c-M/2,k=d-w*.25*m;a.rect(b,k,M,T),a.fill(8947848);const A=b+M,P=k,N=A+w*.45*m,O=P,L=P+w*.44*m,z=(O+L)/2,F=z;if(a.moveTo(A,O),a.lineTo(N,z),a.lineTo(A,F),a.closePath(),a.fill(E),a.moveTo(A,F),a.lineTo(N,z),a.lineTo(A,L),a.closePath(),a.fill(x),o.addChild(a),o.__flagColor=y,o.__flagSecondaryColor=S,typeof r.name=="string"){const U=new zt({text:r.name,style:{fontSize:Si,fill:16777215}});U.scale.set(Ci),U.anchor.set(.5,0),U.x=c,U.y=d+w*.55,U.visible=e,o.__nameLabel=U,o.addChild(U)}break}case"ruin":{const y=typeof r.user=="string"?r.user:void 0,E=y!==void 0&&y===t?ur:dt,x=w*.42,m=6,M=Math.PI/5,T=new q;for(let A=0;A<m;A++){const P=A*Math.PI*2/m,N=P-M/2,O=P+M/2,L=c+x*Math.cos(N),z=d+x*Math.sin(N);T.moveTo(L,z),T.arc(c,d,x,N,O),T.stroke({width:w*.09,color:E,alpha:.75,cap:"round"})}o.addChild(T);const b=w*.18,k=new q;k.moveTo(c-b,d-b),k.lineTo(c+b,d+b),k.moveTo(c+b,d-b),k.lineTo(c-b,d+b),k.stroke({width:w*.11,color:E,cap:"round"}),o.addChild(k);break}case"tombstone":{const y=typeof r.user=="string"?r.user:void 0,E=y!==void 0&&y===t?ur:dt,x=w*.62,m=w*.82,M=c-x/2,T=d-m/2,b=x/2,k=new q;k.moveTo(M,T+b),k.arc(c,T+b,b,Math.PI,0,!1),k.lineTo(M+x,T+m),k.lineTo(M,T+m),k.closePath(),k.fill(fe),k.moveTo(M,T+b),k.arc(c,T+b,b,Math.PI,0,!1),k.lineTo(M+x,T+m),k.lineTo(M,T+m),k.closePath(),k.stroke({width:w*.07,color:E,alpha:.9}),o.addChild(k);const A=w*.18,P=new q;P.moveTo(c-A,d-A*.6),P.lineTo(c+A,d+A*.6),P.moveTo(c+A,d-A*.6),P.lineTo(c-A,d+A*.6),P.stroke({width:w*.09,color:E,cap:"round"}),o.addChild(P);break}default:{const y=w-2;a.rect(1,1,y,y),a.fill(l)}}if(r.type!=="extension"&&r.type!=="road"&&r.type!=="creep"&&r.type!=="tower"&&r.type!=="controller"&&r.type!=="flag"&&r.type!=="source"&&r.type!=="constructionSite"&&r.type!=="mineral"&&r.type!=="tombstone"&&r.type!=="ruin"&&o.addChild(a),r.type==="creep"&&typeof r.name=="string"){const y=Br(r,t);let S;if(y){const m=typeof r.user=="string"?r.user:void 0;S=m?(($=s==null?void 0:s[m])==null?void 0:$.username)??m:"Hostile"}else S=r.name;const E=y?dt:16777215,x=new zt({text:S,style:{fontSize:Si,fill:E}});x.scale.set(Ci),x.anchor.set(.5,1),x.x=c,x.y=gs-ms,x.visible=e,o.__nameLabel=x,o.addChild(x)}return r.type==="creep"&&(o.zIndex=1),r.type==="flag"&&(o.zIndex=10),o.position.set(r.x*w,r.y*w),o}function Jt(r){r.destroy({children:!0})}class Kc{constructor(e,t=!0,i,n,s){_(this,"container");_(this,"objects",new Map);_(this,"rawObjects",new Map);_(this,"roadGraphics");_(this,"rampartGraphics");_(this,"ticker",null);_(this,"tickerCallback",null);_(this,"extAnimations",new Map);_(this,"creepFillAnimations",new Map);_(this,"towerFillAnimations",new Map);_(this,"sourceAnimations",new Map);_(this,"buildGlowAnimations",new Map);_(this,"EXT_ANIM_DURATION",300);_(this,"lastWorldScale",1);_(this,"showLabels");_(this,"currentUserId");_(this,"badge");_(this,"badgeCache",Gc);_(this,"users");this.showLabels=t,this.currentUserId=i,this.badge=n,this.users=s,this.container=new Ee,this.container.sortableChildren=!0,this.rampartGraphics=new q,this.rampartGraphics.zIndex=-1,this.container.addChild(this.rampartGraphics),this.roadGraphics=new q,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,u=c-a.y;Math.abs(d)<.5&&Math.abs(u)<.5?(a.position.set(l,c),a.__targetX=void 0,a.__targetY=void 0):(a.x+=d*.15,a.y+=u*.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(),i=t/1e3,n=.5+.5*Math.sin(t*2*Math.PI/Yc);for(const a of this.objects.values())a.__barrelContainer&&(a.__barrelContainer.rotation=i*.4),a.__csRingGraphics&&a.__csColorDark!==void 0&&a.__csColorLight!==void 0&&_s(a.__csRingGraphics,xs(a.__csColorDark,a.__csColorLight,n));for(const[a,l]of this.extAnimations){const c=t-l.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),u=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;Zc(l.visual,l.fromRadius+(l.toRadius-l.fromRadius)*u),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),u=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;qc(l.visual,l.fromRadius+(l.toRadius-l.fromRadius)*u),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),u=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;Ss(l.visual,l.fromRadius+(l.toRadius-l.fromRadius)*u),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),u=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;Uc(l.visual,l.fromRadius+(l.toRadius-l.fromRadius)*u),d>=1&&this.sourceAnimations.delete(a)}const s=en(t);for(const a of this.objects.values()){const l=a.__sourceGraphics;l&&Qi(l,a.__sourceSize??ki,s)}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 u=(t-l.startTime)/l.duration;let p;u<=0?p=0:u<.5?p=u/.5:u<.7?p=1:u<1?p=1-(u-.7)/.3:p=0,d.clear(),p>0&&(d.circle(w/2,w/2,Xc),d.fill({color:Fe,alpha:p*.75})),u>=1&&this.buildGlowAnimations.delete(a)}}startExtAnimation(e,t,i,n,s,o){const a=Li(i,n),l=Li(s,o);a!==l&&this.extAnimations.set(e,{visual:t,fromRadius:a,toRadius:l,startTime:performance.now()})}startCreepFillAnimation(e,t,i,n,s,o){const a=Oi(i,n),l=Oi(s,o);a!==l&&this.creepFillAnimations.set(e,{visual:t,fromRadius:a,toRadius:l,startTime:performance.now()})}startTowerFillAnimation(e,t,i,n,s,o){const a=Gi(i,n),l=Gi(s,o);a!==l&&this.towerFillAnimations.set(e,{visual:t,fromRadius:a,toRadius:l,startTime:performance.now()})}startSourceAnimation(e,t,i,n,s,o){const a=Ti(i,n),l=Ti(s,o);a!==l&&this.sourceAnimations.set(e,{visual:t,fromRadius:a,toRadius:l,startTime:performance.now()})}update(e,t,i){i&&(this.users=i);let n=!1;if(t)for(const s in t)if(t[s]===null){const a=this.rawObjects.get(s);a&&a.type==="road"&&(n=!0);const l=this.objects.get(s);l&&(this.container.removeChild(l),Jt(l),this.objects.delete(s),this.rawObjects.delete(s),this.extAnimations.delete(s),this.creepFillAnimations.delete(s),this.towerFillAnimations.delete(s),this.sourceAnimations.delete(s),this.buildGlowAnimations.delete(s))}else{const a=e[s];if(!a)continue;if(a.type==="road"){const c=this.rawObjects.get(s);(!c||c.x!==a.x||c.y!==a.y)&&(n=!0)}this.rawObjects.set(s,a);const l=this.objects.get(s);if(l){const c=a.x*w,d=a.y*w;if(a.type==="creep"){const u=a.x-(l.__tileX??a.x),p=a.y-(l.__tileY??a.y);(u!==0||p!==0)&&(l.__angle=Math.atan2(p,u),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:h}=Pi(a);(l.__creepUsed!==f||l.__creepCapacity!==h)&&(this.startCreepFillAnimation(s,l,l.__creepUsed??0,l.__creepCapacity??h,f,h),l.__creepUsed=f,l.__creepCapacity=h)}else if(a.type==="flag"){const u=typeof a.color=="number"?a.color:0,p=typeof a.secondaryColor=="number"?a.secondaryColor:0;if(l.__flagColor!==u||l.__flagSecondaryColor!==p){this.container.removeChild(l),Jt(l),this.objects.delete(s);const h=kr(a,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);h.__tileX=a.x,h.__tileY=a.y,this.applyLabelScale(h),this.objects.set(s,h),this.container.addChild(h)}else l.position.set(c,d)}else l.position.set(c,d);if(a.type==="extension"){const{energy:u,capacity:p}=Gt(a),f=l;(f.__extEnergy!==u||f.__extCapacity!==p)&&(this.startExtAnimation(s,l,f.__extEnergy??0,f.__extCapacity??p,u,p),f.__extEnergy=u,f.__extCapacity=p)}if(a.type==="tower"){const{energy:u,capacity:p}=Gt(a);(l.__towerEnergy!==u||l.__towerCapacity!==p)&&(this.startTowerFillAnimation(s,l,l.__towerEnergy??0,l.__towerCapacity??p,u,p),l.__towerEnergy=u,l.__towerCapacity=p)}if(a.type==="controller"){const u=typeof a.level=="number"?a.level:0,p=typeof a.progress=="number"?a.progress:0,f=typeof a.progressTotal=="number"?a.progressTotal:0;(l.__ctrlLevel!==u||l.__ctrlProgress!==p||l.__ctrlProgressTotal!==f)&&(l.__ctrlSegGraphics&&Bi(l.__ctrlSegGraphics,w/2,w/2,zi,Xe,u,p,f),l.__ctrlLevel=u,l.__ctrlProgress=p,l.__ctrlProgressTotal=f)}if(a.type==="source"){const{energy:u,capacity:p}=Mi(a);(l.__sourceEnergy!==u||l.__sourceCapacity!==p)&&(this.startSourceAnimation(s,l,l.__sourceEnergy??0,l.__sourceCapacity??p,u,p),l.__sourceEnergy=u,l.__sourceCapacity=p)}if(a.type==="constructionSite"){const u=typeof a.progress=="number"?a.progress:0,p=typeof a.progressTotal=="number"?a.progressTotal:1;(l.__csProgress!==u||l.__csProgressTotal!==p)&&(l.__csFillGraphics&&Ri(l.__csFillGraphics,w/2,w/2,Ei,u,p,l.__csColor??ur),l.__csProgress=u,l.__csProgressTotal=p)}}else{const c=kr(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(s,c),this.container.addChild(c)}}else{const s=new Set;for(const o in e){const a=e[o];if(!a)continue;s.add(o),this.rawObjects.set(o,a);const l=this.objects.get(o);if(l){const c=a.x*w,d=a.y*w;if(a.type==="creep"){const u=a.x-(l.__tileX??a.x),p=a.y-(l.__tileY??a.y);(u!==0||p!==0)&&(l.__angle=Math.atan2(p,u),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:h}=Pi(a);(l.__creepUsed!==f||l.__creepCapacity!==h)&&(this.startCreepFillAnimation(o,l,l.__creepUsed??0,l.__creepCapacity??h,f,h),l.__creepUsed=f,l.__creepCapacity=h)}else if(a.type==="flag"){const u=typeof a.color=="number"?a.color:0,p=typeof a.secondaryColor=="number"?a.secondaryColor:0;if(l.__flagColor!==u||l.__flagSecondaryColor!==p){this.container.removeChild(l),Jt(l),this.objects.delete(o);const h=kr(a,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);h.__tileX=a.x,h.__tileY=a.y,this.applyLabelScale(h),this.objects.set(o,h),this.container.addChild(h)}else l.position.set(c,d)}else l.position.set(c,d);if(a.type==="extension"){const{energy:u,capacity:p}=Gt(a),f=l;(f.__extEnergy!==u||f.__extCapacity!==p)&&(this.startExtAnimation(o,l,f.__extEnergy??0,f.__extCapacity??p,u,p),f.__extEnergy=u,f.__extCapacity=p)}if(a.type==="tower"){const{energy:u,capacity:p}=Gt(a);(l.__towerEnergy!==u||l.__towerCapacity!==p)&&(this.startTowerFillAnimation(o,l,l.__towerEnergy??0,l.__towerCapacity??p,u,p),l.__towerEnergy=u,l.__towerCapacity=p)}if(a.type==="controller"){const u=typeof a.level=="number"?a.level:0,p=typeof a.progress=="number"?a.progress:0,f=typeof a.progressTotal=="number"?a.progressTotal:0;(l.__ctrlLevel!==u||l.__ctrlProgress!==p||l.__ctrlProgressTotal!==f)&&(l.__ctrlSegGraphics&&Bi(l.__ctrlSegGraphics,w/2,w/2,zi,Xe,u,p,f),l.__ctrlLevel=u,l.__ctrlProgress=p,l.__ctrlProgressTotal=f)}if(a.type==="source"){const{energy:u,capacity:p}=Mi(a);(l.__sourceEnergy!==u||l.__sourceCapacity!==p)&&(this.startSourceAnimation(o,l,l.__sourceEnergy??0,l.__sourceCapacity??p,u,p),l.__sourceEnergy=u,l.__sourceCapacity=p)}if(a.type==="constructionSite"){const u=typeof a.progress=="number"?a.progress:0,p=typeof a.progressTotal=="number"?a.progressTotal:1;(l.__csProgress!==u||l.__csProgressTotal!==p)&&(l.__csFillGraphics&&Ri(l.__csFillGraphics,w/2,w/2,Ei,u,p,l.__csColor??ur),l.__csProgress=u,l.__csProgressTotal=p)}}else{const c=kr(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)s.has(o)||(this.container.removeChild(a),Jt(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));n=!0}this.redrawRamparts(),n&&this.redrawRoads(),this.refreshForeignCreepLabels(),this.refreshForeignCreepBadges()}redrawRoads(){this.roadGraphics.clear();const e=fs,t=Array.from({length:50},()=>new Array(50).fill(!1)),i=[];for(const l of this.rawObjects.values())l.type==="road"&&(i.push(l),l.x>=0&&l.x<50&&l.y>=0&&l.y<50&&(t[l.x][l.y]=!0));if(i.length===0)return;const n=w/2,s=w/2,o=w*.125;for(const l of i)this.roadGraphics.circle(l.x*w+n,l.y*w+s,o);this.roadGraphics.fill(e);const a=[[1,0],[1,1],[0,1],[-1,1]];for(const l of i){const c=l.x*w+n,d=l.y*w+s;for(const[u,p]of a){const f=l.x+u,h=l.y+p;if(f>=0&&f<50&&h>=0&&h<50&&t[f][h]){const g=f*w+n,$=h*w+s;this.roadGraphics.moveTo(c,d),this.roadGraphics.lineTo(g,$)}}}this.roadGraphics.stroke({width:o*2,color:e})}redrawRamparts(){this.rampartGraphics.clear();const e=w,t=e/2,i=Array.from({length:50},()=>new Array(50).fill(void 0));for(const s of this.rawObjects.values())s.type==="rampart"&&s.x>=0&&s.x<50&&s.y>=0&&s.y<50&&(i[s.x][s.y]=typeof s.user=="string"?s.user:void 0);const n=s=>!s||!this.currentUserId?{color:wn,alpha:.7}:s===this.currentUserId?{color:wn,alpha:.7}:{color:7807522,alpha:.5};for(let s=0;s<50;s++)for(let o=0;o<50;o++){const a=i[o][s],l=a!==void 0,c=s>0&&i[o][s-1]!==void 0,d=s<49&&i[o][s+1]!==void 0,u=o>0&&i[o-1][s]!==void 0,p=o<49&&i[o+1][s]!==void 0,f=o*e+t,h=s*e+t;if(l){const g=n(a);!c&&!u&&s>0&&o>0?(this.rampartGraphics.moveTo(f,s*e),this.rampartGraphics.arc(f,h,t,-Math.PI/2,Math.PI,!0),this.rampartGraphics.lineTo(f,h),this.rampartGraphics.fill(g)):(this.rampartGraphics.rect(o*e,s*e,t,t),this.rampartGraphics.fill(g))}else if(c&&u&&i[o-1][s-1]!==void 0){const g=n(i[o-1][s-1]);this.rampartGraphics.moveTo(f,s*e),this.rampartGraphics.lineTo(o*e,s*e),this.rampartGraphics.lineTo(o*e,h),this.rampartGraphics.arc(f,h,t,Math.PI,-Math.PI/2,!1),this.rampartGraphics.fill(g)}if(l){const g=n(a);!c&&!p&&s>0&&o<49?(this.rampartGraphics.moveTo(f,s*e),this.rampartGraphics.arc(f,h,t,-Math.PI/2,0,!1),this.rampartGraphics.lineTo(f,h),this.rampartGraphics.fill(g)):(this.rampartGraphics.rect(f,s*e,t,t),this.rampartGraphics.fill(g))}else if(c&&p&&i[o+1][s-1]!==void 0){const g=n(i[o+1][s-1]);this.rampartGraphics.moveTo(f,s*e),this.rampartGraphics.lineTo(o*e+e,s*e),this.rampartGraphics.lineTo(o*e+e,h),this.rampartGraphics.arc(f,h,t,0,-Math.PI/2,!0),this.rampartGraphics.fill(g)}if(l){const g=n(a);!d&&!u&&s<49&&o>0?(this.rampartGraphics.moveTo(o*e,h),this.rampartGraphics.arc(f,h,t,Math.PI,Math.PI/2,!0),this.rampartGraphics.lineTo(f,h),this.rampartGraphics.fill(g)):(this.rampartGraphics.rect(o*e,h,t,t),this.rampartGraphics.fill(g))}else if(d&&u&&i[o-1][s+1]!==void 0){const g=n(i[o-1][s+1]);this.rampartGraphics.moveTo(o*e,h),this.rampartGraphics.lineTo(o*e,s*e+e),this.rampartGraphics.lineTo(f,s*e+e),this.rampartGraphics.arc(f,h,t,Math.PI/2,Math.PI,!1),this.rampartGraphics.fill(g)}if(l){const g=n(a);!d&&!p&&s<49&&o<49?(this.rampartGraphics.moveTo(f,s*e+e),this.rampartGraphics.arc(f,h,t,Math.PI/2,0,!0),this.rampartGraphics.lineTo(f,h),this.rampartGraphics.fill(g)):(this.rampartGraphics.rect(f,h,t,t),this.rampartGraphics.fill(g))}else if(d&&p&&i[o+1][s+1]!==void 0){const g=n(i[o+1][s+1]);this.rampartGraphics.moveTo(f,s*e+e),this.rampartGraphics.lineTo(o*e+e,s*e+e),this.rampartGraphics.lineTo(o*e+e,h),this.rampartGraphics.arc(f,h,t,0,Math.PI/2,!1),this.rampartGraphics.fill(g)}}}getObjectsAtTile(e,t){const i=[];for(const[n,s]of this.objects){const o=this.rawObjects.get(n);o&&o.x===e&&o.y===t&&i.push({id:n,obj:o,visual:s})}return i}applyLabelScale(e){if(!e.__nameLabel)return;const t=this.lastWorldScale||1;e.__nameLabel.scale.set(Ci/t),e.__nameLabel.anchor.y===0?e.__nameLabel.y=w/2+w*.55:e.__nameLabel.y=gs-ms/t}refreshForeignCreepLabels(){var e,t;if(this.currentUserId)for(const[i,n]of this.objects){const s=this.rawObjects.get(i);if(!s||s.type!=="creep"||!n.__nameLabel||!Br(s,this.currentUserId))continue;const o=typeof s.user=="string"?s.user:void 0,a=o?((t=(e=this.users)==null?void 0:e[o])==null?void 0:t.username)??o:"Hostile";n.__nameLabel.text!==a&&(n.__nameLabel.text=a)}}refreshForeignCreepBadges(){var e,t;if(this.currentUserId)for(const[i,n]of this.objects){const s=this.rawObjects.get(i);if(!s||s.type!=="creep"||!Br(s,this.currentUserId)||n.__creepBadgeSprite)continue;const o=typeof s.user=="string"?s.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=n.__bodyContainer;if(!l)continue;n.__creepForeignMark&&!n.__creepForeignMark.destroyed&&(l.removeChild(n.__creepForeignMark),n.__creepForeignMark.destroy(),n.__creepForeignMark=void 0);const c=new Ht;c.anchor.set(.5,.5);const d=Be*2;c.width=d,c.height=d,c.rotation=Math.PI/2,l.addChild(c),n.__creepBadgeSprite=c,this.badgeCache.getOrCreate(a).then(u=>{c.destroyed||(c.texture=u)}).catch(()=>{c.destroyed||(l.removeChild(c),c.destroy()),n.__creepBadgeSprite=void 0})}}triggerBuildAt(e,t,i){for(const[n,s]of this.objects){const o=this.rawObjects.get(n);if(!(!o||o.type!=="constructionSite")&&!(o.x!==e||o.y!==t)&&s.__csBuildGlow){this.buildGlowAnimations.set(n,{startTime:performance.now(),duration:i});return}}}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())Jt(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 li=2;function Tt(r,e){return{cx:r*w+w/2,cy:e*w+w/2}}class Jc{constructor(e){_(this,"container");_(this,"graphics");_(this,"animations",[]);_(this,"ticker",null);_(this,"tickerCallback",null);this.container=new Ee,this.graphics=new q,this.container.addChild(this.graphics),e&&(this.ticker=e,this.tickerCallback=()=>this.animate(),e.add(this.tickerCallback))}addHarvest(e,t,i,n,s){const o=Tt(e,t),a=Tt(i,n);this.animations.push({fromX:o.cx,fromY:o.cy,toX:a.cx,toY:a.cy,startTime:performance.now(),duration:s,color:wc,width:li})}addUpgradeController(e,t,i,n,s){const o=Tt(e,t),a=Tt(i,n);this.animations.push({fromX:o.cx,fromY:o.cy,toX:a.cx,toY:a.cy,startTime:performance.now(),duration:s,color:bc,width:li})}addBuild(e,t,i,n,s){const o=Tt(e,t),a=Tt(i,n);this.animations.push({fromX:o.cx,fromY:o.cy,toX:a.cx,toY:a.cy,startTime:performance.now(),duration:s,color:xc,width:li})}animate(){this.graphics.clear();const e=performance.now();let t=!1;for(let i=this.animations.length-1;i>=0;i--){const n=this.animations[i],s=e-n.startTime,o=Math.min(1,s/n.duration);let a,l,c,d;const u=.5,p=.2;if(o<u){const f=o/u;a=n.fromX,l=n.fromY,c=n.fromX+(n.toX-n.fromX)*f,d=n.fromY+(n.toY-n.fromY)*f}else if(o<u+p)a=n.fromX,l=n.fromY,c=n.toX,d=n.toY;else{const f=(o-u-p)/(1-u-p);a=n.fromX+(n.toX-n.fromX)*f,l=n.fromY+(n.toY-n.fromY)*f,c=n.toX,d=n.toY}this.graphics.moveTo(a,l),this.graphics.lineTo(c,d),this.graphics.stroke({width:n.width,color:n.color}),t=!0,o>=1&&this.animations.splice(i,1)}t||this.graphics.clear()}clear(){this.animations.length=0,this.graphics.clear()}destroy(){this.clear(),this.ticker&&this.tickerCallback&&this.ticker.remove(this.tickerCallback),this.ticker=null,this.tickerCallback=null,this.graphics.destroy(),this.container.destroy()}}const Ce=r=>(r+.5)*w,Qt=4,Tr={dashed:[.4*w,.4*w],dotted:[.1*w,.3*w]};function Mr(r,e,t,i){let n=!0,s=t;for(let o=0;o<e.length-1;o++){const[a,l]=e[o],[c,d]=e[o+1],u=c-a,p=d-l,f=Math.sqrt(u*u+p*p);if(f<.001)continue;const h=u/f,g=p/f;let $=0;for(;$<f;){const y=Math.min(s,f-$);if(n){const S=a+h*$,E=l+g*$;r.moveTo(S,E),r.lineTo(S+h*y,E+g*y)}$+=y,s-=y,s<.001&&(n=!n,s=n?t:i)}}}function Qc(r,e,t){const i=Math.max(32,Math.ceil(2*Math.PI*t/2)),n=[];for(let s=0;s<=i;s++){const o=s/i*2*Math.PI;n.push([r+Math.cos(o)*t,e+Math.sin(o)*t])}return n}function ed(r){if(r==null)return .7;if(typeof r=="number")return r;const e=r.match(/^([0-9.]+)(px)?/);if(!e)return .7;const t=parseFloat(e[1]);return e[2]?t/w:t}function td(r){if(typeof r!="string")return"Arial";const e=r.match(/^[0-9.]+(px)?\s+(.+)$/);return e?e[2]:"Arial"}class rd{constructor(){_(this,"container");_(this,"g");this.container=new Ee,this.container.label="visuals",this.g=new q,this.container.addChild(this.g)}update(e){const t=this.container.removeChildren();for(const n of t)n!==this.g&&n.destroy();if(this.g.clear(),this.container.addChild(this.g),!e)return;const i=this.g;for(const n of e.split(`
|
|
9
|
-
`)){if(!n.trim())continue;let s;try{s=JSON.parse(n)}catch{continue}const o=s.s??{},a=o.opacity??1;switch(s.t){case"l":this.drawLine(i,s,o,a);break;case"c":this.drawCircle(i,s,o,a);break;case"r":this.drawRect(i,s,o,a);break;case"p":this.drawPoly(i,s,o,a);break;case"t":this.drawText(s,o,a);break}}}drawLine(e,t,i,n){const s=Ce(t.x1),o=Ce(t.y1),a=Ce(t.x2),l=Ce(t.y2),c=i.color??"#ffffff",d=(i.width??.1)*w;if(i.lineStyle&&i.lineStyle!=="solid"){const[u,p]=Tr[i.lineStyle];Mr(e,[[s,o],[a,l]],u,p)}else e.moveTo(s,o),e.lineTo(a,l);e.stroke({color:c,width:d,alpha:n})}drawCircle(e,t,i,n){const s=Ce(t.x),o=Ce(t.y),a=(i.radius??.5)*w,l=!!(i.fill&&i.fill!=="transparent"),c=!!(i.stroke&&i.strokeWidth),d=i.lineStyle&&i.lineStyle!=="solid";if(l&&(e.circle(s,o,a),e.fill({color:i.fill,alpha:n})),c){const u=i.strokeWidth*w;if(d){const[p,f]=Tr[i.lineStyle];Mr(e,Qc(s,o,a),p,f)}else e.circle(s,o,a);e.stroke({color:i.stroke,width:u,alpha:n})}}drawRect(e,t,i,n){const s=Ce(t.x),o=Ce(t.y),a=t.w*w,l=t.h*w,c=!!(i.fill&&i.fill!=="transparent"),d=!!(i.stroke&&i.strokeWidth),u=i.lineStyle&&i.lineStyle!=="solid";if(c&&(e.rect(s,o,a,l),e.fill({color:i.fill,alpha:n})),d){const p=i.strokeWidth*w;if(u){const[f,h]=Tr[i.lineStyle],g=[[s,o],[s+a,o],[s+a,o+l],[s,o+l],[s,o]];Mr(e,g,f,h)}else e.rect(s,o,a,l);e.stroke({color:i.stroke,width:p,alpha:n})}}drawPoly(e,t,i,n){if(!t.points||t.points.length===0)return;const s=!!(i.fill&&i.fill!=="transparent"),o=!!(i.stroke&&i.strokeWidth);if(!s&&!o)return;const a=i.lineStyle&&i.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[u,p]=t.points[d],f=Ce(u),h=Ce(p);l[d*2]=f,l[d*2+1]=h,c&&(c[d]=[f,h])}if(s&&(e.poly(l,!0),e.fill({color:i.fill,alpha:n})),o){const d=i.strokeWidth*w;if(a&&c){const[u,p]=Tr[i.lineStyle],f=c[0],h=c[c.length-1],g=f[0]===h[0]&&f[1]===h[1];Mr(e,g?c:[...c,f],u,p)}else e.poly(l,!0);e.stroke({color:i.stroke,width:d,alpha:n})}}drawText(e,t,i){const n=ed(t.font),s=td(t.font),o=t.align??"left",a=new eo({fill:t.color??"#ffffff",fontSize:Math.round(n*w*Qt),fontFamily:s,align:o,...t.stroke&&t.strokeWidth?{stroke:{color:t.stroke,width:t.strokeWidth*w*Qt}}:{}});if(t.backgroundColor&&t.backgroundColor!=="transparent"){const c=to.measureText(e.text,a),d=c.width/Qt,u=c.height/Qt,p=(t.backgroundPadding??.3)*w,f=o==="center"?.5:o==="right"?1:0,h=Ce(e.x)-f*d-p,g=Ce(e.y)-u/2-p,$=new q;$.rect(h,g,d+p*2,u+p*2),$.fill({color:t.backgroundColor,alpha:i}),this.container.addChild($)}const l=new zt({text:e.text,style:a});l.scale.set(1/Qt),l.anchor.x=o==="center"?.5:o==="right"?1:0,l.anchor.y=.5,l.position.set(Ce(e.x),Ce(e.y)),l.alpha=i,this.container.addChild(l)}destroy(){const e=this.container.removeChildren();for(const t of e)t!==this.g&&t.destroy();this.g.destroy(),this.container.destroy()}}function xr(r,e){const t=localStorage.getItem(r),[i,n]=G(t!==null?t==="true":e);return[i,s=>{n(s),localStorage.setItem(r,String(s))}]}const[Cs,id]=xr(pe.widescreenMode,!0),[Fi,nd]=xr(pe.showCreepLabels,!0),[ks,Ts]=xr(pe.showMapRoomNames,!1),[Ms,Es]=xr(pe.showUnclaimableRooms,!0),[Gr,sd]=xr(pe.terrainEffects,!0),Hi=Symbol("store-raw"),Bt=Symbol("store-node"),Ye=Symbol("store-has"),Rs=Symbol("store-self");function Ps(r){let e=r[vt];if(!e&&(Object.defineProperty(r,vt,{value:e=new Proxy(r,ld)}),!Array.isArray(r))){const t=Object.keys(r),i=Object.getOwnPropertyDescriptors(r),n=Object.getPrototypeOf(r),s=n!==null&&r!==null&&typeof r=="object"&&!Array.isArray(r)&&n!==Object.prototype;if(s){const o=Object.getOwnPropertyDescriptors(n);t.push(...Object.keys(o)),Object.assign(i,o)}for(let o=0,a=t.length;o<a;o++){const l=t[o];s&&l==="constructor"||i[l].get&&Object.defineProperty(r,l,{configurable:!0,enumerable:i[l].enumerable,get:i[l].get.bind(e)})}}return e}function nt(r){let e;return r!=null&&typeof r=="object"&&(r[vt]||!(e=Object.getPrototypeOf(r))||e===Object.prototype||Array.isArray(r))}function Ut(r,e=new Set){let t,i,n,s;if(t=r!=null&&r[Hi])return t;if(!nt(r)||e.has(r))return r;if(Array.isArray(r)){Object.isFrozen(r)?r=r.slice(0):e.add(r);for(let o=0,a=r.length;o<a;o++)n=r[o],(i=Ut(n,e))!==n&&(r[o]=i)}else{Object.isFrozen(r)?r=Object.assign({},r):e.add(r);const o=Object.keys(r),a=Object.getOwnPropertyDescriptors(r);for(let l=0,c=o.length;l<c;l++)s=o[l],!a[s].get&&(n=r[s],(i=Ut(n,e))!==n&&(r[s]=i))}return r}function Fr(r,e){let t=r[e];return t||Object.defineProperty(r,e,{value:t=Object.create(null)}),t}function gr(r,e,t){if(r[e])return r[e];const[i,n]=G(t,{equals:!1,internal:!0});return i.$=n,r[e]=i}function od(r,e){const t=Reflect.getOwnPropertyDescriptor(r,e);return!t||t.get||!t.configurable||e===vt||e===Bt||(delete t.value,delete t.writable,t.get=()=>r[vt][e]),t}function Os(r){yi()&&gr(Fr(r,Bt),Rs)()}function ad(r){return Os(r),Reflect.ownKeys(r)}const ld={get(r,e,t){if(e===Hi)return r;if(e===vt)return t;if(e===nn)return Os(r),t;const i=Fr(r,Bt),n=i[e];let s=n?n():r[e];if(e===Bt||e===Ye||e==="__proto__")return s;if(!n){const o=Object.getOwnPropertyDescriptor(r,e);yi()&&(typeof s!="function"||r.hasOwnProperty(e))&&!(o&&o.get)&&(s=gr(i,e,s)())}return nt(s)?Ps(s):s},has(r,e){return e===Hi||e===vt||e===nn||e===Bt||e===Ye||e==="__proto__"?!0:(yi()&&gr(Fr(r,Ye),e)(),e in r)},set(){return console.warn("Cannot mutate a Store directly"),!0},deleteProperty(){return console.warn("Cannot mutate a Store directly"),!0},ownKeys:ad,getOwnPropertyDescriptor:od};function Re(r,e,t,i=!1){if(e==="__proto__"){console.warn('Refusing to set "__proto__" on a store.');return}if(!i&&r[e]===t)return;const n=r[e],s=r.length;t===void 0?(delete r[e],r[Ye]&&r[Ye][e]&&n!==void 0&&r[Ye][e].$()):(r[e]=t,r[Ye]&&r[Ye][e]&&n===void 0&&r[Ye][e].$());let o=Fr(r,Bt),a;if((a=gr(o,e,n))&&a.$(()=>t),Array.isArray(r)&&r.length!==s){for(let l=r.length;l<s;l++)(a=o[l])&&a.$();(a=gr(o,"length",s))&&a.$(r.length)}(a=o[Rs])&&a.$()}function Ls(r,e){const t=Object.keys(e);for(let i=0;i<t.length;i+=1){const n=t[i];As(n)||Re(r,n,e[n])}}function As(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function cd(r,e){if(typeof e=="function"&&(e=e(r)),e=Ut(e),Array.isArray(e)){if(r===e)return;let t=0,i=e.length;for(;t<i;t++){const n=e[t];r[t]!==n&&Re(r,t,n)}Re(r,"length",i)}else Ls(r,e)}function ar(r,e,t=[]){let i,n=r;if(e.length>1){i=e.shift();const o=typeof i,a=Array.isArray(r);if(o==="string"&&(i==="__proto__"||e.length>1&&As(i))){console.warn(`Refusing to traverse unsafe key "${i}" on a store.`);return}if(Array.isArray(i)){for(let l=0;l<i.length;l++)ar(r,[i[l]].concat(e),t);return}else if(a&&o==="function"){for(let l=0;l<r.length;l++)i(r[l],l)&&ar(r,[l].concat(e),t);return}else if(a&&o==="object"){const{from:l=0,to:c=r.length-1,by:d=1}=i;for(let u=l;u<=c;u+=d)ar(r,[u].concat(e),t);return}else if(e.length>1){ar(r[i],e,[i].concat(t));return}n=r[i],t=[i].concat(t)}let s=e[0];typeof s=="function"&&(s=s(n,t),s===n)||i===void 0&&s==null||(s=Ut(s),i===void 0||nt(n)&&nt(s)&&!Array.isArray(s)?Ls(n,s):Re(r,i,s))}function dd(...[r,e]){const t=Ut(r||{}),i=Array.isArray(t);if(typeof t!="object"&&typeof t!="function")throw new Error(`Unexpected type ${typeof t} received when initializing 'createStore'. Expected an object.`);const n=Ps(t);js.registerGraph({value:t,name:e&&e.name});function s(...o){Zs(()=>{i&&o.length===1?cd(t,o[0]):ar(t,o)})}return[n,s]}const Wi=Symbol("store-root");function Sn(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function Ot(r,e,t,i,n){if(Sn(t))return;const s=e[t];if(r===s)return;const o=Array.isArray(r);if(t!==Wi&&(!nt(r)||!nt(s)||o!==Array.isArray(s)||n&&r[n]!==s[n])){Re(e,t,r);return}if(o){if(r.length&&s.length&&(!i||n&&r[0]&&r[0][n]!=null)){let c,d,u,p,f,h,g,$;for(u=0,p=Math.min(s.length,r.length);u<p&&(s[u]===r[u]||n&&s[u]&&r[u]&&s[u][n]&&s[u][n]===r[u][n]);u++)Ot(r[u],s,u,i,n);const y=new Array(r.length),S=new Map;for(p=s.length-1,f=r.length-1;p>=u&&f>=u&&(s[p]===r[f]||n&&s[p]&&r[f]&&s[p][n]&&s[p][n]===r[f][n]);p--,f--)y[f]=s[p];if(u>f||u>p){for(d=u;d<=f;d++)Re(s,d,r[d]);for(;d<r.length;d++)Re(s,d,y[d]),Ot(r[d],s,d,i,n);s.length>r.length&&Re(s,"length",r.length);return}for(g=new Array(f+1),d=f;d>=u;d--)h=r[d],$=n&&h?h[n]:h,c=S.get($),g[d]=c===void 0?-1:c,S.set($,d);for(c=u;c<=p;c++)h=s[c],$=n&&h?h[n]:h,d=S.get($),d!==void 0&&d!==-1&&(y[d]=s[c],d=g[d],S.set($,d));for(d=u;d<r.length;d++)d in y?(Re(s,d,y[d]),Ot(r[d],s,d,i,n)):Re(s,d,r[d])}else for(let c=0,d=r.length;c<d;c++)Ot(r[c],s,c,i,n);s.length>r.length&&Re(s,"length",r.length);return}const a=Object.keys(r);for(let c=0,d=a.length;c<d;c++)Sn(a[c])||Ot(r[a[c]],s,a[c],i,n);const l=Object.keys(s);for(let c=0,d=l.length;c<d;c++)r[l[c]]===void 0&&Re(s,l[c],void 0)}function hd(r,e={}){const{merge:t,key:i="id"}=e,n=Ut(r);return s=>{if(!nt(s)||!nt(n))return n;const o=Ot(n,{[Wi]:s},Wi,t,i);return o===void 0?s:o}}const Is=new WeakMap;function Cn(r,e){const[t,i]=dd(e),n={id:r,type:e.type,raw:t};return Is.set(n,s=>i(hd(s,{key:"_id",merge:!1}))),n}const[Hr,mr]=G([]);function ud(){mr([])}function Er(r){mr(e=>e.filter(t=>t.id!==r))}function fd(r,e){const t=Hr();let i=!1;const n=[];for(const s of t){const o=r[s.id];if(o===null){i=!0;continue}if(o!==void 0){const a=e[s.id];if(a){const l=Is.get(s);l==null||l(a)}}n.push(s)}i&&mr(n)}const[pd,kn]=G(null),[Ns,Tn]=G(null),[Dt,Mn]=G(null),[Wr,En]=G({}),[gd,Rn]=G(null);function Ui(r,e,t){return isNaN(t.minX)||isNaN(t.maxX)||isNaN(t.minY)||isNaN(t.maxY)?!0:r>=t.minX&&r<=t.maxX&&e>=t.minY&&e<=t.maxY}function je(r){const e=r.match(/^([WE])(\d+)([NS])(\d+)$/);if(!e)return null;const[,t,i,n,s]=e,o=t==="W"?-(parseInt(i,10)+1):parseInt(i,10),a=n==="N"?-(parseInt(s,10)+1):parseInt(s,10);return{x:o,y:a}}function Ie(r,e){const t=r<0?"W":"E",i=e<0?"N":"S",n=r<0?-r-1:r,s=e<0?-e-1:e;return`${t}${n}${i}${s}`}function Pn(r){return r===0||r<0&&(r+1)%10===0||r>0&&r%10===0}function Nf(r,e){return Pn(r)||Pn(e)}function Gf(r,e){const t=r<0?Math.abs(r+1)%10:Math.abs(r)%10,i=e<0?Math.abs(e+1)%10:Math.abs(e)%10;return t>=4&&t<=6&&i>=4&&i<=6}function Gs(r){const e=r;if(!e)return!1;const t=e.tagName??"";return t==="INPUT"||t==="TEXTAREA"?!0:e.isContentEditable===!0}function md(r){const e=t=>{if(Gs(t.target))return;const i=r.currentRoom(),n=i?je(i):null;if(!n)return;const s=r.worldBounds(),o=(a,l)=>!s||Ui(a,l,s);switch(t.key){case"ArrowLeft":t.preventDefault(),o(n.x-1,n.y)&&r.onMove(n.x-1,n.y);break;case"ArrowRight":t.preventDefault(),o(n.x+1,n.y)&&r.onMove(n.x+1,n.y);break;case"ArrowUp":t.preventDefault(),o(n.x,n.y-1)&&r.onMove(n.x,n.y-1);break;case"ArrowDown":t.preventDefault(),o(n.x,n.y+1)&&r.onMove(n.x,n.y+1);break}};window.addEventListener("keydown",e),Ge(()=>window.removeEventListener("keydown",e))}var yd=R('<div style=text-align:center;display:flex;flex-direction:column;align-items:center;gap:6px><div style=font-size:14px;font-weight:600;color:#f85149>You have no rooms!</div><button style="padding:4px 12px;border-radius:4px;border:1px solid #238636;background:#1a3a2a;color:#3fb950;font-size:12px;cursor:pointer">Place Spawn'),vd=R('<div style=text-align:center;display:flex;flex-direction:column;align-items:center;gap:6px><div style=font-size:14px;font-weight:600;color:#f85149>You lost all your spawns!</div><button style="padding:4px 12px;border-radius:4px;border:1px solid #da3633;background:#3d1a1a;color:#f85149;font-size:12px;cursor:pointer">Respawn'),wd=R("<span>Choose new flag position"),ci=R("<span>"),bd=R("<span>Select structure type, then click to build — Ctrl+click to remove construction sites");const{log:On,warn:xd,error:Ln}=xt("build"),yr={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},Ur={spawn:{0:0,1:1,2:1,3:1,4:1,5:1,6:1,7:2,8:3},extension:{0:0,1:0,2:5,3:10,4:20,5:30,6:40,7:50,8:60},link:{1:0,2:0,3:0,4:0,5:2,6:3,7:4,8:6},road:{0:2500,1:2500,2:2500,3:2500,4:2500,5:2500,6:2500,7:2500,8:2500},constructedWall:{1:0,2:2500,3:2500,4:2500,5:2500,6:2500,7:2500,8:2500},rampart:{1:0,2:2500,3:2500,4:2500,5:2500,6:2500,7:2500,8:2500},storage:{1:0,2:0,3:0,4:1,5:1,6:1,7:1,8:1},tower:{1:0,2:0,3:1,4:1,5:2,6:2,7:3,8:6},observer:{1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:1},powerSpawn:{1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:1},extractor:{1:0,2:0,3:0,4:0,5:0,6:1,7:1,8:1},terminal:{1:0,2:0,3:0,4:0,5:0,6:1,7:1,8:1},lab:{1:0,2:0,3:0,4:0,5:0,6:3,7:6,8:10},container:{0:5,1:5,2:5,3:5,4:5,5:5,6:5,7:5,8:5},nuker:{1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:1},factory:{1:0,2:0,3:0,4:0,5:0,6:0,7:1,8:1}},[bt,ft]=G("view"),[Lt,Ds]=G({name:"",color:"COLOR_WHITE",secondaryColor:"COLOR_WHITE"}),[yt,Xi]=G(null),[tn,Yi]=G(null),[Ze,pt]=G({structureType:"",structureName:""});Un(()=>{he(()=>{const r=Ze().structureType;if(!r)return;const e=Dt()??0,t=Ur[r];if(!t)return;const i=wt()==="empty"&&r==="spawn"?Math.max(t[e]??0,1):t[e]??0;if(i===2500)return;(Wr()[r]??0)>=i&&(pt({structureType:"",structureName:""}),it())})});function it(){Xi(null)}function qi(){Yi(null)}function _d(){pt({structureType:"",structureName:""})}function $d(r,e){const t=ae(),i=Ze(),n=yt();if(!t||!i.structureType||!n){xd("missing requirements",{hasClient:!!t,structureType:i.structureType,pending:n});return}if(wt()==="empty"&&i.structureType==="spawn"){On("placing spawn",{room:r,x:n.tx,y:n.ty,name:i.structureName||void 0,shard:e??void 0}),t.http.game.placeSpawn(r,n.tx,n.ty,i.structureName||void 0,e??void 0).then(()=>(ge("Spawn placed successfully","success"),it(),t.stores.user.refreshWorldStatus())).catch(s=>{Ln("place spawn failed:",s),ge(`Failed to place spawn: ${s.message}`,"error")});return}On("creating construction site",{room:r,x:n.tx,y:n.ty,structureType:i.structureType,name:i.structureName||void 0,shard:e??void 0}),t.http.game.createConstruction(r,n.tx,n.ty,i.structureType,i.structureName||void 0,e??void 0).then(()=>{ge(`Construction site for ${i.structureType} created`,"success"),it()}).catch(s=>{Ln("create construction failed:",s),ge(`Failed to create construction site: ${s.message}`,"error")})}function Sd(){ft("view"),it(),qi(),_d()}function An(){const r=bt(),e=yt(),t=tn(),i=wt();if(i==="empty")return(()=>{var n=yd(),s=n.firstChild,o=s.nextSibling;return o.$$click=()=>{ft("build"),pt({structureType:"spawn",structureName:""})},n})();if(i==="lost")return(()=>{var n=vd(),s=n.firstChild,o=s.nextSibling;return o.$$click=()=>{const a=ae();a&&a.http.user.respawn().then(()=>{ge("Respawn successful","success"),a.stores.user.refreshWorldStatus()}).catch(l=>{ge(`Respawn failed: ${l.message}`,"error")})},n})();if((t==null?void 0:t.type)==="moveFlag")return wd();if(r==="flag")return(()=>{var n=ci();return v(n,e?"Confirm position":"Choose position"),n})();if(r==="build"){const n=Ze(),s=Dt(),o=Wr(),a=n.structureType,l=" — Ctrl+click to remove construction sites";if(!a)return bd();const c=Ur[a],d=(c==null?void 0:c[s??0])??0,u=o[a]??0,p=a.replace(/([A-Z])/g," $1").trim();return d===2500?(()=>{var f=ci();return v(f,`Click to build ${p} (${u}/∞)${l}`),f})():(()=>{var f=ci();return v(f,`Click to build ${p} (${u}/${d})${l}`),f})()}return null}ke(["click"]);var Cd=R("<div style=width:100%;height:100%;position:relative><div style=width:100%;height:100%>"),kd=R('<div style="position:absolute;top:12px;left:50%;transform:translateX(-50%);padding:6px 16px;border-radius:6px;background:rgba(13, 17, 23, 0.65);border:1px solid rgba(48, 54, 61, 0.6);font-size:13px;font-weight:500;color:#c9d1d9;user-select:none;z-index:10">'),Td=R('<div style="position:absolute;top:8px;right:8px;padding:4px 10px;border-radius:4px;background:rgba(13, 17, 23, 0.8);border:1px solid #30363d;font-size:12px;color:#8b949e;z-index:10">Tick ');const{log:er,error:tr}=xt("room");function Md(r){let e,t=null,i=null,n=null,s=null;const[o,a]=G(null),[l,c]=G(null),[d,u]=G(null),[p,f]=G("");return vr(async()=>{if(!e)return;const h=await Ki.create(e);a(h)}),Ge(()=>{t==null||t.destroy(),t=null,i==null||i.destroy(),i=null,n==null||n.destroy(),n=null;const h=o();h&&h.destroy()}),he(()=>{const h=ae();if(!h)return;const g=r.room,$=r.shard;c(null),u(null),f(""),xi(null),ud(),kn(null),Tn(null),Mn(null),En({}),Rn(null);const y=new ji;let S=!1;h.stores.room.terrain(g,$).then(E=>{S||c({room:g,data:E})}).catch(E=>{S||tr(`terrain load failed for ${g}:`,E)}),y.add(h.stores.room.subscribe(g,$)),y.add(h.stores.room.on("room:error",E=>{ge(`Room subscription error (${E.room}): ${E.message}`,"error",8e3)})),y.add(h.stores.room.on("room:update",E=>{var b,k;let x=0;const m={};let M=0,T=null;for(const A in E.objects){x++;const P=E.objects[A];if(!P)continue;const N=P.type;if(typeof N=="string")if(N==="constructionSite"){const O=P.structureType;typeof O=="string"&&(m[O]=(m[O]||0)+1)}else m[N]=(m[N]||0)+1;if(N==="controller"&&typeof P.user=="string"){const O=P.user,L=((k=(b=E.users)==null?void 0:b[O])==null?void 0:k.username)??O;T={userId:O,username:L},typeof P.level=="number"&&(M=P.level)}}E.diff||er(`objects loaded — ${g}: ${x} objects, tick=${E.gameTime}`),u({objects:E.objects,diff:E.diff,users:E.users}),f(E.visual),xi(E.gameTime??null),ya(E.gameTime),kn(x),Tn(T),Mn(M||null),En(m),Rn(E.users??null)})),Ge(()=>{S=!0,y.dispose()})}),he(()=>{const h=o();if(!h)return;r.room,r.shard,Sd(),h.hoverLayer.clearPendingTile(),s==null||s.destroy(),s=null,h.clear(),h.resetView(),t==null||t.destroy(),t=null,i==null||i.destroy(),i=null,n==null||n.destroy(),n=null;const g=we(l);g&&g.room===r.room&&(er(`terrain applied immediately (pre-loaded) — ${r.room}`),s=bn(g.data,h.app.renderer),ai(s,we(Gr)),h.world.addChildAt(s,0),h.bringNavOverlayToTop());const $=r.room,y=r.shard,S=je($),E=we(()=>r.onNavigate),x=we(ii);if(S&&E){const m=(T,b)=>!x||Ui(T,b,x),M=T=>{E(T,y)};h.setupNavigationZones({west:m(S.x-1,S.y)?()=>M(Ie(S.x-1,S.y)):void 0,east:m(S.x+1,S.y)?()=>M(Ie(S.x+1,S.y)):void 0,north:m(S.x,S.y-1)?()=>M(Ie(S.x,S.y-1)):void 0,south:m(S.x,S.y+1)?()=>M(Ie(S.x,S.y+1)):void 0})}}),he(()=>{const h=o();if(!h)return;const g=we(()=>r.room),$=we(()=>r.shard),y=je(g);if(y&&r.onNavigate){const S=r.onNavigate,E=ii(),x=(M,T)=>!E||Ui(M,T,E),m=M=>{S(M,$)};md({currentRoom:()=>r.room,worldBounds:ii,onMove:(M,T)=>m(Ie(M,T))}),h.setupNavigationZones({west:x(y.x-1,y.y)?()=>m(Ie(y.x-1,y.y)):void 0,east:x(y.x+1,y.y)?()=>m(Ie(y.x+1,y.y)):void 0,north:x(y.x,y.y-1)?()=>m(Ie(y.x,y.y-1)):void 0,south:x(y.x,y.y+1)?()=>m(Ie(y.x,y.y+1)):void 0})}}),he(()=>{const h=bt(),g=o();h==="view"&&g&&(it(),g.hoverLayer.clearPendingTile())}),he(()=>{const h=o(),g=yt();h&&(g?h.hoverLayer.setPendingTile(g.tx,g.ty):h.hoverLayer.clearPendingTile())}),he(()=>{const h=o(),g=l();if(!(!h||!g||g.room!==r.room)){if(s!=null&&s.parent){er(`terrain already in scene, skipping — ${r.room}`);return}er(`terrain applied (async) — ${r.room}`),s=bn(g.data,h.app.renderer),ai(s,we(Gr)),h.world.addChildAt(s,0),h.bringNavOverlayToTop()}}),he(()=>{var E,x;const h=o(),g=d();if(!h||!g)return;const{objects:$,diff:y,users:S}=g;if(t||(er(`object layer created — ${r.room}`),t=new Kc(h.app.ticker,Fi(),(E=Oe())==null?void 0:E._id,(x=Oe())==null?void 0:x.badge,S),t.container.label="objects",h.world.addChild(t.container),h.bringNavOverlayToTop(),i=new Jc(h.app.ticker),i.container.label="animations",h.world.addChild(i.container),n=new rd,h.world.addChild(n.container),h.bringNavOverlayToTop(),h.setTileHandlers((m,M)=>{},(m,M,T)=>{const b=r.room,k=r.shard,A=bt(),P=tn();if((P==null?void 0:P.type)==="moveFlag"){const z=ae();if(!z)return;const{name:F,room:U,color:Z,secondaryColor:de}=P;z.http.game.removeFlag(U,F).then(()=>z.http.game.createFlag(b,m,M,F,Z,de,k??void 0)).then(()=>{ge(`Flag "${F}" moved`,"success"),qi()}).catch(re=>{tr("move flag failed:",re),ge(`Failed to move flag "${F}"`,"error"),qi()});return}if(A==="flag"){const z=yt();if(!z||z.tx!==m||z.ty!==M){Xi({tx:m,ty:M}),h.hoverLayer.setPendingTile(m,M);return}const F=ae();if(!F)return;const U=Lt(),Z=U.name.trim();if(!Z){ge("Flag name is required","error");return}const de=yr[U.color]??0,re=yr[U.secondaryColor]??0;F.http.game.createFlag(b,m,M,Z,de,re,k??void 0).then(()=>{ge(`Flag "${Z}" created`,"success"),it(),h.hoverLayer.clearPendingTile(),F.http.game.genUniqueFlagName().then(W=>Ds(Y=>({...Y,name:W.name}))).catch(W=>tr("gen unique flag name failed:",W))}).catch(W=>tr("create flag failed:",W));return}if(A==="build"){if(!T&&!Ze().structureType){ge("Select a structure type first","error");return}if(T){if(!t)return;const F=t.getObjectsAtTile(m,M).filter(({obj:Z})=>Z.type==="constructionSite");if(F.length===0){ge("No construction sites on this tile","error");return}const U=ae();if(!U)return;U.http.game.removeConstructionSite(b,F.map(({id:Z})=>Z),k??void 0).then(()=>{ge(`Removed ${F.length} construction site${F.length>1?"s":""}`,"success"),it(),h.hoverLayer.clearPendingTile()}).catch(Z=>{tr("remove construction sites failed:",Z),ge(`Failed to remove construction sites: ${Z.message}`,"error")});return}Xi({tx:m,ty:M}),h.hoverLayer.setPendingTile(m,M),$d(b,k);return}if(it(),h.hoverLayer.clearPendingTile(),!t)return;const N=t.getObjectsAtTile(m,M);if(N.length===0){T||(mr([]),h.hoverLayer.clearSelection());return}let O=[...Hr()];if(T){const z=new Set(N.map(U=>U.id));if(O.some(U=>z.has(U.id)))O=O.filter(U=>!z.has(U.id));else{const U=N.filter(({id:Z})=>!O.some(de=>de.id===Z)).map(({id:Z,obj:de})=>Cn(Z,de));O=[...O,...U]}}else O=N.map(({id:z,obj:F})=>Cn(z,F));mr(O);const L=O.map(({id:z,type:F})=>({id:z,type:F,visual:t.getVisualById(z)})).filter(z=>z.visual!=null);h.hoverLayer.setSelectedObjects(L)})),y&&fd(y,$),t.update($,y,S),i){i.clear();const m=(_i()??2e3)*.6;for(const M in $){const T=$[M];if(!T||T.type!=="creep")continue;const b=T.actionLog;if(b){if(b.harvest){const k=b.harvest;i.addHarvest(k.x,k.y,T.x,T.y,m)}if(b.upgradeController){const k=b.upgradeController;i.addUpgradeController(T.x,T.y,k.x,k.y,m)}if(b.build){const k=b.build;i.addBuild(T.x,T.y,k.x,k.y,m),t==null||t.triggerBuildAt(k.x,k.y,m)}}}}}),he(()=>{const h=p();n==null||n.update(h)}),he(()=>{t==null||t.setShowLabels(Fi())}),he(()=>{const h=Gr();s&&ai(s,h)}),(()=>{var h=Cd(),g=h.firstChild;return lr($=>e=$,g),v(h,(()=>{var $=ee(()=>!!An());return()=>$()&&(()=>{var y=kd();return v(y,An),I(S=>B(y,"pointer-events",wt()==="empty"||wt()==="lost"?"auto":"none")),y})()})(),null),v(h,(()=>{var $=ee(()=>Wt()!==null);return()=>$()&&(()=>{var y=Td();return y.firstChild,v(y,Wt,null),y})()})(),null),h})()}var Ed=R("<div style=position:fixed;bottom:16px;right:16px;display:flex;flex-direction:column;gap:8px;z-index:9999;pointer-events:none>"),Rd=R('<div style="padding:10px 16px;border-radius:6px;font-size:13px;color:#fff;box-shadow:0 4px 12px rgba(0,0,0,0.4);max-width:320px;word-break:break-word;pointer-events:auto;animation:toast-in 0.2s ease">');function Pd(){return(()=>{var r=Ed();return v(r,C(ye,{get each(){return aa()},children:e=>(()=>{var t=Rd();return v(t,()=>e.message),I(i=>B(t,"background",e.type==="error"?"#da3633":"#238636")),t})()})),r})()}const[rr,Od]=G(!0),[Mt,Ld]=G(!0);function zs(){Od(r=>!r)}function Bs(){Ld(r=>!r)}var Ad=R("<div style=overflow:auto;padding:8px>"),Id=R("<div style=width:4px;flex-shrink:0;cursor:col-resize>"),Nd=R('<div style=flex:1;display:flex;flex-direction:column;overflow:hidden><div style=flex:1;overflow:auto;padding:8px></div><form style="display:flex;gap:6px;padding:8px;border-top:1px solid #30363d"><span style=color:#8b949e;font-size:13px;line-height:28px>></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'),Gd=R("<div style=flex:1;display:flex;overflow:hidden>"),Dd=R('<div style=display:flex;flex-direction:column;height:100%;background:#0d1117><div style="height:32px;flex-shrink:0;padding:0 10px;border-bottom:1px solid #30363d;display:flex;align-items:center;gap:6px"><button>Log</button><button>Console</button><div style=margin-left:auto><button style=background:transparent;border:none;color:#8b949e;font-size:11px;cursor:pointer>Clear'),zd=R("<div style=color:#484f58;font-style:italic>No log output yet…"),Bd=R("<div style=margin-bottom:4px;color:#f85149;white-space:pre-wrap;word-break:break-word>"),Fd=R("<div style=margin-bottom:4px;color:#c9d1d9;white-space:pre-wrap;word-break:break-word>"),Hd=R("<div style=color:#484f58;font-style:italic>No command results yet…"),Wd=R("<div style=margin-bottom:4px;color:#58a6ff;white-space:pre-wrap;word-break:break-word>");const{error:Ud}=xt("console");function Xd(r){const[e,t]=G([]),[i,n]=G(""),[s,o]=G(!0),[a,l]=G(or(pe.consoleSplit,50)),[c,d]=G(!1);let u,p,f,h=0;vr(()=>{const T=ae();if(!T)return;const b=new ji;b.add(T.stores.user.subscribe("console")),b.add(T.stores.user.on("user:console",k=>{const A=k.messages,P={id:h++,log:A.log??[],results:A.results??[],error:A.error??[]};t(N=>{const O=[...N,P];return O.length>200?O.slice(O.length-200):O})})),Ge(()=>b.dispose())}),he(()=>{e(),s()&&requestAnimationFrame(()=>{rr()&&u&&(u.scrollTop=u.scrollHeight),Mt()&&p&&(p.scrollTop=p.scrollHeight)})});const g=(T,b)=>{var A,P;const k=!T&&!b;k&&!r.isCollapsed&&((A=r.onToggle)==null||A.call(r)),!k&&r.isCollapsed&&((P=r.onToggle)==null||P.call(r))};he(()=>{g(rr(),Mt())});const $=T=>{T.preventDefault(),d(!0);const k=f.getBoundingClientRect(),A=N=>{const O=(N.clientX-k.left)/k.width*100,L=Math.max(15,Math.min(85,O));l(L),Or(pe.consoleSplit,L)},P=()=>{d(!1),window.removeEventListener("pointermove",A),window.removeEventListener("pointerup",P)};window.addEventListener("pointermove",A),window.addEventListener("pointerup",P)},y=async T=>{T.preventDefault();const b=ae();if(!(!b||!i().trim()))try{await b.http.user.console(i().trim(),r.shard??"shard0"),n("")}catch(k){Ud("command failed:",k)}},S=T=>({background:T?"#30363d":"transparent",border:`1px solid ${T?"#58a6ff":"transparent"}`,color:T?"#c9d1d9":"#8b949e","font-size":"12px",cursor:"pointer",padding:"2px 10px","border-radius":"4px"}),E=()=>e().flatMap(T=>T.log),x=()=>e().flatMap(T=>T.error),m=()=>e().flatMap(T=>T.results),M={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"};return(()=>{var T=Dd(),b=T.firstChild,k=b.firstChild,A=k.nextSibling,P=A.nextSibling,N=P.firstChild;return Dr(k,"click",zs,!0),Dr(A,"click",Bs,!0),N.$$click=()=>t([]),v(T,C(H,{get when(){return!r.isCollapsed},get children(){var O=Gd();return lr(L=>f=L,O),v(O,C(H,{get when(){return rr()},get children(){var L=Ad();L.addEventListener("scroll",()=>{u&&o(u.scrollHeight-u.scrollTop-u.clientHeight<20)});var z=u;return typeof z=="function"?lr(z,L):u=L,v(L,(()=>{var F=ee(()=>E().length===0&&x().length===0);return()=>F()&&zd()})(),null),v(L,C(ye,{get each(){return x()},children:F=>(()=>{var U=Bd();return U.innerHTML=F,U})()}),null),v(L,C(ye,{get each(){return E()},children:F=>(()=>{var U=Fd();return U.innerHTML=F,U})()}),null),I(F=>X(L,{...Mt()?{width:`${a()}%`,"flex-shrink":0}:{flex:1},...M},F)),L}}),null),v(O,C(H,{get when(){return ee(()=>!!rr())()&&Mt()},get children(){var L=Id();return L.$$pointerdown=$,I(z=>B(L,"background",c()?"#388bfd":"#21262d")),L}}),null),v(O,C(H,{get when(){return Mt()},get children(){var L=Nd(),z=L.firstChild,F=z.nextSibling,U=F.firstChild,Z=U.nextSibling;Z.nextSibling,z.addEventListener("scroll",()=>{p&&o(p.scrollHeight-p.scrollTop-p.clientHeight<20)});var de=p;return typeof de=="function"?lr(de,z):p=z,v(z,(()=>{var re=ee(()=>m().length===0);return()=>re()&&Hd()})(),null),v(z,C(ye,{get each(){return m()},children:re=>(()=>{var W=Wd();return W.innerHTML=re,W})()}),null),F.addEventListener("submit",y),Z.$$input=re=>n(re.currentTarget.value),I(re=>X(z,{...M},re)),I(()=>Z.value=i()),L}}),null),I(L=>B(O,"user-select",c()?"none":"auto")),O}}),null),I(O=>{var L=S(rr()),z=S(Mt());return O.e=X(k,L,O.e),O.t=X(A,z,O.t),O},{e:void 0,t:void 0}),T})()}ke(["click","pointerdown","input"]);const Yd={1:2e4,2:1e4,3:2e4,4:4e4,5:8e4,6:12e4,7:15e4,8:2e5};var qd=R("<div style=display:flex;gap:5px;flex-wrap:wrap>"),Vd=R("<div style=width:18px;height:18px;border-radius:50%;cursor:pointer;flex-shrink:0>");const jd=[{label:"Red",value:1,css:"#ff0000"},{label:"Purple",value:2,css:"#800080"},{label:"Blue",value:3,css:"#0000ff"},{label:"Cyan",value:4,css:"#00ffff"},{label:"Green",value:5,css:"#008000"},{label:"Yellow",value:6,css:"#ffff00"},{label:"Orange",value:7,css:"#ffa500"},{label:"Brown",value:8,css:"#a52a2a"},{label:"Grey",value:9,css:"#808080"},{label:"White",value:10,css:"#ffffff"}];function Xr(r){return(()=>{var e=qd();return v(e,C(ye,{each:jd,children:t=>(()=>{var i=Vd();return i.$$click=()=>r.onChange(t.value),I(n=>{var s=t.label,o=t.css,a=r.value===t.value?"0 0 0 2px #0d1117, 0 0 0 4px #c9d1d9":"none";return s!==n.e&&be(i,"title",n.e=s),o!==n.t&&B(i,"background",n.t=o),a!==n.a&&B(i,"box-shadow",n.a=a),n},{e:void 0,t:void 0,a:void 0}),i})()})),e})()}ke(["click"]);var Ft=R("<div>"),Yr=R("<div style=font-variant-numeric:tabular-nums>"),Zd=R("<span style=font-variant-numeric:tabular-nums;font-weight:400> / "),Kd=R('<div style="background:#21262d;border-top:1px solid #30363d;font-size:10px"><div style="padding:4px 8px;background:#161b22;color:#8b949e;font-weight:600;display:flex;justify-content:space-between"><span>Store Contents</span></div><div style="display:grid;grid-template-columns:1fr 1fr;gap:1px;background:#21262d">'),Jd=R('<div style="padding:3px 8px;background:#0d1117;color:#8b949e">'),Qd=R('<div style="padding:3px 8px;background:#0d1117;color:#c9d1d9;font-variant-numeric:tabular-nums">'),eh=R("<div>Owner"),Fs=R("<div>Hits"),rn=R("<div style=font-variant-numeric:tabular-nums> / "),th=R("<div>Time to live"),rh=R("<div>Fatigue"),ih=R('<div style="background:#21262d;border-top:1px solid #30363d;font-size:10px"><div style="padding:4px 8px;background:#161b22;color:#8b949e;font-weight:600">Body (<!>)</div><div style=display:flex;flex-wrap:wrap;gap:3px;padding:8px;background:#0d1117>'),nh=R("<div><div>"),sh=R("<div style=width:11px;height:11px;border-radius:50%;flex-shrink:0>"),oh=R('<div style=padding:8px;display:flex;flex-direction:column;gap:8px;background:#0d1117><label>Primary color</label><label>Secondary color</label><div style=display:flex;gap:6px><button style="flex:1;border-radius:4px;padding:5px 8px;font-size:11px;transition:background 150ms ease, color 150ms ease, border-color 150ms ease">Apply color</button><button style="border-radius:4px;padding:5px 8px;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background 150ms ease, color 150ms ease">'),ah=R("<div>Level"),lh=R("<div>Progress"),ch=R("<div>Safe modes"),dh=R("<div>Power"),hh=R("<div>Downgrade in"),uh=R("<div>Safe mode active"),fh=R("<div style=font-variant-numeric:tabular-nums> ticks"),ph=R('<div style=padding:8px;display:flex;flex-direction:column;gap:6px;background:#0d1117><button style="color:#fff;border:none;border-radius:4px;padding:6px 8px;font-size:12px">Activate safe mode</button><button style="color:#fff;border:none;border-radius:4px;padding:6px 8px;font-size:12px;cursor:pointer">'),gh=R("<div><div><div>Owner</div><div>"),mh=R("<div>Reserved"),yh=R("<div> (<!>)"),vh=R("<div>Notify when attacked"),wh=R("<div style=display:flex;align-items:center><button style=background:transparent;border:none;cursor:pointer;padding:0;display:flex;align-items:center>"),bh=R("<div><div>Energy</div><div style=font-variant-numeric:tabular-nums> / "),xh=R("<div style=width:8px;height:8px;border-radius:50%;flex-shrink:0>"),di=R('<button style="background:transparent;border:none;cursor:pointer;padding:0 2px;display:flex;align-items:center;justify-content:center;flex-shrink:0">'),_h=R('<div style="border-radius:6px;margin-bottom:6px;overflow:hidden;transition:border-color 150ms ease"><div style="display:flex;align-items:center;gap:7px;padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d"><span style=font-size:11px;font-weight:600;color:#c9d1d9;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:flex;align-items:center;gap:5px></span><span style=font-size:10px;color:#484f58;flex-shrink:0;margin-right:2px>(<!>,<!>)</span><button title=Deselect style="background:transparent;border:none;color:#8b949e;cursor:pointer;padding:0 4px;font-size:14px;line-height:1;display:flex;align-items:center;justify-content:center">×'),$h=R("<span style=font-weight:400;color:#8b949e>"),Sh=R("<div style=flex:1;overflow:auto;min-height:0;padding:8px>"),Ch=R("<div style=color:#484f58;font-style:italic;font-size:12px>Click a tile to select objects…");const{log:In,error:Xt}=xt("SelectionList"),kh={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"},Th={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"},Mh=new Set(["x","y","type","id","name","user","_id","room","hitsMax","energyCapacity","body","storeCapacity","storeCapacityResource"]),Nn=new Set(["hits","energy","energyCapacity","store","progress","progressTotal","nextDecayTime"]),Gn={hits:"Hits",energy:"Energy",progress:"Progress",progressTotal:"Progress total",ticksToLive:"Ticks to live",ticksToRegeneration:"Ticks to regen",ticksToDecay:"Ticks to decay",nextDecayTime:"Decays in",fatigue:"Fatigue",cooldown:"Cooldown",mineralType:"Mineral type",mineralAmount:"Mineral amount",density:"Density",notifyWhenAttacked:"Notify when attacked",isPublic:"Public",structureType:"Structure type",level:"Level",power:"Power",powerCapacity:"Power capacity",depositType:"Deposit type",lastCooldown:"Last cooldown",resourceType:"Resource type",amount:"Amount",decay:"Decay in",mode:"Mode",actionLog:"Action log",store:"Store"};function Eh(r){return Gn[r]?Gn[r]:r.replace(/([A-Z])/g," $1").replace(/^./,e=>e.toUpperCase()).trim()}function Rh(r){return typeof r=="number"?String(r):typeof r=="string"?r:typeof r=="boolean"?r?"Yes":"No":null}function Dn(r){if(r>=1e6){const e=r/1e6;return`${parseFloat(e.toFixed(2))}M`}if(r>=1e3){const e=r/1e3;return`${parseFloat(e.toFixed(1))}K`}return String(r)}const ne=(r=!1)=>({padding:"3px 8px",background:"#0d1117",color:r?"#8b949e":"#c9d1d9",overflow:"hidden","text-overflow":"ellipsis","white-space":"nowrap"}),Kr={display:"grid","grid-template-columns":"1fr 1fr",gap:"1px",background:"#21262d","font-size":"10px"};function Ph(r){const e=()=>{const t=r.item.raw,i=[];for(const n in t){if(Mh.has(n))continue;const s=t[n];let o=Rh(s);if(!(n==="notifyWhenAttacked"&&s===!1)&&!(n==="off"&&s===!1)){if(n==="hits"&&typeof t.hitsMax=="number"&&(o=`${s} / ${t.hitsMax}`),n==="energy"&&typeof t.energyCapacity=="number"&&(o=`${s} / ${t.energyCapacity}`),n==="nextDecayTime"&&typeof s=="number"){const a=Wt();a!==null&&(o=String(s-a))}o!==null&&i.push({key:n,label:Eh(n),value:o})}}return i.sort((n,s)=>{const o=Nn.has(n.key)?0:1,a=Nn.has(s.key)?0:1;return o-a}),i};return C(H,{get when(){return e().length>0},get children(){var t=Ft();return v(t,C(ye,{get each(){return e()},children:i=>[(()=>{var n=Ft();return v(n,()=>i.label),I(s=>X(n,ne(!0),s)),n})(),(()=>{var n=Yr();return v(n,()=>i.value),I(s=>X(n,{...ne()},s)),n})()]})),I(i=>X(t,Kr,i)),t}})}function Oh(r){const e=()=>{const i=r.store||{},n=[];for(const s in i)n.push([s,i[s]]);return n},t=()=>{const i=r.store||{};let n=0;for(const s in i)n+=i[s];return n};return C(H,{get when(){return e().length>0},get children(){var i=Kd(),n=i.firstChild;n.firstChild;var s=n.nextSibling;return v(n,C(H,{get when(){return r.capacity!=null},get children(){var o=Zd(),a=o.firstChild;return v(o,t,a),v(o,()=>r.capacity,null),o}}),null),v(s,C(ye,{get each(){return e()},children:([o,a])=>[(()=>{var l=Jd();return v(l,o),l})(),(()=>{var l=Qd();return v(l,a),l})()]})),i}})}const Lh={tough:"#4c4c4c",move:"#a9b7c6",work:"#ffe56d",carry:"#777777",attack:"#f93842",ranged_attack:"#5d80b2",heal:"#65fd62",claim:"#b99cfb"};function Ah(r){const e=()=>r.item.raw,t=()=>typeof e().user=="string"?e().user:null,i=()=>{var p,f;const u=t();return u?((f=(p=gd())==null?void 0:p[u])==null?void 0:f.username)??u:null},n=()=>typeof e().hits=="number"?e().hits:null,s=()=>typeof e().hitsMax=="number"?e().hitsMax:null,o=()=>{const u=e().ageTime,p=Wt();return typeof u=="number"&&p!==null?Math.max(0,u-p):null},a=()=>typeof e().fatigue=="number"?e().fatigue:null,l=()=>e().store,c=()=>typeof e().storeCapacity=="number"?e().storeCapacity:null,d=()=>e().body??[];return(()=>{var u=nh(),p=u.firstChild;return v(p,C(H,{get when(){return i()},get children(){return[(()=>{var f=eh();return I(h=>X(f,ne(!0),h)),f})(),(()=>{var f=Ft();return v(f,i),I(h=>X(f,ne(),h)),f})()]}}),null),v(p,C(H,{get when(){return ee(()=>n()!==null)()&&s()!==null},get children(){return[(()=>{var f=Fs();return I(h=>X(f,ne(!0),h)),f})(),(()=>{var f=rn(),h=f.firstChild;return v(f,n,h),v(f,s,null),I(g=>X(f,{...ne()},g)),f})()]}}),null),v(p,C(H,{get when(){return o()!==null},get children(){return[(()=>{var f=th();return I(h=>X(f,ne(!0),h)),f})(),(()=>{var f=Yr();return v(f,o),I(h=>X(f,{...ne()},h)),f})()]}}),null),v(p,C(H,{get when(){return ee(()=>a()!==null)()&&a()>0},get children(){return[(()=>{var f=rh();return I(h=>X(f,ne(!0),h)),f})(),(()=>{var f=Yr();return v(f,a),I(h=>X(f,{...ne()},h)),f})()]}}),null),v(u,C(Oh,{get store(){return l()},get capacity(){return c()}}),null),v(u,C(H,{get when(){return d().length>0},get children(){var f=ih(),h=f.firstChild,g=h.firstChild,$=g.nextSibling;$.nextSibling;var y=h.nextSibling;return v(h,()=>d().length,$),v(y,C(ye,{get each(){return d()},children:S=>(()=>{var E=sh();return I(x=>{var m=S.type.replace("_"," "),M=Lh[S.type]??"#484f58",T=S.hits===0?.25:1;return m!==x.e&&be(E,"title",x.e=m),M!==x.t&&B(E,"background",x.t=M),T!==x.a&&B(E,"opacity",x.a=T),x},{e:void 0,t:void 0,a:void 0}),E})()})),f}}),null),I(f=>X(p,Kr,f)),u})()}function Ih(r){const e=()=>r.item.raw,t=()=>typeof e().name=="string"?e().name:"",i=()=>typeof e().room=="string"?e().room:"",n=()=>typeof e().color=="number"?e().color:1,s=()=>typeof e().secondaryColor=="number"?e().secondaryColor:1,[o,a]=G(n()),[l,c]=G(s());he(()=>{a(n()),c(s())});const d=()=>o()!==n()||l()!==s(),u=()=>{const g=ae();if(!g)return;const $=o(),y=l();In(`changeFlagColor: name="${t()}" room=${i()} primary=${$} secondary=${y}`),g.http.game.changeFlagColor(i(),t(),$,y).then(()=>In("changeFlagColor OK")).catch(S=>Xt("changeFlagColor FAILED:",S))},p=()=>{const g=tn();return(g==null?void 0:g.type)==="moveFlag"&&g.id===r.item.id},f=()=>{if(p()){Yi(null);return}Yi({type:"moveFlag",id:r.item.id,name:t(),room:i(),color:o(),secondaryColor:l()})},h={display:"flex","flex-direction":"column",gap:"5px","font-size":"11px",color:"#8b949e"};return(()=>{var g=oh(),$=g.firstChild;$.firstChild;var y=$.nextSibling;y.firstChild;var S=y.nextSibling,E=S.firstChild,x=E.nextSibling;return v($,C(Xr,{get value(){return o()},onChange:a}),null),v(y,C(Xr,{get value(){return l()},onChange:c}),null),E.addEventListener("mouseleave",m=>{d()&&(m.currentTarget.style.background="#238636")}),E.addEventListener("mouseenter",m=>{d()&&(m.currentTarget.style.background="#2ea043")}),E.$$click=u,x.addEventListener("mouseleave",m=>{m.currentTarget.style.color=p()?"#c9d1d9":"#8b949e"}),x.addEventListener("mouseenter",m=>{m.currentTarget.style.color="#c9d1d9"}),x.$$click=f,v(x,(()=>{var m=ee(()=>!!p());return()=>m()?C(Zr,{size:13}):C(dl,{size:13})})()),I(m=>{var M=h,T=h,b=!d(),k=d()?"#238636":"#161b22",A=d()?"#fff":"#484f58",P=`1px solid ${d()?"#238636":"#30363d"}`,N=d()?"pointer":"not-allowed",O=p()?"Abort move":"Move flag",L=p()?"#30363d":"#21262d",z=p()?"#c9d1d9":"#8b949e",F=`1px solid ${p()?"#8b949e":"#30363d"}`;return m.e=X($,M,m.e),m.t=X(y,T,m.t),b!==m.a&&(E.disabled=m.a=b),k!==m.o&&B(E,"background",m.o=k),A!==m.i&&B(E,"color",m.i=A),P!==m.n&&B(E,"border",m.n=P),N!==m.s&&B(E,"cursor",m.s=N),O!==m.h&&be(x,"title",m.h=O),L!==m.r&&B(x,"background",m.r=L),z!==m.d&&B(x,"color",m.d=z),F!==m.l&&B(x,"border",m.l=F),m},{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,l:void 0}),g})()}function Nh(r){const e=()=>r.item.raw,t=()=>typeof e().level=="number"?e().level:0,i=()=>typeof e().progress=="number"?e().progress:null,n=()=>typeof e().progressTotal=="number"?e().progressTotal:null,s=()=>typeof e().downgradeTime=="number"?e().downgradeTime:null,o=()=>typeof e().safeModeAvailable=="number"?e().safeModeAvailable:0,a=()=>typeof e().safeMode=="number"?e().safeMode:null,l=()=>e().isPowerEnabled===!0,c=()=>e().reservation,d=()=>typeof e().user=="string"?e().user:null,u=()=>{var m;const x=d();return x?((m=Ns())==null?void 0:m.username)??x:null},p=()=>{const x=s(),m=Wt();return x!==null&&m!==null?Math.max(0,x-m):null},f=()=>{const x=p();if(x===null)return"—";const m=Yd[t()];return m!==void 0&&x>=m?"Max":String(x)},h=()=>{var x;return d()!==null&&d()===((x=Oe())==null?void 0:x._id)},[g,$]=G(!1);let y=null;const S=()=>{const x=ae();x&&x.http.game.addObjectIntent(r.item.id,e().room,"activateSafeMode",{}).catch(m=>Xt("activateSafeMode failed:",m))},E=()=>{if(!g()){$(!0),y=setTimeout(()=>$(!1),3e3);return}y&&(clearTimeout(y),y=null),$(!1);const x=ae();x&&x.http.game.addObjectIntent(r.item.id,e().room,"unclaim",{}).catch(m=>Xt("unclaim failed:",m))};return(()=>{var x=gh(),m=x.firstChild,M=m.firstChild,T=M.nextSibling;return v(T,()=>u()??"None"),v(m,C(H,{get when(){return c()},children:b=>[(()=>{var k=mh();return I(A=>X(k,ne(!0),A)),k})(),(()=>{var k=yh(),A=k.firstChild,P=A.nextSibling;return P.nextSibling,v(k,()=>b().username,A),v(k,()=>b().ticksToEnd,P),I(N=>X(k,ne(),N)),k})()]}),null),v(m,C(H,{get when(){return t()>0},get children(){return[(()=>{var b=ah();return I(k=>X(b,ne(!0),k)),b})(),(()=>{var b=Ft();return v(b,t),I(k=>X(b,ne(),k)),b})(),C(H,{get when(){return ee(()=>i()!==null)()&&n()!==null},get children(){return[(()=>{var b=lh();return I(k=>X(b,ne(!0),k)),b})(),(()=>{var b=rn(),k=b.firstChild;return v(b,()=>Dn(i()),k),v(b,()=>Dn(n()),null),I(A=>X(b,{...ne()},A)),b})()]}}),(()=>{var b=ch();return I(k=>X(b,ne(!0),k)),b})(),(()=>{var b=Ft();return v(b,o),I(k=>X(b,ne(),k)),b})(),(()=>{var b=dh();return I(k=>X(b,ne(!0),k)),b})(),(()=>{var b=Ft();return v(b,()=>l()?"Enabled":"Disabled"),I(k=>X(b,ne(),k)),b})(),(()=>{var b=hh();return I(k=>X(b,ne(!0),k)),b})(),(()=>{var b=Yr();return v(b,f),I(k=>X(b,{...ne(),color:f()==="Max"?"#3fb950":void 0},k)),b})()]}}),null),v(m,C(H,{get when(){return a()!==null},get children(){return[(()=>{var b=uh();return I(k=>X(b,ne(!0),k)),b})(),(()=>{var b=fh(),k=b.firstChild;return v(b,a,k),I(A=>X(b,{...ne()},A)),b})()]}}),null),v(x,C(H,{get when(){return h()},get children(){var b=ph(),k=b.firstChild,A=k.nextSibling;return k.addEventListener("mouseleave",P=>{o()>0&&(P.currentTarget.style.background="#1f6feb")}),k.addEventListener("mouseenter",P=>{o()>0&&(P.currentTarget.style.background="#388bfd")}),k.$$click=S,A.addEventListener("mouseleave",P=>{g()||(P.currentTarget.style.background="#f85149")}),A.addEventListener("mouseenter",P=>{g()||(P.currentTarget.style.background="#da3633")}),A.$$click=E,v(A,()=>g()?"Confirm unclaim":"Unclaim"),I(P=>{var N=o()===0,O=o()>0?"#1f6feb":"#161b22",L=o()>0?"pointer":"not-allowed",z=o()>0?1:.5,F=g()?"#da3633":"#f85149";return N!==P.e&&(k.disabled=P.e=N),O!==P.t&&B(k,"background",P.t=O),L!==P.a&&B(k,"cursor",P.a=L),z!==P.o&&B(k,"opacity",P.o=z),F!==P.i&&B(A,"background",P.i=F),P},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),b}}),null),I(b=>{var k=Kr,A=ne(!0),P=ne();return b.e=X(m,k,b.e),b.t=X(M,A,b.t),b.a=X(T,P,b.a),b},{e:void 0,t:void 0,a:void 0}),x})()}function Gh(r){const e=()=>r.item.raw,t=()=>{const d=e().store;return(d==null?void 0:d.energy)??0},i=()=>{const d=e().storeCapacityResource;return(d==null?void 0:d.energy)??0},n=()=>typeof e().hits=="number"?e().hits:null,s=()=>typeof e().hitsMax=="number"?e().hitsMax:null,o=()=>e().notifyWhenAttacked===!0,a=()=>typeof e().user=="string"?e().user:null,l=()=>{var d;return a()!==null&&a()===((d=Oe())==null?void 0:d._id)},c=()=>{const d=ae();d&&d.http.game.addObjectIntent(r.item.id,e().room,"notifyWhenAttacked",{enabled:!o()}).catch(u=>Xt("notifyWhenAttacked failed:",u))};return(()=>{var d=bh(),u=d.firstChild,p=u.nextSibling,f=p.firstChild;return v(p,t,f),v(p,i,null),v(d,C(H,{get when(){return ee(()=>n()!==null)()&&s()!==null},get children(){return[(()=>{var h=Fs();return I(g=>X(h,ne(!0),g)),h})(),(()=>{var h=rn(),g=h.firstChild;return v(h,n,g),v(h,s,null),I($=>X(h,{...ne()},$)),h})()]}}),null),v(d,C(H,{get when(){return l()},get children(){return[(()=>{var h=vh();return I(g=>X(h,ne(!0),g)),h})(),(()=>{var h=wh(),g=h.firstChild;return g.addEventListener("mouseleave",$=>{$.currentTarget.style.color=o()?"#3fb950":"#484f58"}),g.addEventListener("mouseenter",$=>{$.currentTarget.style.color=o()?"#56d364":"#8b949e"}),g.$$click=c,v(g,(()=>{var $=ee(()=>!!o());return()=>$()?C(Oa,{size:12}):C(Ea,{size:12})})()),I($=>{var y={...ne()},S=o()?"Notifications on — click to disable":"Notifications off — click to enable",E=o()?"#3fb950":"#484f58";return $.e=X(h,y,$.e),S!==$.t&&be(g,"title",$.t=S),E!==$.a&&B(g,"color",$.a=E),$},{e:void 0,t:void 0,a:void 0}),h})()]}}),null),I(h=>{var g=Kr,$=ne(!0),y={...ne()};return h.e=X(d,g,h.e),h.t=X(u,$,h.t),h.a=X(p,y,h.a),h},{e:void 0,t:void 0,a:void 0}),d})()}const Dh={creep:Ah,flag:Ih,controller:Nh,extension:Gh};function zh(r){const e=()=>kh[r.item.type]??"#c9d1d9",t=()=>Th[r.item.type]??r.item.type,i=()=>r.item.type==="creep",n=()=>r.item.type==="flag",s=()=>{var M;if(!i())return!1;const x=r.item.raw,m=typeof x.user=="string"?x.user:null;return m!==null&&m===((M=Oe())==null?void 0:M._id)},o=()=>{var M;if(i()||n()||r.item.type==="controller")return!1;const x=r.item.raw,m=typeof x.user=="string"?x.user:null;return m!==null&&m===((M=Oe())==null?void 0:M._id)},a=()=>Dh[r.item.type]||Ph,[l,c]=G(!1);let d=null;const[u,p]=G(!1);let f=null;const[h,g]=G(!1);let $=null;const y=x=>{if(x.stopPropagation(),!h()){g(!0),$=setTimeout(()=>g(!1),3e3);return}$&&(clearTimeout($),$=null),g(!1);const m=ae();if(!m)return;const M=r.item.id,T=r.item.raw;m.http.game.removeFlag(T.room,T.name).then(()=>Er(M)).catch(()=>{})},S=x=>{if(x.stopPropagation(),!u()){p(!0),f=setTimeout(()=>p(!1),3e3);return}f&&(clearTimeout(f),f=null),p(!1);const m=ae();if(!m)return;const M=r.item.id,T=r.item.raw,b=T.room;m.http.game.addObjectIntent("room",b,"destroyStructure",[{id:M,roomName:b,user:T.user}]).then(()=>Er(M)).catch(k=>Xt("destroyStructure failed:",k))},E=x=>{if(x.stopPropagation(),!l()){c(!0),d=setTimeout(()=>c(!1),3e3);return}d&&(clearTimeout(d),d=null),c(!1);const m=ae();if(!m)return;const M=r.item.id;m.http.game.addObjectIntent(M,r.item.raw.room,"suicide",{}).then(()=>Er(M)).catch(T=>Xt("suicide failed:",T))};return(()=>{var x=_h(),m=x.firstChild,M=m.firstChild,T=M.nextSibling,b=T.firstChild,k=b.nextSibling,A=k.nextSibling,P=A.nextSibling;P.nextSibling;var N=T.nextSibling;return v(m,C(H,{get when(){return ee(()=>!i())()&&!n()},get children(){var O=xh();return I(L=>B(O,"background",e())),O}}),M),v(M,C(H,{get when(){return n()},get fallback(){return ee(t)},get children(){return C(ls,{size:12})}}),null),v(M,C(H,{get when(){return ee(()=>typeof r.item.raw.name=="string")()&&r.item.raw.name},children:O=>(()=>{var L=$h();return v(L,()=>O()),L})()}),null),v(T,()=>r.item.raw.x,k),v(T,()=>r.item.raw.y,P),v(m,C(H,{get when(){return s()},get children(){var O=di();return O.addEventListener("mouseleave",L=>{l()||(L.currentTarget.style.color="#8b949e")}),O.addEventListener("mouseenter",L=>{l()||(L.currentTarget.style.color="#f85149")}),O.$$click=E,v(O,C(ni,{size:13})),I(L=>{var z=l()?"Click again to confirm suicide":"Suicide",F=l()?"#f85149":"#8b949e";return z!==L.e&&be(O,"title",L.e=z),F!==L.t&&B(O,"color",L.t=F),L},{e:void 0,t:void 0}),O}}),N),v(m,C(H,{get when(){return o()},get children(){var O=di();return O.addEventListener("mouseleave",L=>{u()||(L.currentTarget.style.color="#8b949e")}),O.addEventListener("mouseenter",L=>{u()||(L.currentTarget.style.color="#f85149")}),O.$$click=S,v(O,C(ni,{size:13})),I(L=>{var z=u()?"Click again to confirm destruction":"Destroy structure",F=u()?"#f85149":"#8b949e";return z!==L.e&&be(O,"title",L.e=z),F!==L.t&&B(O,"color",L.t=F),L},{e:void 0,t:void 0}),O}}),N),v(m,C(H,{get when(){return n()},get children(){var O=di();return O.addEventListener("mouseleave",L=>{h()||(L.currentTarget.style.color="#8b949e")}),O.addEventListener("mouseenter",L=>{h()||(L.currentTarget.style.color="#f85149")}),O.$$click=y,v(O,C(ni,{size:13})),I(L=>{var z=h()?"Click again to confirm deletion":"Delete flag",F=h()?"#f85149":"#8b949e";return z!==L.e&&be(O,"title",L.e=z),F!==L.t&&B(O,"color",L.t=F),L},{e:void 0,t:void 0}),O}}),N),N.addEventListener("mouseleave",O=>O.currentTarget.style.color="#8b949e"),N.addEventListener("mouseenter",O=>O.currentTarget.style.color="#fff"),N.$$click=()=>Er(r.item.id),v(x,C(Kn,{get component(){return a()},get item(){return r.item}}),null),I(O=>B(x,"border",`1px solid ${s()&&l()||u()||h()?"#f85149":"#30363d"}`)),x})()}function Bh(){return(()=>{var r=Sh();return v(r,C(H,{get when(){return Hr().length>0},get fallback(){return Ch()},get children(){return C(ye,{get each(){return Hr()},children:e=>C(zh,{item:e})})}})),r})()}ke(["click"]);var Fh=R('<div style="display:grid;grid-template-columns:repeat(3, 1fr);gap:4px;margin-top:8px">'),Hh=R('<div style="padding:8px;border-bottom:1px solid #30363d;flex-shrink:0"><div style="padding:4px 8px;background:#161b22;border-radius:6px;border:1px solid #30363d"><div style=font-size:10px;font-weight:600;color:#8b949e;text-transform:uppercase;letter-spacing:0.04em;margin-bottom:4px> Room</div><div style=font-size:13px;font-weight:600;color:#c9d1d9></div><div style="display:grid;grid-template-columns:auto 1fr;row-gap:1px;margin-top:4px;font-size:11px"><div style="padding:3px 0;color:#8b949e">Shard</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Tick</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Tick duration</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Objects</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Owner</div><div style="padding:3px 0;color:#c9d1d9">'),Wh=R('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;display:flex;align-items:center;justify-content:center">');const Uh=[{mode:"view",label:"View",icon:()=>C(qa,{size:14})},{mode:"flag",label:"Flag",icon:()=>C(ls,{size:14})},{mode:"build",label:"Build",icon:()=>C(Ja,{size:14})}];function Xh(r){return(()=>{var e=Hh(),t=e.firstChild,i=t.firstChild,n=i.nextSibling,s=n.nextSibling,o=s.firstChild,a=o.nextSibling,l=a.nextSibling,c=l.nextSibling,d=c.nextSibling,u=d.nextSibling,p=u.nextSibling,f=p.nextSibling,h=f.nextSibling,g=h.nextSibling;return v(n,()=>r.room),v(a,()=>r.shard??"—"),v(c,()=>Wt()??"—"),v(u,(()=>{var $=ee(()=>!!_i());return()=>$()?`${_i()}ms`:"—"})()),v(f,()=>pd()??"—"),v(g,()=>{var $;return(($=Ns())==null?void 0:$.username)??"—"}),v(e,C(H,{get when(){return!qe()},get children(){var $=Fh();return v($,C(ye,{each:Uh,children:y=>{const S=()=>bt()===y.mode;return(()=>{var E=Wh();return E.$$click=()=>ft(y.mode),v(E,()=>y.icon()),I(x=>{var m=y.label,M=`1px solid ${S()?"#58a6ff":"#30363d"}`,T=S()?"#1f6feb33":"#161b22",b=S()?"#c9d1d9":"#8b949e";return m!==x.e&&be(E,"title",x.e=m),M!==x.t&&B(E,"border",x.t=M),T!==x.a&&B(E,"background",x.a=T),b!==x.o&&B(E,"color",x.o=b),x},{e:void 0,t:void 0,a:void 0,o:void 0}),E})()}})),$}}),null),e})()}ke(["click"]);const[Yh,qh]=G("owner"),Hs="screeps-terrain-v1";async function Vh(r,e,t){try{const i=await caches.open(Hs),n=`/terrain/${r}_${e}_z${t}.webp`,s=new Request(n),o=await i.match(s);if(o)return await o.blob()}catch{}return null}async function jh(r,e,t,i){try{const n=await caches.open(Hs),s=`/terrain/${r}_${e}_z${t}.webp`,o=new Request(s),a=new Response(i);await n.put(o,a)}catch{}}async function Zh(r){const e=new OffscreenCanvas(r.width,r.height),t=e.getContext("2d");if(!t)throw new Error("OffscreenCanvas 2D context not available");return t.drawImage(r,0,0),await e.convertToBlob({type:"image/webp"})}async function Kh(r){return await createImageBitmap(r)}function Jh(r){return new Worker("/assets/terrain.worker-D9zNeJfz.js",{name:r==null?void 0:r.name})}const{warn:Qh}=xt("MapRenderer"),Ws=3,V=Ws*50,eu=[50,60,70,80,90,100,110],ir=1,ht=.5,Rr=50,tu=2600,ru=5,hi=.2,ui=5,iu=br,nu=16777215,su=mt,ou=hr,au=us,lu=dt,cu=4486980,du=8921634,hu=new Set(["w","r","pb","p","s","c","m","k"]),uu={H:13421772,O:13421772,U:5809919,L:4176208,K:10711543,Z:13801762,X:16273737},fu=[16,24,32,40];class Df{constructor(e){_(this,"app");_(this,"world");_(this,"boundsGraphics",null);_(this,"selectionGraphics",null);_(this,"safeModeGraphics",null);_(this,"safeModeRooms",new Set);_(this,"activeRooms",new Map);_(this,"roomPool",[]);_(this,"terrainBaked",new Set);_(this,"terrainData",new Map);_(this,"worker");_(this,"pendingBakes",new Map);_(this,"nextBakeId",0);_(this,"currentShard","shard0");_(this,"callbacks");_(this,"resizeObserver",null);_(this,"_destroyed",!1);_(this,"showRoomNames",!1);_(this,"worldBoundsSet",null);_(this,"lastVisibleBounds",null);_(this,"animTargetX",0);_(this,"animTargetY",0);_(this,"isAnimating",!1);_(this,"overlayMode","owner");_(this,"showUnclaimableOverlay",!0);_(this,"isDragging",!1);_(this,"hasDragged",!1);_(this,"dragStartX",0);_(this,"dragStartY",0);_(this,"dragWorldX",0);_(this,"dragWorldY",0);_(this,"isPinching",!1);_(this,"pinchPivotWorldX",0);_(this,"pinchPivotWorldY",0);_(this,"pinchStartDist",0);_(this,"pinchStartScale",0);_(this,"lastVisibleKey","");_(this,"visibleDebounceTimer",null);_(this,"selectedRoom",null);_(this,"currentUserId",null);_(this,"badgeCache",new ps);_(this,"lastCheckX",0);_(this,"lastCheckY",0);_(this,"lastCheckScale",0);this.app=new qn,this.callbacks=e,this.worker=new Jh,this.worker.onmessage=t=>{const{id:i,bitmap:n}=t.data,s=this.pendingBakes.get(i);s&&(this.pendingBakes.delete(i),s.resolve(n))}}async init(e){const t=e.parentElement??e,{width:i,height:n}=t.getBoundingClientRect();await this.app.init({canvas:e,width:i,height:n,background:ec,antialias:!1,preference:"webgl"}),this.resizeObserver=new ResizeObserver(s=>{const{width:o,height:a}=s[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 Ee,this.app.stage.addChild(this.world),this.boundsGraphics=new q,this.world.addChild(this.boundsGraphics),this.selectionGraphics=new q,this.world.addChild(this.selectionGraphics),this.safeModeGraphics=new q,this.world.addChild(this.safeModeGraphics),this.setupInteraction(),this.app.ticker.add(()=>{if(this.isAnimating){const s=this.animTargetX-this.world.x,o=this.animTargetY-this.world.y;Math.abs(s)<.5&&Math.abs(o)<.5?(this.world.x=this.animTargetX,this.world.y=this.animTargetY,this.isAnimating=!1):(this.world.x+=s*.2,this.world.y+=o*.2)}this.checkVisibleRooms()})}get zoom(){var e;return((e=this.world)==null?void 0:e.scale.x)??1}setZoom(e){if(!this.world||(e=Math.max(hi,Math.min(ui,e)),e===this.world.scale.x))return;const t=this.app.screen.width/2,i=this.app.screen.height/2;this.applyZoomAt(e,t,i)}applyZoomAt(e,t,i){var d,u;const n=this.world.scale.x,s=this.getLOD(),o=this.zoom>=ir,a=this.zoom>=ht,l=(t-this.world.x)/n,c=(i-this.world.y)/n;this.world.scale.set(e),this.world.x=t-l*e,this.world.y=i-c*e,this.getLOD()!==s&&this.applyLOD(),(e>=ir!==o||e>=ht!==a)&&this.updateAllNameLabels(),this.updateAllRoomScales(e),(u=(d=this.callbacks).onZoomChanged)==null||u.call(d,e),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode()}centerOn(e,t,i=!1){const n=e*V+V/2,s=t*V+V/2,o=this.world.scale.x,a=this.app.screen.width/2-n*o,l=this.app.screen.height/2-s*o;i?(this.animTargetX=a,this.animTargetY=l,this.isAnimating=!0):(this.isAnimating=!1,this.world.x=a,this.world.y=l)}async getTerrainBitmap(e,t,i){const n=this.currentShard;try{const s=await Vh(n,e,t);if(s)return await Kh(s);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:i});const l=await a;return Zh(l).then(c=>{jh(n,e,t,c)}).catch(c=>Qh("failed to save to terrainCache:",c)),l}catch{return null}}async setRoomTerrain(e,t){const i=t.raw;let n=!1;for(let c=0;c<i.length;c++)if(i[c]!==0){n=!0;break}if(!n){this.terrainBaked.add(e);return}const s=this.getOrCreate(e),o=this.getLOD();o===0&&this.terrainData.set(e,i);const a=await this.getTerrainBitmap(e,o,i);if(!a)return;if(!this.activeRooms.has(e)){a.close();return}const l=sr.from(a);o===0?(s.texLo&&!s.texLo.destroyed&&s.texLo.destroy(!0),s.texLo=l,this.getLOD()===0&&s.texLo&&(s.terrainSprite.texture=s.texLo)):(s.texHi&&!s.texHi.destroyed&&s.texHi.destroy(!0),s.texHi=l,this.getLOD()===1&&s.texHi&&(s.terrainSprite.texture=s.texHi)),s.terrainSprite.width=V,s.terrainSprite.height=V,this.terrainBaked.add(e)}getLOD(){return this.zoom<ir?0:1}async applyLOD(){const e=this.getLOD()===1,t=[];for(const[i,n]of this.activeRooms)if(this.terrainBaked.has(i))if(e&&!n.texHi){const s=this.terrainData.get(i);s&&(this.terrainData.delete(i),t.push(this.getTerrainBitmap(i,1,s).then(o=>{o&&this.activeRooms.has(i)?(n.texHi=sr.from(o),this.getLOD()===1&&(n.terrainSprite.texture=n.texHi)):o&&o.close()})))}else{const s=e?n.texHi:n.texLo;s&&!s.destroyed&&(n.terrainSprite.texture=s)}await Promise.all(t)}setRoomMap2(e,t,i="live"){const n=this.getOrCreate(e);n.lastMap2Data=t,n.lastMap2Source=i,this.drawMap2(n,t,i)}drawMap2(e,t,i){const n=e.map2Graphics;n.alpha=i==="cache"?.6:1;const s=Ws;n.clear();const o=t.r??[];for(const[h,g]of o)n.rect(h*s,g*s,s,s);o.length&&n.fill(Ji);const a=t.w??[];for(const[h,g]of a)n.rect(h*s+.5,g*s+.5,s-1,s-1);a.length&&n.fill(e.ownerState==="other"?du:cu);const l=t.s??[];for(const[h,g]of l)n.circle((h+.5)*s,(g+.5)*s,2.5);l.length&&n.fill(iu);const c=t.c??[];for(const[h,g]of c)n.circle((h+.5)*s,(g+.5)*s,2);c.length&&n.fill(nu);const d=t.m??[];for(const[h,g]of d)n.circle((h+.5)*s,(g+.5)*s,2);d.length&&n.fill(su);const u=t.k??[];for(const[h,g]of u)n.circle((h+.5)*s,(g+.5)*s,2);u.length&&n.fill(ou);const p=t.pb??[];for(const[h,g]of p)n.circle((h+.5)*s,(g+.5)*s,1.5);p.length&&n.fill(hr);const f=t;for(const h in f){if(hu.has(h))continue;const g=f[h];if(!Array.isArray(g)||g.length===0)continue;for(const[y,S]of g)n.circle((y+.5)*s,(S+.5)*s,1);const $=h===this.currentUserId?au:lu;n.fill($)}}clearRoomMap2(e){var t;(t=this.activeRooms.get(e))==null||t.map2Graphics.clear()}clearAllMap2(){for(const e of this.activeRooms.values())e.map2Graphics.clear()}setRoomOwned(e,t){const i=this.activeRooms.get(e);if(!i)return;i.ownerState!==t&&(i.ownerState=t,i.lastMap2Data&&this.drawMap2(i,i.lastMap2Data,i.lastMap2Source??"live"));const n=i.ownerOverlay;n.clear(),t==="other"?(n.rect(0,0,V,V),n.fill({color:10027008,alpha:.18})):t==="own"&&(n.rect(0,0,V,V),n.fill({color:102,alpha:.35})),n.visible=this.showUnclaimableOverlay}setUnclaimableOverlayVisible(e){if(this.showUnclaimableOverlay!==e){this.showUnclaimableOverlay=e;for(const t of this.activeRooms.values())t.ownerOverlay.visible=e}}async setRoomBadge(e,t,i){const n=this.activeRooms.get(e);if(n){if(!t){n.badgeSprite&&(n.container.removeChild(n.badgeSprite),n.badgeSprite.destroy(),n.badgeSprite=void 0),n.badgeLevel=void 0;return}try{const s=await this.badgeCache.getOrCreate(t);if(!this.activeRooms.has(e))return;if(n.badgeSprite){if(n.badgeSprite.texture===s){n.badgeLevel=i,this.applyBadgeSize(n,this.zoom),this.applyOverlayMode(n);return}n.badgeSprite.texture=s}else{const o=new Ht(s);o.anchor.set(.5),o.x=V/2,o.y=V/2;const a=n.container.getChildIndex(n.nameLabel);n.container.addChildAt(o,a),n.badgeSprite=o}n.badgeLevel=i,this.applyBadgeSize(n,this.zoom),this.applyOverlayMode(n)}catch{}}}applyBadgeSize(e,t){if(!e.badgeSprite||e.badgeLevel===void 0)return;const n=(eu[e.badgeLevel-1]??24)*Math.min(1,t);e.badgeSprite.width=n/t,e.badgeSprite.height=n/t}setOverlayMode(e){if(this.overlayMode!==e){this.overlayMode=e;for(const t of this.activeRooms.values())this.applyOverlayMode(t)}}setRoomMineral(e,t,i){const n=this.activeRooms.get(e);if(!n)return;if(!t||!i){n.mineralCircle&&(n.container.removeChild(n.mineralCircle),n.mineralCircle.destroy(),n.mineralCircle=void 0),n.mineralLabel&&(n.container.removeChild(n.mineralLabel),n.mineralLabel.destroy(),n.mineralLabel=void 0),n.mineralDensity=void 0;return}const s=uu[t]??mt;if(n.mineralDensity=i,n.mineralColor=s,!n.mineralCircle){const o=new q;o.x=V/2,o.y=V/2;const a=n.container.getChildIndex(n.nameLabel);n.container.addChildAt(o,a),n.mineralCircle=o}if(n.mineralLabel)n.mineralLabel.text=t;else{const o=new zt({text:t,style:{fontSize:36,fill:16777215,fontFamily:"ui-monospace, monospace",fontWeight:"bold"}});o.anchor.set(.5),o.x=V/2,o.y=V/2,n.container.addChild(o),n.mineralLabel=o}this.applyMineralSize(n,this.zoom),this.applyOverlayMode(n)}applyOverlayMode(e){e.badgeSprite&&(e.badgeSprite.visible=this.overlayMode==="owner"),e.mineralCircle&&(e.mineralCircle.visible=this.overlayMode==="mineral"),e.mineralLabel&&(e.mineralLabel.visible=this.overlayMode==="mineral")}applyMineralSize(e,t){if(!e.mineralCircle||!e.mineralLabel||e.mineralDensity===void 0||e.mineralColor===void 0)return;const i=Math.max(.5,Math.min(1.5,t)),n=(fu[e.mineralDensity-1]??24)*i,s=n/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/s}),e.mineralCircle.scale.set(s);const c=n*.55/36/t;e.mineralLabel.scale.set(c)}updateNameLabelScale(e,t){const n=.3/Math.sqrt(t),s=12/(36*t);e.nameLabel.scale.set(Math.max(n,s))}updateAllRoomScales(e){for(const t of this.activeRooms.values())this.applyBadgeSize(t,e),this.updateNameLabelScale(t,e),this.applyMineralSize(t,e)}setCurrentUser(e){this.currentUserId=e}setSelectedRoom(e){if(this.selectedRoom=e,!this.selectionGraphics||(this.selectionGraphics.clear(),this.world.removeChild(this.selectionGraphics),this.world.addChild(this.selectionGraphics),!e))return;const t=je(e);if(!t)return;const i=t.x*V,n=t.y*V;this.selectionGraphics.rect(i,n,V,V);const s=Math.max(2,Math.ceil(2/this.zoom));this.selectionGraphics.stroke({color:16777215,width:s,alignment:0})}setRoomSafeMode(e,t){t?this.safeModeRooms.add(e):this.safeModeRooms.delete(e),this.redrawSafeMode()}redrawSafeMode(){if(!this.safeModeGraphics||(this.safeModeGraphics.clear(),this.safeModeRooms.size===0))return;const e=Math.max(1,Math.ceil(1/this.zoom));for(const t of this.safeModeRooms){const i=je(t);if(!i)continue;const n=i.x*V,s=i.y*V;this.safeModeGraphics.rect(n,s,V,V),this.safeModeGraphics.stroke({color:16776960,width:e,alignment:1,alpha:.5})}this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)}setBounds(e,t,i,n){if(!this.boundsGraphics)return;this.worldBoundsSet={minX:e,maxX:t,minY:i,maxY:n},this.boundsGraphics.clear();const s=e*V,o=i*V,a=(t-e+1)*V,l=(n-i+1)*V;this.boundsGraphics.rect(s,o,a,l),this.boundsGraphics.stroke({color:hs,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=sr.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<tu?this.roomPool.push(t):(this.world.removeChild(t.container),t.container.destroy({children:!0,context:!0})))}clearInvisibleRooms(e){const t=this.lastVisibleBounds;for(const i of[...this.activeRooms.keys()])if(!e.has(i)){if(t){const n=je(i);if(n&&n.x>=t.rxMin-Rr&&n.x<=t.rxMax+Rr&&n.y>=t.ryMin-Rr&&n.y<=t.ryMax+Rr)continue}this.clearRoom(i)}}destroy(){var e;if(!this._destroyed){this._destroyed=!0,(e=this.resizeObserver)==null||e.disconnect(),this.resizeObserver=null,this.visibleDebounceTimer!==null&&(clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=null);for(const[,t]of this.activeRooms)t.texLo&&!t.texLo.destroyed&&t.texLo.destroy(!0),t.texHi&&!t.texHi.destroyed&&t.texHi.destroy(!0);this.activeRooms.clear(),this.safeModeRooms.clear();for(const t of this.roomPool)t.texLo&&!t.texLo.destroyed&&t.texLo.destroy(!0),t.texHi&&!t.texHi.destroyed&&t.texHi.destroy(!0);this.roomPool.length=0,this.terrainBaked.clear(),this.terrainData.clear(),this.worker.terminate(),this.pendingBakes.clear(),this.badgeCache.destroy();try{this.app.destroy(!1,{children:!0,texture:!0,context:!0})}catch{}}}getOrCreate(e){const t=this.activeRooms.get(e);if(t)return t;const i=je(e);if(!i)throw new Error(`MapRenderer: invalid room "${e}"`);let n;if(this.roomPool.length>0)n=this.roomPool.pop();else{const s=new Ee;s.cullable=!0;const o=new Ht(sr.EMPTY),a=new q,l=new q;s.addChild(o),s.addChild(a),s.addChild(l);const c=new zt({text:"",style:{fontSize:36,fill:9147550,fontFamily:"ui-monospace, monospace"}});c.scale.set(.25),c.x=2,c.y=2,s.addChild(c),this.world.addChild(s),n={container:s,terrainSprite:o,texLo:null,texHi:null,map2Graphics:a,ownerOverlay:l,ownerState:"none",nameLabel:c}}return n.container.x=i.x*V,n.container.y=i.y*V,n.container.visible=!0,n.nameLabel.text=e,n.nameLabel.visible=this.showRoomNames&&this.zoom>=ht&&this.nameLabelShouldShow(i.x,i.y),this.updateNameLabelScale(n,this.zoom),n.badgeSprite&&(n.container.removeChild(n.badgeSprite),n.badgeSprite.destroy(),n.badgeSprite=void 0),n.mineralCircle&&(n.container.removeChild(n.mineralCircle),n.mineralCircle.destroy(),n.mineralCircle=void 0),n.mineralLabel&&(n.container.removeChild(n.mineralLabel),n.mineralLabel.destroy(),n.mineralLabel=void 0),n.mineralDensity=void 0,n.mineralColor=void 0,this.safeModeGraphics&&(this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)),this.selectionGraphics&&(this.world.removeChild(this.selectionGraphics),this.world.addChild(this.selectionGraphics)),this.activeRooms.set(e,n),n}nameLabelShouldShow(e,t){const i=this.worldBoundsSet;return!(i&&(e<i.minX||e>i.maxX||t<i.minY||t>i.maxY))}updateAllNameLabels(){const e=this.showRoomNames&&this.zoom>=ht;for(const[t,i]of this.activeRooms){if(!e){i.nameLabel.visible=!1;continue}const n=je(t);n&&(i.nameLabel.visible=this.nameLabelShouldShow(n.x,n.y))}}setupInteraction(){const e=this.app.canvas;e.style.touchAction="none",e.style.userSelect="none";const t=new Map;e.addEventListener("pointermove",i=>{var n,s;if(!t.has(i.pointerId)){if(!this.isDragging&&!this.isPinching){const o=e.getBoundingClientRect();this.emitHover(i.clientX-o.left,i.clientY-o.top)}return}if(t.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPinching&&t.size===2){const o=[...t.values()],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),u=Math.max(hi,Math.min(ui,this.pinchStartScale*(d/this.pinchStartDist))),p=this.getLOD(),f=this.zoom>=ir,h=this.zoom>=ht;this.world.scale.set(u),this.world.x=l-this.pinchPivotWorldX*u,this.world.y=c-this.pinchPivotWorldY*u,this.getLOD()!==p&&this.applyLOD(),(u>=ir!==f||u>=ht!==h)&&this.updateAllNameLabels(),this.updateAllRoomScales(u),(s=(n=this.callbacks).onZoomChanged)==null||s.call(n,u),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode();return}if(this.isDragging){const o=i.clientX-this.dragStartX,a=i.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,u=d-(l.maxX+1)*V*c,p=this.app.screen.width-d-l.minX*V*c,f=d-(l.maxY+1)*V*c,h=this.app.screen.height-d-l.minY*V*c;this.world.x=this.rubberBand(this.dragWorldX+o,u,p),this.world.y=this.rubberBand(this.dragWorldY+a,f,h)}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",i=>{if(i.preventDefault(),this.isAnimating=!1,t.set(i.pointerId,{x:i.clientX,y:i.clientY}),e.setPointerCapture(i.pointerId),t.size>=2){this.isDragging=!1,this.isPinching=!0;const n=[...t.values()],s=e.getBoundingClientRect(),o=(n[0].x+n[1].x)/2-s.left,a=(n[0].y+n[1].y)/2-s.top;this.pinchStartDist=Math.hypot(n[1].x-n[0].x,n[1].y-n[0].y),this.pinchStartScale=this.world.scale.x,this.pinchPivotWorldX=(o-this.world.x)/this.pinchStartScale,this.pinchPivotWorldY=(a-this.world.y)/this.pinchStartScale}else this.isPinching=!1,this.isDragging=!0,this.hasDragged=!1,this.dragStartX=i.clientX,this.dragStartY=i.clientY,this.dragWorldX=this.world.x,this.dragWorldY=this.world.y}),e.addEventListener("pointerup",i=>{if(t.delete(i.pointerId),e.releasePointerCapture(i.pointerId),this.isPinching){t.size<2&&(this.isPinching=!1,this.isDragging=!1,this.springBack());return}if(this.isDragging){if(this.isDragging=!1,!this.hasDragged){const n=e.getBoundingClientRect(),s=this.screenToRoom(i.clientX-n.left,i.clientY-n.top);s&&this.callbacks.onRoomClick(s)}this.springBack()}}),e.addEventListener("pointercancel",i=>{t.delete(i.pointerId),e.releasePointerCapture(i.pointerId),(this.isPinching||this.isDragging)&&(this.isPinching=!1,this.isDragging=!1,this.springBack())}),e.addEventListener("wheel",i=>{if(i.preventDefault(),this.isDragging||this.isPinching)return;this.isAnimating=!1;const n=this.world.scale.x,s=i.deltaY<0?1.1:.9,o=Math.max(hi,Math.min(ui,n*s));this.applyZoomAt(o,i.offsetX,i.offsetY)},{passive:!1})}rubberBand(e,t,i){const n=i-t;if(n<=0||e>=t&&e<=i)return e;const s=.55;if(e<t){const a=t-e;return t-(1-1/(a*s/n+1))*n*s}const o=e-i;return i+(1-1/(o*s/n+1))*n*s}springBack(){const e=this.worldBoundsSet;if(!e)return;const t=this.world.scale.x,i=this.app.screen.width,n=this.app.screen.height,s=50,o=this.world.x+e.minX*V*t,a=this.world.x+(e.maxX+1)*V*t,l=this.world.y+e.minY*V*t,c=this.world.y+(e.maxY+1)*V*t;let d=this.world.x,u=this.world.y;a<s?d+=s-a:o>i-s&&(d-=o-(i-s)),c<s?u+=s-c:l>n-s&&(u-=l-(n-s)),(d!==this.world.x||u!==this.world.y)&&(this.animTargetX=d,this.animTargetY=u,this.isAnimating=!0)}screenToRoom(e,t){const i=this.world.scale.x,n=(e-this.world.x)/i,s=(t-this.world.y)/i,o=Math.floor(n/V),a=Math.floor(s/V);return Ie(o,a)}emitHover(e,t){this.callbacks.onRoomHover(this.screenToRoom(e,t))}checkVisibleRooms(){const e=this.world.scale.x,t=this.world.x,i=this.world.y;if(this.lastCheckX===t&&this.lastCheckY===i&&this.lastCheckScale===e)return;this.lastCheckX=t,this.lastCheckY=i,this.lastCheckScale=e;const n=-t/e,s=-i/e,o=(this.app.screen.width-t)/e,a=(this.app.screen.height-i)/e,l=Math.floor(n/V)-1,c=Math.ceil(o/V),d=Math.floor(s/V)-1,u=Math.ceil(a/V);this.lastVisibleBounds={rxMin:l,rxMax:c,ryMin:d,ryMax:u};const p=[];for(let h=l;h<=c;h++)for(let g=d;g<=u;g++){const $=Ie(h,g);$&&p.push($)}const f=`${l},${d},${c},${u}`;f!==this.lastVisibleKey&&(this.lastVisibleKey=f,this.visibleDebounceTimer!==null&&clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=setTimeout(()=>{this.visibleDebounceTimer=null,this.callbacks.onVisibleRoomsChanged(p)},ru))}}var pu=R('<div style="padding:8px;border-bottom:1px solid #30363d;flex-shrink:0"><div style="padding:4px 8px;background:#161b22;border-radius:6px;border:1px solid #30363d"><div style=font-size:10px;font-weight:600;color:#8b949e;text-transform:uppercase;letter-spacing:0.04em;margin-bottom:4px>Map</div><div style="display:grid;grid-template-columns:auto 1fr;row-gap:1px;font-size:11px;margin-bottom:8px"><div style="padding:3px 0;color:#8b949e">Zoom</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Live</div><div style="padding:3px 0;color:#c9d1d9"></div></div><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px><span>Show room names</span><input type=checkbox></label><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px;color:#c9d1d9;cursor:pointer;margin-top:4px><span>Show unclaimable rooms</span><input type=checkbox></label></div><div style="display:grid;grid-template-columns:repeat(3, 1fr);gap:4px;margin-top:8px">'),gu=R('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;font-size:11px;font-weight:600">');const mu=[{mode:"owner",label:"Owner"},{mode:"mineral",label:"Mineral"},{mode:"none",label:"None"}];function yu(r){const e=()=>(r.zoom??1)>=ht;return(()=>{var t=pu(),i=t.firstChild,n=i.firstChild,s=n.nextSibling,o=s.firstChild,a=o.nextSibling,l=a.nextSibling,c=l.nextSibling,d=s.nextSibling,u=d.firstChild,p=u.nextSibling,f=d.nextSibling,h=f.firstChild,g=h.nextSibling,$=i.nextSibling;return v(a,()=>{var y;return((y=r.zoom)==null?void 0:y.toFixed(2))??"—"}),v(c,()=>r.subsActive?"Yes":"No"),p.addEventListener("change",y=>Ts(y.currentTarget.checked)),g.addEventListener("change",y=>Es(y.currentTarget.checked)),v($,C(ye,{each:mu,children:y=>{const S=()=>Yh()===y.mode;return(()=>{var E=gu();return E.$$click=()=>qh(y.mode),v(E,()=>y.label),I(x=>{var m=`1px solid ${S()?"#58a6ff":"#30363d"}`,M=S()?"#1f6feb33":"#161b22",T=S()?"#c9d1d9":"#8b949e";return m!==x.e&&B(E,"border",x.e=m),M!==x.t&&B(E,"background",x.t=M),T!==x.a&&B(E,"color",x.a=T),x},{e:void 0,t:void 0,a:void 0}),E})()}})),I(y=>{var S=e()?"#c9d1d9":"#484f58",E=e()?"pointer":"default",x=!e();return S!==y.e&&B(d,"color",y.e=S),E!==y.t&&B(d,"cursor",y.t=E),x!==y.a&&(p.disabled=y.a=x),y},{e:void 0,t:void 0,a:void 0}),I(()=>p.checked=ks()),I(()=>g.checked=Ms()),t})()}ke(["click"]);var vu=R('<div style="margin:8px 8px 0;border-radius:6px;overflow:hidden"><div style="padding:4px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:10px;font-weight:600;color:#8b949e;text-transform:uppercase;letter-spacing:0.04em">'),wu=R('<div style="padding:6px 8px;font-size:11px;color:#484f58;font-style:italic">None'),bu=R('<div style="padding:3px 8px;color:#8b949e">Mineral'),xu=R('<div style="padding:3px 8px;color:#79c0ff">'),_u=R('<div style="padding:3px 8px;color:#8b949e">Density'),$u=R('<div style="padding:3px 8px;color:#c9d1d9">'),Su=R('<div style=font-size:11px><div style="padding:5px 8px;font-weight:600;color:#c9d1d9;font-size:12px;border-bottom:1px solid #21262d"></div><div style="display:grid;grid-template-columns:auto 1fr;row-gap:1px;column-gap:0"><div style="padding:3px 8px;color:#8b949e">Owner</div><div style="padding:3px 8px;color:#c9d1d9">');const Cu=["Low","Medium","High","Ultra"];function ku(r){return Cu[r-1]??String(r)}function zn(r){return(()=>{var e=vu(),t=e.firstChild;return v(t,()=>r.label),v(e,C(H,{get when(){return r.info},get fallback(){return wu()},children:i=>(()=>{var n=Su(),s=n.firstChild,o=s.nextSibling,a=o.firstChild,l=a.nextSibling;return v(s,()=>i().room),v(l,()=>i().owner??"None"),v(o,C(H,{get when(){return i().mineral},get children(){return[bu(),(()=>{var c=xu();return v(c,()=>i().mineral),c})(),_u(),(()=>{var c=$u();return v(c,()=>ku(i().density??0)),c})()]}}),null),n})()}),null),I(i=>{var n=`1px solid ${r.dim?"#21262d":"#30363d"}`,s=r.dim?.6:1;return n!==i.e&&B(e,"border",i.e=n),s!==i.t&&B(e,"opacity",i.t=s),i},{e:void 0,t:void 0}),e})()}var Tu=R("<span style=color:#8b949e;font-size:11px>Checking…"),Mu=R('<div style=margin-top:8px><div style="padding:6px 8px;font-size:11px;font-weight:600;color:#c9d1d9;margin-bottom:6px">Your flags'),Eu=R('<div style=flex:1;overflow:auto;min-height:0;padding:8px><div style="border-radius:6px;border:1px solid #30363d;overflow:hidden;background:#0d1117"><div style="padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:11px;font-weight:600;color:#c9d1d9">Create flag</div><div style=padding:8px;display:flex;flex-direction:column;gap:8px><label>Name<input placeholder="Flag name"style="background:#010409;color:#c9d1d9;border-radius:4px;padding:5px 6px;font-size:12px;outline:none"></label><label>Primary color</label><label>Secondary color</label><div style=color:#484f58;font-size:11px;line-height:1.4>'),Ru=R("<span style=color:#f85149;font-size:11px>"),Pu=R("<div style=margin-top:8px;color:#484f58;font-style:italic;font-size:12px>No flags."),Ou=R('<div style="border-radius:6px;border:1px solid #30363d;margin-bottom:6px;overflow:hidden"><div style="display:flex;align-items:center;gap:7px;padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d"><div style=width:8px;height:8px;border-radius:50%;flex-shrink:0></div><span style=font-size:11px;font-weight:600;color:#c9d1d9;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap></span><span style=font-size:10px;color:#8b949e;flex-shrink:0></span><span style=font-size:10px;color:#484f58;flex-shrink:0;margin-left:4px>(<!>,<!>)');const{error:Lu}=xt("flag"),Vi={};for(const[r,e]of Object.entries(yr))Vi[e]=r;function Au(){const r=h=>{Ds({...Lt(),...h})},[e,t]=G(null),[i,n]=G(!1);let s=null;he(()=>{if(bt()!=="flag"||Lt().name.trim()!=="")return;const h=ae();h&&h.http.game.genUniqueFlagName().then(g=>{r({name:g.name}),t(null)}).catch(g=>{Lu("gen unique name failed:",g)})});const o=h=>{r({name:h}),t(null),s&&clearTimeout(s);const g=h.trim();if(!g){n(!1);return}n(!0),s=setTimeout(()=>{const $=ae();if(!$){n(!1);return}$.http.game.checkUniqueFlagName(g).then(()=>{t(null)}).catch(y=>{t(y.message)}).finally(()=>{n(!1)})},300)},a=()=>yr[Lt().color]??1,l=()=>yr[Lt().secondaryColor]??1,c=h=>{r({color:Vi[h]??"COLOR_WHITE"})},d=h=>{r({secondaryColor:Vi[h]??"COLOR_WHITE"})},u=()=>{const h=ga(),g=[];for(const[$,y]of Object.entries(h))y&&typeof y=="object"&&"room"in y&&"x"in y&&"y"in y&&g.push([$,y]);return g},p=h=>h===void 0||h<0||h>=It.length?"#8b949e":`#${It[h].toString(16).padStart(6,"0")}`,f={display:"flex","flex-direction":"column",gap:"5px","font-size":"11px",color:"#8b949e"};return(()=>{var h=Eu(),g=h.firstChild,$=g.firstChild,y=$.nextSibling,S=y.firstChild,E=S.firstChild,x=E.nextSibling,m=S.nextSibling;m.firstChild;var M=m.nextSibling;M.firstChild;var T=M.nextSibling;return x.$$input=b=>o(b.currentTarget.value),v(S,C(H,{get when(){return e()},children:b=>(()=>{var k=Ru();return v(k,b),k})()}),null),v(S,C(H,{get when(){return i()},get children(){return Tu()}}),null),v(m,C(Xr,{get value(){return a()},onChange:c}),null),v(M,C(Xr,{get value(){return l()},onChange:d}),null),v(T,(()=>{var b=ee(()=>!!yt());return()=>b()?`Marked at x=${yt().tx}, y=${yt().ty}. Click again to create the flag, or click elsewhere to move the mark.`:"Click a position in the room to mark it."})()),v(h,C(H,{get when(){return u().length>0},get fallback(){return Pu()},get children(){var b=Mu();return b.firstChild,v(b,C(ye,{get each(){return u()},children:([k,A])=>(()=>{var P=Ou(),N=P.firstChild,O=N.firstChild,L=O.nextSibling,z=L.nextSibling,F=z.nextSibling,U=F.firstChild,Z=U.nextSibling,de=Z.nextSibling,re=de.nextSibling;return re.nextSibling,v(L,k),v(z,()=>A.room),v(F,()=>A.x,Z),v(F,()=>A.y,re),I(W=>B(O,"background",p(A.color))),P})()}),null),b}}),null),I(b=>{var k=f,A=`1px solid ${e()?"#f85149":"#30363d"}`,P=f,N=f;return b.e=X(S,k,b.e),A!==b.t&&B(x,"border",b.t=A),b.a=X(m,P,b.a),b.o=X(M,N,b.o),b},{e:void 0,t:void 0,a:void 0,o:void 0}),I(()=>x.value=Lt().name),h})()}ke(["input"]);var Iu=R("<span style=color:#8b949e>…"),Nu=R("<span style=color:#3fb950>✓"),Gu=R("<span style=color:#f85149>✗"),Du=R("<div style=font-size:10px;color:#f85149>"),zu=R('<div style="margin-top:8px;border-radius:6px;border:1px solid #30363d;overflow:hidden;background:#0d1117"><div style="padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:11px;font-weight:600;color:#c9d1d9">Spawn name</div><div style=padding:8px;display:flex;flex-direction:column;gap:6px><div style=display:flex;gap:6px;align-items:center><input type=text style="flex:1;background:#010409;color:#c9d1d9;border-radius:4px;padding:5px 7px;font-size:12px;outline:none;transition:border-color 150ms ease"><span style=font-size:14px;flex-shrink:0;width:14px;text-align:center>'),Bu=R('<div style=flex:1;overflow:auto;min-height:0;padding:8px><div style="border-radius:6px;border:1px solid #30363d;overflow:hidden;background:#0d1117;margin-bottom:8px"><div style="padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:11px;font-weight:600;color:#c9d1d9">Controller Level </div><div style=padding:8px;font-size:11px;color:#8b949e></div></div><div style="border-radius:6px;border:1px solid #30363d;overflow:hidden;background:#0d1117"><div style="padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:11px;font-weight:600;color:#c9d1d9">Structures</div></div><div style="margin-top:8px;padding:0 4px"><div style=color:#484f58;font-style:italic;font-size:12px>'),Fu=R('<div style="padding:6px 8px;display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid #21262d;font-size:11px;color:#c9d1d9"><span style=text-transform:capitalize></span><span style=color:#8b949e>');function Hu(r){const e=Object.keys(Ur),[t,i]=G("idle"),[n,s]=G("");let o=null;const a=(h,g)=>{const $=Ur[h];return $?wt()==="empty"&&h==="spawn"?Math.max($[g]??0,1):$[g]??0:0},l=(h,g)=>{const $=a(h,g);if($===2500)return 1/0;const y=Wr()[h]??0;return Math.max(0,$-y)},c=()=>Ze().structureType==="spawn";he(Ks(()=>Ze().structureType,h=>{if(h!=="spawn")return;const g=ae();g&&(i("loading"),s(""),g.http.game.genUniqueObjectName("spawn",r.shard).then($=>{pt({structureType:"spawn",structureName:$.name}),i("valid")}).catch(()=>{pt({structureType:"spawn",structureName:"Spawn1"}),i("idle")}))}));const d=h=>{if(o&&clearTimeout(o),!h.trim()){i("invalid"),s("Name cannot be empty");return}i("loading"),s(""),o=setTimeout(()=>{const g=ae();g&&g.http.game.checkUniqueObjectName("spawn",h.trim(),r.shard).then($=>{$.error?(i("invalid"),s($.error)):(i("valid"),s(""))}).catch(()=>{i("invalid"),s("Could not validate name")})},400)},u=h=>{pt({structureType:"spawn",structureName:h}),d(h)},p=h=>{pt({structureType:h,structureName:""}),i("idle"),s("")},f=()=>{switch(t()){case"loading":return Iu();case"valid":return Nu();case"invalid":return Gu();default:return null}};return(()=>{var h=Bu(),g=h.firstChild,$=g.firstChild;$.firstChild;var y=$.nextSibling,S=g.nextSibling;S.firstChild;var E=S.nextSibling,x=E.firstChild;return v($,()=>Dt()??"?",null),v(y,()=>{const m=wt();return m==="empty"?"World is empty — place a spawn to claim this room.":m==="lost"?"You lost all your spawns — respawn to continue.":Dt()!=null?`RCL ${Dt()} — Select a structure type and click a tile to build.`:"No controller — roads and containers only."}),v(S,C(ye,{each:e,children:m=>{const M=()=>Dt()??0,T=()=>a(m,M()),b=()=>Wr()[m]??0,k=()=>Ze().structureType===m,A=()=>T()===2500,P=()=>!A()&&l(m,M())<=0;return C(H,{get when(){return T()>0},get children(){var N=Fu(),O=N.firstChild,L=O.nextSibling;return N.$$click=()=>!P()&&p(m),v(O,()=>m.replace(/([A-Z])/g," $1").trim(),null),v(O,()=>k()&&" ✓",null),v(L,(()=>{var z=ee(()=>!!A());return()=>z()?`${b()}/∞`:`${b()}/${T()}`})(),null),v(L,()=>P()&&" (Max)",null),I(z=>{var F=k()?"#1f3158":"transparent",U=P()?"default":"pointer",Z=P()?.5:1;return F!==z.e&&B(N,"background",z.e=F),U!==z.t&&B(N,"cursor",z.t=U),Z!==z.a&&B(N,"opacity",z.a=Z),z},{e:void 0,t:void 0,a:void 0}),N}})}}),null),v(h,C(H,{get when(){return c()},get children(){var m=zu(),M=m.firstChild,T=M.nextSibling,b=T.firstChild,k=b.firstChild,A=k.nextSibling;return k.$$input=P=>u(P.currentTarget.value),v(A,f),v(T,C(H,{get when(){return ee(()=>t()==="invalid")()&&n()},get children(){var P=Du();return v(P,n),P}}),null),I(P=>B(k,"border",`1px solid ${t()==="invalid"?"#f85149":t()==="valid"?"#238636":"#30363d"}`)),I(()=>k.value=Ze().structureName??""),m}}),E),v(x,()=>Ze().structureType?"Click a tile in the room to build.":"Select a structure type, then click a tile."),h})()}ke(["input","click"]);var Wu=R("<div style=padding-bottom:8px;overflow:auto;min-height:0>"),Uu=R('<div style=display:flex;flex-direction:row;height:100%;background:#0d1117><div style="width:32px;height:100%;display:flex;flex-direction:column;align-items:center;border-right:1px solid #30363d;padding:8px 0;cursor:pointer"></div><div style=flex:1;display:flex;flex-direction:column;overflow:hidden><div style="padding:6px 10px;border-bottom:1px solid #30363d;font-size:12px;font-weight:600;color:#8b949e;display:flex;justify-content:space-between;align-items:center"><span>Properties'),Xu=R("<button style=background:transparent;border:none;color:#8b949e;font-size:14px;cursor:pointer;padding:4px>"),Yu=R("<button style=background:transparent;border:none;color:#8b949e;font-size:11px;cursor:pointer>Collapse");function qu(r){return C(H,{get when(){return bt()==="flag"},get fallback(){return C(H,{get when(){return bt()==="build"},get fallback(){return C(Bh,{})},get children(){return C(Hu,{get shard(){return r.shard}})}})},get children(){return C(Au,{})}})}function Vu(r){const e=()=>{var i;(i=r.onToggle)==null||i.call(r)},t=i=>{var n;i.stopPropagation(),(n=r.onToggle)==null||n.call(r)};return(()=>{var i=Uu(),n=i.firstChild,s=n.nextSibling,o=s.firstChild;return o.firstChild,n.$$click=e,v(n,(()=>{var a=ee(()=>!!r.onToggle);return()=>a()&&(()=>{var l=Xu();return l.$$click=t,v(l,()=>r.isCollapsed?"▶":"◀"),l})()})()),v(o,(()=>{var a=ee(()=>!!r.onToggle);return()=>a()&&(()=>{var l=Yu();return l.$$click=t,l})()})(),null),v(s,C(H,{get when(){return r.mapMode},get fallback(){return C(Xh,{get room(){return r.room??"—"},get shard(){return r.shard??null}})},get children(){return C(yu,{get zoom(){return r.mapZoom},get subsActive(){return r.mapSubsActive}})}}),null),v(s,C(H,{get when(){return r.mapMode},get fallback(){return C(qu,{get shard(){return r.shard}})},get children(){var a=Wu();return v(a,C(zn,{label:"Selected",get info(){return r.selectedRoomInfo??null}}),null),v(a,C(zn,{label:"Cursor",get info(){return r.hoveredRoomInfo??null},dim:!0}),null),a}}),null),i})()}ke(["click"]);var ju=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>CPU:</span><span style=color:#c9d1d9>"),Zu=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Memory:</span><span style=color:#c9d1d9>"),Ku=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Zoom:</span><span style=color:#c9d1d9>%"),Ju=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Subs:</span><span>"),Qu=R('<div style="display:flex;gap:16px;padding:6px 16px;font-size:12px;color:#8b949e;align-items:center">');function ef(r){const[e,t]=G(null);vr(()=>{const s=ae();if(!s)return;const o=new ji;o.add(s.stores.user.subscribe("cpu")),o.add(s.stores.user.on("user:cpu",a=>{t(a)})),Ge(()=>{o.dispose()})});const i=()=>{var a;const s=e();if(!s)return"—";const o=((a=Oe())==null?void 0:a.cpu)??"?";return`${s.cpu.toFixed(1)} / ${o}`},n=()=>{const s=e();return s?`${(s.memory/1024).toFixed(1)} KB`:"—"};return(()=>{var s=Qu();return v(s,C(H,{get when(){return e()!==null},get children(){return[(()=>{var o=ju(),a=o.firstChild,l=a.nextSibling;return v(l,i),o})(),(()=>{var o=Zu(),a=o.firstChild,l=a.nextSibling;return v(l,n),o})()]}}),null),v(s,C(H,{get when(){return ee(()=>r.mapZoom!==null)()&&r.mapZoom!==void 0},get children(){return[(()=>{var o=Ku(),a=o.firstChild,l=a.nextSibling,c=l.firstChild;return v(l,()=>(r.mapZoom*100).toFixed(0),c),o})(),(()=>{var o=Ju(),a=o.firstChild,l=a.nextSibling;return v(l,()=>r.mapSubsActive===!1?"paused":"active"),I(c=>B(l,"color",r.mapSubsActive===!1?"#e3b341":"#3fb950")),o})()]}}),null),s})()}var tf=R('<div style=position:fixed;inset:0;background:rgba(0,0,0,0.65);z-index:200;display:flex;align-items:center;justify-content:center><div style="background:#161b22;border:1px solid #30363d;border-radius:10px;width:540px;max-height:90vh;display:flex;flex-direction:column;overflow:hidden"><div style="display:flex;align-items:center;justify-content:space-between;padding:14px 20px;border-bottom:1px solid #30363d;flex-shrink:0"><span style=font-size:15px;font-weight:600;color:#c9d1d9>Edit Badge</span><button style="background:transparent;border:none;color:#8b949e;cursor:pointer;line-height:1;padding:2px 6px"></button></div><div style=overflow:auto;flex:1;padding:20px><div style=display:flex;gap:16px;margin-bottom:20px><div style=flex-shrink:0><div style=font-size:11px;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:8px;font-weight:700>Preview</div><img width=96 height=96 style=display:block></div><div style=flex:1;min-width:0><div style=font-size:11px;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:8px;font-weight:700>Badge Design</div><div style="display:grid;grid-template-columns:repeat(6, 1fr);gap:4px"></div></div></div><div style=margin-bottom:20px><div style=font-size:11px;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:8px;font-weight:700>Colors</div><div style=display:flex;gap:6px;margin-bottom:10px></div><div style="display:grid;grid-template-columns:repeat(20, 1fr);gap:2px;margin-bottom:10px"></div><div style=display:flex;align-items:center;gap:8px><div style="width:24px;height:24px;border-radius:4px;border:1px solid rgba(255,255,255,0.2);flex-shrink:0"></div><input type=text maxlength=7 placeholder=#rrggbb style="width:90px;padding:4px 8px;border-radius:4px;background:#0d1117;color:#c9d1d9;font-size:12px;font-family:monospace;outline:none"></div></div><div style=margin-bottom:16px><div style=display:flex;align-items:baseline;gap:8px;margin-bottom:6px><span style=font-size:11px;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;font-weight:700>Variation</span><span style=font-size:12px;color:#c9d1d9></span></div><input type=range min=-100 max=100 style=width:100%;accent-color:#58a6ff></div><label style=display:flex;align-items:center;gap:8px;cursor:pointer;font-size:13px;color:#c9d1d9><input type=checkbox style=accent-color:#58a6ff;width:14px;height:14px>Rotate / Flip</label></div><div style="display:flex;justify-content:flex-end;gap:8px;padding:14px 20px;border-top:1px solid #30363d;flex-shrink:0"><button style="padding:8px 16px;border-radius:6px;border:1px solid #30363d;background:transparent;color:#8b949e;font-size:13px">Cancel</button><button style="padding:8px 16px;border-radius:6px;border:none;background:#238636;color:#fff;font-size:13px;font-weight:600">'),rf=R("<button style=border-radius:4px;padding:3px;cursor:pointer;display:flex;align-items:center;justify-content:center><img width=48 height=48 style=display:block>"),nf=R('<button style="display:flex;align-items:center;gap:6px;padding:5px 10px;border-radius:6px;font-size:12px;cursor:pointer"><div style="width:12px;height:12px;border-radius:50%;border:1px solid rgba(255,255,255,0.2);flex-shrink:0">'),sf=R("<button style=width:100%;aspect-ratio:1;border-radius:2px;cursor:pointer;padding:0;outline:none>");const Us={};for(let r=1;r<=24;r++){const e=qr({type:r,color1:"#4a5060",color2:"#7a9ec0",color3:"#c0daf0",param:0,flip:!1});Us[r]=`data:image/svg+xml,${encodeURIComponent(e)}`}function ct(r){var e;return typeof r=="string"?r:((e=cr[r])==null?void 0:e.rgb)??"#000000"}function Pr(r){return typeof r=="number"?Math.max(0,Math.min(79,r)):r}const of=[{slot:1,label:"Background"},{slot:2,label:"Primary"},{slot:3,label:"Secondary"}],af=Array.from({length:24},(r,e)=>e+1),fi=/^#[0-9a-f]{6}$/i;function lf(r){const[e,t]=G(we(()=>typeof r.badge.type=="number"?r.badge.type:1)),[i,n]=G(we(()=>Pr(r.badge.color1))),[s,o]=G(we(()=>Pr(r.badge.color2))),[a,l]=G(we(()=>Pr(r.badge.color3))),[c,d]=G(we(()=>r.badge.param??0)),[u,p]=G(we(()=>r.badge.flip??!1)),[f,h]=G(1),[g,$]=G(!1),[y,S]=G(we(()=>ct(Pr(r.badge.color1)))),E=P=>P===1?i():P===2?s():a(),x=P=>{const N=f();N===1?n(P):N===2?o(P):l(P)};he(()=>{S(ct(E(f())))});const m=P=>{var O;const N=E(f());return typeof N=="number"?N===P:N.toLowerCase()===(((O=cr[P])==null?void 0:O.rgb)??"").toLowerCase()},M=()=>({type:e(),color1:ct(i()),color2:ct(s()),color3:ct(a()),param:c(),flip:u()}),T=fr(()=>{const P=qr(M());return`data:image/svg+xml,${encodeURIComponent(P)}`}),b=P=>{if(S(P),!fi.test(P))return;const N=cr.findIndex(O=>O.rgb.toLowerCase()===P.toLowerCase());x(N>=0?N:P)},k=async()=>{var N;const P=ae();if(P){$(!0);try{await P.http.user.badge(M()),await P.stores.user.refreshMe(),r.onClose(),(N=r.onSaved)==null||N.call(r),ge("Badge saved","success",3e3)}catch(O){ge(`Failed to save badge: ${O instanceof Error?O.message:String(O)}`,"error",5e3)}finally{$(!1)}}},A=P=>{P.target===P.currentTarget&&r.onClose()};return(()=>{var P=tf(),N=P.firstChild,O=N.firstChild,L=O.firstChild,z=L.nextSibling,F=O.nextSibling,U=F.firstChild,Z=U.firstChild,de=Z.firstChild,re=de.nextSibling,W=Z.nextSibling,Y=W.firstChild,ie=Y.nextSibling,K=U.nextSibling,oe=K.firstChild,De=oe.nextSibling,ot=De.nextSibling,_t=ot.nextSibling,He=_t.firstChild,We=He.nextSibling,Je=K.nextSibling,Le=Je.firstChild,J=Le.firstChild,Te=J.nextSibling,at=Le.nextSibling,_r=Je.nextSibling,te=_r.firstChild,Q=F.nextSibling,le=Q.firstChild,se=le.nextSibling;return P.$$click=A,z.$$click=()=>r.onClose(),v(z,C(Zr,{size:18})),v(ie,C(ye,{each:af,children:D=>(()=>{var j=rf(),ce=j.firstChild;return j.$$click=()=>t(D),I($e=>{var me=e()===D?"#1f3a2a":"#0d1117",Ae=`1px solid ${e()===D?"#238636":"#21262d"}`,Qe=e()===D?T():Us[D];return me!==$e.e&&B(j,"background",$e.e=me),Ae!==$e.t&&B(j,"border",$e.t=Ae),Qe!==$e.a&&be(ce,"src",$e.a=Qe),$e},{e:void 0,t:void 0,a:void 0}),j})()})),v(De,C(ye,{each:of,children:({slot:D,label:j})=>(()=>{var ce=nf(),$e=ce.firstChild;return ce.$$click=()=>h(D),v(ce,j,null),I(me=>{var Ae=`1px solid ${f()===D?"#58a6ff":"#30363d"}`,Qe=f()===D?"#1c2d47":"transparent",qt=f()===D?"#58a6ff":"#8b949e",Vt=ct(E(D));return Ae!==me.e&&B(ce,"border",me.e=Ae),Qe!==me.t&&B(ce,"background",me.t=Qe),qt!==me.a&&B(ce,"color",me.a=qt),Vt!==me.o&&B($e,"background",me.o=Vt),me},{e:void 0,t:void 0,a:void 0,o:void 0}),ce})()})),v(ot,C(ye,{each:cr,children:D=>(()=>{var j=sf();return j.$$click=()=>x(D.index),I(ce=>{var $e=D.rgb,me=D.rgb,Ae=m(D.index)?"2px solid #fff":"1px solid transparent";return $e!==ce.e&&be(j,"title",ce.e=$e),me!==ce.t&&B(j,"background",ce.t=me),Ae!==ce.a&&B(j,"border",ce.a=Ae),ce},{e:void 0,t:void 0,a:void 0}),j})()})),We.$$input=D=>b(D.currentTarget.value),v(Te,c),at.$$input=D=>d(+D.currentTarget.value),te.addEventListener("change",D=>p(D.currentTarget.checked)),le.$$click=()=>r.onClose(),se.$$click=k,v(se,()=>g()?"Saving…":"Save Badge"),I(D=>{var j=T(),ce=fi.test(y())?y():ct(E(f())),$e=`1px solid ${fi.test(y())?"#30363d":"#f85149"}`,me=g(),Ae=g()?"not-allowed":"pointer",Qe=g(),qt=g()?"not-allowed":"pointer",Vt=g()?.7:1;return j!==D.e&&be(re,"src",D.e=j),ce!==D.t&&B(He,"background",D.t=ce),$e!==D.a&&B(We,"border",D.a=$e),me!==D.o&&(le.disabled=D.o=me),Ae!==D.i&&B(le,"cursor",D.i=Ae),Qe!==D.n&&(se.disabled=D.n=Qe),qt!==D.s&&B(se,"cursor",D.s=qt),Vt!==D.h&&B(se,"opacity",D.h=Vt),D},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0}),I(()=>We.value=y()),I(()=>at.value=c()),I(()=>te.checked=u()),P})()}ke(["click","input"]);var cf=R('<div style="display:flex;align-items:center;justify-content:space-between;padding:10px 0;border-bottom:1px solid #21262d"><div><div style=font-size:13px;color:#c9d1d9></div></div><button style="flex-shrink:0;margin-left:24px;width:40px;height:20px;border-radius:10px;border:none;cursor:pointer;position:relative;transition:background 0.15s"><div style="position:absolute;top:2px;width:16px;height:16px;border-radius:50%;background:#fff;transition:left 0.15s">'),df=R("<div style=font-size:11px;color:#8b949e;margin-top:3px>"),hf=R("<div style=margin-bottom:24px><div style=font-size:10px;font-weight:700;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:4px>"),uf=R('<div style="display:flex;align-items:center;justify-content:space-between;gap:24px;padding:10px 0;border-bottom:1px solid #21262d"><div style=font-size:13px;color:#c9d1d9></div><div style=font-size:12px;color:#8b949e;text-align:right>'),ff=R("<img width=40 height=40 style=display:block>"),pf=R('<div style="display:flex;align-items:center;justify-content:space-between;padding:10px 0;border-bottom:1px solid #21262d"><div style=display:flex;align-items:center;gap:12px><span style=font-size:13px;color:#c9d1d9></span></div><button style="padding:6px 14px;border-radius:6px;border:1px solid #30363d;background:transparent;color:#c9d1d9;font-size:12px;cursor:pointer;flex-shrink:0">'),gf=R('<div style="display:flex;align-items:center;justify-content:space-between;padding:10px 0;border-bottom:1px solid #21262d"><div><div style=font-size:13px;color:#c9d1d9>Clear all caches</div><div style=font-size:11px;color:#8b949e;margin-top:3px>Deletes IndexedDB, Cache API, and localStorage. Session is kept. Page reloads afterwards.</div></div><button style="flex-shrink:0;margin-left:24px;padding:6px 14px;border-radius:6px;border:1px solid #da3633;background:transparent;font-size:12px">'),mf=R('<div style="position:absolute;inset:0px;background:rgba(13, 17, 23, 0.96);z-index:100;display:flex;flex-direction:column;overflow:hidden"><div style="display:flex;align-items:center;justify-content:space-between;padding:14px 24px;border-bottom:1px solid #30363d;flex-shrink:0"><span style=font-size:15px;font-weight:600;color:#c9d1d9>Settings</span><button style="background:transparent;border:none;color:#8b949e;cursor:pointer;line-height:1;padding:2px 6px"></button></div><div style="overflow:auto;flex:1;padding:20px 24px"><div style=max-width:480px>');const yf={type:1,color1:"#4a5060",color2:"#7a9ec0",color3:"#c0daf0",param:0,flip:!1};function nr(r){return(()=>{var e=cf(),t=e.firstChild,i=t.firstChild,n=t.nextSibling,s=n.firstChild;return v(i,()=>r.label),v(t,(()=>{var o=ee(()=>!!r.description);return()=>o()&&(()=>{var a=df();return v(a,()=>r.description),a})()})(),null),n.$$click=()=>r.onChange(!r.value),I(o=>{var a=r.value?"#238636":"#30363d",l=r.value?"22px":"2px";return a!==o.e&&B(n,"background",o.e=a),l!==o.t&&B(s,"left",o.t=l),o},{e:void 0,t:void 0}),e})()}function Et(r){return(()=>{var e=hf(),t=e.firstChild;return v(t,()=>r.title),v(e,()=>r.children,null),e})()}function Bn(r){return(()=>{var e=uf(),t=e.firstChild,i=t.nextSibling;return v(t,()=>r.label),v(i,()=>r.value),e})()}function vf(r){var c;const e=ua(),t=!qe()&&!((c=Oe())!=null&&c.badge),[i,n]=G(t),[s,o]=G(!1),a=fr(()=>{var p;const d=(p=Oe())==null?void 0:p.badge;if(!d)return null;const u=qr(d);return`data:image/svg+xml,${encodeURIComponent(u)}`});async function l(){o(!0);try{await pa(),ge("All caches cleared. Reloading…","success",2e3),setTimeout(()=>window.location.reload(),1500)}catch{ge("Failed to clear caches.","error"),o(!1)}}return(()=>{var d=mf(),u=d.firstChild,p=u.firstChild,f=p.nextSibling,h=u.nextSibling,g=h.firstChild;return f.$$click=()=>r.onClose(),v(f,C(Zr,{size:18})),v(d,C(H,{get when(){return i()},get children(){return C(lf,{get badge(){var $;return(($=Oe())==null?void 0:$.badge)??yf},onClose:()=>n(!1),onSaved:t?()=>r.onClose():void 0})}}),h),v(g,C(Et,{title:"Layout",get children(){return C(nr,{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 Cs()},onChange:id})}}),null),v(g,C(Et,{title:"Room View",get children(){return[C(nr,{label:"Show creep labels",description:"Display each creep's name above its sprite.",get value(){return Fi()},onChange:nd}),C(nr,{label:"Terrain effects",description:"Swamp glow and wall noise texture overlay.",get value(){return Gr()},onChange:sd})]}}),null),v(g,C(Et,{title:"Map View",get children(){return[C(nr,{label:"Show room names",description:"Render a small room name in the top-left corner of each map tile.",get value(){return ks()},onChange:Ts}),C(nr,{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 Ms()},onChange:Es})]}}),null),v(g,C(H,{get when(){return!qe()},get children(){return C(Et,{title:"Player Badge",get children(){var $=pf(),y=$.firstChild,S=y.firstChild,E=y.nextSibling;return v(y,C(H,{get when(){return a()},get children(){var x=ff();return I(()=>be(x,"src",a())),x}}),S),v(S,()=>{var x;return((x=Oe())==null?void 0:x.username)??""}),E.$$click=()=>n(!0),v(E,()=>a()?"Edit Badge":"Create Badge"),$}})}}),null),v(g,C(Et,{title:"Data",get children(){var $=gf(),y=$.firstChild,S=y.firstChild;S.nextSibling;var E=y.nextSibling;return E.$$click=l,v(E,()=>s()?"Clearing…":"Clear"),I(x=>{var m=s(),M=s()?"#8b949e":"#f85149",T=s()?"default":"pointer",b=s()?.6:1;return m!==x.e&&(E.disabled=x.e=m),M!==x.t&&B(E,"color",x.t=M),T!==x.a&&B(E,"cursor",x.a=T),b!==x.o&&B(E,"opacity",x.o=b),x},{e:void 0,t:void 0,a:void 0,o:void 0}),$}}),null),v(g,C(Et,{title:"About",get children(){return[C(Bn,{label:"Client version",get value(){return ha()}}),ee(()=>e&&C(Bn,{label:"Mod version",get value(){return`${e.version} (${e.kind})`}}))]}}),null),d})()}ke(["click"]);var wf=R('<button style="padding:7px;border-radius:4px;cursor:pointer;margin:0 4px;display:flex;align-items:center">'),bf=R('<button style="padding:7px;border-radius:4px;border:1px solid #30363d;background:#21262d;margin:0 2px;display:flex;align-items:center">'),xf=R("<div style=flex:1;position:relative;overflow:hidden>"),_f=R('<div style="border-top:1px solid #30363d;overflow:hidden;position:relative"><div style=position:absolute;top:0;left:0;width:100%;height:4px;cursor:row-resize;z-index:10;background:#21262d>'),$f=R('<div style="border-left:1px solid #30363d;overflow:hidden;position:relative"><div style=position:absolute;top:0;left:0;width:4px;height:100%;cursor:col-resize;z-index:10;background:#21262d>'),Sf=R("<div style=display:flex;flex:1;overflow:hidden><div style=display:flex;flex-direction:column;flex:1;overflow:hidden>"),Cf=R('<div style=width:100%;height:100%;display:flex;flex-direction:column;overflow:hidden;background:#0d1117><div style="display:flex;border-bottom:1px solid #30363d;align-items:center"><div style=flex:1></div><button title=Logout style="padding:7px;border-radius:4px;border:none;background:#da3633;color:#fff;cursor:pointer;margin:0 16px 0 8px;display:flex;align-items:center">'),kf=R("<div style=display:flex;flex-direction:column;flex:1;overflow:hidden><div style=display:flex;flex:1;overflow:hidden>");const Tf=Yn(()=>jn(()=>import("./CodePanel-CT25L3sq.js"),__vite__mapDeps([0,1,2])).then(r=>({default:r.CodePanel}))),Mf=Yn(()=>jn(()=>import("./MapViewer-BPHjWJtJ.js"),__vite__mapDeps([3,1,2])).then(r=>({default:r.MapViewer})));function pi(){const r=jr(),e=window.location.pathname.match(new RegExp(`^${r}/room/([A-Za-z0-9]+)`));if(!e)return{room:null,shard:null};const t=e[1].toUpperCase();if(!je(t))return{room:null,shard:null};const i=new URLSearchParams(window.location.search).get("shard");return{room:t,shard:i}}function Fn(r,e){return`${jr()}/room/${r}${e?`?shard=${encodeURIComponent(e)}`:""}`}function Hn(r){return`${jr()}/map${r?`?shard=${encodeURIComponent(r)}`:""}`}function gi(){return window.location.pathname.startsWith(`${jr()}/map`)?{shard:new URLSearchParams(window.location.search).get("shard")}:null}function mi(r){return(()=>{var e=wf();return e.$$click=()=>r.onClick(),v(e,()=>r.children),I(t=>{var i=r.title,n=`1px solid ${r.active?"#388bfd":"#30363d"}`,s=r.active?"#1f3158":"#21262d",o=r.active?"#58a6ff":"#c9d1d9";return i!==t.e&&be(e,"title",t.e=i),n!==t.t&&B(e,"border",t.t=n),s!==t.a&&B(e,"background",t.a=s),o!==t.o&&B(e,"color",t.o=o),t},{e:void 0,t:void 0,a:void 0,o:void 0}),e})()}function Wn(r){return(()=>{var e=bf();return e.$$click=()=>r.onClick(),v(e,()=>r.children),I(t=>{var i=r.title,n=r.disabled,s=r.disabled?"#484f58":"#c9d1d9",o=r.disabled?"default":"pointer";return i!==t.e&&be(e,"title",t.e=i),n!==t.t&&(e.disabled=t.t=n),s!==t.a&&B(e,"color",t.a=s),o!==t.o&&B(e,"cursor",t.o=o),t},{e:void 0,t:void 0,a:void 0,o:void 0}),e})()}function Ef(){var _r;const r=pi(),[e,t]=G(r.room??ti(pe.room)??"W1N1"),[i,n]=G(r.shard??ti(pe.shard)),[s,o]=G(gi()!==null||!r.room),[a,l]=G(!qe()&&!((_r=Oe())!=null&&_r.badge)),[c,d]=G(!1),[u,p]=G(!1);he(()=>{c(),p(!0),Promise.resolve().then(()=>p(!1))}),he(()=>{qe()&&ft("view")});const[f,h]=G(void 0),[g,$]=G(null),[y,S]=G(null),E=ti(pe.mapZoom),[x,m]=G(r.room&&E?Number(E):null),[M,T]=G(null),[b,k]=G(!1),[A,P]=G(!1),[N,O]=G(or(pe.sidebarWidth,300)),[L,z]=G(or(pe.sidebarWidth,300)),[F,U]=G(or(pe.consoleHeight,220)),[Z,de]=G(or(pe.consoleHeight,220)),[re,W]=G(!1),[Y,ie]=G(!1),K=()=>N()<=32,oe=()=>F()<=32,De=()=>{N()>32?(z(N()),O(32)):O(L())},ot=()=>{F()>32?(de(F()),U(32)):U(Z())},_t=te=>{te.preventDefault(),W(!0);const Q=te.clientX,le=N(),se=j=>{const ce=j.clientX-Q;O(Math.max(32,Math.min(500,le-ce)))},D=()=>{W(!1),Or(pe.sidebarWidth,N()),window.removeEventListener("pointermove",se),window.removeEventListener("pointerup",D)};window.addEventListener("pointermove",se),window.addEventListener("pointerup",D)},He=te=>{te.preventDefault(),ie(!0);const Q=te.clientY,le=F(),se=j=>{const ce=j.clientY-Q;U(Math.max(32,Math.min(500,le-ce)))},D=()=>{ie(!1),Or(pe.consoleHeight,F()),window.removeEventListener("pointermove",se),window.removeEventListener("pointerup",D)};window.addEventListener("pointermove",se),window.addEventListener("pointerup",D)},We=(te,Q)=>{var le;(le=ae())==null||le.stores.navigation.navigateTo(te,Q)},Je=te=>{h(te),o(!0),history.pushState(null,"",Hn(i()))},Le=()=>{s()?(o(!1),$(null),S(null),history.pushState(null,"",Fn(e(),i()))):Je(e())};vr(()=>{var se;!pi().room&&!gi()&&history.replaceState(null,"",Hn(i()));const te=()=>{const D=gi();if(D){o(!0),D.shard!==null&&n(D.shard);return}const{room:j,shard:ce}=pi();j&&(t(j),n(ce),o(!1))};window.addEventListener("popstate",te),Ge(()=>window.removeEventListener("popstate",te));const Q=(se=ae())==null?void 0:se.stores.navigation;if(Q){const D=Q.on("navigation:change",j=>{j.room!==null&&(t(j.room),n(j.shard),o(!1),$(null),S(null),k(Q.canBack()),P(Q.canForward()),hn(pe.room,j.room),j.shard?hn(pe.shard,j.shard):fa(pe.shard),history.pushState(null,"",Fn(j.room,j.shard)))});Ge(()=>D.dispose())}const le=D=>{if(!Gs(D.target)){if(D.key==="o"||D.key==="O"){d(j=>!j),l(!1);return}(D.key==="l"||D.key==="L")&&zs(),(D.key==="c"||D.key==="C")&&Bs(),s()||(D.key==="1"&&ft("view"),qe()||(D.key==="2"&&ft("flag"),D.key==="3"&&ft("build")),D.key==="m"&&Je(e()))}};window.addEventListener("keydown",le),Ge(()=>window.removeEventListener("keydown",le))});const J=()=>(()=>{var te=xf();return v(te,C(H,{get when(){return a()},get children(){return C(vf,{onClose:()=>l(!1)})}}),null),v(te,C(H,{get when(){return c()},get children(){return C(Tf,{onClose:()=>d(!1)})}}),null),v(te,C(H,{get when(){return!s()},get fallback(){return C(Mf,{get shard(){return i()},get originRoom(){return f()},get initialZoom(){return x()??void 0},onNavigateToRoom:Q=>We(Q,i()),onHoveredRoomChanged:$,onSelectedRoomChanged:S,onZoomChanged:Q=>{m(Q),Or(pe.mapZoom,Q)},onSubscriptionStateChanged:T})},get children(){return C(Md,{get room(){return e()},get shard(){return i()},onNavigate:We})}}),null),te})(),Te=()=>C(H,{get when(){return!qe()},get children(){var te=_f(),Q=te.firstChild;return Q.$$pointerdown=He,v(te,C(Xd,{get shard(){return i()},get isCollapsed(){return oe()},onToggle:ot}),null),I(le=>{var se=`${F()}px`,D=Y()?"none":"height 0.15s ease";return se!==le.e&&B(te,"height",le.e=se),D!==le.t&&B(te,"transition",le.t=D),le},{e:void 0,t:void 0}),te}}),at=te=>(()=>{var Q=$f(),le=Q.firstChild;return le.$$pointerdown=_t,v(Q,C(Vu,{get isCollapsed(){return K()},onToggle:De,get mapMode(){return s()},get hoveredRoomInfo(){return g()},get selectedRoomInfo(){return y()},get room(){return e()},get shard(){return i()},get mapZoom(){return x()},get mapSubsActive(){return M()}}),null),I(se=>{var D=c()?"0":`${N()}px`,j=te&&!(u()||re())?"width 0.15s ease":"none";return D!==se.e&&B(Q,"width",se.e=D),j!==se.t&&B(Q,"transition",se.t=j),se},{e:void 0,t:void 0}),Q})();return(()=>{var te=Cf(),Q=te.firstChild,le=Q.firstChild,se=le.nextSibling;return v(Q,C(Vl,{}),le),v(Q,C(H,{get when(){return!qe()||s()},get children(){return C(ef,{get mapZoom(){return ee(()=>!!s())()?x():null},get mapSubsActive(){return ee(()=>!!s())()?M():null}})}}),le),v(Q,C(Wn,{title:"Back",get disabled(){return!b()},onClick:()=>{var D;return(D=ae())==null?void 0:D.stores.navigation.back()},get children(){return C(Fa,{size:16})}}),se),v(Q,C(Wn,{title:"Forward",get disabled(){return!A()},onClick:()=>{var D;return(D=ae())==null?void 0:D.stores.navigation.forward()},get children(){return C(Da,{size:16})}}),se),v(Q,C(mi,{get title(){return s()?"Room View":"Map"},get active(){return s()},onClick:Le,get children(){return ee(()=>!!s())()?C(tl,{size:16}):C(al,{size:16})}}),se),v(Q,C(mi,{title:"Code Editor",get active(){return c()},onClick:()=>{d(D=>!D),l(!1)},get children(){return C(Ua,{size:16})}}),se),v(Q,C(mi,{title:"Settings",get active(){return a()},onClick:()=>{l(D=>!D),d(!1)},get children(){return C(fl,{size:16})}}),se),Dr(se,"click",ba,!0),v(se,C(nl,{size:16})),v(te,C(H,{get when(){return Cs()},get fallback(){return(()=>{var D=kf(),j=D.firstChild;return v(j,J,null),v(j,()=>at(!0),null),v(D,Te,null),D})()},get children(){var D=Sf(),j=D.firstChild;return v(j,J,null),v(j,Te,null),v(D,()=>at(!1),null),D}}),null),v(te,C(Pd,{}),null),te})()}ke(["click","pointerdown"]);var Rf=R("<div style=width:100%;height:100%>");function Pf(){const r=()=>gt()==="connected"&&ae()!==null;return vr(async()=>{if(gt()==="idle"&&(await wa().catch(()=>{}),gt()!=="connected")){const e=Vr();ut({url:e,auth:"guest",storage:null}).catch(()=>{})}}),(()=>{var e=Rf();return v(e,(()=>{var t=ee(()=>!!r());return()=>t()?C(Ef,{}):C(Xl,{})})()),e})()}const Xs=document.getElementById("root");if(!Xs)throw new Error("Root element not found");fo(()=>C(Pf,{}),Xs);export{Df as M,ge as a,xt as b,ae as c,ke as d,Nf as e,Ie as f,Gf as g,Ui as h,v as i,ss as j,ks as k,Ms as l,Yh as m,md as n,Oe as o,je as p,B as s,R as t,lr as u,ii as w};
|