screeps-client 0.13.1 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/embedded/_client/CodePanel-7NohyDV6.js +1 -0
  2. package/dist/embedded/_client/{MapRenderer-Ba9hdALR.js → MapRenderer-BuhWaUfG.js} +2 -2
  3. package/dist/embedded/_client/MapViewer-DS8BhHNY.js +1 -0
  4. package/dist/embedded/_client/clientStore-arNZaq85.js +2 -0
  5. package/dist/embedded/_client/dist-js-CNTp3ssl.js +1 -0
  6. package/dist/embedded/_client/index-OIg48RYH.js +18 -0
  7. package/dist/embedded/_client/src-C7OP3M2f.js +1 -0
  8. package/dist/embedded/_client/src-JUwOmHaV.js +2 -0
  9. package/dist/embedded/index.html +4 -4
  10. package/dist/standalone/_client/CodePanel-Bnx6yEOR.js +1 -0
  11. package/dist/standalone/_client/{MapRenderer-CssWw9Rx.js → MapRenderer-DMPg8WXJ.js} +2 -2
  12. package/dist/standalone/_client/MapViewer-DaIbuKvz.js +1 -0
  13. package/dist/standalone/_client/clientStore-_HtNkRuX.js +2 -0
  14. package/dist/standalone/_client/dist-js-CNTp3ssl.js +1 -0
  15. package/dist/standalone/_client/index-CWis1qJt.js +18 -0
  16. package/dist/standalone/_client/src-B4JTNv2e.js +2 -0
  17. package/dist/standalone/_client/src-DuWuK5VM.js +1 -0
  18. package/dist/standalone/index.html +4 -4
  19. package/dist/xxscreeps-mod/_client/CodePanel-BjhdXK6-.js +1 -0
  20. package/dist/xxscreeps-mod/_client/{MapRenderer-Dv9Z0-8a.js → MapRenderer-D27u9j9v.js} +2 -2
  21. package/dist/xxscreeps-mod/_client/MapViewer-DoIBPjP7.js +1 -0
  22. package/dist/xxscreeps-mod/_client/clientStore-DkbarCgD.js +2 -0
  23. package/dist/xxscreeps-mod/_client/dist-js-CNTp3ssl.js +1 -0
  24. package/dist/xxscreeps-mod/_client/index-C0IyNcFE.js +18 -0
  25. package/dist/xxscreeps-mod/_client/src-Cfev0JqA.js +2 -0
  26. package/dist/xxscreeps-mod/_client/src-Cyk4KYvY.js +1 -0
  27. package/dist/xxscreeps-mod/index.html +4 -4
  28. package/package.json +1 -1
  29. package/dist/embedded/_client/CodePanel-D0uNCoEg.js +0 -1
  30. package/dist/embedded/_client/MapViewer-bnDa7ywa.js +0 -1
  31. package/dist/embedded/_client/clientStore-X6p73rOf.js +0 -2
  32. package/dist/embedded/_client/index-CNP0F5K4.js +0 -18
  33. package/dist/embedded/_client/src-C_QJ_OPN.js +0 -1
  34. package/dist/embedded/_client/src-DncdLdQu.js +0 -2
  35. package/dist/standalone/_client/CodePanel-BgI_oizo.js +0 -1
  36. package/dist/standalone/_client/MapViewer-BYWSoClB.js +0 -1
  37. package/dist/standalone/_client/clientStore-DyM1Zzi0.js +0 -2
  38. package/dist/standalone/_client/index-Bg71156Y.js +0 -18
  39. package/dist/standalone/_client/src-CW9qO3i6.js +0 -1
  40. package/dist/standalone/_client/src-D6b4QinV.js +0 -2
  41. package/dist/xxscreeps-mod/_client/CodePanel-BoFVhT99.js +0 -1
  42. package/dist/xxscreeps-mod/_client/MapViewer-Cqe2t4CZ.js +0 -1
  43. package/dist/xxscreeps-mod/_client/clientStore-CEftQs13.js +0 -2
  44. package/dist/xxscreeps-mod/_client/index-2AK4X3eW.js +0 -18
  45. package/dist/xxscreeps-mod/_client/src-CMxciU1t.js +0 -2
  46. package/dist/xxscreeps-mod/_client/src-DBC49Pqo.js +0 -1
@@ -0,0 +1 @@
1
+ import{S as e,_ as t,a as n,d as r,g as i,i as a,n as o,o as s,p as c,r as l,t as u,y as d}from"./vendor-codemirror-B6f_i0wP.js";import{$ as f,G as p,Q as m,R as h,n as g,ot as _,rt as v,st as y}from"./clientStore-arNZaq85.js";var b=_(`<span style=font-size:11px;color:#e3b341>Unsaved changes`),x=_(`<div style="padding:12px 10px;font-size:12px;color:#484f58;font-style:italic">Loading…`),S=_(`<div style=flex:1;display:flex;align-items:center;justify-content:center;color:#484f58;font-size:13px;font-style:italic>`),C=_(`<div style=position:absolute;inset:0px;background:#0d1117;z-index:100;display:flex;flex-direction:column;overflow:hidden><div style="display:flex;align-items:center;gap:12px;padding:10px 16px;border-bottom:1px solid #30363d;flex-shrink:0"><span style=font-size:15px;font-weight:600;color:#c9d1d9>Code</span><select style="background:#010409;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:4px 8px;font-size:12px;cursor:pointer"></select><div style=flex:1></div><button style="padding:5px 14px;border-radius:4px;border:1px solid #238636;font-size:12px;font-weight:600"></button><button style="background:transparent;border:none;color:#8b949e;font-size:18px;cursor:pointer;line-height:1;padding:2px 6px">✕</button></div><div style=flex:1;display:flex;overflow:hidden><div style="width:180px;flex-shrink:0;border-right:1px solid #21262d;display:flex;flex-direction:column;overflow:hidden"><div style="padding:6px 10px;font-size:10px;font-weight:700;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;border-bottom:1px solid #21262d;flex-shrink:0">Modules</div><div style=flex:1;overflow:auto></div></div><div style=flex:1;display:flex;flex-direction:column;overflow:hidden><div style="padding:5px 14px;font-size:12px;color:#8b949e;border-bottom:1px solid #21262d;flex-shrink:0;font-family:monospace;background:#0d1117">.js</div><div style=flex:1;overflow:hidden;flex-direction:column>`),w=_(`<option>`),T=_(`<div style="padding:7px 12px;font-size:12px;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis">`),{error:E}=h(`code`),D=s.theme({"&":{height:`100%`},".cm-scroller":{"font-family":`'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace`,"font-size":`13px`,"line-height":`1.6`,overflow:`auto`},".cm-gutters":{background:`#0d1117`,"border-right":`1px solid #21262d`},".cm-lineNumbers .cm-gutterElement":{color:`#484f58`,"min-width":`3em`},".cm-activeLineGutter":{background:`#161b22`},".cm-activeLine":{background:`#161b22`}}),O=[l,o(),u,D];function k(o){let[s,l]=e([]),[u,m]=e(``),[h,_]=e({}),[D,k]=e(``),[A,j]=e(!1),[M,N]=e(!1),[P,F]=e(!1),I=()=>Object.keys(h()),{editorView:L,ref:R,createExtension:z}=n({onValueChange:e=>{let t=D();!t||h()[t]===e||(_(n=>({...n,[t]:e})),F(!0))}});a(L,()=>h()[D()]??``),z(O),t(()=>{let e=g();e&&e.http.user.branches().then(e=>{l(e.list);let t=e.list.find(e=>e.activeWorld)??e.list[0];t&&m(t.branch)}).catch(e=>{E(`branches failed:`,e),p(`Failed to load branches`,`error`)})}),t(()=>{let e=u(),t=g();!e||!t||(j(!0),_({}),k(``),F(!1),t.http.user.code.get(e).then(e=>{let t=e.modules??{};_(t),k(Object.keys(t)[0]??``)}).catch(e=>{E(`get failed:`,e),p(`Failed to load code`,`error`)}).finally(()=>j(!1)))});let B=()=>{let e=g(),t=u();!e||!t||(N(!0),e.http.user.code.set(t,h()).then(()=>{p(`Code saved`,`success`),F(!1)}).catch(e=>{E(`set failed:`,e),p(`Failed to save code`,`error`)}).finally(()=>N(!1)))};return(()=>{var e=C(),t=e.firstChild,n=t.firstChild.nextSibling,a=n.nextSibling.nextSibling,l=a.nextSibling,p=t.nextSibling.firstChild,h=p.firstChild.nextSibling,g=p.nextSibling,_=g.firstChild,E=_.firstChild,O=_.nextSibling;return n.addEventListener(`change`,e=>m(e.currentTarget.value)),f(n,i(r,{get each(){return s()},children:e=>(()=>{var t=w();return f(t,()=>e.branch,null),f(t,()=>e.activeWorld?` ★`:``,null),d(()=>t.value=e.branch),t})()})),f(t,i(c,{get when(){return P()},get children(){return b()}}),a),a.$$click=B,f(a,()=>M()?`Saving…`:`Save`),l.$$click=()=>o.onClose(),f(h,i(c,{get when(){return A()},get children(){return x()}}),null),f(h,i(r,{get each(){return I()},children:e=>(()=>{var t=T();return t.$$click=()=>k(e),f(t,e),d(n=>{var r=D()===e?`#1f3158`:`transparent`,i=D()===e?`#58a6ff`:`#c9d1d9`,a=`2px solid ${D()===e?`#388bfd`:`transparent`}`;return r!==n.e&&v(t,`background`,n.e=r),i!==n.t&&v(t,`color`,n.t=i),a!==n.a&&v(t,`border-left`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),null),f(_,D,E),y(R,O),f(g,i(c,{get when(){return!D()},get children(){var e=S();return f(e,()=>A()?`Loading code…`:`Select a module`),e}}),null),d(e=>{var t=M()||A()||!P(),n=M()||!P()?`#161b22`:`#1a3a2a`,r=M()||!P()?`#484f58`:`#3fb950`,i=M()||!P()?`default`:`pointer`,o=D()?`block`:`none`,s=D()?`flex`:`none`;return t!==e.e&&(a.disabled=e.e=t),n!==e.t&&v(a,`background`,e.t=n),r!==e.a&&v(a,`color`,e.a=r),i!==e.o&&v(a,`cursor`,e.o=i),o!==e.i&&v(_,`display`,e.i=o),s!==e.n&&v(O,`display`,e.n=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),d(()=>n.value=u()),e})()}m([`click`]);export{k as CodePanel};
@@ -1,2 +1,2 @@
1
- import{D as e,S as t}from"./vendor-codemirror-B6f_i0wP.js";import{F as n,I as r,L as i,w as a}from"./clientStore-X6p73rOf.js";import{_ as o,f as s,g as c,h as l,l as u,o as d,s as f,v as p}from"./vendor-pixi-QLQyXP3g.js";import{t as m}from"./src-DncdLdQu.js";var h=856343,g=1448738,_=1843496,ee=3421243,te=h,v=7039337,ne=3159613,re=1579032,ie=2631720,ae=2632986,oe=2500383,se=2771488,ce={tough:5000268,move:11122630,work:16770413,carry:7829367,attack:16332866,ranged_attack:6127794,heal:6684002,claim:12164347},y=5809919,b=7979263,x=4176208,S=9147550,C=13801762,le=10711543,ue=16218298,w=16273737,T=15763518,de=2172461,fe=v,pe=13226457,me=12283502,he=[16777215,16711680,8388736,255,65535,32768,16776960,16753920,10824234,8421504,16777215],ge={creep:T,spawn:y,extension:b,tower:x,container:S,storage:C,link:le,rampart:y,road:fe,constructedWall:de,extractor:S,lab:ue,terminal:C,observer:b,powerSpawn:T,nuker:w,factory:S,invaderCore:w,source:C,mineral:b,deposit:C,controller:y,powerBank:T,portal:le},E=16771195,_e=E,ve=b,ye=E,be=b,xe=E,Se=E,Ce=w,we=x,Te=b,Ee=16777215,De=9419667,Oe=7245682,ke=12116924,Ae=12283502,je=9787480,Me=14721184,Ne=_,Pe=13684944,Fe=4067858,Ie=14440008,Le=11940394,Re=1579032,ze=5592405,Be=11184810,Ve=9419667,D=16771195,O=16069959,He=7105644,Ue={energy:D,power:O,H:13421772,O:16777215,U:5822457,L:62626,K:10514943,Z:16631694,X:11568379,G:16777215},We={biomass:8695826,metal:9793372,mist:14314485,silicon:5023717},Ge=5617743,Ke=9099642,qe=11680314,Je=14049376;function Ye(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>t(r),r.onerror=n,r.src=e})}var k=class{cache=new Map;pending=new Map;getKey(e){return JSON.stringify(e)}has(e){return this.cache.has(this.getKey(e))}getOrCreate(e){let t=this.getKey(e),n=this.cache.get(t);if(n)return Promise.resolve(n);let r=this.pending.get(t);if(r)return r;let i=this.buildTexture(e,t);return this.pending.set(t,i),i.then(()=>{this.pending.delete(t)}).catch(()=>{this.pending.delete(t)}),i}async buildTexture(e,t){let n=m(e),r=new Blob([n],{type:`image/svg+xml;charset=utf-8`}),i=URL.createObjectURL(r);try{let e=window.devicePixelRatio||1,n=128*Math.max(2,e),r=await Ye(i),a=document.createElement(`canvas`);a.width=n,a.height=n,a.getContext(`2d`).drawImage(r,0,0,n,n);let o=p.from(a);return this.cache.set(t,o),o}finally{URL.revokeObjectURL(i)}}destroy(){for(let e of this.cache.values())e.destroyed||e.destroy(!0);this.cache.clear(),this.pending.clear()}};function A(e,n){let r=localStorage.getItem(e),[i,a]=t(r===null?n:r===`true`);return[i,t=>{a(t),localStorage.setItem(e,String(t))}]}function Xe(e,n){let[r,i]=t(localStorage.getItem(e)??n);return[r,t=>{i(t),localStorage.setItem(e,t)}]}var[Ze,Qe]=A(a.widescreenMode,!0),[$e,et]=A(a.showCreepLabels,!0),[tt,nt]=A(a.showMapRoomNames,!1),[rt,it]=A(a.showUnclaimableRooms,!0),[at,ot]=A(a.terrainEffects,!0),[st,ct]=A(a.showRoomDecorations,!1),[lt,ut]=A(a.roomDarkOverlay,!0),[dt,ft]=A(a.showRoomVisuals,!0),[pt,mt]=Xe(a.spriteTheme,`default`),[ht,gt]=A(a.showMapVisuals,!0),j=i(),_t=j?`?v=${encodeURIComponent(j)}`:``,M={id:`default`,name:`Default`,atlasUrl:`${r()}/themes/default/sprite-0.json${_t}`,sprites:{storage:{layers:[{frame:`storage/shell`,tint:`owner`},{frame:`storage/fill`}],tileScale:1.75}},controller:{backgroundFrame:`controller/background`,segmentFrame:`controller/segment`,tileScale:2},flag:{mainFrame:`flag/main`,secondFrame:`flag/second`,tileScale:3,zIndex:5},tombstone:{shellFrame:`grave/shell`,crossFrame:`grave/cross`,tileScale:1,zIndex:4},deposit:{tileScale:1.2},mineral:{tileScale:2.6},tower:{ringFrame:`tower/ring`,bodyFrame:`tower/body`,tileScale:2.5,fill:{x:-39,yMin:-25,width:78,heightMax:58,rx:12,ry:12}}},vt=class{cache=new Map;pending=new Map;frames=new Map;getOrLoad(e){let t=this.cache.get(e);if(t)return Promise.resolve(t);let n=this.pending.get(e);if(n)return n;let r=s.load(e).then(t=>(this.cache.set(e,t),this.frames.set(e,yt(t)),this.pending.delete(e),t)).catch(t=>{throw this.pending.delete(e),t});return this.pending.set(e,r),r}getTexture(e,t){return this.frames.get(e)?.[t]}destroy(){for(let[,e]of this.cache){for(let t of e.linkedSheets??[])t.destroy(!0);e.destroy(!0)}this.cache.clear(),this.frames.clear(),this.pending.clear()}};function yt(e){let t={...e.textures};for(let n of e.linkedSheets??[])Object.assign(t,n.textures);return t}var N=new vt;function bt(e,t,n){return isNaN(n.minX)||isNaN(n.maxX)||isNaN(n.minY)||isNaN(n.maxY)?!0:e>=n.minX&&e<=n.maxX&&t>=n.minY&&t<=n.maxY}function P(e){let t=e.match(/^([WE])(\d+)([NS])(\d+)$/);if(!t)return null;let[,n,r,i,a]=t;return{x:n===`W`?-(parseInt(r,10)+1):parseInt(r,10),y:i===`N`?-(parseInt(a,10)+1):parseInt(a,10)}}function F(e,t){let n=e<0?`W`:`E`,r=t<0?`N`:`S`;return`${n}${e<0?-e-1:e}${r}${t<0?-t-1:t}`}function xt(e){return e===0||e<0&&(e+1)%10==0||e>0&&e%10==0}function St(e,t){return xt(e)||xt(t)}function Ct(e,t){let n=e<0?Math.abs(e+1)%10:Math.abs(e)%10,r=t<0?Math.abs(t+1)%10:Math.abs(t)%10;return n>=4&&n<=6&&r>=4&&r<=6}function wt(e){let t=e;if(!t)return!1;let n=t.tagName??``;return n===`INPUT`||n===`TEXTAREA`?!0:t.isContentEditable===!0}function Tt(t){let n=e=>{if(wt(e.target))return;let n=t.currentRoom(),r=n?P(n):null;if(!r)return;let i=t.worldBounds(),a=(e,t)=>!i||bt(e,t,i);switch(e.key){case`ArrowLeft`:e.preventDefault(),a(r.x-1,r.y)&&t.onMove(r.x-1,r.y);break;case`ArrowRight`:e.preventDefault(),a(r.x+1,r.y)&&t.onMove(r.x+1,r.y);break;case`ArrowUp`:e.preventDefault(),a(r.x,r.y-1)&&t.onMove(r.x,r.y-1);break;case`ArrowDown`:e.preventDefault(),a(r.x,r.y+1)&&t.onMove(r.x,r.y+1);break}};window.addEventListener(`keydown`,n),e(()=>window.removeEventListener(`keydown`,n))}var[Et,Dt]=t(`owner`),I=3,Ot=I*50,L=4;function R(e,t,n){let r=P(e);return r?[r.x*Ot+t*I,r.y*Ot+n*I]:null}var z=3*I,B=2.5*I,V=1*I,H=2*I;function U(e,t,n,r){let i=!0,a=n;for(let o=0;o<t.length-1;o++){let[s,c]=t[o],[l,u]=t[o+1],d=l-s,f=u-c,p=Math.sqrt(d*d+f*f);if(p<.001)continue;let m=d/p,h=f/p,g=0;for(;g<p;){let t=Math.min(a,p-g);if(i){let n=s+m*g,r=c+h*g;e.moveTo(n,r),e.lineTo(n+m*t,r+h*t)}g+=t,a-=t,a<.001&&(i=!i,a=i?n:r)}}}function kt(e,t,n){let r=Math.max(32,Math.ceil(2*Math.PI*n/2)),i=[];for(let a=0;a<=r;a++){let o=a/r*2*Math.PI;i.push([e+Math.cos(o)*n,t+Math.sin(o)*n])}return i}var At=class{container;g;constructor(){this.container=new o,this.container.label=`mapVisuals`,this.g=new u,this.container.addChild(this.g)}update(e){let t=this.container.removeChildren();for(let e of t)e!==this.g&&e.destroy();if(this.g.clear(),this.container.addChild(this.g),!e)return;let n=this.g;for(let t of e.split(`
2
- `)){if(!t.trim())continue;let e;try{e=JSON.parse(t)}catch{continue}let r=e.s??{},i=r.opacity??.5;switch(e.t){case`l`:this.drawLine(n,e,r,i);break;case`c`:this.drawCircle(n,e,r,i);break;case`r`:this.drawRect(n,e,r,i);break;case`p`:this.drawPoly(n,e,r,i);break;case`t`:this.drawText(e,r,i);break}}}clear(){let e=this.container.removeChildren();for(let t of e)t!==this.g&&t.destroy();this.g.clear(),this.container.addChild(this.g)}drawLine(e,t,n,r){let i=R(t.n1,t.x1,t.y1),a=R(t.n2,t.x2,t.y2);if(!i||!a)return;let o=n.color??`#ffffff`,s=(n.width??.5)*I;n.lineStyle===`dashed`?U(e,[i,a],z*(n.width??.5),B*(n.width??.5)):n.lineStyle===`dotted`?U(e,[i,a],V*(n.width??.5),H*(n.width??.5)):(e.moveTo(i[0],i[1]),e.lineTo(a[0],a[1])),e.stroke({color:o,width:s,alpha:r})}drawCircle(e,t,n,r){let i=R(t.n,t.x,t.y);if(!i)return;let[a,o]=i,s=(n.radius??10)*I,c=!!(n.fill&&n.fill!==`transparent`),l=!!(n.stroke&&n.strokeWidth),u=(n.strokeWidth??.5)*I;c&&(e.circle(a,o,s),e.fill({color:n.fill,alpha:r})),l&&(n.lineStyle===`dashed`?U(e,kt(a,o,s),z*(n.strokeWidth??.5),B*(n.strokeWidth??.5)):n.lineStyle===`dotted`?U(e,kt(a,o,s),V*(n.strokeWidth??.5),H*(n.strokeWidth??.5)):e.circle(a,o,s),e.stroke({color:n.stroke,width:u,alpha:r}))}drawRect(e,t,n,r){let i=R(t.n,t.x,t.y),a=R(t.n,t.x+t.w,t.y),o=R(t.n,t.x+t.w,t.y+t.h),s=R(t.n,t.x,t.y+t.h);if(!i||!a||!o||!s)return;let c=!!(n.fill&&n.fill!==`transparent`),l=!!(n.stroke&&n.strokeWidth),u=[i,a,o,s,i],d=u.flatMap(e=>e),f=(n.strokeWidth??.5)*I;c&&(e.poly(d.slice(0,8),!0),e.fill({color:n.fill,alpha:r})),l&&(n.lineStyle===`dashed`?U(e,u,z*(n.strokeWidth??.5),B*(n.strokeWidth??.5)):n.lineStyle===`dotted`?U(e,u,V*(n.strokeWidth??.5),H*(n.strokeWidth??.5)):e.poly(d.slice(0,8),!0),e.stroke({color:n.stroke,width:f,alpha:r}))}drawPoly(e,t,n,r){if(!t.points||t.points.length===0)return;let i=!!(n.fill&&n.fill!==`transparent`),a=!!(n.stroke&&n.strokeWidth);if(!i&&!a)return;let o=[];for(let{n:e,x:n,y:r}of t.points){let t=R(e,n,r);if(!t)return;o.push(t)}let s=o.flatMap(e=>e),c=(n.strokeWidth??.5)*I;if(i&&(e.poly(s,!0),e.fill({color:n.fill,alpha:r})),a){if(n.lineStyle===`dashed`){let t=o[0],r=o[o.length-1];U(e,t[0]===r[0]&&t[1]===r[1]?o:[...o,t],z*(n.strokeWidth??.5),B*(n.strokeWidth??.5))}else if(n.lineStyle===`dotted`){let t=o[0],r=o[o.length-1];U(e,t[0]===r[0]&&t[1]===r[1]?o:[...o,t],V*(n.strokeWidth??.5),H*(n.strokeWidth??.5))}else e.poly(s,!0);e.stroke({color:n.stroke,width:c,alpha:r})}}drawText(e,t,n){let r=R(e.n,e.x,e.y);if(!r)return;let[i,a]=r,o=t.fontSize??10,s=t.fontFamily??`sans-serif`,c=o*I,l=t.align??`center`,p=new f({fill:t.color??`#ffffff`,fontSize:c*L,fontFamily:s,align:l,...t.fontStyle?{fontStyle:t.fontStyle}:{},...t.fontVariant?{fontVariant:t.fontVariant}:{},...t.stroke&&t.strokeWidth?{stroke:{color:t.stroke,width:t.strokeWidth*I*L}}:{}});if(t.backgroundColor&&t.backgroundColor!==`transparent`){let r=(t.backgroundPadding??2)*I,o=new d({text:e.text,style:p});o.scale.set(1/L);let s=o.width,c=o.height;o.destroy();let f=i-(l===`center`?.5:+(l===`right`))*s-r,m=a-c/2-r,h=new u;h.rect(f,m,s+r*2,c+r*2),h.fill({color:t.backgroundColor,alpha:n}),this.container.addChild(h)}let m=new d({text:e.text,style:p});m.scale.set(1/L),m.anchor.x=l===`center`?.5:+(l===`right`),m.anchor.y=.5,m.position.set(i,a),m.alpha=n,this.container.addChild(m)}destroy(){let e=this.container.removeChildren();for(let t of e)t!==this.g&&t.destroy();this.g.destroy(),this.container.destroy()}},{warn:jt}=n(`terrainCache`),Mt=`screeps-terrain-v1`;async function Nt(e,t,n){try{let r=await caches.open(Mt),i=`/terrain/${e}_${t}_z${n}.webp`,a=new Request(i),o=await r.match(a);if(o){let e=await o.arrayBuffer(),t=o.headers.get(`Content-Type`)??`image/webp`;return new Blob([e],{type:t})}}catch(e){jt(`get failed:`,e)}return null}async function Pt(e,t,n,r){try{let i=await caches.open(Mt),a=`/terrain/${e}_${t}_z${n}.webp`,o=new Request(a),s=new Response(r);await i.put(o,s)}catch(e){jt(`save failed:`,e)}}var W=null;async function Ft(e){if(W!==!1)try{let t=await createImageBitmap(e);return W=!0,t}catch(e){if(W===!0)throw e;W=!1}let t=URL.createObjectURL(e);try{let e=new Image;return e.src=t,await e.decode(),await createImageBitmap(e)}finally{URL.revokeObjectURL(t)}}function It(e){return new Worker(`/client/_client/terrain.worker-t5M0-yfM.js`,{name:e?.name})}var Lt=2962235,Rt=856343,zt=4020797,Bt=v,G=4486980,Vt=8921634,Ht=x,Ut=me,Wt=[{key:`s`,color:E,radius:2.5},{key:`c`,color:16777215,radius:2},{key:`m`,color:b,radius:2},{key:`k`,color:T,radius:2},{key:`pb`,color:16720418,radius:2.5},{key:`d`,color:16777215,radius:2.5}],Gt=new Set([`w`,`r`,`pb`,`p`,`s`,`c`,`m`,`k`,`d`]);function Kt(e){return`#`+e.toString(16).padStart(6,`0`)}var{warn:K}=n(`MapRenderer`),q=3,J=q*50,qt=[50,60,70,80,90,100,105,120],Y=1,X=.5,Z=50,Jt=2600,Yt=5,Q=.2,$=5,Xt=[80,104,128,160],Zt=class{app;world;boundsGraphics=null;selectionGraphics=null;safeModeGraphics=null;mapVisualLayer=null;safeModeRooms=new Set;activeRooms=new Map;roomPool=[];terrainBaked=new Set;terrainData=new Map;statsApplied=new Set;roomDecorations=new Map;showDecorations=!0;worker;pendingBakes=new Map;nextBakeId=0;currentShard=`shard0`;callbacks;resizeObserver=null;_destroyed=!1;showRoomNames=!1;worldBoundsSet=null;lastVisibleBounds=null;animTargetX=0;animTargetY=0;isAnimating=!1;overlayMode=`owner`;showUnclaimableOverlay=!0;isDragging=!1;hasDragged=!1;dragStartX=0;dragStartY=0;dragWorldX=0;dragWorldY=0;isPinching=!1;pinchPivotWorldX=0;pinchPivotWorldY=0;pinchStartDist=0;pinchStartScale=0;lastVisibleKey=``;visibleDebounceTimer=null;selectedRoom=null;currentUserId=null;badgeCache=new k;constructor(e){this.app=new l,this.callbacks=e,this.worker=new It,this.worker.onmessage=e=>{let t=e.data;if(t.kind===`cache`){Pt(t.shard,t.roomName,t.lod,new Blob([t.cacheBytes],{type:t.cacheType||`image/webp`}));return}let n=this.pendingBakes.get(t.id);n&&(this.pendingBakes.delete(t.id),n.resolve(t.bitmap))}}async init(e){let t=e.parentElement??e,{width:n,height:r}=t.getBoundingClientRect();await this.app.init({canvas:e,width:n,height:r,background:te,antialias:!1,preference:`webgl`}),this.resizeObserver=new ResizeObserver(e=>{let{width:t,height:n}=e[0].contentRect,r=this.app.screen.width,i=this.app.screen.height;this.app.renderer.resize(t,n),this.world.x+=(t-r)/2,this.world.y+=(n-i)/2}),this.resizeObserver.observe(t),this.world=new o,this.app.stage.addChild(this.world),this.boundsGraphics=new u,this.world.addChild(this.boundsGraphics),this.selectionGraphics=new u,this.world.addChild(this.selectionGraphics),this.safeModeGraphics=new u,this.world.addChild(this.safeModeGraphics),this.mapVisualLayer=new At,this.world.addChild(this.mapVisualLayer.container),this.setupInteraction(),this.app.ticker.add(()=>{if(this.isAnimating){let e=this.animTargetX-this.world.x,t=this.animTargetY-this.world.y;Math.abs(e)<.5&&Math.abs(t)<.5?(this.world.x=this.animTargetX,this.world.y=this.animTargetY,this.isAnimating=!1):(this.world.x+=e*.2,this.world.y+=t*.2)}this.checkVisibleRooms()})}get zoom(){return this.world?.scale.x??1}setZoom(e){if(!this.world||(e=Math.max(Q,Math.min($,e)),e===this.world.scale.x))return;let t=this.app.screen.width/2,n=this.app.screen.height/2;this.applyZoomAt(e,t,n)}applyZoomAt(e,t,n){let r=this.world.scale.x,i=this.getLOD(),a=this.zoom>=Y,o=this.zoom>=X,s=(t-this.world.x)/r,c=(n-this.world.y)/r;this.world.scale.set(e),this.world.x=t-s*e,this.world.y=n-c*e,this.getLOD()!==i&&this.applyLOD(),(e>=Y!==a||e>=.5!==o)&&this.updateAllNameLabels(),this.updateAllRoomScales(e),this.callbacks.onZoomChanged?.(e),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode()}centerOn(e,t,n=!1){let r=e*J+J/2,i=t*J+J/2,a=this.world.scale.x,o=this.app.screen.width/2-r*a,s=this.app.screen.height/2-i*a;n?(this.animTargetX=o,this.animTargetY=s,this.isAnimating=!0):(this.isAnimating=!1,this.world.x=o,this.world.y=s)}async getTerrainBitmap(e,t,n,r){let i=this.currentShard;try{if(!r){let n=await Nt(i,e,t);if(n)return await Ft(n)}let a=this.nextBakeId++,o=new Promise((n,r)=>{this.pendingBakes.set(a,{roomName:e,lod:t,resolve:n,reject:r})});return this.worker.postMessage({id:a,roomName:e,lod:t,raw:n,shard:i,colors:r}),await o}catch(e){return K(`error getting terrain bitmap:`,e),null}}async setRoomTerrain(e,t){let n=t.raw,r=!1;for(let e=0;e<n.length;e++)if(n[e]!==0){r=!0;break}if(!r){this.terrainBaked.add(e);return}let i=this.getOrCreate(e),a=this.getLOD();this.terrainData.set(e,n);let o=await this.getTerrainBitmap(e,a,n);if(!o)return;if(!this.activeRooms.has(e)){o.close();return}let s=p.from(o);a===0?(i.texLo&&!i.texLo.destroyed&&(i.terrainSprite.texture===i.texLo&&(i.terrainSprite.texture=p.EMPTY),i.texLo.destroy(!0)),i.texLo=s):(i.texHi&&!i.texHi.destroyed&&(i.terrainSprite.texture===i.texHi&&(i.terrainSprite.texture=p.EMPTY),i.texHi.destroy(!0)),i.texHi=s),i.terrainSprite.width=J,i.terrainSprite.height=J,this.terrainBaked.add(e),this.ensureCurrentLod(e,i),this.revealIfReady(e,i)}getLOD(){return this.zoom<Y?0:1}ensureCurrentLod(e,t){let n=this.getLOD()===1,r=n?t.texHi:t.texLo;if(r&&!r.destroyed){t.terrainSprite.texture=r;return}let i=this.terrainData.get(e);if(!i)return;let a=this.showDecorations?this.roomDecorations.get(e):void 0;return this.getTerrainBitmap(e,+!!n,i,a).then(r=>{if(!r)return;if(!this.activeRooms.has(e)){r.close();return}let i=p.from(r);n?t.texHi=i:t.texLo=i,this.getLOD()===1===n&&(t.terrainSprite.texture=i)})}async applyLOD(){let e=[];for(let[t,n]of this.activeRooms){if(!this.terrainBaked.has(t))continue;let r=this.ensureCurrentLod(t,n);r&&e.push(r)}await Promise.all(e)}setRoomMap2(e,t,n=`live`){let r=this.getOrCreate(e);r.lastMap2Data=t,r.lastMap2Source=n,this.drawMap2(r,t,n)}drawMap2(e,t,n){let r=e.map2Graphics;r.alpha=n===`cache`?.6:1;let i=q;r.clear();let a=t.r??[];for(let[e,t]of a)r.rect(e*i,t*i,i,i);a.length&&r.fill(Bt);let o=t.w??[];for(let[e,t]of o)r.rect(e*i+.5,t*i+.5,i-1,i-1);o.length&&r.fill(e.ownerState===`other`||e.ownerState===`prohibited`?Vt:G);for(let e of Wt){let n=t[e.key]??[];for(let[t,a]of n)r.circle((t+.5)*i,(a+.5)*i,e.radius);n.length&&r.fill(e.color)}let s=t;for(let e in s){if(Gt.has(e))continue;let t=s[e];if(!Array.isArray(t)||t.length===0)continue;for(let[e,n]of t)r.circle((e+.5)*i,(n+.5)*i,1);let n=e===this.currentUserId?Ht:Ut;r.fill(n)}}clearRoomMap2(e){this.activeRooms.get(e)?.map2Graphics.clear()}clearAllMap2(){for(let e of this.activeRooms.values())e.map2Graphics.clear()}setRoomOwned(e,t){let n=this.activeRooms.get(e);if(!n)return;this.statsApplied.add(e),n.ownerState!==t&&(n.ownerState=t,n.lastMap2Data&&this.drawMap2(n,n.lastMap2Data,n.lastMap2Source??`live`));let r=n.ownerOverlay;r.clear(),t===`prohibited`?(r.rect(0,0,J,J),r.fill({color:0,alpha:.5})):t===`other`?(r.rect(0,0,J,J),r.fill({color:10027008,alpha:.18})):t===`own`&&(r.rect(0,0,J,J),r.fill({color:102,alpha:.35})),r.visible=t===`prohibited`||this.showUnclaimableOverlay,this.revealIfReady(e,n)}setUnclaimableOverlayVisible(e){if(this.showUnclaimableOverlay!==e){this.showUnclaimableOverlay=e;for(let t of this.activeRooms.values())t.ownerOverlay.visible=t.ownerState===`prohibited`||e}}revealIfReady(e,t){this.terrainBaked.has(e)&&this.statsApplied.has(e)&&(t.container.visible=!0)}setRoomDecoration(e,t){let n=this.roomDecorations.get(e);(t?JSON.stringify(t):``)!==(n?JSON.stringify(n):``)&&(t?this.roomDecorations.set(e,t):this.roomDecorations.delete(e),this.rebakeRoom(e))}setDecorationsVisible(e){if(this.showDecorations!==e){this.showDecorations=e;for(let e of this.roomDecorations.keys())this.rebakeRoom(e)}}rebakeRoom(e){let t=this.activeRooms.get(e);if(t){for(let e of[`texLo`,`texHi`]){let n=t[e];n&&!n.destroyed&&(t.terrainSprite.texture===n&&(t.terrainSprite.texture=p.EMPTY),n.destroy(!0),t[e]=null)}this.ensureCurrentLod(e,t)}}async setRoomBadge(e,t,n){let r=this.activeRooms.get(e);if(r){if(!t){r.badgeSprite&&=(r.container.removeChild(r.badgeSprite),r.badgeSprite.destroy(),void 0),r.badgeLevel=void 0;return}try{let i=await this.badgeCache.getOrCreate(t);if(!this.activeRooms.has(e))return;if(r.badgeSprite){if(r.badgeSprite.texture===i){r.badgeLevel=n,this.applyBadgeSize(r,this.zoom),this.applyOverlayMode(r);return}r.badgeSprite.texture=i}else{let e=new c(i);e.anchor.set(.5),e.x=J/2,e.y=J/2;let t=r.container.getChildIndex(r.nameLabel);r.container.addChildAt(e,t),r.badgeSprite=e}r.badgeLevel=n,this.applyBadgeSize(r,this.zoom),this.applyOverlayMode(r)}catch(t){K(`failed to load badge for`,e,t)}}}applyBadgeSize(e,t){if(!e.badgeSprite||e.badgeLevel===void 0)return;let n=(qt[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(let e of this.activeRooms.values())this.applyOverlayMode(e)}}setRoomMineral(e,t,n){let r=this.activeRooms.get(e);if(r){if(!t||!n){r.mineralSprite&&=(r.container.removeChild(r.mineralSprite),r.mineralSprite.destroy(),void 0),r.mineralType=void 0,r.mineralDensity=void 0;return}if(r.mineralDensity=n,!r.mineralSprite||r.mineralType!==t){r.mineralSprite&&(r.container.removeChild(r.mineralSprite),r.mineralSprite.destroy());let e=`mineral/${t}`,n=new c;n.anchor.set(.5),n.x=J/2,n.y=J/2;let i=r.container.getChildIndex(r.nameLabel);r.container.addChildAt(n,i),r.mineralSprite=n,r.mineralType=t;let a=N.getTexture(M.atlasUrl,e);a?n.texture=a:N.getOrLoad(M.atlasUrl).then(t=>{n.destroyed||(n.texture=t.textures[e]??p.EMPTY)}).catch(()=>{})}this.applyMineralSize(r,this.zoom),this.applyOverlayMode(r)}}applyOverlayMode(e){e.badgeSprite&&(e.badgeSprite.visible=this.overlayMode===`owner`),e.mineralSprite&&(e.mineralSprite.visible=this.overlayMode===`mineral`)}applyMineralSize(e,t){if(!e.mineralSprite||e.mineralDensity===void 0)return;let n=Xt[e.mineralDensity-1]??52,r=14/t,i=Math.max(n,r);e.mineralSprite.width=i,e.mineralSprite.height=i}updateNameLabelScale(e,t){let n=.3/Math.sqrt(t),r=12/(36*t);e.nameLabel.scale.set(Math.max(n,r))}updateAllRoomScales(e){for(let t of this.activeRooms.values())this.applyBadgeSize(t,e),this.updateNameLabelScale(t,e),this.applyMineralSize(t,e)}setCurrentUser(e){this.currentUserId=e}setMapVisual(e){this.mapVisualLayer?.update(e),this.mapVisualLayer&&(this.world.removeChild(this.mapVisualLayer.container),this.world.addChild(this.mapVisualLayer.container))}clearMapVisual(){this.mapVisualLayer?.clear()}setMapVisualVisible(e){this.mapVisualLayer&&(this.mapVisualLayer.container.visible=e)}setSelectedRoom(e){if(this.selectedRoom=e,!this.selectionGraphics||(this.selectionGraphics.clear(),this.world.removeChild(this.selectionGraphics),this.world.addChild(this.selectionGraphics),!e))return;let t=P(e);if(!t)return;let n=t.x*J,r=t.y*J;this.selectionGraphics.rect(n,r,J,J);let i=Math.max(2,Math.ceil(2/this.zoom));this.selectionGraphics.stroke({color:16777215,width:i,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;let e=Math.max(1,Math.ceil(1/this.zoom));for(let t of this.safeModeRooms){let n=P(t);if(!n)continue;let r=n.x*J,i=n.y*J;this.safeModeGraphics.rect(r,i,J,J),this.safeModeGraphics.stroke({color:16776960,width:e,alignment:1,alpha:.5})}this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)}setBounds(e,t,n,r){if(!this.boundsGraphics)return;this.worldBoundsSet={minX:e,maxX:t,minY:n,maxY:r},this.boundsGraphics.clear();let i=e*J,a=n*J,o=(t-e+1)*J,s=(r-n+1)*J;this.boundsGraphics.rect(i,a,o,s),this.boundsGraphics.stroke({color:ne,width:6,alignment:0}),this.updateAllNameLabels()}clearBounds(){this.worldBoundsSet=null,this.boundsGraphics?.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){let 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=p.EMPTY,t.map2Graphics.clear(),t.ownerOverlay.clear(),t.badgeSprite&&=(t.container.removeChild(t.badgeSprite),t.badgeSprite.destroy(),void 0),t.mineralSprite&&=(t.container.removeChild(t.mineralSprite),t.mineralSprite.destroy(),void 0),t.mineralType=void 0,t.mineralDensity=void 0,t.container.visible=!1,this.safeModeRooms.delete(e),this.terrainBaked.delete(e),this.terrainData.delete(e),this.statsApplied.delete(e),this.roomDecorations.delete(e),this.activeRooms.delete(e),this.roomPool.length<Jt?this.roomPool.push(t):(this.world.removeChild(t.container),t.container.destroy({children:!0,context:!0})))}clearInvisibleRooms(e){let t=this.lastVisibleBounds;for(let n of[...this.activeRooms.keys()])if(!e.has(n)){if(t){let e=P(n);if(e&&e.x>=t.rxMin-Z&&e.x<=t.rxMax+Z&&e.y>=t.ryMin-Z&&e.y<=t.ryMax+Z)continue}this.clearRoom(n)}}destroy(){if(!this._destroyed){this._destroyed=!0,this.resizeObserver?.disconnect(),this.resizeObserver=null,this.visibleDebounceTimer!==null&&(clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=null);for(let[,e]of this.activeRooms)e.texLo&&!e.texLo.destroyed&&e.texLo.destroy(!0),e.texHi&&!e.texHi.destroyed&&e.texHi.destroy(!0);this.activeRooms.clear(),this.safeModeRooms.clear();for(let e of this.roomPool)e.texLo&&!e.texLo.destroyed&&e.texLo.destroy(!0),e.texHi&&!e.texHi.destroyed&&e.texHi.destroy(!0);this.roomPool.length=0,this.terrainBaked.clear(),this.terrainData.clear(),this.statsApplied.clear(),this.roomDecorations.clear(),this.worker.terminate(),this.pendingBakes.clear(),this.badgeCache.destroy(),this.mapVisualLayer?.destroy(),this.mapVisualLayer=null;try{this.app.destroy(!1,{children:!0,context:!0})}catch(e){K(`destroy error (ignored):`,e)}}}getOrCreate(e){let t=this.activeRooms.get(e);if(t)return t;let n=P(e);if(!n)throw Error(`MapRenderer: invalid room "${e}"`);let r;if(this.roomPool.length>0)r=this.roomPool.pop();else{let e=new o;e.cullable=!0;let t=new c(p.EMPTY),n=new u,i=new u;e.addChild(t),e.addChild(n),e.addChild(i);let a=new d({text:``,style:{fontSize:36,fill:9147550,fontFamily:`ui-monospace, monospace`}});a.scale.set(.25),a.x=2,a.y=2,e.addChild(a),this.world.addChild(e),r={container:e,terrainSprite:t,texLo:null,texHi:null,map2Graphics:n,ownerOverlay:i,ownerState:`none`,nameLabel:a}}return r.container.x=n.x*J,r.container.y=n.y*J,r.container.visible=!1,r.nameLabel.text=e,r.nameLabel.visible=this.showRoomNames&&this.zoom>=.5&&this.nameLabelShouldShow(n.x,n.y),this.updateNameLabelScale(r,this.zoom),r.badgeSprite&&(r.container.removeChild(r.badgeSprite),r.badgeSprite.destroy(),r.badgeSprite=void 0),r.mineralSprite&&(r.container.removeChild(r.mineralSprite),r.mineralSprite.destroy(),r.mineralSprite=void 0),r.mineralType=void 0,r.mineralDensity=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,r),r}nameLabelShouldShow(e,t){let n=this.worldBoundsSet;return!(n&&(e<n.minX||e>n.maxX||t<n.minY||t>n.maxY))}updateAllNameLabels(){let e=this.showRoomNames&&this.zoom>=.5;for(let[t,n]of this.activeRooms){if(!e){n.nameLabel.visible=!1;continue}let r=P(t);r&&(n.nameLabel.visible=this.nameLabelShouldShow(r.x,r.y))}}setupInteraction(){let e=this.app.canvas;e.style.touchAction=`none`,e.style.userSelect=`none`;let t=new Map;e.addEventListener(`pointermove`,n=>{if(!t.has(n.pointerId)){if(!this.isDragging&&!this.isPinching){let t=e.getBoundingClientRect();this.emitHover(n.clientX-t.left,n.clientY-t.top)}return}if(t.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.isPinching&&t.size===2){let n=[...t.values()],r=e.getBoundingClientRect(),i=(n[0].x+n[1].x)/2-r.left,a=(n[0].y+n[1].y)/2-r.top,o=Math.hypot(n[1].x-n[0].x,n[1].y-n[0].y),s=Math.max(Q,Math.min($,this.pinchStartScale*(o/this.pinchStartDist))),c=this.getLOD(),l=this.zoom>=Y,u=this.zoom>=X;this.world.scale.set(s),this.world.x=i-this.pinchPivotWorldX*s,this.world.y=a-this.pinchPivotWorldY*s,this.getLOD()!==c&&this.applyLOD(),(s>=Y!==l||s>=.5!==u)&&this.updateAllNameLabels(),this.updateAllRoomScales(s),this.callbacks.onZoomChanged?.(s),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode();return}if(this.isDragging){let e=n.clientX-this.dragStartX,t=n.clientY-this.dragStartY;(Math.abs(e)>3||Math.abs(t)>3)&&(this.hasDragged=!0);let r=this.worldBoundsSet;if(r){let n=this.world.scale.x,i=50-(r.maxX+1)*J*n,a=this.app.screen.width-50-r.minX*J*n,o=50-(r.maxY+1)*J*n,s=this.app.screen.height-50-r.minY*J*n;this.world.x=this.rubberBand(this.dragWorldX+e,i,a),this.world.y=this.rubberBand(this.dragWorldY+t,o,s)}else this.world.x=this.dragWorldX+e,this.world.y=this.dragWorldY+t}}),e.addEventListener(`pointerleave`,()=>{!this.isDragging&&!this.isPinching&&this.callbacks.onRoomHover(null)}),e.addEventListener(`pointerdown`,n=>{if(n.preventDefault(),this.isAnimating=!1,t.set(n.pointerId,{x:n.clientX,y:n.clientY}),e.setPointerCapture(n.pointerId),t.size>=2){this.isDragging=!1,this.isPinching=!0;let n=[...t.values()],r=e.getBoundingClientRect(),i=(n[0].x+n[1].x)/2-r.left,a=(n[0].y+n[1].y)/2-r.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=(i-this.world.x)/this.pinchStartScale,this.pinchPivotWorldY=(a-this.world.y)/this.pinchStartScale}else this.isPinching=!1,this.isDragging=!0,this.hasDragged=!1,this.dragStartX=n.clientX,this.dragStartY=n.clientY,this.dragWorldX=this.world.x,this.dragWorldY=this.world.y}),e.addEventListener(`pointerup`,n=>{if(t.delete(n.pointerId),e.releasePointerCapture(n.pointerId),this.isPinching){t.size<2&&(this.isPinching=!1,this.isDragging=!1,this.springBack());return}if(this.isDragging){if(this.isDragging=!1,!this.hasDragged){let t=e.getBoundingClientRect(),r=this.screenToRoom(n.clientX-t.left,n.clientY-t.top);r&&this.callbacks.onRoomClick(r)}this.springBack()}}),e.addEventListener(`pointercancel`,n=>{t.delete(n.pointerId),e.releasePointerCapture(n.pointerId),(this.isPinching||this.isDragging)&&(this.isPinching=!1,this.isDragging=!1,this.springBack())}),e.addEventListener(`wheel`,e=>{if(e.preventDefault(),this.isDragging||this.isPinching)return;this.isAnimating=!1;let t=this.world.scale.x,n=e.deltaY<0?1.1:.9,r=Math.max(Q,Math.min($,t*n));this.applyZoomAt(r,e.offsetX,e.offsetY)},{passive:!1})}rubberBand(e,t,n){let r=n-t;if(r<=0||e>=t&&e<=n)return e;let i=.55;return e<t?t-(1-1/((t-e)*i/r+1))*r*i:n+(1-1/((e-n)*i/r+1))*r*i}springBack(){let e=this.worldBoundsSet;if(!e)return;let t=this.world.scale.x,n=this.app.screen.width,r=this.app.screen.height,i=this.world.x+e.minX*J*t,a=this.world.x+(e.maxX+1)*J*t,o=this.world.y+e.minY*J*t,s=this.world.y+(e.maxY+1)*J*t,c=this.world.x,l=this.world.y;a<50?c+=50-a:i>n-50&&(c-=i-(n-50)),s<50?l+=50-s:o>r-50&&(l-=o-(r-50)),(c!==this.world.x||l!==this.world.y)&&(this.animTargetX=c,this.animTargetY=l,this.isAnimating=!0)}screenToRoom(e,t){let n=this.world.scale.x,r=(e-this.world.x)/n,i=(t-this.world.y)/n;return F(Math.floor(r/J),Math.floor(i/J))}emitHover(e,t){this.callbacks.onRoomHover(this.screenToRoom(e,t))}lastCheckX=0;lastCheckY=0;lastCheckScale=0;checkVisibleRooms(){let e=this.world.scale.x,t=this.world.x,n=this.world.y;if(this.lastCheckX===t&&this.lastCheckY===n&&this.lastCheckScale===e)return;this.lastCheckX=t,this.lastCheckY=n,this.lastCheckScale=e;let r=-t/e,i=-n/e,a=(this.app.screen.width-t)/e,o=(this.app.screen.height-n)/e,s=Math.floor(r/J)-1,c=Math.ceil(a/J),l=Math.floor(i/J)-1,u=Math.ceil(o/J);this.lastVisibleBounds={rxMin:s,rxMax:c,ryMin:l,ryMax:u};let d=[],f=this.worldBoundsSet,p=f?Math.max(s,f.minX):s,m=f?Math.min(c,f.maxX):c,h=f?Math.max(l,f.minY):l,g=f?Math.min(u,f.maxY):u;for(let e=p;e<=m;e++)for(let t=h;t<=g;t++){let n=F(e,t);n&&d.push(n)}let _=`${s},${l},${c},${u}`;_!==this.lastVisibleKey&&(this.lastVisibleKey=_,this.visibleDebounceTimer!==null&&clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=setTimeout(()=>{this.visibleDebounceTimer=null,this.callbacks.onVisibleRoomsChanged(d)},Yt))}};export{xe as $,ft as A,O as At,rt as B,ae as Bt,M as C,fe as Ct,nt as D,ze as Dt,et as E,D as Et,$e as F,He as Ft,ye as G,at as H,re as Ht,tt as I,ne as It,Se as J,_e as K,ht as L,ee as Lt,mt as M,qe as Mt,ot as N,Je as Nt,gt as O,Be as Ot,Qe as P,Ke as Pt,Te as Q,st as R,v as Rt,N as S,S as St,ut as T,Re as Tt,Ze as U,ie as Ut,pt as V,se as Vt,k as W,Ce as X,be as Y,we as Z,F as _,Ie as _t,Lt as a,Ne as at,bt as b,pe as bt,Ut as c,Me as ct,G as d,ke as dt,ve as et,Kt as f,We as ft,wt as g,Le as gt,Tt as h,Fe as ht,Gt as i,Pe as it,it as j,Ge as jt,ct as k,Ve as kt,Ht as l,De as lt,Dt as m,he as mt,X as n,h as nt,Bt as o,Ae as ot,Et as p,E as pt,Ee as q,Wt as r,ce as rt,zt as s,je as st,Zt as t,g as tt,Rt as u,Oe as ut,St as v,ge as vt,lt as w,Ue as wt,P as x,me as xt,Ct as y,b as yt,dt as z,oe as zt};
1
+ import{D as e,S as t}from"./vendor-codemirror-B6f_i0wP.js";import{B as n,D as r,R as i,z as a}from"./clientStore-arNZaq85.js";import{_ as o,f as s,g as c,h as l,l as u,o as d,s as f,v as p}from"./vendor-pixi-QLQyXP3g.js";import{t as m}from"./src-JUwOmHaV.js";var h=856343,g=1448738,_=1843496,ee=3421243,te=h,v=7039337,ne=3159613,re=1579032,ie=2631720,ae=2632986,oe=2500383,se=2771488,ce={tough:5000268,move:11122630,work:16770413,carry:7829367,attack:16332866,ranged_attack:6127794,heal:6684002,claim:12164347},y=5809919,b=7979263,x=4176208,S=9147550,C=13801762,le=10711543,ue=16218298,w=16273737,T=15763518,de=2172461,fe=v,pe=13226457,me=12283502,he=[16777215,16711680,8388736,255,65535,32768,16776960,16753920,10824234,8421504,16777215],ge={creep:T,spawn:y,extension:b,tower:x,container:S,storage:C,link:le,rampart:y,road:fe,constructedWall:de,extractor:S,lab:ue,terminal:C,observer:b,powerSpawn:T,nuker:w,factory:S,invaderCore:w,source:C,mineral:b,deposit:C,controller:y,powerBank:T,portal:le,keeperLair:w},E=16771195,_e=E,ve=b,ye=E,be=b,xe=E,Se=E,Ce=w,we=x,Te=b,Ee=16777215,De=9419667,Oe=7245682,ke=12116924,Ae=12283502,je=9787480,Me=14721184,Ne=_,Pe=13684944,Fe=4067858,Ie=14440008,Le=11940394,Re=1579032,ze=5592405,Be=11184810,Ve=9419667,D=16771195,O=16069959,He=7105644,Ue={energy:D,power:O,H:13421772,O:16777215,U:5822457,L:62626,K:10514943,Z:16631694,X:11568379,G:16777215},We={biomass:8695826,metal:9793372,mist:14314485,silicon:5023717},Ge=5617743,Ke=9099642,qe=11680314,Je=14049376;function Ye(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>t(r),r.onerror=n,r.src=e})}var k=class{cache=new Map;pending=new Map;getKey(e){return JSON.stringify(e)}has(e){return this.cache.has(this.getKey(e))}getOrCreate(e){let t=this.getKey(e),n=this.cache.get(t);if(n)return Promise.resolve(n);let r=this.pending.get(t);if(r)return r;let i=this.buildTexture(e,t);return this.pending.set(t,i),i.then(()=>{this.pending.delete(t)}).catch(()=>{this.pending.delete(t)}),i}async buildTexture(e,t){let n=m(e),r=new Blob([n],{type:`image/svg+xml;charset=utf-8`}),i=URL.createObjectURL(r);try{let e=window.devicePixelRatio||1,n=128*Math.max(2,e),r=await Ye(i),a=document.createElement(`canvas`);a.width=n,a.height=n,a.getContext(`2d`).drawImage(r,0,0,n,n);let o=p.from(a);return this.cache.set(t,o),o}finally{URL.revokeObjectURL(i)}}destroy(){for(let e of this.cache.values())e.destroyed||e.destroy(!0);this.cache.clear(),this.pending.clear()}};function A(e,n){let r=localStorage.getItem(e),[i,a]=t(r===null?n:r===`true`);return[i,t=>{a(t),localStorage.setItem(e,String(t))}]}function Xe(e,n){let[r,i]=t(localStorage.getItem(e)??n);return[r,t=>{i(t),localStorage.setItem(e,t)}]}var[Ze,Qe]=A(r.widescreenMode,!0),[$e,et]=A(r.showCreepLabels,!0),[tt,nt]=A(r.showMapRoomNames,!1),[rt,it]=A(r.showUnclaimableRooms,!0),[at,ot]=A(r.terrainEffects,!0),[st,ct]=A(r.showRoomDecorations,!1),[lt,ut]=A(r.roomDarkOverlay,!0),[dt,ft]=A(r.showRoomVisuals,!0),[pt,mt]=Xe(r.spriteTheme,`default`),[ht,gt]=A(r.showMapVisuals,!0),j=n(),_t=j?`?v=${encodeURIComponent(j)}`:``,M={id:`default`,name:`Default`,atlasUrl:`${a()}/themes/default/sprite-0.json${_t}`,sprites:{storage:{layers:[{frame:`storage/shell`,tint:`owner`},{frame:`storage/fill`}],tileScale:1.75}},controller:{backgroundFrame:`controller/background`,segmentFrame:`controller/segment`,tileScale:2},flag:{mainFrame:`flag/main`,secondFrame:`flag/second`,tileScale:3,zIndex:5},tombstone:{shellFrame:`grave/shell`,crossFrame:`grave/cross`,tileScale:1,zIndex:4},deposit:{tileScale:1.2},mineral:{tileScale:2.6},tower:{ringFrame:`tower/ring`,bodyFrame:`tower/body`,tileScale:2.5,fill:{x:-39,yMin:-25,width:78,heightMax:58,rx:12,ry:12}}},vt=class{cache=new Map;pending=new Map;frames=new Map;getOrLoad(e){let t=this.cache.get(e);if(t)return Promise.resolve(t);let n=this.pending.get(e);if(n)return n;let r=s.load(e).then(t=>(this.cache.set(e,t),this.frames.set(e,yt(t)),this.pending.delete(e),t)).catch(t=>{throw this.pending.delete(e),t});return this.pending.set(e,r),r}getTexture(e,t){return this.frames.get(e)?.[t]}destroy(){for(let[,e]of this.cache){for(let t of e.linkedSheets??[])t.destroy(!0);e.destroy(!0)}this.cache.clear(),this.frames.clear(),this.pending.clear()}};function yt(e){let t={...e.textures};for(let n of e.linkedSheets??[])Object.assign(t,n.textures);return t}var N=new vt;function bt(e,t,n){return isNaN(n.minX)||isNaN(n.maxX)||isNaN(n.minY)||isNaN(n.maxY)?!0:e>=n.minX&&e<=n.maxX&&t>=n.minY&&t<=n.maxY}function P(e){let t=e.match(/^([WE])(\d+)([NS])(\d+)$/);if(!t)return null;let[,n,r,i,a]=t;return{x:n===`W`?-(parseInt(r,10)+1):parseInt(r,10),y:i===`N`?-(parseInt(a,10)+1):parseInt(a,10)}}function F(e,t){let n=e<0?`W`:`E`,r=t<0?`N`:`S`;return`${n}${e<0?-e-1:e}${r}${t<0?-t-1:t}`}function xt(e){return e===0||e<0&&(e+1)%10==0||e>0&&e%10==0}function St(e,t){return xt(e)||xt(t)}function Ct(e,t){let n=e<0?Math.abs(e+1)%10:Math.abs(e)%10,r=t<0?Math.abs(t+1)%10:Math.abs(t)%10;return n>=4&&n<=6&&r>=4&&r<=6}function wt(e){let t=e;if(!t)return!1;let n=t.tagName??``;return n===`INPUT`||n===`TEXTAREA`?!0:t.isContentEditable===!0}function Tt(t){let n=e=>{if(wt(e.target))return;let n=t.currentRoom(),r=n?P(n):null;if(!r)return;let i=t.worldBounds(),a=(e,t)=>!i||bt(e,t,i);switch(e.key){case`ArrowLeft`:e.preventDefault(),a(r.x-1,r.y)&&t.onMove(r.x-1,r.y);break;case`ArrowRight`:e.preventDefault(),a(r.x+1,r.y)&&t.onMove(r.x+1,r.y);break;case`ArrowUp`:e.preventDefault(),a(r.x,r.y-1)&&t.onMove(r.x,r.y-1);break;case`ArrowDown`:e.preventDefault(),a(r.x,r.y+1)&&t.onMove(r.x,r.y+1);break}};window.addEventListener(`keydown`,n),e(()=>window.removeEventListener(`keydown`,n))}var[Et,Dt]=t(`owner`),I=3,Ot=I*50,L=4;function R(e,t,n){let r=P(e);return r?[r.x*Ot+t*I,r.y*Ot+n*I]:null}var z=3*I,B=2.5*I,V=1*I,H=2*I;function U(e,t,n,r){let i=!0,a=n;for(let o=0;o<t.length-1;o++){let[s,c]=t[o],[l,u]=t[o+1],d=l-s,f=u-c,p=Math.sqrt(d*d+f*f);if(p<.001)continue;let m=d/p,h=f/p,g=0;for(;g<p;){let t=Math.min(a,p-g);if(i){let n=s+m*g,r=c+h*g;e.moveTo(n,r),e.lineTo(n+m*t,r+h*t)}g+=t,a-=t,a<.001&&(i=!i,a=i?n:r)}}}function kt(e,t,n){let r=Math.max(32,Math.ceil(2*Math.PI*n/2)),i=[];for(let a=0;a<=r;a++){let o=a/r*2*Math.PI;i.push([e+Math.cos(o)*n,t+Math.sin(o)*n])}return i}var At=class{container;g;constructor(){this.container=new o,this.container.label=`mapVisuals`,this.g=new u,this.container.addChild(this.g)}update(e){let t=this.container.removeChildren();for(let e of t)e!==this.g&&e.destroy();if(this.g.clear(),this.container.addChild(this.g),!e)return;let n=this.g;for(let t of e.split(`
2
+ `)){if(!t.trim())continue;let e;try{e=JSON.parse(t)}catch{continue}let r=e.s??{},i=r.opacity??.5;switch(e.t){case`l`:this.drawLine(n,e,r,i);break;case`c`:this.drawCircle(n,e,r,i);break;case`r`:this.drawRect(n,e,r,i);break;case`p`:this.drawPoly(n,e,r,i);break;case`t`:this.drawText(e,r,i);break}}}clear(){let e=this.container.removeChildren();for(let t of e)t!==this.g&&t.destroy();this.g.clear(),this.container.addChild(this.g)}drawLine(e,t,n,r){let i=R(t.n1,t.x1,t.y1),a=R(t.n2,t.x2,t.y2);if(!i||!a)return;let o=n.color??`#ffffff`,s=(n.width??.5)*I;n.lineStyle===`dashed`?U(e,[i,a],z*(n.width??.5),B*(n.width??.5)):n.lineStyle===`dotted`?U(e,[i,a],V*(n.width??.5),H*(n.width??.5)):(e.moveTo(i[0],i[1]),e.lineTo(a[0],a[1])),e.stroke({color:o,width:s,alpha:r})}drawCircle(e,t,n,r){let i=R(t.n,t.x,t.y);if(!i)return;let[a,o]=i,s=(n.radius??10)*I,c=!!(n.fill&&n.fill!==`transparent`),l=!!(n.stroke&&n.strokeWidth),u=(n.strokeWidth??.5)*I;c&&(e.circle(a,o,s),e.fill({color:n.fill,alpha:r})),l&&(n.lineStyle===`dashed`?U(e,kt(a,o,s),z*(n.strokeWidth??.5),B*(n.strokeWidth??.5)):n.lineStyle===`dotted`?U(e,kt(a,o,s),V*(n.strokeWidth??.5),H*(n.strokeWidth??.5)):e.circle(a,o,s),e.stroke({color:n.stroke,width:u,alpha:r}))}drawRect(e,t,n,r){let i=R(t.n,t.x,t.y),a=R(t.n,t.x+t.w,t.y),o=R(t.n,t.x+t.w,t.y+t.h),s=R(t.n,t.x,t.y+t.h);if(!i||!a||!o||!s)return;let c=!!(n.fill&&n.fill!==`transparent`),l=!!(n.stroke&&n.strokeWidth),u=[i,a,o,s,i],d=u.flatMap(e=>e),f=(n.strokeWidth??.5)*I;c&&(e.poly(d.slice(0,8),!0),e.fill({color:n.fill,alpha:r})),l&&(n.lineStyle===`dashed`?U(e,u,z*(n.strokeWidth??.5),B*(n.strokeWidth??.5)):n.lineStyle===`dotted`?U(e,u,V*(n.strokeWidth??.5),H*(n.strokeWidth??.5)):e.poly(d.slice(0,8),!0),e.stroke({color:n.stroke,width:f,alpha:r}))}drawPoly(e,t,n,r){if(!t.points||t.points.length===0)return;let i=!!(n.fill&&n.fill!==`transparent`),a=!!(n.stroke&&n.strokeWidth);if(!i&&!a)return;let o=[];for(let{n:e,x:n,y:r}of t.points){let t=R(e,n,r);if(!t)return;o.push(t)}let s=o.flatMap(e=>e),c=(n.strokeWidth??.5)*I;if(i&&(e.poly(s,!0),e.fill({color:n.fill,alpha:r})),a){if(n.lineStyle===`dashed`){let t=o[0],r=o[o.length-1];U(e,t[0]===r[0]&&t[1]===r[1]?o:[...o,t],z*(n.strokeWidth??.5),B*(n.strokeWidth??.5))}else if(n.lineStyle===`dotted`){let t=o[0],r=o[o.length-1];U(e,t[0]===r[0]&&t[1]===r[1]?o:[...o,t],V*(n.strokeWidth??.5),H*(n.strokeWidth??.5))}else e.poly(s,!0);e.stroke({color:n.stroke,width:c,alpha:r})}}drawText(e,t,n){let r=R(e.n,e.x,e.y);if(!r)return;let[i,a]=r,o=t.fontSize??10,s=t.fontFamily??`sans-serif`,c=o*I,l=t.align??`center`,p=new f({fill:t.color??`#ffffff`,fontSize:c*L,fontFamily:s,align:l,...t.fontStyle?{fontStyle:t.fontStyle}:{},...t.fontVariant?{fontVariant:t.fontVariant}:{},...t.stroke&&t.strokeWidth?{stroke:{color:t.stroke,width:t.strokeWidth*I*L}}:{}});if(t.backgroundColor&&t.backgroundColor!==`transparent`){let r=(t.backgroundPadding??2)*I,o=new d({text:e.text,style:p});o.scale.set(1/L);let s=o.width,c=o.height;o.destroy();let f=i-(l===`center`?.5:+(l===`right`))*s-r,m=a-c/2-r,h=new u;h.rect(f,m,s+r*2,c+r*2),h.fill({color:t.backgroundColor,alpha:n}),this.container.addChild(h)}let m=new d({text:e.text,style:p});m.scale.set(1/L),m.anchor.x=l===`center`?.5:+(l===`right`),m.anchor.y=.5,m.position.set(i,a),m.alpha=n,this.container.addChild(m)}destroy(){let e=this.container.removeChildren();for(let t of e)t!==this.g&&t.destroy();this.g.destroy(),this.container.destroy()}},{warn:jt}=i(`terrainCache`),Mt=`screeps-terrain-v1`;async function Nt(e,t,n){try{let r=await caches.open(Mt),i=`/terrain/${e}_${t}_z${n}.webp`,a=new Request(i),o=await r.match(a);if(o){let e=await o.arrayBuffer(),t=o.headers.get(`Content-Type`)??`image/webp`;return new Blob([e],{type:t})}}catch(e){jt(`get failed:`,e)}return null}async function Pt(e,t,n,r){try{let i=await caches.open(Mt),a=`/terrain/${e}_${t}_z${n}.webp`,o=new Request(a),s=new Response(r);await i.put(o,s)}catch(e){jt(`save failed:`,e)}}var W=null;async function Ft(e){if(W!==!1)try{let t=await createImageBitmap(e);return W=!0,t}catch(e){if(W===!0)throw e;W=!1}let t=URL.createObjectURL(e);try{let e=new Image;return e.src=t,await e.decode(),await createImageBitmap(e)}finally{URL.revokeObjectURL(t)}}function It(e){return new Worker(`/client/_client/terrain.worker-t5M0-yfM.js`,{name:e?.name})}var Lt=2962235,Rt=856343,zt=4020797,Bt=v,G=4486980,Vt=8921634,Ht=x,Ut=me,Wt=[{key:`s`,color:E,radius:2.5},{key:`c`,color:16777215,radius:2},{key:`m`,color:b,radius:2},{key:`k`,color:T,radius:2},{key:`pb`,color:16720418,radius:2.5},{key:`d`,color:16777215,radius:2.5}],Gt=new Set([`w`,`r`,`pb`,`p`,`s`,`c`,`m`,`k`,`d`]);function Kt(e){return`#`+e.toString(16).padStart(6,`0`)}var{warn:K}=i(`MapRenderer`),q=3,J=q*50,qt=[50,60,70,80,90,100,105,120],Y=1,X=.5,Z=50,Jt=2600,Yt=5,Q=.2,$=5,Xt=[80,104,128,160],Zt=class{app;world;boundsGraphics=null;selectionGraphics=null;safeModeGraphics=null;mapVisualLayer=null;safeModeRooms=new Set;activeRooms=new Map;roomPool=[];terrainBaked=new Set;terrainData=new Map;statsApplied=new Set;roomDecorations=new Map;showDecorations=!0;worker;pendingBakes=new Map;nextBakeId=0;currentShard=`shard0`;callbacks;resizeObserver=null;_destroyed=!1;showRoomNames=!1;worldBoundsSet=null;lastVisibleBounds=null;animTargetX=0;animTargetY=0;isAnimating=!1;overlayMode=`owner`;showUnclaimableOverlay=!0;isDragging=!1;hasDragged=!1;dragStartX=0;dragStartY=0;dragWorldX=0;dragWorldY=0;isPinching=!1;pinchPivotWorldX=0;pinchPivotWorldY=0;pinchStartDist=0;pinchStartScale=0;lastVisibleKey=``;visibleDebounceTimer=null;selectedRoom=null;currentUserId=null;badgeCache=new k;constructor(e){this.app=new l,this.callbacks=e,this.worker=new It,this.worker.onmessage=e=>{let t=e.data;if(t.kind===`cache`){Pt(t.shard,t.roomName,t.lod,new Blob([t.cacheBytes],{type:t.cacheType||`image/webp`}));return}let n=this.pendingBakes.get(t.id);n&&(this.pendingBakes.delete(t.id),n.resolve(t.bitmap))}}async init(e){let t=e.parentElement??e,{width:n,height:r}=t.getBoundingClientRect();await this.app.init({canvas:e,width:n,height:r,background:te,antialias:!1,preference:`webgl`}),this.resizeObserver=new ResizeObserver(e=>{let{width:t,height:n}=e[0].contentRect,r=this.app.screen.width,i=this.app.screen.height;this.app.renderer.resize(t,n),this.world.x+=(t-r)/2,this.world.y+=(n-i)/2}),this.resizeObserver.observe(t),this.world=new o,this.app.stage.addChild(this.world),this.boundsGraphics=new u,this.world.addChild(this.boundsGraphics),this.selectionGraphics=new u,this.world.addChild(this.selectionGraphics),this.safeModeGraphics=new u,this.world.addChild(this.safeModeGraphics),this.mapVisualLayer=new At,this.world.addChild(this.mapVisualLayer.container),this.setupInteraction(),this.app.ticker.add(()=>{if(this.isAnimating){let e=this.animTargetX-this.world.x,t=this.animTargetY-this.world.y;Math.abs(e)<.5&&Math.abs(t)<.5?(this.world.x=this.animTargetX,this.world.y=this.animTargetY,this.isAnimating=!1):(this.world.x+=e*.2,this.world.y+=t*.2)}this.checkVisibleRooms()})}get zoom(){return this.world?.scale.x??1}setZoom(e){if(!this.world||(e=Math.max(Q,Math.min($,e)),e===this.world.scale.x))return;let t=this.app.screen.width/2,n=this.app.screen.height/2;this.applyZoomAt(e,t,n)}applyZoomAt(e,t,n){let r=this.world.scale.x,i=this.getLOD(),a=this.zoom>=Y,o=this.zoom>=X,s=(t-this.world.x)/r,c=(n-this.world.y)/r;this.world.scale.set(e),this.world.x=t-s*e,this.world.y=n-c*e,this.getLOD()!==i&&this.applyLOD(),(e>=Y!==a||e>=.5!==o)&&this.updateAllNameLabels(),this.updateAllRoomScales(e),this.callbacks.onZoomChanged?.(e),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode()}centerOn(e,t,n=!1){let r=e*J+J/2,i=t*J+J/2,a=this.world.scale.x,o=this.app.screen.width/2-r*a,s=this.app.screen.height/2-i*a;n?(this.animTargetX=o,this.animTargetY=s,this.isAnimating=!0):(this.isAnimating=!1,this.world.x=o,this.world.y=s)}async getTerrainBitmap(e,t,n,r){let i=this.currentShard;try{if(!r){let n=await Nt(i,e,t);if(n)return await Ft(n)}let a=this.nextBakeId++,o=new Promise((n,r)=>{this.pendingBakes.set(a,{roomName:e,lod:t,resolve:n,reject:r})});return this.worker.postMessage({id:a,roomName:e,lod:t,raw:n,shard:i,colors:r}),await o}catch(e){return K(`error getting terrain bitmap:`,e),null}}async setRoomTerrain(e,t){let n=t.raw,r=!1;for(let e=0;e<n.length;e++)if(n[e]!==0){r=!0;break}if(!r){this.terrainBaked.add(e);return}let i=this.getOrCreate(e),a=this.getLOD();this.terrainData.set(e,n);let o=await this.getTerrainBitmap(e,a,n);if(!o)return;if(!this.activeRooms.has(e)){o.close();return}let s=p.from(o);a===0?(i.texLo&&!i.texLo.destroyed&&(i.terrainSprite.texture===i.texLo&&(i.terrainSprite.texture=p.EMPTY),i.texLo.destroy(!0)),i.texLo=s):(i.texHi&&!i.texHi.destroyed&&(i.terrainSprite.texture===i.texHi&&(i.terrainSprite.texture=p.EMPTY),i.texHi.destroy(!0)),i.texHi=s),i.terrainSprite.width=J,i.terrainSprite.height=J,this.terrainBaked.add(e),this.ensureCurrentLod(e,i),this.revealIfReady(e,i)}getLOD(){return this.zoom<Y?0:1}ensureCurrentLod(e,t){let n=this.getLOD()===1,r=n?t.texHi:t.texLo;if(r&&!r.destroyed){t.terrainSprite.texture=r;return}let i=this.terrainData.get(e);if(!i)return;let a=this.showDecorations?this.roomDecorations.get(e):void 0;return this.getTerrainBitmap(e,+!!n,i,a).then(r=>{if(!r)return;if(!this.activeRooms.has(e)){r.close();return}let i=p.from(r);n?t.texHi=i:t.texLo=i,this.getLOD()===1===n&&(t.terrainSprite.texture=i)})}async applyLOD(){let e=[];for(let[t,n]of this.activeRooms){if(!this.terrainBaked.has(t))continue;let r=this.ensureCurrentLod(t,n);r&&e.push(r)}await Promise.all(e)}setRoomMap2(e,t,n=`live`){let r=this.getOrCreate(e);r.lastMap2Data=t,r.lastMap2Source=n,this.drawMap2(r,t,n)}drawMap2(e,t,n){let r=e.map2Graphics;r.alpha=n===`cache`?.6:1;let i=q;r.clear();let a=t.r??[];for(let[e,t]of a)r.rect(e*i,t*i,i,i);a.length&&r.fill(Bt);let o=t.w??[];for(let[e,t]of o)r.rect(e*i+.5,t*i+.5,i-1,i-1);o.length&&r.fill(e.ownerState===`other`||e.ownerState===`prohibited`?Vt:G);for(let e of Wt){let n=t[e.key]??[];for(let[t,a]of n)r.circle((t+.5)*i,(a+.5)*i,e.radius);n.length&&r.fill(e.color)}let s=t;for(let e in s){if(Gt.has(e))continue;let t=s[e];if(!Array.isArray(t)||t.length===0)continue;for(let[e,n]of t)r.circle((e+.5)*i,(n+.5)*i,1);let n=e===this.currentUserId?Ht:Ut;r.fill(n)}}clearRoomMap2(e){this.activeRooms.get(e)?.map2Graphics.clear()}clearAllMap2(){for(let e of this.activeRooms.values())e.map2Graphics.clear()}setRoomOwned(e,t){let n=this.activeRooms.get(e);if(!n)return;this.statsApplied.add(e),n.ownerState!==t&&(n.ownerState=t,n.lastMap2Data&&this.drawMap2(n,n.lastMap2Data,n.lastMap2Source??`live`));let r=n.ownerOverlay;r.clear(),t===`prohibited`?(r.rect(0,0,J,J),r.fill({color:0,alpha:.5})):t===`other`?(r.rect(0,0,J,J),r.fill({color:10027008,alpha:.18})):t===`own`&&(r.rect(0,0,J,J),r.fill({color:102,alpha:.35})),r.visible=t===`prohibited`||this.showUnclaimableOverlay,this.revealIfReady(e,n)}setUnclaimableOverlayVisible(e){if(this.showUnclaimableOverlay!==e){this.showUnclaimableOverlay=e;for(let t of this.activeRooms.values())t.ownerOverlay.visible=t.ownerState===`prohibited`||e}}revealIfReady(e,t){this.terrainBaked.has(e)&&this.statsApplied.has(e)&&(t.container.visible=!0)}setRoomDecoration(e,t){let n=this.roomDecorations.get(e);(t?JSON.stringify(t):``)!==(n?JSON.stringify(n):``)&&(t?this.roomDecorations.set(e,t):this.roomDecorations.delete(e),this.rebakeRoom(e))}setDecorationsVisible(e){if(this.showDecorations!==e){this.showDecorations=e;for(let e of this.roomDecorations.keys())this.rebakeRoom(e)}}rebakeRoom(e){let t=this.activeRooms.get(e);if(t){for(let e of[`texLo`,`texHi`]){let n=t[e];n&&!n.destroyed&&(t.terrainSprite.texture===n&&(t.terrainSprite.texture=p.EMPTY),n.destroy(!0),t[e]=null)}this.ensureCurrentLod(e,t)}}async setRoomBadge(e,t,n){let r=this.activeRooms.get(e);if(r){if(!t){r.badgeSprite&&=(r.container.removeChild(r.badgeSprite),r.badgeSprite.destroy(),void 0),r.badgeLevel=void 0;return}try{let i=await this.badgeCache.getOrCreate(t);if(!this.activeRooms.has(e))return;if(r.badgeSprite){if(r.badgeSprite.texture===i){r.badgeLevel=n,this.applyBadgeSize(r,this.zoom),this.applyOverlayMode(r);return}r.badgeSprite.texture=i}else{let e=new c(i);e.anchor.set(.5),e.x=J/2,e.y=J/2;let t=r.container.getChildIndex(r.nameLabel);r.container.addChildAt(e,t),r.badgeSprite=e}r.badgeLevel=n,this.applyBadgeSize(r,this.zoom),this.applyOverlayMode(r)}catch(t){K(`failed to load badge for`,e,t)}}}applyBadgeSize(e,t){if(!e.badgeSprite||e.badgeLevel===void 0)return;let n=(qt[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(let e of this.activeRooms.values())this.applyOverlayMode(e)}}setRoomMineral(e,t,n){let r=this.activeRooms.get(e);if(r){if(!t||!n){r.mineralSprite&&=(r.container.removeChild(r.mineralSprite),r.mineralSprite.destroy(),void 0),r.mineralType=void 0,r.mineralDensity=void 0;return}if(r.mineralDensity=n,!r.mineralSprite||r.mineralType!==t){r.mineralSprite&&(r.container.removeChild(r.mineralSprite),r.mineralSprite.destroy());let e=`mineral/${t}`,n=new c;n.anchor.set(.5),n.x=J/2,n.y=J/2;let i=r.container.getChildIndex(r.nameLabel);r.container.addChildAt(n,i),r.mineralSprite=n,r.mineralType=t;let a=N.getTexture(M.atlasUrl,e);a?n.texture=a:N.getOrLoad(M.atlasUrl).then(t=>{n.destroyed||(n.texture=t.textures[e]??p.EMPTY)}).catch(()=>{})}this.applyMineralSize(r,this.zoom),this.applyOverlayMode(r)}}applyOverlayMode(e){e.badgeSprite&&(e.badgeSprite.visible=this.overlayMode===`owner`),e.mineralSprite&&(e.mineralSprite.visible=this.overlayMode===`mineral`)}applyMineralSize(e,t){if(!e.mineralSprite||e.mineralDensity===void 0)return;let n=Xt[e.mineralDensity-1]??52,r=14/t,i=Math.max(n,r);e.mineralSprite.width=i,e.mineralSprite.height=i}updateNameLabelScale(e,t){let n=.3/Math.sqrt(t),r=12/(36*t);e.nameLabel.scale.set(Math.max(n,r))}updateAllRoomScales(e){for(let t of this.activeRooms.values())this.applyBadgeSize(t,e),this.updateNameLabelScale(t,e),this.applyMineralSize(t,e)}setCurrentUser(e){this.currentUserId=e}setMapVisual(e){this.mapVisualLayer?.update(e),this.mapVisualLayer&&(this.world.removeChild(this.mapVisualLayer.container),this.world.addChild(this.mapVisualLayer.container))}clearMapVisual(){this.mapVisualLayer?.clear()}setMapVisualVisible(e){this.mapVisualLayer&&(this.mapVisualLayer.container.visible=e)}setSelectedRoom(e){if(this.selectedRoom=e,!this.selectionGraphics||(this.selectionGraphics.clear(),this.world.removeChild(this.selectionGraphics),this.world.addChild(this.selectionGraphics),!e))return;let t=P(e);if(!t)return;let n=t.x*J,r=t.y*J;this.selectionGraphics.rect(n,r,J,J);let i=Math.max(2,Math.ceil(2/this.zoom));this.selectionGraphics.stroke({color:16777215,width:i,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;let e=Math.max(1,Math.ceil(1/this.zoom));for(let t of this.safeModeRooms){let n=P(t);if(!n)continue;let r=n.x*J,i=n.y*J;this.safeModeGraphics.rect(r,i,J,J),this.safeModeGraphics.stroke({color:16776960,width:e,alignment:1,alpha:.5})}this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)}setBounds(e,t,n,r){if(!this.boundsGraphics)return;this.worldBoundsSet={minX:e,maxX:t,minY:n,maxY:r},this.boundsGraphics.clear();let i=e*J,a=n*J,o=(t-e+1)*J,s=(r-n+1)*J;this.boundsGraphics.rect(i,a,o,s),this.boundsGraphics.stroke({color:ne,width:6,alignment:0}),this.updateAllNameLabels()}clearBounds(){this.worldBoundsSet=null,this.boundsGraphics?.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){let 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=p.EMPTY,t.map2Graphics.clear(),t.ownerOverlay.clear(),t.badgeSprite&&=(t.container.removeChild(t.badgeSprite),t.badgeSprite.destroy(),void 0),t.mineralSprite&&=(t.container.removeChild(t.mineralSprite),t.mineralSprite.destroy(),void 0),t.mineralType=void 0,t.mineralDensity=void 0,t.container.visible=!1,this.safeModeRooms.delete(e),this.terrainBaked.delete(e),this.terrainData.delete(e),this.statsApplied.delete(e),this.roomDecorations.delete(e),this.activeRooms.delete(e),this.roomPool.length<Jt?this.roomPool.push(t):(this.world.removeChild(t.container),t.container.destroy({children:!0,context:!0})))}clearAllRooms(){for(let e of[...this.activeRooms.keys()])this.clearRoom(e)}clearInvisibleRooms(e){let t=this.lastVisibleBounds;for(let n of[...this.activeRooms.keys()])if(!e.has(n)){if(t){let e=P(n);if(e&&e.x>=t.rxMin-Z&&e.x<=t.rxMax+Z&&e.y>=t.ryMin-Z&&e.y<=t.ryMax+Z)continue}this.clearRoom(n)}}destroy(){if(!this._destroyed){this._destroyed=!0,this.resizeObserver?.disconnect(),this.resizeObserver=null,this.visibleDebounceTimer!==null&&(clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=null);for(let[,e]of this.activeRooms)e.texLo&&!e.texLo.destroyed&&e.texLo.destroy(!0),e.texHi&&!e.texHi.destroyed&&e.texHi.destroy(!0);this.activeRooms.clear(),this.safeModeRooms.clear();for(let e of this.roomPool)e.texLo&&!e.texLo.destroyed&&e.texLo.destroy(!0),e.texHi&&!e.texHi.destroyed&&e.texHi.destroy(!0);this.roomPool.length=0,this.terrainBaked.clear(),this.terrainData.clear(),this.statsApplied.clear(),this.roomDecorations.clear(),this.worker.terminate(),this.pendingBakes.clear(),this.badgeCache.destroy(),this.mapVisualLayer?.destroy(),this.mapVisualLayer=null;try{this.app.destroy(!1,{children:!0,context:!0})}catch(e){K(`destroy error (ignored):`,e)}}}getOrCreate(e){let t=this.activeRooms.get(e);if(t)return t;let n=P(e);if(!n)throw Error(`MapRenderer: invalid room "${e}"`);let r;if(this.roomPool.length>0)r=this.roomPool.pop();else{let e=new o;e.cullable=!0;let t=new c(p.EMPTY),n=new u,i=new u;e.addChild(t),e.addChild(n),e.addChild(i);let a=new d({text:``,style:{fontSize:36,fill:9147550,fontFamily:`ui-monospace, monospace`}});a.scale.set(.25),a.x=2,a.y=2,e.addChild(a),this.world.addChild(e),r={container:e,terrainSprite:t,texLo:null,texHi:null,map2Graphics:n,ownerOverlay:i,ownerState:`none`,nameLabel:a}}return r.container.x=n.x*J,r.container.y=n.y*J,r.container.visible=!1,r.nameLabel.text=e,r.nameLabel.visible=this.showRoomNames&&this.zoom>=.5&&this.nameLabelShouldShow(n.x,n.y),this.updateNameLabelScale(r,this.zoom),r.badgeSprite&&(r.container.removeChild(r.badgeSprite),r.badgeSprite.destroy(),r.badgeSprite=void 0),r.mineralSprite&&(r.container.removeChild(r.mineralSprite),r.mineralSprite.destroy(),r.mineralSprite=void 0),r.mineralType=void 0,r.mineralDensity=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,r),r}nameLabelShouldShow(e,t){let n=this.worldBoundsSet;return!(n&&(e<n.minX||e>n.maxX||t<n.minY||t>n.maxY))}updateAllNameLabels(){let e=this.showRoomNames&&this.zoom>=.5;for(let[t,n]of this.activeRooms){if(!e){n.nameLabel.visible=!1;continue}let r=P(t);r&&(n.nameLabel.visible=this.nameLabelShouldShow(r.x,r.y))}}setupInteraction(){let e=this.app.canvas;e.style.touchAction=`none`,e.style.userSelect=`none`;let t=new Map;e.addEventListener(`pointermove`,n=>{if(!t.has(n.pointerId)){if(!this.isDragging&&!this.isPinching){let t=e.getBoundingClientRect();this.emitHover(n.clientX-t.left,n.clientY-t.top)}return}if(t.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.isPinching&&t.size===2){let n=[...t.values()],r=e.getBoundingClientRect(),i=(n[0].x+n[1].x)/2-r.left,a=(n[0].y+n[1].y)/2-r.top,o=Math.hypot(n[1].x-n[0].x,n[1].y-n[0].y),s=Math.max(Q,Math.min($,this.pinchStartScale*(o/this.pinchStartDist))),c=this.getLOD(),l=this.zoom>=Y,u=this.zoom>=X;this.world.scale.set(s),this.world.x=i-this.pinchPivotWorldX*s,this.world.y=a-this.pinchPivotWorldY*s,this.getLOD()!==c&&this.applyLOD(),(s>=Y!==l||s>=.5!==u)&&this.updateAllNameLabels(),this.updateAllRoomScales(s),this.callbacks.onZoomChanged?.(s),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode();return}if(this.isDragging){let e=n.clientX-this.dragStartX,t=n.clientY-this.dragStartY;(Math.abs(e)>3||Math.abs(t)>3)&&(this.hasDragged=!0);let r=this.worldBoundsSet;if(r){let n=this.world.scale.x,i=50-(r.maxX+1)*J*n,a=this.app.screen.width-50-r.minX*J*n,o=50-(r.maxY+1)*J*n,s=this.app.screen.height-50-r.minY*J*n;this.world.x=this.rubberBand(this.dragWorldX+e,i,a),this.world.y=this.rubberBand(this.dragWorldY+t,o,s)}else this.world.x=this.dragWorldX+e,this.world.y=this.dragWorldY+t}}),e.addEventListener(`pointerleave`,()=>{!this.isDragging&&!this.isPinching&&this.callbacks.onRoomHover(null)}),e.addEventListener(`pointerdown`,n=>{if(n.preventDefault(),this.isAnimating=!1,t.set(n.pointerId,{x:n.clientX,y:n.clientY}),e.setPointerCapture(n.pointerId),t.size>=2){this.isDragging=!1,this.isPinching=!0;let n=[...t.values()],r=e.getBoundingClientRect(),i=(n[0].x+n[1].x)/2-r.left,a=(n[0].y+n[1].y)/2-r.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=(i-this.world.x)/this.pinchStartScale,this.pinchPivotWorldY=(a-this.world.y)/this.pinchStartScale}else this.isPinching=!1,this.isDragging=!0,this.hasDragged=!1,this.dragStartX=n.clientX,this.dragStartY=n.clientY,this.dragWorldX=this.world.x,this.dragWorldY=this.world.y}),e.addEventListener(`pointerup`,n=>{if(t.delete(n.pointerId),e.releasePointerCapture(n.pointerId),this.isPinching){t.size<2&&(this.isPinching=!1,this.isDragging=!1,this.springBack());return}if(this.isDragging){if(this.isDragging=!1,!this.hasDragged){let t=e.getBoundingClientRect(),r=this.screenToRoom(n.clientX-t.left,n.clientY-t.top);r&&this.callbacks.onRoomClick(r)}this.springBack()}}),e.addEventListener(`pointercancel`,n=>{t.delete(n.pointerId),e.releasePointerCapture(n.pointerId),(this.isPinching||this.isDragging)&&(this.isPinching=!1,this.isDragging=!1,this.springBack())}),e.addEventListener(`wheel`,e=>{if(e.preventDefault(),this.isDragging||this.isPinching)return;this.isAnimating=!1;let t=this.world.scale.x,n=e.deltaY<0?1.1:.9,r=Math.max(Q,Math.min($,t*n));this.applyZoomAt(r,e.offsetX,e.offsetY)},{passive:!1})}rubberBand(e,t,n){let r=n-t;if(r<=0||e>=t&&e<=n)return e;let i=.55;return e<t?t-(1-1/((t-e)*i/r+1))*r*i:n+(1-1/((e-n)*i/r+1))*r*i}springBack(){let e=this.worldBoundsSet;if(!e)return;let t=this.world.scale.x,n=this.app.screen.width,r=this.app.screen.height,i=this.world.x+e.minX*J*t,a=this.world.x+(e.maxX+1)*J*t,o=this.world.y+e.minY*J*t,s=this.world.y+(e.maxY+1)*J*t,c=this.world.x,l=this.world.y;a<50?c+=50-a:i>n-50&&(c-=i-(n-50)),s<50?l+=50-s:o>r-50&&(l-=o-(r-50)),(c!==this.world.x||l!==this.world.y)&&(this.animTargetX=c,this.animTargetY=l,this.isAnimating=!0)}screenToRoom(e,t){let n=this.world.scale.x,r=(e-this.world.x)/n,i=(t-this.world.y)/n;return F(Math.floor(r/J),Math.floor(i/J))}emitHover(e,t){this.callbacks.onRoomHover(this.screenToRoom(e,t))}lastCheckX=0;lastCheckY=0;lastCheckScale=0;checkVisibleRooms(){let e=this.world.scale.x,t=this.world.x,n=this.world.y;if(this.lastCheckX===t&&this.lastCheckY===n&&this.lastCheckScale===e)return;this.lastCheckX=t,this.lastCheckY=n,this.lastCheckScale=e;let r=-t/e,i=-n/e,a=(this.app.screen.width-t)/e,o=(this.app.screen.height-n)/e,s=Math.floor(r/J)-1,c=Math.ceil(a/J),l=Math.floor(i/J)-1,u=Math.ceil(o/J);this.lastVisibleBounds={rxMin:s,rxMax:c,ryMin:l,ryMax:u};let d=[],f=this.worldBoundsSet,p=f?Math.max(s,f.minX):s,m=f?Math.min(c,f.maxX):c,h=f?Math.max(l,f.minY):l,g=f?Math.min(u,f.maxY):u;for(let e=p;e<=m;e++)for(let t=h;t<=g;t++){let n=F(e,t);n&&d.push(n)}let _=`${s},${l},${c},${u}`;_!==this.lastVisibleKey&&(this.lastVisibleKey=_,this.visibleDebounceTimer!==null&&clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=setTimeout(()=>{this.visibleDebounceTimer=null,this.callbacks.onVisibleRoomsChanged(d)},Yt))}};export{xe as $,ft as A,O as At,rt as B,ae as Bt,M as C,fe as Ct,nt as D,ze as Dt,et as E,D as Et,$e as F,He as Ft,ye as G,at as H,re as Ht,tt as I,ne as It,Se as J,_e as K,ht as L,ee as Lt,mt as M,qe as Mt,ot as N,Je as Nt,gt as O,Be as Ot,Qe as P,Ke as Pt,Te as Q,st as R,v as Rt,N as S,S as St,ut as T,Re as Tt,Ze as U,ie as Ut,pt as V,se as Vt,k as W,Ce as X,be as Y,we as Z,F as _,Ie as _t,Lt as a,Ne as at,bt as b,pe as bt,Ut as c,Me as ct,G as d,ke as dt,ve as et,Kt as f,We as ft,wt as g,Le as gt,Tt as h,Fe as ht,Gt as i,Pe as it,it as j,Ge as jt,ct as k,Ve as kt,Ht as l,De as lt,Dt as m,he as mt,X as n,h as nt,Bt as o,Ae as ot,Et as p,E as pt,Ee as q,Wt as r,ce as rt,zt as s,je as st,Zt as t,g as tt,Rt as u,Oe as ut,St as v,ge as vt,lt as w,Ue as wt,P as x,me as xt,Ct as y,b as yt,dt as z,oe as zt};
@@ -0,0 +1 @@
1
+ import{D as e,O as t,S as n,_ as r}from"./vendor-codemirror-B6f_i0wP.js";import{R as i,S as a,g as o,n as s,ot as c,st as l,x as u}from"./clientStore-arNZaq85.js";import{w as d}from"./src-JUwOmHaV.js";import{B as f,I as p,L as m,R as h,_ as g,b as _,h as v,p as y,t as b,v as x,x as S,y as C}from"./MapRenderer-BuhWaUfG.js";var w=c(`<div style=width:100%;height:100%;position:relative><canvas style=display:block>`),{log:T,error:E}=i(`map`);function D(i){let c,D=null,[O,k]=n([]),[A,j]=n(1),[M,N]=n(i.originRoom??null),P=null,F=null,I=new Map,L=new Map,R=new Map,z=new Map,B=e=>{let t=a();if(!t)return!0;let n=S(e);return!!n&&_(n.x,n.y,t)},V=e=>{let t=L.get(e),n=t?.own,r=t?.username??(n?.user?`user:${n.user}`:null),i=!!n&&n.level>=1,a=!!n&&n.level===0,o=t?.sign;return{room:e,owner:i?r:null,reservation:a?r:null,level:i?n.level:null,mineral:t?.mineral??null,density:t?.density??null,badge:t?.badge??null,sign:o?{text:o.text,datetime:o.datetime,username:o.username??(o.user?`user:${o.user}`:null),badge:o.badge??null}:null}},H=[],U=null,W=new Set,G=()=>{U=null;let e=s();if(!e||!D)return;let t=new Set(O());if(H=H.filter(e=>t.has(e)&&!D.hasRoom(e)&&!W.has(e)),H.length===0)return;let n=H.splice(0,200);for(let e of n)W.add(e);e.stores.room.terrainBulk(n,i.shard).then(async e=>{let t=[];for(let[n,r]of e){let e=D?.setRoomTerrain(n,r);e&&t.push(e);let i=R.get(n);i!==void 0&&D?.setRoomOwned(n,i);let a=L.get(n);a&&D?.setRoomMineral(n,a.mineral,a.density)}for(let t of n)e.has(t)||D?.markRoomFetched(t);await Promise.all(t)}).catch(e=>E(`terrain fetch failed:`,e)).finally(()=>{for(let e of n)W.delete(e);H.length>0&&(U=setTimeout(G,0))})};return r(()=>{s(),i.shard,L.clear(),R.clear(),W.clear(),D?.clearAllRooms()}),t(()=>{c&&(async()=>{if(D=new b({onRoomHover:e=>{i.onHoveredRoomChanged?.(e?V(e):null)},onRoomClick:e=>{M()===e?B(e)&&setTimeout(()=>i.onNavigateToRoom(e),0):(N(e),D?.setSelectedRoom(e),i.onSelectedRoomChanged?.(V(e)))},onVisibleRoomsChanged:e=>{let t=e.length===0;F!==t&&(F=t,T(t?`zoom out — too many rooms visible, terrain loading paused`:`zoom in — terrain loading active, ${e.length} rooms visible`)),k(e)},onZoomChanged:e=>{j(e),i.onZoomChanged?.(e)}}),await D.init(c),!D)return;i.initialZoom!==void 0&&i.initialZoom>0&&D.setZoom(i.initialZoom),i.onZoomChanged?.(D.zoom);let e=a();if(e&&D.setBounds(e.minX,e.maxX,e.minY,e.maxY),i.originRoom){let e=S(i.originRoom);e&&D.centerOn(e.x,e.y),D.setSelectedRoom(i.originRoom),i.onSelectedRoomChanged?.(V(i.originRoom))}else{let e=s();if(e)try{let t=await e.http.user.worldStartRoom(i.shard??`shard0`);if(!D)return;let n=Array.isArray(t?.room)?t.room[0]:t?.room;if(typeof n==`string`){let e=S(n);e&&D.centerOn(e.x,e.y)}}catch(e){E(`worldStartRoom failed:`,e)}}})()}),e(()=>{U!==null&&(clearTimeout(U),U=null),H=[],W.clear();for(let e of I.values())e.dispose();I.clear(),D?.destroy(),D=null}),r(()=>{v({currentRoom:M,worldBounds:a,onMove:(e,t)=>{let n=g(e,t);N(n),D?.setSelectedRoom(n),D?.centerOn(e,t,!0),i.onSelectedRoomChanged?.(V(n)),i.onHoveredRoomChanged?.(V(n))}});let t=e=>{let t=e.target?.tagName??``,n=e.target?.isContentEditable??!1;if(!(t===`INPUT`||t===`TEXTAREA`||n)&&e.key===`m`){let e=M();e&&B(e)&&i.onNavigateToRoom(e)}};window.addEventListener(`keydown`,t),e(()=>window.removeEventListener(`keydown`,t))}),r(()=>{let e=s(),t=O(),n=i.shard;if(!e||t.length===0)return;let r=new Set(t),a=t.filter(e=>!D?.hasRoom(e)&&!W.has(e));if(a.length>0){let e=t.reduce((e,t)=>e+(S(t)?.x??0),0)/t.length,n=t.reduce((e,t)=>e+(S(t)?.y??0),0)/t.length;H=a.slice().sort((t,r)=>{let i=S(t),a=S(r);return(i?Math.abs(i.x-e)+Math.abs(i.y-n):999)-(a?Math.abs(a.x-e)+Math.abs(a.y-n):999)}),U===null&&(U=setTimeout(G,0))}e.stores.mapStats.request(t,d.owner,n??void 0);let o=A()>=.4;if(o!==P&&(P=o,i.onSubscriptionStateChanged?.(o),o||D?.clearAllMap2()),o){let r=new Set(t.map(e=>`${e}/${n}`));for(let[e,t]of I)r.has(e)||(t.dispose(),I.delete(e),D?.clearRoomMap2(e.split(`/`)[0]));for(let r of t){let t=`${r}/${n}`;I.has(t)||I.set(t,e.stores.map.subscribeMap2(r,n))}}else{for(let[,e]of I)e.dispose();I.clear()}D?.clearInvisibleRooms(r)}),r(()=>{D?.setShowRoomNames(p()),D&&(D.currentShard=i.shard??`shard0`)}),r(()=>{D?.setUnclaimableOverlayVisible(f())}),r(()=>{D?.setMapVisualVisible(m())}),r(()=>{D?.setOverlayMode(y())}),r(()=>{D?.setDecorationsVisible(h())}),r(()=>{let e=s(),t=O(),n=i.shard;!e||t.length===0||y()!==`mineral`||e.stores.mapStats.request(t,d.minerals,n??void 0)}),r(()=>{let e=s(),t=i.shard;e&&e.stores.server.worldInfo(t??void 0).then(e=>{T(`worldInfo(shard=${t??`none`}) — x: [${e.minX}, ${e.maxX}] y: [${e.minY}, ${e.maxY}]`),o(e)}).catch(e=>{T(`worldInfo(shard=${t??`none`}) failed:`,e)})}),r(()=>{D?.setCurrentUser(u()?._id??null)}),r(()=>{let e=a();e?(D?.setBounds(e.minX,e.maxX,e.minY,e.maxY),T(`worldBounds applied — shard: ${i.shard??`none`} x: [${e.minX}, ${e.maxX}] y: [${e.minY}, ${e.maxY}] (fetched for shard: ${e.shard??`none`})`)):(D?.clearBounds(),T(`worldBounds — none (shard: ${i.shard??`none`})`))}),r(()=>{let t=s();if(!t)return;let n=t.stores.user.subscribeMapVisual(i.shard),r=t.stores.user.on(`user:mapVisual`,({shard:e,data:t})=>{e===i.shard&&(t?D?.setMapVisual(t):D?.clearMapVisual())});e(()=>{n.dispose(),r.dispose()})}),r(()=>{let t=s();if(!t)return;let n=t.stores.map.on(`room:map2update`,({room:e,shard:t,data:n,source:r})=>{t===i.shard&&D?.setRoomMap2(e,n,r)});e(()=>n.dispose())}),r(()=>{let t=s();if(!t)return;let n=u()?._id,r=new Set(O()),a=t.stores.mapStats.on(`mapStats:room`,({room:e,stat:t,statName:a})=>{let o=L.get(e);if(a===d.minerals)L.set(e,{...o,mineral:t.mineral,density:t.density}),D?.setRoomMineral(e,t.mineral,t.density);else{let i={...t,mineral:o?.mineral,density:o?.density};L.set(e,i);let a=S(e),s=a?x(a.x,a.y)||C(a.x,a.y):!1,c=t.status===`out of borders`,l=!!(t.own&&t.own.user===n),u=!!(t.own&&t.own.user!==n),d=l?`own`:c?`prohibited`:s||u?`other`:`none`;R.set(e,d),r.has(e)&&(D?.setRoomOwned(e,d),D?.setRoomSafeMode(e,!!t.safeMode)),o?.mineral!==void 0&&D?.setRoomMineral(e,o.mineral,o.density),D?.setRoomDecoration(e,t.terrainColors);let f=t.badge?JSON.stringify(t.badge):``;z.get(e)!==f&&(z.set(e,f),D?.setRoomBadge(e,t.badge,t.own?.level))}M()===e&&i.onSelectedRoomChanged?.(V(e))});e(()=>a.dispose())}),(()=>{var e=w(),t=e.firstChild;return l(e=>c=e,t),e})()}export{D as MapViewer};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_client/dist-js-wcmIejjc.js","_client/core-BpboMUoB.js","_client/src-C7OP3M2f.js","_client/src-JUwOmHaV.js","_client/vendor-pixi-QLQyXP3g.js","_client/rolldown-runtime-Bh1tDfsg.js","_client/decompress-CWkNrR0q.js","_client/dist-js-CNTp3ssl.js"])))=>i.map(i=>d[i]);
2
+ import{A as e,S as t,j as n,k as r,s as i,v as a,x as o,y as s}from"./vendor-codemirror-B6f_i0wP.js";import{x as c}from"./vendor-pixi-QLQyXP3g.js";import{S as l,_ as u,b as d,x as ee,y as te}from"./src-JUwOmHaV.js";import{t as f}from"./core-BpboMUoB.js";var ne=new Set([`className`,`value`,`readOnly`,`noValidate`,`formNoValidate`,`isMap`,`noModule`,`playsInline`,`adAuctionHeaders`,`allowFullscreen`,`browsingTopics`,`defaultChecked`,`defaultMuted`,`defaultSelected`,`disablePictureInPicture`,`disableRemotePlayback`,`preservesPitch`,`shadowRootClonable`,`shadowRootCustomElementRegistry`,`shadowRootDelegatesFocus`,`shadowRootSerializable`,`sharedStorageWritable`,...`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`.split(`.`)]),re=new Set([`innerHTML`,`textContent`,`innerText`,`children`]),ie=Object.assign(Object.create(null),{className:`class`,htmlFor:`for`}),ae=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 oe(e,t){let n=ae[e];return typeof n==`object`?n[t]?n.$:void 0:n}var se=new Set([`beforeinput`,`click`,`dblclick`,`contextmenu`,`focusin`,`focusout`,`input`,`keydown`,`keyup`,`mousedown`,`mousemove`,`mouseout`,`mouseover`,`mouseup`,`pointerdown`,`pointermove`,`pointerout`,`pointerover`,`pointerup`,`touchend`,`touchmove`,`touchstart`]),ce=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`.split(`.`)),le={xlink:`http://www.w3.org/1999/xlink`,xml:`http://www.w3.org/XML/1998/namespace`},ue=e=>a(()=>e());function de(e,t,n){let r=n.length,i=t.length,a=r,o=0,s=0,c=t[i-1].nextSibling,l=null;for(;o<i||s<a;){if(t[o]===n[s]){o++,s++;continue}for(;t[i-1]===n[a-1];)i--,a--;if(i===o){let t=a<r?s?n[s-1].nextSibling:n[a-s]:c;for(;s<a;)e.insertBefore(n[s++],t)}else if(a===s)for(;o<i;)(!l||!l.has(t[o]))&&t[o].remove(),o++;else if(t[o]===n[a-1]&&n[s]===t[i-1]){let r=t[--i].nextSibling;e.insertBefore(n[s++],t[o++].nextSibling),e.insertBefore(n[--a],r),t[i]=n[a]}else{if(!l){l=new Map;let e=s;for(;e<a;)l.set(n[e],e++)}let r=l.get(t[o]);if(r!=null)if(s<r&&r<a){let c=o,u=1,d;for(;++c<i&&c<a&&!((d=l.get(t[c]))==null||d!==r+u);)u++;if(u>r-s){let i=t[o];for(;s<r;)e.insertBefore(n[s++],i)}else e.replaceChild(n[s++],t[o++])}else o++;else t[o++].remove()}}}var p=`_$DX_DELEGATE`;function fe(e,t,n,r={}){if(!t)throw Error("The `element` passed to `render(..., element)` doesn't exist. Make sure `element` exists in the document.");let i;return o(r=>{i=r,t===document?e():we(t,e(),t.firstChild?null:void 0,n)},r.owner),()=>{i(),t.textContent=``}}function pe(e,t,r,i){let a,o=()=>{if(h())throw Error(`Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration.`);let t=i?document.createElementNS(`http://www.w3.org/1998/Math/MathML`,`template`):document.createElement(`template`);return t.innerHTML=e,r?t.content.firstChild.firstChild:i?t.firstChild:t.content.firstChild},s=t?()=>n(()=>document.importNode(a||=o(),!0)):()=>(a||=o()).cloneNode(!0);return s.cloneNode=s,s}function me(e,t=window.document){let n=t[p]||(t[p]=new Set);for(let r=0,i=e.length;r<i;r++){let i=e[r];n.has(i)||(n.add(i),t.addEventListener(i,Ae))}}function m(e,t,n){h(e)||(n==null?e.removeAttribute(t):e.setAttribute(t,n))}function he(e,t,n,r){h(e)||(r==null?e.removeAttributeNS(t,n):e.setAttributeNS(t,n,r))}function ge(e,t,n){h(e)||(n?e.setAttribute(t,``):e.removeAttribute(t))}function _e(e,t){h(e)||(t==null?e.removeAttribute(`class`):e.className=t)}function ve(e,t,n,r){if(r)Array.isArray(n)?(e[`$$${t}`]=n[0],e[`$$${t}Data`]=n[1]):e[`$$${t}`]=n;else if(Array.isArray(n)){let r=n[0];e.addEventListener(t,n[0]=t=>r.call(e,n[1],t))}else e.addEventListener(t,n,typeof n!=`function`&&n)}function ye(e,t,n={}){let r=Object.keys(t||{}),i=Object.keys(n),a,o;for(a=0,o=i.length;a<o;a++){let r=i[a];!r||r===`undefined`||t[r]||(Oe(e,r,!1),delete n[r])}for(a=0,o=r.length;a<o;a++){let i=r[a],o=!!t[i];!i||i===`undefined`||n[i]===o||!o||(Oe(e,i,!0),n[i]=o)}return n}function be(e,t,n){if(!t)return n?m(e,`style`):t;let r=e.style;if(typeof t==`string`)return r.cssText=t;typeof n==`string`&&(r.cssText=n=void 0),n||={},t||={};let i,a;for(a in n)t[a]??r.removeProperty(a),delete n[a];for(a in t)i=t[a],i!==n[a]&&(r.setProperty(a,i),n[a]=i);return n}function xe(e,t,n){n==null?e.style.removeProperty(t):e.style.setProperty(t,n)}function Se(e,t={},n,r){let i={};return r||s(()=>i.children=g(e,t.children,i.children)),s(()=>typeof t.ref==`function`&&Ce(t.ref,e)),s(()=>Te(e,t,n,!0,i,!0)),i}function Ce(e,t,r){return n(()=>e(t,r))}function we(e,t,n,r){if(n!==void 0&&!r&&(r=[]),typeof t!=`function`)return g(e,t,r,n);s(r=>g(e,t(),r,n),r)}function Te(e,t,n,r,i={},a=!1){t||={};for(let r in i)if(!(r in t)){if(r===`children`)continue;i[r]=ke(e,r,null,i[r],n,a,t)}for(let o in t){if(o===`children`){r||g(e,t.children);continue}let s=t[o];i[o]=ke(e,o,s,i[o],n,a,t)}}function Ee(e){let t,n,i=h();if(!i||!(t=r.registry.get(n=je()))){if(i)throw r.done=!0,Error(`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${n}\n${e?e().outerHTML:``}`);return e()}return r.completed&&r.completed.add(t),r.registry.delete(n),t}function h(e){return!!r.context&&!r.done&&(!e||e.isConnected)}function De(e){return e.toLowerCase().replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function Oe(e,t,n){let r=t.trim().split(/\s+/);for(let t=0,i=r.length;t<i;t++)e.classList.toggle(r[t],n)}function ke(e,t,n,r,i,a,o){let s,c,l,u,d;if(t===`style`)return be(e,n,r);if(t===`classList`)return ye(e,n,r);if(n===r)return r;if(t===`ref`)a||n(e);else if(t.slice(0,3)===`on:`){let i=t.slice(3);r&&e.removeEventListener(i,r,typeof r!=`function`&&r),n&&e.addEventListener(i,n,typeof n!=`function`&&n)}else if(t.slice(0,10)===`oncapture:`){let i=t.slice(10);r&&e.removeEventListener(i,r,!0),n&&e.addEventListener(i,n,!0)}else if(t.slice(0,2)===`on`){let i=t.slice(2).toLowerCase(),a=se.has(i);if(!a&&r){let t=Array.isArray(r)?r[0]:r;e.removeEventListener(i,t)}(a||n)&&(ve(e,i,n,a),a&&me([i]))}else if(t.slice(0,5)===`attr:`)m(e,t.slice(5),n);else if(t.slice(0,5)===`bool:`)ge(e,t.slice(5),n);else if((d=t.slice(0,5)===`prop:`)||(l=re.has(t))||!i&&((u=oe(t,e.tagName))||(c=ne.has(t)))||(s=e.nodeName.includes(`-`)||`is`in o)){if(d)t=t.slice(5),c=!0;else if(h(e))return n;t===`class`||t===`className`?_e(e,n):s&&!c&&!l?e[De(t)]=n:e[u||t]=n}else{let r=i&&t.indexOf(`:`)>-1&&le[t.split(`:`)[0]];r?he(e,r,t,n):m(e,ie[t]||t,n)}return n}function Ae(e){if(r.registry&&r.events&&r.events.find(([t,n])=>n===e))return;let t=e.target,n=`$$${e.type}`,i=e.target,a=e.currentTarget,o=t=>Object.defineProperty(e,"target",{configurable:!0,value:t}),s=()=>{let r=t[n];if(r&&!t.disabled){let i=t[`${n}Data`];if(i===void 0?r.call(t,e):r.call(t,i,e),e.cancelBubble)return}return t.host&&typeof t.host!=`string`&&!t.host._$host&&t.contains(e.target)&&o(t.host),!0},c=()=>{for(;s()&&(t=t._$host||t.parentNode||t.host););};if(Object.defineProperty(e,"currentTarget",{configurable:!0,get(){return t||document}}),r.registry&&!r.done&&(r.done=_$HY.done=!0),e.composedPath){let n=e.composedPath();o(n[0]);for(let e=0;e<n.length-2&&(t=n[e],s());e++){if(t._$host){t=t._$host,c();break}if(t.parentNode===a)break}}else c();o(i)}function g(e,t,n,r,i){let a=h(e);if(a){!n&&(n=[...e.childNodes]);let t=[];for(let e=0;e<n.length;e++){let r=n[e];r.nodeType===8&&r.data.slice(0,2)===`!$`?r.remove():t.push(r)}n=t}for(;typeof n==`function`;)n=n();if(t===n)return n;let o=typeof t,c=r!==void 0;if(e=c&&n[0]&&n[0].parentNode||e,o===`string`||o===`number`){if(a||o===`number`&&(t=t.toString(),t===n))return n;if(c){let i=n[0];i&&i.nodeType===3?i.data!==t&&(i.data=t):i=document.createTextNode(t),n=y(e,n,r,i)}else n=n!==``&&typeof n==`string`?e.firstChild.data=t:e.textContent=t}else if(t==null||o===`boolean`){if(a)return n;n=y(e,n,r)}else if(o===`function`)return s(()=>{let i=t();for(;typeof i==`function`;)i=i();n=g(e,i,n,r)}),()=>n;else if(Array.isArray(t)){let o=[],l=n&&Array.isArray(n);if(_(o,t,n,i))return s(()=>n=g(e,o,n,r,!0)),()=>n;if(a){if(!o.length)return n;if(r===void 0)return n=[...e.childNodes];let t=o[0];if(t.parentNode!==e)return n;let i=[t];for(;(t=t.nextSibling)!==r;)i.push(t);return n=i}if(o.length===0){if(n=y(e,n,r),c)return n}else l?n.length===0?v(e,o,r):de(e,n,o):(n&&y(e),v(e,o));n=o}else if(t.nodeType){if(a&&t.parentNode)return n=c?[t]:t;if(Array.isArray(n)){if(c)return n=y(e,n,r,t);y(e,n,null,t)}else n==null||n===``||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);n=t}else console.warn(`Unrecognized value. Skipped inserting`,t);return n}function _(e,t,n,r){let i=!1;for(let a=0,o=t.length;a<o;a++){let o=t[a],s=n&&n[e.length],c;if(!(o==null||o===!0||o===!1))if((c=typeof o)==`object`&&o.nodeType)e.push(o);else if(Array.isArray(o))i=_(e,o,s)||i;else if(c===`function`)if(r){for(;typeof o==`function`;)o=o();i=_(e,Array.isArray(o)?o:[o],Array.isArray(s)?s:[s])||i}else e.push(o),i=!0;else{let t=String(o);s&&s.nodeType===3&&s.data===t?e.push(s):e.push(document.createTextNode(t))}}return i}function v(e,t,n=null){for(let r=0,i=t.length;r<i;r++)e.insertBefore(t[r],n)}function y(e,t,n,r){if(n===void 0)return e.textContent=``;let i=r||document.createTextNode(``);if(t.length){let r=!1;for(let a=t.length-1;a>=0;a--){let o=t[a];if(i!==o){let t=o.parentNode===e;!r&&!a?t?e.replaceChild(i,o):e.insertBefore(i,n):t&&o.remove()}else r=!0}}else e.insertBefore(i,n);return[i]}function je(){return r.getNextContextId()}var Me=`http://www.w3.org/2000/svg`;function Ne(e,t=!1,n=void 0){return t?document.createElementNS(Me,e):document.createElement(e,{is:n})}function Pe(e,t){let o=a(e);return a(()=>{let e=o();switch(typeof e){case`function`:return Object.assign(e,{[i]:!0}),n(()=>e(t));case`string`:let a=ce.has(e),o=r.context?Ee():Ne(e,a,n(()=>t.is));return Se(o,t,a),o}})}function Fe(t){let[,n]=e(t,[`component`]);return Pe(()=>t.component,n)}function b(){return typeof window<`u`&&window.__TAURI_INTERNALS__!=null}var x=!1;async function Ie(){if(x)return;let[{fetch:e},{setFetch:t}]=await Promise.all([c(()=>import(`./dist-js-wcmIejjc.js`),__vite__mapDeps([0,1])),c(()=>import(`./src-C7OP3M2f.js`),__vite__mapDeps([2,3,4,5,6]))]);t(e),x=!0}async function Le(e){if(b()){let{openUrl:t}=await c(async()=>{let{openUrl:e}=await import(`./dist-js-CNTp3ssl.js`);return{openUrl:e}},__vite__mapDeps([7,1]));await t(e)}else window.open(e,`_blank`,`noopener,noreferrer`)}var[Re,S]=t([]),ze=0;function C(e,t=`success`,n=4e3){let r=ze++;S(i=>[...i,{id:r,message:e,type:t,duration:n}]),setTimeout(()=>{S(e=>e.filter(e=>e.id!==r))},n)}var Be=!1;function w(){return!0}function Ve(){return Be}function T(){return window.location.origin}function He(){return`0.14.1`}function Ue(){return typeof window>`u`?null:window.__SCREEPS_CLIENT_EMBEDDED__??null}function We(){let e=`/client/`;return e.startsWith(`.`)?``:e.replace(/\/$/,``)}function E(e){let t=`[${e}]`;return{log:()=>{},warn:()=>{},error:(...e)=>console.error(t,...e)}}function D(){return b()?localStorage:sessionStorage}var Ge={room:`screeps:room`,shard:`screeps:shard`,sidebarWidth:`screeps:sidebarWidth`,consoleHeight:`screeps:consoleHeight`,consoleSplit:`screeps:consoleSplit`,consoleWeights:`screeps:consoleWeights`,memoryWatches:`screeps:memoryWatches`,mapZoom:`screeps:mapZoom`,widescreenMode:`screeps:settings:widescreenMode`,showCreepLabels:`screeps:settings:showCreepLabels`,showMapRoomNames:`screeps:settings:showMapRoomNames`,showUnclaimableRooms:`screeps:settings:showUnclaimableRooms`,terrainEffects:`screeps:settings:terrainEffects`,showRoomDecorations:`screeps:settings:showRoomDecorations`,roomDarkOverlay:`screeps:settings:roomDarkOverlay`,showRoomVisuals:`screeps:settings:showRoomVisuals`,spriteTheme:`screeps:settings:spriteTheme`,showMapVisuals:`screeps:settings:showMapVisuals`},O={url:`screeps:url`,token:`screeps:token`,serverPassword:`screeps:serverPassword`,authMethod:`screeps:authMethod`};function Ke(e){return localStorage.getItem(e)}function qe(e,t){localStorage.setItem(e,t)}function Je(e){localStorage.removeItem(e)}function Ye(e,t){let n=localStorage.getItem(e);if(n===null)return t;let r=Number(n);return Number.isFinite(r)&&r!==0?r:t}function Xe(e,t){localStorage.setItem(e,String(t))}function Ze(e,t){let n=localStorage.getItem(e);if(n===null)return t;try{return JSON.parse(n)}catch{return t}}function Qe(e,t){localStorage.setItem(e,JSON.stringify(t))}function k(e){return D().getItem(e)}function A(e,t){D().setItem(e,t)}function j(e){D().removeItem(e)}async function $e(){if(localStorage.clear(),indexedDB.databases){let e=await indexedDB.databases();await Promise.all(e.map(e=>e.name?new Promise(t=>{let n=indexedDB.deleteDatabase(e.name);n.onsuccess=()=>t(),n.onerror=()=>t(),n.onblocked=()=>t()}):Promise.resolve()))}if(`caches`in window){let e=await caches.keys();await Promise.all(e.map(e=>caches.delete(e)))}}var{log:M}=E(`keychain`),N=`screeps-desktop`;async function P(e,t){M(`save [${e}]`);try{await f(`keyring_set`,{service:N,account:e,secret:t}),M(`save [${e}] ✓`)}catch(t){throw M(`save [${e}] ✗`,t),t}}async function F(e){M(`load [${e}]`);try{let t=await f(`keyring_get`,{service:N,account:e});return M(`load [${e}] →`,t===null?`[not found]`:`[found]`),t}catch(t){throw M(`load [${e}] ✗`,t),t}}async function I(e){M(`delete [${e}]`);try{await f(`keyring_delete`,{service:N,account:e}),M(`delete [${e}] ✓`)}catch(t){throw M(`delete [${e}] ✗`,t),t}}var L=e=>`${e}:token`,R=e=>`${e}:serverPassword`,z=e=>`${e}:savedCredential`;async function et(e,t){b()&&await P(L(e),t)}async function tt(e){return b()?F(L(e)):null}async function nt(e){b()&&await I(L(e))}async function rt(e,t){b()&&await P(R(e),t)}async function it(e){return b()?F(R(e)):null}async function at(e){b()&&await I(R(e))}async function ot(e,t){b()&&await P(z(e),t)}async function st(e){return b()?F(z(e)):null}async function ct(e){b()&&await I(z(e))}var{log:B}=E(`client`),[V,H]=t(null),[lt,U]=t(`idle`),[ut,W]=t(null),[dt,G]=t(null),[ft,K]=t(null),[pt,mt]=t(null),[ht,gt]=t(null),[_t,vt]=t(null),[yt,bt]=t(null),[xt,St]=t(!1),[Ct,wt]=t(null),[Tt,Et]=t(null),[Dt,Ot]=t({}),[kt,At]=t(null),jt=1e3,Mt=15e3,q=null,J=0;function Nt(){q===null&&(B(`world status polling: start`),q=setInterval(()=>{let e=V();e&&e.stores.user.refreshWorldStatus().catch(()=>{})},jt))}function Pt(){q!==null&&(B(`world status polling: stop`),clearInterval(q),q=null)}function Y(e){e===`empty`||e===`lost`||Date.now()<J?Nt():Pt()}function Ft(){J=Date.now()+Mt,Nt()}var X=-1,Z=-1,Q=[],It=5;function Lt(e){if(e===void 0)return;let t=Date.now();if(X>=0&&e>X){let e=t-Z;if(e>0){Q.push(e),Q.length>It&&Q.shift();let t=Q.reduce((e,t)=>e+t,0)/Q.length;bt(Math.round(t))}}X=e,Z=t}function Rt(){X=-1,Z=-1,Q.length=0,bt(null)}var zt=()=>{let e=ht();return e?(e.serverData?.shards?.length??0)===0:null};async function $(e){w()&&(e={...e,url:T()}),B(`connecting to ${e.url} (auth: ${e.auth})`),U(`connecting`),W(null),G(null),K(null);try{let t;if(e.auth===`guest`)t=new te,St(!0);else if(e.auth===`password`){if(!e.email||!e.password)throw Error(`Email and password are required`);t=new d({email:e.email,password:e.password})}else{if(!e.token)throw Error(`Token is required`);let n=e.authMethod===`steam`||e.authMethod===`password`;t=new ee({token:e.token,supportsTokenRefresh:n})}let n=new l({url:e.url,auth:t,storage:e.storage??new u(`screeps-client`),debug:!1,serverPassword:e.serverPassword});n.http.on(`http:tokenRefresh`,({token:t})=>{B(`token refreshed`),b()?et(e.url,t):A(O.token,t)}),n.http.on(`http:error`,({method:e,path:t,error:n,silent:r,status:i})=>{if(B(`http error:`,e,t,n.message),i===429){let e=n.message.match(/https?:\/\/\S+/);K({message:n.message.replace(/^HTTP 429:\s*/,``),disableLink:e?e[0]:null});return}r||C(`Request failed: ${e} ${t} — ${n.message}`,`error`,6e3)}),n.stores.server.on(`server:disconnected`,e=>{B(`server disconnected (willReconnect: ${e.willReconnect})`),e.willReconnect||(J=0,Y(null),G(`Lost connection to the server.`))}),n.stores.server.on(`server:error`,e=>{B(`server error:`,e.error.message),G(e.error.message)}),n.stores.user.on(`user:me`,e=>{B(`user: ${e.username} (id: ${e._id})`),mt(e)}),n.stores.server.on(`server:version`,e=>{B(`server version: ${e.package??`unknown`}`),gt(e)}),n.stores.user.on(`user:stream`,e=>{if(e&&typeof e==`object`&&`flags`in e){let t=e.flags;t&&typeof t==`object`&&Ot(t)}}),n.stores.user.on(`user:worldStatus`,({status:e})=>{B(`world status: ${e}`),At(e),Y(e)}),await n.connect(),n.stores.user.subscribeUserStream(),H(n),U(`connected`),B(`connected to ${e.url}`),A(O.url,e.url);let r=e.authMethod??e.auth;wt(r),A(O.authMethod,r),n.http.token&&(b()?await et(e.url,n.http.token):A(O.token,n.http.token)),e.serverPassword?b()?await rt(e.url,e.serverPassword):A(O.serverPassword,e.serverPassword):b()?at(e.url):j(O.serverPassword)}catch(e){let t=e instanceof Error?e.message:String(e);throw B(`connection failed:`,t),W(t),U(`error`),H(null),e}}async function Bt(){let e=w()?T():k(O.url);if(!e)return;let t,n;if(b()?(t=await tt(e),n=await it(e)??void 0):(t=k(O.token),n=k(O.serverPassword)??void 0),!t)return;let r=k(O.authMethod);B(`auto-connect: ${e}`);try{t===`guest`?await $({url:e,auth:`guest`,storage:null,serverPassword:n}):await $({url:e,auth:`token`,token:t,serverPassword:n,authMethod:r??`token`})}catch{B(`auto-connect failed — clearing stored token`),b()?nt(e):j(O.token)}}function Vt(){if(B(`disconnecting`),b()){let e=k(O.url),t=Ct();e&&t!==`token`&&nt(e)}let e=V();e&&e.disconnect(),H(null),U(`idle`),W(null),G(null),K(null),mt(null),gt(null),vt(null),St(!1),wt(null),Et(null),Ot({}),At(null),J=0,Y(null),Rt(),b()?j(O.authMethod):(j(O.token),j(O.url),j(O.serverPassword),j(O.authMethod))}export{we as $,Ze as A,He as B,kt as C,Ge as D,ot as E,Qe as F,C as G,T as H,Xe as I,b as J,Re as K,qe as L,k as M,Ke as N,O,Je as P,me as Q,E as R,Tt as S,st as T,w as U,Ue as V,Ve as W,Fe as X,Le as Y,ve as Z,lt as _,ut as a,be as at,Dt as b,xt as c,Lt as d,ue as et,ht as f,Et as g,K as h,Vt as i,Se as it,Ye as j,$e as k,zt as l,vt as m,V as n,m as nt,Ft as o,pe as ot,dt as p,Ie as q,$ as r,xe as rt,_t as s,Ce as st,Ct as t,fe as tt,ft as u,yt as v,ct as w,pt as x,Bt as y,We as z};
@@ -0,0 +1 @@
1
+ import{t as e}from"./core-BpboMUoB.js";async function t(t,n){await e(`plugin:opener|open_url`,{url:t,with:n})}export{t as openUrl};