screeps-client 0.3.5 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/embedded/assets/{CodePanel-DwY4J5sq.js → CodePanel-DkDYXbQL.js} +1 -1
- package/dist/embedded/assets/{MapViewer-DQGXhk2D.js → MapViewer-CoCRN8TR.js} +1 -1
- package/dist/embedded/assets/index-DTRa3SgN.js +24 -0
- package/dist/embedded/index.html +1 -1
- package/dist/{xxscreeps-mod/assets/CodePanel-CTa3DpMi.js → standalone/assets/CodePanel-C0efW9c6.js} +1 -1
- package/dist/standalone/assets/{MapViewer-YLclqH-L.js → MapViewer-BN8i0uFB.js} +1 -1
- package/dist/standalone/assets/index-Cd5zMBNk.js +24 -0
- package/dist/standalone/index.html +1 -1
- package/dist/{standalone/assets/CodePanel-BXBo2h-F.js → xxscreeps-mod/assets/CodePanel-OjDhyKF-.js} +1 -1
- package/dist/xxscreeps-mod/assets/{MapViewer-DhpwVvu_.js → MapViewer-B7WO94rt.js} +1 -1
- package/dist/xxscreeps-mod/assets/index-D5eNG4b5.js +24 -0
- package/dist/xxscreeps-mod/index.html +1 -1
- package/package.json +1 -1
- package/dist/embedded/assets/index-CsVFgPW8.js +0 -24
- package/dist/standalone/assets/index-DlCmDpPr.js +0 -24
- package/dist/xxscreeps-mod/assets/index-C9JapZJr.js +0 -24
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodePanel-BXBo2h-F.js","assets/vendor-codemirror-D3PB7yT8.js","assets/vendor-pixi-CXkRT4gi.js","assets/MapViewer-YLclqH-L.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
var So=Object.defineProperty;var ko=(r,e,t)=>e in r?So(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var _=(r,e,t)=>ko(r,typeof e!="symbol"?e+"":e,t);import{k as ps,j as N,i as wr,v as gs,w as fe,$ as Co,u as Ce,l as G,p as be,f as S,F as ve,S as X,h as de,r as Ge,D as To,a as Ct,d as Mo,b as En,m as Hi,s as Mr,q as Eo,o as ms}from"./vendor-codemirror-D3PB7yT8.js";import{a as Pe,G as te,A as ys,P as nr,R as vs,N as Ro,S as Vt,B as Po,c as yt,T as Yt,b as Oo,C as Lo,_ as bs}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 Ao=["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",...Ao]),No=new Set(["innerHTML","textContent","innerText","children"]),Go=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),Do=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 zo(r,e){const t=Do[r];return typeof t=="object"?t[e]?t.$:void 0:t}const Bo=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),Ho=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"]),Fo={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},ie=r=>wr(()=>r());function Wo(r,e,t){let i=t.length,n=e.length,s=i,o=0,l=0,a=e[n-1].nextSibling,c=null;for(;o<n||l<s;){if(e[o]===t[l]){o++,l++;continue}for(;e[n-1]===t[s-1];)n--,s--;if(n===o){const d=s<i?l?t[l-1].nextSibling:t[s-l]:a;for(;l<s;)r.insertBefore(t[l++],d)}else if(s===l)for(;o<n;)(!c||!c.has(e[o]))&&e[o].remove(),o++;else if(e[o]===t[s-1]&&t[l]===e[n-1]){const d=e[--n].nextSibling;r.insertBefore(t[l++],e[o++].nextSibling),r.insertBefore(t[--s],d),e[n]=t[s]}else{if(!c){c=new Map;let h=l;for(;h<s;)c.set(t[h],h++)}const d=c.get(e[o]);if(d!=null)if(l<d&&d<s){let h=o,f=1,u;for(;++h<n&&h<s&&!((u=c.get(e[h]))==null||u!==d+f);)f++;if(f>d-l){const p=e[o];for(;l<d;)r.insertBefore(t[l++],p)}else r.replaceChild(t[l++],e[o++])}else o++;else e[o++].remove()}}}const Rn="_$DX_DELEGATE";function Uo(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 ps(s=>{n=s,e===document?r():y(e,r(),e.firstChild?null:void 0,t)},i.owner),()=>{n(),e.textContent=""}}function E(r,e,t,i){let n;const s=()=>{if(ft())throw new Error("Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration.");const l=document.createElement("template");return l.innerHTML=r,l.content.firstChild},o=()=>(n||(n=s())).cloneNode(!0);return o.cloneNode=o,o}function ke(r,e=window.document){const t=e[Rn]||(e[Rn]=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,Jo))}}function _e(r,e,t){ft(r)||(t==null?r.removeAttribute(e):r.setAttribute(e,t))}function Xo(r,e,t,i){ft(r)||(i==null?r.removeAttributeNS(e,t):r.setAttributeNS(e,t,i))}function Yo(r,e,t){ft(r)||(t?r.setAttribute(e,""):r.removeAttribute(e))}function qo(r,e){ft(r)||(e==null?r.removeAttribute("class"):r.className=e)}function ct(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 jo(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 l=n[s];!l||l==="undefined"||e[l]||(Pn(r,l,!1),delete t[l])}for(s=0,o=i.length;s<o;s++){const l=i[s],a=!!e[l];!l||l==="undefined"||t[l]===a||!a||(Pn(r,l,!0),t[l]=a)}return t}function Z(r,e,t){if(!e)return t?_e(r,"style"):e;const i=r.style;if(typeof e=="string")return i.cssText=e;typeof t=="string"&&(i.cssText=t=void 0),t||(t={}),e||(e={});let n,s;for(s in t)e[s]==null&&i.removeProperty(s),delete t[s];for(s in e)n=e[s],n!==t[s]&&(i.setProperty(s,n),t[s]=n);return t}function D(r,e,t){t!=null?r.style.setProperty(e,t):r.style.removeProperty(e)}function ws(r,e={},t,i){const n={};return i||N(()=>n.children=xr(r,e.children,n.children)),N(()=>typeof e.ref=="function"&&pr(e.ref,r)),N(()=>Vo(r,e,t,!0,n,!0)),n}function pr(r,e,t){return fe(()=>r(e,t))}function y(r,e,t,i){if(t!==void 0&&!i&&(i=[]),typeof e!="function")return xr(r,e,i,t);N(n=>xr(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]=On(r,o,null,n[o],t,s,e)}for(const o in e){if(o==="children")continue;const l=e[o];n[o]=On(r,o,l,n[o],t,s,e)}}function Zo(r){let e,t,i=ft();if(!i||!(e=Ce.registry.get(t=Qo()))){if(i)throw Ce.done=!0,new Error(`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${t}
|
|
3
|
-
`);return r()}return Ce.completed&&Ce.completed.add(e),Ce.registry.delete(t),e}function ft(r){return!!Ce.context&&!Ce.done&&(!r||r.isConnected)}function Ko(r){return r.toLowerCase().replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function Pn(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 On(r,e,t,i,n,s,o){let l,a,c,d,h;if(e==="style")return Z(r,t,i);if(e==="classList")return jo(r,t,i);if(t===i)return i;if(e==="ref")s||t(r);else if(e.slice(0,3)==="on:"){const f=e.slice(3);i&&r.removeEventListener(f,i,typeof i!="function"&&i),t&&r.addEventListener(f,t,typeof t!="function"&&t)}else if(e.slice(0,10)==="oncapture:"){const f=e.slice(10);i&&r.removeEventListener(f,i,!0),t&&r.addEventListener(f,t,!0)}else if(e.slice(0,2)==="on"){const f=e.slice(2).toLowerCase(),u=Bo.has(f);if(!u&&i){const p=Array.isArray(i)?i[0]:i;r.removeEventListener(f,p)}(u||t)&&(ct(r,f,t,u),u&&ke([f]))}else if(e.slice(0,5)==="attr:")_e(r,e.slice(5),t);else if(e.slice(0,5)==="bool:")Yo(r,e.slice(5),t);else if((h=e.slice(0,5)==="prop:")||(c=No.has(e))||!n&&((d=zo(e,r.tagName))||(a=Io.has(e)))||(l=r.nodeName.includes("-")||"is"in o)){if(h)e=e.slice(5),a=!0;else if(ft(r))return t;e==="class"||e==="className"?qo(r,t):l&&!a&&!c?r[Ko(e)]=t:r[d||e]=t}else{const f=n&&e.indexOf(":")>-1&&Fo[e.split(":")[0]];f?Xo(r,f,e,t):_e(r,Go[e]||e,t)}return t}function Jo(r){if(Ce.registry&&Ce.events&&Ce.events.find(([a,c])=>c===r))return;let e=r.target;const t=`$$${r.type}`,i=r.target,n=r.currentTarget,s=a=>Object.defineProperty(r,"target",{configurable:!0,value:a}),o=()=>{const a=e[t];if(a&&!e.disabled){const c=e[`${t}Data`];if(c!==void 0?a.call(e,c,r):a.call(e,r),r.cancelBubble)return}return e.host&&typeof e.host!="string"&&!e.host._$host&&e.contains(r.target)&&s(e.host),!0},l=()=>{for(;o()&&(e=e._$host||e.parentNode||e.host););};if(Object.defineProperty(r,"currentTarget",{configurable:!0,get(){return e||document}}),Ce.registry&&!Ce.done&&(Ce.done=_$HY.done=!0),r.composedPath){const a=r.composedPath();s(a[0]);for(let c=0;c<a.length-2&&(e=a[c],!!o());c++){if(e._$host){e=e._$host,l();break}if(e.parentNode===n)break}}else l();s(i)}function xr(r,e,t,i,n){const s=ft(r);if(s){!t&&(t=[...r.childNodes]);let a=[];for(let c=0;c<t.length;c++){const d=t[c];d.nodeType===8&&d.data.slice(0,2)==="!$"?d.remove():a.push(d)}t=a}for(;typeof t=="function";)t=t();if(e===t)return t;const o=typeof e,l=i!==void 0;if(r=l&&t[0]&&t[0].parentNode||r,o==="string"||o==="number"){if(s||o==="number"&&(e=e.toString(),e===t))return t;if(l){let a=t[0];a&&a.nodeType===3?a.data!==e&&(a.data=e):a=document.createTextNode(e),t=Rt(r,t,i,a)}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=Rt(r,t,i)}else{if(o==="function")return N(()=>{let a=e();for(;typeof a=="function";)a=a();t=xr(r,a,t,i)}),()=>t;if(Array.isArray(e)){const a=[],c=t&&Array.isArray(t);if(Fi(a,e,t,n))return N(()=>t=xr(r,a,t,i,!0)),()=>t;if(s){if(!a.length)return t;if(i===void 0)return t=[...r.childNodes];let d=a[0];if(d.parentNode!==r)return t;const h=[d];for(;(d=d.nextSibling)!==i;)h.push(d);return t=h}if(a.length===0){if(t=Rt(r,t,i),l)return t}else c?t.length===0?Ln(r,a,i):Wo(r,t,a):(t&&Rt(r),Ln(r,a));t=a}else if(e.nodeType){if(s&&e.parentNode)return t=l?[e]:e;if(Array.isArray(t)){if(l)return t=Rt(r,t,i,e);Rt(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 Fi(r,e,t,i){let n=!1;for(let s=0,o=e.length;s<o;s++){let l=e[s],a=t&&t[r.length],c;if(!(l==null||l===!0||l===!1))if((c=typeof l)=="object"&&l.nodeType)r.push(l);else if(Array.isArray(l))n=Fi(r,l,a)||n;else if(c==="function")if(i){for(;typeof l=="function";)l=l();n=Fi(r,Array.isArray(l)?l:[l],Array.isArray(a)?a:[a])||n}else r.push(l),n=!0;else{const d=String(l);a&&a.nodeType===3&&a.data===d?r.push(a):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 Rt(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 l=e[o];if(n!==l){const a=l.parentNode===r;!s&&!o?a?r.replaceChild(n,l):r.insertBefore(n,t):a&&l.remove()}else s=!0}}else r.insertBefore(n,t);return[n]}function Qo(){return Ce.getNextContextId()}const el="http://www.w3.org/2000/svg";function tl(r,e=!1,t=void 0){return e?document.createElementNS(el,r):document.createElement(r,{is:t})}function rl(r,e){const t=wr(r);return wr(()=>{const i=t();switch(typeof i){case"function":return Object.assign(i,{[Co]:!0}),fe(()=>i(e));case"string":const n=Ho.has(i),s=Ce.context?Zo():tl(i,n,fe(()=>e.is));return ws(s,e,n),s}})}function xs(r){const[,e]=gs(r,["component"]);return rl(()=>r.component,e)}async function _s(r,e){const t=r.slice(3),i=Uint8Array.from(atob(t),h=>h.charCodeAt(0)),n=new DecompressionStream(e),s=n.writable.getWriter();await s.write(i),await s.close();const o=n.readable.getReader(),l=[];try{for(;;){const{done:h,value:f}=await o.read();if(h)break;l.push(f)}}catch(h){throw o.cancel(),h}let a=0;for(const h of l)a+=h.length;const c=new Uint8Array(a);let d=0;for(const h of l)c.set(h,d),d+=h.length;return JSON.parse(new TextDecoder().decode(c))}function il(r){return _s(r,"gzip")}function nl(r){return _s(r,"deflate")}class tt{constructor(e){_(this,"fn");this.fn=e}static create(e){return e===!0?new tt(console.debug.bind(console)):typeof e=="function"?new tt(e):new tt(null)}child(e){if(!this.fn)return this;const t=this.fn;return new tt((...i)=>t(`[screeps:${e}]`,...i))}log(...e){var t;(t=this.fn)==null||t.call(this,...e)}}function sl(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 ol(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 Se(r,e){return e&&(r.shard=e),r}function ll(r){return{roomTerrain:(e,t)=>r.request("GET","/api/game/room-terrain",Se({room:e,encoded:1},t)),roomObjects:(e,t)=>r.request("GET","/api/game/room-objects",Se({room:e},t)),roomStatus:(e,t)=>r.request("GET","/api/game/room-status",Se({room:e},t)),roomOverview:(e,t=8,i)=>r.request("GET","/api/game/room-overview",Se({room:e,interval:t},i)),time:e=>r.request("GET","/api/game/time",Se({},e)),worldSize:e=>r.request("GET","/api/game/world-size",Se({},e)),mapStats:(e,t,i)=>r.request("POST","/api/game/map-stats",Se({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,l)=>r.request("POST","/api/game/create-flag",Se({room:e,x:t,y:i,name:n,color:s,secondaryColor:o},l)),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",Se({type:e},t)),checkUniqueObjectName:(e,t,i)=>r.request("POST","/api/game/check-unique-object-name",Se({type:e,name:t},i)),placeSpawn:(e,t,i,n,s)=>r.request("POST","/api/game/place-spawn",Se({room:e,x:t,y:i,...n?{name:n}:{}},s)),createConstruction:(e,t,i,n,s,o)=>r.request("POST","/api/game/create-construction",Se({room:e,x:t,y:i,structureType:n,...s?{name:s}:{}},o)),removeConstructionSite:(e,t,i)=>r.request("POST","/api/game/add-object-intent",Se({_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:ol(r),market:{ordersIndex:e=>r.request("GET","/api/game/market/orders-index",Se({},e)),myOrders:()=>r.request("GET","/api/game/market/my-orders"),orders:(e,t)=>r.request("GET","/api/game/market/orders",Se({resourceType:e},t)),stats:(e,t)=>r.request("GET","/api/game/market/stats",Se({resourceType:e},t))},shards:{info:()=>r.request("GET","/api/game/shards/info")}}}function al(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 Pt(r,e){return e&&(r.shard=e),r}function cl(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",Pt({path:e},t)),set:(e,t,i)=>r.request("POST","/api/user/memory",Pt({path:e,value:t},i)),segment:{get:(e,t)=>r.request("GET","/api/user/memory-segment",Pt({segment:e},t)),set:(e,t,i)=>r.request("POST","/api/user/memory-segment",Pt({segment:e,data:t},i))}},console:(e,t)=>r.request("POST","/api/user/console",Pt({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",Pt({},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:al(r)}}function dl(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 ul(r){return{pvp:(e=100)=>r.request("GET","/api/experimental/pvp",{interval:e}),nukes:()=>r.request("GET","/api/experimental/nukes")}}function hl(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 fl 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??tt.create(),this.serverPassword=t.serverPassword??null,this.auth=sl(this),this.register=hl(this),this.game=ll(this),this.user=cl(this),this.leaderboard=dl(this),this.experimental=ul(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),l={};this.token&&(l["X-Token"]=this.token,l["X-Username"]=this.token),this.serverPassword&&(l["X-Server-Password"]=this.serverPassword);const a={method:t,headers:l};if(t==="GET"&&n)for(const[f,u]of Object.entries(n))u!=null&&o.searchParams.set(f,String(u));else n&&(l["Content-Type"]="application/json",a.body=JSON.stringify(n));const c=await fetch(o.toString(),a),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 f="";try{f=await c.text()}catch{}const u=new Error(`HTTP ${c.status}: ${f}`);throw this.emit("http:error",{method:t,path:i,status:c.status,error:u}),u}this.emit("http:success",{method:t,path:i,status:c.status});const h=await c.json();if(typeof h.error=="string"){const f=new Error(`Screeps API error: ${h.error}`);throw this.emit("http:error",{method:t,path:i,status:c.status,error:f}),f}return typeof h.data=="string"&&h.data.startsWith("gz:")&&(h.data=await il(h.data)),h}updateRateLimit(t,i){const n=i.headers.get("x-ratelimit-limit"),s=i.headers.get("x-ratelimit-remaining"),o=i.headers.get("x-ratelimit-reset");n&&s&&o&&this.rateLimits.set(t,{limit:parseInt(n,10),remaining:parseInt(s,10),reset:parseInt(o,10)})}}async function pl(r){let e=typeof r=="string"?r:r.data;if(e.startsWith("gz:")&&(e=JSON.stringify(await nl(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 gl{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??tt.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 l=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:",l),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 pl(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 ml{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 Qt extends EventTarget{constructor(t){super();_(this,"logger");this.logger=t??tt.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 Fe=(r=>(r[r.Plain=0]="Plain",r[r.Wall=1]="Wall",r[r.Swamp=2]="Swamp",r))(Fe||{});class Ht{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 Ht(t)}get(e,t){return this.raw[t*50+e]}}class yl extends Qt{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 l=o.split("~");if(l.length!==5)continue;const[a,c,d,h,f]=l,u=parseInt(c,10),p=parseInt(d,10),w=parseInt(h,10),C=parseInt(f,10);isNaN(u)||isNaN(p)||isNaN(w)||isNaN(C)||n.push({_id:a,type:"flag",room:i,name:a,x:w,y:C,color:u,secondaryColor:p})}return n}async terrain(t,i){const n=`terrain/${i}/${t}`,s=this.cache.get(n);if(s)return this.logger.log("terrain",t,i,"(memory cache hit)"),s;const o=await this.cache.getPersistent(n);if(o){this.logger.log("terrain",t,i,"(persistent cache hit)");const d=new Ht(o);return this.cache.set(n,d),d}this.logger.log("terrain",t,i,"(fetching)");const a=(await this.http.game.roomTerrain(t,i??void 0)).terrain[0];if(!a)throw new Error(`No terrain data for room ${t} shard ${i}`);const c=Ht.fromEncodedString(a.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 a of t){const c=this.cache.get(`terrain/${i}/${a}`);c?n.set(a,c):s.push(a)}if(s.length===0)return n;const o=[];if(await Promise.all(s.map(async a=>{const c=`terrain/${i}/${a}`,d=await this.cache.getPersistent(c);if(d){const h=new Ht(d);this.cache.set(c,h),n.set(a,h)}else o.push(a)})),o.length===0)return n;this.logger.log("terrainBulk",`fetching ${o.length} rooms`,i);const l=await this.http.game.roomsTerrain(o,i??void 0);return await Promise.all(l.rooms.map(async a=>{const c=Ht.fromEncodedString(a.terrain),d=`terrain/${i}/${a.room}`;this.cache.set(d,c),await this.cache.setPersistent(d,c.raw),this.emit("room:terrainavailable",{room:a.room,shard:i,terrain:c}),n.set(a.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 a of s.objects)a&&typeof a=="object"&&"_id"in a&&(o[a._id]=a);this.roomObjects.set(n,o);const l=this.roomUsers.get(n);this.emit("room:update",{room:t,shard:i,gameTime:void 0,objects:o,diff:o,visual:"",users:l})}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}`,l=i?`err@room:${i}/${t}`:`err@room:${t}`,a=this.socket.subscribe(o),c=this.socket.on(l,h=>{const f=typeof h=="string"?h:JSON.stringify(h);this.logger.log("room error",t,i,f),this.emit("room:error",{room:t,shard:i,message:f})}),d=this.socket.on(o,h=>{const f=h,u={...this.roomObjects.get(n)??{}};if(f.objects==null)f.objects===null&&this.logger.log("room update has null objects field",t,i,`gameTime: ${f.gameTime}`);else for(const[C,g]of Object.entries(f.objects))g===null?delete u[C]:u[C]?u[C]={...u[C],...g}:u[C]=g;const p={...f.objects??{}};if("flags"in f){const C=f.flags??"",g=this.lastFlagsString.get(n)??"";if(C!==g){this.lastFlagsString.set(n,C);const k=this.parseFlagsString(C,t),O=new Map;for(const b of k)O.set(b.name,b);for(const b in u){const v=u[b];(v==null?void 0:v.type)==="flag"&&!O.has(b)&&(delete u[b],p[b]=null,this.logger.log(`[flag:room] removed ${b} @ ${t}`))}for(const[b,v]of O){const T=u[b];(!T||T.x!==v.x||T.y!==v.y||T.color!==v.color||T.secondaryColor!==v.secondaryColor)&&(u[b]=v,p[b]=v,this.logger.log(`[flag:room] ${T?"changed":"added"} ${b} @ ${t} (${v.x},${v.y})`))}}}if(f.users){const C=this.roomUsers.get(n)??{};this.roomUsers.set(n,{...C,...f.users})}this.roomObjects.set(n,u);const w=this.roomUsers.get(n);this.emit("room:update",{room:t,shard:i,gameTime:f.gameTime,objects:u,diff:p,visual:f.visual??"",users:w})});return{dispose:()=>{a.dispose(),d.dispose(),c.dispose();const h=(this.roomSubCount.get(n)??1)-1;h<=0?(this.roomSubCount.delete(n),this.roomObjects.delete(n),this.roomUsers.delete(n),this.lastFlagsString.delete(n),this.logger.log("unsubscribe",t,i,"(last ref)","active:",this.activeRooms())):(this.roomSubCount.set(n,h),this.logger.log("unsubscribe",t,i,`(refs: ${h})`,"active:",this.activeRooms()))}}}}class vl extends Qt{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 l=this._userId??(await this.me())._id;if(s)return;const a=`user:${l}/${t}`;i=this.socket.subscribe(a),n=this.socket.on(a,c=>{var d,h,f;if(t==="cpu")this._cpu=c,this.emit("user:cpu",this._cpu);else if(t==="console"){const u=c,p={log:((d=u.messages)==null?void 0:d.log)??[],results:((h=u.messages)==null?void 0:h.results)??[],error:((f=u.messages)==null?void 0:f.error)??[]};u.error&&p.error.push(u.error),this.console.push(p),this.console.length>this.maxConsoleSize&&this.console.splice(0,this.console.length-this.maxConsoleSize),this.emit("user:console",{messages:p})}else t==="code"&&this.emit("user:code",c)})}catch(l){s||this.dispatchEvent(new ErrorEvent("error",{error:l instanceof Error?l:new Error(String(l))}))}})(),{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 l=`user:${o}`;t=this.socket.subscribe(l),i=this.socket.on(l,a=>{const c=a;if(c&&typeof c=="object"&&"flags"in c){const d=c.flags;if(d&&typeof d=="object")for(const[h,f]of Object.entries(d)){const u=f;if(u&&typeof u=="object"){const p=u.room??"unknown",w=u.x??"?",C=u.y??"?";this.logger.log(`[flag:user] ${h} @ ${p} (${w},${C})`)}}}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 bl extends Qt{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 l=o;this.emit("server:disconnected",{willReconnect:l.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 l=await this.http.request("GET","/api/game/world-size",o),{width:a,height:c}=l;this.logger.log(`worldInfo shard=${t??"none"} — raw size: ${a}x${c}`);let d=-a,h=-1,f=-c,u=-1;try{const C=(await this.http.request("POST","/api/game/map-stats",{rooms:["W0N0","E0N0","W0S0","E0S0"],statName:"owner0",...o})).stats??{},g=["W0N0","E0N0","W0S0","E0S0"].filter(k=>k in C);this.logger.log(`worldInfo corner probe — found: [${g.length?g.join(", "):"none"}]`),("E0N0"in C||"E0S0"in C)&&(d=-Math.ceil(a/2),h=Math.floor(a/2)-1),("W0S0"in C||"E0S0"in C)&&(f=-Math.ceil(c/2),u=Math.floor(c/2)-1)}catch(w){this.logger.log("worldInfo corner probe failed — keeping W/N defaults:",w)}this.logger.log(`worldInfo computed bounds — x: [${d}, ${h}] y: [${f}, ${u}]`);const p={shard:t??null,width:a,height:c,minX:d,maxX:h,minY:f,maxY:u};return this.cache.set(n,p,10*6e4),p}invalidateWorldInfo(t){this.cache.delete(`server/world/${t??"default"}`)}}class wl{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 An(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 xl extends Qt{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 a=this.getOrCreateKeyState(n,"active");return this.emitWarmStart(t,i),this.makeSubscription(t,i,n,a)}const o=this.waitlist.find(a=>a.key===n);if(o){o.refCount++,this.logger.log("subscribeMap2",t,i,`(pending, refs: ${o.refCount})`);const a=this.getOrCreateKeyState(n,"pending");return this.emitWarmStart(t,i),this.makeSubscription(t,i,n,a)}if(this.active.size<this.maxSubscriptions){this.activateKey(t,i,n,1),this.logger.log("subscribeMap2",t,i,"(new active)");const a=this.getOrCreateKeyState(n,"active");return this.emit("room:map2state",{room:t,shard:i,status:"active"}),this.emitWarmStart(t,i),this.makeSubscription(t,i,n,a)}this.waitlist.push({key:n,room:t,shard:i,refCount:1}),this.logger.log("subscribeMap2",t,i,"(new pending)");const l=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,l)}activateKey(t,i,n,s){const o=i?`roomMap2:${i}/${t}`:`roomMap2:${t}`,l=this.socket.subscribe(o),a=this.storage.getMemory(t,i),c={room:t,shard:i,refCount:s,socketSub:l,listenerSub:void 0,lastHash:a?An(a):null};c.listenerSub=this.socket.on(o,d=>{const h=d,f=An(h);c.lastHash!==f&&(c.lastHash=f,this.storage.put(t,i,h),this.emit("room:map2update",{room:t,shard:i,data:h,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:l=>(s.statusHandlers.add(l),{dispose:()=>{s.statusHandlers.delete(l)}}),dispose:()=>{o||(o=!0,this.disposeSubscription(t,i,n))}}}disposeSubscription(t,i,n){const s=this.waitlist.findIndex(l=>l.key===n);if(s>=0){const l=this.waitlist[s];l.refCount--,this.logger.log("unsubscribeMap2",t,i,`(pending, refs: ${l.refCount})`),l.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 _l extends Qt{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 a=Date.now()-this.lastFlushTime,c=Math.max(this.debounceMs,this.minIntervalMs-a);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[l,a]of Object.entries(s.stats)){const c=this.buildData(a,o);this.emit("mapStats:room",{room:l,shard:i.shard==="shard0"?null:i.shard,stat:c})}for(const l of n)s.stats[l]||this.emit("mapStats:room",{room:l,shard:i.shard==="shard0"?null:i.shard,stat:{}})}catch(s){this.logger.log("mapStats fetch failed:",s)}}}buildData(t,i){var l,a,c;let n,s;for(let d=0;d<3;d++){const h=`minerals${d}`,f=t[h];if(f){n=f.type,s=f.density;break}}const o=(l=t.own)==null?void 0:l.user;return{own:t.own,mineral:n,density:s,username:o?(a=i[o])==null?void 0:a.username:void 0,safeMode:t.safeMode,badge:o?(c=i[o])==null?void 0:c.badge:void 0,status:t.status}}}class $l extends Qt{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 Sl{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=tt.create(e.debug),this.logger.log(`[screeps:client] init ${e.url}`),this.cache=new ml(t,e.storage??null),this.http=new fl({url:e.url,auth:e.auth,logger:this.logger.child("http"),serverPassword:e.serverPassword}),this.socket=new gl({url:e.url,WebSocket:e.WebSocket,logger:this.logger.child("socket")});const i=new wl({adapter:e.storage??null,namespace:t,maxEntries:((n=e.map2)==null?void 0:n.maxCacheEntries)??1e4});this.stores={room:new yl(this.http,this.socket,this.cache,this.logger.child("room")),user:new vl(this.http,this.socket,this.cache,this.logger.child("user")),server:new bl(this.http,this.socket,this.cache,this.logger.child("server")),map:new xl(this.socket,i,{maxSubscriptions:((s=e.map2)==null?void 0:s.maxSubscriptions)??500},this.logger.child("map")),mapStats:new _l(this.http,100,500,this.logger.child("mapStats")),navigation:new $l(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 kl{constructor(e){_(this,"token");this.token=e.token}async authenticate(e){return this.token}}class Cl{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 Tl{async authenticate(e){return"guest"}}const Ml=1,je="data";class El{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,Ml);i.onupgradeneeded=()=>{i.result.createObjectStore(je)},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(je,"readonly").objectStore(je).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 l=i.transaction(je,"readwrite").objectStore(je).put(t,e);l.onsuccess=()=>n(),l.onerror=()=>s(l.error)})}async delete(e){const t=await this.open();return new Promise((i,n)=>{const o=t.transaction(je,"readwrite").objectStore(je).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(je,"readwrite").objectStore(je).clear();s.onsuccess=()=>t(),s.onerror=()=>i(s.error)})}}class vn{constructor(){_(this,"subs",[])}add(e){this.subs.push(e)}dispose(){for(const e of this.subs)e.dispose();this.subs.length=0}}const Rl=5*6e4;function $s(r,e){try{return`screeps:${r}:${new URL(e).hostname}`}catch{return`screeps:${r}:${e}`}}function Ss(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 ks(r,e){if(!(typeof sessionStorage>"u"))try{sessionStorage.setItem(r,JSON.stringify({data:e,expires:Date.now()+Rl}))}catch{}}function Er(r){return r.endsWith("/")?r:`${r}/`}async function Pl(r){const e=$s("version",r),t=Ss(e);if(t)return t;const i=await fetch(`${Er(r)}api/version`);if(!i.ok)throw new Error(`HTTP ${i.status}`);const n=await i.json();return ks(e,n),n}async function Ol(r){const e=$s("authmod",r),t=Ss(e);if(t)return t;const i=await fetch(`${Er(r)}api/authmod`);if(!i.ok)return null;const n=await i.json();return n.ok?(ks(e,n),n):null}async function Ll(r,e){const t=new URLSearchParams({username:e}),i=await fetch(`${Er(r)}api/register/check-username?${t}`);if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}async function Al(r,e){const t=new URLSearchParams({email:e}),i=await fetch(`${Er(r)}api/register/check-email?${t}`);if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}async function Il(r,e,t,i){const n=await fetch(`${Er(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 Nl(r,e){return r.serverData.features.find(t=>t.name===e)}function Cs(r){return Nl(r,"screepsmod-auth")}const pi={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 gi(r){const e=Math.round(r).toString(16);return e.length<2?"0"+e:e}function ot(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,l=0,a=0;!Number.isNaN(r)&&r!==null&&r!==void 0&&(n>=0&&n<1?(o=i,l=s,a=0):n>=1&&n<2?(o=s,l=i,a=0):n>=2&&n<3?(o=0,l=i,a=s):n>=3&&n<4?(o=0,l=s,a=i):n>=4&&n<5?(o=s,l=0,a=i):n>=5&&n<6&&(o=i,l=0,a=s));const c=t-i/2,d=(o+c)*255,h=(l+c)*255,f=(a+c)*255;return"#"+gi(d)+gi(h)+gi(f)}function Gl(){const r=[];let e=0;r.push({index:e++,rgb:ot(0,0,.8)});for(let t=0;t<19;t++)r.push({index:e++,rgb:ot(t*360/19,.6,.8)});r.push({index:e++,rgb:ot(0,0,.5)});for(let t=0;t<19;t++)r.push({index:e++,rgb:ot(t*360/19,.7,.5)});r.push({index:e++,rgb:ot(0,0,.3)});for(let t=0;t<19;t++)r.push({index:e++,rgb:ot(t*360/19,.4,.3)});r.push({index:e++,rgb:ot(0,0,.1)});for(let t=0;t<19;t++)r.push({index:e++,rgb:ot(t*360/19,.5,.1)});return r}const gr=Gl();function mi(r){if(typeof r=="string")return r;if(typeof r=="number"){const e=gr[r];return e?e.rgb:"#000000"}return"#000000"}function ci(r){const e=mi(r.color1),t=mi(r.color2),i=mi(r.color3),n=r.param??0;if(typeof r.type=="number"){const d=pi[r.type];d&&d.calc(n)}let s=0;if(r.flip&&typeof r.type=="number"){const d=pi[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,l;if(typeof r.type=="number"){const d=pi[r.type];o=(d==null?void 0:d.path1)??"",l=(d==null?void 0:d.path2)??""}else o=r.type.path1,l=r.type.path2;const a=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="${a}"/></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)"/>`),l&&(c+=`<path d="${l}" 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[Dl,In]=G([]);let zl=0;function ye(r,e="success",t=4e3){const i=zl++;In(n=>[...n,{id:i,message:r,type:e,duration:t}]),setTimeout(()=>{In(n=>n.filter(s=>s.id!==i))},t)}const Bl=!1;function di(){return typeof window>"u"?!1:window.location.pathname.startsWith("/client")}function Hl(){return Bl}function bn(){return window.location.origin}function Fl(){return"0.3.5"}function Wl(){return typeof window>"u"?null:window.__SCREEPS_CLIENT_EMBEDDED__??null}function ui(){return"/".replace(/\/$/,"")}function Et(r){const e=`[${r}]`;return{log:()=>{},warn:()=>{},error:(...t)=>console.error(e,...t)}}const me={room:"screeps:room",shard:"screeps:shard",sidebarWidth:"screeps:sidebarWidth",consoleHeight:"screeps:consoleHeight",consoleWeights:"screeps:consoleWeights",mapZoom:"screeps:mapZoom",widescreenMode:"screeps:settings:widescreenMode",showCreepLabels:"screeps:settings:showCreepLabels",showMapRoomNames:"screeps:settings:showMapRoomNames",showUnclaimableRooms:"screeps:settings:showUnclaimableRooms",terrainEffects:"screeps:settings:terrainEffects",showRoomVisuals:"screeps:settings:showRoomVisuals"},Re={url:"screeps:url",token:"screeps:token",serverPassword:"screeps:serverPassword"};function yi(r){return localStorage.getItem(r)}function Nn(r,e){localStorage.setItem(r,e)}function Ul(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 vi(r,e){localStorage.setItem(r,String(e))}function Xl(r,e){const t=localStorage.getItem(r);if(t===null)return e;try{return JSON.parse(t)}catch{return e}}function Yl(r,e){localStorage.setItem(r,JSON.stringify(e))}function Fr(r){return sessionStorage.getItem(r)}function Lr(r,e){sessionStorage.setItem(r,e)}function mr(r){sessionStorage.removeItem(r)}async function ql(){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:Ue}=Et("client"),[ae,Wr]=G(null),[$t,Gt]=G("idle"),[Gn,Ur]=G(null),[Ne,Wi]=G(null),[Ts,Ui]=G(null),[Ie,Xr]=G(null),[Jr,Ms]=G(null),[He,Es]=G(!1),[bi,Rs]=G(null),[jl,Ps]=G({}),[Tt,Os]=G(null);let Yr=-1,Xi=-1;const Dt=[],Vl=5;function Zl(r){if(r===void 0)return;const e=Date.now();if(Yr>=0&&r>Yr){const t=e-Xi;if(t>0){Dt.push(t),Dt.length>Vl&&Dt.shift();const i=Dt.reduce((n,s)=>n+s,0)/Dt.length;Ms(Math.round(i))}}Yr=r,Xi=e}function Kl(){Yr=-1,Xi=-1,Dt.length=0,Ms(null)}const Jl=()=>{var e,t;const r=Ts();return r?(((t=(e=r.serverData)==null?void 0:e.shards)==null?void 0:t.length)??0)===0:null};async function wt(r){di()&&(r={...r,url:bn()}),Ue(`connecting to ${r.url} (auth: ${r.auth})`),Gt("connecting"),Ur(null);try{let e;if(r.auth==="guest")e=new Tl,Es(!0);else if(r.auth==="password"){if(!r.email||!r.password)throw new Error("Email and password are required");e=new Cl({email:r.email,password:r.password})}else{if(!r.token)throw new Error("Token is required");e=new kl({token:r.token})}const t=new Sl({url:r.url,auth:e,storage:r.storage??new El("screeps-client"),debug:!1,serverPassword:r.serverPassword});t.http.on("http:tokenRefresh",({token:i})=>{Ue("token refreshed"),Lr(Re.token,i)}),t.http.on("http:error",({method:i,path:n,error:s})=>{Ue("http error:",i,n,s.message),ye(`Request failed: ${i} ${n} — ${s.message}`,"error",6e3)}),t.stores.server.on("server:disconnected",i=>{Ue(`server disconnected (willReconnect: ${i.willReconnect})`),i.willReconnect||(Gt("idle"),Wr(null),Wi(null),Ui(null))}),t.stores.server.on("server:error",i=>{Ue("server error:",i.error.message),Ur(i.error.message),Gt("error")}),t.stores.user.on("user:me",i=>{Ue(`user: ${i.username} (id: ${i._id})`),Wi(i)}),t.stores.server.on("server:version",i=>{Ue(`server version: ${i.package??"unknown"}`),Ui(i)}),t.stores.user.on("user:stream",i=>{if(i&&typeof i=="object"&&"flags"in i){const n=i.flags;n&&typeof n=="object"&&Ps(n)}}),t.stores.user.on("user:worldStatus",({status:i})=>{Ue(`world status: ${i}`),Os(i)}),await t.connect(),t.stores.user.subscribeUserStream(),Wr(t),Gt("connected"),Ue(`connected to ${r.url}`),t.stores.server.worldInfo().then(i=>{Rs(i),Ue(`world: ${i.width}x${i.height} x[${i.minX},${i.maxX}] y[${i.minY},${i.maxY}]`)}).catch(()=>{}),Lr(Re.url,r.url),t.http.token&&Lr(Re.token,t.http.token),r.serverPassword?Lr(Re.serverPassword,r.serverPassword):mr(Re.serverPassword)}catch(e){const t=e instanceof Error?e.message:String(e);throw Ur(t),Gt("error"),Wr(null),e}}async function Ql(){const r=di()?bn():Fr(Re.url),e=Fr(Re.token);if(!r||!e)return;const t=Fr(Re.serverPassword)??void 0;try{e==="guest"?await wt({url:r,auth:"guest",storage:null,serverPassword:t}):await wt({url:r,auth:"token",token:e,serverPassword:t})}catch{mr(Re.token)}}function ea(){const r=ae();r&&r.disconnect(),Wr(null),Gt("idle"),Ur(null),Wi(null),Ui(null),Xr(null),Es(!1),Rs(null),Ps({}),Os(null),Kl(),mr(Re.token),mr(Re.url),mr(Re.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 ta={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"},Ot=ta,ra=E("<svg>"),Dn=r=>r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),ia=r=>r.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,i)=>i?i.toUpperCase():t.toLowerCase()),na=r=>{const e=ia(r);return e.charAt(0).toUpperCase()+e.slice(1)},sa=(...r)=>r.filter((e,t,i)=>!!e&&e.trim()!==""&&i.indexOf(e)===t).join(" ").trim(),oa=r=>{const[e,t]=gs(r,["color","size","strokeWidth","children","class","name","iconNode","absoluteStrokeWidth"]);return(()=>{var i=ra();return ws(i,be(Ot,{get width(){return e.size??Ot.width},get height(){return e.size??Ot.height},get stroke(){return e.color??Ot.stroke},get"stroke-width"(){return ie(()=>!!e.absoluteStrokeWidth)()?Number(e.strokeWidth??Ot["stroke-width"])*24/Number(e.size):Number(e.strokeWidth??Ot["stroke-width"])},get class(){return sa("lucide","lucide-icon",...e.name!=null?[`lucide-${Dn(na(e.name))}`,`lucide-${Dn(e.name)}`]:[],e.class!=null?e.class:"")}},t),!0,!0),y(i,S(ve,{get each(){return e.iconNode},children:([n,s])=>S(xs,be({component:n},s))})),i})()},$e=oa,la=[["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"}]],aa=r=>S($e,be(r,{iconNode:la,name:"bell-off"})),ca=aa,da=[["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"}]],ua=r=>S($e,be(r,{iconNode:da,name:"bell"})),ha=ua,fa=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],pa=r=>S($e,be(r,{iconNode:fa,name:"check"})),ga=pa,ma=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],ya=r=>S($e,be(r,{iconNode:ma,name:"chevron-right"})),va=ya,ba=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],wa=r=>S($e,be(r,{iconNode:ba,name:"chevron-left"})),xa=wa,_a=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]],$a=r=>S($e,be(r,{iconNode:_a,name:"clock"})),Sa=$a,ka=[["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"}]],Ca=r=>S($e,be(r,{iconNode:ka,name:"code-xml"})),Ta=Ca,Ma=[["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"}]],Ea=r=>S($e,be(r,{iconNode:Ma,name:"eye"})),Ra=Ea,Pa=[["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"}]],Oa=r=>S($e,be(r,{iconNode:Pa,name:"flag"})),Ls=Oa,La=[["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"}]],Aa=r=>S($e,be(r,{iconNode:La,name:"hammer"})),Ia=Aa,Na=[["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"}]],Ga=r=>S($e,be(r,{iconNode:Na,name:"layout-grid"})),Da=Ga,za=[["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"}]],Ba=r=>S($e,be(r,{iconNode:za,name:"log-out"})),Ha=Ba,Fa=[["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"}]],Wa=r=>S($e,be(r,{iconNode:Fa,name:"map"})),Ua=Wa,Xa=[["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"}]],Ya=r=>S($e,be(r,{iconNode:Xa,name:"move"})),qa=Ya,ja=[["rect",{x:"14",y:"4",width:"4",height:"16",rx:"1",key:"zuxfzm"}],["rect",{x:"6",y:"4",width:"4",height:"16",rx:"1",key:"1okwgv"}]],Va=r=>S($e,be(r,{iconNode:ja,name:"pause"})),Za=Va,Ka=[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]],Ja=r=>S($e,be(r,{iconNode:Ka,name:"play"})),Qa=Ja,ec=[["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"}]],tc=r=>S($e,be(r,{iconNode:ec,name:"settings"})),rc=tc,ic=[["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"}]],nc=r=>S($e,be(r,{iconNode:ic,name:"trash-2"})),qr=nc,sc=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],oc=r=>S($e,be(r,{iconNode:sc,name:"x"})),hi=oc,lc=E("<span style=font-size:11px;display:inline-flex;align-items:center;gap:3px>"),ac=E('<div style="color:#3fb950;font-size:14px;text-align:center;padding:8px 0">Account created! Logging you in…'),cc=E("<label style=display:flex;flex-direction:column;gap:4px><div style=display:flex;align-items:baseline;gap:8px><span style=font-size:12px;color:#8b949e>Username</span></div><input type=text name=username autocomplete=username>"),dc=E("<label style=display:flex;flex-direction:column;gap:4px><div style=display:flex;align-items:baseline;gap:8px><span style=font-size:12px;color:#8b949e>Email</span></div><input type=email name=email autocomplete=email>"),uc=E("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Password</span><input type=password name=new-password autocomplete=new-password>"),hc=E("<span style=font-size:11px;color:#f85149>Passwords don't match"),fc=E("<label style=display:flex;flex-direction:column;gap:4px><div style=display:flex;align-items:baseline;gap:8px><span style=font-size:12px;color:#8b949e>Confirm Password</span></div><input type=password name=confirm-password autocomplete=new-password>"),pc=E("<button type=submit style=padding:10px;border-radius:6px;border:none;background:#238636;color:#fff;font-weight:600>"),gc=E('<button type=button style="padding:8px;border-radius:6px;border:1px solid #30363d;background:transparent;color:#8b949e;font-size:12px;cursor:pointer">Back to Login'),mc=E("<form style=display:flex;flex-direction:column;gap:16px><h2 style=margin:0;font-size:20px>Create Account"),As=E("<div style=color:#f85149;font-size:13px>"),yc=E('<div style="width:360px;padding:16px 20px;border-radius:8px;background:#161b22;border:1px solid #30363d;color:#c9d1d9;font-size:13px;line-height:1.6">'),vc=E("<button type=button style=background:none;border:none;color:#58a6ff;font-size:12px;cursor:pointer;padding:0>Create account"),bc=E('<div style=display:flex;gap:8px><button type=button style="flex:1;padding:8px;border-radius:6px;border:1px solid #30363d;color:#fff;cursor:pointer">Password</button><button type=button style="flex:1;padding:8px;border-radius:6px;border:1px solid #30363d;color:#fff;cursor:pointer">Token'),wc=E("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Server URL</span><input type=url name=url autocomplete=url inputmode=url>"),xc=E("<div style=color:#8b949e;font-size:12px;margin-top:-8px>"),_c=E("<div style=display:flex;align-items:center;gap:8px;color:#484f58;font-size:12px><div style=flex:1;height:1px;background:#30363d></div>or<div style=flex:1;height:1px;background:#30363d>"),$c=E("<button type=button style=padding:10px;border-radius:6px;border:none;background:#1b2838;color:#c7d5e0;font-weight:600>Login with Steam"),Sc=E('<button type=button style="padding:8px;border-radius:6px;border:1px solid #30363d;background:transparent;color:#8b949e;font-size:12px">Connect as Guest (read-only)'),kc=E('<form style=display:flex;flex-direction:column;gap:16px><div style=display:flex;align-items:baseline;justify-content:space-between><h2 style=margin:0;font-size:20px>Connect to Screeps</h2></div><label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Server Password <span style=color:#484f58>(optional)</span></span><input type=password name=server-password autocomplete=off data-1p-ignore data-lpignore=true placeholder="Leave empty if not required"></label><button type=submit style=padding:10px;border-radius:6px;border:none;background:#238636;color:#fff;font-weight:600>'),Cc=E('<div style="width:360px;padding:12px 20px;border-radius:8px;background:#161b22;border:1px solid #30363d"><div style=font-size:11px;color:#484f58;margin-bottom:8px;text-transform:uppercase;letter-spacing:0.05em>Server Mods</div><div style=display:flex;flex-wrap:wrap;gap:6px>'),Tc=E('<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;gap:16px;width:100%;height:100%;overflow:auto;padding:24px 0;box-sizing:border-box"><div style="display:flex;flex-direction:column;gap:16px;width:360px;padding:32px;border-radius:8px;background:#161b22;border:1px solid #30363d">'),Mc=E("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Email or Username</span><input type=text id=username name=username autocomplete=username>"),Ec=E("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Password</span><input type=password id=password name=password autocomplete=current-password>"),Rc=E("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Auth Token</span><input type=password name=token autocomplete=off>"),Pc=E('<span style="font-size:11px;padding:2px 8px;border-radius:12px;background:#21262d;border:1px solid #30363d;color:#8b949e;font-family:monospace">');const Je={padding:"8px 12px","border-radius":"6px",border:"1px solid #30363d",background:"#0d1117",color:"#c9d1d9"};function Oc(r){const[e,t]=G(null),[i,n]=G(null),[s,o]=G(null);return de(()=>{const l=r();t(null),n(null),o(null);let a=!1;const c=setTimeout(async()=>{try{const d=await Pl(l);if(a)return;if(t(d),o(null),Cs(d)){const h=await Ol(l);a||n(h)}}catch{a||(o("Could not reach server"),t(null))}},400);Ge(()=>{a=!0,clearTimeout(c)})}),{serverVersion:e,authModInfo:i,serverError:s}}function zn(r,e,t){const[i,n]=G("idle");return de(()=>{const s=e();if(!s){n("idle");return}n("checking");let o=!1;const l=setTimeout(async()=>{try{const a=await t(r(),s);o||n(a.error?"taken":"available")}catch{o||n("error")}},500);Ge(()=>{o=!0,clearTimeout(l)})}),i}function Bn(r){const e={idle:null,checking:{children:"Checking…",color:"#8b949e"},available:{children:[S(ga,{size:12})," Available"],color:"#3fb950"},taken:{children:[S(hi,{size:12})," Already taken"],color:"#f85149"},error:{children:"Could not verify",color:"#d29922"}},t=()=>e[r.state];return S(X,{get when(){return t()},get children(){var i=lc();return y(i,()=>t().children),N(n=>D(i,"color",t().color)),i}})}function Lc(r){const[e,t]=G(""),[i,n]=G(""),[s,o]=G(""),[l,a]=G(""),[c,d]=G(!1),[h,f]=G(null),[u,p]=G(!1),w=zn(()=>r.url,e,Ll),C=zn(()=>r.url,i,Al),g=()=>l()!==""&&s()!==l(),k=()=>!c()&&e()!==""&&i()!==""&&s().length>=4&&s()===l()&&w()!=="taken"&&w()!=="checking"&&C()!=="taken"&&C()!=="checking",O=async b=>{if(b.preventDefault(),!!k()){d(!0),f(null);try{const v=await Il(r.url,e(),i(),s());if(v.error){f(v.error);return}p(!0),setTimeout(()=>r.onSuccess(i(),s()),1500)}catch(v){f(v instanceof Error?v.message:"Registration failed")}finally{d(!1)}}};return(()=>{var b=mc();return b.firstChild,b.addEventListener("submit",O),y(b,S(X,{get when(){return u()},get children(){return ac()}}),null),y(b,S(X,{get when(){return!u()},get children(){return[(()=>{var v=cc(),T=v.firstChild;T.firstChild;var P=T.nextSibling;return y(T,S(Bn,{get state(){return w()}}),null),P.$$input=m=>t(m.currentTarget.value),N(m=>{var $=Je,R=c();return m.e=Z(P,$,m.e),R!==m.t&&(P.disabled=m.t=R),m},{e:void 0,t:void 0}),N(()=>P.value=e()),v})(),(()=>{var v=dc(),T=v.firstChild;T.firstChild;var P=T.nextSibling;return y(T,S(Bn,{get state(){return C()}}),null),P.$$input=m=>n(m.currentTarget.value),N(m=>{var $=Je,R=c();return m.e=Z(P,$,m.e),R!==m.t&&(P.disabled=m.t=R),m},{e:void 0,t:void 0}),N(()=>P.value=i()),v})(),(()=>{var v=uc(),T=v.firstChild,P=T.nextSibling;return P.$$input=m=>o(m.currentTarget.value),N(m=>{var $=Je,R=c();return m.e=Z(P,$,m.e),R!==m.t&&(P.disabled=m.t=R),m},{e:void 0,t:void 0}),N(()=>P.value=s()),v})(),(()=>{var v=fc(),T=v.firstChild;T.firstChild;var P=T.nextSibling;return y(T,S(X,{get when(){return g()},get children(){return hc()}}),null),P.$$input=m=>a(m.currentTarget.value),N(m=>{var $={...Je,border:g()?"1px solid #f85149":"1px solid #30363d"},R=c();return m.e=Z(P,$,m.e),R!==m.t&&(P.disabled=m.t=R),m},{e:void 0,t:void 0}),N(()=>P.value=l()),v})(),ie(()=>ie(()=>!!h())()&&(()=>{var v=As();return y(v,h),v})()),(()=>{var v=pc();return y(v,()=>c()?"Creating account…":"Create Account"),N(T=>{var P=!k(),m=k()?"pointer":"not-allowed",$=k()?1:.5;return P!==T.e&&(v.disabled=T.e=P),m!==T.t&&D(v,"cursor",T.t=m),$!==T.a&&D(v,"opacity",T.a=$),T},{e:void 0,t:void 0,a:void 0}),v})(),(()=>{var v=gc();return v.$$click=()=>r.onCancel(),v})()]}}),null),b})()}function Ac(){const r=di(),e=Hl(),[t,i]=G("login"),[n,s]=G("password"),[o,l]=G(r?bn():window.location.origin),[a,c]=G(""),[d,h]=G(""),[f,u]=G(""),[p,w]=G(""),{serverVersion:C,authModInfo:g,serverError:k}=Oc(o),O=()=>{var I,L;return((L=(I=C())==null?void 0:I.serverData)==null?void 0:L.welcomeText)??null},b=()=>{var I,L;return(((L=(I=C())==null?void 0:I.serverData)==null?void 0:L.features)??[]).filter(A=>A.name!=="auth"&&A.version!=null)},v=()=>{var L,A;const I=C();return I?((A=(L=Cs(I))==null?void 0:L.authTypes)==null?void 0:A.includes("steam"))??!0:!0},T=()=>{var I,L,A;return((I=g())==null?void 0:I.allowRegistration)===!0||(((A=(L=C())==null?void 0:L.serverData)==null?void 0:A.features)??[]).some(B=>B.name==="official-like")},P=()=>{const I=o().replace(/\/$/,""),L=window.open(`${I}/api/auth/steam`,"screeps-steam-auth","width=800,height=600,left=200,top=100"),A=K=>{try{const H=JSON.parse(K.data);H.token&&(W(),wt({url:I,auth:"token",token:H.token,serverPassword:p()||void 0,storage:null}))}catch{}},B=setInterval(()=>{L!=null&&L.closed&&W()},500),W=()=>{clearInterval(B),window.removeEventListener("message",A)};window.addEventListener("message",A),Ge(W)},m=async I=>{I.preventDefault(),await wt({url:o(),auth:n(),email:a()||void 0,password:d()||void 0,token:f()||void 0,serverPassword:p()||void 0,storage:null})},$=async I=>{I.preventDefault(),await wt({url:o(),auth:"guest",serverPassword:p()||void 0,storage:null})},R=async(I,L)=>{try{await wt({url:o(),auth:"password",email:I,password:L,serverPassword:p()||void 0,storage:null})}catch{i("login"),s("password"),c(I),h(L)}},M=()=>$t()==="connecting";return(()=>{var I=Tc(),L=I.firstChild;return y(I,S(X,{get when(){return O()},get children(){var A=yc();return N(()=>A.innerHTML=O()),A}}),L),y(L,S(X,{get when(){return t()==="register"},get children(){return S(Lc,{get url(){return o()},get serverPassword(){return p()},onSuccess:R,onCancel:()=>i("login")})}}),null),y(L,S(X,{get when(){return t()==="login"},get children(){var A=kc(),B=A.firstChild;B.firstChild;var W=B.nextSibling,K=W.firstChild,H=K.firstChild;H.nextSibling;var F=K.nextSibling,Y=W.nextSibling;return A.addEventListener("submit",m),y(B,S(X,{get when(){return T()},get children(){var z=vc();return z.$$click=()=>i("register"),z}}),null),y(A,S(X,{when:!r,get children(){var z=bc(),U=z.firstChild,Q=U.nextSibling;return U.$$click=()=>s("password"),Q.$$click=()=>s("token"),N(J=>{var V=n()==="password"?"#238636":"transparent",he=n()==="token"?"#238636":"transparent";return V!==J.e&&D(U,"background",J.e=V),he!==J.t&&D(Q,"background",J.t=he),J},{e:void 0,t:void 0}),z}}),W),y(A,S(X,{when:!r,get children(){return[(()=>{var z=wc(),U=z.firstChild,Q=U.nextSibling;return Q.$$input=J=>l(J.currentTarget.value),N(J=>Z(Q,Je,J)),N(()=>Q.value=o()),z})(),S(X,{get when(){return k()},get children(){var z=xc();return y(z,k),z}})]}}),W),y(A,(()=>{var z=ie(()=>n()==="password");return()=>z()?[(()=>{var U=Mc(),Q=U.firstChild,J=Q.nextSibling;return J.$$input=V=>c(V.currentTarget.value),N(V=>Z(J,Je,V)),N(()=>J.value=a()),U})(),(()=>{var U=Ec(),Q=U.firstChild,J=Q.nextSibling;return J.$$input=V=>h(V.currentTarget.value),N(V=>Z(J,Je,V)),N(()=>J.value=d()),U})()]:(()=>{var U=Rc(),Q=U.firstChild,J=Q.nextSibling;return J.$$input=V=>u(V.currentTarget.value),N(V=>Z(J,Je,V)),N(()=>J.value=f()),U})()})(),W),F.$$input=z=>w(z.currentTarget.value),y(A,(()=>{var z=ie(()=>!!Gn());return()=>z()&&(()=>{var U=As();return y(U,Gn),U})()})(),Y),y(Y,()=>M()?"Connecting…":"Connect"),y(A,S(X,{get when(){return v()},get children(){return[(()=>{var z=_c(),U=z.firstChild,Q=U.nextSibling;return Q.nextSibling,z})(),(()=>{var z=$c();return z.$$click=P,N(U=>{var Q=M(),J=M()?"not-allowed":"pointer",V=M()?.6:1;return Q!==U.e&&(z.disabled=U.e=Q),J!==U.t&&D(z,"cursor",U.t=J),V!==U.a&&D(z,"opacity",U.a=V),U},{e:void 0,t:void 0,a:void 0}),z})()]}}),null),y(A,S(X,{when:!r||e,get children(){var z=Sc();return z.addEventListener("mouseleave",U=>{U.currentTarget.style.borderColor="#30363d"}),z.addEventListener("mouseenter",U=>{M()||(U.currentTarget.style.borderColor="#8b949e")}),z.$$click=$,N(U=>{var Q=M(),J=M()?"not-allowed":"pointer",V=M()?.6:1;return Q!==U.e&&(z.disabled=U.e=Q),J!==U.t&&D(z,"cursor",U.t=J),V!==U.a&&D(z,"opacity",U.a=V),U},{e:void 0,t:void 0,a:void 0}),z}}),null),N(z=>{var U=Je,Q=M(),J=M()?"not-allowed":"pointer",V=M()?.6:1;return z.e=Z(F,U,z.e),Q!==z.t&&(Y.disabled=z.t=Q),J!==z.a&&D(Y,"cursor",z.a=J),V!==z.o&&D(Y,"opacity",z.o=V),z},{e:void 0,t:void 0,a:void 0,o:void 0}),N(()=>F.value=p()),A}}),null),y(I,S(X,{get when(){return b().length>0},get children(){var A=Cc(),B=A.firstChild,W=B.nextSibling;return y(W,S(ve,{get each(){return b()},children:K=>(()=>{var H=Pc();return y(H,()=>K.name,null),y(H,(()=>{var F=ie(()=>!!K.version);return()=>F()?` ${K.version}`:""})(),null),H})()})),A}}),null),I})()}ke(["input","click"]);var Ic=E('<span style="padding:2px 8px;border-radius:4px;background:#21262d;border:1px solid #30363d;color:#8b949e;font-size:11px;font-weight:600;letter-spacing:0.05em;text-transform:uppercase">Guest'),Nc=E('<div style="display:flex;align-items:center;gap:12px;padding:8px 16px;border-bottom:1px solid #30363d;font-size:13px"><div style=display:flex;align-items:center;gap:6px><span style=width:8px;height:8px;border-radius:50%;display:inline-block></span><span style=color:#8b949e>');function Gc(){const r=()=>{switch($t()){case"connected":return"#238636";case"connecting":return"#d29922";case"error":return"#f85149";default:return"#8b949e"}};return(()=>{var e=Nc(),t=e.firstChild,i=t.firstChild,n=i.nextSibling;return y(n,(()=>{var s=ie(()=>$t()==="connected");return()=>s()?"Online":$t()})()),y(e,S(X,{get when(){return He()},get children(){return Ic()}}),null),N(s=>D(i,"background-color",r())),e})()}class Dc{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 Pe,this.container.label="hoverHighlight",this.container.eventMode="none",this.hoverGraphics=new te,this.hoverGraphics.eventMode="none",this.container.addChild(this.hoverGraphics),this.pendingGraphics=new te,this.pendingGraphics.eventMode="none",this.container.addChild(this.pendingGraphics),this.selectionContainer=new Pe,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*x,n=t*x;this.hoverGraphics.rect(i,n,x,x),this.hoverGraphics.stroke({width:1,color:16777215,alpha:.35}),this.hoverGraphics.rect(i,n,x,x),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 te;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*x,n=t*x,s=i+x/2,o=n+x/2,l=x*.35;this.pendingGraphics.moveTo(s-l,o),this.pendingGraphics.lineTo(s+l,o),this.pendingGraphics.moveTo(s,o-l),this.pendingGraphics.lineTo(s,o+l),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.9}),this.pendingGraphics.rect(i+1,n+1,x-2,x-2),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.6})}clearPendingTile(){this.pendingGraphics.clear()}drawCreepRing(e,t,i){e.clear();const n=t+x/2,s=i+x/2,o=x*.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,x-n*2,x-n*2),e.stroke({width:1.5,color:16777215,alpha:.9}),e.rect(t+n,i+n,x-n*2,x-n*2),e.fill({color:16777215,alpha:.04})}trackCreepRings(){for(const[e,t]of this.selectionGraphics){if(this.selectionTypes.get(e)!=="creep")continue;const i=this.selectionVisuals.get(e);!i||i.destroyed||this.drawCreepRing(t,i.x,i.y)}}destroy(){this.ticker&&this.tickerCallback&&this.ticker.remove(this.tickerCallback),this.ticker=null,this.tickerCallback=null,this.clearSelection(),this.clearPendingTile(),this.pendingGraphics.destroy(),this.hoverGraphics.destroy(),this.container.destroy()}}const x=12,Ee=50*x,we=48,sr=128;class wn{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 Pe,this.app.stage.addChild(this.world),this.hoverLayer=new Dc(e.ticker),this.world.addChild(this.hoverLayer.container),this.navOverlay=new Pe,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 ys;return await t.init({background:"#0d1117",antialias:!0,resolution:window.devicePixelRatio||1,autoDensity:!0}),e.appendChild(t.canvas),new wn(t,e)}getMinScale(){const t=this.container.clientWidth,i=this.container.clientHeight;return Math.min(t,i)/(Ee+64)}clampView(e=!1){const t=this.world.scale.x,i=Ee*t,n=this.container.clientWidth,s=this.container.clientHeight,o=e?sr:0;if(i<=n){const l=n/2-i/2;e?this.world.x=Math.min(l+sr,Math.max(l-sr,this.world.x)):this.world.x=l}else{const l=n-i-we-o,a=we+o;this.world.x=Math.min(a,Math.max(l,this.world.x))}if(i<=s){const l=s/2-i/2;e?this.world.y=Math.min(l+sr,Math.max(l-sr,this.world.y)):this.world.y=l}else{const l=s-i-we-o,a=we+o;this.world.y=Math.min(a,Math.max(l,this.world.y))}this.canDrag=!0}getTargetPosition(){const e=this.world.scale.x,t=Ee*e,i=this.container.clientWidth,n=this.container.clientHeight;let s=null,o=null;if(t<=i)s=i/2-t/2;else{const l=i-t-we,a=we;this.world.x<l?s=l:this.world.x>a&&(s=a)}if(t<=n)o=n/2-t/2;else{const l=n-t-we,a=we;this.world.y<l?o=l:this.world.y>a&&(o=a)}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(),l=300,a=this.container.clientWidth/2,c=this.container.clientHeight/2,d=(a-i)/s,h=(c-n)/s,f=u=>{const p=u-o,w=Math.min(1,p/l),C=1-Math.pow(1-w,3);if(t!==null){const g=s+(t-s)*C;this.world.scale.set(g),this.world.x=a-d*g,this.world.y=c-h*g}e&&t===null&&(this.world.x=i+(e.x-i)*C,this.world.y=n+(e.y-n)*C),w<1?this.bounceRaf=requestAnimationFrame(f):(this.bounceRaf=null,this.clampView())};this.cancelBounce(),this.bounceRaf=requestAnimationFrame(f)}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 nr(0,0),i=new nr(0,0);const n=this.app.canvas,s=4;n.style.touchAction="none",n.style.userSelect="none";const o=new Map;let l=!1,a=0,c=0,d=0,h=0;n.addEventListener("contextmenu",u=>{u.preventDefault()}),n.addEventListener("pointerdown",u=>{if(this.cancelBounce(),this.cancelWheelTimeout(),o.set(u.pointerId,{x:u.clientX,y:u.clientY}),n.setPointerCapture(u.pointerId),o.size>=2){e=!1,l=!0;const p=[...o.values()],w=n.getBoundingClientRect(),C=(p[0].x+p[1].x)/2-w.left,g=(p[0].y+p[1].y)/2-w.top;d=Math.hypot(p[1].x-p[0].x,p[1].y-p[0].y),h=this.world.scale.x,a=(C-this.world.x)/h,c=(g-this.world.y)/h}else l=!1,e=this.canDrag,t=new nr(u.clientX,u.clientY),i=new nr(u.clientX,u.clientY)}),n.addEventListener("pointermove",u=>{var g;const p=n.getBoundingClientRect();if(this.lastMouseX=u.clientX-p.left,this.lastMouseY=u.clientY-p.top,o.has(u.pointerId)&&o.set(u.pointerId,{x:u.clientX,y:u.clientY}),l&&o.size===2){const k=[...o.values()],O=(k[0].x+k[1].x)/2-p.left,b=(k[0].y+k[1].y)/2-p.top,v=Math.hypot(k[1].x-k[0].x,k[1].y-k[0].y),T=this.getMinScale(),P=5,m=.6;let $=h*(v/d);$<T&&($=T+($-T)*m),$>P&&($=P+($-P)*m),this.cancelBounce(),this.world.scale.set($),this.world.x=O-a*$,this.world.y=b-c*$,this.clampView(!0);return}if(!l){const k=this.screenToTile(this.lastMouseX,this.lastMouseY);this.hoverLayer.setHoveredTile((k==null?void 0:k.tx)??null,(k==null?void 0:k.ty)??null),(g=this.onHoverTile)==null||g.call(this,(k==null?void 0:k.tx)??null,(k==null?void 0:k.ty)??null)}if(!e||!this.canDrag)return;const w=u.clientX-t.x,C=u.clientY-t.y;this.world.x+=w,this.world.y+=C,t=new nr(u.clientX,u.clientY),this.clampView(!0)});const f=u=>{var g;if(n.releasePointerCapture(u.pointerId),o.delete(u.pointerId),l){o.size<2&&(l=!1,e=!1,this.springBack());return}e=!1;const p=u.clientX-i.x,w=u.clientY-i.y;if(Math.sqrt(p*p+w*w)<s){const k=n.getBoundingClientRect(),O=u.clientX-k.left,b=u.clientY-k.top,v=this.screenToTile(O,b);v&&((g=this.onClickTile)==null||g.call(this,v.tx,v.ty,u.ctrlKey||u.metaKey))}this.springBack()};n.addEventListener("pointerup",f),n.addEventListener("pointercancel",f),n.addEventListener("pointerleave",()=>{var u;this.hoverLayer.setHoveredTile(null,null),(u=this.onHoverTile)==null||u.call(this,null,null)}),n.addEventListener("wheel",u=>{u.preventDefault();const p=u.deltaY>0?.9:1.1,w=this.getMinScale(),C=5;let g=this.world.scale.x*p;const k=.6;g<w&&(g=w+(g-w)*k),g>C&&(g=C+(g-C)*k);const O=n.getBoundingClientRect(),b=u.clientX-O.left,v=u.clientY-O.top;if(this.cancelBounce(),g<w){const T=this.container.clientWidth/2,P=this.container.clientHeight/2,m=(T-this.world.x)/this.world.scale.x,$=(P-this.world.y)/this.world.scale.y;this.world.scale.set(g),this.world.x=T-m*g,this.world.y=P-$*g}else{const T=(b-this.world.x)/this.world.scale.x,P=(v-this.world.y)/this.world.scale.y;this.world.scale.set(g),this.world.x=b-T*g,this.world.y=v-P*g}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/x),o=Math.floor(n/x);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-Ee*i/2,this.world.y=t-Ee*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,l,a,c,d,h)=>{if(!h)return;const f=new te;f.x=o,f.y=l,f.hitArea=new vs(0,0,a,c),f.fill({color:16777215,alpha:.12}),f.poly(d),f.fill(),f.eventMode="static",f.cursor="pointer",f.alpha=1,f.on("pointerover",()=>{f.clear(),f.fill({color:16777215,alpha:.06}),f.rect(0,0,a,c),f.fill(),f.fill({color:16777215,alpha:.35}),f.poly(d),f.fill()}),f.on("pointerout",()=>{f.clear(),f.fill({color:16777215,alpha:.12}),f.poly(d),f.fill()}),f.on("pointerdown",h),this.navOverlay.addChild(f)},i=Ee/2,n=Ee/2,s=18;t(-we,0,we,Ee,[18,n,we-6,n-s,we-6,n+s],e.west),t(Ee,0,we,Ee,[we-18,n,6,n-s,6,n+s],e.east),t(0,-we,Ee,we,[i,18,i-s,we-6,i+s,we-6],e.north),t(0,Ee,Ee,we,[i,we-18,i-s,6,i+s,6],e.south);for(const o of this.navOverlay.children){const l=o,a=l.hitArea,c=this.world.x+l.x*this.world.scale.x,d=this.world.y+l.y*this.world.scale.y,h=a.width*this.world.scale.x,f=a.height*this.world.scale.y;this.lastMouseX>=c&&this.lastMouseX<=c+h&&this.lastMouseY>=d&&this.lastMouseY<=d+f&&l.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 Is=856343,zc=1448738,Bc=1843496,Hc=3421243,Fc=Hc,Wc=Is,xn=7039337,Ns=3159613,Uc=1579032,Xc=0,Yc=2631720,qc=2632986,jc=2500383,Vc=2771488,Zc=5000268,Kc=11122630,Jc=16770413,Qc=7829367,ed=16332866,td=6127794,rd=6684002,id=12164347,Ar={tough:Zc,move:Kc,work:Jc,carry:Qc,attack:ed,ranged_attack:td,heal:rd,claim:id},wi=5809919,St=7979263,Gs=4176208,xi=9147550,Ir=13801762,Hn=10711543,nd=16218298,Fn=16273737,yr=15763518,sd=2172461,Ds=xn,od=13226457,vt=12283502,Ft=[16777215,16711680,8388736,255,65535,32768,16776960,16753920,10824234,8421504,16777215],ld={creep:yr,spawn:wi,extension:St,tower:Gs,container:xi,storage:Ir,link:Hn,rampart:wi,road:Ds,wall:sd,extractor:xi,lab:nd,terminal:Ir,observer:St,powerSpawn:yr,nuker:Fn,factory:xi,invaderCore:Fn,source:Ir,mineral:St,deposit:Ir,controller:wi,powerBank:yr,portal:Hn},Rr=16771195,ad=Rr,cd=St,dd=Rr,vr=9419667,ud=7245682,hd=12116924,fd=12283502,pd=9787480,gd=14721184,Wn=Bc,md=13684944,xe=1579032,gt=5592405,jr=11184810,yd=9419667,qe=16771195,vd=16069959,Un=4410435,bd=x*.05,wd=x*.2;function Wt(r,e,t,i){const n=x,s=n/2;let o=!1;for(let l=0;l<50;l++)for(let a=0;a<50;a++){const c=e.get(a,l)===t,d=l>0&&e.get(a,l-1)===t,h=l<49&&e.get(a,l+1)===t,f=a>0&&e.get(a-1,l)===t,u=a<49&&e.get(a+1,l)===t,p=a*n+s,w=l*n+s;c?(o=!0,!d&&!f&&l>0&&a>0?(r.moveTo(p,l*n),r.arc(p,w,s,-Math.PI/2,Math.PI,!0),r.lineTo(p,w),r.closePath()):r.rect(a*n,l*n,s,s)):d&&f&&e.get(a-1,l-1)===t&&(o=!0,r.moveTo(p,l*n),r.lineTo(a*n,l*n),r.lineTo(a*n,w),r.arc(p,w,s,Math.PI,-Math.PI/2,!1),r.closePath()),c?!d&&!u&&l>0&&a<49?(r.moveTo(p,l*n),r.arc(p,w,s,-Math.PI/2,0,!1),r.lineTo(p,w),r.closePath()):r.rect(p,l*n,s,s):d&&u&&e.get(a+1,l-1)===t&&(o=!0,r.moveTo(p,l*n),r.lineTo(a*n+n,l*n),r.lineTo(a*n+n,w),r.arc(p,w,s,0,-Math.PI/2,!0),r.closePath()),c?!h&&!f&&l<49&&a>0?(r.moveTo(a*n,w),r.arc(p,w,s,Math.PI,Math.PI/2,!0),r.lineTo(p,w),r.closePath()):r.rect(a*n,w,s,s):h&&f&&e.get(a-1,l+1)===t&&(o=!0,r.moveTo(a*n,w),r.lineTo(a*n,l*n+n),r.lineTo(p,l*n+n),r.arc(p,w,s,Math.PI/2,Math.PI,!1),r.closePath()),c?!h&&!u&&l<49&&a<49?(r.moveTo(p,l*n+n),r.arc(p,w,s,Math.PI/2,0,!0),r.lineTo(p,w),r.closePath()):r.rect(p,w,s,s):h&&u&&e.get(a+1,l+1)===t&&(o=!0,r.moveTo(p,l*n+n),r.lineTo(a*n+n,l*n+n),r.lineTo(a*n+n,w),r.arc(p,w,s,0,Math.PI/2,!1),r.closePath())}o&&i(r)}function xd(r,e){const t=xn,i=x,n=(s,o,l)=>{const a=s*i+i/2,c=o*i+i/2,d=i*.3;l==="up"?(r.moveTo(a,c-d),r.lineTo(a+d,c+d),r.lineTo(a-d,c+d)):l==="down"?(r.moveTo(a,c+d),r.lineTo(a+d,c-d),r.lineTo(a-d,c-d)):l==="left"?(r.moveTo(a-d,c),r.lineTo(a+d,c-d),r.lineTo(a+d,c+d)):l==="right"&&(r.moveTo(a+d,c),r.lineTo(a-d,c-d),r.lineTo(a-d,c+d)),r.fill(t)};for(let s=0;s<50;s++)e.get(s,0)!==Fe.Wall&&n(s,0,"up"),e.get(s,49)!==Fe.Wall&&n(s,49,"down");for(let s=0;s<50;s++)e.get(0,s)!==Fe.Wall&&n(0,s,"left"),e.get(49,s)!==Fe.Wall&&n(49,s,"right")}function _d(r){const e=new te;e.rect(0,0,50*x,50*x),e.fill(Fc);const t={color:jc,width:wd,alignment:0,cap:"round",join:"round"};Wt(e,r,Fe.Swamp,n=>n.stroke(t)),Wt(e,r,Fe.Swamp,n=>n.fill(qc));const i={color:Xc,width:bd,alignment:0,cap:"round",join:"round"};return Wt(e,r,Fe.Wall,n=>n.stroke(i)),Wt(e,r,Fe.Wall,n=>n.fill(Uc)),xd(e,r),e.rect(0,0,50*x,50*x),e.stroke({width:1,color:Ns}),e}function $d(r){const e=new te;return e.label="swampGlow",Wt(e,r,Fe.Swamp,t=>t.fill(Vc)),e.alpha=.45,e.filters=[new Po({strength:5,quality:3})],e}function Sd(r,e){const t=new te;Wt(t,r,Fe.Wall,s=>s.fill(Yc)),t.alpha=.5,t.filters=[new Ro({noise:.12,seed:1})],t.filterArea=new vs(0,0,50*x,50*x);const i=e.generateTexture({target:t,frame:t.filterArea});t.filters=null,t.destroy();const n=new Vt(i);return n.label="wallNoise",n}function Xn(r,e){const t=new Pe,i=Sd(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(_d(r)),t.addChild($d(r)),t.addChild(i),t}function _i(r,e){r.getChildByLabel("swampGlow").visible=e,r.getChildByLabel("wallNoise").visible=e}function kd(r){return new Promise((e,t)=>{const i=new Image;i.onload=()=>e(i),i.onerror=t,i.src=r})}class zs{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=ci(e),n=new Blob([i],{type:"image/svg+xml;charset=utf-8"}),s=URL.createObjectURL(n);try{const o=window.devicePixelRatio||1,l=128*Math.max(2,o),a=await kd(s),c=document.createElement("canvas");c.width=l,c.height=l,c.getContext("2d").drawImage(a,0,0,l,l);const h=yt.from(c);return this.cache.set(t,h),h}finally{URL.revokeObjectURL(s)}}destroy(){for(const e of this.cache.values())e.destroyed||e.destroy(!0);this.cache.clear(),this.pending.clear()}}const Cd=new zs,dt=x*.44,Ye=x*.28,or=50,Yi=32,qi=12/Yi,Bs=x/2-x*.44,Hs=2,Yn=x*.42,Fs=x*.3,Td=Math.max(1,x*.08),Md={H:13421772,O:16777215,U:5822457,L:62626,K:10514943,Z:16631694,X:11568379},Ed={H:2236962,O:2236962},Rd=x*.42,Ws=32,Pd=9/Ws,ji=x-4,qn=x*.28,jn=1600,Od=16776428;function Vi(r,e){if(e<=0)return ji;const t=Math.max(0,Math.min(1,r/e));return qn+(ji-qn)*t}function _n(r,e,t=qe){const i=e/2,n=x/2,s=x/2,o=e*.25;r.clear(),r.roundRect(n-i,s-i,e,e,o),r.fill(t)}function $i(r,e){const t=r.__sourceGraphics;t&&(r.__sourceSize=e,_n(t,e,$n(performance.now())))}function $n(r){const e=r%jn/jn,t=.5-.5*Math.cos(e*Math.PI*2);return Ys(qe,Od,t)}function Zi(r){const e=typeof r.energy=="number"?r.energy:0,t=typeof r.energyCapacity=="number"?r.energyCapacity:3e3;return{energy:e,capacity:t}}const Us=x*.3,Xs=Math.max(1,x*.12),Ki=Us-Xs/2,Ld=x*.42,Ad=1500;function Ys(r,e,t){const i=r>>16&255,n=r>>8&255,s=r&255,o=e>>16&255,l=e>>8&255,a=e&255,c=Math.round(i+(o-i)*t),d=Math.round(n+(l-n)*t),h=Math.round(s+(a-s)*t);return c<<16|d<<8|h}function qs(r,e){r.clear(),r.circle(x/2,x/2,Us),r.stroke({width:Xs,color:e,alpha:.95})}function Ji(r,e,t,i,n,s,o){if(r.clear(),s<=0||n<=0)return;const l=Math.min(1,n/s);if(l>=1){r.circle(e,t,i),r.fill({color:o,alpha:.55});return}const a=-Math.PI/2,c=a+l*Math.PI*2;r.moveTo(e,t),r.lineTo(e+i*Math.cos(a),t+i*Math.sin(a)),r.arc(e,t,i,a,c),r.closePath(),r.fill({color:o,alpha:.55})}function lt(r,e,t){return t.flatMap(([i,n])=>[r+i*x,e+n*x])}function Lt(r,e,t,i){t-e<.001||(r.moveTo(dt*Math.cos(e),dt*Math.sin(e)),r.arc(0,0,dt,e,t),r.lineTo(Ye*Math.cos(t),Ye*Math.sin(t)),r.arc(0,0,Ye,t,e,!0),r.closePath(),r.fill(i))}function Qi(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 en(r,e){return e<=0||r<=0?0:Ye*.8*Math.min(1,r/e)}function Si(r,e){const t=r.__creepFillGraphics;t&&(t.clear(),e>0&&(t.circle(0,0,e),t.fill(Rr)))}function Id(r){return ld[r]??od}function Ut(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 js(r){return r>=200?1.15:r>=100?.85:.7}function tn(r,e){return e<=0||r<=0?0:Fs*js(e)*Math.min(1,r/e)}function Nd(r,e,t,i){const n=x/2,s=x/2,o=js(t),l=new te;l.circle(n,s,Yn*o),l.fill(xe),l.circle(n,s,Yn*o),l.stroke({width:Td*o,color:i}),l.circle(n,s,Fs*o),l.fill(jr),r.addChild(l);const a=new te,c=tn(e,t);c>0&&(a.circle(n,s,c),a.fill(qe)),r.addChild(a),r.__fillGraphics=a}function ki(r,e){const t=x/2,i=x/2,n=r.__fillGraphics;n&&(n.clear(),e>0&&(n.circle(t,i,e),n.fill(qe)))}const rn=-x*.4,nn=-x*.3,sn=x*.8,Qr=x*.6;function on(r,e){return e<=0||r<=0?0:Qr*Math.min(1,r/e)}function Vr(r,e){const t=r.__towerFillGraphics;if(t&&(t.clear(),e>0)){const i=Math.max(.5,x*.02);t.rect(rn+i,nn+Qr-e+i,sn-i*2,e-i*2),t.fill(qe)}}const ln=x*.65,an=ln,Ze=x*.42;function cn(r,e,t,i,n,s,o,l){r.clear();const a=8,c=.1,d=2*Math.PI/a-c;for(let h=0;h<a;h++){const f=-Math.PI/2+h*(2*Math.PI/a)+c/2,u=f+d,p=e+n*Math.cos(f),w=t+n*Math.sin(f);if(h<s)r.moveTo(p,w),r.arc(e,t,i,f,u),r.arc(e,t,n,u,f,!0),r.closePath(),r.fill({color:14540253,alpha:.9});else if(h===s&&l>0){if(r.moveTo(p,w),r.arc(e,t,i,f,u),r.arc(e,t,n,u,f,!0),r.closePath(),r.fill({color:1973790,alpha:.85}),o>0){const C=Math.min(1,o/l),g=f+d*C;r.moveTo(p,w),r.arc(e,t,i,f,g),r.arc(e,t,n,g,f,!0),r.closePath(),r.fill({color:14540253,alpha:.9})}}else r.moveTo(p,w),r.arc(e,t,i,f,u),r.arc(e,t,n,u,f,!0),r.closePath(),r.fill({color:1973790,alpha:.6})}}function ei(r,e){const t=r.user;return typeof t!="string"||!e?!1:t!==e}function Nr(r,e=!0,t,i,n,s){var p,w,C;const o=new Pe,l=new te,a=Id(r.type),c=x/2,d=x/2,h=typeof r.user=="string"?r.user:void 0,u=h!==void 0&&t!==void 0&&h!==t?vt:yd;switch(r.type){case"creep":{const g=2*Math.PI,k=new Pe;k.position.set(c,d),k.rotation=-Math.PI/2;const O=ei(r,t);if(O){const oe=new te;oe.circle(0,0,dt+.75),oe.stroke({width:1.5,color:vt}),k.addChild(oe)}const b=new te;b.circle(0,0,dt),b.fill(Is),k.addChild(b);const v=r.body??[];let T=0,P=0,m=0;const $=[],R={};for(const oe of v)oe.type==="work"?T++:oe.type==="move"?P++:(R[oe.type]===void 0&&($.push(oe.type),R[oe.type]=0),R[oe.type]++,m++);const M=T/or*g,I=P/or*g,L=m/or*g,A=M/2,B=A+L/2,W=Math.PI-I/2,K=Math.PI+I/2,H=g-M/2-L/2,F=g-M/2,Y=new te;M>0&&Lt(Y,-M/2,A,Ar.work);let z=A;for(const oe of $){const Me=(R[oe]??0)/or*g/2;Lt(Y,z,z+Me,Ar[oe]??7829367),z+=Me}Lt(Y,B,W,Wn),I>0&&Lt(Y,W,K,Ar.move),Lt(Y,K,H,Wn);let U=F;for(const oe of $){const Me=(R[oe]??0)/or*g/2;Lt(Y,U-Me,U,Ar[oe]??7829367),U-=Me}k.addChild(Y);const Q=new te;Q.circle(0,0,Ye),Q.fill(zc),k.addChild(Q);const J=typeof r.user=="string"?r.user:void 0,V=J?(p=s==null?void 0:s[J])==null?void 0:p.badge:void 0;if(V&&n){const oe=new Vt;oe.anchor.set(.5,.5);const Me=Ye*2;oe.width=Me,oe.height=Me,oe.rotation=Math.PI/2,k.addChild(oe),o.__creepBadgeSprite=oe,n.getOrCreate(V).then(pt=>{oe.destroyed||(oe.texture=pt)}).catch(()=>{})}else if(O){const oe=new te;oe.circle(0,0,Ye*.82),oe.fill({color:vt,alpha:.9}),k.addChild(oe),o.__creepForeignMark=oe}const{used:he,capacity:Oe}=Qi(r),it=en(he,Oe),De=new te;it>0&&(De.circle(0,0,it),De.fill(Rr)),k.addChild(De),o.__creepFillGraphics=De,o.__creepUsed=he,o.__creepCapacity=Oe;const We=(dt+Ye)/2,nt=(dt-Ye)*.45,Le=new te;Le.moveTo(dt,0),Le.lineTo(We,-nt),Le.lineTo(We,nt),Le.closePath(),Le.fill(md),k.addChild(Le),o.addChild(k),o.__bodyContainer=k;break}case"extension":{const{energy:g,capacity:k}=Ut(r);Nd(o,g,k,u),o.__extEnergy=g,o.__extCapacity=k;break}case"spawn":{l.circle(c,d,x*.65),l.fill(xe),l.circle(c,d,x*.65),l.stroke({width:x*.1,color:13421772}),l.circle(c,d,x*.4),l.fill(qe);break}case"powerSpawn":{l.circle(c,d,x*.65),l.fill(xe),l.circle(c,d,x*.65),l.stroke({width:x*.1,color:vd}),l.circle(c,d,x*.4),l.fill(qe);break}case"source":{const{energy:g,capacity:k}=Zi(r),O=Vi(g,k),b=new te;_n(b,O,$n(performance.now())),o.addChild(b),o.__sourceGraphics=b,o.__sourceEnergy=g,o.__sourceCapacity=k,o.__sourceSize=O;break}case"constructionSite":{const g=typeof r.user=="string"?r.user:void 0,k=g!==void 0&&g===t,O=k?vr:fd,b=k?ud:pd,v=k?hd:gd,T=typeof r.progress=="number"?r.progress:0,P=typeof r.progressTotal=="number"?r.progressTotal:1,m=new te;o.addChild(m),o.__csBuildGlow=m;const $=new te;Ji($,c,d,Ki,T,P,O),o.addChild($),o.__csFillGraphics=$;const R=new te;qs(R,O),o.addChild(R),o.__csRingGraphics=R,o.__csProgress=T,o.__csProgressTotal=P,o.__csUser=g,o.__csColor=O,o.__csColorDark=b,o.__csColorLight=v;break}case"mineral":{const g=typeof r.mineralType=="string"?r.mineralType:"?",k=Md[g]??St,O=Ed[g]??16777215,b=new te;b.circle(c,d,Rd),b.fill(k),o.addChild(b);const v=new Yt({text:g,style:{fontSize:Ws,fill:O,fontWeight:"bold"}});v.anchor.set(.5,.5),v.scale.set(Pd),v.position.set(c,d),o.addChild(v);break}case"deposit":{l.rect(2,2,x-4,x-4),l.fill(a);break}case"controller":{const g=typeof r.level=="number"?r.level:0,k=typeof r.progress=="number"?r.progress:0,O=typeof r.progressTotal=="number"?r.progressTotal:0,b=typeof r.user=="string"?r.user:void 0,v=b?(w=s==null?void 0:s[b])==null?void 0:w.badge:void 0,T=new te,P=[];for(let R=0;R<8;R++){const M=-Math.PI/2+R*Math.PI/4;P.push(c+ln*Math.cos(M),d+ln*Math.sin(M))}T.poly(P),T.fill(2238513),T.poly(P),T.stroke({width:x*.07,color:8027781}),o.addChild(T);const m=new te;cn(m,c,d,an,Ze,g,k,O),o.addChild(m),o.__ctrlSegGraphics=m,o.__ctrlLevel=g,o.__ctrlProgress=k,o.__ctrlProgressTotal=O;const $=new te;if(v?($.circle(c,d,Ze),$.fill(xe)):($.circle(c,d,Ze),$.fill(3028031),$.circle(c,d,Ze),$.stroke({width:x*.04,color:8027781}),$.circle(c,d,x*.16),$.fill(10133672)),o.addChild($),v&&n){const R=new Vt;R.anchor.set(.5,.5),R.width=Ze*2,R.height=Ze*2,R.position.set(c,d);const M=new te;M.circle(c,d,Ze),M.fill(16777215),o.addChild(R),R.mask=M,o.addChild(M),n.getOrCreate(v).then(I=>{R.destroyed||(R.texture=I)}).catch(()=>{})}break}case"energy":{l.circle(c,d,x*.2),l.fill(qe);break}case"road":break;case"wall":{l.circle(c,d,x*.4),l.fill(xe),l.circle(c,d,x*.4),l.stroke({width:x*.05,color:jr});break}case"rampart":break;case"tower":{const{energy:g,capacity:k}=Ut(r),O=new te;O.circle(c,d,x*.6),O.fill(xe),O.circle(c,d,x*.6),O.stroke({width:x*.05,color:u}),o.addChild(O);const b=new Pe;b.position.set(c,d);const v=new te;v.rect(rn,nn,sn,Qr),v.fill(xe),b.addChild(v);const T=new te;b.addChild(T),o.__towerFillGraphics=T,o.__towerEnergy=g,o.__towerCapacity=k,Vr(o,on(g,k));const P=new te;P.rect(rn,nn,sn,Qr),P.stroke({width:1,color:gt}),b.addChild(P);const m=new te;m.rect(-x*.2,-x*.9,x*.4,x*.5),m.fill(jr),m.rect(-x*.2,-x*.9,x*.4,x*.5),m.stroke({width:x*.07,color:xe}),b.addChild(m),o.addChild(b),o.__barrelContainer=b;break}case"storage":{const g=lt(c,d,[[-.6,-.7],[0,-.8],[.6,-.7],[.65,0],[.6,.7],[0,.8],[-.6,.7],[-.65,0],[-.6,-.7]]);l.poly(g),l.fill(xe),l.poly(g),l.stroke({width:x*.05,color:u}),l.rect(c-x*.5,d-x*.6,x*1,x*1.2),l.fill(gt),l.rect(c-x*.5,d-x*.6,x*1,x*1.2),l.stroke({width:x*.1,color:xe});break}case"terminal":{const g=lt(c,d,[[0,-.8],[.55,-.55],[.8,0],[.55,.55],[0,.8],[-.55,.55],[-.8,0],[-.55,-.55],[0,-.8]]),k=lt(c,d,[[0,-.65],[.45,-.45],[.65,0],[.45,.45],[0,.65],[-.45,.45],[-.65,0],[-.45,-.45],[0,-.65]]);l.poly(g),l.fill(xe),l.poly(g),l.stroke({width:x*.05,color:u}),l.poly(k),l.fill(jr),l.rect(c-x*.45,d-x*.45,x*.9,x*.9),l.fill(gt),l.rect(c-x*.45,d-x*.45,x*.9,x*.9),l.stroke({width:x*.1,color:xe});break}case"link":{const g=lt(c,d,[[0,-.5],[.4,0],[0,.5],[-.4,0],[0,-.5]]),k=lt(c,d,[[0,-.3],[.25,0],[0,.3],[-.25,0],[0,-.3]]);l.poly(g),l.fill(xe),l.poly(g),l.stroke({width:x*.05,color:u}),l.poly(k),l.fill(gt);break}case"lab":{const g=d-x*.025;l.circle(c,g,x*.55),l.fill(xe),l.circle(c,g,x*.55),l.stroke({width:x*.05,color:u}),l.circle(c,g,x*.4),l.fill(gt),l.rect(c-x*.45,d+x*.3,x*.9,x*.25),l.fill(xe),l.poly(lt(c,d,[[-.45,.3],[-.45,.55],[.45,.55],[.45,.3]])),l.stroke({width:x*.05,color:u});break}case"container":{l.rect(c-x*.225,d-x*.3,x*.45,x*.6),l.fill(qe),l.rect(c-x*.225,d-x*.3,x*.45,x*.6),l.stroke({width:x*.1,color:xe});break}case"observer":{l.circle(c,d,x*.45),l.fill(xe),l.circle(c,d,x*.45),l.stroke({width:x*.05,color:u}),l.circle(c+x*.225,d,x*.2),l.fill(u);break}case"nuker":{const g=lt(c,d,[[0,-1],[-.47,.2],[-.5,.5],[.5,.5],[.47,.2],[0,-1]]),k=lt(c,d,[[0,-.8],[-.4,.2],[.4,.2],[0,-.8]]);l.poly(g),l.fill(xe),l.poly(g),l.stroke({width:x*.05,color:u}),l.poly(k),l.fill(gt),l.poly(k),l.stroke({width:x*.01,color:u});break}case"factory":case"extractor":case"invaderCore":{l.circle(c,d,x*.45),l.fill(xe),l.circle(c,d,x*.45),l.stroke({width:x*.05,color:u}),l.circle(c,d,x*.35),l.fill(gt);break}case"flag":{const g=typeof r.color=="number"?r.color:0,k=typeof r.secondaryColor=="number"?r.secondaryColor:0,O=Ft[g]??Ft[0],b=Ft[k]??Ft[0],v=1.5,T=x*.08*v,P=x*.7*v,m=c-T/2,$=d-x*.25*v;l.rect(m,$,T,P),l.fill(8947848);const R=m+T,M=$,I=R+x*.45*v,L=M,A=M+x*.44*v,B=(L+A)/2,W=B;if(l.moveTo(R,L),l.lineTo(I,B),l.lineTo(R,W),l.closePath(),l.fill(O),l.moveTo(R,W),l.lineTo(I,B),l.lineTo(R,A),l.closePath(),l.fill(b),o.addChild(l),o.__flagColor=g,o.__flagSecondaryColor=k,typeof r.name=="string"){const K=new Yt({text:r.name,style:{fontSize:Yi,fill:16777215}});K.scale.set(qi),K.anchor.set(.5,0),K.x=c,K.y=d+x*.55,K.visible=e,o.__nameLabel=K,o.addChild(K)}break}case"ruin":{const g=typeof r.user=="string"?r.user:void 0,O=g!==void 0&&g===t?vr:vt,b=x*.42,v=6,T=Math.PI/5,P=new te;for(let R=0;R<v;R++){const M=R*Math.PI*2/v,I=M-T/2,L=M+T/2,A=c+b*Math.cos(I),B=d+b*Math.sin(I);P.moveTo(A,B),P.arc(c,d,b,I,L),P.stroke({width:x*.09,color:O,alpha:.75,cap:"round"})}o.addChild(P);const m=x*.18,$=new te;$.moveTo(c-m,d-m),$.lineTo(c+m,d+m),$.moveTo(c+m,d-m),$.lineTo(c-m,d+m),$.stroke({width:x*.11,color:O,cap:"round"}),o.addChild($);break}case"tombstone":{const g=typeof r.user=="string"?r.user:void 0,O=g!==void 0&&g===t?vr:vt,b=x*.62,v=x*.82,T=c-b/2,P=d-v/2,m=b/2,$=new te;$.moveTo(T,P+m),$.arc(c,P+m,m,Math.PI,0,!1),$.lineTo(T+b,P+v),$.lineTo(T,P+v),$.closePath(),$.fill(xe),$.moveTo(T,P+m),$.arc(c,P+m,m,Math.PI,0,!1),$.lineTo(T+b,P+v),$.lineTo(T,P+v),$.closePath(),$.stroke({width:x*.07,color:O,alpha:.9}),o.addChild($);const R=x*.18,M=new te;M.moveTo(c-R,d-R*.6),M.lineTo(c+R,d+R*.6),M.moveTo(c+R,d-R*.6),M.lineTo(c-R,d+R*.6),M.stroke({width:x*.09,color:O,cap:"round"}),o.addChild(M);break}default:{const g=x-2;l.rect(1,1,g,g),l.fill(a)}}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(l),r.type==="creep"&&typeof r.name=="string"){const g=ei(r,t);let k;if(g){const v=typeof r.user=="string"?r.user:void 0;k=v?((C=s==null?void 0:s[v])==null?void 0:C.username)??v:"Hostile"}else k=r.name;const O=g?vt:16777215,b=new Yt({text:k,style:{fontSize:Yi,fill:O}});b.scale.set(qi),b.anchor.set(.5,1),b.x=c,b.y=Bs-Hs,b.visible=e,o.__nameLabel=b,o.addChild(b)}return r.type==="creep"&&(o.zIndex=1),r.type==="flag"&&(o.zIndex=10),o.position.set(r.x*x,r.y*x),o}function lr(r){r.destroy({children:!0})}class Gd{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,"instantMode",!1);_(this,"lastWorldScale",1);_(this,"showLabels");_(this,"currentUserId");_(this,"badge");_(this,"badgeCache",Cd);_(this,"users");this.showLabels=t,this.currentUserId=i,this.badge=n,this.users=s,this.container=new Pe,this.container.sortableChildren=!0,this.rampartGraphics=new te,this.rampartGraphics.zIndex=-1,this.container.addChild(this.rampartGraphics),this.roadGraphics=new te,this.container.addChild(this.roadGraphics),e&&(this.ticker=e,this.tickerCallback=()=>this.tick(),e.add(this.tickerCallback))}tick(){var o;for(const l of this.objects.values()){const a=l.__targetX,c=l.__targetY;if(a!==void 0&&c!==void 0){const d=a-l.x,h=c-l.y;Math.abs(d)<.5&&Math.abs(h)<.5?(l.position.set(a,c),l.__targetX=void 0,l.__targetY=void 0):(l.x+=d*.15,l.y+=h*.15)}}const e=((o=this.container.parent)==null?void 0:o.scale.x)??1;if(e!==this.lastWorldScale){this.lastWorldScale=e;for(const l of this.objects.values())this.applyLabelScale(l)}const t=performance.now(),i=t/1e3,n=.5+.5*Math.sin(t*2*Math.PI/Ad);for(const l of this.objects.values())l.__barrelContainer&&(l.__barrelContainer.rotation=i*.4),l.__csRingGraphics&&l.__csColorDark!==void 0&&l.__csColorLight!==void 0&&qs(l.__csRingGraphics,Ys(l.__csColorDark,l.__csColorLight,n));for(const[l,a]of this.extAnimations){const c=t-a.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),h=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;ki(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*h),d>=1&&this.extAnimations.delete(l)}for(const[l,a]of this.creepFillAnimations){const c=t-a.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),h=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;Si(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*h),d>=1&&this.creepFillAnimations.delete(l)}for(const[l,a]of this.towerFillAnimations){const c=t-a.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),h=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;Vr(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*h),d>=1&&this.towerFillAnimations.delete(l)}for(const[l,a]of this.sourceAnimations){const c=t-a.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),h=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;$i(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*h),d>=1&&this.sourceAnimations.delete(l)}const s=$n(t);for(const l of this.objects.values()){const a=l.__sourceGraphics;a&&_n(a,l.__sourceSize??ji,s)}for(const[l,a]of this.buildGlowAnimations){const c=this.objects.get(l),d=c==null?void 0:c.__csBuildGlow;if(!c||!d){this.buildGlowAnimations.delete(l);continue}const h=(t-a.startTime)/a.duration;let f;h<=0?f=0:h<.5?f=h/.5:h<.7?f=1:h<1?f=1-(h-.7)/.3:f=0,d.clear(),f>0&&(d.circle(x/2,x/2,Ld),d.fill({color:qe,alpha:f*.75})),h>=1&&this.buildGlowAnimations.delete(l)}}startExtAnimation(e,t,i,n,s,o){const l=tn(s,o);if(this.instantMode){ki(t,l);return}const a=tn(i,n);a!==l&&this.extAnimations.set(e,{visual:t,fromRadius:a,toRadius:l,startTime:performance.now()})}startCreepFillAnimation(e,t,i,n,s,o){const l=en(s,o);if(this.instantMode){Si(t,l);return}const a=en(i,n);a!==l&&this.creepFillAnimations.set(e,{visual:t,fromRadius:a,toRadius:l,startTime:performance.now()})}startTowerFillAnimation(e,t,i,n,s,o){const l=on(s,o);if(this.instantMode){Vr(t,l);return}const a=on(i,n);a!==l&&this.towerFillAnimations.set(e,{visual:t,fromRadius:a,toRadius:l,startTime:performance.now()})}startSourceAnimation(e,t,i,n,s,o){const l=Vi(s,o);if(this.instantMode){$i(t,l);return}const a=Vi(i,n);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 l=this.rawObjects.get(s);l&&l.type==="road"&&(n=!0);const a=this.objects.get(s);a&&(this.container.removeChild(a),lr(a),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 l=e[s];if(!l)continue;if(l.type==="road"){const c=this.rawObjects.get(s);(!c||c.x!==l.x||c.y!==l.y)&&(n=!0)}this.rawObjects.set(s,l);const a=this.objects.get(s);if(a){const c=l.x*x,d=l.y*x;if(l.type==="creep"){const h=l.x-(a.__tileX??l.x),f=l.y-(a.__tileY??l.y);(h!==0||f!==0)&&(a.__angle=Math.atan2(f,h),a.__bodyContainer&&(a.__bodyContainer.rotation=a.__angle)),a.__tileX=l.x,a.__tileY=l.y,this.instantMode?(a.position.set(c,d),a.__targetX=void 0,a.__targetY=void 0):(a.x!==c||a.y!==d)&&(a.__targetX=c,a.__targetY=d);const{used:u,capacity:p}=Qi(l);(a.__creepUsed!==u||a.__creepCapacity!==p)&&(this.startCreepFillAnimation(s,a,a.__creepUsed??0,a.__creepCapacity??p,u,p),a.__creepUsed=u,a.__creepCapacity=p)}else if(l.type==="flag"){const h=typeof l.color=="number"?l.color:0,f=typeof l.secondaryColor=="number"?l.secondaryColor:0;if(a.__flagColor!==h||a.__flagSecondaryColor!==f){this.container.removeChild(a),lr(a),this.objects.delete(s);const p=Nr(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);p.__tileX=l.x,p.__tileY=l.y,this.applyLabelScale(p),this.objects.set(s,p),this.container.addChild(p)}else a.position.set(c,d)}else a.position.set(c,d);if(l.type==="extension"){const{energy:h,capacity:f}=Ut(l),u=a;(u.__extEnergy!==h||u.__extCapacity!==f)&&(this.startExtAnimation(s,a,u.__extEnergy??0,u.__extCapacity??f,h,f),u.__extEnergy=h,u.__extCapacity=f)}if(l.type==="tower"){const{energy:h,capacity:f}=Ut(l);(a.__towerEnergy!==h||a.__towerCapacity!==f)&&(this.startTowerFillAnimation(s,a,a.__towerEnergy??0,a.__towerCapacity??f,h,f),a.__towerEnergy=h,a.__towerCapacity=f)}if(l.type==="controller"){const h=typeof l.level=="number"?l.level:0,f=typeof l.progress=="number"?l.progress:0,u=typeof l.progressTotal=="number"?l.progressTotal:0;(a.__ctrlLevel!==h||a.__ctrlProgress!==f||a.__ctrlProgressTotal!==u)&&(a.__ctrlSegGraphics&&cn(a.__ctrlSegGraphics,x/2,x/2,an,Ze,h,f,u),a.__ctrlLevel=h,a.__ctrlProgress=f,a.__ctrlProgressTotal=u)}if(l.type==="source"){const{energy:h,capacity:f}=Zi(l);(a.__sourceEnergy!==h||a.__sourceCapacity!==f)&&(this.startSourceAnimation(s,a,a.__sourceEnergy??0,a.__sourceCapacity??f,h,f),a.__sourceEnergy=h,a.__sourceCapacity=f)}if(l.type==="constructionSite"){const h=typeof l.progress=="number"?l.progress:0,f=typeof l.progressTotal=="number"?l.progressTotal:1;(a.__csProgress!==h||a.__csProgressTotal!==f)&&(a.__csFillGraphics&&Ji(a.__csFillGraphics,x/2,x/2,Ki,h,f,a.__csColor??vr),a.__csProgress=h,a.__csProgressTotal=f)}}else{const c=Nr(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);c.__tileX=l.x,c.__tileY=l.y,this.applyLabelScale(c),this.objects.set(s,c),this.container.addChild(c)}}else{const s=new Set;for(const o in e){const l=e[o];if(!l)continue;s.add(o),this.rawObjects.set(o,l);const a=this.objects.get(o);if(a){const c=l.x*x,d=l.y*x;if(l.type==="creep"){const h=l.x-(a.__tileX??l.x),f=l.y-(a.__tileY??l.y);(h!==0||f!==0)&&(a.__angle=Math.atan2(f,h),a.__bodyContainer&&(a.__bodyContainer.rotation=a.__angle)),a.__tileX=l.x,a.__tileY=l.y,this.instantMode?(a.position.set(c,d),a.__targetX=void 0,a.__targetY=void 0):(a.x!==c||a.y!==d)&&(a.__targetX=c,a.__targetY=d);const{used:u,capacity:p}=Qi(l);(a.__creepUsed!==u||a.__creepCapacity!==p)&&(this.startCreepFillAnimation(o,a,a.__creepUsed??0,a.__creepCapacity??p,u,p),a.__creepUsed=u,a.__creepCapacity=p)}else if(l.type==="flag"){const h=typeof l.color=="number"?l.color:0,f=typeof l.secondaryColor=="number"?l.secondaryColor:0;if(a.__flagColor!==h||a.__flagSecondaryColor!==f){this.container.removeChild(a),lr(a),this.objects.delete(o);const p=Nr(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);p.__tileX=l.x,p.__tileY=l.y,this.applyLabelScale(p),this.objects.set(o,p),this.container.addChild(p)}else a.position.set(c,d)}else a.position.set(c,d);if(l.type==="extension"){const{energy:h,capacity:f}=Ut(l),u=a;(u.__extEnergy!==h||u.__extCapacity!==f)&&(this.startExtAnimation(o,a,u.__extEnergy??0,u.__extCapacity??f,h,f),u.__extEnergy=h,u.__extCapacity=f)}if(l.type==="tower"){const{energy:h,capacity:f}=Ut(l);(a.__towerEnergy!==h||a.__towerCapacity!==f)&&(this.startTowerFillAnimation(o,a,a.__towerEnergy??0,a.__towerCapacity??f,h,f),a.__towerEnergy=h,a.__towerCapacity=f)}if(l.type==="controller"){const h=typeof l.level=="number"?l.level:0,f=typeof l.progress=="number"?l.progress:0,u=typeof l.progressTotal=="number"?l.progressTotal:0;(a.__ctrlLevel!==h||a.__ctrlProgress!==f||a.__ctrlProgressTotal!==u)&&(a.__ctrlSegGraphics&&cn(a.__ctrlSegGraphics,x/2,x/2,an,Ze,h,f,u),a.__ctrlLevel=h,a.__ctrlProgress=f,a.__ctrlProgressTotal=u)}if(l.type==="source"){const{energy:h,capacity:f}=Zi(l);(a.__sourceEnergy!==h||a.__sourceCapacity!==f)&&(this.startSourceAnimation(o,a,a.__sourceEnergy??0,a.__sourceCapacity??f,h,f),a.__sourceEnergy=h,a.__sourceCapacity=f)}if(l.type==="constructionSite"){const h=typeof l.progress=="number"?l.progress:0,f=typeof l.progressTotal=="number"?l.progressTotal:1;(a.__csProgress!==h||a.__csProgressTotal!==f)&&(a.__csFillGraphics&&Ji(a.__csFillGraphics,x/2,x/2,Ki,h,f,a.__csColor??vr),a.__csProgress=h,a.__csProgressTotal=f)}}else{const c=Nr(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);c.__tileX=l.x,c.__tileY=l.y,this.applyLabelScale(c),this.objects.set(o,c),this.container.addChild(c)}}for(const[o,l]of this.objects)s.has(o)||(this.container.removeChild(l),lr(l),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=Ds,t=Array.from({length:50},()=>new Array(50).fill(!1)),i=[];for(const a of this.rawObjects.values())a.type==="road"&&(i.push(a),a.x>=0&&a.x<50&&a.y>=0&&a.y<50&&(t[a.x][a.y]=!0));if(i.length===0)return;const n=x/2,s=x/2,o=x*.125;for(const a of i)this.roadGraphics.circle(a.x*x+n,a.y*x+s,o);this.roadGraphics.fill(e);const l=[[1,0],[1,1],[0,1],[-1,1]];for(const a of i){const c=a.x*x+n,d=a.y*x+s;for(const[h,f]of l){const u=a.x+h,p=a.y+f;if(u>=0&&u<50&&p>=0&&p<50&&t[u][p]){const w=u*x+n,C=p*x+s;this.roadGraphics.moveTo(c,d),this.roadGraphics.lineTo(w,C)}}}this.roadGraphics.stroke({width:o*2,color:e})}redrawRamparts(){this.rampartGraphics.clear();const e=x,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:Un,alpha:.7}:s===this.currentUserId?{color:Un,alpha:.7}:{color:7807522,alpha:.5};for(let s=0;s<50;s++)for(let o=0;o<50;o++){const l=i[o][s],a=l!==void 0,c=s>0&&i[o][s-1]!==void 0,d=s<49&&i[o][s+1]!==void 0,h=o>0&&i[o-1][s]!==void 0,f=o<49&&i[o+1][s]!==void 0,u=o*e+t,p=s*e+t;if(a){const w=n(l);!c&&!h&&s>0&&o>0?(this.rampartGraphics.moveTo(u,s*e),this.rampartGraphics.arc(u,p,t,-Math.PI/2,Math.PI,!0),this.rampartGraphics.lineTo(u,p),this.rampartGraphics.fill(w)):(this.rampartGraphics.rect(o*e,s*e,t,t),this.rampartGraphics.fill(w))}else if(c&&h&&i[o-1][s-1]!==void 0){const w=n(i[o-1][s-1]);this.rampartGraphics.moveTo(u,s*e),this.rampartGraphics.lineTo(o*e,s*e),this.rampartGraphics.lineTo(o*e,p),this.rampartGraphics.arc(u,p,t,Math.PI,-Math.PI/2,!1),this.rampartGraphics.fill(w)}if(a){const w=n(l);!c&&!f&&s>0&&o<49?(this.rampartGraphics.moveTo(u,s*e),this.rampartGraphics.arc(u,p,t,-Math.PI/2,0,!1),this.rampartGraphics.lineTo(u,p),this.rampartGraphics.fill(w)):(this.rampartGraphics.rect(u,s*e,t,t),this.rampartGraphics.fill(w))}else if(c&&f&&i[o+1][s-1]!==void 0){const w=n(i[o+1][s-1]);this.rampartGraphics.moveTo(u,s*e),this.rampartGraphics.lineTo(o*e+e,s*e),this.rampartGraphics.lineTo(o*e+e,p),this.rampartGraphics.arc(u,p,t,0,-Math.PI/2,!0),this.rampartGraphics.fill(w)}if(a){const w=n(l);!d&&!h&&s<49&&o>0?(this.rampartGraphics.moveTo(o*e,p),this.rampartGraphics.arc(u,p,t,Math.PI,Math.PI/2,!0),this.rampartGraphics.lineTo(u,p),this.rampartGraphics.fill(w)):(this.rampartGraphics.rect(o*e,p,t,t),this.rampartGraphics.fill(w))}else if(d&&h&&i[o-1][s+1]!==void 0){const w=n(i[o-1][s+1]);this.rampartGraphics.moveTo(o*e,p),this.rampartGraphics.lineTo(o*e,s*e+e),this.rampartGraphics.lineTo(u,s*e+e),this.rampartGraphics.arc(u,p,t,Math.PI/2,Math.PI,!1),this.rampartGraphics.fill(w)}if(a){const w=n(l);!d&&!f&&s<49&&o<49?(this.rampartGraphics.moveTo(u,s*e+e),this.rampartGraphics.arc(u,p,t,Math.PI/2,0,!0),this.rampartGraphics.lineTo(u,p),this.rampartGraphics.fill(w)):(this.rampartGraphics.rect(u,p,t,t),this.rampartGraphics.fill(w))}else if(d&&f&&i[o+1][s+1]!==void 0){const w=n(i[o+1][s+1]);this.rampartGraphics.moveTo(u,s*e+e),this.rampartGraphics.lineTo(o*e+e,s*e+e),this.rampartGraphics.lineTo(o*e+e,p),this.rampartGraphics.arc(u,p,t,0,Math.PI/2,!1),this.rampartGraphics.fill(w)}}}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(qi/t),e.__nameLabel.anchor.y===0?e.__nameLabel.y=x/2+x*.55:e.__nameLabel.y=Bs-Hs/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||!ei(s,this.currentUserId))continue;const o=typeof s.user=="string"?s.user:void 0,l=o?((t=(e=this.users)==null?void 0:e[o])==null?void 0:t.username)??o:"Hostile";n.__nameLabel.text!==l&&(n.__nameLabel.text=l)}}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"||!ei(s,this.currentUserId)||n.__creepBadgeSprite)continue;const o=typeof s.user=="string"?s.user:void 0,l=o?(t=(e=this.users)==null?void 0:e[o])==null?void 0:t.badge:void 0;if(!l)continue;const a=n.__bodyContainer;if(!a)continue;n.__creepForeignMark&&!n.__creepForeignMark.destroyed&&(a.removeChild(n.__creepForeignMark),n.__creepForeignMark.destroy(),n.__creepForeignMark=void 0);const c=new Vt;c.anchor.set(.5,.5);const d=Ye*2;c.width=d,c.height=d,c.rotation=Math.PI/2,a.addChild(c),n.__creepBadgeSprite=c,this.badgeCache.getOrCreate(l).then(h=>{c.destroyed||(c.texture=h)}).catch(()=>{c.destroyed||(a.removeChild(c),c.destroy()),n.__creepBadgeSprite=void 0})}}triggerBuildAt(e,t,i){if(!this.instantMode)for(const[n,s]of this.objects){const o=this.rawObjects.get(n);if(!(!o||o.type!=="constructionSite")&&!(o.x!==e||o.y!==t)&&s.__csBuildGlow){this.buildGlowAnimations.set(n,{startTime:performance.now(),duration:i});return}}}setInstantMode(e){if(this.instantMode=e,!!e){for(const t of this.objects.values())t.__targetX!==void 0&&(t.position.set(t.__targetX,t.__targetY),t.__targetX=void 0,t.__targetY=void 0);for(const t of this.extAnimations.values())ki(t.visual,t.toRadius);this.extAnimations.clear();for(const t of this.creepFillAnimations.values())Si(t.visual,t.toRadius);this.creepFillAnimations.clear();for(const t of this.towerFillAnimations.values())Vr(t.visual,t.toRadius);this.towerFillAnimations.clear();for(const t of this.sourceAnimations.values())$i(t.visual,t.toRadius);this.sourceAnimations.clear(),this.buildGlowAnimations.clear()}}setShowLabels(e){this.showLabels=e;for(const t of this.objects.values())t.__nameLabel&&(t.__nameLabel.visible=e)}getVisualById(e){return this.objects.get(e)}clear(){for(const e of this.objects.values())lr(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(),this.container.addChild(this.rampartGraphics),this.container.addChild(this.roadGraphics)}destroy(){this.clear(),this.ticker&&this.tickerCallback&&this.ticker.remove(this.tickerCallback),this.ticker=null,this.tickerCallback=null}}const Ci=2;function At(r,e){return{cx:r*x+x/2,cy:e*x+x/2}}class Dd{constructor(e){_(this,"container");_(this,"graphics");_(this,"animations",[]);_(this,"ticker",null);_(this,"tickerCallback",null);this.container=new Pe,this.graphics=new te,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=At(e,t),l=At(i,n);this.animations.push({fromX:o.cx,fromY:o.cy,toX:l.cx,toY:l.cy,startTime:performance.now(),duration:s,color:ad,width:Ci})}addUpgradeController(e,t,i,n,s){const o=At(e,t),l=At(i,n);this.animations.push({fromX:o.cx,fromY:o.cy,toX:l.cx,toY:l.cy,startTime:performance.now(),duration:s,color:cd,width:Ci})}addBuild(e,t,i,n,s){const o=At(e,t),l=At(i,n);this.animations.push({fromX:o.cx,fromY:o.cy,toX:l.cx,toY:l.cy,startTime:performance.now(),duration:s,color:dd,width:Ci})}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 l,a,c,d;const h=.5,f=.2;if(o<h){const u=o/h;l=n.fromX,a=n.fromY,c=n.fromX+(n.toX-n.fromX)*u,d=n.fromY+(n.toY-n.fromY)*u}else if(o<h+f)l=n.fromX,a=n.fromY,c=n.toX,d=n.toY;else{const u=(o-h-f)/(1-h-f);l=n.fromX+(n.toX-n.fromX)*u,a=n.fromY+(n.toY-n.fromY)*u,c=n.toX,d=n.toY}this.graphics.moveTo(l,a),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 Te=r=>(r+.5)*x,ar=4,Gr={dashed:[.4*x,.4*x],dotted:[.1*x,.3*x]};function Dr(r,e,t,i){let n=!0,s=t;for(let o=0;o<e.length-1;o++){const[l,a]=e[o],[c,d]=e[o+1],h=c-l,f=d-a,u=Math.sqrt(h*h+f*f);if(u<.001)continue;const p=h/u,w=f/u;let C=0;for(;C<u;){const g=Math.min(s,u-C);if(n){const k=l+p*C,O=a+w*C;r.moveTo(k,O),r.lineTo(k+p*g,O+w*g)}C+=g,s-=g,s<.001&&(n=!n,s=n?t:i)}}}function zd(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 Bd(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/x:t}function Hd(r){if(typeof r!="string")return"Arial";const e=r.match(/^[0-9.]+(px)?\s+(.+)$/);return e?e[2]:"Arial"}class Fd{constructor(){_(this,"container");_(this,"g");this.container=new Pe,this.container.label="visuals",this.g=new te,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??{},l=o.opacity??1;switch(s.t){case"l":this.drawLine(i,s,o,l);break;case"c":this.drawCircle(i,s,o,l);break;case"r":this.drawRect(i,s,o,l);break;case"p":this.drawPoly(i,s,o,l);break;case"t":this.drawText(s,o,l);break}}}drawLine(e,t,i,n){const s=Te(t.x1),o=Te(t.y1),l=Te(t.x2),a=Te(t.y2),c=i.color??"#ffffff",d=(i.width??.1)*x;if(i.lineStyle&&i.lineStyle!=="solid"){const[h,f]=Gr[i.lineStyle];Dr(e,[[s,o],[l,a]],h,f)}else e.moveTo(s,o),e.lineTo(l,a);e.stroke({color:c,width:d,alpha:n})}drawCircle(e,t,i,n){const s=Te(t.x),o=Te(t.y),l=(i.radius??.5)*x,a=!!(i.fill&&i.fill!=="transparent"),c=!!(i.stroke&&i.strokeWidth),d=i.lineStyle&&i.lineStyle!=="solid";if(a&&(e.circle(s,o,l),e.fill({color:i.fill,alpha:n})),c){const h=i.strokeWidth*x;if(d){const[f,u]=Gr[i.lineStyle];Dr(e,zd(s,o,l),f,u)}else e.circle(s,o,l);e.stroke({color:i.stroke,width:h,alpha:n})}}drawRect(e,t,i,n){const s=Te(t.x),o=Te(t.y),l=t.w*x,a=t.h*x,c=!!(i.fill&&i.fill!=="transparent"),d=!!(i.stroke&&i.strokeWidth),h=i.lineStyle&&i.lineStyle!=="solid";if(c&&(e.rect(s,o,l,a),e.fill({color:i.fill,alpha:n})),d){const f=i.strokeWidth*x;if(h){const[u,p]=Gr[i.lineStyle],w=[[s,o],[s+l,o],[s+l,o+a],[s,o+a],[s,o]];Dr(e,w,u,p)}else e.rect(s,o,l,a);e.stroke({color:i.stroke,width:f,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 l=i.lineStyle&&i.lineStyle!=="solid",a=new Array(t.points.length*2);let c;o&&l&&(c=new Array(t.points.length));for(let d=0;d<t.points.length;d++){const[h,f]=t.points[d],u=Te(h),p=Te(f);a[d*2]=u,a[d*2+1]=p,c&&(c[d]=[u,p])}if(s&&(e.poly(a,!0),e.fill({color:i.fill,alpha:n})),o){const d=i.strokeWidth*x;if(l&&c){const[h,f]=Gr[i.lineStyle],u=c[0],p=c[c.length-1],w=u[0]===p[0]&&u[1]===p[1];Dr(e,w?c:[...c,u],h,f)}else e.poly(a,!0);e.stroke({color:i.stroke,width:d,alpha:n})}}drawText(e,t,i){const n=Bd(t.font),s=Hd(t.font),o=t.align??"left",l=new Oo({fill:t.color??"#ffffff",fontSize:Math.round(n*x*ar),fontFamily:s,align:o,...t.stroke&&t.strokeWidth?{stroke:{color:t.stroke,width:t.strokeWidth*x*ar}}:{}});if(t.backgroundColor&&t.backgroundColor!=="transparent"){const c=Lo.measureText(e.text,l),d=c.width/ar,h=c.height/ar,f=(t.backgroundPadding??.3)*x,u=o==="center"?.5:o==="right"?1:0,p=Te(e.x)-u*d-f,w=Te(e.y)-h/2-f,C=new te;C.rect(p,w,d+f*2,h+f*2),C.fill({color:t.backgroundColor,alpha:i}),this.container.addChild(C)}const a=new Yt({text:e.text,style:l});a.scale.set(1/ar),a.anchor.x=o==="center"?.5:o==="right"?1:0,a.anchor.y=.5,a.position.set(Te(e.x),Te(e.y)),a.alpha=i,this.container.addChild(a)}destroy(){const e=this.container.removeChildren();for(const t of e)t!==this.g&&t.destroy();this.g.destroy(),this.container.destroy()}}function er(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[Vs,Wd]=er(me.widescreenMode,!0),[ti,Zs]=er(me.showCreepLabels,!0),[Ks,Js]=er(me.showMapRoomNames,!1),[Qs,eo]=er(me.showUnclaimableRooms,!0),[Zr,Ud]=er(me.terrainEffects,!0),[to,Xd]=er(me.showRoomVisuals,!0),dn=Symbol("store-raw"),qt=Symbol("store-node"),Ke=Symbol("store-has"),ro=Symbol("store-self");function io(r){let e=r[Ct];if(!e&&(Object.defineProperty(r,Ct,{value:e=new Proxy(r,jd)}),!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,l=t.length;o<l;o++){const a=t[o];s&&a==="constructor"||i[a].get&&Object.defineProperty(r,a,{configurable:!0,enumerable:i[a].enumerable,get:i[a].get.bind(e)})}}return e}function ht(r){let e;return r!=null&&typeof r=="object"&&(r[Ct]||!(e=Object.getPrototypeOf(r))||e===Object.prototype||Array.isArray(r))}function Zt(r,e=new Set){let t,i,n,s;if(t=r!=null&&r[dn])return t;if(!ht(r)||e.has(r))return r;if(Array.isArray(r)){Object.isFrozen(r)?r=r.slice(0):e.add(r);for(let o=0,l=r.length;o<l;o++)n=r[o],(i=Zt(n,e))!==n&&(r[o]=i)}else{Object.isFrozen(r)?r=Object.assign({},r):e.add(r);const o=Object.keys(r),l=Object.getOwnPropertyDescriptors(r);for(let a=0,c=o.length;a<c;a++)s=o[a],!l[s].get&&(n=r[s],(i=Zt(n,e))!==n&&(r[s]=i))}return r}function ri(r,e){let t=r[e];return t||Object.defineProperty(r,e,{value:t=Object.create(null)}),t}function _r(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 Yd(r,e){const t=Reflect.getOwnPropertyDescriptor(r,e);return!t||t.get||!t.configurable||e===Ct||e===qt||(delete t.value,delete t.writable,t.get=()=>r[Ct][e]),t}function no(r){Hi()&&_r(ri(r,qt),ro)()}function qd(r){return no(r),Reflect.ownKeys(r)}const jd={get(r,e,t){if(e===dn)return r;if(e===Ct)return t;if(e===En)return no(r),t;const i=ri(r,qt),n=i[e];let s=n?n():r[e];if(e===qt||e===Ke||e==="__proto__")return s;if(!n){const o=Object.getOwnPropertyDescriptor(r,e);Hi()&&(typeof s!="function"||r.hasOwnProperty(e))&&!(o&&o.get)&&(s=_r(i,e,s)())}return ht(s)?io(s):s},has(r,e){return e===dn||e===Ct||e===En||e===qt||e===Ke||e==="__proto__"?!0:(Hi()&&_r(ri(r,Ke),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:qd,getOwnPropertyDescriptor:Yd};function Ae(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[Ke]&&r[Ke][e]&&n!==void 0&&r[Ke][e].$()):(r[e]=t,r[Ke]&&r[Ke][e]&&n===void 0&&r[Ke][e].$());let o=ri(r,qt),l;if((l=_r(o,e,n))&&l.$(()=>t),Array.isArray(r)&&r.length!==s){for(let a=r.length;a<s;a++)(l=o[a])&&l.$();(l=_r(o,"length",s))&&l.$(r.length)}(l=o[ro])&&l.$()}function so(r,e){const t=Object.keys(e);for(let i=0;i<t.length;i+=1){const n=t[i];oo(n)||Ae(r,n,e[n])}}function oo(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function Vd(r,e){if(typeof e=="function"&&(e=e(r)),e=Zt(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&&Ae(r,t,n)}Ae(r,"length",i)}else so(r,e)}function fr(r,e,t=[]){let i,n=r;if(e.length>1){i=e.shift();const o=typeof i,l=Array.isArray(r);if(o==="string"&&(i==="__proto__"||e.length>1&&oo(i))){console.warn(`Refusing to traverse unsafe key "${i}" on a store.`);return}if(Array.isArray(i)){for(let a=0;a<i.length;a++)fr(r,[i[a]].concat(e),t);return}else if(l&&o==="function"){for(let a=0;a<r.length;a++)i(r[a],a)&&fr(r,[a].concat(e),t);return}else if(l&&o==="object"){const{from:a=0,to:c=r.length-1,by:d=1}=i;for(let h=a;h<=c;h+=d)fr(r,[h].concat(e),t);return}else if(e.length>1){fr(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=Zt(s),i===void 0||ht(n)&&ht(s)&&!Array.isArray(s)?so(n,s):Ae(r,i,s))}function Zd(...[r,e]){const t=Zt(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=io(t);To.registerGraph({value:t,name:e&&e.name});function s(...o){Mo(()=>{i&&o.length===1?Vd(t,o[0]):fr(t,o)})}return[n,s]}const un=Symbol("store-root");function Vn(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function zt(r,e,t,i,n){if(Vn(t))return;const s=e[t];if(r===s)return;const o=Array.isArray(r);if(t!==un&&(!ht(r)||!ht(s)||o!==Array.isArray(s)||n&&r[n]!==s[n])){Ae(e,t,r);return}if(o){if(r.length&&s.length&&(!i||n&&r[0]&&r[0][n]!=null)){let c,d,h,f,u,p,w,C;for(h=0,f=Math.min(s.length,r.length);h<f&&(s[h]===r[h]||n&&s[h]&&r[h]&&s[h][n]&&s[h][n]===r[h][n]);h++)zt(r[h],s,h,i,n);const g=new Array(r.length),k=new Map;for(f=s.length-1,u=r.length-1;f>=h&&u>=h&&(s[f]===r[u]||n&&s[f]&&r[u]&&s[f][n]&&s[f][n]===r[u][n]);f--,u--)g[u]=s[f];if(h>u||h>f){for(d=h;d<=u;d++)Ae(s,d,r[d]);for(;d<r.length;d++)Ae(s,d,g[d]),zt(r[d],s,d,i,n);s.length>r.length&&Ae(s,"length",r.length);return}for(w=new Array(u+1),d=u;d>=h;d--)p=r[d],C=n&&p?p[n]:p,c=k.get(C),w[d]=c===void 0?-1:c,k.set(C,d);for(c=h;c<=f;c++)p=s[c],C=n&&p?p[n]:p,d=k.get(C),d!==void 0&&d!==-1&&(g[d]=s[c],d=w[d],k.set(C,d));for(d=h;d<r.length;d++)d in g?(Ae(s,d,g[d]),zt(r[d],s,d,i,n)):Ae(s,d,r[d])}else for(let c=0,d=r.length;c<d;c++)zt(r[c],s,c,i,n);s.length>r.length&&Ae(s,"length",r.length);return}const l=Object.keys(r);for(let c=0,d=l.length;c<d;c++)Vn(l[c])||zt(r[l[c]],s,l[c],i,n);const a=Object.keys(s);for(let c=0,d=a.length;c<d;c++)r[a[c]]===void 0&&Ae(s,a[c],void 0)}function Kd(r,e={}){const{merge:t,key:i="id"}=e,n=Zt(r);return s=>{if(!ht(s)||!ht(n))return n;const o=zt(n,{[un]:s},un,t,i);return o===void 0?s:o}}const Sn=new WeakMap;function Zn(r,e){const[t,i]=Zd(e),n={id:r,type:e.type,raw:t};return Sn.set(n,s=>i(Kd(s,{key:"_id",merge:!1}))),n}const[$r,Kt]=G([]);function Jd(){Kt([])}function zr(r){Kt(e=>e.filter(t=>t.id!==r))}function Qd(r,e){const t=$r();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 l=e[s.id];if(l){const a=Sn.get(s);a==null||a(l)}}n.push(s)}i&&Kt(n)}function eu(r){var n;const e=$r();if(e.length===0)return;let t=!1;const i=[];for(const s of e){const o=r[s.id];if(!o){t=!0;continue}(n=Sn.get(s))==null||n(o),i.push(s)}t&&Kt(i)}const[tu,Ti]=G(null),[lo,Mi]=G(null),[Xt,Ei]=G(null),[ii,Ri]=G({}),[ao,Kn]=G(null);function hn(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 Qe(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),l=n==="N"?-(parseInt(s,10)+1):parseInt(s,10);return{x:o,y:l}}function Be(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 Jn(r){return r===0||r<0&&(r+1)%10===0||r>0&&r%10===0}function Ip(r,e){return Jn(r)||Jn(e)}function Np(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 co(r){const e=r;if(!e)return!1;const t=e.tagName??"";return t==="INPUT"||t==="TEXTAREA"?!0:e.isContentEditable===!0}function ru(r){const e=t=>{if(co(t.target))return;const i=r.currentRoom(),n=i?Qe(i):null;if(!n)return;const s=r.worldBounds(),o=(l,a)=>!s||hn(l,a,s);switch(t.key){case"ArrowLeft":t.preventDefault(),o(n.x-1,n.y)&&r.onMove(n.x-1,n.y);break;case"ArrowRight":t.preventDefault(),o(n.x+1,n.y)&&r.onMove(n.x+1,n.y);break;case"ArrowUp":t.preventDefault(),o(n.x,n.y-1)&&r.onMove(n.x,n.y-1);break;case"ArrowDown":t.preventDefault(),o(n.x,n.y+1)&&r.onMove(n.x,n.y+1);break}};window.addEventListener("keydown",e),Ge(()=>window.removeEventListener("keydown",e))}const[ue,uo]=G(!1),[rt,kn]=G(0),[fn,iu]=G(0),[Sr,ho]=G(0),[br,kr]=G(!1),[Cn,nu]=G(1),[Xe,Pi]=G(!1);let Kr=null;function Cr(){Kr!==null&&(clearInterval(Kr),Kr=null)}function fo(){Cr(),Kr=setInterval(()=>{const r=rt()+1;r>Sr()?(Cr(),kr(!1)):kn(r)},Math.max(50,Math.round(1e3/Cn())))}function po(r){const e=r,t=Math.max(0,e-2e5);ho(e),iu(t),kn(r),kr(!1),Cr(),uo(!0)}function ni(){Cr(),kr(!1),uo(!1)}function si(r){const e=Math.max(fn(),Math.min(Sr(),r));kn(e)}function Qn(r){si(rt()+r)}function su(){br()?(Cr(),kr(!1)):(kr(!0),fo())}function ou(r){nu(r),br()&&fo()}class lu{constructor(e,t,i,n,s,o){_(this,"chunkCache",new Map);_(this,"inflight",new Map);this.room=e,this.shard=t,this.baseUrl=i,this.getToken=n,this.chunkSize=s,this.isPrivate=o}chunkBase(e){return e-e%this.chunkSize}buildUrl(e){return this.isPrivate||this.shard===null?`${this.baseUrl}room-history?room=${encodeURIComponent(this.room)}&time=${e}`:`${this.baseUrl}room-history/${encodeURIComponent(this.shard)}/${encodeURIComponent(this.room)}/${e}.json`}loadChunk(e){const t=this.chunkCache.get(e);if(t)return Promise.resolve(t);const i=this.inflight.get(e);if(i)return i;const n=this.buildUrl(e),s=this.getToken(),o={};s&&(o["X-Token"]=s,o["X-Username"]=s);const l=fetch(n,{headers:o}).then(a=>{if(!a.ok)throw new Error(`HTTP ${a.status}`);return a.json()}).then(a=>(this.chunkCache.set(e,a),this.inflight.delete(e),a)).catch(a=>{throw this.inflight.delete(e),a});return this.inflight.set(e,l),l}applyDiff(e,t){const i={...e};for(const n in t){const s=t[n];s===null?delete i[n]:i[n]?i[n]={...i[n],...s}:i[n]=s}return i}async getStateAtTick(e){let t=this.chunkBase(e),i,n;try{i=await this.loadChunk(t)}catch{const l=t-this.chunkSize;if(l<0)throw new Error(`No history data available before tick ${t}`);i=await this.loadChunk(l),t=l;const a=Object.keys(i.ticks).map(Number).filter(d=>d>=t),c=a.length>0?Math.max(...a):t;n=c,e=c}const s=i.ticks[String(t)]??{};let o={};for(const l in s)s[l]!==null&&(o[l]=s[l]);for(let l=t+1;l<=e;l++){const a=i.ticks[String(l)];a&&Object.keys(a).length>0&&(o=this.applyDiff(o,a))}return{objects:o,diff:i.ticks[String(e)]??{},gameTime:e,clampedTo:n}}}var au=E('<div style=text-align:center;display:flex;flex-direction:column;align-items:center;gap:6px><div style=font-size:14px;font-weight:600;color:#f85149>You have no rooms!</div><button style="padding:4px 12px;border-radius:4px;border:1px solid #238636;background:#1a3a2a;color:#3fb950;font-size:12px;cursor:pointer">Place Spawn'),cu=E('<div style=text-align:center;display:flex;flex-direction:column;align-items:center;gap:6px><div style=font-size:14px;font-weight:600;color:#f85149>You lost all your spawns!</div><button style="padding:4px 12px;border-radius:4px;border:1px solid #da3633;background:#3d1a1a;color:#f85149;font-size:12px;cursor:pointer">Respawn'),du=E("<span>Choose new flag position"),Oi=E("<span>"),uu=E("<span>Select structure type, then click to build — Ctrl+click to remove construction sites");const{log:es,warn:hu,error:ts}=Et("build"),Tr={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},oi={spawn:{0:0,1:1,2:1,3:1,4:1,5:1,6:1,7:2,8:3},extension:{0:0,1:0,2:5,3:10,4:20,5:30,6:40,7:50,8:60},link:{1:0,2:0,3:0,4:0,5:2,6:3,7:4,8:6},road:{0:2500,1:2500,2:2500,3:2500,4:2500,5:2500,6:2500,7:2500,8:2500},constructedWall:{1:0,2:2500,3:2500,4:2500,5:2500,6:2500,7:2500,8:2500},rampart:{1:0,2:2500,3:2500,4:2500,5:2500,6:2500,7:2500,8:2500},storage:{1:0,2:0,3:0,4:1,5:1,6:1,7:1,8:1},tower:{1:0,2:0,3:1,4:1,5:2,6:2,7:3,8:6},observer:{1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:1},powerSpawn:{1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:1},extractor:{1:0,2:0,3:0,4:0,5:0,6:1,7:1,8:1},terminal:{1:0,2:0,3:0,4:0,5:0,6:1,7:1,8:1},lab:{1:0,2:0,3:0,4:0,5:0,6:3,7:6,8:10},container:{0:5,1:5,2:5,3:5,4:5,5:5,6:5,7:5,8:5},nuker:{1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:1},factory:{1:0,2:0,3:0,4:0,5:0,6:0,7:1,8:1}},[Mt,xt]=G("view"),[Bt,go]=G({name:"",color:"COLOR_WHITE",secondaryColor:"COLOR_WHITE"}),[kt,pn]=G(null),[Tn,gn]=G(null),[et,_t]=G({structureType:"",structureName:""});ps(()=>{de(()=>{const r=et().structureType;if(!r)return;const e=Xt()??0,t=oi[r];if(!t)return;const i=Tt()==="empty"&&r==="spawn"?Math.max(t[e]??0,1):t[e]??0;if(i===2500)return;(ii()[r]??0)>=i&&(_t({structureType:"",structureName:""}),ut())})});function ut(){pn(null)}function mn(){gn(null)}function fu(){_t({structureType:"",structureName:""})}function pu(r,e){const t=ae(),i=et(),n=kt();if(!t||!i.structureType||!n){hu("missing requirements",{hasClient:!!t,structureType:i.structureType,pending:n});return}if(Tt()==="empty"&&i.structureType==="spawn"){es("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(()=>(ye("Spawn placed successfully","success"),ut(),t.stores.user.refreshWorldStatus())).catch(s=>{ts("place spawn failed:",s),ye(`Failed to place spawn: ${s.message}`,"error")});return}es("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(()=>{ye(`Construction site for ${i.structureType} created`,"success"),ut()}).catch(s=>{ts("create construction failed:",s),ye(`Failed to create construction site: ${s.message}`,"error")})}function gu(){xt("view"),ut(),mn(),fu()}function rs(){const r=Mt(),e=kt(),t=Tn(),i=Tt();if(i==="empty")return(()=>{var n=au(),s=n.firstChild,o=s.nextSibling;return o.$$click=()=>{xt("build"),_t({structureType:"spawn",structureName:""})},n})();if(i==="lost")return(()=>{var n=cu(),s=n.firstChild,o=s.nextSibling;return o.$$click=()=>{const l=ae();l&&l.http.user.respawn().then(()=>{ye("Respawn successful","success"),l.stores.user.refreshWorldStatus()}).catch(a=>{ye(`Respawn failed: ${a.message}`,"error")})},n})();if((t==null?void 0:t.type)==="moveFlag")return du();if(r==="flag")return(()=>{var n=Oi();return y(n,e?"Confirm position":"Choose position"),n})();if(r==="build"){const n=et(),s=Xt(),o=ii(),l=n.structureType,a=" — Ctrl+click to remove construction sites";if(!l)return uu();const c=oi[l],d=(c==null?void 0:c[s??0])??0,h=o[l]??0,f=l.replace(/([A-Z])/g," $1").trim();return d===2500?(()=>{var u=Oi();return y(u,`Click to build ${f} (${h}/∞)${a}`),u})():(()=>{var u=Oi();return y(u,`Click to build ${f} (${h}/${d})${a}`),u})()}return null}ke(["click"]);var mu=E('<div style="position:absolute;bottom:0;left:0;right:0;padding:8px 12px;background:rgba(13, 17, 23, 0.85);border-top:1px solid #30363d;z-index:10"><input type=range step=1 style=width:100%;cursor:pointer><div style=display:flex;justify-content:space-between;font-size:10px;color:#8b949e;margin-top:2px><span></span><span></span><span>'),yu=E("<div style=width:100%;height:100%;position:relative><div style=width:100%;height:100%>"),vu=E('<div style="position:absolute;top:12px;left:50%;transform:translateX(-50%);padding:6px 16px;border-radius:6px;background:rgba(13, 17, 23, 0.65);border:1px solid rgba(48, 54, 61, 0.6);font-size:13px;font-weight:500;color:#c9d1d9;user-select:none;z-index:10">'),bu=E('<div style="position:absolute;top:8px;right:8px;padding:4px 10px;border-radius:4px;background:rgba(13, 17, 23, 0.8);border:1px solid #30363d;font-size:12px;color:#8b949e;z-index:10">Tick ');const{log:cr,error:dr}=Et("room");function wu(r){let e,t=null,i=null,n=null,s=null;const[o,l]=G(null),[a,c]=G(null),[d,h]=G(null),[f,u]=G(""),[p,w]=G(rt());de(()=>w(rt()));let C=null;return Mr(async()=>{if(!e)return;const g=await wn.create(e);l(g)}),Ge(()=>{C!==null&&clearTimeout(C),t==null||t.destroy(),t=null,i==null||i.destroy(),i=null,n==null||n.destroy(),n=null;const g=o();g&&g.destroy()}),de(()=>{const g=ae();if(!g||ue())return;const k=r.room,O=r.shard;c(null),h(null),u(""),Xr(null),Jd(),Ti(null),Mi(null),Ei(null),Ri({}),Kn(null);const b=new vn;let v=!1;g.stores.room.terrain(k,O).then(T=>{v||c({room:k,data:T})}).catch(T=>{v||dr(`terrain load failed for ${k}:`,T)}),b.add(g.stores.room.subscribe(k,O)),b.add(g.stores.room.on("room:error",T=>{ye(`Room subscription error (${T.room}): ${T.message}`,"error",8e3)})),b.add(g.stores.room.on("room:update",T=>{var M,I;let P=0;const m={};let $=0,R=null;for(const L in T.objects){P++;const A=T.objects[L];if(!A)continue;const B=A.type;if(typeof B=="string")if(B==="constructionSite"){const W=A.structureType;typeof W=="string"&&(m[W]=(m[W]||0)+1)}else m[B]=(m[B]||0)+1;if(B==="controller"&&typeof A.user=="string"){const W=A.user,K=((I=(M=T.users)==null?void 0:M[W])==null?void 0:I.username)??W;R={userId:W,username:K},typeof A.level=="number"&&($=A.level)}}T.diff||cr(`objects loaded — ${k}: ${P} objects, tick=${T.gameTime}`),h({objects:T.objects,diff:T.diff,users:T.users}),u(T.visual),Xr(T.gameTime??null),Zl(T.gameTime),Ti(P),Mi(R),Ei($||null),Ri(m),Kn(T.users??null)})),Ge(()=>{v=!0,b.dispose()})}),de(()=>{var m,$;const g=ae();if(!g||!ue())return;u("");const k=r.room,O=r.shard,b=Jl()??!0,v=(($=(m=Ts())==null?void 0:m.serverData)==null?void 0:$.historyChunkSize)??(b?20:100),T=fe(ao)??void 0,P=new lu(k,O,g.http.baseUrl,()=>g.http.token,v,b);de(()=>{const R=rt();let M=!1;Pi(!0),P.getStateAtTick(R).then(I=>{var K;if(M)return;if(Pi(!1),I.clampedTo!==void 0){ho(I.clampedTo),si(I.clampedTo);return}h({objects:I.objects,diff:void 0,users:T}),Xr(I.gameTime);let L=0;const A={};let B=0,W=null;for(const H in I.objects){L++;const F=I.objects[H];if(!F)continue;const Y=F.type;if(typeof Y=="string")if(Y==="constructionSite"){const z=F.structureType;typeof z=="string"&&(A[z]=(A[z]||0)+1)}else A[Y]=(A[Y]||0)+1;if(Y==="controller"&&typeof F.user=="string"){const z=F.user,U=((K=T==null?void 0:T[z])==null?void 0:K.username)??z;W={userId:z,username:U},typeof F.level=="number"&&(B=F.level)}}Ti(L),Mi(W),Ei(B||null),Ri(A)}).catch(I=>{M||(Pi(!1),ye(`History load failed for tick ${R}: ${I.message}`,"error",5e3))}),Ge(()=>{M=!0})})}),de(()=>{const g=o();if(!g)return;r.room,r.shard,gu(),g.hoverLayer.clearPendingTile(),s==null||s.destroy(),s=null,g.clear(),g.resetView(),t==null||t.destroy(),t=null,i==null||i.destroy(),i=null,n==null||n.destroy(),n=null;const k=fe(a);k&&k.room===r.room&&(cr(`terrain applied immediately (pre-loaded) — ${r.room}`),s=Xn(k.data,g.app.renderer),_i(s,fe(Zr)),g.world.addChildAt(s,0),g.bringNavOverlayToTop());const O=r.room,b=r.shard,v=Qe(O),T=fe(()=>r.onNavigate),P=fe(bi);if(v&&T){const m=(R,M)=>!P||hn(R,M,P),$=R=>{T(R,b)};g.setupNavigationZones({west:m(v.x-1,v.y)?()=>$(Be(v.x-1,v.y)):void 0,east:m(v.x+1,v.y)?()=>$(Be(v.x+1,v.y)):void 0,north:m(v.x,v.y-1)?()=>$(Be(v.x,v.y-1)):void 0,south:m(v.x,v.y+1)?()=>$(Be(v.x,v.y+1)):void 0})}}),de(()=>{const g=o();if(!g)return;const k=fe(()=>r.room),O=fe(()=>r.shard),b=Qe(k);if(b&&r.onNavigate){const v=r.onNavigate,T=bi(),P=($,R)=>!T||hn($,R,T),m=$=>{v($,O)};ru({currentRoom:()=>r.room,worldBounds:bi,onMove:($,R)=>m(Be($,R))}),g.setupNavigationZones({west:P(b.x-1,b.y)?()=>m(Be(b.x-1,b.y)):void 0,east:P(b.x+1,b.y)?()=>m(Be(b.x+1,b.y)):void 0,north:P(b.x,b.y-1)?()=>m(Be(b.x,b.y-1)):void 0,south:P(b.x,b.y+1)?()=>m(Be(b.x,b.y+1)):void 0})}}),de(()=>{const g=Mt(),k=o();g==="view"&&k&&(ut(),k.hoverLayer.clearPendingTile())}),de(()=>{const g=o(),k=kt();g&&(k?g.hoverLayer.setPendingTile(k.tx,k.ty):g.hoverLayer.clearPendingTile())}),de(()=>{const g=o(),k=a();if(!(!g||!k||k.room!==r.room)){if(s!=null&&s.parent){cr(`terrain already in scene, skipping — ${r.room}`);return}cr(`terrain applied (async) — ${r.room}`),s=Xn(k.data,g.app.renderer),_i(s,fe(Zr)),g.world.addChildAt(s,0),g.bringNavOverlayToTop()}}),de(()=>{var T,P;const g=o(),k=d();if(!g)return;if(!k){t==null||t.clear(),i==null||i.clear();return}const{objects:O,diff:b,users:v}=k;if(t||(cr(`object layer created — ${r.room}`),t=new Gd(g.app.ticker,ti(),(T=Ne())==null?void 0:T._id,(P=Ne())==null?void 0:P.badge,v),t.setInstantMode(fe(ue)),t.container.label="objects",g.world.addChild(t.container),g.bringNavOverlayToTop(),i=new Dd(g.app.ticker),i.container.label="animations",g.world.addChild(i.container),n=new Fd,g.world.addChild(n.container),g.bringNavOverlayToTop(),g.setTileHandlers((m,$)=>{},(m,$,R)=>{const M=r.room,I=r.shard,L=Mt(),A=Tn();if((A==null?void 0:A.type)==="moveFlag"){const H=ae();if(!H)return;const{name:F,room:Y,color:z,secondaryColor:U}=A;H.http.game.removeFlag(Y,F).then(()=>H.http.game.createFlag(M,m,$,F,z,U,I??void 0)).then(()=>{ye(`Flag "${F}" moved`,"success"),mn()}).catch(Q=>{dr("move flag failed:",Q),ye(`Failed to move flag "${F}"`,"error"),mn()});return}if(L==="flag"){const H=kt();if(!H||H.tx!==m||H.ty!==$){pn({tx:m,ty:$}),g.hoverLayer.setPendingTile(m,$);return}const F=ae();if(!F)return;const Y=Bt(),z=Y.name.trim();if(!z){ye("Flag name is required","error");return}const U=Tr[Y.color]??0,Q=Tr[Y.secondaryColor]??0;F.http.game.createFlag(M,m,$,z,U,Q,I??void 0).then(()=>{ye(`Flag "${z}" created`,"success"),ut(),g.hoverLayer.clearPendingTile(),F.http.game.genUniqueFlagName().then(J=>go(V=>({...V,name:J.name}))).catch(J=>dr("gen unique flag name failed:",J))}).catch(J=>dr("create flag failed:",J));return}if(L==="build"){if(!R&&!et().structureType){ye("Select a structure type first","error");return}if(R){if(!t)return;const F=t.getObjectsAtTile(m,$).filter(({obj:z})=>z.type==="constructionSite");if(F.length===0){ye("No construction sites on this tile","error");return}const Y=ae();if(!Y)return;Y.http.game.removeConstructionSite(M,F.map(({id:z})=>z),I??void 0).then(()=>{ye(`Removed ${F.length} construction site${F.length>1?"s":""}`,"success"),ut(),g.hoverLayer.clearPendingTile()}).catch(z=>{dr("remove construction sites failed:",z),ye(`Failed to remove construction sites: ${z.message}`,"error")});return}pn({tx:m,ty:$}),g.hoverLayer.setPendingTile(m,$),pu(M,I);return}if(ut(),g.hoverLayer.clearPendingTile(),!t)return;const B=t.getObjectsAtTile(m,$);if(B.length===0){R||(Kt([]),g.hoverLayer.clearSelection());return}let W=[...$r()];if(R){const H=new Set(B.map(Y=>Y.id));if(W.some(Y=>H.has(Y.id)))W=W.filter(Y=>!H.has(Y.id));else{const Y=B.filter(({id:z})=>!W.some(U=>U.id===z)).map(({id:z,obj:U})=>Zn(z,U));W=[...W,...Y]}}else W=B.map(({id:H,obj:F})=>Zn(H,F));Kt(W);const K=W.map(({id:H,type:F})=>({id:H,type:F,visual:t.getVisualById(H)})).filter(H=>H.visual!=null);g.hoverLayer.setSelectedObjects(K)})),b?Qd(b,O):eu(O),t.update(O,b,v),t.setShowLabels(fe(ti)),i){i.clear();const m=ue()?Math.round(1e3/fe(Cn)):(Jr()??2e3)*.6;for(const $ in O){const R=O[$];if(!R||R.type!=="creep")continue;const M=R.actionLog;if(M){if(M.harvest){const I=M.harvest;i.addHarvest(I.x,I.y,R.x,R.y,m)}if(M.upgradeController){const I=M.upgradeController;i.addUpgradeController(R.x,R.y,I.x,I.y,m)}if(M.build){const I=M.build;i.addBuild(R.x,R.y,I.x,I.y,m),t==null||t.triggerBuildAt(I.x,I.y,m)}}}}}),de(()=>{const g=f();n==null||n.update(to()?g:"")}),de(()=>{t==null||t.setInstantMode(ue())}),de(()=>{const g=Zr();s&&_i(s,g)}),(()=>{var g=yu(),k=g.firstChild;return pr(O=>e=O,k),y(g,(()=>{var O=ie(()=>!!rs());return()=>O()&&(()=>{var b=vu();return y(b,rs),N(v=>D(b,"pointer-events",Tt()==="empty"||Tt()==="lost"?"auto":"none")),b})()})(),null),y(g,(()=>{var O=ie(()=>!ue()&&Ie()!==null);return()=>O()&&(()=>{var b=bu();return b.firstChild,y(b,Ie,null),b})()})(),null),y(g,S(X,{get when(){return ue()},get children(){var O=mu(),b=O.firstChild,v=b.nextSibling,T=v.firstChild,P=T.nextSibling,m=P.nextSibling;return b.$$input=$=>{const R=parseInt($.currentTarget.value,10);w(R),C!==null&&clearTimeout(C),C=setTimeout(()=>{C=null,si(R)},150)},y(T,fn),y(P,(()=>{var $=ie(()=>!!Xe());return()=>$()?"Loading…":`Tick ${rt()}`})()),y(m,Sr),N($=>{var R=fn(),M=Sr(),I=Xe()?"#f0883e":"#8b949e";return R!==$.e&&_e(b,"min",$.e=R),M!==$.t&&_e(b,"max",$.t=M),I!==$.a&&D(P,"color",$.a=I),$},{e:void 0,t:void 0,a:void 0}),N(()=>b.value=p()),O}}),null),g})()}ke(["input"]);var xu=E("<div style=position:fixed;bottom:16px;right:16px;display:flex;flex-direction:column;gap:8px;z-index:9999;pointer-events:none>"),_u=E('<div style="padding:10px 16px;border-radius:6px;font-size:13px;color:#fff;box-shadow:0 4px 12px rgba(0,0,0,0.4);max-width:320px;word-break:break-word;pointer-events:auto;animation:toast-in 0.2s ease">');function $u(){return(()=>{var r=xu();return y(r,S(ve,{get each(){return Dl()},children:e=>(()=>{var t=_u();return y(t,()=>e.message),N(i=>D(t,"background",e.type==="error"?"#da3633":"#238636")),t})()})),r})()}const[at,Su]=G(!0),[Ve,ku]=G(!0),[It,Cu]=G(!1);function mo(){Su(r=>!r)}function yo(){ku(r=>!r)}function vo(){Cu(r=>!r)}var Tu=E('<div style=flex-shrink:0;display:flex;overflow:hidden><div style="width:32px;flex-shrink:0;border-right:1px solid #30363d;display:flex;flex-direction:column;align-items:center;padding:6px 0;gap:6px"><button></button><button title=Clear></button></div><div class=console-scroll style=flex:1;overflow:auto;padding:8px>'),is=E("<div style=width:4px;flex-shrink:0;cursor:col-resize>"),Mu=E('<div style=flex-shrink:0;display:flex;flex-direction:column;overflow:hidden><div class=console-scroll style=flex:1;overflow:auto;padding:8px></div><form style="display:flex;gap:6px;padding:8px;border-top:1px solid #30363d"><span style=color:#8b949e;font-size:13px;line-height:28px>></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'),Eu=E("<div style=flex-shrink:0;display:flex;flex-direction:column;overflow:hidden><div style=flex:1;display:flex;align-items:center;justify-content:center;color:#484f58;font-style:italic>Memory – coming soon"),Ru=E("<div style=flex:1;display:flex;overflow:hidden>"),Pu=E(`<div style=display:flex;flex-direction:column;height:100%;background:#0d1117><div style="height:32px;flex-shrink:0;padding:0 10px;border-bottom:1px solid #30363d;display:flex;align-items:center;gap:6px"><button>Log</button><button>Console</button><button>Memory</button></div><style>
|
|
10
|
-
.console-scroll::-webkit-scrollbar {
|
|
11
|
-
width: 8px;
|
|
12
|
-
height: 8px;
|
|
13
|
-
}
|
|
14
|
-
.console-scroll::-webkit-scrollbar-track {
|
|
15
|
-
background: #161b22;
|
|
16
|
-
}
|
|
17
|
-
.console-scroll::-webkit-scrollbar-thumb {
|
|
18
|
-
background: #484f58;
|
|
19
|
-
border-radius: 4px;
|
|
20
|
-
}
|
|
21
|
-
.console-scroll::-webkit-scrollbar-thumb:hover {
|
|
22
|
-
background: #6e7681;
|
|
23
|
-
}
|
|
24
|
-
`),Ou=E("<div style=color:#484f58;font-style:italic>No log output yet…"),Lu=E("<div style=margin-bottom:4px;color:#f85149;white-space:pre-wrap;word-break:break-word>"),Au=E("<div style=margin-bottom:4px;color:#c9d1d9;white-space:pre-wrap;word-break:break-word>"),Iu=E("<div style=color:#484f58;font-style:italic>No command results yet…"),Nu=E("<div style=margin-bottom:4px;color:#58a6ff;white-space:pre-wrap;word-break:break-word>");const{error:Gu}=Et("console");function Du(r){const[e,t]=G([]),[i,n]=G(""),[s,o]=G(!0),l=[1,1,1],[a,c]=G(Xl(me.consoleWeights,[...l])),[d,h]=G(null);let f,u,p,w=0;Mr(()=>{const L=ae();if(!L)return;const A=new vn;A.add(L.stores.user.subscribe("console")),A.add(L.stores.user.on("user:console",B=>{const W=B.messages,K={id:w++,log:W.log??[],results:W.results??[],error:W.error??[]};t(H=>{const F=[...H,K];return F.length>200?F.slice(F.length-200):F})})),Ge(()=>A.dispose())}),de(()=>{e(),s()&&requestAnimationFrame(()=>{at()&&f&&(f.scrollTop=f.scrollHeight),Ve()&&u&&(u.scrollTop=u.scrollHeight)})});const C=(L,A,B)=>{var K,H;const W=!L&&!A&&!B;W&&!r.isCollapsed&&((K=r.onToggle)==null||K.call(r)),!W&&r.isCollapsed&&((H=r.onToggle)==null||H.call(r))};de(()=>{C(at(),Ve(),It())});const g=()=>{const L=a(),A=[at(),Ve(),It()],B=A.filter(Boolean).length;if(B===0)return[0,0,0];if(B===1){const H=A.findIndex(Boolean);return[0,0,0].map((F,Y)=>Y===H?1:0)}const K=A.map((H,F)=>H?L[F]:0).reduce((H,F)=>H+F,0);if(K===0){const H=1/B;return[0,0,0].map((F,Y)=>A[Y]?H:0)}return A.map((H,F)=>H?L[F]/K:0)};de(()=>{Yl(me.consoleWeights,a())});const k=L=>A=>{A.preventDefault(),A.stopPropagation(),h(L),document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("pointermove",O),window.addEventListener("pointerup",b,{once:!0})},O=L=>{const A=d();if(A===null)return;const B=p;if(!B)return;const W=B.getBoundingClientRect(),K=Math.max(.02,Math.min(.98,(L.clientX-W.left)/W.width)),H=[...a()],F=[at(),Ve(),It()];if(A===0){const Y=F[0],z=F[1];if(!Y||!z)return;const U=K/(1-K);H[0]=U,H[1]=1,c(H)}else{const Y=F[1],z=F[2];if(!Y||!z)return;const U=K/(1-K);H[1]=U,H[2]=1,c(H)}},b=()=>{h(null),document.body.style.cursor="",document.body.style.userSelect="",window.removeEventListener("pointermove",O)},v=async L=>{L.preventDefault();const A=ae();if(!(!A||!i().trim()))try{await A.http.user.console(i().trim(),r.shard??"shard0"),n("")}catch(B){Gu("command failed:",B)}},T=L=>({background:L?"#30363d":"transparent",border:`1px solid ${L?"#58a6ff":"transparent"}`,color:L?"#c9d1d9":"#8b949e","font-size":"12px",cursor:"pointer",padding:"2px 10px","border-radius":"4px"}),P=()=>e().flatMap(L=>L.log),m=()=>e().flatMap(L=>L.error),$=()=>e().flatMap(L=>L.results),R={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"},M={background:"transparent",border:"none",color:"#8b949e",cursor:"pointer",padding:"4px","border-radius":"4px",display:"flex","align-items":"center","justify-content":"center"},I=()=>{o(!0),requestAnimationFrame(()=>{at()&&f&&(f.scrollTop=f.scrollHeight),Ve()&&u&&(u.scrollTop=u.scrollHeight)})};return(()=>{var L=Pu(),A=L.firstChild,B=A.firstChild,W=B.nextSibling,K=W.nextSibling;return A.nextSibling,ct(B,"click",mo,!0),ct(W,"click",yo,!0),ct(K,"click",vo,!0),y(L,S(X,{get when(){return!r.isCollapsed},get children(){var H=Ru();return pr(F=>p=F,H),y(H,S(X,{get when(){return at()},get children(){var F=Tu(),Y=F.firstChild,z=Y.firstChild,U=z.nextSibling,Q=Y.nextSibling;z.$$click=()=>s()?o(!1):I(),y(z,(()=>{var V=ie(()=>!!s());return()=>V()?S(Za,{size:16}):S(Qa,{size:16})})()),U.$$click=()=>t([]),y(U,S(qr,{size:16})),Q.addEventListener("scroll",()=>{f&&o(f.scrollHeight-f.scrollTop-f.clientHeight<20)});var J=f;return typeof J=="function"?pr(J,Q):f=Q,y(Q,(()=>{var V=ie(()=>P().length===0&&m().length===0);return()=>V()&&Ou()})(),null),y(Q,S(ve,{get each(){return m()},children:V=>(()=>{var he=Lu();return he.innerHTML=V,he})()}),null),y(Q,S(ve,{get each(){return P()},children:V=>(()=>{var he=Au();return he.innerHTML=V,he})()}),null),N(V=>{var he=`${g()[0]*100}%`,Oe=s()?"Pause scrolling":"Resume scrolling",it=M,De=M,We={...R};return he!==V.e&&D(F,"width",V.e=he),Oe!==V.t&&_e(z,"title",V.t=Oe),V.a=Z(z,it,V.a),V.o=Z(U,De,V.o),V.i=Z(Q,We,V.i),V},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),F}}),null),y(H,S(X,{get when(){return ie(()=>!!at())()&&Ve()},get children(){var F=is();return ct(F,"pointerdown",k(0),!0),N(Y=>D(F,"background",d()===0?"#388bfd":"#21262d")),F}}),null),y(H,S(X,{get when(){return Ve()},get children(){var F=Mu(),Y=F.firstChild,z=Y.nextSibling,U=z.firstChild,Q=U.nextSibling;Q.nextSibling,Y.addEventListener("scroll",()=>{u&&o(u.scrollHeight-u.scrollTop-u.clientHeight<20)});var J=u;return typeof J=="function"?pr(J,Y):u=Y,y(Y,(()=>{var V=ie(()=>$().length===0);return()=>V()&&Iu()})(),null),y(Y,S(ve,{get each(){return $()},children:V=>(()=>{var he=Nu();return he.innerHTML=V,he})()}),null),z.addEventListener("submit",v),Q.$$input=V=>n(V.currentTarget.value),N(V=>{var he=`${g()[1]*100}%`,Oe={...R};return he!==V.e&&D(F,"width",V.e=he),V.t=Z(Y,Oe,V.t),V},{e:void 0,t:void 0}),N(()=>Q.value=i()),F}}),null),y(H,S(X,{get when(){return ie(()=>!!Ve())()&&It()},get children(){var F=is();return ct(F,"pointerdown",k(1),!0),N(Y=>D(F,"background",d()===1?"#388bfd":"#21262d")),F}}),null),y(H,S(X,{get when(){return It()},get children(){var F=Eu();return F.firstChild,N(Y=>D(F,"width",`${g()[2]*100}%`)),F}}),null),N(F=>D(H,"user-select",d()!==null?"none":"auto")),H}}),null),N(H=>{var F=T(at()),Y=T(Ve()),z=T(It());return H.e=Z(B,F,H.e),H.t=Z(W,Y,H.t),H.a=Z(K,z,H.a),H},{e:void 0,t:void 0,a:void 0}),L})()}ke(["click","pointerdown","input"]);const zu={1:2e4,2:1e4,3:2e4,4:4e4,5:8e4,6:12e4,7:15e4,8:2e5};var Bu=E("<div style=display:flex;gap:5px;flex-wrap:wrap>"),Hu=E("<div style=width:18px;height:18px;border-radius:50%;cursor:pointer;flex-shrink:0>");const Fu=[{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 li(r){return(()=>{var e=Bu();return y(e,S(ve,{each:Fu,children:t=>(()=>{var i=Hu();return i.$$click=()=>r.onChange(t.value),N(n=>{var s=t.label,o=t.css,l=r.value===t.value?"0 0 0 2px #0d1117, 0 0 0 4px #c9d1d9":"none";return s!==n.e&&_e(i,"title",n.e=s),o!==n.t&&D(i,"background",n.t=o),l!==n.a&&D(i,"box-shadow",n.a=l),n},{e:void 0,t:void 0,a:void 0}),i})()})),e})()}ke(["click"]);var jt=E("<div>"),ai=E("<div style=font-variant-numeric:tabular-nums>"),Wu=E("<span style=font-variant-numeric:tabular-nums;font-weight:400> / "),Uu=E('<div style="background:#21262d;border-top:1px solid #30363d;font-size:10px"><div style="padding:4px 8px;background:#161b22;color:#8b949e;font-weight:600;display:flex;justify-content:space-between"><span>Store Contents</span></div><div style="display:grid;grid-template-columns:1fr 1fr;gap:1px;background:#21262d">'),Xu=E('<div style="padding:3px 8px;background:#0d1117;color:#8b949e">'),Yu=E('<div style="padding:3px 8px;background:#0d1117;color:#c9d1d9;font-variant-numeric:tabular-nums">'),qu=E("<div>Owner"),bo=E("<div>Hits"),Mn=E("<div style=font-variant-numeric:tabular-nums> / "),ju=E("<div>Time to live"),Vu=E("<div>Fatigue"),Zu=E('<div style="background:#21262d;border-top:1px solid #30363d;font-size:10px"><div style="padding:4px 8px;background:#161b22;color:#8b949e;font-weight:600">Body (<!>)</div><div style=display:flex;flex-wrap:wrap;gap:3px;padding:8px;background:#0d1117>'),Ku=E("<div><div>"),Ju=E("<div style=width:11px;height:11px;border-radius:50%;flex-shrink:0>"),Qu=E('<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">'),eh=E("<div style=padding:8px;display:flex;flex-direction:column;gap:8px;background:#0d1117><label>Primary color</label><label>Secondary color"),th=E("<div>Level"),rh=E("<div>Progress"),ih=E("<div>Safe modes"),nh=E("<div>Power"),sh=E("<div>Downgrade in"),oh=E("<div>Safe mode active"),lh=E("<div style=font-variant-numeric:tabular-nums> ticks"),ah=E('<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">'),ch=E("<div><div><div>Owner</div><div>"),dh=E("<div>Reserved"),uh=E("<div> (<!>)"),hh=E("<div>Notify when attacked"),fh=E("<div style=display:flex;align-items:center><button style=background:transparent;border:none;cursor:pointer;padding:0;display:flex;align-items:center>"),ph=E("<div><div>Energy</div><div style=font-variant-numeric:tabular-nums> / "),gh=E("<div style=width:8px;height:8px;border-radius:50%;flex-shrink:0>"),Li=E('<button style="background:transparent;border:none;cursor:pointer;padding:0 2px;display:flex;align-items:center;justify-content:center;flex-shrink:0">'),mh=E('<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">×'),yh=E("<span style=font-weight:400;color:#8b949e>"),vh=E("<div style=flex:1;overflow:auto;min-height:0;padding:8px>"),bh=E("<div style=color:#484f58;font-style:italic;font-size:12px>Click a tile to select objects…");const{log:ns,error:Jt}=Et("SelectionList"),wh={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"},xh={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"},_h=new Set(["x","y","type","id","name","user","_id","room","hitsMax","energyCapacity","body","storeCapacity","storeCapacityResource"]),ss=new Set(["hits","energy","energyCapacity","store","progress","progressTotal","nextDecayTime"]),os={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 $h(r){return os[r]?os[r]:r.replace(/([A-Z])/g," $1").replace(/^./,e=>e.toUpperCase()).trim()}function Sh(r){return typeof r=="number"?String(r):typeof r=="string"?r:typeof r=="boolean"?r?"Yes":"No":null}function ls(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 le=(r=!1)=>({padding:"3px 8px",background:"#0d1117",color:r?"#8b949e":"#c9d1d9",overflow:"hidden","text-overflow":"ellipsis","white-space":"nowrap"}),fi={display:"grid","grid-template-columns":"1fr 1fr",gap:"1px",background:"#21262d","font-size":"10px"};function kh(r){const e=()=>{const t=r.item.raw,i=[];for(const n in t){if(_h.has(n))continue;const s=t[n];let o=Sh(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 l=Ie();l!==null&&(o=String(s-l))}o!==null&&i.push({key:n,label:$h(n),value:o})}}return i.sort((n,s)=>{const o=ss.has(n.key)?0:1,l=ss.has(s.key)?0:1;return o-l}),i};return S(X,{get when(){return e().length>0},get children(){var t=jt();return y(t,S(ve,{get each(){return e()},children:i=>[(()=>{var n=jt();return y(n,()=>i.label),N(s=>Z(n,le(!0),s)),n})(),(()=>{var n=ai();return y(n,()=>i.value),N(s=>Z(n,{...le()},s)),n})()]})),N(i=>Z(t,fi,i)),t}})}function Ch(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 S(X,{get when(){return e().length>0},get children(){var i=Uu(),n=i.firstChild;n.firstChild;var s=n.nextSibling;return y(n,S(X,{get when(){return r.capacity!=null},get children(){var o=Wu(),l=o.firstChild;return y(o,t,l),y(o,()=>r.capacity,null),o}}),null),y(s,S(ve,{get each(){return e()},children:([o,l])=>[(()=>{var a=Xu();return y(a,o),a})(),(()=>{var a=Yu();return y(a,l),a})()]})),i}})}const Th={tough:"#4c4c4c",move:"#a9b7c6",work:"#ffe56d",carry:"#777777",attack:"#f93842",ranged_attack:"#5d80b2",heal:"#65fd62",claim:"#b99cfb"};function Mh(r){const e=()=>r.item.raw,t=()=>typeof e().user=="string"?e().user:null,i=()=>{var f,u;const h=t();return h?((u=(f=ao())==null?void 0:f[h])==null?void 0:u.username)??h:null},n=()=>typeof e().hits=="number"?e().hits:null,s=()=>typeof e().hitsMax=="number"?e().hitsMax:null,o=()=>{const h=e().ageTime,f=Ie();return typeof h=="number"&&f!==null?Math.max(0,h-f):null},l=()=>typeof e().fatigue=="number"?e().fatigue:null,a=()=>e().store,c=()=>typeof e().storeCapacity=="number"?e().storeCapacity:null,d=()=>e().body??[];return(()=>{var h=Ku(),f=h.firstChild;return y(f,S(X,{get when(){return i()},get children(){return[(()=>{var u=qu();return N(p=>Z(u,le(!0),p)),u})(),(()=>{var u=jt();return y(u,i),N(p=>Z(u,le(),p)),u})()]}}),null),y(f,S(X,{get when(){return ie(()=>n()!==null)()&&s()!==null},get children(){return[(()=>{var u=bo();return N(p=>Z(u,le(!0),p)),u})(),(()=>{var u=Mn(),p=u.firstChild;return y(u,n,p),y(u,s,null),N(w=>Z(u,{...le()},w)),u})()]}}),null),y(f,S(X,{get when(){return o()!==null},get children(){return[(()=>{var u=ju();return N(p=>Z(u,le(!0),p)),u})(),(()=>{var u=ai();return y(u,o),N(p=>Z(u,{...le()},p)),u})()]}}),null),y(f,S(X,{get when(){return ie(()=>l()!==null)()&&l()>0},get children(){return[(()=>{var u=Vu();return N(p=>Z(u,le(!0),p)),u})(),(()=>{var u=ai();return y(u,l),N(p=>Z(u,{...le()},p)),u})()]}}),null),y(h,S(Ch,{get store(){return a()},get capacity(){return c()}}),null),y(h,S(X,{get when(){return d().length>0},get children(){var u=Zu(),p=u.firstChild,w=p.firstChild,C=w.nextSibling;C.nextSibling;var g=p.nextSibling;return y(p,()=>d().length,C),y(g,S(ve,{get each(){return d()},children:k=>(()=>{var O=Ju();return N(b=>{var v=k.type.replace("_"," "),T=Th[k.type]??"#484f58",P=k.hits===0?.25:1;return v!==b.e&&_e(O,"title",b.e=v),T!==b.t&&D(O,"background",b.t=T),P!==b.a&&D(O,"opacity",b.a=P),b},{e:void 0,t:void 0,a:void 0}),O})()})),u}}),null),N(u=>Z(f,fi,u)),h})()}function Eh(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,l]=G(n()),[a,c]=G(s());de(()=>{l(n()),c(s())});const d=()=>o()!==n()||a()!==s(),h=()=>{const w=ae();if(!w)return;const C=o(),g=a();ns(`changeFlagColor: name="${t()}" room=${i()} primary=${C} secondary=${g}`),w.http.game.changeFlagColor(i(),t(),C,g).then(()=>ns("changeFlagColor OK")).catch(k=>Jt("changeFlagColor FAILED:",k))},f=()=>{const w=Tn();return(w==null?void 0:w.type)==="moveFlag"&&w.id===r.item.id},u=()=>{if(f()){gn(null);return}gn({type:"moveFlag",id:r.item.id,name:t(),room:i(),color:o(),secondaryColor:a()})},p={display:"flex","flex-direction":"column",gap:"5px","font-size":"11px",color:"#8b949e"};return(()=>{var w=eh(),C=w.firstChild;C.firstChild;var g=C.nextSibling;return g.firstChild,y(C,S(li,{get value(){return o()},onChange:l}),null),y(g,S(li,{get value(){return a()},onChange:c}),null),y(w,S(X,{get when(){return!ue()},get children(){var k=Qu(),O=k.firstChild,b=O.nextSibling;return O.addEventListener("mouseleave",v=>{d()&&(v.currentTarget.style.background="#238636")}),O.addEventListener("mouseenter",v=>{d()&&(v.currentTarget.style.background="#2ea043")}),O.$$click=h,b.addEventListener("mouseleave",v=>{v.currentTarget.style.color=f()?"#c9d1d9":"#8b949e"}),b.addEventListener("mouseenter",v=>{v.currentTarget.style.color="#c9d1d9"}),b.$$click=u,y(b,(()=>{var v=ie(()=>!!f());return()=>v()?S(hi,{size:13}):S(qa,{size:13})})()),N(v=>{var T=!d(),P=d()?"#238636":"#161b22",m=d()?"#fff":"#484f58",$=`1px solid ${d()?"#238636":"#30363d"}`,R=d()?"pointer":"not-allowed",M=f()?"Abort move":"Move flag",I=f()?"#30363d":"#21262d",L=f()?"#c9d1d9":"#8b949e",A=`1px solid ${f()?"#8b949e":"#30363d"}`;return T!==v.e&&(O.disabled=v.e=T),P!==v.t&&D(O,"background",v.t=P),m!==v.a&&D(O,"color",v.a=m),$!==v.o&&D(O,"border",v.o=$),R!==v.i&&D(O,"cursor",v.i=R),M!==v.n&&_e(b,"title",v.n=M),I!==v.s&&D(b,"background",v.s=I),L!==v.h&&D(b,"color",v.h=L),A!==v.r&&D(b,"border",v.r=A),v},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0}),k}}),null),N(k=>{var O=p,b=p;return k.e=Z(C,O,k.e),k.t=Z(g,b,k.t),k},{e:void 0,t:void 0}),w})()}function Rh(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,l=()=>typeof e().safeMode=="number"?e().safeMode:null,a=()=>e().isPowerEnabled===!0,c=()=>e().reservation,d=()=>typeof e().user=="string"?e().user:null,h=()=>{var v;const b=d();return b?((v=lo())==null?void 0:v.username)??b:null},f=()=>{const b=s(),v=Ie();return b!==null&&v!==null?Math.max(0,b-v):null},u=()=>{const b=f();if(b===null)return"—";const v=zu[t()];return v!==void 0&&b>=v?"Max":String(b)},p=()=>{var b;return d()!==null&&d()===((b=Ne())==null?void 0:b._id)},[w,C]=G(!1);let g=null;const k=()=>{const b=ae();b&&b.http.game.addObjectIntent(r.item.id,e().room,"activateSafeMode",{}).catch(v=>Jt("activateSafeMode failed:",v))},O=()=>{if(!w()){C(!0),g=setTimeout(()=>C(!1),3e3);return}g&&(clearTimeout(g),g=null),C(!1);const b=ae();b&&b.http.game.addObjectIntent(r.item.id,e().room,"unclaim",{}).catch(v=>Jt("unclaim failed:",v))};return(()=>{var b=ch(),v=b.firstChild,T=v.firstChild,P=T.nextSibling;return y(P,()=>h()??"None"),y(v,S(X,{get when(){return c()},children:m=>[(()=>{var $=dh();return N(R=>Z($,le(!0),R)),$})(),(()=>{var $=uh(),R=$.firstChild,M=R.nextSibling;return M.nextSibling,y($,()=>m().username,R),y($,()=>m().ticksToEnd,M),N(I=>Z($,le(),I)),$})()]}),null),y(v,S(X,{get when(){return t()>0},get children(){return[(()=>{var m=th();return N($=>Z(m,le(!0),$)),m})(),(()=>{var m=jt();return y(m,t),N($=>Z(m,le(),$)),m})(),S(X,{get when(){return ie(()=>i()!==null)()&&n()!==null},get children(){return[(()=>{var m=rh();return N($=>Z(m,le(!0),$)),m})(),(()=>{var m=Mn(),$=m.firstChild;return y(m,()=>ls(i()),$),y(m,()=>ls(n()),null),N(R=>Z(m,{...le()},R)),m})()]}}),(()=>{var m=ih();return N($=>Z(m,le(!0),$)),m})(),(()=>{var m=jt();return y(m,o),N($=>Z(m,le(),$)),m})(),(()=>{var m=nh();return N($=>Z(m,le(!0),$)),m})(),(()=>{var m=jt();return y(m,()=>a()?"Enabled":"Disabled"),N($=>Z(m,le(),$)),m})(),(()=>{var m=sh();return N($=>Z(m,le(!0),$)),m})(),(()=>{var m=ai();return y(m,u),N($=>Z(m,{...le(),color:u()==="Max"?"#3fb950":void 0},$)),m})()]}}),null),y(v,S(X,{get when(){return l()!==null},get children(){return[(()=>{var m=oh();return N($=>Z(m,le(!0),$)),m})(),(()=>{var m=lh(),$=m.firstChild;return y(m,l,$),N(R=>Z(m,{...le()},R)),m})()]}}),null),y(b,S(X,{get when(){return ie(()=>!!p())()&&!ue()},get children(){var m=ah(),$=m.firstChild,R=$.nextSibling;return $.addEventListener("mouseleave",M=>{o()>0&&(M.currentTarget.style.background="#1f6feb")}),$.addEventListener("mouseenter",M=>{o()>0&&(M.currentTarget.style.background="#388bfd")}),$.$$click=k,R.addEventListener("mouseleave",M=>{w()||(M.currentTarget.style.background="#f85149")}),R.addEventListener("mouseenter",M=>{w()||(M.currentTarget.style.background="#da3633")}),R.$$click=O,y(R,()=>w()?"Confirm unclaim":"Unclaim"),N(M=>{var I=o()===0,L=o()>0?"#1f6feb":"#161b22",A=o()>0?"pointer":"not-allowed",B=o()>0?1:.5,W=w()?"#da3633":"#f85149";return I!==M.e&&($.disabled=M.e=I),L!==M.t&&D($,"background",M.t=L),A!==M.a&&D($,"cursor",M.a=A),B!==M.o&&D($,"opacity",M.o=B),W!==M.i&&D(R,"background",M.i=W),M},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),m}}),null),N(m=>{var $=fi,R=le(!0),M=le();return m.e=Z(v,$,m.e),m.t=Z(T,R,m.t),m.a=Z(P,M,m.a),m},{e:void 0,t:void 0,a:void 0}),b})()}function Ph(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,l=()=>typeof e().user=="string"?e().user:null,a=()=>{var d;return l()!==null&&l()===((d=Ne())==null?void 0:d._id)},c=()=>{const d=ae();d&&d.http.game.addObjectIntent(r.item.id,e().room,"notifyWhenAttacked",{enabled:!o()}).catch(h=>Jt("notifyWhenAttacked failed:",h))};return(()=>{var d=ph(),h=d.firstChild,f=h.nextSibling,u=f.firstChild;return y(f,t,u),y(f,i,null),y(d,S(X,{get when(){return ie(()=>n()!==null)()&&s()!==null},get children(){return[(()=>{var p=bo();return N(w=>Z(p,le(!0),w)),p})(),(()=>{var p=Mn(),w=p.firstChild;return y(p,n,w),y(p,s,null),N(C=>Z(p,{...le()},C)),p})()]}}),null),y(d,S(X,{get when(){return ie(()=>!!a())()&&!ue()},get children(){return[(()=>{var p=hh();return N(w=>Z(p,le(!0),w)),p})(),(()=>{var p=fh(),w=p.firstChild;return w.addEventListener("mouseleave",C=>{C.currentTarget.style.color=o()?"#3fb950":"#484f58"}),w.addEventListener("mouseenter",C=>{C.currentTarget.style.color=o()?"#56d364":"#8b949e"}),w.$$click=c,y(w,(()=>{var C=ie(()=>!!o());return()=>C()?S(ha,{size:12}):S(ca,{size:12})})()),N(C=>{var g={...le()},k=o()?"Notifications on — click to disable":"Notifications off — click to enable",O=o()?"#3fb950":"#484f58";return C.e=Z(p,g,C.e),k!==C.t&&_e(w,"title",C.t=k),O!==C.a&&D(w,"color",C.a=O),C},{e:void 0,t:void 0,a:void 0}),p})()]}}),null),N(p=>{var w=fi,C=le(!0),g={...le()};return p.e=Z(d,w,p.e),p.t=Z(h,C,p.t),p.a=Z(f,g,p.a),p},{e:void 0,t:void 0,a:void 0}),d})()}const Oh={creep:Mh,flag:Eh,controller:Rh,extension:Ph};function Lh(r){const e=()=>wh[r.item.type]??"#c9d1d9",t=()=>xh[r.item.type]??r.item.type,i=()=>r.item.type==="creep",n=()=>r.item.type==="flag",s=()=>{var T;if(!i())return!1;const b=r.item.raw,v=typeof b.user=="string"?b.user:null;return v!==null&&v===((T=Ne())==null?void 0:T._id)},o=()=>{var T;if(i()||n()||r.item.type==="controller")return!1;const b=r.item.raw,v=typeof b.user=="string"?b.user:null;return v!==null&&v===((T=Ne())==null?void 0:T._id)},l=()=>Oh[r.item.type]||kh,[a,c]=G(!1);let d=null;const[h,f]=G(!1);let u=null;const[p,w]=G(!1);let C=null;const g=b=>{if(b.stopPropagation(),!p()){w(!0),C=setTimeout(()=>w(!1),3e3);return}C&&(clearTimeout(C),C=null),w(!1);const v=ae();if(!v)return;const T=r.item.id,P=r.item.raw;v.http.game.removeFlag(P.room,P.name).then(()=>zr(T)).catch(()=>{})},k=b=>{if(b.stopPropagation(),!h()){f(!0),u=setTimeout(()=>f(!1),3e3);return}u&&(clearTimeout(u),u=null),f(!1);const v=ae();if(!v)return;const T=r.item.id,P=r.item.raw,m=P.room;v.http.game.addObjectIntent("room",m,"destroyStructure",[{id:T,roomName:m,user:P.user}]).then(()=>zr(T)).catch($=>Jt("destroyStructure failed:",$))},O=b=>{if(b.stopPropagation(),!a()){c(!0),d=setTimeout(()=>c(!1),3e3);return}d&&(clearTimeout(d),d=null),c(!1);const v=ae();if(!v)return;const T=r.item.id;v.http.game.addObjectIntent(T,r.item.raw.room,"suicide",{}).then(()=>zr(T)).catch(P=>Jt("suicide failed:",P))};return(()=>{var b=mh(),v=b.firstChild,T=v.firstChild,P=T.nextSibling,m=P.firstChild,$=m.nextSibling,R=$.nextSibling,M=R.nextSibling;M.nextSibling;var I=P.nextSibling;return y(v,S(X,{get when(){return ie(()=>!i())()&&!n()},get children(){var L=gh();return N(A=>D(L,"background",e())),L}}),T),y(T,S(X,{get when(){return n()},get fallback(){return ie(t)},get children(){return S(Ls,{size:12})}}),null),y(T,S(X,{get when(){return ie(()=>typeof r.item.raw.name=="string")()&&r.item.raw.name},children:L=>(()=>{var A=yh();return y(A,()=>L()),A})()}),null),y(P,()=>r.item.raw.x,$),y(P,()=>r.item.raw.y,M),y(v,S(X,{get when(){return ie(()=>!!s())()&&!ue()},get children(){var L=Li();return L.addEventListener("mouseleave",A=>{a()||(A.currentTarget.style.color="#8b949e")}),L.addEventListener("mouseenter",A=>{a()||(A.currentTarget.style.color="#f85149")}),L.$$click=O,y(L,S(qr,{size:13})),N(A=>{var B=a()?"Click again to confirm suicide":"Suicide",W=a()?"#f85149":"#8b949e";return B!==A.e&&_e(L,"title",A.e=B),W!==A.t&&D(L,"color",A.t=W),A},{e:void 0,t:void 0}),L}}),I),y(v,S(X,{get when(){return ie(()=>!!o())()&&!ue()},get children(){var L=Li();return L.addEventListener("mouseleave",A=>{h()||(A.currentTarget.style.color="#8b949e")}),L.addEventListener("mouseenter",A=>{h()||(A.currentTarget.style.color="#f85149")}),L.$$click=k,y(L,S(qr,{size:13})),N(A=>{var B=h()?"Click again to confirm destruction":"Destroy structure",W=h()?"#f85149":"#8b949e";return B!==A.e&&_e(L,"title",A.e=B),W!==A.t&&D(L,"color",A.t=W),A},{e:void 0,t:void 0}),L}}),I),y(v,S(X,{get when(){return ie(()=>!!n())()&&!ue()},get children(){var L=Li();return L.addEventListener("mouseleave",A=>{p()||(A.currentTarget.style.color="#8b949e")}),L.addEventListener("mouseenter",A=>{p()||(A.currentTarget.style.color="#f85149")}),L.$$click=g,y(L,S(qr,{size:13})),N(A=>{var B=p()?"Click again to confirm deletion":"Delete flag",W=p()?"#f85149":"#8b949e";return B!==A.e&&_e(L,"title",A.e=B),W!==A.t&&D(L,"color",A.t=W),A},{e:void 0,t:void 0}),L}}),I),I.addEventListener("mouseleave",L=>L.currentTarget.style.color="#8b949e"),I.addEventListener("mouseenter",L=>L.currentTarget.style.color="#fff"),I.$$click=()=>zr(r.item.id),y(b,S(xs,{get component(){return l()},get item(){return r.item}}),null),N(L=>D(b,"border",`1px solid ${s()&&a()||h()||p()?"#f85149":"#30363d"}`)),b})()}function Ah(){return(()=>{var r=vh();return y(r,S(X,{get when(){return $r().length>0},get fallback(){return bh()},get children(){return S(ve,{get each(){return $r()},children:e=>S(Lh,{item:e})})}})),r})()}ke(["click"]);var Ih=E('<div style="padding:8px;border-bottom:1px solid #30363d;flex-shrink:0"><div style="padding:4px 8px;background:#161b22;border-radius:6px;border:1px solid #30363d"><div style=font-size:10px;font-weight:600;color:#8b949e;text-transform:uppercase;letter-spacing:0.04em;margin-bottom:4px> Room</div><div style=font-size:13px;font-weight:600;color:#c9d1d9></div><div style="display:grid;grid-template-columns:auto 1fr;row-gap:1px;margin-top:4px;font-size:11px"><div style="padding:3px 0;color:#8b949e">Shard</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Tick</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Tick duration</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Objects</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Owner</div><div style="padding:3px 0;color:#c9d1d9"></div></div><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px;color:#c9d1d9;cursor:pointer;margin-top:6px><span>Creep-Namen</span><input type=checkbox></label><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px;color:#c9d1d9;cursor:pointer;margin-top:4px><span>Room Visuals</span><input type=checkbox></label></div><div style=display:grid;gap:4px;margin-top:8px><button type=button title=History style="padding:5px 8px;border-radius:6px;display:flex;align-items:center;justify-content:center">'),Nh=E('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;display:flex;align-items:center;justify-content:center">');const Gh=[{mode:"view",label:"View",icon:()=>S(Ra,{size:14})},{mode:"flag",label:"Flag",icon:()=>S(Ls,{size:14})},{mode:"build",label:"Build",icon:()=>S(Ia,{size:14})}];function Dh(r){return(()=>{var e=Ih(),t=e.firstChild,i=t.firstChild,n=i.nextSibling,s=n.nextSibling,o=s.firstChild,l=o.nextSibling,a=l.nextSibling,c=a.nextSibling,d=c.nextSibling,h=d.nextSibling,f=h.nextSibling,u=f.nextSibling,p=u.nextSibling,w=p.nextSibling,C=s.nextSibling,g=C.firstChild,k=g.nextSibling,O=C.nextSibling,b=O.firstChild,v=b.nextSibling,T=t.nextSibling,P=T.firstChild;return y(n,()=>r.room),y(l,()=>r.shard??"—"),y(c,()=>Ie()??"—"),y(h,(()=>{var m=ie(()=>!!Jr());return()=>m()?`${Jr()}ms`:"—"})()),y(u,()=>tu()??"—"),y(w,()=>{var m;return((m=lo())==null?void 0:m.username)??"—"}),k.addEventListener("change",m=>Zs(m.currentTarget.checked)),v.addEventListener("change",m=>Xd(m.currentTarget.checked)),y(T,S(X,{get when(){return!He()},get children(){return S(ve,{each:Gh,children:m=>{const $=()=>!ue()&&Mt()===m.mode;return(()=>{var R=Nh();return R.$$click=()=>{ue()&&ni(),xt(m.mode)},y(R,()=>m.icon()),N(M=>{var I=m.label,L=`1px solid ${$()?"#58a6ff":"#30363d"}`,A=$()?"#1f6feb33":"#161b22",B=$()?"#c9d1d9":"#8b949e";return I!==M.e&&_e(R,"title",M.e=I),L!==M.t&&D(R,"border",M.t=L),A!==M.a&&D(R,"background",M.a=A),B!==M.o&&D(R,"color",M.o=B),M},{e:void 0,t:void 0,a:void 0,o:void 0}),R})()}})}}),P),P.$$click=()=>ue()?ni():Ie()!==null&&po(Ie()),y(P,S(Sa,{size:14})),N(m=>{var $=`repeat(${He()?2:4}, 1fr)`,R=!ue()&&Ie()===null,M=He()?"span 2":void 0,I=`1px solid ${ue()?"#58a6ff":"#30363d"}`,L=ue()?"#1f6feb33":"#161b22",A=ue()?"#c9d1d9":"#8b949e",B=!ue()&&Ie()===null?"not-allowed":"pointer",W=!ue()&&Ie()===null?.4:1;return $!==m.e&&D(T,"grid-template-columns",m.e=$),R!==m.t&&(P.disabled=m.t=R),M!==m.a&&D(P,"grid-column",m.a=M),I!==m.o&&D(P,"border",m.o=I),L!==m.i&&D(P,"background",m.i=L),A!==m.n&&D(P,"color",m.n=A),B!==m.s&&D(P,"cursor",m.s=B),W!==m.h&&D(P,"opacity",m.h=W),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}),N(()=>k.checked=ti()),N(()=>v.checked=to()),e})()}ke(["click"]);const[zh,Bh]=G("owner"),wo="screeps-terrain-v1";async function Hh(r,e,t){try{const i=await caches.open(wo),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 Fh(r,e,t,i){try{const n=await caches.open(wo),s=`/terrain/${r}_${e}_z${t}.webp`,o=new Request(s),l=new Response(i);await n.put(o,l)}catch{}}async function Wh(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 Uh(r){return await createImageBitmap(r)}function Xh(r){return new Worker("/assets/terrain.worker-D9zNeJfz.js",{name:r==null?void 0:r.name})}const{warn:Yh}=Et("MapRenderer"),xo=3,re=xo*50,qh=[50,60,70,80,90,100,110],ur=1,bt=.5,Br=50,jh=2600,Vh=5,Ai=.2,Ii=5,Zh=Rr,Kh=16777215,Jh=St,Qh=yr,ef=Gs,tf=vt,rf=4486980,nf=8921634,sf=new Set(["w","r","pb","p","s","c","m","k"]),of={H:13421772,O:13421772,U:5809919,L:4176208,K:10711543,Z:13801762,X:16273737},lf=[16,24,32,40];class Gp{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 zs);_(this,"lastCheckX",0);_(this,"lastCheckY",0);_(this,"lastCheckScale",0);this.app=new ys,this.callbacks=e,this.worker=new Xh,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:Wc,antialias:!1,preference:"webgl"}),this.resizeObserver=new ResizeObserver(s=>{const{width:o,height:l}=s[0].contentRect,a=this.app.screen.width,c=this.app.screen.height;this.app.renderer.resize(o,l),this.world.x+=(o-a)/2,this.world.y+=(l-c)/2}),this.resizeObserver.observe(t),this.world=new Pe,this.app.stage.addChild(this.world),this.boundsGraphics=new te,this.world.addChild(this.boundsGraphics),this.selectionGraphics=new te,this.world.addChild(this.selectionGraphics),this.safeModeGraphics=new te,this.world.addChild(this.safeModeGraphics),this.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(Ai,Math.min(Ii,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,h;const n=this.world.scale.x,s=this.getLOD(),o=this.zoom>=ur,l=this.zoom>=bt,a=(t-this.world.x)/n,c=(i-this.world.y)/n;this.world.scale.set(e),this.world.x=t-a*e,this.world.y=i-c*e,this.getLOD()!==s&&this.applyLOD(),(e>=ur!==o||e>=bt!==l)&&this.updateAllNameLabels(),this.updateAllRoomScales(e),(h=(d=this.callbacks).onZoomChanged)==null||h.call(d,e),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode()}centerOn(e,t,i=!1){const n=e*re+re/2,s=t*re+re/2,o=this.world.scale.x,l=this.app.screen.width/2-n*o,a=this.app.screen.height/2-s*o;i?(this.animTargetX=l,this.animTargetY=a,this.isAnimating=!0):(this.isAnimating=!1,this.world.x=l,this.world.y=a)}async getTerrainBitmap(e,t,i){const n=this.currentShard;try{const s=await Hh(n,e,t);if(s)return await Uh(s);const o=this.nextBakeId++,l=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 a=await l;return Wh(a).then(c=>{Fh(n,e,t,c)}).catch(c=>Yh("failed to save to terrainCache:",c)),a}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 l=await this.getTerrainBitmap(e,o,i);if(!l)return;if(!this.activeRooms.has(e)){l.close();return}const a=yt.from(l);o===0?(s.texLo&&!s.texLo.destroyed&&(s.terrainSprite.texture===s.texLo&&(s.terrainSprite.texture=yt.EMPTY),s.texLo.destroy(!0)),s.texLo=a,this.getLOD()===0&&(s.terrainSprite.texture=a)):(s.texHi&&!s.texHi.destroyed&&(s.terrainSprite.texture===s.texHi&&(s.terrainSprite.texture=yt.EMPTY),s.texHi.destroy(!0)),s.texHi=a,this.getLOD()===1&&(s.terrainSprite.texture=a)),s.terrainSprite.width=re,s.terrainSprite.height=re,this.terrainBaked.add(e)}getLOD(){return this.zoom<ur?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=yt.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=xo;n.clear();const o=t.r??[];for(const[p,w]of o)n.rect(p*s,w*s,s,s);o.length&&n.fill(xn);const l=t.w??[];for(const[p,w]of l)n.rect(p*s+.5,w*s+.5,s-1,s-1);l.length&&n.fill(e.ownerState==="other"?nf:rf);const a=t.s??[];for(const[p,w]of a)n.circle((p+.5)*s,(w+.5)*s,2.5);a.length&&n.fill(Zh);const c=t.c??[];for(const[p,w]of c)n.circle((p+.5)*s,(w+.5)*s,2);c.length&&n.fill(Kh);const d=t.m??[];for(const[p,w]of d)n.circle((p+.5)*s,(w+.5)*s,2);d.length&&n.fill(Jh);const h=t.k??[];for(const[p,w]of h)n.circle((p+.5)*s,(w+.5)*s,2);h.length&&n.fill(Qh);const f=t.pb??[];for(const[p,w]of f)n.circle((p+.5)*s,(w+.5)*s,1.5);f.length&&n.fill(yr);const u=t;for(const p in u){if(sf.has(p))continue;const w=u[p];if(!Array.isArray(w)||w.length===0)continue;for(const[g,k]of w)n.circle((g+.5)*s,(k+.5)*s,1);const C=p===this.currentUserId?ef:tf;n.fill(C)}}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,re,re),n.fill({color:10027008,alpha:.18})):t==="own"&&(n.rect(0,0,re,re),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 Vt(s);o.anchor.set(.5),o.x=re/2,o.y=re/2;const l=n.container.getChildIndex(n.nameLabel);n.container.addChildAt(o,l),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=(qh[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=of[t]??St;if(n.mineralDensity=i,n.mineralColor=s,!n.mineralCircle){const o=new te;o.x=re/2,o.y=re/2;const l=n.container.getChildIndex(n.nameLabel);n.container.addChildAt(o,l),n.mineralCircle=o}if(n.mineralLabel)n.mineralLabel.text=t;else{const o=new Yt({text:t,style:{fontSize:36,fill:16777215,fontFamily:"ui-monospace, monospace",fontWeight:"bold"}});o.anchor.set(.5),o.x=re/2,o.y=re/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=(lf[e.mineralDensity-1]??24)*i,s=n/2/t;e.mineralCircle.clear(),e.mineralCircle.circle(0,0,1),e.mineralCircle.fill(e.mineralColor);const l=2/t;e.mineralCircle.stroke({color:0,width:l/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=Qe(e);if(!t)return;const i=t.x*re,n=t.y*re;this.selectionGraphics.rect(i,n,re,re);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=Qe(t);if(!i)continue;const n=i.x*re,s=i.y*re;this.safeModeGraphics.rect(n,s,re,re),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*re,o=i*re,l=(t-e+1)*re,a=(n-i+1)*re;this.boundsGraphics.rect(s,o,l,a),this.boundsGraphics.stroke({color:Ns,width:6,alignment:0}),this.updateAllNameLabels()}clearBounds(){var e;this.worldBoundsSet=null,(e=this.boundsGraphics)==null||e.clear(),this.updateAllNameLabels()}setShowRoomNames(e){this.showRoomNames=e,this.updateAllNameLabels()}hasRoom(e){return this.terrainBaked.has(e)}markRoomFetched(e){this.terrainBaked.add(e)}clearRoom(e){const t=this.activeRooms.get(e);t&&(t.texLo&&!t.texLo.destroyed&&t.texLo.destroy(!0),t.texHi&&!t.texHi.destroyed&&t.texHi.destroy(!0),t.texLo=null,t.texHi=null,t.terrainSprite.texture=yt.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<jh?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=Qe(i);if(n&&n.x>=t.rxMin-Br&&n.x<=t.rxMax+Br&&n.y>=t.ryMin-Br&&n.y<=t.ryMax+Br)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=Qe(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 Pe;s.cullable=!0;const o=new Vt(yt.EMPTY),l=new te,a=new te;s.addChild(o),s.addChild(l),s.addChild(a);const c=new Yt({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:l,ownerOverlay:a,ownerState:"none",nameLabel:c}}return n.container.x=i.x*re,n.container.y=i.y*re,n.container.visible=!0,n.nameLabel.text=e,n.nameLabel.visible=this.showRoomNames&&this.zoom>=bt&&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>=bt;for(const[t,i]of this.activeRooms){if(!e){i.nameLabel.visible=!1;continue}const n=Qe(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()],l=e.getBoundingClientRect(),a=(o[0].x+o[1].x)/2-l.left,c=(o[0].y+o[1].y)/2-l.top,d=Math.hypot(o[1].x-o[0].x,o[1].y-o[0].y),h=Math.max(Ai,Math.min(Ii,this.pinchStartScale*(d/this.pinchStartDist))),f=this.getLOD(),u=this.zoom>=ur,p=this.zoom>=bt;this.world.scale.set(h),this.world.x=a-this.pinchPivotWorldX*h,this.world.y=c-this.pinchPivotWorldY*h,this.getLOD()!==f&&this.applyLOD(),(h>=ur!==u||h>=bt!==p)&&this.updateAllNameLabels(),this.updateAllRoomScales(h),(s=(n=this.callbacks).onZoomChanged)==null||s.call(n,h),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode();return}if(this.isDragging){const o=i.clientX-this.dragStartX,l=i.clientY-this.dragStartY;(Math.abs(o)>3||Math.abs(l)>3)&&(this.hasDragged=!0);const a=this.worldBoundsSet;if(a){const c=this.world.scale.x,d=50,h=d-(a.maxX+1)*re*c,f=this.app.screen.width-d-a.minX*re*c,u=d-(a.maxY+1)*re*c,p=this.app.screen.height-d-a.minY*re*c;this.world.x=this.rubberBand(this.dragWorldX+o,h,f),this.world.y=this.rubberBand(this.dragWorldY+l,u,p)}else this.world.x=this.dragWorldX+o,this.world.y=this.dragWorldY+l}}),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,l=(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=(l-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(Ai,Math.min(Ii,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 l=t-e;return t-(1-1/(l*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*re*t,l=this.world.x+(e.maxX+1)*re*t,a=this.world.y+e.minY*re*t,c=this.world.y+(e.maxY+1)*re*t;let d=this.world.x,h=this.world.y;l<s?d+=s-l:o>i-s&&(d-=o-(i-s)),c<s?h+=s-c:a>n-s&&(h-=a-(n-s)),(d!==this.world.x||h!==this.world.y)&&(this.animTargetX=d,this.animTargetY=h,this.isAnimating=!0)}screenToRoom(e,t){const i=this.world.scale.x,n=(e-this.world.x)/i,s=(t-this.world.y)/i,o=Math.floor(n/re),l=Math.floor(s/re);return Be(o,l)}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,l=(this.app.screen.height-i)/e,a=Math.floor(n/re)-1,c=Math.ceil(o/re),d=Math.floor(s/re)-1,h=Math.ceil(l/re);this.lastVisibleBounds={rxMin:a,rxMax:c,ryMin:d,ryMax:h};const f=[],u=this.worldBoundsSet,p=u?Math.max(a,u.minX):a,w=u?Math.min(c,u.maxX):c,C=u?Math.max(d,u.minY):d,g=u?Math.min(h,u.maxY):h;for(let O=p;O<=w;O++)for(let b=C;b<=g;b++){const v=Be(O,b);v&&f.push(v)}const k=`${a},${d},${c},${h}`;k!==this.lastVisibleKey&&(this.lastVisibleKey=k,this.visibleDebounceTimer!==null&&clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=setTimeout(()=>{this.visibleDebounceTimer=null,this.callbacks.onVisibleRoomsChanged(f)},Vh))}}var af=E('<div style="padding:8px;border-bottom:1px solid #30363d;flex-shrink:0"><div style="padding:4px 8px;background:#161b22;border-radius:6px;border:1px solid #30363d"><div style=font-size:10px;font-weight:600;color:#8b949e;text-transform:uppercase;letter-spacing:0.04em;margin-bottom:4px>Map</div><div style="display:grid;grid-template-columns:auto 1fr;row-gap:1px;font-size:11px;margin-bottom:8px"><div style="padding:3px 0;color:#8b949e">Zoom</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Live</div><div style="padding:3px 0;color:#c9d1d9"></div></div><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px><span>Show room names</span><input type=checkbox></label><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px;color:#c9d1d9;cursor:pointer;margin-top:4px><span>Show unclaimable rooms</span><input type=checkbox></label></div><div style="display:grid;grid-template-columns:repeat(3, 1fr);gap:4px;margin-top:8px">'),cf=E('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;font-size:11px;font-weight:600">');const df=[{mode:"owner",label:"Owner"},{mode:"mineral",label:"Mineral"},{mode:"none",label:"None"}];function uf(r){const e=()=>(r.zoom??1)>=bt;return(()=>{var t=af(),i=t.firstChild,n=i.firstChild,s=n.nextSibling,o=s.firstChild,l=o.nextSibling,a=l.nextSibling,c=a.nextSibling,d=s.nextSibling,h=d.firstChild,f=h.nextSibling,u=d.nextSibling,p=u.firstChild,w=p.nextSibling,C=i.nextSibling;return y(l,()=>{var g;return((g=r.zoom)==null?void 0:g.toFixed(2))??"—"}),y(c,()=>r.subsActive?"Yes":"No"),f.addEventListener("change",g=>Js(g.currentTarget.checked)),w.addEventListener("change",g=>eo(g.currentTarget.checked)),y(C,S(ve,{each:df,children:g=>{const k=()=>zh()===g.mode;return(()=>{var O=cf();return O.$$click=()=>Bh(g.mode),y(O,()=>g.label),N(b=>{var v=`1px solid ${k()?"#58a6ff":"#30363d"}`,T=k()?"#1f6feb33":"#161b22",P=k()?"#c9d1d9":"#8b949e";return v!==b.e&&D(O,"border",b.e=v),T!==b.t&&D(O,"background",b.t=T),P!==b.a&&D(O,"color",b.a=P),b},{e:void 0,t:void 0,a:void 0}),O})()}})),N(g=>{var k=e()?"#c9d1d9":"#484f58",O=e()?"pointer":"default",b=!e();return k!==g.e&&D(d,"color",g.e=k),O!==g.t&&D(d,"cursor",g.t=O),b!==g.a&&(f.disabled=g.a=b),g},{e:void 0,t:void 0,a:void 0}),N(()=>f.checked=Ks()),N(()=>w.checked=Qs()),t})()}ke(["click"]);var hf=E('<div style="margin:8px 8px 0;border-radius:6px;overflow:hidden"><div style="padding:4px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:10px;font-weight:600;color:#8b949e;text-transform:uppercase;letter-spacing:0.04em">'),ff=E('<div style="padding:6px 8px;font-size:11px;color:#484f58;font-style:italic">None'),pf=E('<div style="padding:3px 8px;color:#8b949e">Mineral'),gf=E('<div style="padding:3px 8px;color:#79c0ff">'),mf=E('<div style="padding:3px 8px;color:#8b949e">Density'),yf=E('<div style="padding:3px 8px;color:#c9d1d9">'),vf=E('<div style=font-size:11px><div style="padding:5px 8px;font-weight:600;color:#c9d1d9;font-size:12px;border-bottom:1px solid #21262d"></div><div style="display:grid;grid-template-columns:auto 1fr;row-gap:1px;column-gap:0"><div style="padding:3px 8px;color:#8b949e">Owner</div><div style="padding:3px 8px;color:#c9d1d9">');const bf=["Low","Medium","High","Ultra"];function wf(r){return bf[r-1]??String(r)}function as(r){return(()=>{var e=hf(),t=e.firstChild;return y(t,()=>r.label),y(e,S(X,{get when(){return r.info},get fallback(){return ff()},children:i=>(()=>{var n=vf(),s=n.firstChild,o=s.nextSibling,l=o.firstChild,a=l.nextSibling;return y(s,()=>i().room),y(a,()=>i().owner??"None"),y(o,S(X,{get when(){return i().mineral},get children(){return[pf(),(()=>{var c=gf();return y(c,()=>i().mineral),c})(),mf(),(()=>{var c=yf();return y(c,()=>wf(i().density??0)),c})()]}}),null),n})()}),null),N(i=>{var n=`1px solid ${r.dim?"#21262d":"#30363d"}`,s=r.dim?.6:1;return n!==i.e&&D(e,"border",i.e=n),s!==i.t&&D(e,"opacity",i.t=s),i},{e:void 0,t:void 0}),e})()}var xf=E("<span style=color:#8b949e;font-size:11px>Checking…"),_f=E('<div style=margin-top:8px><div style="padding:6px 8px;font-size:11px;font-weight:600;color:#c9d1d9;margin-bottom:6px">Your flags'),$f=E('<div style=flex:1;overflow:auto;min-height:0;padding:8px><div style="border-radius:6px;border:1px solid #30363d;overflow:hidden;background:#0d1117"><div style="padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:11px;font-weight:600;color:#c9d1d9">Create flag</div><div style=padding:8px;display:flex;flex-direction:column;gap:8px><label>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>'),Sf=E("<span style=color:#f85149;font-size:11px>"),kf=E("<div style=margin-top:8px;color:#484f58;font-style:italic;font-size:12px>No flags."),Cf=E('<div style="border-radius:6px;border:1px solid #30363d;margin-bottom:6px;overflow:hidden"><div style="display:flex;align-items:center;gap:7px;padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d"><div style=width:8px;height:8px;border-radius:50%;flex-shrink:0></div><span style=font-size:11px;font-weight:600;color:#c9d1d9;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap></span><span style=font-size:10px;color:#8b949e;flex-shrink:0></span><span style=font-size:10px;color:#484f58;flex-shrink:0;margin-left:4px>(<!>,<!>)');const{error:Tf}=Et("flag"),yn={};for(const[r,e]of Object.entries(Tr))yn[e]=r;function Mf(){const r=p=>{go({...Bt(),...p})},[e,t]=G(null),[i,n]=G(!1);let s=null;de(()=>{if(Mt()!=="flag"||Bt().name.trim()!=="")return;const p=ae();p&&p.http.game.genUniqueFlagName().then(w=>{r({name:w.name}),t(null)}).catch(w=>{Tf("gen unique name failed:",w)})});const o=p=>{r({name:p}),t(null),s&&clearTimeout(s);const w=p.trim();if(!w){n(!1);return}n(!0),s=setTimeout(()=>{const C=ae();if(!C){n(!1);return}C.http.game.checkUniqueFlagName(w).then(()=>{t(null)}).catch(g=>{t(g.message)}).finally(()=>{n(!1)})},300)},l=()=>Tr[Bt().color]??1,a=()=>Tr[Bt().secondaryColor]??1,c=p=>{r({color:yn[p]??"COLOR_WHITE"})},d=p=>{r({secondaryColor:yn[p]??"COLOR_WHITE"})},h=()=>{const p=jl(),w=[];for(const[C,g]of Object.entries(p))g&&typeof g=="object"&&"room"in g&&"x"in g&&"y"in g&&w.push([C,g]);return w},f=p=>p===void 0||p<0||p>=Ft.length?"#8b949e":`#${Ft[p].toString(16).padStart(6,"0")}`,u={display:"flex","flex-direction":"column",gap:"5px","font-size":"11px",color:"#8b949e"};return(()=>{var p=$f(),w=p.firstChild,C=w.firstChild,g=C.nextSibling,k=g.firstChild,O=k.firstChild,b=O.nextSibling,v=k.nextSibling;v.firstChild;var T=v.nextSibling;T.firstChild;var P=T.nextSibling;return b.$$input=m=>o(m.currentTarget.value),y(k,S(X,{get when(){return e()},children:m=>(()=>{var $=Sf();return y($,m),$})()}),null),y(k,S(X,{get when(){return i()},get children(){return xf()}}),null),y(v,S(li,{get value(){return l()},onChange:c}),null),y(T,S(li,{get value(){return a()},onChange:d}),null),y(P,(()=>{var m=ie(()=>!!kt());return()=>m()?`Marked at x=${kt().tx}, y=${kt().ty}. Click again to create the flag, or click elsewhere to move the mark.`:"Click a position in the room to mark it."})()),y(p,S(X,{get when(){return h().length>0},get fallback(){return kf()},get children(){var m=_f();return m.firstChild,y(m,S(ve,{get each(){return h()},children:([$,R])=>(()=>{var M=Cf(),I=M.firstChild,L=I.firstChild,A=L.nextSibling,B=A.nextSibling,W=B.nextSibling,K=W.firstChild,H=K.nextSibling,F=H.nextSibling,Y=F.nextSibling;return Y.nextSibling,y(A,$),y(B,()=>R.room),y(W,()=>R.x,H),y(W,()=>R.y,Y),N(z=>D(L,"background",f(R.color))),M})()}),null),m}}),null),N(m=>{var $=u,R=`1px solid ${e()?"#f85149":"#30363d"}`,M=u,I=u;return m.e=Z(k,$,m.e),R!==m.t&&D(b,"border",m.t=R),m.a=Z(v,M,m.a),m.o=Z(T,I,m.o),m},{e:void 0,t:void 0,a:void 0,o:void 0}),N(()=>b.value=Bt().name),p})()}ke(["input"]);var Ef=E("<span style=color:#8b949e>…"),Rf=E("<span style=color:#3fb950>✓"),Pf=E("<span style=color:#f85149>✗"),Of=E("<div style=font-size:10px;color:#f85149>"),Lf=E('<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>'),Af=E('<div style=flex:1;overflow:auto;min-height:0;padding:8px><div style="border-radius:6px;border:1px solid #30363d;overflow:hidden;background:#0d1117;margin-bottom:8px"><div style="padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:11px;font-weight:600;color:#c9d1d9">Controller Level </div><div style=padding:8px;font-size:11px;color:#8b949e></div></div><div style="border-radius:6px;border:1px solid #30363d;overflow:hidden;background:#0d1117"><div style="padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:11px;font-weight:600;color:#c9d1d9">Structures</div></div><div style="margin-top:8px;padding:0 4px"><div style=color:#484f58;font-style:italic;font-size:12px>'),If=E('<div style="padding:6px 8px;display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid #21262d;font-size:11px;color:#c9d1d9"><span style=text-transform:capitalize></span><span style=color:#8b949e>');function Nf(r){const e=Object.keys(oi),[t,i]=G("idle"),[n,s]=G("");let o=null;const l=(p,w)=>{const C=oi[p];return C?Tt()==="empty"&&p==="spawn"?Math.max(C[w]??0,1):C[w]??0:0},a=(p,w)=>{const C=l(p,w);if(C===2500)return 1/0;const g=ii()[p]??0;return Math.max(0,C-g)},c=()=>et().structureType==="spawn";de(Eo(()=>et().structureType,p=>{if(p!=="spawn")return;const w=ae();w&&(i("loading"),s(""),w.http.game.genUniqueObjectName("spawn",r.shard).then(C=>{_t({structureType:"spawn",structureName:C.name}),i("valid")}).catch(()=>{_t({structureType:"spawn",structureName:"Spawn1"}),i("idle")}))}));const d=p=>{if(o&&clearTimeout(o),!p.trim()){i("invalid"),s("Name cannot be empty");return}i("loading"),s(""),o=setTimeout(()=>{const w=ae();w&&w.http.game.checkUniqueObjectName("spawn",p.trim(),r.shard).then(C=>{C.error?(i("invalid"),s(C.error)):(i("valid"),s(""))}).catch(()=>{i("invalid"),s("Could not validate name")})},400)},h=p=>{_t({structureType:"spawn",structureName:p}),d(p)},f=p=>{_t({structureType:p,structureName:""}),i("idle"),s("")},u=()=>{switch(t()){case"loading":return Ef();case"valid":return Rf();case"invalid":return Pf();default:return null}};return(()=>{var p=Af(),w=p.firstChild,C=w.firstChild;C.firstChild;var g=C.nextSibling,k=w.nextSibling;k.firstChild;var O=k.nextSibling,b=O.firstChild;return y(C,()=>Xt()??"?",null),y(g,()=>{const v=Tt();return v==="empty"?"World is empty — place a spawn to claim this room.":v==="lost"?"You lost all your spawns — respawn to continue.":Xt()!=null?`RCL ${Xt()} — Select a structure type and click a tile to build.`:"No controller — roads and containers only."}),y(k,S(ve,{each:e,children:v=>{const T=()=>Xt()??0,P=()=>l(v,T()),m=()=>ii()[v]??0,$=()=>et().structureType===v,R=()=>P()===2500,M=()=>!R()&&a(v,T())<=0;return S(X,{get when(){return P()>0},get children(){var I=If(),L=I.firstChild,A=L.nextSibling;return I.$$click=()=>!M()&&f(v),y(L,()=>v.replace(/([A-Z])/g," $1").trim(),null),y(L,()=>$()&&" ✓",null),y(A,(()=>{var B=ie(()=>!!R());return()=>B()?`${m()}/∞`:`${m()}/${P()}`})(),null),y(A,()=>M()&&" (Max)",null),N(B=>{var W=$()?"#1f3158":"transparent",K=M()?"default":"pointer",H=M()?.5:1;return W!==B.e&&D(I,"background",B.e=W),K!==B.t&&D(I,"cursor",B.t=K),H!==B.a&&D(I,"opacity",B.a=H),B},{e:void 0,t:void 0,a:void 0}),I}})}}),null),y(p,S(X,{get when(){return c()},get children(){var v=Lf(),T=v.firstChild,P=T.nextSibling,m=P.firstChild,$=m.firstChild,R=$.nextSibling;return $.$$input=M=>h(M.currentTarget.value),y(R,u),y(P,S(X,{get when(){return ie(()=>t()==="invalid")()&&n()},get children(){var M=Of();return y(M,n),M}}),null),N(M=>D($,"border",`1px solid ${t()==="invalid"?"#f85149":t()==="valid"?"#238636":"#30363d"}`)),N(()=>$.value=et().structureName??""),v}}),O),y(b,()=>et().structureType?"Click a tile in the room to build.":"Select a structure type, then click a tile."),p})()}ke(["input","click"]);var Gf=E('<div style="padding:8px;border-bottom:1px solid #30363d;flex-shrink:0"><div style=display:flex;flex-direction:column;gap:6px><div style=font-size:11px><div></div><div style=font-size:10px;color:#484f58;margin-top:2px>~</div></div><div style=display:flex;gap:3px><button type=button style="flex:1.5;padding:4px;border-radius:4px;border:1px solid #30363d;font-size:11px"></button></div><div style=display:flex;align-items:center;gap:6px><span style=font-size:10px;color:#8b949e;white-space:nowrap>Speed</span><select style="flex:1;background:#161b22;color:#8b949e;border:1px solid #30363d;border-radius:4px;padding:3px 6px;font-size:11px;cursor:pointer">'),cs=E("<button type=button>"),Df=E("<option>/s");const zf=[.5,1,2,5,10,20],Bf=[{delta:-100,label:"-100"},{delta:-10,label:"-10"}],Hf=[{delta:10,label:"+10"},{delta:100,label:"+100"}];function ds(r){return{flex:"1",padding:"4px","border-radius":"4px",border:"1px solid #30363d",background:"#161b22",color:r?"#484f58":"#8b949e",cursor:r?"not-allowed":"pointer","font-size":"11px"}}function Ff(){const r=()=>{const e=Sr(),t=rt(),i=Jr()??3e3,n=(e-t)*i;return new Date(Date.now()-n).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})};return(()=>{var e=Gf(),t=e.firstChild,i=t.firstChild,n=i.firstChild,s=n.nextSibling;s.firstChild;var o=i.nextSibling,l=o.firstChild,a=o.nextSibling,c=a.firstChild,d=c.nextSibling;return y(n,(()=>{var h=ie(()=>!!Xe());return()=>h()?"Loading…":`Tick ${rt()}`})()),y(s,r,null),y(o,S(ve,{each:Bf,children:h=>(()=>{var f=cs();return f.$$click=()=>Qn(h.delta),y(f,()=>h.label),N(u=>{var p=Xe(),w=ds(Xe());return p!==u.e&&(f.disabled=u.e=p),u.t=Z(f,w,u.t),u},{e:void 0,t:void 0}),f})()}),l),ct(l,"click",su,!0),y(l,()=>br()?"⏸":"▶"),y(o,S(ve,{each:Hf,children:h=>(()=>{var f=cs();return f.$$click=()=>Qn(h.delta),y(f,()=>h.label),N(u=>{var p=Xe(),w=ds(Xe());return p!==u.e&&(f.disabled=u.e=p),u.t=Z(f,w,u.t),u},{e:void 0,t:void 0}),f})()}),null),d.addEventListener("change",h=>ou(parseFloat(h.currentTarget.value))),y(d,S(ve,{each:zf,children:h=>(()=>{var f=Df(),u=f.firstChild;return f.value=h,y(f,h,u),f})()})),N(h=>{var f=Xe()?"#f0883e":"#c9d1d9",u=Xe(),p=br()?"#1a3a2a":"#161b22",w=br()?"#3fb950":"#8b949e",C=Xe()?"not-allowed":"pointer";return f!==h.e&&D(n,"color",h.e=f),u!==h.t&&(l.disabled=h.t=u),p!==h.a&&D(l,"background",h.a=p),w!==h.o&&D(l,"color",h.o=w),C!==h.i&&D(l,"cursor",h.i=C),h},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),N(()=>d.value=Cn()),e})()}ke(["click"]);var Wf=E("<div style=padding-bottom:8px;overflow:auto;min-height:0>"),Uf=E('<div style=display:flex;flex-direction:row;height:100%;background:#0d1117><div style="width:32px;height:100%;display:flex;flex-direction:column;align-items:center;border-right:1px solid #30363d;padding:8px 0;cursor:pointer"></div><div style=flex:1;display:flex;flex-direction:column;overflow:hidden><div style="padding:6px 10px;border-bottom:1px solid #30363d;font-size:12px;font-weight:600;color:#8b949e;display:flex;justify-content:space-between;align-items:center"><span>Properties'),Xf=E("<button style=background:transparent;border:none;color:#8b949e;font-size:14px;cursor:pointer;padding:4px>"),Yf=E("<button style=background:transparent;border:none;color:#8b949e;font-size:11px;cursor:pointer>Collapse");function qf(r){return S(X,{get when(){return Mt()==="flag"},get fallback(){return S(X,{get when(){return Mt()==="build"},get fallback(){return S(Ah,{})},get children(){return S(Nf,{get shard(){return r.shard}})}})},get children(){return S(Mf,{})}})}function jf(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=Uf(),n=i.firstChild,s=n.nextSibling,o=s.firstChild;return o.firstChild,n.$$click=e,y(n,(()=>{var l=ie(()=>!!r.onToggle);return()=>l()&&(()=>{var a=Xf();return a.$$click=t,y(a,()=>r.isCollapsed?"▶":"◀"),a})()})()),y(o,(()=>{var l=ie(()=>!!r.onToggle);return()=>l()&&(()=>{var a=Yf();return a.$$click=t,a})()})(),null),y(s,S(X,{get when(){return r.mapMode},get fallback(){return S(Dh,{get room(){return r.room??"—"},get shard(){return r.shard??null}})},get children(){return S(uf,{get zoom(){return r.mapZoom},get subsActive(){return r.mapSubsActive}})}}),null),y(s,S(X,{get when(){return ie(()=>!r.mapMode)()&&ue()},get children(){return S(Ff,{})}}),null),y(s,S(X,{get when(){return r.mapMode},get fallback(){return S(qf,{get shard(){return r.shard}})},get children(){var l=Wf();return y(l,S(as,{label:"Selected",get info(){return r.selectedRoomInfo??null}}),null),y(l,S(as,{label:"Cursor",get info(){return r.hoveredRoomInfo??null},dim:!0}),null),l}}),null),i})()}ke(["click"]);var Vf=E("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>CPU:</span><span style=color:#c9d1d9>"),Zf=E("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Memory:</span><span style=color:#c9d1d9>"),Kf=E("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Zoom:</span><span style=color:#c9d1d9>%"),Jf=E("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Subs:</span><span>"),Qf=E('<div style="display:flex;gap:16px;padding:6px 16px;font-size:12px;color:#8b949e;align-items:center">');function ep(r){const[e,t]=G(null);Mr(()=>{const s=ae();if(!s)return;const o=new vn;o.add(s.stores.user.subscribe("cpu")),o.add(s.stores.user.on("user:cpu",l=>{t(l)})),Ge(()=>{o.dispose()})});const i=()=>{var l;const s=e();if(!s)return"—";const o=((l=Ne())==null?void 0:l.cpu)??"?";return`${s.cpu.toFixed(1)} / ${o}`},n=()=>{const s=e();return s?`${(s.memory/1024).toFixed(1)} KB`:"—"};return(()=>{var s=Qf();return y(s,S(X,{get when(){return e()!==null},get children(){return[(()=>{var o=Vf(),l=o.firstChild,a=l.nextSibling;return y(a,i),o})(),(()=>{var o=Zf(),l=o.firstChild,a=l.nextSibling;return y(a,n),o})()]}}),null),y(s,S(X,{get when(){return ie(()=>r.mapZoom!==null)()&&r.mapZoom!==void 0},get children(){return[(()=>{var o=Kf(),l=o.firstChild,a=l.nextSibling,c=a.firstChild;return y(a,()=>(r.mapZoom*100).toFixed(0),c),o})(),(()=>{var o=Jf(),l=o.firstChild,a=l.nextSibling;return y(a,()=>r.mapSubsActive===!1?"paused":"active"),N(c=>D(a,"color",r.mapSubsActive===!1?"#e3b341":"#3fb950")),o})()]}}),null),s})()}var tp=E('<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">'),rp=E("<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>"),ip=E('<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">'),np=E("<button style=width:100%;aspect-ratio:1;border-radius:2px;cursor:pointer;padding:0;outline:none>");const _o={};for(let r=1;r<=24;r++){const e=ci({type:r,color1:"#4a5060",color2:"#7a9ec0",color3:"#c0daf0",param:0,flip:!1});_o[r]=`data:image/svg+xml,${encodeURIComponent(e)}`}function mt(r){var e;return typeof r=="string"?r:((e=gr[r])==null?void 0:e.rgb)??"#000000"}function Hr(r){return typeof r=="number"?Math.max(0,Math.min(79,r)):r}const sp=[{slot:1,label:"Background"},{slot:2,label:"Primary"},{slot:3,label:"Secondary"}],op=Array.from({length:24},(r,e)=>e+1),Ni=/^#[0-9a-f]{6}$/i;function lp(r){const[e,t]=G(fe(()=>typeof r.badge.type=="number"?r.badge.type:1)),[i,n]=G(fe(()=>Hr(r.badge.color1))),[s,o]=G(fe(()=>Hr(r.badge.color2))),[l,a]=G(fe(()=>Hr(r.badge.color3))),[c,d]=G(fe(()=>r.badge.param??0)),[h,f]=G(fe(()=>r.badge.flip??!1)),[u,p]=G(1),[w,C]=G(!1),[g,k]=G(fe(()=>mt(Hr(r.badge.color1)))),O=M=>M===1?i():M===2?s():l(),b=M=>{const I=u();I===1?n(M):I===2?o(M):a(M)};de(()=>{k(mt(O(u())))});const v=M=>{var L;const I=O(u());return typeof I=="number"?I===M:I.toLowerCase()===(((L=gr[M])==null?void 0:L.rgb)??"").toLowerCase()},T=()=>({type:e(),color1:mt(i()),color2:mt(s()),color3:mt(l()),param:c(),flip:h()}),P=wr(()=>{const M=ci(T());return`data:image/svg+xml,${encodeURIComponent(M)}`}),m=M=>{if(k(M),!Ni.test(M))return;const I=gr.findIndex(L=>L.rgb.toLowerCase()===M.toLowerCase());b(I>=0?I:M)},$=async()=>{var I;const M=ae();if(M){C(!0);try{await M.http.user.badge(T()),await M.stores.user.refreshMe(),r.onClose(),(I=r.onSaved)==null||I.call(r),ye("Badge saved","success",3e3)}catch(L){ye(`Failed to save badge: ${L instanceof Error?L.message:String(L)}`,"error",5e3)}finally{C(!1)}}},R=M=>{M.target===M.currentTarget&&r.onClose()};return(()=>{var M=tp(),I=M.firstChild,L=I.firstChild,A=L.firstChild,B=A.nextSibling,W=L.nextSibling,K=W.firstChild,H=K.firstChild,F=H.firstChild,Y=F.nextSibling,z=H.nextSibling,U=z.firstChild,Q=U.nextSibling,J=K.nextSibling,V=J.firstChild,he=V.nextSibling,Oe=he.nextSibling,it=Oe.nextSibling,De=it.firstChild,We=De.nextSibling,nt=J.nextSibling,Le=nt.firstChild,oe=Le.firstChild,Me=oe.nextSibling,pt=Le.nextSibling,Pr=nt.nextSibling,tr=Pr.firstChild,se=W.nextSibling,ne=se.firstChild,ce=ne.nextSibling;return M.$$click=R,B.$$click=()=>r.onClose(),y(B,S(hi,{size:18})),y(Q,S(ve,{each:op,children:q=>(()=>{var j=rp(),ee=j.firstChild;return j.$$click=()=>t(q),N(pe=>{var ge=e()===q?"#1f3a2a":"#0d1117",ze=`1px solid ${e()===q?"#238636":"#21262d"}`,st=e()===q?P():_o[q];return ge!==pe.e&&D(j,"background",pe.e=ge),ze!==pe.t&&D(j,"border",pe.t=ze),st!==pe.a&&_e(ee,"src",pe.a=st),pe},{e:void 0,t:void 0,a:void 0}),j})()})),y(he,S(ve,{each:sp,children:({slot:q,label:j})=>(()=>{var ee=ip(),pe=ee.firstChild;return ee.$$click=()=>p(q),y(ee,j,null),N(ge=>{var ze=`1px solid ${u()===q?"#58a6ff":"#30363d"}`,st=u()===q?"#1c2d47":"transparent",rr=u()===q?"#58a6ff":"#8b949e",ir=mt(O(q));return ze!==ge.e&&D(ee,"border",ge.e=ze),st!==ge.t&&D(ee,"background",ge.t=st),rr!==ge.a&&D(ee,"color",ge.a=rr),ir!==ge.o&&D(pe,"background",ge.o=ir),ge},{e:void 0,t:void 0,a:void 0,o:void 0}),ee})()})),y(Oe,S(ve,{each:gr,children:q=>(()=>{var j=np();return j.$$click=()=>b(q.index),N(ee=>{var pe=q.rgb,ge=q.rgb,ze=v(q.index)?"2px solid #fff":"1px solid transparent";return pe!==ee.e&&_e(j,"title",ee.e=pe),ge!==ee.t&&D(j,"background",ee.t=ge),ze!==ee.a&&D(j,"border",ee.a=ze),ee},{e:void 0,t:void 0,a:void 0}),j})()})),We.$$input=q=>m(q.currentTarget.value),y(Me,c),pt.$$input=q=>d(+q.currentTarget.value),tr.addEventListener("change",q=>f(q.currentTarget.checked)),ne.$$click=()=>r.onClose(),ce.$$click=$,y(ce,()=>w()?"Saving…":"Save Badge"),N(q=>{var j=P(),ee=Ni.test(g())?g():mt(O(u())),pe=`1px solid ${Ni.test(g())?"#30363d":"#f85149"}`,ge=w(),ze=w()?"not-allowed":"pointer",st=w(),rr=w()?"not-allowed":"pointer",ir=w()?.7:1;return j!==q.e&&_e(Y,"src",q.e=j),ee!==q.t&&D(De,"background",q.t=ee),pe!==q.a&&D(We,"border",q.a=pe),ge!==q.o&&(ne.disabled=q.o=ge),ze!==q.i&&D(ne,"cursor",q.i=ze),st!==q.n&&(ce.disabled=q.n=st),rr!==q.s&&D(ce,"cursor",q.s=rr),ir!==q.h&&D(ce,"opacity",q.h=ir),q},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0}),N(()=>We.value=g()),N(()=>pt.value=c()),N(()=>tr.checked=h()),M})()}ke(["click","input"]);var ap=E('<div style="display:flex;align-items:center;justify-content:space-between;padding:10px 0;border-bottom:1px solid #21262d"><div><div style=font-size:13px;color:#c9d1d9></div></div><button style="flex-shrink:0;margin-left:24px;width:40px;height:20px;border-radius:10px;border:none;cursor:pointer;position:relative;transition:background 0.15s"><div style="position:absolute;top:2px;width:16px;height:16px;border-radius:50%;background:#fff;transition:left 0.15s">'),cp=E("<div style=font-size:11px;color:#8b949e;margin-top:3px>"),dp=E("<div style=margin-bottom:24px><div style=font-size:10px;font-weight:700;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:4px>"),up=E('<div style="display:flex;align-items:center;justify-content:space-between;gap:24px;padding:10px 0;border-bottom:1px solid #21262d"><div style=font-size:13px;color:#c9d1d9></div><div style=font-size:12px;color:#8b949e;text-align:right>'),hp=E("<img width=40 height=40 style=display:block>"),fp=E('<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">'),pp=E('<div style="display:flex;align-items:center;justify-content:space-between;padding:10px 0;border-bottom:1px solid #21262d"><div><div style=font-size:13px;color:#c9d1d9>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">'),gp=E('<div style="position:absolute;inset:0px;background:rgba(13, 17, 23, 0.96);z-index:100;display:flex;flex-direction:column;overflow:hidden"><div style="display:flex;align-items:center;justify-content:space-between;padding:14px 24px;border-bottom:1px solid #30363d;flex-shrink:0"><span style=font-size:15px;font-weight:600;color:#c9d1d9>Settings</span><button style="background:transparent;border:none;color:#8b949e;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 mp={type:1,color1:"#4a5060",color2:"#7a9ec0",color3:"#c0daf0",param:0,flip:!1};function hr(r){return(()=>{var e=ap(),t=e.firstChild,i=t.firstChild,n=t.nextSibling,s=n.firstChild;return y(i,()=>r.label),y(t,(()=>{var o=ie(()=>!!r.description);return()=>o()&&(()=>{var l=cp();return y(l,()=>r.description),l})()})(),null),n.$$click=()=>r.onChange(!r.value),N(o=>{var l=r.value?"#238636":"#30363d",a=r.value?"22px":"2px";return l!==o.e&&D(n,"background",o.e=l),a!==o.t&&D(s,"left",o.t=a),o},{e:void 0,t:void 0}),e})()}function Nt(r){return(()=>{var e=dp(),t=e.firstChild;return y(t,()=>r.title),y(e,()=>r.children,null),e})()}function us(r){return(()=>{var e=up(),t=e.firstChild,i=t.nextSibling;return y(t,()=>r.label),y(i,()=>r.value),e})()}function yp(r){var c;const e=Wl(),t=!He()&&!((c=Ne())!=null&&c.badge),[i,n]=G(t),[s,o]=G(!1),l=wr(()=>{var f;const d=(f=Ne())==null?void 0:f.badge;if(!d)return null;const h=ci(d);return`data:image/svg+xml,${encodeURIComponent(h)}`});async function a(){o(!0);try{await ql(),ye("All caches cleared. Reloading…","success",2e3),setTimeout(()=>window.location.reload(),1500)}catch{ye("Failed to clear caches.","error"),o(!1)}}return(()=>{var d=gp(),h=d.firstChild,f=h.firstChild,u=f.nextSibling,p=h.nextSibling,w=p.firstChild;return u.$$click=()=>r.onClose(),y(u,S(hi,{size:18})),y(d,S(X,{get when(){return i()},get children(){return S(lp,{get badge(){var C;return((C=Ne())==null?void 0:C.badge)??mp},onClose:()=>n(!1),onSaved:t?()=>r.onClose():void 0})}}),p),y(w,S(Nt,{title:"Layout",get children(){return S(hr,{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 Vs()},onChange:Wd})}}),null),y(w,S(Nt,{title:"Room View",get children(){return[S(hr,{label:"Show creep labels",description:"Display each creep's name above its sprite.",get value(){return ti()},onChange:Zs}),S(hr,{label:"Terrain effects",description:"Swamp glow and wall noise texture overlay.",get value(){return Zr()},onChange:Ud})]}}),null),y(w,S(Nt,{title:"Map View",get children(){return[S(hr,{label:"Show room names",description:"Render a small room name in the top-left corner of each map tile.",get value(){return Ks()},onChange:Js}),S(hr,{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 Qs()},onChange:eo})]}}),null),y(w,S(X,{get when(){return!He()},get children(){return S(Nt,{title:"Player Badge",get children(){var C=fp(),g=C.firstChild,k=g.firstChild,O=g.nextSibling;return y(g,S(X,{get when(){return l()},get children(){var b=hp();return N(()=>_e(b,"src",l())),b}}),k),y(k,()=>{var b;return((b=Ne())==null?void 0:b.username)??""}),O.$$click=()=>n(!0),y(O,()=>l()?"Edit Badge":"Create Badge"),C}})}}),null),y(w,S(Nt,{title:"Data",get children(){var C=pp(),g=C.firstChild,k=g.firstChild;k.nextSibling;var O=g.nextSibling;return O.$$click=a,y(O,()=>s()?"Clearing…":"Clear"),N(b=>{var v=s(),T=s()?"#8b949e":"#f85149",P=s()?"default":"pointer",m=s()?.6:1;return v!==b.e&&(O.disabled=b.e=v),T!==b.t&&D(O,"color",b.t=T),P!==b.a&&D(O,"cursor",b.a=P),m!==b.o&&D(O,"opacity",b.o=m),b},{e:void 0,t:void 0,a:void 0,o:void 0}),C}}),null),y(w,S(Nt,{title:"About",get children(){return[S(us,{label:"Client version",get value(){return Fl()}}),ie(()=>e&&S(us,{label:"Mod version",get value(){return`${e.version} (${e.kind})`}}))]}}),null),d})()}ke(["click"]);var vp=E('<button style="padding:7px;border-radius:4px;cursor:pointer;margin:0 4px;display:flex;align-items:center">'),bp=E('<button style="padding:7px;border-radius:4px;border:1px solid #30363d;background:#21262d;margin:0 2px;display:flex;align-items:center">'),wp=E("<div style=flex:1;position:relative;overflow:hidden>"),xp=E('<div style="border-top:1px solid #30363d;overflow:hidden;position:relative"><div style=position:absolute;top:0;left:0;width:100%;height:4px;cursor:row-resize;z-index:10;background:#21262d>'),_p=E('<div style="border-left:1px solid #30363d;overflow:hidden;position:relative"><div style=position:absolute;top:0;left:0;width:4px;height:100%;cursor:col-resize;z-index:10;background:#21262d>'),$p=E("<div style=display:flex;flex:1;overflow:hidden><div style=display:flex;flex-direction:column;flex:1;overflow:hidden>"),Sp=E('<div style=width:100%;height:100%;display:flex;flex-direction:column;overflow:hidden;background:#0d1117><div style="display:flex;border-bottom:1px solid #30363d;align-items:center"><div style=flex:1></div><button 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">'),kp=E("<div style=display:flex;flex-direction:column;flex:1;overflow:hidden><div style=display:flex;flex:1;overflow:hidden>");const Cp=ms(()=>bs(()=>import("./CodePanel-BXBo2h-F.js"),__vite__mapDeps([0,1,2])).then(r=>({default:r.CodePanel}))),Tp=ms(()=>bs(()=>import("./MapViewer-YLclqH-L.js"),__vite__mapDeps([3,1,2])).then(r=>({default:r.MapViewer})));function Gi(){const r=ui(),e=window.location.pathname.match(new RegExp(`^${r}/room/([A-Za-z0-9]+)`));if(!e)return{room:null,shard:null,tick:null};const t=e[1].toUpperCase();if(!Qe(t))return{room:null,shard:null,tick:null};const i=new URLSearchParams(window.location.search).get("shard"),n=window.location.hash.match(/tick=(\d+)/),s=n?parseInt(n[1],10):null;return{room:t,shard:i,tick:s}}function Di(r,e){return`${ui()}/room/${r}${e?`?shard=${encodeURIComponent(e)}`:""}`}function hs(r){return`${ui()}/map${r?`?shard=${encodeURIComponent(r)}`:""}`}function zi(){return window.location.pathname.startsWith(`${ui()}/map`)?{shard:new URLSearchParams(window.location.search).get("shard")}:null}function Bi(r){return(()=>{var e=vp();return e.$$click=()=>r.onClick(),y(e,()=>r.children),N(t=>{var i=r.title,n=`1px solid ${r.active?"#388bfd":"#30363d"}`,s=r.active?"#1f3158":"#21262d",o=r.active?"#58a6ff":"#c9d1d9";return i!==t.e&&_e(e,"title",t.e=i),n!==t.t&&D(e,"border",t.t=n),s!==t.a&&D(e,"background",t.a=s),o!==t.o&&D(e,"color",t.o=o),t},{e:void 0,t:void 0,a:void 0,o:void 0}),e})()}function fs(r){return(()=>{var e=bp();return e.$$click=()=>r.onClick(),y(e,()=>r.children),N(t=>{var i=r.title,n=r.disabled,s=r.disabled?"#484f58":"#c9d1d9",o=r.disabled?"default":"pointer";return i!==t.e&&_e(e,"title",t.e=i),n!==t.t&&(e.disabled=t.t=n),s!==t.a&&D(e,"color",t.a=s),o!==t.o&&D(e,"cursor",t.o=o),t},{e:void 0,t:void 0,a:void 0,o:void 0}),e})()}function Mp(){var tr;const r=Gi(),[e,t]=G(r.room??yi(me.room)??"W1N1"),[i,n]=G(r.shard??yi(me.shard)),[s,o]=G(zi()!==null||!r.room),[l,a]=G(!He()&&!((tr=Ne())!=null&&tr.badge)),[c,d]=G(!1),[h,f]=G(!1);de(()=>{c(),f(!0),Promise.resolve().then(()=>f(!1))}),de(()=>{He()&&xt("view")});const[u,p]=G(void 0),[w,C]=G(null),[g,k]=G(null),O=yi(me.mapZoom),[b,v]=G(r.room&&O?Number(O):null),[T,P]=G(null),[m,$]=G(!1),[R,M]=G(!1);let I=r.tick;de(()=>{const se=Ie();if(se===null||I===null)return;const ne=I;I=null,po(se),si(ne)}),de(()=>{if(s())return;const se=Di(e(),i());ue()?history.replaceState(null,"",`${se}#tick=${rt()}`):history.replaceState(null,"",se)});const[L,A]=G(Or(me.sidebarWidth,300)),[B,W]=G(Or(me.sidebarWidth,300)),[K,H]=G(Or(me.consoleHeight,220)),[F,Y]=G(Or(me.consoleHeight,220)),[z,U]=G(!1),[Q,J]=G(!1),V=()=>L()<=32,he=()=>K()<=32,Oe=()=>{L()>32?(W(L()),A(32)):A(B())},it=()=>{K()>32?(Y(K()),H(32)):H(F())},De=se=>{se.preventDefault(),U(!0);const ne=se.clientX,ce=L(),q=ee=>{const pe=ee.clientX-ne;A(Math.max(32,Math.min(500,ce-pe)))},j=()=>{U(!1),vi(me.sidebarWidth,L()),window.removeEventListener("pointermove",q),window.removeEventListener("pointerup",j)};window.addEventListener("pointermove",q),window.addEventListener("pointerup",j)},We=se=>{se.preventDefault(),J(!0);const ne=se.clientY,ce=K(),q=ee=>{const pe=ee.clientY-ne;H(Math.max(32,Math.min(500,ce-pe)))},j=()=>{J(!1),vi(me.consoleHeight,K()),window.removeEventListener("pointermove",q),window.removeEventListener("pointerup",j)};window.addEventListener("pointermove",q),window.addEventListener("pointerup",j)},nt=(se,ne)=>{var ce;(ce=ae())==null||ce.stores.navigation.navigateTo(se,ne)},Le=se=>{p(se),o(!0),history.pushState(null,"",hs(i()))},oe=()=>{s()?(o(!1),C(null),k(null),history.pushState(null,"",Di(e(),i()))):Le(e())};Mr(()=>{var q;!Gi().room&&!zi()&&history.replaceState(null,"",hs(i()));const se=()=>{const j=zi();if(j){o(!0),j.shard!==null&&n(j.shard),fe(ue)&&ni();return}const{room:ee,shard:pe,tick:ge}=Gi();ee&&(t(ee),n(pe),o(!1),ge!==null?I=ge:fe(ue)&&ni())};window.addEventListener("popstate",se),Ge(()=>window.removeEventListener("popstate",se));const ne=(q=ae())==null?void 0:q.stores.navigation;if(ne){const j=ne.on("navigation:change",ee=>{ee.room!==null&&(t(ee.room),n(ee.shard),o(!1),C(null),k(null),$(ne.canBack()),M(ne.canForward()),Nn(me.room,ee.room),ee.shard?Nn(me.shard,ee.shard):Ul(me.shard),history.pushState(null,"",Di(ee.room,ee.shard)))});Ge(()=>j.dispose())}const ce=j=>{if(!co(j.target)){if(j.key==="o"||j.key==="O"){d(ee=>!ee),a(!1);return}(j.key==="l"||j.key==="L")&&mo(),(j.key==="c"||j.key==="C")&&yo(),(j.key==="y"||j.key==="Y")&&vo(),s()||(j.key==="1"&&xt("view"),He()||(j.key==="2"&&xt("flag"),j.key==="3"&&xt("build")),j.key==="m"&&Le(e()))}};window.addEventListener("keydown",ce),Ge(()=>window.removeEventListener("keydown",ce))});const Me=()=>(()=>{var se=wp();return y(se,S(X,{get when(){return l()},get children(){return S(yp,{onClose:()=>a(!1)})}}),null),y(se,S(X,{get when(){return c()},get children(){return S(Cp,{onClose:()=>d(!1)})}}),null),y(se,S(X,{get when(){return!s()},get fallback(){return S(Tp,{get shard(){return i()},get originRoom(){return u()},get initialZoom(){return b()??void 0},onNavigateToRoom:ne=>nt(ne,i()),onHoveredRoomChanged:C,onSelectedRoomChanged:k,onZoomChanged:ne=>{v(ne),vi(me.mapZoom,ne)},onSubscriptionStateChanged:P})},get children(){return S(wu,{get room(){return e()},get shard(){return i()},onNavigate:nt})}}),null),se})(),pt=()=>S(X,{get when(){return!He()},get children(){var se=xp(),ne=se.firstChild;return ne.$$pointerdown=We,y(se,S(Du,{get shard(){return i()},get isCollapsed(){return he()},onToggle:it}),null),N(ce=>{var q=`${K()}px`,j=Q()?"none":"height 0.15s ease";return q!==ce.e&&D(se,"height",ce.e=q),j!==ce.t&&D(se,"transition",ce.t=j),ce},{e:void 0,t:void 0}),se}}),Pr=se=>(()=>{var ne=_p(),ce=ne.firstChild;return ce.$$pointerdown=De,y(ne,S(jf,{get isCollapsed(){return V()},onToggle:Oe,get mapMode(){return s()},get hoveredRoomInfo(){return w()},get selectedRoomInfo(){return g()},get room(){return e()},get shard(){return i()},get mapZoom(){return b()},get mapSubsActive(){return T()}}),null),N(q=>{var j=c()?"0":`${L()}px`,ee=se&&!(h()||z())?"width 0.15s ease":"none";return j!==q.e&&D(ne,"width",q.e=j),ee!==q.t&&D(ne,"transition",q.t=ee),q},{e:void 0,t:void 0}),ne})();return(()=>{var se=Sp(),ne=se.firstChild,ce=ne.firstChild,q=ce.nextSibling;return y(ne,S(Gc,{}),ce),y(ne,S(X,{get when(){return!He()||s()},get children(){return S(ep,{get mapZoom(){return ie(()=>!!s())()?b():null},get mapSubsActive(){return ie(()=>!!s())()?T():null}})}}),ce),y(ne,S(fs,{title:"Back",get disabled(){return!m()},onClick:()=>{var j;return(j=ae())==null?void 0:j.stores.navigation.back()},get children(){return S(xa,{size:16})}}),q),y(ne,S(fs,{title:"Forward",get disabled(){return!R()},onClick:()=>{var j;return(j=ae())==null?void 0:j.stores.navigation.forward()},get children(){return S(va,{size:16})}}),q),y(ne,S(Bi,{get title(){return s()?"Room View":"Map"},get active(){return s()},onClick:oe,get children(){return ie(()=>!!s())()?S(Da,{size:16}):S(Ua,{size:16})}}),q),y(ne,S(Bi,{title:"Code Editor",get active(){return c()},onClick:()=>{d(j=>!j),a(!1)},get children(){return S(Ta,{size:16})}}),q),y(ne,S(Bi,{title:"Settings",get active(){return l()},onClick:()=>{a(j=>!j),d(!1)},get children(){return S(rc,{size:16})}}),q),ct(q,"click",ea,!0),y(q,S(Ha,{size:16})),y(se,S(X,{get when(){return Vs()},get fallback(){return(()=>{var j=kp(),ee=j.firstChild;return y(ee,Me,null),y(ee,()=>Pr(!0),null),y(j,pt,null),j})()},get children(){var j=$p(),ee=j.firstChild;return y(ee,Me,null),y(ee,pt,null),y(j,()=>Pr(!1),null),j}}),null),y(se,S($u,{}),null),se})()}ke(["click","pointerdown"]);var Ep=E("<div style=width:100%;height:100%>");function Rp(){const r=new URLSearchParams(window.location.search).get("guest");return r===null?null:r.startsWith("http")?r:Fr(Re.url)??"https://screeps.com"}function Pp(){const r=()=>$t()==="connected"&&ae()!==null;return Mr(async()=>{if($t()==="idle"&&(await Ql().catch(()=>{}),$t()!=="connected"&&!di())){const e=Rp();e&&wt({url:e,auth:"guest",storage:null}).catch(()=>{})}}),(()=>{var e=Ep();return y(e,(()=>{var t=ie(()=>!!r());return()=>t()?S(Mp,{}):S(Ac,{})})()),e})()}const $o=document.getElementById("root");if(!$o)throw new Error("Root element not found");Uo(()=>S(Pp,{}),$o);export{Gp as M,ye as a,Et as b,ae as c,ke as d,Ip as e,Be as f,Np as g,hn as h,y as i,Rs as j,Ks as k,Qs as l,zh as m,ru as n,Ne as o,Qe as p,D as s,E as t,pr as u,bi as w};
|