screeps-client 0.3.5 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,7 +19,7 @@
19
19
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
20
20
  }
21
21
  </style>
22
- <script type="module" crossorigin src="/assets/index-DlCmDpPr.js"></script>
22
+ <script type="module" crossorigin src="/assets/index-Cd5zMBNk.js"></script>
23
23
  <link rel="modulepreload" crossorigin href="/assets/vendor-codemirror-D3PB7yT8.js">
24
24
  <link rel="modulepreload" crossorigin href="/assets/vendor-pixi-CXkRT4gi.js">
25
25
  </head>
@@ -1 +1 @@
1
- import{c as E,a as w,i as r,s as c,u as ee,b as te,t as u,d as oe}from"./index-DlCmDpPr.js";import{l as f,e as ie,g as ne,c as re,t as le,h as P,f as b,j as $,F as R,S as L,n as de,E as se}from"./vendor-codemirror-D3PB7yT8.js";import"./vendor-pixi-CXkRT4gi.js";var ae=u("<span style=font-size:11px;color:#e3b341>Unsaved changes"),ce=u('<div style="padding:12px 10px;font-size:12px;color:#484f58;font-style:italic">Loading…'),fe=u("<div style=flex:1;display:flex;align-items:center;justify-content:center;color:#484f58;font-size:13px;font-style:italic>"),ue=u('<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>'),pe=u("<option>"),xe=u('<div style="padding:7px 12px;font-size:12px;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis">');const{error:j}=te("code"),ve=se.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"}}),he=[re,de(),le,ve];function ye(W){const[A,G]=f([]),[k,F]=f(""),[m,S]=f({}),[d,C]=f(""),[_,M]=f(!1),[p,B]=f(!1),[x,z]=f(!1),J=()=>Object.keys(m()),{editorView:U,ref:q,createExtension:H}=ie({onValueChange:o=>{const t=d();!t||m()[t]===o||(S(n=>({...n,[t]:o})),z(!0))}});ne(U,()=>m()[d()]??""),H(he),P(()=>{const o=E();o&&o.http.user.branches().then(t=>{G(t.list);const n=t.list.find(s=>s.activeWorld)??t.list[0];n&&F(n.branch)}).catch(t=>{j("branches failed:",t),w("Failed to load branches","error")})}),P(()=>{const o=k(),t=E();!o||!t||(M(!0),S({}),C(""),z(!1),t.http.user.code.get(o).then(n=>{const s=n.modules??{};S(s),C(Object.keys(s)[0]??"")}).catch(n=>{j("get failed:",n),w("Failed to load code","error")}).finally(()=>M(!1)))});const I=()=>{const o=E(),t=k();!o||!t||(B(!0),o.http.user.code.set(t,m()).then(()=>{w("Code saved","success"),z(!1)}).catch(n=>{j("set failed:",n),w("Failed to save code","error")}).finally(()=>B(!1)))};return(()=>{var o=ue(),t=o.firstChild,n=t.firstChild,s=n.nextSibling,K=s.nextSibling,a=K.nextSibling,Q=a.nextSibling,X=t.nextSibling,V=X.firstChild,Y=V.firstChild,T=Y.nextSibling,D=V.nextSibling,y=D.firstChild,Z=y.firstChild,N=y.nextSibling;return s.addEventListener("change",e=>F(e.currentTarget.value)),r(s,b(R,{get each(){return A()},children:e=>(()=>{var i=pe();return r(i,()=>e.branch,null),r(i,()=>e.activeWorld?" ★":"",null),$(()=>i.value=e.branch),i})()})),r(t,b(L,{get when(){return x()},get children(){return ae()}}),a),a.$$click=I,r(a,()=>p()?"Saving…":"Save"),Q.$$click=()=>W.onClose(),r(T,b(L,{get when(){return _()},get children(){return ce()}}),null),r(T,b(R,{get each(){return J()},children:e=>(()=>{var i=xe();return i.$$click=()=>C(e),r(i,e),$(l=>{var v=d()===e?"#1f3158":"transparent",h=d()===e?"#58a6ff":"#c9d1d9",g=`2px solid ${d()===e?"#388bfd":"transparent"}`;return v!==l.e&&c(i,"background",l.e=v),h!==l.t&&c(i,"color",l.t=h),g!==l.a&&c(i,"border-left",l.a=g),l},{e:void 0,t:void 0,a:void 0}),i})()}),null),r(y,d,Z),ee(q,N),r(D,b(L,{get when(){return!d()},get children(){var e=fe();return r(e,()=>_()?"Loading code…":"Select a module"),e}}),null),$(e=>{var i=p()||_()||!x(),l=p()||!x()?"#161b22":"#1a3a2a",v=p()||!x()?"#484f58":"#3fb950",h=p()||!x()?"default":"pointer",g=d()?"block":"none",O=d()?"flex":"none";return i!==e.e&&(a.disabled=e.e=i),l!==e.t&&c(a,"background",e.t=l),v!==e.a&&c(a,"color",e.a=v),h!==e.o&&c(a,"cursor",e.o=h),g!==e.i&&c(y,"display",e.i=g),O!==e.n&&c(N,"display",e.n=O),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),$(()=>s.value=k()),o})()}oe(["click"]);export{ye as CodePanel};
1
+ import{c as E,a as w,i as r,s as c,u as ee,b as te,t as u,d as oe}from"./index-D5eNG4b5.js";import{l as f,e as ie,g as ne,c as re,t as le,h as P,f as b,j as $,F as R,S as L,n as de,E as se}from"./vendor-codemirror-D3PB7yT8.js";import"./vendor-pixi-CXkRT4gi.js";var ae=u("<span style=font-size:11px;color:#e3b341>Unsaved changes"),ce=u('<div style="padding:12px 10px;font-size:12px;color:#484f58;font-style:italic">Loading…'),fe=u("<div style=flex:1;display:flex;align-items:center;justify-content:center;color:#484f58;font-size:13px;font-style:italic>"),ue=u('<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>'),pe=u("<option>"),xe=u('<div style="padding:7px 12px;font-size:12px;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis">');const{error:j}=te("code"),ve=se.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"}}),he=[re,de(),le,ve];function ye(W){const[A,G]=f([]),[k,F]=f(""),[m,S]=f({}),[d,C]=f(""),[_,M]=f(!1),[p,B]=f(!1),[x,z]=f(!1),J=()=>Object.keys(m()),{editorView:U,ref:q,createExtension:H}=ie({onValueChange:o=>{const t=d();!t||m()[t]===o||(S(n=>({...n,[t]:o})),z(!0))}});ne(U,()=>m()[d()]??""),H(he),P(()=>{const o=E();o&&o.http.user.branches().then(t=>{G(t.list);const n=t.list.find(s=>s.activeWorld)??t.list[0];n&&F(n.branch)}).catch(t=>{j("branches failed:",t),w("Failed to load branches","error")})}),P(()=>{const o=k(),t=E();!o||!t||(M(!0),S({}),C(""),z(!1),t.http.user.code.get(o).then(n=>{const s=n.modules??{};S(s),C(Object.keys(s)[0]??"")}).catch(n=>{j("get failed:",n),w("Failed to load code","error")}).finally(()=>M(!1)))});const I=()=>{const o=E(),t=k();!o||!t||(B(!0),o.http.user.code.set(t,m()).then(()=>{w("Code saved","success"),z(!1)}).catch(n=>{j("set failed:",n),w("Failed to save code","error")}).finally(()=>B(!1)))};return(()=>{var o=ue(),t=o.firstChild,n=t.firstChild,s=n.nextSibling,K=s.nextSibling,a=K.nextSibling,Q=a.nextSibling,X=t.nextSibling,V=X.firstChild,Y=V.firstChild,T=Y.nextSibling,D=V.nextSibling,y=D.firstChild,Z=y.firstChild,N=y.nextSibling;return s.addEventListener("change",e=>F(e.currentTarget.value)),r(s,b(R,{get each(){return A()},children:e=>(()=>{var i=pe();return r(i,()=>e.branch,null),r(i,()=>e.activeWorld?" ★":"",null),$(()=>i.value=e.branch),i})()})),r(t,b(L,{get when(){return x()},get children(){return ae()}}),a),a.$$click=I,r(a,()=>p()?"Saving…":"Save"),Q.$$click=()=>W.onClose(),r(T,b(L,{get when(){return _()},get children(){return ce()}}),null),r(T,b(R,{get each(){return J()},children:e=>(()=>{var i=xe();return i.$$click=()=>C(e),r(i,e),$(l=>{var v=d()===e?"#1f3158":"transparent",h=d()===e?"#58a6ff":"#c9d1d9",g=`2px solid ${d()===e?"#388bfd":"transparent"}`;return v!==l.e&&c(i,"background",l.e=v),h!==l.t&&c(i,"color",l.t=h),g!==l.a&&c(i,"border-left",l.a=g),l},{e:void 0,t:void 0,a:void 0}),i})()}),null),r(y,d,Z),ee(q,N),r(D,b(L,{get when(){return!d()},get children(){var e=fe();return r(e,()=>_()?"Loading code…":"Select a module"),e}}),null),$(e=>{var i=p()||_()||!x(),l=p()||!x()?"#161b22":"#1a3a2a",v=p()||!x()?"#484f58":"#3fb950",h=p()||!x()?"default":"pointer",g=d()?"block":"none",O=d()?"flex":"none";return i!==e.e&&(a.disabled=e.e=i),l!==e.t&&c(a,"background",e.t=l),v!==e.a&&c(a,"color",e.a=v),h!==e.o&&c(a,"cursor",e.o=h),g!==e.i&&c(y,"display",e.i=g),O!==e.n&&c(N,"display",e.n=O),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),$(()=>s.value=k()),o})()}oe(["click"]);export{ye as CodePanel};
@@ -1 +1 @@
1
- import{c as v,n as P,w as C,p as g,k as Q,l as r,m as G,j as p,o as L,e as oo,g as to,u as no,f as eo,h as ao,b as so,t as io,M as lo}from"./index-C9JapZJr.js";import{l as I,h,s as co,r as T}from"./vendor-codemirror-D3PB7yT8.js";import"./vendor-pixi-CXkRT4gi.js";var mo=io("<div style=width:100%;height:100%;position:relative><canvas style=display:block>");const{log:B,error:z}=so("map");function Ro(t){let N,o=null;const[A,W]=I([]),[j,q]=I(1),D=()=>t.originRoom,[$,O]=I(D()??null);let X=null,Z=null;const R=new Map,E=new Map,k=new Map,_=new Map,Y=n=>{const e=C();if(!e)return!0;const i=g(n);return!!i&&ao(i.x,i.y,e)},S=n=>{var i;const e=E.get(n);return{room:n,owner:(e==null?void 0:e.username)??((i=e==null?void 0:e.own)!=null&&i.user?`user:${e.own.user}`:null),mineral:(e==null?void 0:e.mineral)??null,density:(e==null?void 0:e.density)??null}},F=200,J=0;let w=[],b=null;const U=()=>{b=null;const n=v();if(!n||!o)return;const e=new Set(A());if(w=w.filter(s=>e.has(s)&&!o.hasRoom(s)),w.length===0)return;const i=w.splice(0,F);n.stores.room.terrainBulk(i,t.shard).then(s=>{for(const[a,l]of s){o==null||o.setRoomTerrain(a,l);const c=k.get(a);c!==void 0&&(o==null||o.setRoomOwned(a,c))}for(const a of i)s.has(a)||o==null||o.markRoomFetched(a)}).catch(s=>z("terrain fetch failed:",s)).finally(()=>{w.length>0&&(b=setTimeout(U,J))})};return h(()=>{v(),t.shard,E.clear(),k.clear()}),co(()=>{N&&(async()=>{var e,i;if(o=new lo({onRoomHover:s=>{var a;(a=t.onHoveredRoomChanged)==null||a.call(t,s?S(s):null)},onRoomClick:s=>{var a;$()!==s?(O(s),o==null||o.setSelectedRoom(s),(a=t.onSelectedRoomChanged)==null||a.call(t,S(s))):Y(s)&&setTimeout(()=>t.onNavigateToRoom(s),0)},onVisibleRoomsChanged:s=>{const a=s.length===0;Z!==a&&(Z=a,a||B(`zoom in — terrain loading active, ${s.length} rooms visible`)),W(s)},onZoomChanged:s=>{var a;q(s),(a=t.onZoomChanged)==null||a.call(t,s)}}),await o.init(N),!o)return;t.initialZoom!==void 0&&t.initialZoom>0&&o.setZoom(t.initialZoom),(e=t.onZoomChanged)==null||e.call(t,o.zoom);const n=C();if(n&&o.setBounds(n.minX,n.maxX,n.minY,n.maxY),t.originRoom){const s=g(t.originRoom);s&&o.centerOn(s.x,s.y),o.setSelectedRoom(t.originRoom),(i=t.onSelectedRoomChanged)==null||i.call(t,S(t.originRoom))}else{const s=v();if(s)try{const a=await s.http.user.worldStartRoom(t.shard??"shard0");if(!o)return;const l=Array.isArray(a==null?void 0:a.room)?a.room[0]:a==null?void 0:a.room;if(typeof l=="string"){const c=g(l);c&&o.centerOn(c.x,c.y)}}catch(a){z("worldStartRoom failed:",a)}}})()}),T(()=>{b!==null&&(clearTimeout(b),b=null),w=[];for(const n of R.values())n.dispose();R.clear(),o==null||o.destroy(),o=null}),h(()=>{P({currentRoom:$,worldBounds:C,onMove:(i,s)=>{var l,c;const a=eo(i,s);O(a),o==null||o.setSelectedRoom(a),o==null||o.centerOn(i,s,!0),(l=t.onSelectedRoomChanged)==null||l.call(t,S(a)),(c=t.onHoveredRoomChanged)==null||c.call(t,S(a))}});const e=i=>{var l,c;const s=((l=i.target)==null?void 0:l.tagName)??"",a=((c=i.target)==null?void 0:c.isContentEditable)??!1;if(!(s==="INPUT"||s==="TEXTAREA"||a)&&i.key==="m"){const m=$();m&&Y(m)&&t.onNavigateToRoom(m)}};window.addEventListener("keydown",e),T(()=>window.removeEventListener("keydown",e))}),h(()=>{var c;const n=v(),e=A(),i=t.shard;if(!n||e.length===0)return;const s=new Set(e),a=e.filter(m=>!(o!=null&&o.hasRoom(m)));if(a.length>0){const m=e.reduce((d,y)=>{var f;return d+(((f=g(y))==null?void 0:f.x)??0)},0)/e.length,u=e.reduce((d,y)=>{var f;return d+(((f=g(y))==null?void 0:f.y)??0)},0)/e.length;w=a.slice().sort((d,y)=>{const f=g(d),M=g(y),x=f?Math.abs(f.x-m)+Math.abs(f.y-u):999,H=M?Math.abs(M.x-m)+Math.abs(M.y-u):999;return x-H}),b===null&&(b=setTimeout(U,0))}n.stores.mapStats.request(e,"owner0",i??void 0);const l=j()>=.4;if(l!==X&&(X=l,(c=t.onSubscriptionStateChanged)==null||c.call(t,l),l||o==null||o.clearAllMap2()),l){const m=new Set(e.map(u=>`${u}/${i}`));for(const[u,d]of R)m.has(u)||(d.dispose(),R.delete(u),o==null||o.clearRoomMap2(u.split("/")[0]));for(const u of e){const d=`${u}/${i}`;R.has(d)||R.set(d,n.stores.map.subscribeMap2(u,i))}}else{for(const[,m]of R)m.dispose();R.clear()}o==null||o.clearInvisibleRooms(s)}),h(()=>{o==null||o.setShowRoomNames(Q()),o&&(o.currentShard=t.shard??"shard0")}),h(()=>{o==null||o.setUnclaimableOverlayVisible(r())}),h(()=>{o==null||o.setOverlayMode(G())}),h(()=>{const n=v(),e=t.shard;n&&n.stores.server.worldInfo(e??void 0).then(i=>{B(`worldInfo(shard=${e??"none"}) — x: [${i.minX}, ${i.maxX}] y: [${i.minY}, ${i.maxY}]`),p(i)}).catch(i=>{})}),h(()=>{var n;o==null||o.setCurrentUser(((n=L())==null?void 0:n._id)??null)}),h(()=>{const n=C();n?(o==null||o.setBounds(n.minX,n.maxX,n.minY,n.maxY),B(`worldBounds applied — shard: ${t.shard??"none"} x: [${n.minX}, ${n.maxX}] y: [${n.minY}, ${n.maxY}] (fetched for shard: ${n.shard??"none"})`)):(o==null||o.clearBounds(),B(`worldBounds — none (shard: ${t.shard??"none"})`))}),h(()=>{const n=v();if(!n)return;const e=n.stores.map.on("room:map2update",({room:i,shard:s,data:a,source:l})=>{s===t.shard&&(o==null||o.setRoomMap2(i,a,l))});T(()=>e.dispose())}),h(()=>{var a;const n=v();if(!n)return;const e=(a=L())==null?void 0:a._id,i=new Set(A()),s=n.stores.mapStats.on("mapStats:room",({room:l,stat:c})=>{var K,V;E.set(l,c);const m=g(l),u=m?oo(m.x,m.y)||to(m.x,m.y):!1,d=c.status==="out of borders",y=!!(c.own&&c.own.user===e),f=!!(c.own&&c.own.user!==e),M=y?"own":u||d||f?"other":"none";k.set(l,M),i.has(l)&&(o==null||o.setRoomOwned(l,M),o==null||o.setRoomSafeMode(l,!!c.safeMode)),o==null||o.setRoomMineral(l,c.mineral,c.density);const x=c.badge?JSON.stringify(c.badge):"";_.get(l)!==x&&(_.set(l,x),o==null||o.setRoomBadge(l,c.badge,(K=c.own)==null?void 0:K.level)),$()===l&&((V=t.onSelectedRoomChanged)==null||V.call(t,S(l)))});T(()=>s.dispose())}),(()=>{var n=mo(),e=n.firstChild;return no(i=>N=i,e),n})()}export{Ro as MapViewer};
1
+ import{c as v,n as P,w as C,p as g,k as Q,l as r,m as G,j as p,o as L,e as oo,g as to,u as no,f as eo,h as ao,b as so,t as io,M as lo}from"./index-D5eNG4b5.js";import{l as I,h,s as co,r as T}from"./vendor-codemirror-D3PB7yT8.js";import"./vendor-pixi-CXkRT4gi.js";var mo=io("<div style=width:100%;height:100%;position:relative><canvas style=display:block>");const{log:B,error:z}=so("map");function Ro(t){let N,o=null;const[A,W]=I([]),[j,q]=I(1),D=()=>t.originRoom,[$,O]=I(D()??null);let X=null,Z=null;const R=new Map,E=new Map,k=new Map,_=new Map,Y=n=>{const e=C();if(!e)return!0;const i=g(n);return!!i&&ao(i.x,i.y,e)},S=n=>{var i;const e=E.get(n);return{room:n,owner:(e==null?void 0:e.username)??((i=e==null?void 0:e.own)!=null&&i.user?`user:${e.own.user}`:null),mineral:(e==null?void 0:e.mineral)??null,density:(e==null?void 0:e.density)??null}},F=200,J=0;let w=[],b=null;const U=()=>{b=null;const n=v();if(!n||!o)return;const e=new Set(A());if(w=w.filter(s=>e.has(s)&&!o.hasRoom(s)),w.length===0)return;const i=w.splice(0,F);n.stores.room.terrainBulk(i,t.shard).then(s=>{for(const[a,l]of s){o==null||o.setRoomTerrain(a,l);const c=k.get(a);c!==void 0&&(o==null||o.setRoomOwned(a,c))}for(const a of i)s.has(a)||o==null||o.markRoomFetched(a)}).catch(s=>z("terrain fetch failed:",s)).finally(()=>{w.length>0&&(b=setTimeout(U,J))})};return h(()=>{v(),t.shard,E.clear(),k.clear()}),co(()=>{N&&(async()=>{var e,i;if(o=new lo({onRoomHover:s=>{var a;(a=t.onHoveredRoomChanged)==null||a.call(t,s?S(s):null)},onRoomClick:s=>{var a;$()!==s?(O(s),o==null||o.setSelectedRoom(s),(a=t.onSelectedRoomChanged)==null||a.call(t,S(s))):Y(s)&&setTimeout(()=>t.onNavigateToRoom(s),0)},onVisibleRoomsChanged:s=>{const a=s.length===0;Z!==a&&(Z=a,a||B(`zoom in — terrain loading active, ${s.length} rooms visible`)),W(s)},onZoomChanged:s=>{var a;q(s),(a=t.onZoomChanged)==null||a.call(t,s)}}),await o.init(N),!o)return;t.initialZoom!==void 0&&t.initialZoom>0&&o.setZoom(t.initialZoom),(e=t.onZoomChanged)==null||e.call(t,o.zoom);const n=C();if(n&&o.setBounds(n.minX,n.maxX,n.minY,n.maxY),t.originRoom){const s=g(t.originRoom);s&&o.centerOn(s.x,s.y),o.setSelectedRoom(t.originRoom),(i=t.onSelectedRoomChanged)==null||i.call(t,S(t.originRoom))}else{const s=v();if(s)try{const a=await s.http.user.worldStartRoom(t.shard??"shard0");if(!o)return;const l=Array.isArray(a==null?void 0:a.room)?a.room[0]:a==null?void 0:a.room;if(typeof l=="string"){const c=g(l);c&&o.centerOn(c.x,c.y)}}catch(a){z("worldStartRoom failed:",a)}}})()}),T(()=>{b!==null&&(clearTimeout(b),b=null),w=[];for(const n of R.values())n.dispose();R.clear(),o==null||o.destroy(),o=null}),h(()=>{P({currentRoom:$,worldBounds:C,onMove:(i,s)=>{var l,c;const a=eo(i,s);O(a),o==null||o.setSelectedRoom(a),o==null||o.centerOn(i,s,!0),(l=t.onSelectedRoomChanged)==null||l.call(t,S(a)),(c=t.onHoveredRoomChanged)==null||c.call(t,S(a))}});const e=i=>{var l,c;const s=((l=i.target)==null?void 0:l.tagName)??"",a=((c=i.target)==null?void 0:c.isContentEditable)??!1;if(!(s==="INPUT"||s==="TEXTAREA"||a)&&i.key==="m"){const m=$();m&&Y(m)&&t.onNavigateToRoom(m)}};window.addEventListener("keydown",e),T(()=>window.removeEventListener("keydown",e))}),h(()=>{var c;const n=v(),e=A(),i=t.shard;if(!n||e.length===0)return;const s=new Set(e),a=e.filter(m=>!(o!=null&&o.hasRoom(m)));if(a.length>0){const m=e.reduce((d,y)=>{var f;return d+(((f=g(y))==null?void 0:f.x)??0)},0)/e.length,u=e.reduce((d,y)=>{var f;return d+(((f=g(y))==null?void 0:f.y)??0)},0)/e.length;w=a.slice().sort((d,y)=>{const f=g(d),M=g(y),x=f?Math.abs(f.x-m)+Math.abs(f.y-u):999,H=M?Math.abs(M.x-m)+Math.abs(M.y-u):999;return x-H}),b===null&&(b=setTimeout(U,0))}n.stores.mapStats.request(e,"owner0",i??void 0);const l=j()>=.4;if(l!==X&&(X=l,(c=t.onSubscriptionStateChanged)==null||c.call(t,l),l||o==null||o.clearAllMap2()),l){const m=new Set(e.map(u=>`${u}/${i}`));for(const[u,d]of R)m.has(u)||(d.dispose(),R.delete(u),o==null||o.clearRoomMap2(u.split("/")[0]));for(const u of e){const d=`${u}/${i}`;R.has(d)||R.set(d,n.stores.map.subscribeMap2(u,i))}}else{for(const[,m]of R)m.dispose();R.clear()}o==null||o.clearInvisibleRooms(s)}),h(()=>{o==null||o.setShowRoomNames(Q()),o&&(o.currentShard=t.shard??"shard0")}),h(()=>{o==null||o.setUnclaimableOverlayVisible(r())}),h(()=>{o==null||o.setOverlayMode(G())}),h(()=>{const n=v(),e=t.shard;n&&n.stores.server.worldInfo(e??void 0).then(i=>{B(`worldInfo(shard=${e??"none"}) — x: [${i.minX}, ${i.maxX}] y: [${i.minY}, ${i.maxY}]`),p(i)}).catch(i=>{})}),h(()=>{var n;o==null||o.setCurrentUser(((n=L())==null?void 0:n._id)??null)}),h(()=>{const n=C();n?(o==null||o.setBounds(n.minX,n.maxX,n.minY,n.maxY),B(`worldBounds applied — shard: ${t.shard??"none"} x: [${n.minX}, ${n.maxX}] y: [${n.minY}, ${n.maxY}] (fetched for shard: ${n.shard??"none"})`)):(o==null||o.clearBounds(),B(`worldBounds — none (shard: ${t.shard??"none"})`))}),h(()=>{const n=v();if(!n)return;const e=n.stores.map.on("room:map2update",({room:i,shard:s,data:a,source:l})=>{s===t.shard&&(o==null||o.setRoomMap2(i,a,l))});T(()=>e.dispose())}),h(()=>{var a;const n=v();if(!n)return;const e=(a=L())==null?void 0:a._id,i=new Set(A()),s=n.stores.mapStats.on("mapStats:room",({room:l,stat:c})=>{var K,V;E.set(l,c);const m=g(l),u=m?oo(m.x,m.y)||to(m.x,m.y):!1,d=c.status==="out of borders",y=!!(c.own&&c.own.user===e),f=!!(c.own&&c.own.user!==e),M=y?"own":u||d||f?"other":"none";k.set(l,M),i.has(l)&&(o==null||o.setRoomOwned(l,M),o==null||o.setRoomSafeMode(l,!!c.safeMode)),o==null||o.setRoomMineral(l,c.mineral,c.density);const x=c.badge?JSON.stringify(c.badge):"";_.get(l)!==x&&(_.set(l,x),o==null||o.setRoomBadge(l,c.badge,(K=c.own)==null?void 0:K.level)),$()===l&&((V=t.onSelectedRoomChanged)==null||V.call(t,S(l)))});T(()=>s.dispose())}),(()=>{var n=mo(),e=n.firstChild;return no(i=>N=i,e),n})()}export{Ro as MapViewer};