screeps-client 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/embedded/_client/CodePanel-CUszTe4x.js +1 -0
- package/dist/embedded/_client/CustomUiEditor-CA0Ny_j7.js +1 -0
- package/dist/embedded/_client/{MapRenderer-BV1i1L45.js → MapRenderer-CueN4I27.js} +2 -2
- package/dist/{standalone/_client/MapViewer-yvKKoBKD.js → embedded/_client/MapViewer-D33TjQbK.js} +1 -1
- package/dist/embedded/_client/SegmentsPanel-C2IbUuSI.js +1 -0
- package/dist/embedded/_client/clientStore-Bi6dgzok.js +2 -0
- package/dist/embedded/_client/customUiStore-BUPlwV2f.js +1 -0
- package/dist/embedded/_client/index-yK7cBYrR.js +18 -0
- package/dist/embedded/_client/{src-BwP2JcoP.js → src-BasnHkIF.js} +1 -1
- package/dist/embedded/_client/{src-TPXksuke.js → src-C1zkeMAI.js} +1 -1
- package/dist/embedded/index.html +5 -4
- package/dist/standalone/_client/CodePanel-A66OQb5I.js +1 -0
- package/dist/standalone/_client/CustomUiEditor-DOs2a4Uz.js +1 -0
- package/dist/standalone/_client/{MapRenderer-DwUceI5B.js → MapRenderer-q-UM2WFq.js} +2 -2
- package/dist/{xxscreeps-mod/_client/MapViewer-Bz7VRhSO.js → standalone/_client/MapViewer-CtNLcbWv.js} +1 -1
- package/dist/standalone/_client/SegmentsPanel-Bxm4LlDl.js +1 -0
- package/dist/standalone/_client/clientStore-BLqi5PSJ.js +2 -0
- package/dist/standalone/_client/customUiStore-CrI2P_6E.js +1 -0
- package/dist/standalone/_client/index-fy4gLy4q.js +18 -0
- package/dist/standalone/_client/{src-XIy2kGvh.js → src-C3KsBQO7.js} +1 -1
- package/dist/standalone/_client/{src-CI80OTL8.js → src-Df3-Jc-t.js} +1 -1
- package/dist/standalone/index.html +5 -4
- package/dist/xxscreeps-mod/_client/CodePanel-D8Rov2hs.js +1 -0
- package/dist/xxscreeps-mod/_client/CustomUiEditor-DaJ0hBQL.js +1 -0
- package/dist/xxscreeps-mod/_client/{MapRenderer-uhzXgF31.js → MapRenderer-Bh4UoU-H.js} +2 -2
- package/dist/{embedded/_client/MapViewer-D3H3HyXS.js → xxscreeps-mod/_client/MapViewer-WQle7Thb.js} +1 -1
- package/dist/xxscreeps-mod/_client/SegmentsPanel-CCwdea9I.js +1 -0
- package/dist/xxscreeps-mod/_client/clientStore-yyTplrrk.js +2 -0
- package/dist/xxscreeps-mod/_client/customUiStore-C_t1MKn-.js +1 -0
- package/dist/xxscreeps-mod/_client/index-Co5Ul2aQ.js +18 -0
- package/dist/xxscreeps-mod/_client/{src-BUyiLFQu.js → src-B_rPKkI8.js} +1 -1
- package/dist/xxscreeps-mod/_client/{src-CzyO7ux4.js → src-CiYiyotu.js} +1 -1
- package/dist/xxscreeps-mod/index.html +5 -4
- package/package.json +1 -1
- package/dist/embedded/_client/CodePanel-CHPhho9S.js +0 -1
- package/dist/embedded/_client/SegmentsPanel-D5OVxC4l.js +0 -1
- package/dist/embedded/_client/clientStore-X5fpw1Qu.js +0 -2
- package/dist/embedded/_client/index-DuoXyyYs.js +0 -18
- package/dist/standalone/_client/CodePanel-CBW87mpY.js +0 -1
- package/dist/standalone/_client/SegmentsPanel-51YXJ_uE.js +0 -1
- package/dist/standalone/_client/clientStore-Ca6immKQ.js +0 -2
- package/dist/standalone/_client/index-Evwic1P4.js +0 -18
- package/dist/xxscreeps-mod/_client/CodePanel-C_J2c7-_.js +0 -1
- package/dist/xxscreeps-mod/_client/SegmentsPanel-CXkBcnk_.js +0 -1
- package/dist/xxscreeps-mod/_client/clientStore-CBiEHyn3.js +0 -2
- package/dist/xxscreeps-mod/_client/index-CqHCqMGH.js +0 -18
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as e,C as t,D as n,F as r,T as i,a,b as o,c as s,d as c,f as l,i as u,l as d,n as f,o as p,p as m,r as h,s as g,u as _,v}from"./vendor-codemirror-Brvxffeo.js";import{A as y,D as b,F as ee,L as x,N as te,R as ne,at as S,ct as C,et as w,it as T,lt as re,n as E,nt as ie,q as D,tt as O}from"./clientStore-Bi6dgzok.js";import{g as ae}from"./src-C1zkeMAI.js";var k=`.ts`,A=e=>e.endsWith(k),oe=e=>e.slice(0,-3);function se(e){let t=new Map;for(let[n,r]of Object.entries(e))A(n)&&t.set(oe(n),r);let n=[],r=new Set;for(let[i,a]of Object.entries(e))A(i)||(r.add(i),t.has(i)?n.push({name:i,lang:`ts`,source:t.get(i)}):n.push({name:i,lang:`js`,source:a}));for(let[e,i]of t)r.has(e)||n.push({name:e,lang:`ts`,source:i});return n}function ce(e,t){let n={};for(let r of e)if(r.lang===`ts`){if(!(r.name in t))throw Error(`missing compiled output for TS module "${r.name}"`);n[r.name]=t[r.name],n[r.name+k]=r.source}else n[r.name]=r.source;return n}var le=e=>e.filter(e=>e.lang===`ts`).map(e=>e.name),j=Symbol(`Comlink.proxy`),ue=Symbol(`Comlink.endpoint`),M=Symbol(`Comlink.releaseProxy`),N=Symbol(`Comlink.finalizer`),P=Symbol(`Comlink.thrown`),de=e=>typeof e==`object`&&!!e||typeof e==`function`,fe=new Map([[`proxy`,{canHandle:e=>de(e)&&e[j],serialize(e){let{port1:t,port2:n}=new MessageChannel;return I(e,t),[n,[n]]},deserialize(e){return e.start(),z(e)}}],[`throw`,{canHandle:e=>de(e)&&P in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){throw e.isError?Object.assign(Error(e.value.message),e.value):e.value}}]]);function F(e,t){for(let n of e)if(t===n||n===`*`||n instanceof RegExp&&n.test(t))return!0;return!1}function I(e,t=globalThis,n=[`*`]){t.addEventListener(`message`,function r(i){if(!i||!i.data)return;if(!F(n,i.origin)){console.warn(`Invalid origin '${i.origin}' for comlink proxy`);return}let{id:a,type:o,path:s}=Object.assign({path:[]},i.data),c=(i.data.argumentList||[]).map(Y),l;try{let t=s.slice(0,-1).reduce((e,t)=>e[t],e),n=s.reduce((e,t)=>e[t],e);switch(o){case`GET`:l=n;break;case`SET`:t[s.slice(-1)[0]]=Y(i.data.value),l=!0;break;case`APPLY`:l=n.apply(t,c);break;case`CONSTRUCT`:l=ge(new n(...c));break;case`ENDPOINT`:{let{port1:t,port2:n}=new MessageChannel;I(e,n),l=he(t,[t])}break;case`RELEASE`:l=void 0;break;default:return}}catch(e){l={value:e,[P]:0}}Promise.resolve(l).catch(e=>({value:e,[P]:0})).then(n=>{let[i,s]=J(n);t.postMessage(Object.assign(Object.assign({},i),{id:a}),s),o===`RELEASE`&&(t.removeEventListener(`message`,r),R(t),N in e&&typeof e[N]==`function`&&e[N]())}).catch(e=>{let[n,r]=J({value:TypeError(`Unserializable return value`),[P]:0});t.postMessage(Object.assign(Object.assign({},n),{id:a}),r)})}),t.start&&t.start()}function L(e){return e.constructor.name===`MessagePort`}function R(e){L(e)&&e.close()}function z(e,t){let n=new Map;return e.addEventListener(`message`,function(e){let{data:t}=e;if(!t||!t.id)return;let r=n.get(t.id);if(r)try{r(t)}finally{n.delete(t.id)}}),G(e,n,[],t)}function B(e){if(e)throw Error(`Proxy has been released and is not useable`)}function V(e){return X(e,new Map,{type:`RELEASE`}).then(()=>{R(e)})}var H=new WeakMap,U=`FinalizationRegistry`in globalThis&&new FinalizationRegistry(e=>{let t=(H.get(e)||0)-1;H.set(e,t),t===0&&V(e)});function W(e,t){let n=(H.get(t)||0)+1;H.set(t,n),U&&U.register(e,t,e)}function pe(e){U&&U.unregister(e)}function G(e,t,n=[],r=function(){}){let i=!1,a=new Proxy(r,{get(r,o){if(B(i),o===M)return()=>{pe(a),V(e),t.clear(),i=!0};if(o===`then`){if(n.length===0)return{then:()=>a};let r=X(e,t,{type:`GET`,path:n.map(e=>e.toString())}).then(Y);return r.then.bind(r)}return G(e,t,[...n,o])},set(r,a,o){B(i);let[s,c]=J(o);return X(e,t,{type:`SET`,path:[...n,a].map(e=>e.toString()),value:s},c).then(Y)},apply(r,a,o){B(i);let s=n[n.length-1];if(s===ue)return X(e,t,{type:`ENDPOINT`}).then(Y);if(s===`bind`)return G(e,t,n.slice(0,-1));let[c,l]=K(o);return X(e,t,{type:`APPLY`,path:n.map(e=>e.toString()),argumentList:c},l).then(Y)},construct(r,a){B(i);let[o,s]=K(a);return X(e,t,{type:`CONSTRUCT`,path:n.map(e=>e.toString()),argumentList:o},s).then(Y)}});return W(a,e),a}function me(e){return Array.prototype.concat.apply([],e)}function K(e){let t=e.map(J);return[t.map(e=>e[0]),me(t.map(e=>e[1]))]}var q=new WeakMap;function he(e,t){return q.set(e,t),e}function ge(e){return Object.assign(e,{[j]:!0})}function J(e){for(let[t,n]of fe)if(n.canHandle(e)){let[r,i]=n.serialize(e);return[{type:`HANDLER`,name:t,value:r},i]}return[{type:`RAW`,value:e},q.get(e)||[]]}function Y(e){switch(e.type){case`HANDLER`:return fe.get(e.name).deserialize(e.value);case`RAW`:return e.value}}function X(e,t,n,r){return new Promise(i=>{let a=_e();t.set(a,i),e.start&&e.start(),e.postMessage(Object.assign({id:a},n),r)})}function _e(){return[,,,,].fill(0).map(()=>Math.floor(Math.random()*(2**53-1)).toString(16)).join(`-`)}function ve(){let e=!0;return d.updateListener.of(t=>{let n=t.view.state.facet(Z);n&&(!t.docChanged&&!e||(e=!1,n.worker.updateFile({path:n.path,code:t.state.doc.toString()})))})}function ye(){return async e=>{let t=e.state.facet(Z);return t?t.worker.getAutocompletion({path:t.path,context:{pos:e.pos,explicit:e.explicit}}):null}}function be({diagnosticCodesToIgnore:e}={}){return a(async t=>{let n=t.state.facet(Z);return n?n.worker.getLints({path:n.path,diagnosticCodesToIgnore:e||[]}):[]})}var xe=e=>{let t=document.createElement(`div`);if(e.quickInfo?.displayParts)for(let n of e.quickInfo.displayParts){let e=t.appendChild(document.createElement(`span`));e.className=`quick-info-${n.kind}`,e.innerText=n.text}return{dom:t}};function Se({renderTooltip:e=xe}={}){return _(async(t,n)=>{let r=t.state.facet(Z);if(!r)return null;let i=await r.worker.getHover({path:r.path,pos:n});return i?{pos:i.start,end:i.end,create:()=>e(i,t)}:null})}var Z=l.define({combine(e){return m(e,{})}}),Ce=(e,t)=>`/${e}.${t}`,we=null;function Te(){return we||=(async()=>{let e=z(new Worker(new URL(`/client/_client/tsWorker-DQ-f6vFs.js`,``+import.meta.url),{type:`module`}));return await e.initialize(),e})(),we}async function Ee(e,t,n){await(await Te()).updateFile({path:Ce(e,t),code:n})}function De(e,t){return[Z.of({worker:e,path:t}),ve(),p({override:[ye()]}),be(),Se()]}var Oe=C(`<input autofocus placeholder="branch name"style="background:#010409;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:4px 8px;font-size:12px;width:140px">`),ke=C(`<button style="padding:4px 10px;border-radius:4px;border:1px solid #238636;font-size:12px">`),Ae=C(`<button style="padding:4px 10px;border-radius:4px;border:1px solid #30363d;background:#161b22;color:#8b949e;font-size:12px;cursor:pointer">Cancel`),je=C(`<span style=font-size:11px;color:#e3b341>Unsaved changes`),Me=C(`<div style="display:flex;gap:4px;padding:6px;border-bottom:1px solid #21262d"><input autofocus placeholder="module name"style="flex:1;min-width:0;background:#010409;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:3px 6px;font-size:12px"><button title="Toggle module language"style="padding:3px 8px;border-radius:4px;border:1px solid #30363d;background:#161b22;font-size:11px;font-weight:600;cursor:pointer;flex-shrink:0">.</button><button style="padding:3px 8px;border-radius:4px;border:1px solid #238636;font-size:12px;flex-shrink:0">Add`),Ne=C(`<div style="padding:12px 10px;font-size:12px;color:#484f58;font-style:italic">Loading…`),Pe=C(`<span style=margin-left:8px;color:#6e7681;font-style:italic>generated · read-only`),Fe=C(`<button style="padding:3px 10px;border-radius:4px;border:1px solid #30363d;background:#161b22;font-size:11px;font-family:inherit;cursor:pointer">`),Ie=C(`<div style=flex:1;display:flex;align-items:center;justify-content:center;color:#484f58;font-size:13px;font-style:italic>`),Le=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><button style="padding:4px 10px;border-radius:4px;font-size:12px"></button><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="display:flex;align-items:center;padding:4px 6px 4px 10px;border-bottom:1px solid #21262d;flex-shrink:0"><span style=flex:1;font-size:10px;font-weight:700;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em>Modules</span><button title="Add a new module"style="background:transparent;border:none;font-size:16px;line-height:1;padding:0 4px">+</button></div><div style=flex:1;overflow:auto></div></div><div style=flex:1;display:flex;flex-direction:column;overflow:hidden><div style="align-items:center;gap:8px;padding:4px 8px 4px 14px;font-size:12px;color:#8b949e;border-bottom:1px solid #21262d;flex-shrink:0;font-family:monospace;background:#0d1117"><span style=flex:1>.</span></div><div style=flex:1;overflow:hidden;flex-direction:column>`),Re=C(`<option>`),ze=C(`<button title="Create a new branch from the selected one"style="padding:4px 10px;border-radius:4px;border:1px solid #30363d;background:#161b22;color:#c9d1d9;font-size:12px;cursor:pointer">+ New branch`),Be=C(`<button style="background:transparent;border:none;color:#8b949e;font-size:13px;line-height:1;cursor:pointer;padding:0 2px;flex-shrink:0">✕`),Ve=C(`<div style="display:flex;align-items:center;gap:4px;padding:7px 8px 7px 12px;font-size:12px;cursor:pointer"><span style=flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap><span>.`),He=C(`<div style="display:flex;align-items:center;padding:5px 8px 5px 24px;font-size:11px;font-style:italic;cursor:pointer"><span style=flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap>.js</span><span style=font-size:9px;font-style:normal;flex-shrink:0>generated`),{error:Q}=ne(`code`),Ue=[u,f,d.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`}})];function $(a){let[l,u]=e([]),[f,p]=e(``),[m,_]=e({}),[ne,C]=e({}),[w,k]=e(``),[A,oe]=e(!1),[j,ue]=e(!1),[M,N]=e(!1),[P,de]=e(!1),[fe,F]=e(!1),[I,L]=e(``),[R,z]=e(!1),[B,V]=e(!1),[H,U]=e(``),[W,pe]=e(`ts`),[G,me]=e(``),[K,q]=e(null),[he,ge]=e(``),J=()=>Object.keys(m()),Y=e=>ne()[e]??`js`,X=()=>l().find(e=>e.branch===f())?.activeWorld??!1,_e=te(b.codeBranch),ve=te(b.codeModule),ye=y(b.codeCursors,{}),be=!1,xe=e=>{if(be||K())return;let t=f(),n=w();!t||!n||((ye[t]??={})[n]=e,ee(b.codeCursors,ye))},{editorView:Se,ref:Z,createExtension:we}=s({onValueChange:e=>{if(K())return;let t=w();!t||m()[t]===e||(_(n=>({...n,[t]:e})),N(!0))}});i(()=>{let e=f(),t=w();be=!0;let n=e&&t?ye[e]?.[t]:void 0;queueMicrotask(()=>{let e=Se();if(e&&t&&n!=null){let t=Math.min(n,e.state.doc.length);e.dispatch({selection:{anchor:t},scrollIntoView:!0})}be=!1})}),g(Se,()=>K()?he():m()[w()]??``);let $=new c;we([...Ue,$.of(h())]),we(d.updateListener.of(e=>{(e.selectionSet||e.docChanged)&&xe(e.state.selection.main.head)})),i(()=>{let e=Se();if(!e)return;if(K()){e.dispatch({effects:$.reconfigure([h(),d.editable.of(!1)])});return}let t=w(),n=Y(t);t&&(n===`ts`?Te().then(async n=>{await Promise.all(Object.entries(m()).map(([e,t])=>n.updateFile({path:Ce(e,Y(e)),code:t}))),w()===t&&e.dispatch({effects:$.reconfigure([h({typescript:!0}),De(n,Ce(t,`ts`))])})}).catch(e=>Q(`ts service failed:`,e)):e.dispatch({effects:$.reconfigure(h())}))}),i(()=>{let e=f();e&&x(b.codeBranch,e)}),i(()=>{let e=w();e&&x(b.codeModule,e)});let We=(e,t)=>e.http.user.branches().then(e=>{u(e.list);let n=t??_e,r=(n?e.list.find(e=>e.branch===n):void 0)??e.list.find(e=>e.activeWorld)??e.list[0];r&&p(r.branch)}).catch(e=>{Q(`branches failed:`,e),D(`Failed to load branches`,`error`)});i(()=>{let e=E();e&&We(e)}),i(()=>{let e=E();if(!e)return;let t=new ae;t.add(e.stores.user.subscribe(`set-active-branch`)),t.add(e.stores.user.on(`user:setActiveBranch`,({activeName:e,branch:t})=>{u(n=>n.map(n=>({...n,[e]:n.branch===t})))})),r(()=>t.dispose())}),i(()=>{let e=f(),t=E();if(!e||!t)return;let n=!1;r(()=>{n=!0}),oe(!0),_({}),C({}),q(null),k(``),N(!1),t.http.user.code.get(e).then(t=>{if(n)return;let r=se(t.modules??{}),i={},a={};for(let e of r)i[e.name]=e.source,a[e.name]=e.lang;_(i),C(a);let o=r.map(e=>e.name),s=e===_e&&ve&&o.includes(ve);k(s?ve:o[0]??``)}).catch(e=>{n||(Q(`get failed:`,e),D(`Failed to load code`,`error`))}).finally(()=>{n||oe(!1)})});let Ge=e=>{q(null),k(e)},Ke=async e=>{k(e);try{let t=await Te();ge(await t.transpile(m()[e]??``)),q(e)}catch(e){Q(`transpile failed:`,e),D(`Failed to compile module`,`error`)}},qe=(e,t)=>{!e||Y(e)===t||(C(n=>({...n,[e]:t})),N(!0),K()===e&&q(null),t===`ts`&&Ee(e,`ts`,m()[e]??``).catch(()=>{}))},Je=async()=>{let e=E(),t=f();if(!(!e||!t)){ue(!0);try{let n=J().map(e=>({name:e,lang:Y(e),source:m()[e]??``})),r=le(n),i={};if(r.length){let e=await Te();await Promise.all(r.map(async t=>{i[t]=await e.transpile(m()[t]??``)}))}await e.http.user.code.set(t,ce(n,i)),D(`Code saved`,`success`),N(!1)}catch(e){Q(`set failed:`,e),D(`Failed to save code`,`error`)}finally{ue(!1)}}},Ye=()=>{let e=H().trim().replace(/\.(ts|js)$/i,``);if(!e)return;if(m()[e]!==void 0){D(`Module "${e}" already exists`,`error`);return}let t=W();_(t=>({...t,[e]:``})),C(n=>({...n,[e]:t})),t===`ts`&&Ee(e,`ts`,``).catch(()=>{}),q(null),k(e),N(!0),V(!1),U(``)},Xe=e=>{if(e===`main`||!confirm(`Delete module "${e}.${Y(e)}"? This takes effect when you Save.`))return;let t=[];_(n=>{let r={...n};return delete r[e],t=Object.keys(r),r}),C(t=>{let n={...t};return delete n[e],n}),K()===e&&q(null),w()===e&&(q(null),k(t[0]??``)),N(!0)},Ze=()=>{let e=E(),t=f();!e||!t||X()||(de(!0),e.http.user.setActiveBranch(`activeWorld`,t).then(()=>{D(`Branch "${t}" now running on server`,`success`),u(e=>e.map(e=>({...e,activeWorld:e.branch===t})))}).catch(e=>{Q(`setActiveBranch failed:`,e),D(`Failed to set active branch`,`error`)}).finally(()=>de(!1)))},Qe=()=>{let e=E(),t=I().trim(),n=f();if(!(!e||!t)){if(l().some(e=>e.branch===t)){D(`Branch "${t}" already exists`,`error`);return}z(!0),e.http.user.cloneBranch(t,n||void 0,n?void 0:!0).then(()=>(D(`Branch "${t}" created`,`success`),F(!1),L(``),We(e,t))).catch(e=>{Q(`cloneBranch failed:`,e),D(`Failed to create branch`,`error`)}).finally(()=>z(!1))}};return(()=>{var e=Le(),r=e.firstChild,i=r.firstChild.nextSibling,s=i.nextSibling,c=s.nextSibling.nextSibling,u=c.nextSibling,d=r.nextSibling.firstChild,m=d.firstChild,h=m.firstChild.nextSibling,g=m.nextSibling,_=d.nextSibling,y=_.firstChild,b=y.firstChild,ee=b.firstChild,x=y.nextSibling;return i.addEventListener(`change`,e=>p(e.currentTarget.value)),O(i,t(v,{get each(){return l()},children:e=>(()=>{var t=Re();return O(t,()=>e.branch,null),O(t,()=>e.activeWorld?` ★`:``,null),n(()=>t.value=e.branch),t})()})),O(r,t(o,{get when(){return fe()},get fallback(){return(()=>{var e=ze();return e.$$click=()=>F(!0),e})()},get children(){return[(()=>{var e=Oe();return e.$$keydown=e=>{e.key===`Enter`?Qe():e.key===`Escape`&&(F(!1),L(``))},e.$$input=e=>L(e.currentTarget.value),n(()=>e.value=I()),e})(),(()=>{var e=ke();return e.$$click=Qe,O(e,()=>R()?`Creating…`:`Create`),n(t=>{var n=R()||!I().trim(),r=R()||!I().trim()?`#161b22`:`#1a3a2a`,i=R()||!I().trim()?`#484f58`:`#3fb950`,a=R()||!I().trim()?`default`:`pointer`;return n!==t.e&&(e.disabled=t.e=n),r!==t.t&&S(e,`background`,t.t=r),i!==t.a&&S(e,`color`,t.a=i),a!==t.o&&S(e,`cursor`,t.o=a),t},{e:void 0,t:void 0,a:void 0,o:void 0}),e})(),(()=>{var e=Ae();return e.$$click=()=>{F(!1),L(``)},e})()]}}),s),s.$$click=Ze,O(s,(()=>{var e=ie(()=>!!X());return()=>e()?`★ Running on server`:P()?`Setting…`:`Run on server`})()),O(r,t(o,{get when(){return M()},get children(){return je()}}),c),c.$$click=Je,O(c,()=>j()?`Saving…`:`Save`),u.$$click=()=>a.onClose(),h.$$click=()=>{V(e=>!e),U(``)},O(d,t(o,{get when(){return B()},get children(){var e=Me(),t=e.firstChild,r=t.nextSibling;r.firstChild;var i=r.nextSibling;return t.$$keydown=e=>{e.key===`Enter`?Ye():e.key===`Escape`&&(V(!1),U(``))},t.$$input=e=>U(e.currentTarget.value),r.$$click=()=>pe(e=>e===`ts`?`js`:`ts`),O(r,W,null),i.$$click=Ye,n(e=>{var t=W()===`ts`?`#58a6ff`:`#e3b341`,n=!H().trim(),a=H().trim()?`#1a3a2a`:`#161b22`,o=H().trim()?`#3fb950`:`#484f58`,s=H().trim()?`pointer`:`default`;return t!==e.e&&S(r,`color`,e.e=t),n!==e.t&&(i.disabled=e.t=n),a!==e.a&&S(i,`background`,e.a=a),o!==e.o&&S(i,`color`,e.o=o),s!==e.i&&S(i,`cursor`,e.i=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),n(()=>t.value=H()),e}}),g),O(g,t(o,{get when(){return A()},get children(){return Ne()}}),null),O(g,t(v,{get each(){return J()},children:e=>{let r=()=>w()===e&&!K(),i=()=>K()===e;return[(()=>{var i=Ve(),a=i.firstChild,s=a.firstChild;return s.firstChild,i.addEventListener(`mouseleave`,()=>me(t=>t===e?``:t)),i.addEventListener(`mouseenter`,()=>me(e)),i.$$click=()=>Ge(e),O(a,e,s),O(s,()=>Y(e),null),O(i,t(o,{get when(){return e!==`main`&&G()===e},get children(){var t=Be();return t.$$click=t=>{t.stopPropagation(),Xe(e)},n(()=>T(t,`title`,`Delete ${e}.${Y(e)}`)),t}}),null),n(t=>{var n=r()?`#1f3158`:`transparent`,o=r()?`#58a6ff`:`#c9d1d9`,c=`2px solid ${r()?`#388bfd`:`transparent`}`,l=`${e}.${Y(e)}`,u=Y(e)===`ts`?`#58a6ff`:`#6e7681`;return n!==t.e&&S(i,`background`,t.e=n),o!==t.t&&S(i,`color`,t.t=o),c!==t.a&&S(i,`border-left`,t.a=c),l!==t.o&&T(a,`title`,t.o=l),u!==t.i&&S(s,`color`,t.i=u),t},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),i})(),t(o,{get when(){return Y(e)===`ts`},get children(){var t=He(),r=t.firstChild,a=r.firstChild;return r.nextSibling,t.$$click=()=>void Ke(e),T(t,`title`,`${e}.js — generated from ${e}.ts (read-only)`),O(r,e,a),n(e=>{var n=i()?`#1f3158`:`transparent`,r=i()?`#79c0ff`:`#6e7681`,a=`2px solid ${i()?`#388bfd`:`transparent`}`;return n!==e.e&&S(t,`background`,e.e=n),r!==e.t&&S(t,`color`,e.t=r),a!==e.a&&S(t,`border-left`,e.a=a),e},{e:void 0,t:void 0,a:void 0}),t}})]}}),null),O(b,w,ee),O(b,(()=>{var e=ie(()=>!!K());return()=>e()?`js`:Y(w())})(),null),O(b,t(o,{get when(){return K()},get children(){return Pe()}}),null),O(y,t(o,{get when(){return ie(()=>!!w())()&&!K()},get children(){var e=Fe();return e.$$click=()=>qe(w(),Y(w())===`ts`?`js`:`ts`),O(e,()=>Y(w())===`ts`?`Convert to JS`:`Convert to TS`),n(t=>{var n=Y(w())===`ts`?`Convert this module to plain JavaScript`:`Convert this module to TypeScript`,r=Y(w())===`ts`?`#e3b341`:`#58a6ff`;return n!==t.e&&T(e,`title`,t.e=n),r!==t.t&&S(e,`color`,t.t=r),t},{e:void 0,t:void 0}),e}}),null),re(Z,x),O(_,t(o,{get when(){return!w()},get children(){var e=Ie();return O(e,()=>A()?`Loading code…`:`Select a module`),e}}),null),n(e=>{var t=P()||X()||!f(),n=X()?`This branch is running on the server`:`Set this branch to run on the server`,r=`1px solid ${X()?`#30363d`:`#1f6feb`}`,i=X()?`#161b22`:`#12233f`,a=X()?`#484f58`:`#58a6ff`,o=P()||X()||!f()?`default`:`pointer`,l=j()||A()||!M(),u=j()||!M()?`#161b22`:`#1a3a2a`,d=j()||!M()?`#484f58`:`#3fb950`,p=j()||!M()?`default`:`pointer`,m=A()||!f(),g=B()?`#58a6ff`:`#8b949e`,_=A()||!f()?`default`:`pointer`,v=w()?`flex`:`none`,b=w()?`flex`:`none`;return t!==e.e&&(s.disabled=e.e=t),n!==e.t&&T(s,`title`,e.t=n),r!==e.a&&S(s,`border`,e.a=r),i!==e.o&&S(s,`background`,e.o=i),a!==e.i&&S(s,`color`,e.i=a),o!==e.n&&S(s,`cursor`,e.n=o),l!==e.s&&(c.disabled=e.s=l),u!==e.h&&S(c,`background`,e.h=u),d!==e.r&&S(c,`color`,e.r=d),p!==e.d&&S(c,`cursor`,e.d=p),m!==e.l&&(h.disabled=e.l=m),g!==e.u&&S(h,`color`,e.u=g),_!==e.c&&S(h,`cursor`,e.c=_),v!==e.w&&S(y,`display`,e.w=v),b!==e.m&&S(x,`display`,e.m=b),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0,l:void 0,u:void 0,c:void 0,w:void 0,m:void 0}),n(()=>i.value=f()),e})()}w([`input`,`keydown`,`click`]);export{$ as CodePanel};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as e,C as t,D as n,E as r,F as i,T as a,b as o,c as s,i as c,l,n as u,s as d,t as f,v as p,x as m,y as h}from"./vendor-codemirror-Brvxffeo.js";import{D as g,L as _,N as v,R as y,at as b,ct as x,et as S,it as C,lt as ee,n as w,nt as te,q as T,st as E,tt as D}from"./clientStore-Bi6dgzok.js";import{F as ne,P as O,_ as re,c as k,g as ie,o as ae,t as A}from"./customUiStore-BUPlwV2f.js";var j=x(`<label style=display:flex;flex-direction:column;gap:3px;flex:1;min-width:120px><span>`),M=x(`<input type=text>`),N=x(`<div style=display:flex;flex-direction:column;gap:4px><button style=align-self:flex-start;color:#58a6ff>+ `),P=x(`<div style=display:flex;gap:4px><input type=text><button title=Remove style="flex-shrink:0;padding:4px 8px">✕`),F=x(`<label style=display:flex;align-items:center;gap:5px;font-size:12px;color:#c9d1d9;cursor:pointer><input type=checkbox>`),oe=x(`<select>`),I=x(`<select><option value>any</option><option value=own>own</option><option value=foreign>foreign`),L=x(`<div style=display:flex;gap:8px;flex-wrap:wrap>`),se=x(`<div style=display:flex;flex-direction:column;gap:6px><span>Requires (needs)</span><div style=display:flex;gap:12px;flex-wrap:wrap>`),ce=x(`<div style="display:flex;flex-direction:column;gap:6px;border-left:2px solid #21262d;padding-left:10px"><span>Items`),R=x(`<div style=display:flex;flex-direction:column;gap:10px;padding:10px><div style=display:flex;gap:8px;flex-wrap:wrap></div><div style=display:flex;flex-direction:column;gap:6px><span>Visible when (showIf)</span><div style=display:flex;gap:8px;flex-wrap:wrap;align-items:flex-end><div style=display:flex;flex-direction:column;gap:4px><span>Room standing</span><div style=display:flex;gap:5px;flex-wrap:wrap>`),z=x(`<div style="border:1px solid #21262d;border-radius:6px;background:#0d1117;overflow:hidden"><div style="display:flex;align-items:center;gap:6px;padding:6px 8px;background:#161b22"><button style=background:transparent;border:none;color:#8b949e;cursor:pointer;font-size:11px;width:14px></button><span style=font-size:10px;font-weight:700;text-transform:uppercase;color:#58a6ff;flex-shrink:0></span><span style=flex:1;font-size:12px;color:#c9d1d9;overflow:hidden;text-overflow:ellipsis;white-space:nowrap></span><button title="Move up"style="padding:2px 7px">↑</button><button title="Move down"style="padding:2px 7px">↓</button><button title="Remove element"style="padding:2px 7px;color:#f85149">✕`),B=x(`<option>`),V=x(`<button>`),H=x(`<div style="font-size:12px;color:#484f58;font-style:italic;padding:2px 0">No elements yet.`),U=x(`<div style=display:flex;flex-direction:column;gap:8px><div style=display:flex;gap:6px;flex-wrap:wrap>`),le=x(`<button style=color:#3fb950;border-color:#238636>+ `),ue=x(`<div style="border-bottom:1px solid #21262d;padding-bottom:2px;margin-top:4px">`),de=x(`<div style="display:flex;justify-content:space-between;gap:8px;font-size:12px;padding:1px 0"><span style=color:#8b949e></span><span style=color:#c9d1d9;font-family:monospace>—`),fe=x(`<div style=display:flex;gap:4px><select disabled style=flex:1;min-width:0;background:#161b22></select><button disabled style=background:#21262d>`),pe=x(`<button disabled style=width:100%;text-align:left;background:#21262d;color:#c9d1d9;cursor:default>`),me=x(`<div style=font-size:10px;color:#484f58;margin-top:1px>`),he=x(`<div>`),ge=x(`<div style=display:flex;flex-direction:column;gap:4px>`),_e=x(`<div style="border-top:1px solid #30363d;padding:8px 10px"><div style=margin-bottom:6px>`),ve=x(`<div style=font-size:11px;color:#484f58;font-style:italic>—`),ye=x(`<span style=font-size:11px;color:#e3b341>Unsaved changes`),be=x(`<div style="padding:8px 16px;font-size:12px;color:#e3b341;background:#1a1a0d;border-bottom:1px solid #30363d">`),xe=x(`<div style=position:absolute;inset:0px;display:flex;align-items:center;justify-content:center;background:rgba(13,17,23,0.7);color:#484f58;font-size:13px;font-style:italic>Loading segment <!>…`),Se=x(`<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:8px;padding:10px 16px;border-bottom:1px solid #30363d;flex-shrink:0"><span style=font-size:15px;font-weight:600;color:#c9d1d9>Custom UI</span><span style=font-size:12px;color:#8b949e>Segment </span><div style=display:flex;gap:2px;margin-left:8px><button>Form</button><button>JSON</button></div><button>Reload</button><div style=flex:1></div><span style=font-size:11px> / <!> chars</span><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;position:relative><div style=flex:1;overflow:auto><div style=padding:16px;display:flex;flex-direction:column;gap:18px;max-width:760px></div></div><div style=flex:1;overflow:hidden;flex-direction:column><div style=flex:1;overflow:hidden;display:flex;flex-direction:column></div></div><div style="width:260px;flex-shrink:0;border-left:1px solid #21262d;overflow:auto;background:#0d1117"><div style=padding:10px>Preview</div><div style=padding:10px;font-size:10px;color:#484f58;line-height:1.5>Static preview — showIf/needs are listed as hints but not applied.`),Ce=x(`<div style=display:flex;flex-direction:column;gap:8px><div><div style=font-size:13px;font-weight:600;color:#c9d1d9></div><div style=font-size:11px;color:#8b949e;margin-top:2px>`),{error:we}=y(`customUiEditor`),Te=100*1024,W=[`room`,`selection`,`tile`];function Ee(){return{handler:`uiCommand`,map:[],room:[],objects:[]}}function De(e){switch(e){case`select`:return{type:e,label:`New select`,cmd:`command`,options:[`alpha`,`beta`]};case`status`:return{type:e,label:`New status`,path:`stats.energy`};case`header`:return{type:e,label:`New header`,items:[]};default:return{type:`button`,label:`New button`,cmd:`command`}}}function G(e,t){let n=typeof e==`object`&&e?e:{},r={type:[`button`,`select`,`status`,`header`].includes(n.type)?n.type:`button`,label:typeof n.label==`string`?n.label:``};if(typeof n.cmd==`string`&&(r.cmd=n.cmd),Array.isArray(n.options)&&(r.options=n.options.filter(e=>typeof e==`string`)),typeof n.path==`string`&&(r.path=n.path),Array.isArray(n.items)&&(r.items=n.items.map(e=>G(e,!1))),t&&n.obj!==void 0&&(r.obj=(Array.isArray(n.obj)?n.obj:[n.obj]).filter(e=>typeof e==`string`)),(n.owner===`own`||n.owner===`foreign`)&&(r.owner=n.owner),Array.isArray(n.needs)&&(r.needs=n.needs.filter(e=>W.includes(e))),n.confirm===!0&&(r.confirm=!0),typeof n.showIf==`object`&&n.showIf!==null){let e=n.showIf,t={};if(typeof e.selType==`string`&&(t.selType=e.selType),e.room!==void 0){let n=(Array.isArray(e.room)?e.room:[e.room]).filter(e=>A.includes(e));n.length&&(t.room=n)}(t.selType!==void 0||t.room!==void 0)&&(r.showIf=t)}return r}function Oe(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return`handler`in t||`map`in t||`room`in t||`objects`in t}function ke(e){let t=typeof e==`object`&&e?e:{};return{handler:typeof t.handler==`string`?t.handler:``,map:Array.isArray(t.map)?t.map.map(e=>G(e,!1)):[],room:Array.isArray(t.room)?t.room.map(e=>G(e,!1)):[],objects:Array.isArray(t.objects)?t.objects.map(e=>G(e,!0)):[]}}function K(e,t){let n={};if(e.type!==`button`&&(n.type=e.type),n.label=e.label,(e.type===`button`||e.type===`select`)&&(n.cmd=e.cmd??``),e.type===`select`&&(n.options=e.options??[]),e.type===`status`&&(n.path=e.path??``),e.type===`header`&&(n.items=(e.items??[]).map(e=>K(e,!1))),t&&e.obj!==void 0&&(n.obj=e.obj.length===1?e.obj[0]:e.obj),t&&e.owner!==void 0&&(n.owner=e.owner),e.needs&&e.needs.length>0&&(n.needs=e.needs),e.confirm&&(n.confirm=!0),e.showIf){let t={};e.showIf.selType&&(t.selType=e.showIf.selType),e.showIf.room&&e.showIf.room.length>0&&(t.room=e.showIf.room.length===1?e.showIf.room[0]:e.showIf.room),Object.keys(t).length>0&&(n.showIf=t)}return n}function Ae(e){return JSON.stringify({v:1,handler:e.handler,map:e.map.map(e=>K(e,!1)),room:e.room.map(e=>K(e,!1)),objects:e.objects.map(e=>K(e,!0))},null,2)}var je=l.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`}}),q=e=>({padding:`4px 10px`,"border-radius":`4px`,border:`1px solid #30363d`,background:`#161b22`,color:e?`#c9d1d9`:`#484f58`,"font-size":`12px`,cursor:e?`pointer`:`default`}),J={background:`#0d1117`,color:`#c9d1d9`,border:`1px solid #30363d`,"border-radius":`4px`,padding:`4px 8px`,"font-size":`12px`,width:`100%`,"box-sizing":`border-box`},Y={"font-size":`10px`,"font-weight":700,color:`#8b949e`,"text-transform":`uppercase`,"letter-spacing":`0.05em`},Me=e=>({padding:`3px 8px`,"border-radius":`4px`,border:`1px solid ${e?`#388bfd`:`#30363d`}`,background:e?`#1f3158`:`#161b22`,color:e?`#58a6ff`:`#8b949e`,"font-size":`11px`,cursor:`pointer`});function X(e){return(()=>{var t=j(),r=t.firstChild;return D(r,()=>e.label),D(t,()=>e.children,null),n(e=>E(r,Y,e)),t})()}function Z(e){return(()=>{var t=M();return t.$$input=t=>e.onInput(t.currentTarget.value),n(n=>{var r=e.placeholder,i=J;return r!==n.e&&C(t,`placeholder`,n.e=r),n.t=E(t,i,n.t),n},{e:void 0,t:void 0}),n(()=>t.value=e.value),t})()}function Ne(e){return(()=>{var r=N(),i=r.firstChild;return i.firstChild,D(r,t(p,{get each(){return e.values},children:(t,r)=>(()=>{var i=P(),a=i.firstChild,o=a.nextSibling;return a.$$input=t=>e.onChange(e.values.map((e,n)=>n===r()?t.currentTarget.value:e)),a.value=t,o.$$click=()=>e.onChange(e.values.filter((e,t)=>t!==r())),n(t=>{var n=e.placeholder,r=J,i={...q(!0)};return n!==t.e&&C(a,`placeholder`,t.e=n),t.t=E(a,r,t.t),t.a=E(o,i,t.a),t},{e:void 0,t:void 0,a:void 0}),i})()}),i),i.$$click=()=>e.onChange([...e.values,``]),D(i,()=>e.addLabel,null),n(e=>E(i,{...q(!0)},e)),r})()}function Pe(e){return(()=>{var t=F(),r=t.firstChild;return r.addEventListener(`change`,t=>e.onChange(t.currentTarget.checked)),D(t,()=>e.label,null),n(()=>r.checked=e.checked),t})()}function Fe(r){let[i,a]=e(!0),s=()=>r.objects?[`button`,`select`]:r.allowHeader?[`button`,`select`,`status`,`header`]:[`button`,`select`,`status`],c=e=>r.onEdit(t=>{t.type=e,e===`select`&&!t.options&&(t.options=[`alpha`,`beta`]),(e===`button`||e===`select`)&&t.cmd===void 0&&(t.cmd=`command`),e===`status`&&t.path===void 0&&(t.path=`stats.energy`),e===`header`&&!t.items&&(t.items=[])}),l=()=>{let e=r.el,t=[e.label||`(no label)`];return e.cmd&&t.push(`→ ${e.cmd}`),e.path&&t.push(`= ${e.path}`),t.join(` `)};return(()=>{var e=z(),u=e.firstChild.firstChild,d=u.nextSibling,f=d.nextSibling,m=f.nextSibling,h=m.nextSibling,g=h.nextSibling;return u.$$click=()=>a(e=>!e),D(u,()=>i()?`▾`:`▸`),D(d,()=>r.el.type),D(f,l),m.$$click=()=>r.onMove(-1),h.$$click=()=>r.onMove(1),g.$$click=()=>r.onRemove(),D(e,t(o,{get when(){return i()},get children(){var e=R(),i=e.firstChild,a=i.nextSibling,l=a.firstChild,u=l.nextSibling,d=u.firstChild,f=d.firstChild,m=f.nextSibling;return D(i,t(X,{label:`Type`,get children(){var e=oe();return e.addEventListener(`change`,e=>c(e.currentTarget.value)),D(e,t(p,{get each(){return s()},children:e=>(()=>{var t=B();return t.value=e,D(t,e),t})()})),n(t=>E(e,J,t)),n(()=>e.value=r.el.type),e}}),null),D(i,t(X,{label:`Label`,get children(){return t(Z,{get value(){return r.el.label},placeholder:`Button text`,onInput:e=>r.onEdit(t=>t.label=e)})}}),null),D(e,t(o,{get when(){return r.el.type===`button`||r.el.type===`select`},get children(){return t(X,{label:`Command (cmd)`,get children(){return t(Z,{get value(){return r.el.cmd??``},placeholder:`passed to your handler`,onInput:e=>r.onEdit(t=>t.cmd=e)})}})}}),a),D(e,t(o,{get when(){return r.el.type===`select`},get children(){return t(X,{label:`Options`,get children(){return t(Ne,{get values(){return r.el.options??[]},addLabel:`option`,placeholder:`choice sent as value`,onChange:e=>r.onEdit(t=>t.options=e)})}})}}),a),D(e,t(o,{get when(){return r.el.type===`status`},get children(){return t(X,{label:`Memory path`,get children(){return t(Z,{get value(){return r.el.path??``},placeholder:`stats.energy`,onInput:e=>r.onEdit(t=>t.path=e)})}})}}),a),D(e,t(o,{get when(){return r.objects},get children(){var e=L();return D(e,t(X,{label:`Object types (obj)`,get children(){return t(Ne,{get values(){return r.el.obj??[]},addLabel:`type`,placeholder:`creep, powerBank …`,onChange:e=>r.onEdit(t=>t.obj=e)})}}),null),D(e,t(X,{label:`Owner filter`,get children(){var e=I();return e.addEventListener(`change`,e=>r.onEdit(t=>t.owner=e.currentTarget.value||void 0)),n(t=>E(e,J,t)),n(()=>e.value=r.el.owner??``),e}}),null),e}}),a),D(e,t(o,{get when(){return r.el.type===`button`||r.el.type===`select`},get children(){var e=se(),i=e.firstChild,a=i.nextSibling;return D(a,t(p,{each:W,children:e=>t(Pe,{label:e,get checked(){return r.el.needs?.includes(e)??!1},onChange:t=>r.onEdit(n=>{let r=new Set(n.needs??[]);t?r.add(e):r.delete(e),n.needs=r.size?W.filter(e=>r.has(e)):void 0})})}),null),D(a,t(Pe,{label:`confirm`,get checked(){return r.el.confirm??!1},onChange:e=>r.onEdit(t=>t.confirm=e||void 0)}),null),n(e=>E(i,Y,e)),e}}),a),D(u,t(o,{get when(){return!r.objects},get children(){return t(X,{label:`Selected type (selType)`,get children(){return t(Z,{get value(){return r.el.showIf?.selType??``},placeholder:`creep, tower …`,onInput:e=>r.onEdit(t=>{let n={...t.showIf};e.trim()?n.selType=e:delete n.selType,t.showIf=n.selType!==void 0||n.room!==void 0?n:void 0})})}})}}),d),D(m,t(p,{each:A,children:e=>{let t=()=>r.el.showIf?.room?.includes(e)??!1;return(()=>{var i=V();return i.$$click=()=>r.onEdit(t=>{let n=new Set(t.showIf?.room??[]);n.has(e)?n.delete(e):n.add(e);let r=n.size?A.filter(e=>n.has(e)):void 0,i={...t.showIf};r?i.room=r:delete i.room,t.showIf=i.selType!==void 0||i.room!==void 0?i:void 0}),D(i,e),n(e=>E(i,Me(t()),e)),i})()}})),D(e,t(o,{get when(){return r.el.type===`header`},get children(){var e=ce(),i=e.firstChild;return D(e,t(Q,{get items(){return r.el.items??[]},get section(){return r.section},objects:!1,allowHeader:!1,mutate:e=>r.onEdit(t=>{t.items??=[],e(t.items)})}),null),n(e=>E(i,Y,e)),e}}),null),n(e=>{var t=Y,n=Y;return e.e=E(l,t,e.e),e.t=E(f,n,e.t),e},{e:void 0,t:void 0}),e}}),null),n(e=>{var t=r.index===0,n={...q(r.index!==0)},i=r.index===r.count-1,a={...q(r.index!==r.count-1)},o={...q(!0)};return t!==e.e&&(m.disabled=e.e=t),e.t=E(m,n,e.t),i!==e.a&&(h.disabled=e.a=i),e.o=E(h,a,e.o),e.i=E(g,o,e.i),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),e})()}function Q(e){let r=()=>e.objects?[`button`,`select`]:e.allowHeader?[`button`,`select`,`status`,`header`]:[`button`,`select`,`status`];return(()=>{var i=U(),a=i.firstChild;return D(i,t(p,{get each(){return e.items},children:(n,r)=>t(Fe,{el:n,get index(){return r()},get count(){return e.items.length},get section(){return e.section},get objects(){return e.objects},get allowHeader(){return e.allowHeader},onEdit:t=>e.mutate(e=>t(e[r()])),onRemove:()=>e.mutate(e=>e.splice(r(),1)),onMove:t=>e.mutate(e=>{let n=r()+t;if(n<0||n>=e.length)return;let i=e[r()];e[r()]=e[n],e[n]=i})})}),a),D(i,t(o,{get when(){return e.items.length===0},get children(){return H()}}),a),D(a,t(p,{get each(){return r()},children:t=>(()=>{var r=le();return r.firstChild,r.$$click=()=>e.mutate(e=>e.push(De(t))),D(r,t,null),n(e=>E(r,{...q(!0)},e)),r})()})),i})()}function Ie(e){let r=()=>{let t=[];return e.el.needs?.length&&t.push(`needs ${e.el.needs.join(`, `)}`),e.el.confirm&&t.push(`confirm`),e.el.showIf?.selType&&t.push(`selType=${e.el.showIf.selType}`),e.el.showIf?.room?.length&&t.push(e.el.showIf.room.join(`/`)),t.join(` · `)};return(()=>{var i=he();return D(i,t(m,{get children(){return[t(h,{get when(){return e.el.type===`header`},get children(){return[(()=>{var t=ue();return D(t,()=>e.el.label),n(e=>E(t,{...Y},e)),t})(),t(p,{get each(){return e.el.items??[]},children:e=>t(Ie,{el:e,indent:!0})})]}}),t(h,{get when(){return e.el.type===`status`},get children(){var t=de(),n=t.firstChild;return n.nextSibling,D(n,()=>e.el.label),t}}),t(h,{get when(){return e.el.type===`select`},get children(){var r=fe(),i=r.firstChild,a=i.nextSibling;return D(i,t(p,{get each(){return e.el.options??[]},children:e=>(()=>{var t=B();return D(t,e),t})()})),D(a,()=>e.el.label),n(e=>{var t={...J},n={...q(!1)};return e.e=E(i,t,e.e),e.t=E(a,n,e.t),e},{e:void 0,t:void 0}),r}}),t(h,{get when(){return e.el.type===`button`},get children(){var t=pe();return D(t,()=>e.el.label),n(e=>E(t,{...q(!0)},e)),t}})]}}),null),D(i,t(o,{get when(){return r()},get children(){var e=me();return D(e,r),e}}),null),n(t=>b(i,`margin-left`,e.indent?`10px`:`0`)),i})()}function Le(e){return(()=>{var r=_e(),i=r.firstChild;return D(i,()=>e.title),D(r,t(o,{get when(){return e.items.length>0},get fallback(){return ve()},get children(){var n=ge();return D(n,t(p,{get each(){return e.items},children:e=>t(Ie,{el:e})})),n}}),null),n(e=>E(i,{...Y},e)),r})()}function Re(p){let m=ie,h=()=>re()||null,[y,x]=O(Ee()),[S,A]=e(v(g.customUiEditorView)===`json`?`json`:`form`),[j,M]=e(``),[N,P]=e(!1),[F,oe]=e(!1),[I,L]=e(!1),[se,ce]=e(0),[R,z]=e(null);a(()=>_(g.customUiEditorView,S()));let B=r(()=>Ae(y)),V=e=>{x(ne(e)),P(!0)},H=()=>S()===`json`?j().length:B().length,U=()=>H()>Te,{editorView:le,ref:ue,createExtension:de}=s({onValueChange:e=>{j()!==e&&(M(e),P(!0))}});d(le,j),de([c,u,je,f(),l.lineWrapping]),a(()=>{let e=w(),t=m(),n=h();if(se(),!e||t===null)return;let r=!1;i(()=>{r=!0}),oe(!0),z(null),e.http.user.memory.segment.get(t,n).then(e=>{if(r)return;let n=e.data??``;if(!n.trim())x(Ee()),A(`form`);else try{let e=JSON.parse(n);if(!Oe(e))throw Error(`not a Custom UI config`);x(ke(e)),A(`form`)}catch{M(n),A(`json`),z(`Segment ${t} isn’t valid Custom UI JSON — showing the raw contents.`)}P(!1)}).catch(e=>{r||(we(`segment load failed:`,e),T(`Failed to load segment ${t}`,`error`))}).finally(()=>{r||oe(!1)})}),a(()=>{S()===`json`&&!R()&&M(B())});let fe=()=>{try{let e=JSON.parse(j());x(ke(e)),z(null),A(`form`)}catch{T(`JSON is not valid — fix it before switching to the form`,`error`)}},pe=()=>{M(B()),z(null),A(`json`)},me=()=>{N()&&!confirm(`Discard unsaved changes and reload from the segment?`)||ce(e=>e+1)},he=()=>{let e=w(),t=m();if(!e||t===null)return;let n=S()===`json`?j():B();try{k(n)}catch(e){T(`Invalid config: ${e.message}`,`error`);return}L(!0),e.http.user.memory.segment.set(t,n,h()).then(()=>{T(`Custom UI saved to segment ${t}`,`success`),P(!1),ae()}).catch(e=>{we(`segment save failed:`,e),T(`Failed to save segment ${t}`,`error`)}).finally(()=>L(!1))};return(()=>{var e=Se(),r=e.firstChild,i=r.firstChild.nextSibling;i.firstChild;var a=i.nextSibling,s=a.firstChild,c=s.nextSibling,l=a.nextSibling,u=l.nextSibling.nextSibling,d=u.firstChild,f=d.nextSibling;f.nextSibling;var g=u.nextSibling,_=g.nextSibling,v=r.nextSibling,x=v.firstChild,w=x.firstChild,T=x.nextSibling,ne=T.firstChild,O=T.nextSibling,re=O.firstChild,k=re.nextSibling;return D(i,m,null),D(i,(()=>{var e=te(()=>!!h());return()=>e()?` · ${h()}`:``})(),null),s.$$click=fe,c.$$click=pe,l.$$click=me,D(u,()=>H().toLocaleString(),d),D(u,()=>Te.toLocaleString(),f),D(r,t(o,{get when(){return N()},get children(){return ye()}}),g),g.$$click=he,D(g,()=>I()?`Saving…`:`Save`),_.$$click=()=>p.onClose(),D(e,t(o,{get when(){return R()},get children(){var e=be();return D(e,R),e}}),v),D(w,t(X,{label:`Handler function`,get children(){return t(Z,{get value(){return y.handler},placeholder:`uiCommand`,onInput:e=>V(t=>t.handler=e)})}}),null),D(w,t($,{title:`Map sidebar`,hint:`Buttons shown on the world map.`,get children(){return t(Q,{get items(){return y.map},section:`map`,objects:!1,allowHeader:!0,mutate:e=>V(t=>e(t.map))})}}),null),D(w,t($,{title:`Room sidebar`,hint:`Elements shown while viewing a room.`,get children(){return t(Q,{get items(){return y.room},section:`room`,objects:!1,allowHeader:!0,mutate:e=>V(t=>e(t.room))})}}),null),D(w,t($,{title:`Object actions`,hint:`Buttons inside a selected object’s card.`,get children(){return t(Q,{get items(){return y.objects},section:`objects`,objects:!0,allowHeader:!1,mutate:e=>V(t=>e(t.objects))})}}),null),ee(ue,ne),D(O,t(Le,{title:`Map`,get items(){return y.map}}),k),D(O,t(Le,{title:`Room`,get items(){return y.room}}),k),D(O,t(Le,{title:`Object actions`,get items(){return y.objects}}),k),D(v,t(o,{get when(){return F()},get children(){var e=xe(),t=e.firstChild.nextSibling;return t.nextSibling,D(e,m,t),e}}),null),n(e=>{var t={...q(!0),...S()===`form`?{background:`#1f3158`,color:`#58a6ff`,"border-color":`#388bfd`}:{}},n={...q(!0),...S()===`json`?{background:`#1f3158`,color:`#58a6ff`,"border-color":`#388bfd`}:{}},r=F(),i=q(!F()),a=U()?`#f85149`:`#8b949e`,o=I()||F()||!N()||U(),d=U()?`Content exceeds the 100 KB segment limit`:`Save this config to the segment`,f=I()||!N()||U()?`#161b22`:`#1a3a2a`,p=I()||!N()||U()?`#484f58`:`#3fb950`,m=I()||!N()||U()?`default`:`pointer`,h=S()===`form`?`block`:`none`,_=S()===`json`?`flex`:`none`,v={...Y};return e.e=E(s,t,e.e),e.t=E(c,n,e.t),r!==e.a&&(l.disabled=e.a=r),e.o=E(l,i,e.o),a!==e.i&&b(u,`color`,e.i=a),o!==e.n&&(g.disabled=e.n=o),d!==e.s&&C(g,`title`,e.s=d),f!==e.h&&b(g,`background`,e.h=f),p!==e.r&&b(g,`color`,e.r=p),m!==e.d&&b(g,`cursor`,e.d=m),h!==e.l&&b(x,`display`,e.l=h),_!==e.u&&b(T,`display`,e.u=_),e.c=E(re,v,e.c),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0,l:void 0,u:void 0,c:void 0}),e})()}function $(e){return(()=>{var t=Ce(),n=t.firstChild.firstChild,r=n.nextSibling;return D(n,()=>e.title),D(r,()=>e.hint),D(t,()=>e.children,null),t})()}S([`input`,`click`]);export{Re as CustomUiEditor};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{A as e,F as t}from"./vendor-codemirror-Brvxffeo.js";import{
|
|
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=B(t.n1,t.x1,t.y1),a=B(t.n2,t.x2,t.y2);if(!i||!a)return;let o=n.color??`#ffffff`,s=(n.width??.5)*L;n.lineStyle===`dashed`?G(e,[i,a],V*(n.width??.5),H*(n.width??.5)):n.lineStyle===`dotted`?G(e,[i,a],U*(n.width??.5),W*(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=B(t.n,t.x,t.y);if(!i)return;let[a,o]=i,s=(n.radius??10)*L,c=!!(n.fill&&n.fill!==`transparent`),l=!!(n.stroke&&n.strokeWidth),u=(n.strokeWidth??.5)*L;c&&(e.circle(a,o,s),e.fill({color:n.fill,alpha:r})),l&&(n.lineStyle===`dashed`?G(e,kt(a,o,s),V*(n.strokeWidth??.5),H*(n.strokeWidth??.5)):n.lineStyle===`dotted`?G(e,kt(a,o,s),U*(n.strokeWidth??.5),W*(n.strokeWidth??.5)):e.circle(a,o,s),e.stroke({color:n.stroke,width:u,alpha:r}))}drawRect(e,t,n,r){let i=B(t.n,t.x,t.y),a=B(t.n,t.x+t.w,t.y),o=B(t.n,t.x+t.w,t.y+t.h),s=B(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)*L;c&&(e.poly(d.slice(0,8),!0),e.fill({color:n.fill,alpha:r})),l&&(n.lineStyle===`dashed`?G(e,u,V*(n.strokeWidth??.5),H*(n.strokeWidth??.5)):n.lineStyle===`dotted`?G(e,u,U*(n.strokeWidth??.5),W*(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=B(e,n,r);if(!t)return;o.push(t)}let s=o.flatMap(e=>e),c=(n.strokeWidth??.5)*L;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];G(e,t[0]===r[0]&&t[1]===r[1]?o:[...o,t],V*(n.strokeWidth??.5),H*(n.strokeWidth??.5))}else if(n.lineStyle===`dotted`){let t=o[0],r=o[o.length-1];G(e,t[0]===r[0]&&t[1]===r[1]?o:[...o,t],U*(n.strokeWidth??.5),W*(n.strokeWidth??.5))}else e.poly(s,!0);e.stroke({color:n.stroke,width:c,alpha:r})}}drawText(e,t,n){let r=B(e.n,e.x,e.y);if(!r)return;let[i,a]=r,o=t.fontSize??10,s=t.fontFamily??`sans-serif`,c=o*L,l=t.align??`center`,p=new f({fill:t.color??`#ffffff`,fontSize:c*z,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*L*z}}:{}});if(t.backgroundColor&&t.backgroundColor!==`transparent`){let r=(t.backgroundPadding??2)*L,o=new d({text:e.text,style:p});o.scale.set(1/z);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/z),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 K=null;async function Ft(e){if(K!==!1)try{let t=await createImageBitmap(e);return K=!0,t}catch(e){if(K===!0)throw e;K=!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-DvfBTPFd.js`,{type:`module`,name:e?.name})}var Lt=2962235,Rt=856343,zt=4020797,Bt=v,Vt=4486980,Ht=8921634,Ut=x,Wt=O,Gt=[{key:`s`,color:k,radius:2.5},{key:`c`,color:16777215,radius:2},{key:`m`,color:b,radius:2},{key:`k`,color:E,radius:2},{key:`pb`,color:16720418,radius:2.5},{key:`d`,color:16777215,radius:2.5}],Kt=new Set([`w`,`r`,`pb`,`p`,`s`,`c`,`m`,`k`,`d`]);function qt(e){return`#`+e.toString(16).padStart(6,`0`)}var{warn:q}=i(`MapRenderer`),Jt=3,J=Jt*50,Yt=[50,60,70,80,90,100,105,120],Y=1,X=.5,Z=50,Xt=2600,Zt=5,Q=.2,$=5,Qt=[80,104,128,160],$t=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 Ye;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 q(`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=Jt;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`?Ht:Vt);for(let e of Gt){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(Kt.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?Ut:Wt;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){q(`failed to load badge for`,e,t)}}}applyBadgeSize(e,t){if(!e.badgeSprite||e.badgeLevel===void 0)return;let n=(Yt[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=M.getTexture(j.atlasUrl,e);a?n.texture=a:M.getOrLoad(j.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=Qt[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=N(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=N(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<Xt?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=N(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){q(`destroy error (ignored):`,e)}}}getOrCreate(e){let t=this.activeRooms.get(e);if(t)return t;let n=N(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=N(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 P(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=P(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)},Zt))}};export{xe as $,gt as A,Le as At,st as B,v as Bt,j as C,O as Ct,ut as D,Fe as Dt,vt as E,He as Et,ot as F,qe as Ft,Ze as G,ie as Gt,rt as H,ae as Ht,Qe as I,Ge as It,me as J,Ye as K,$e as L,Ve as Lt,ft as M,Be as Mt,it as N,We as Nt,et as O,ze as Ot,mt as P,Ke as Pt,be as Q,tt as R,ne as Rt,M as S,de as St,lt as T,D as Tt,pt as U,se as Ut,dt as V,oe as Vt,at as W,re as Wt,ye as X,Ce as Y,_e as Z,P as _,Me as _t,Lt as a,ce as at,Ct as b,pe as bt,Wt as c,De as ct,Vt as d,we as dt,Se as et,qt as f,Te as ft,I as g,fe as gt,Et as h,k as ht,Kt as i,h as it,ct as j,Re as jt,nt as k,Ie as kt,Ut as l,Oe as lt,Ot as m,Ue as mt,X as n,he as nt,Bt as o,je as ot,Dt as p,Ee as pt,ge as q,Gt as r,g as rt,zt as s,Ae as st,$t as t,ve as tt,Rt as u,ke as ut,wt as v,Pe as vt,_t as w,S as wt,N as x,b as xt,Tt as y,Ne as yt,ht as z,ee as zt};
|
|
1
|
+
import{A as e,F as t}from"./vendor-codemirror-Brvxffeo.js";import{D as n,H as r,R as i,V as a}from"./clientStore-Bi6dgzok.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-Dpe0vQ3d.js";import{t as m}from"./src-C1zkeMAI.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,w=10711543,le=16218298,T=16273737,E=15763518,ue=2172461,D=v,de=13226457,O=12283502,fe=[16777215,16711680,8388736,255,65535,32768,16776960,16753920,10824234,8421504,16777215],pe={creep:E,spawn:y,extension:b,tower:x,container:S,storage:C,link:w,rampart:y,road:D,constructedWall:ue,extractor:S,lab:le,terminal:C,observer:b,powerSpawn:E,nuker:T,factory:S,invaderCore:T,source:C,mineral:b,deposit:C,controller:y,powerBank:E,portal:w,keeperLair:T},k=16771195,me=k,he=b,ge=k,_e=b,ve=k,ye=k,be=T,xe=x,Se=b,Ce=16777215,we=9419667,Te=7245682,Ee=12116924,De=12283502,Oe=9787480,ke=14721184,Ae=_,je=13684944,Me=4067858,Ne=14440008,Pe=11940394,Fe=1579032,Ie=5592405,Le=11184810,Re=9419667,ze=16771195,Be=16069959,Ve=7105644,He={energy:ze,power:Be,H:13421772,O:16777215,U:5822457,L:62626,K:10514943,Z:16631694,X:11568379,G:16777215},Ue={biomass:8695826,metal:9793372,mist:14314485,silicon:5023717},We=5617743,Ge=9099642,Ke=11680314,qe=14049376;function Je(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>t(r),r.onerror=n,r.src=e})}var Ye=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 Je(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(t,n){let r=localStorage.getItem(t),[i,a]=e(r===null?n:r===`true`);return[i,e=>{a(e),localStorage.setItem(t,String(e))}]}function Xe(t,n){let[r,i]=e(localStorage.getItem(t)??n);return[r,e=>{i(e),localStorage.setItem(t,e)}]}var[Ze,Qe]=A(n.widescreenMode,!0),[$e,et]=A(n.showCreepLabels,!0),[tt,nt]=A(n.showMapRoomNames,!1),[rt,it]=A(n.showUnclaimableRooms,!0),[at,ot]=A(n.terrainEffects,!0),[st,ct]=A(n.showRoomDecorations,!1),[lt,ut]=A(n.roomDarkOverlay,!0),[dt,ft]=A(n.showRoomVisuals,!0),[pt,mt]=A(n.smoothAnimations,!0),[ht,gt]=Xe(n.spriteTheme,`default`),[_t,vt]=A(n.showMapVisuals,!0),[yt,bt]=A(n.hideCustomUiProtocol,!0),xt=r(),St=xt?`?v=${encodeURIComponent(xt)}`:``,j={id:`default`,name:`Default`,atlasUrl:`${a()}/themes/default/sprite-0.json${St}`,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}}},Ct=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,wt(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 wt(e){let t={...e.textures};for(let n of e.linkedSheets??[])Object.assign(t,n.textures);return t}var M=new Ct;function Tt(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 N(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 P(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 F(e){return e===0||e<0&&(e+1)%10==0||e>0&&e%10==0}function Et(e,t){return F(e)||F(t)}function Dt(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 I(e){let t=e;if(!t)return!1;let n=t.tagName??``;return n===`INPUT`||n===`TEXTAREA`?!0:t.isContentEditable===!0}function Ot(e){let n=t=>{if(I(t.target))return;let n=e.currentRoom(),r=n?N(n):null;if(!r)return;let i=e.worldBounds(),a=(e,t)=>!i||Tt(e,t,i);switch(t.key){case`ArrowLeft`:t.preventDefault(),a(r.x-1,r.y)&&e.onMove(r.x-1,r.y);break;case`ArrowRight`:t.preventDefault(),a(r.x+1,r.y)&&e.onMove(r.x+1,r.y);break;case`ArrowUp`:t.preventDefault(),a(r.x,r.y-1)&&e.onMove(r.x,r.y-1);break;case`ArrowDown`:t.preventDefault(),a(r.x,r.y+1)&&e.onMove(r.x,r.y+1);break}};window.addEventListener(`keydown`,n),t(()=>window.removeEventListener(`keydown`,n))}var[kt,At]=e(`owner`),L=3,R=L*50,z=4;function B(e,t,n){let r=N(e);return r?[r.x*R+t*L,r.y*R+n*L]:null}var V=3*L,H=2.5*L,U=1*L,W=2*L;function G(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 jt(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 Mt=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=B(t.n1,t.x1,t.y1),a=B(t.n2,t.x2,t.y2);if(!i||!a)return;let o=n.color??`#ffffff`,s=(n.width??.5)*L;n.lineStyle===`dashed`?G(e,[i,a],V*(n.width??.5),H*(n.width??.5)):n.lineStyle===`dotted`?G(e,[i,a],U*(n.width??.5),W*(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=B(t.n,t.x,t.y);if(!i)return;let[a,o]=i,s=(n.radius??10)*L,c=!!(n.fill&&n.fill!==`transparent`),l=!!(n.stroke&&n.strokeWidth),u=(n.strokeWidth??.5)*L;c&&(e.circle(a,o,s),e.fill({color:n.fill,alpha:r})),l&&(n.lineStyle===`dashed`?G(e,jt(a,o,s),V*(n.strokeWidth??.5),H*(n.strokeWidth??.5)):n.lineStyle===`dotted`?G(e,jt(a,o,s),U*(n.strokeWidth??.5),W*(n.strokeWidth??.5)):e.circle(a,o,s),e.stroke({color:n.stroke,width:u,alpha:r}))}drawRect(e,t,n,r){let i=B(t.n,t.x,t.y),a=B(t.n,t.x+t.w,t.y),o=B(t.n,t.x+t.w,t.y+t.h),s=B(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)*L;c&&(e.poly(d.slice(0,8),!0),e.fill({color:n.fill,alpha:r})),l&&(n.lineStyle===`dashed`?G(e,u,V*(n.strokeWidth??.5),H*(n.strokeWidth??.5)):n.lineStyle===`dotted`?G(e,u,U*(n.strokeWidth??.5),W*(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=B(e,n,r);if(!t)return;o.push(t)}let s=o.flatMap(e=>e),c=(n.strokeWidth??.5)*L;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];G(e,t[0]===r[0]&&t[1]===r[1]?o:[...o,t],V*(n.strokeWidth??.5),H*(n.strokeWidth??.5))}else if(n.lineStyle===`dotted`){let t=o[0],r=o[o.length-1];G(e,t[0]===r[0]&&t[1]===r[1]?o:[...o,t],U*(n.strokeWidth??.5),W*(n.strokeWidth??.5))}else e.poly(s,!0);e.stroke({color:n.stroke,width:c,alpha:r})}}drawText(e,t,n){let r=B(e.n,e.x,e.y);if(!r)return;let[i,a]=r,o=t.fontSize??10,s=t.fontFamily??`sans-serif`,c=o*L,l=t.align??`center`,p=new f({fill:t.color??`#ffffff`,fontSize:c*z,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*L*z}}:{}});if(t.backgroundColor&&t.backgroundColor!==`transparent`){let r=(t.backgroundPadding??2)*L,o=new d({text:e.text,style:p});o.scale.set(1/z);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/z),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:Nt}=i(`terrainCache`),Pt=`screeps-terrain-v1`;async function Ft(e,t,n){try{let r=await caches.open(Pt),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){Nt(`get failed:`,e)}return null}async function It(e,t,n,r){try{let i=await caches.open(Pt),a=`/terrain/${e}_${t}_z${n}.webp`,o=new Request(a),s=new Response(r);await i.put(o,s)}catch(e){Nt(`save failed:`,e)}}var K=null;async function Lt(e){if(K!==!1)try{let t=await createImageBitmap(e);return K=!0,t}catch(e){if(K===!0)throw e;K=!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 Rt(e){return new Worker(`/client/_client/terrain.worker-DvfBTPFd.js`,{type:`module`,name:e?.name})}var zt=2962235,Bt=856343,Vt=4020797,Ht=v,Ut=4486980,Wt=8921634,Gt=x,Kt=O,qt=[{key:`s`,color:k,radius:2.5},{key:`c`,color:16777215,radius:2},{key:`m`,color:b,radius:2},{key:`k`,color:E,radius:2},{key:`pb`,color:16720418,radius:2.5},{key:`d`,color:16777215,radius:2.5}],Jt=new Set([`w`,`r`,`pb`,`p`,`s`,`c`,`m`,`k`,`d`]);function Yt(e){return`#`+e.toString(16).padStart(6,`0`)}var{warn:q}=i(`MapRenderer`),Xt=3,J=Xt*50,Zt=[50,60,70,80,90,100,105,120],Y=1,X=.5,Z=50,Qt=2600,$t=5,Q=.2,$=5,en=[80,104,128,160],tn=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 Ye;constructor(e){this.app=new l,this.callbacks=e,this.worker=new Rt,this.worker.onmessage=e=>{let t=e.data;if(t.kind===`cache`){It(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 Mt,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 Ft(i,e,t);if(n)return await Lt(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 q(`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=Xt;r.clear();let a=t.r??[];for(let[e,t]of a)r.rect(e*i,t*i,i,i);a.length&&r.fill(Ht);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`?Wt:Ut);for(let e of qt){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(Jt.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?Gt:Kt;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){q(`failed to load badge for`,e,t)}}}applyBadgeSize(e,t){if(!e.badgeSprite||e.badgeLevel===void 0)return;let n=(Zt[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=M.getTexture(j.atlasUrl,e);a?n.texture=a:M.getOrLoad(j.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=en[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=N(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=N(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<Qt?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=N(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){q(`destroy error (ignored):`,e)}}}getOrCreate(e){let t=this.activeRooms.get(e);if(t)return t;let n=N(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=N(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 P(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=P(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)},$t))}};export{_e as $,vt as A,ze as At,_t as B,ne as Bt,j as C,b as Ct,ut as D,D as Dt,bt as E,S as Et,gt as F,We as Ft,ht as G,se as Gt,dt as H,v as Ht,ot as I,Ke as It,Ye as J,at as K,re as Kt,Qe as L,qe as Lt,ft as M,Le as Mt,it as N,Re as Nt,et as O,He as Ot,mt as P,Be as Pt,ye as Q,$e as R,Ge as Rt,M as S,pe as St,lt as T,O as Tt,rt as U,oe as Ut,st as V,ee as Vt,pt as W,ae as Wt,me as X,ge as Y,Ce as Z,P as _,k as _t,zt as a,g as at,Tt as b,Pe as bt,Kt as c,je as ct,Ut as d,Oe as dt,be as et,Yt as f,ke as ft,I as g,Ue as gt,Ot as h,Ee as ht,Jt as i,he as it,ct as j,Ie as jt,nt as k,Fe as kt,Gt as l,Ae as lt,At as m,Te as mt,X as n,Se as nt,Ht as o,h as ot,kt as p,we as pt,Ze as q,ie as qt,qt as r,ve as rt,Vt as s,ce as st,tn as t,xe as tt,Bt as u,De as ut,Et as v,fe as vt,yt as w,de as wt,N as x,Ne as xt,Dt as y,Me as yt,tt as z,Ve as zt};
|
package/dist/{standalone/_client/MapViewer-yvKKoBKD.js → embedded/_client/MapViewer-D33TjQbK.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as e,F as t,I as n,T as r}from"./vendor-codemirror-Brvxffeo.js";import{R as i,S as a,
|
|
1
|
+
import{A as e,F as t,I as n,T as r}from"./vendor-codemirror-Brvxffeo.js";import{R as i,S as a,ct as o,g as s,lt as c,n as l,x as u}from"./clientStore-Bi6dgzok.js";import{T as d}from"./src-C1zkeMAI.js";import{B as f,U as p,V as m,_ as h,b as g,h as _,p as v,t as y,v as b,x,y as S,z as C}from"./MapRenderer-CueN4I27.js";var w=o(`<div style=width:100%;height:100%;position:relative><canvas style=display:block>`),{log:T,error:E}=i(`map`);function D(i){let o,D=null,[O,k]=e([]),[A,j]=e(1),[M,N]=e(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=x(e);return!!n&&g(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=l();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(()=>{l(),i.shard,L.clear(),R.clear(),W.clear(),D?.clearAllRooms()}),n(()=>{o&&(async()=>{if(D=new y({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(o),!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=x(i.originRoom);e&&D.centerOn(e.x,e.y),D.setSelectedRoom(i.originRoom),i.onSelectedRoomChanged?.(V(i.originRoom))}else{let e=l();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=x(n);e&&D.centerOn(e.x,e.y)}}catch(e){E(`worldStartRoom failed:`,e)}}})()}),t(()=>{U!==null&&(clearTimeout(U),U=null),H=[],W.clear();for(let e of I.values())e.dispose();I.clear(),D?.destroy(),D=null}),r(()=>{_({currentRoom:M,worldBounds:a,onMove:(e,t)=>{let n=h(e,t);N(n),D?.setSelectedRoom(n),D?.centerOn(e,t,!0),i.onSelectedRoomChanged?.(V(n)),i.onHoveredRoomChanged?.(V(n))}});let e=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`,e),t(()=>window.removeEventListener(`keydown`,e))}),r(()=>{let e=l(),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+(x(t)?.x??0),0)/t.length,n=t.reduce((e,t)=>e+(x(t)?.y??0),0)/t.length;H=a.slice().sort((t,r)=>{let i=x(t),a=x(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(C()),D&&(D.currentShard=i.shard??`shard0`)}),r(()=>{D?.setUnclaimableOverlayVisible(p())}),r(()=>{D?.setMapVisualVisible(f())}),r(()=>{D?.setOverlayMode(v())}),r(()=>{D?.setDecorationsVisible(m())}),r(()=>{let e=l(),t=O(),n=i.shard;!e||t.length===0||v()!==`mineral`||e.stores.mapStats.request(t,d.minerals,n??void 0)}),r(()=>{let e=l(),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}]`),s(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 e=l();if(!e)return;let n=e.stores.user.subscribeMapVisual(i.shard),r=e.stores.user.on(`user:mapVisual`,({shard:e,data:t})=>{e===i.shard&&(t?D?.setMapVisual(t):D?.clearMapVisual())});t(()=>{n.dispose(),r.dispose()})}),r(()=>{let e=l();if(!e)return;let n=e.stores.map.on(`room:map2update`,({room:e,shard:t,data:n,source:r})=>{t===i.shard&&D?.setRoomMap2(e,n,r)});t(()=>n.dispose())}),r(()=>{let e=l();if(!e)return;let n=u()?._id,r=new Set(O()),a=e.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=x(e),s=a?b(a.x,a.y)||S(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))});t(()=>a.dispose())}),(()=>{var e=w(),t=e.firstChild;return c(e=>o=e,t),e})()}export{D as MapViewer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./rolldown-runtime-Bh1tDfsg.js";import{A as t,C as n,D as r,F as i,T as a,b as o,c as s,i as c,l,n as u,s as d,t as f,v as p}from"./vendor-codemirror-Brvxffeo.js";import{D as m,L as h,N as g,R as _,at as v,ct as y,et as b,f as x,it as S,lt as C,n as w,nt as T,q as E,st as D,tt as O}from"./clientStore-Bi6dgzok.js";import{a as k}from"./roomDataStore-0NPTJjQf.js";var A=e(((e,t)=>{var n=(function(){var e=String.fromCharCode,t=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=`,n=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$`,r={};function i(e,t){if(!r[e]){r[e]={};for(var n=0;n<e.length;n++)r[e][e.charAt(n)]=n}return r[e][t]}var a={compressToBase64:function(e){if(e==null)return``;var n=a._compress(e,6,function(e){return t.charAt(e)});switch(n.length%4){default:case 0:return n;case 1:return n+`===`;case 2:return n+`==`;case 3:return n+`=`}},decompressFromBase64:function(e){return e==null?``:e==``?null:a._decompress(e.length,32,function(n){return i(t,e.charAt(n))})},compressToUTF16:function(t){return t==null?``:a._compress(t,15,function(t){return e(t+32)})+` `},decompressFromUTF16:function(e){return e==null?``:e==``?null:a._decompress(e.length,16384,function(t){return e.charCodeAt(t)-32})},compressToUint8Array:function(e){for(var t=a.compress(e),n=new Uint8Array(t.length*2),r=0,i=t.length;r<i;r++){var o=t.charCodeAt(r);n[r*2]=o>>>8,n[r*2+1]=o%256}return n},decompressFromUint8Array:function(t){if(t==null)return a.decompress(t);for(var n=Array(t.length/2),r=0,i=n.length;r<i;r++)n[r]=t[r*2]*256+t[r*2+1];var o=[];return n.forEach(function(t){o.push(e(t))}),a.decompress(o.join(``))},compressToEncodedURIComponent:function(e){return e==null?``:a._compress(e,6,function(e){return n.charAt(e)})},decompressFromEncodedURIComponent:function(e){return e==null?``:e==``?null:(e=e.replace(/ /g,`+`),a._decompress(e.length,32,function(t){return i(n,e.charAt(t))}))},compress:function(t){return a._compress(t,16,function(t){return e(t)})},_compress:function(e,t,n){if(e==null)return``;var r,i,a={},o={},s=``,c=``,l=``,u=2,d=3,f=2,p=[],m=0,h=0,g;for(g=0;g<e.length;g+=1)if(s=e.charAt(g),Object.prototype.hasOwnProperty.call(a,s)||(a[s]=d++,o[s]=!0),c=l+s,Object.prototype.hasOwnProperty.call(a,c))l=c;else{if(Object.prototype.hasOwnProperty.call(o,l)){if(l.charCodeAt(0)<256){for(r=0;r<f;r++)m<<=1,h==t-1?(h=0,p.push(n(m)),m=0):h++;for(i=l.charCodeAt(0),r=0;r<8;r++)m=m<<1|i&1,h==t-1?(h=0,p.push(n(m)),m=0):h++,i>>=1}else{for(i=1,r=0;r<f;r++)m=m<<1|i,h==t-1?(h=0,p.push(n(m)),m=0):h++,i=0;for(i=l.charCodeAt(0),r=0;r<16;r++)m=m<<1|i&1,h==t-1?(h=0,p.push(n(m)),m=0):h++,i>>=1}u--,u==0&&(u=2**f,f++),delete o[l]}else for(i=a[l],r=0;r<f;r++)m=m<<1|i&1,h==t-1?(h=0,p.push(n(m)),m=0):h++,i>>=1;u--,u==0&&(u=2**f,f++),a[c]=d++,l=String(s)}if(l!==``){if(Object.prototype.hasOwnProperty.call(o,l)){if(l.charCodeAt(0)<256){for(r=0;r<f;r++)m<<=1,h==t-1?(h=0,p.push(n(m)),m=0):h++;for(i=l.charCodeAt(0),r=0;r<8;r++)m=m<<1|i&1,h==t-1?(h=0,p.push(n(m)),m=0):h++,i>>=1}else{for(i=1,r=0;r<f;r++)m=m<<1|i,h==t-1?(h=0,p.push(n(m)),m=0):h++,i=0;for(i=l.charCodeAt(0),r=0;r<16;r++)m=m<<1|i&1,h==t-1?(h=0,p.push(n(m)),m=0):h++,i>>=1}u--,u==0&&(u=2**f,f++),delete o[l]}else for(i=a[l],r=0;r<f;r++)m=m<<1|i&1,h==t-1?(h=0,p.push(n(m)),m=0):h++,i>>=1;u--,u==0&&(u=2**f,f++)}for(i=2,r=0;r<f;r++)m=m<<1|i&1,h==t-1?(h=0,p.push(n(m)),m=0):h++,i>>=1;for(;;)if(m<<=1,h==t-1){p.push(n(m));break}else h++;return p.join(``)},decompress:function(e){return e==null?``:e==``?null:a._decompress(e.length,32768,function(t){return e.charCodeAt(t)})},_decompress:function(t,n,r){var i=[],a=4,o=4,s=3,c=``,l=[],u,d,f,p,m,h,g,_={val:r(0),position:n,index:1};for(u=0;u<3;u+=1)i[u]=u;for(f=0,m=2**2,h=1;h!=m;)p=_.val&_.position,_.position>>=1,_.position==0&&(_.position=n,_.val=r(_.index++)),f|=+(p>0)*h,h<<=1;switch(f){case 0:for(f=0,m=2**8,h=1;h!=m;)p=_.val&_.position,_.position>>=1,_.position==0&&(_.position=n,_.val=r(_.index++)),f|=+(p>0)*h,h<<=1;g=e(f);break;case 1:for(f=0,m=2**16,h=1;h!=m;)p=_.val&_.position,_.position>>=1,_.position==0&&(_.position=n,_.val=r(_.index++)),f|=+(p>0)*h,h<<=1;g=e(f);break;case 2:return``}for(i[3]=g,d=g,l.push(g);;){if(_.index>t)return``;for(f=0,m=2**s,h=1;h!=m;)p=_.val&_.position,_.position>>=1,_.position==0&&(_.position=n,_.val=r(_.index++)),f|=+(p>0)*h,h<<=1;switch(g=f){case 0:for(f=0,m=2**8,h=1;h!=m;)p=_.val&_.position,_.position>>=1,_.position==0&&(_.position=n,_.val=r(_.index++)),f|=+(p>0)*h,h<<=1;i[o++]=e(f),g=o-1,a--;break;case 1:for(f=0,m=2**16,h=1;h!=m;)p=_.val&_.position,_.position>>=1,_.position==0&&(_.position=n,_.val=r(_.index++)),f|=+(p>0)*h,h<<=1;i[o++]=e(f),g=o-1,a--;break;case 2:return l.join(``)}if(a==0&&(a=2**s,s++),i[g])c=i[g];else if(g===o)c=d+d.charAt(0);else return null;l.push(c),i[o++]=d+c.charAt(0),a--,d=c,a==0&&(a=2**s,s++)}}};return a})();typeof define==`function`&&define.amd?define(function(){return n}):t!==void 0&&t!=null?t.exports=n:typeof angular<`u`&&angular!=null&&angular.module(`LZString`,[]).factory(`LZString`,function(){return n})}))(),j=y(`<select style="background:#010409;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:4px 8px;font-size:12px;cursor:pointer">`),M=y(`<span style=font-size:11px;color:#e3b341>Unsaved changes`),ee=y(`<div style=position:absolute;inset:0px;display:flex;align-items:center;justify-content:center;background:rgba(13,17,23,0.7);color:#484f58;font-size:13px;font-style:italic>Loading segment <!>…`),te=y(`<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:8px;padding:10px 16px;border-bottom:1px solid #30363d;flex-shrink:0"><span style=font-size:15px;font-weight:600;color:#c9d1d9>Segment </span><button>Reload</button><div style=width:1px;height:18px;background:#30363d></div><button title="Pretty-print the content as JSON">Format JSON</button><button title="Re-serialize the content as compact JSON without whitespace">Minify</button><button title="Compress the content with lz-string (compressToUTF16)">Compress</button><button title="Decompress lz-string content (UTF-16, with raw fallback)">Decompress</button><div style=flex:1></div><span style=font-size:11px> / <!> chars</span><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:130px;flex-shrink:0;border-right:1px solid #21262d;display:flex;flex-direction:column;overflow:hidden"><div style="padding:6px 10px;border-bottom:1px solid #21262d;font-size:10px;font-weight:700;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;flex-shrink:0">Segments</div><div style=flex:1;overflow:auto></div></div><div style=flex:1;display:flex;flex-direction:column;overflow:hidden;position:relative><div style=flex:1;overflow:hidden;display:flex;flex-direction:column>`),ne=y(`<option>`),re=y(`<span style=font-size:10px>`),ie=y(`<div style="display:flex;align-items:center;gap:4px;padding:5px 8px 5px 12px;font-size:12px;font-family:monospace;cursor:pointer"><span style=flex:1>`),{error:N}=_(`segments`),P=100,F=100*1024,I=Array.from({length:P},(e,t)=>t),L=l.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`}}),R=e=>({padding:`4px 10px`,"border-radius":`4px`,border:`1px solid #30363d`,background:`#161b22`,color:e?`#c9d1d9`:`#484f58`,"font-size":`12px`,cursor:e?`pointer`:`default`});function z(e){let _=()=>(x()?.serverData?.shards??[]).filter(e=>e!==null),[y,b]=t(e.shard??k()),z=Number(g(m.segmentsLast)??`0`),[B,ae]=t(Number.isInteger(z)&&z>=0&&z<P?z:0),[V,H]=t(``),[oe,se]=t(0),[U,W]=t(!1),[G,K]=t(!1),[q,J]=t(!1),[ce,le]=t({}),Y=(e,t)=>`${e??``}:${t}`,X=(e,t,n)=>le(r=>({...r,[Y(e,t)]:n}));a(()=>h(m.segmentsLast,String(B())));let{editorView:ue,ref:de,createExtension:fe}=s({onValueChange:e=>{V()!==e&&(H(e),J(!0))}});d(ue,V),fe([c,u,L,f(),l.lineWrapping]),a(()=>{let e=w(),t=B(),n=y();if(oe(),!e)return;let r=!1;i(()=>{r=!0}),W(!0),J(!1),H(``),e.http.user.memory.segment.get(t,n).then(e=>{if(r)return;let i=e.data??``;H(i),J(!1),X(n,t,i.length)}).catch(e=>{r||(N(`get failed:`,e),E(`Failed to load segment ${t}`,`error`))}).finally(()=>{r||W(!1)})});let pe=()=>{let e=w();if(!e)return;let t=B(),n=y(),r=V();K(!0),e.http.user.memory.segment.set(t,r,n).then(()=>{E(`Segment ${t} saved`,`success`),J(!1),X(n,t,r.length)}).catch(e=>{N(`set failed:`,e),E(`Failed to save segment ${t}`,`error`)}).finally(()=>K(!1))},me=()=>{q()&&!confirm(`Discard unsaved changes and reload this segment?`)||se(e=>e+1)},he=e=>{e!==B()&&(q()&&!confirm(`Discard unsaved changes and switch segments?`)||ae(e))},ge=e=>{e!==y()&&(q()&&!confirm(`Discard unsaved changes and switch shards?`)||b(e))},Z=e=>{H(e),J(!0)},_e=()=>{V()&&Z((0,A.compressToUTF16)(V()))},ve=()=>{let e=V();if(!e)return;let t=(0,A.decompressFromUTF16)(e);if(t)return Z(t);let n=(0,A.decompress)(e);if(n)return Z(n);E(`Content is not lz-string compressed`,`error`)},Q=e=>{try{Z(JSON.stringify(JSON.parse(V()),null,e))}catch{E(`Content is not valid JSON`,`error`)}},$=()=>V().length>F;return(()=>{var t=te(),i=t.firstChild,a=i.firstChild;a.firstChild;var s=a.nextSibling,c=s.nextSibling.nextSibling,l=c.nextSibling,u=l.nextSibling,d=u.nextSibling,f=d.nextSibling.nextSibling,m=f.firstChild,h=m.nextSibling;h.nextSibling;var g=f.nextSibling,b=g.nextSibling,x=i.nextSibling.firstChild,w=x.firstChild.nextSibling,E=x.nextSibling,k=E.firstChild;return O(a,B,null),O(i,n(o,{get when(){return _().length>0},get children(){var e=j();return e.addEventListener(`change`,e=>ge(e.currentTarget.value)),O(e,n(p,{get each(){return _()},children:e=>(()=>{var t=ne();return t.value=e,O(t,e),t})()})),r(()=>e.value=y()??``),e}}),s),s.$$click=me,c.$$click=()=>Q(2),l.$$click=()=>Q(),u.$$click=_e,d.$$click=ve,O(f,()=>V().length.toLocaleString(),m),O(f,()=>F.toLocaleString(),h),O(i,n(o,{get when(){return q()},get children(){return M()}}),g),g.$$click=pe,O(g,()=>G()?`Saving…`:`Save`),b.$$click=()=>e.onClose(),O(w,n(p,{each:I,children:e=>{let t=()=>B()===e,i=()=>ce()[Y(y(),e)];return(()=>{var a=ie(),s=a.firstChild;return a.$$click=()=>he(e),O(s,e),O(a,n(o,{get when(){return i()!==void 0},get children(){var e=re();return O(e,(()=>{var e=T(()=>i()===0);return()=>e()?`empty`:`${i().toLocaleString()}`})()),r(t=>v(e,`color`,i()===0?`#484f58`:`#8b949e`)),e}}),null),r(e=>{var n=t()?`#1f3158`:`transparent`,r=t()?`#58a6ff`:`#c9d1d9`,i=`2px solid ${t()?`#388bfd`:`transparent`}`;return n!==e.e&&v(a,`background`,e.e=n),r!==e.t&&v(a,`color`,e.t=r),i!==e.a&&v(a,`border-left`,e.a=i),e},{e:void 0,t:void 0,a:void 0}),a})()}})),C(de,k),O(E,n(o,{get when(){return U()},get children(){var e=ee(),t=e.firstChild.nextSibling;return t.nextSibling,O(e,B,t),e}}),null),r(e=>{var t=U(),n=R(!U()),r=U()||!V(),i=R(!U()&&!!V()),a=U()||!V(),o=R(!U()&&!!V()),p=U()||!V(),m=R(!U()&&!!V()),h=U()||!V(),_=R(!U()&&!!V()),y=$()?`#f85149`:`#8b949e`,b=G()||U()||!q()||$(),x=$()?`Content exceeds the 100 KB segment limit`:`Save this segment to the server`,C=G()||!q()||$()?`#161b22`:`#1a3a2a`,w=G()||!q()||$()?`#484f58`:`#3fb950`,T=G()||!q()||$()?`default`:`pointer`;return t!==e.e&&(s.disabled=e.e=t),e.t=D(s,n,e.t),r!==e.a&&(c.disabled=e.a=r),e.o=D(c,i,e.o),a!==e.i&&(l.disabled=e.i=a),e.n=D(l,o,e.n),p!==e.s&&(u.disabled=e.s=p),e.h=D(u,m,e.h),h!==e.r&&(d.disabled=e.r=h),e.d=D(d,_,e.d),y!==e.l&&v(f,`color`,e.l=y),b!==e.u&&(g.disabled=e.u=b),x!==e.c&&S(g,`title`,e.c=x),C!==e.w&&v(g,`background`,e.w=C),w!==e.m&&v(g,`color`,e.m=w),T!==e.f&&v(g,`cursor`,e.f=T),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0,l:void 0,u:void 0,c:void 0,w:void 0,m:void 0,f:void 0}),t})()}b([`click`]);export{z as SegmentsPanel};
|
|
@@ -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-BasnHkIF.js","_client/src-C1zkeMAI.js","_client/vendor-pixi-Dpe0vQ3d.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,D as t,E as n,L as r,R as i,k as a,m as o,z as s}from"./vendor-codemirror-Brvxffeo.js";import{x as c}from"./vendor-pixi-Dpe0vQ3d.js";import{C as l,S as u,b as d,v as ee,x as te}from"./src-C1zkeMAI.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=>n(()=>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 fe=`_$DX_DELEGATE`;function pe(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 a(r=>{i=r,t===document?e():we(t,e(),t.firstChild?null:void 0,n)},r.owner),()=>{i(),t.textContent=``}}function me(e,t,n,r){let i,a=()=>{if(h())throw Error(`Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration.`);let t=r?document.createElementNS(`http://www.w3.org/1998/Math/MathML`,`template`):document.createElement(`template`);return t.innerHTML=e,n?t.content.firstChild.firstChild:r?t.firstChild:t.content.firstChild},o=t?()=>s(()=>document.importNode(i||=a(),!0)):()=>(i||=a()).cloneNode(!0);return o.cloneNode=o,o}function he(e,t=window.document){let n=t[fe]||(t[fe]=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,ke))}}function p(e,t,n){h(e)||(n==null?e.removeAttribute(t):e.setAttribute(t,n))}function ge(e,t,n,r){h(e)||(r==null?e.removeAttributeNS(t,n):e.setAttributeNS(t,n,r))}function _e(e,t,n){h(e)||(n?e.setAttribute(t,``):e.removeAttribute(t))}function ve(e,t){h(e)||(t==null?e.removeAttribute(`class`):e.className=t)}function ye(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 be(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 m(e,t,n){if(!t)return n?p(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,n={},r,i){let a={};return i||t(()=>a.children=_(e,n.children,a.children)),t(()=>typeof n.ref==`function`&&Ce(n.ref,e)),t(()=>Te(e,n,r,!0,a,!0)),a}function Ce(e,t,n){return s(()=>e(t,n))}function we(e,n,r,i){if(r!==void 0&&!i&&(i=[]),typeof n!=`function`)return _(e,n,i,r);t(t=>_(e,n(),t,r),i)}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]=g(e,r,null,i[r],n,a,t)}for(let o in t){if(o===`children`){r||_(e,t.children);continue}let s=t[o];i[o]=g(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 g(e,t,n,r,i,a,o){let s,c,l,u,d;if(t===`style`)return m(e,n,r);if(t===`classList`)return be(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)&&(ye(e,i,n,a),a&&he([i]))}else if(t.slice(0,5)===`attr:`)p(e,t.slice(5),n);else if(t.slice(0,5)===`bool:`)_e(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`?ve(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?ge(e,r,t,n):p(e,ie[t]||t,n)}return n}function ke(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 _(e,n,r,i,a){let o=h(e);if(o){!r&&(r=[...e.childNodes]);let t=[];for(let e=0;e<r.length;e++){let n=r[e];n.nodeType===8&&n.data.slice(0,2)===`!$`?n.remove():t.push(n)}r=t}for(;typeof r==`function`;)r=r();if(n===r)return r;let s=typeof n,c=i!==void 0;if(e=c&&r[0]&&r[0].parentNode||e,s===`string`||s===`number`){if(o||s===`number`&&(n=n.toString(),n===r))return r;if(c){let t=r[0];t&&t.nodeType===3?t.data!==n&&(t.data=n):t=document.createTextNode(n),r=y(e,r,i,t)}else r=r!==``&&typeof r==`string`?e.firstChild.data=n:e.textContent=n}else if(n==null||s===`boolean`){if(o)return r;r=y(e,r,i)}else if(s===`function`)return t(()=>{let t=n();for(;typeof t==`function`;)t=t();r=_(e,t,r,i)}),()=>r;else if(Array.isArray(n)){let s=[],l=r&&Array.isArray(r);if(v(s,n,r,a))return t(()=>r=_(e,s,r,i,!0)),()=>r;if(o){if(!s.length)return r;if(i===void 0)return r=[...e.childNodes];let t=s[0];if(t.parentNode!==e)return r;let n=[t];for(;(t=t.nextSibling)!==i;)n.push(t);return r=n}if(s.length===0){if(r=y(e,r,i),c)return r}else l?r.length===0?Ae(e,s,i):de(e,r,s):(r&&y(e),Ae(e,s));r=s}else if(n.nodeType){if(o&&n.parentNode)return r=c?[n]:n;if(Array.isArray(r)){if(c)return r=y(e,r,i,n);y(e,r,null,n)}else r==null||r===``||!e.firstChild?e.appendChild(n):e.replaceChild(n,e.firstChild);r=n}else console.warn(`Unrecognized value. Skipped inserting`,n);return r}function v(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=v(e,o,s)||i;else if(c===`function`)if(r){for(;typeof o==`function`;)o=o();i=v(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 Ae(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 i=n(e);return n(()=>{let e=i();switch(typeof e){case`function`:return Object.assign(e,{[o]:!0}),s(()=>e(t));case`string`:let n=ce.has(e),i=r.context?Ee():Ne(e,n,s(()=>t.is));return Se(i,t,n),i}})}function Fe(e){let[,t]=i(e,[`component`]);return Pe(()=>e.component,t)}function b(){return typeof window<`u`&&window.__TAURI_INTERNALS__!=null}var Ie=!1;async function Le(){if(Ie)return;let[{fetch:e},{setFetch:t}]=await Promise.all([c(()=>import(`./dist-js-wcmIejjc.js`),__vite__mapDeps([0,1])),c(()=>import(`./src-BasnHkIF.js`),__vite__mapDeps([2,3,4,5,6]))]);t(e),Ie=!0}async function Re(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[ze,Be]=e([]),Ve=0;function He(e,t=`success`,n=4e3){let r=Ve++;Be(i=>[...i,{id:r,message:e,type:t,duration:n}]),setTimeout(()=>{Be(e=>e.filter(e=>e.id!==r))},n)}var Ue=!1;function x(){return!0}function We(){return Ue}function S(){return window.location.origin}function Ge(){return`0.17.0`}function Ke(){return typeof window>`u`?null:window.__SCREEPS_CLIENT_EMBEDDED__??null}function qe(){let e=`/client/`;return e.startsWith(`.`)?``:e.replace(/\/$/,``)}function C(){return typeof window<`u`&&window.__SCREEPS_CLIENT_PROXY__!=null}function Je(){return window.__SCREEPS_CLIENT_PROXY__?.backend??null}function Ye(e){let t=window.location.origin;return Je()?t:e.startsWith(`${t}/(`)?e:`${t}/(${e.replace(/\/$/,``)})`}function w(e){let t=`[${e}]`;return{log:()=>{},warn:()=>{},error:(...e)=>console.error(t,...e)}}function T(){return b()||C()?localStorage:sessionStorage}var Xe={room:`screeps:room`,shard:`screeps:shard`,sidebarWidth:`screeps:sidebarWidth`,consoleHeight:`screeps:consoleHeight`,consoleSplit:`screeps:consoleSplit`,consoleWeights:`screeps:consoleWeights`,memoryWatches:`screeps:memoryWatches`,mapZoom:`screeps:mapZoom`,codeBranch:`screeps:code:branch`,codeModule:`screeps:code:module`,codeCursors:`screeps:code:cursors`,segmentsLast:`screeps:segments:last`,customUiEditorView:`screeps:customUi:editorView`,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`,smoothAnimations:`screeps:settings:smoothAnimations`,spriteTheme:`screeps:settings:spriteTheme`,showMapVisuals:`screeps:settings:showMapVisuals`,hideCustomUiProtocol:`screeps:settings:hideCustomUiProtocol`,customUiSegment:`screeps:customUi:segment`,customUiShard:`screeps:customUi:shard`},E={url:`screeps:url`,token:`screeps:token`,serverPassword:`screeps:serverPassword`,authMethod:`screeps:authMethod`};function Ze(e){return localStorage.getItem(e)}function Qe(e,t){localStorage.setItem(e,t)}function $e(e){localStorage.removeItem(e)}function et(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 tt(e,t){localStorage.setItem(e,String(t))}function nt(e,t){let n=localStorage.getItem(e);if(n===null)return t;try{return JSON.parse(n)}catch{return t}}function rt(e,t){localStorage.setItem(e,JSON.stringify(t))}function D(e){return T().getItem(e)}function O(e,t){T().setItem(e,t)}function k(e){T().removeItem(e)}async function it(){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:A}=w(`keychain`),j=`screeps-desktop`,at=`screeps:keychain:`,M=e=>`${at}${e}`;async function ot(e,t){A(`save [${e}]`);try{await f(`keyring_set`,{service:j,account:e,secret:t}),A(`save [${e}] ✓`)}catch(t){throw A(`save [${e}] ✗`,t),t}}async function st(e){A(`load [${e}]`);try{let t=await f(`keyring_get`,{service:j,account:e});return A(`load [${e}] →`,t===null?`[not found]`:`[found]`),t}catch(t){throw A(`load [${e}] ✗`,t),t}}async function ct(e){A(`delete [${e}]`);try{await f(`keyring_delete`,{service:j,account:e}),A(`delete [${e}] ✓`)}catch(t){throw A(`delete [${e}] ✗`,t),t}}var N=e=>`${e}:token`,P=e=>`${e}:serverPassword`,F=e=>`${e}:savedCredential`;async function I(e,t){if(b())return ot(e,t);if(C()){localStorage.setItem(M(e),t);return}}async function L(e){return b()?st(e):C()?localStorage.getItem(M(e)):null}async function R(e){if(b())return ct(e);if(C()){localStorage.removeItem(M(e));return}}async function lt(e,t){await I(N(e),t)}async function ut(e){return L(N(e))}async function dt(e){await R(N(e))}async function ft(e,t){await I(P(e),t)}async function pt(e){return L(P(e))}async function mt(e){await R(P(e))}async function ht(e,t){await I(F(e),t)}async function gt(e){return L(F(e))}async function _t(e){await R(F(e))}var{log:z}=w(`client`),[B,V]=e(null),[vt,H]=e(`idle`),[yt,U]=e(null),[bt,W]=e(null),[xt,G]=e(null),[St,Ct]=e(null),[wt,Tt]=e(null),[Et,Dt]=e(null),[Ot,kt]=e(null),[At,jt]=e(!1),[Mt,Nt]=e(null),[Pt,K]=e(null),[Ft,It]=e({}),[Lt,Rt]=e(null),zt=1e3,Bt=15e3,q=null,J=0;function Vt(){q===null&&(z(`world status polling: start`),q=setInterval(()=>{let e=B();e&&e.stores.user.refreshWorldStatus().catch(()=>{})},zt))}function Ht(){q!==null&&(z(`world status polling: stop`),clearInterval(q),q=null)}function Y(e){e===`empty`||e===`lost`||Date.now()<J?Vt():Ht()}function Ut(){J=Date.now()+Bt,Vt()}var X=-1,Z=-1,Q=[],Wt=5;function Gt(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>Wt&&Q.shift();let t=Q.reduce((e,t)=>e+t,0)/Q.length;kt(Math.round(t))}}X=e,Z=t}function Kt(){X=-1,Z=-1,Q.length=0,kt(null)}var qt=()=>{let e=wt();return e?(e.serverData?.shards?.length??0)===0:null};async function $(e){x()?e={...e,url:S()}:C()&&(e={...e,url:Ye(e.url)}),z(`connecting to ${e.url} (auth: ${e.auth})`),H(`connecting`),U(null),W(null),G(null);try{let t;if(e.auth===`guest`)t=new d,jt(!0);else if(e.auth===`password`){if(!e.email||!e.password)throw Error(`Email and password are required`);t=new te({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 u({token:e.token,supportsTokenRefresh:n})}let n=new l({url:e.url,auth:t,storage:e.storage??new ee(`screeps-client`),debug:!1,serverPassword:e.serverPassword});n.http.on(`http:tokenRefresh`,({token:t})=>{z(`token refreshed`),b()?lt(e.url,t):O(E.token,t)}),n.http.on(`http:error`,({method:e,path:t,error:n,silent:r,status:i})=>{if(z(`http error:`,e,t,n.message),i===429){let e=n.message.match(/https?:\/\/\S+/);G({message:n.message.replace(/^HTTP 429:\s*/,``),disableLink:e?e[0]:null});return}r||He(`Request failed: ${e} ${t} — ${n.message}`,`error`,6e3)}),n.stores.server.on(`server:disconnected`,e=>{z(`server disconnected (willReconnect: ${e.willReconnect}, intentional: ${e.intentional})`),!e.willReconnect&&!e.intentional&&(J=0,Y(null),W(`Lost connection to the server.`))}),n.stores.server.on(`server:error`,e=>{z(`server error:`,e.error.message),W(e.error.message)}),n.stores.user.on(`user:me`,e=>{z(`user: ${e.username} (id: ${e._id})`),Ct(e)}),n.stores.server.on(`server:version`,e=>{z(`server version: ${e.package??`unknown`}`),Tt(e)}),n.stores.user.on(`user:stream`,e=>{if(e&&typeof e==`object`&&`flags`in e){let t=e.flags;t&&typeof t==`object`&&It(t)}}),n.stores.user.on(`user:worldStatus`,({status:e})=>{z(`world status: ${e}`),Rt(e),Y(e)}),await n.connect(),n.stores.user.subscribeUserStream(),V(n),H(`connected`),z(`connected to ${e.url}`),O(E.url,e.url);let r=e.authMethod??e.auth;Nt(r),O(E.authMethod,r),n.http.token&&(b()?await lt(e.url,n.http.token):O(E.token,n.http.token)),e.serverPassword?b()?await ft(e.url,e.serverPassword):O(E.serverPassword,e.serverPassword):b()?mt(e.url):k(E.serverPassword)}catch(e){let t=e instanceof Error?e.message:String(e);throw z(`connection failed:`,t),U(t),H(`error`),V(null),e}}async function Jt(){let e=x()?S():D(E.url);if(!e)return;let t,n;if(b()?(t=await ut(e),n=await pt(e)??void 0):(t=D(E.token),n=D(E.serverPassword)??void 0),!t)return;let r=D(E.authMethod);z(`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{z(`auto-connect failed — clearing stored token`),b()?dt(e):k(E.token)}}function Yt(){if(z(`disconnecting`),b()){let e=D(E.url),t=Mt();e&&t!==`token`&&dt(e)}let e=B();e&&e.disconnect(),V(null),H(`idle`),U(null),W(null),G(null),Ct(null),Tt(null),Dt(null),jt(!1),Nt(null),K(null),It({}),Rt(null),J=0,Y(null),Kt(),b()?k(E.authMethod):(k(E.token),k(E.url),k(E.serverPassword),k(E.authMethod))}export{ye as $,nt as A,Ye as B,Lt as C,Xe as D,ht as E,rt as F,x as G,Ge as H,tt as I,ze as J,We as K,Qe as L,D as M,Ze as N,E as O,$e as P,Fe as Q,w as R,Pt as S,gt as T,Ke as U,qe as V,S as W,b as X,Le as Y,Re as Z,vt as _,yt as a,xe as at,Ft as b,At as c,me as ct,Gt as d,he as et,wt as f,K as g,G as h,Yt as i,p as it,et as j,it as k,qt as l,Ce as lt,Dt as m,B as n,ue as nt,Ut as o,Se as ot,bt as p,He as q,$ as r,pe as rt,Et as s,m as st,Mt as t,we as tt,xt as u,Ot as v,_t as w,St as x,Jt as y,C as z};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as e,S as t,_ as n,g as r,h as i,j as a}from"./vendor-codemirror-Brvxffeo.js";import{D as o,L as s,M as c,N as l,O as u,P as d,R as f,c as p,n as m,q as h,x as g}from"./clientStore-Bi6dgzok.js";import{g as ee}from"./src-C1zkeMAI.js";import{r as te,s as ne}from"./roomDataStore-0NPTJjQf.js";var _=Symbol(`store-raw`),v=Symbol(`store-node`),y=Symbol(`store-has`),re=Symbol(`store-self`),ie={onStoreNodeUpdate:null};function ae(e){let t=e[i];if(!t&&(Object.defineProperty(e,i,{value:t=new Proxy(e,ce)}),!Array.isArray(e))){let n=Object.keys(e),r=Object.getOwnPropertyDescriptors(e),i=Object.getPrototypeOf(e),a=i!==null&&typeof e==`object`&&!!e&&!Array.isArray(e)&&i!==Object.prototype;if(a){let e=Object.getOwnPropertyDescriptors(i);n.push(...Object.keys(e)),Object.assign(r,e)}for(let i=0,o=n.length;i<o;i++){let o=n[i];a&&o===`constructor`||r[o].get&&Object.defineProperty(e,o,{configurable:!0,enumerable:r[o].enumerable,get:r[o].get.bind(t)})}}return t}function b(e){let t;return typeof e==`object`&&!!e&&(e[i]||!(t=Object.getPrototypeOf(e))||t===Object.prototype||Array.isArray(e))}function x(e,t=new Set){let n,r,i,a;if(n=e!=null&&e[_])return n;if(!b(e)||t.has(e))return e;if(Array.isArray(e)){Object.isFrozen(e)?e=e.slice(0):t.add(e);for(let n=0,a=e.length;n<a;n++)i=e[n],(r=x(i,t))!==i&&(e[n]=r)}else{Object.isFrozen(e)?e=Object.assign({},e):t.add(e);let n=Object.keys(e),o=Object.getOwnPropertyDescriptors(e);for(let s=0,c=n.length;s<c;s++)a=n[s],!o[a].get&&(i=e[a],(r=x(i,t))!==i&&(e[a]=r))}return e}function S(e,t){let n=e[t];return n||Object.defineProperty(e,t,{value:n=Object.create(null)}),n}function C(t,n,r){if(t[n])return t[n];let[i,a]=e(r,{equals:!1,internal:!0});return i.$=a,t[n]=i}function oe(e,t){let n=Reflect.getOwnPropertyDescriptor(e,t);return!n||n.get||!n.configurable||t===i||t===v?n:(delete n.value,delete n.writable,n.get=()=>e[i][t],n)}function w(e){a()&&C(S(e,v),re)()}function se(e){return w(e),Reflect.ownKeys(e)}var ce={get(e,t,n){if(t===_)return e;if(t===i)return n;if(t===r)return w(e),n;let o=S(e,v),s=o[t],c=s?s():e[t];if(t===v||t===y||t===`__proto__`)return c;if(!s){let n=Object.getOwnPropertyDescriptor(e,t);a()&&(typeof c!=`function`||Object.prototype.hasOwnProperty.call(e,t))&&!(n&&n.get)&&(c=C(o,t,c)())}return b(c)?ae(c):c},has(e,t){return t===_||t===i||t===r||t===v||t===y||t===`__proto__`?!0:(a()&&C(S(e,y),t)(),t in e)},set(){return console.warn(`Cannot mutate a Store directly`),!0},deleteProperty(){return console.warn(`Cannot mutate a Store directly`),!0},ownKeys:se,getOwnPropertyDescriptor:oe};function T(e,t,n,r=!1){if(t===`__proto__`){console.warn(`Refusing to set "__proto__" on a store.`);return}if(!r&&e[t]===n)return;let i=e[t],a=e.length;ie.onStoreNodeUpdate&&ie.onStoreNodeUpdate(e,t,n,i),n===void 0?(delete e[t],e[y]&&e[y][t]&&i!==void 0&&e[y][t].$()):(e[t]=n,e[y]&&e[y][t]&&i===void 0&&e[y][t].$());let o=S(e,v),s;if((s=C(o,t,i))&&s.$(()=>n),Array.isArray(e)&&e.length!==a){for(let t=e.length;t<a;t++)(s=o[t])&&s.$();(s=C(o,`length`,a))&&s.$(e.length)}(s=o[re])&&s.$()}function le(e,t){let n=Object.keys(t);for(let r=0;r<n.length;r+=1){let i=n[r];ue(i)||T(e,i,t[i])}}function ue(e){return e===`__proto__`||e===`constructor`||e===`prototype`}function de(e,t){if(typeof t==`function`&&(t=t(e)),t=x(t),Array.isArray(t)){if(e===t)return;let n=0,r=t.length;for(;n<r;n++){let r=t[n];e[n]!==r&&T(e,n,r)}T(e,`length`,r)}else le(e,t)}function E(e,t,n=[]){let r,i=e;if(t.length>1){r=t.shift();let a=typeof r,o=Array.isArray(e);if(a===`string`&&(r===`__proto__`||t.length>1&&ue(r))){console.warn(`Refusing to traverse unsafe key "${r}" on a store.`);return}if(Array.isArray(r)){for(let i=0;i<r.length;i++)E(e,[r[i]].concat(t),n);return}else if(o&&a===`function`){for(let i=0;i<e.length;i++)r(e[i],i)&&E(e,[i].concat(t),n);return}else if(o&&a===`object`){let{from:i=0,to:a=e.length-1,by:o=1}=r;for(let r=i;r<=a;r+=o)E(e,[r].concat(t),n);return}else if(t.length>1){E(e[r],t,[r].concat(n));return}i=e[r],n=[r].concat(n)}let a=t[0];typeof a==`function`&&(a=a(i,n),a===i)||r===void 0&&a==null||(a=x(a),r===void 0||b(i)&&b(a)&&!Array.isArray(a)?le(i,a):T(e,r,a))}function fe(...[e,r]){let i=x(e||{}),a=Array.isArray(i);if(typeof i!=`object`&&typeof i!=`function`)throw Error(`Unexpected type ${typeof i} received when initializing 'createStore'. Expected an object.`);let o=ae(i);n.registerGraph({value:i,name:r&&r.name});function s(...e){t(()=>{a&&e.length===1?de(i,e[0]):E(i,e)})}return[o,s]}var D=Symbol(`store-root`);function pe(e){return e===`__proto__`||e===`constructor`||e===`prototype`}function O(e,t,n,r,i){if(pe(n))return;let a=t[n];if(e===a)return;let o=Array.isArray(e);if(n!==D&&(!b(e)||!b(a)||o!==Array.isArray(a)||i&&e[i]!==a[i])){T(t,n,e);return}if(o){if(e.length&&a.length&&(!r||i&&e[0]&&e[0][i]!=null)){let t,n,o,s,c,l,u,d;for(o=0,s=Math.min(a.length,e.length);o<s&&(a[o]===e[o]||i&&a[o]&&e[o]&&a[o][i]&&a[o][i]===e[o][i]);o++)O(e[o],a,o,r,i);let f=Array(e.length),p=new Map;for(s=a.length-1,c=e.length-1;s>=o&&c>=o&&(a[s]===e[c]||i&&a[s]&&e[c]&&a[s][i]&&a[s][i]===e[c][i]);s--,c--)f[c]=a[s];if(o>c||o>s){for(n=o;n<=c;n++)T(a,n,e[n]);for(;n<e.length;n++)T(a,n,f[n]),O(e[n],a,n,r,i);a.length>e.length&&T(a,`length`,e.length);return}for(u=Array(c+1),n=c;n>=o;n--)l=e[n],d=i&&l?l[i]:l,t=p.get(d),u[n]=t===void 0?-1:t,p.set(d,n);for(t=o;t<=s;t++)l=a[t],d=i&&l?l[i]:l,n=p.get(d),n!==void 0&&n!==-1&&(f[n]=a[t],n=u[n],p.set(d,n));for(n=o;n<e.length;n++)n in f?(T(a,n,f[n]),O(e[n],a,n,r,i)):T(a,n,e[n])}else for(let t=0,n=e.length;t<n;t++)O(e[t],a,t,r,i);a.length>e.length&&T(a,`length`,e.length);return}let s=Object.keys(e);for(let t=0,n=s.length;t<n;t++)pe(s[t])||O(e[s[t]],a,s[t],r,i);let c=Object.keys(a);for(let t=0,n=c.length;t<n;t++)e[c[t]]===void 0&&T(a,c[t],void 0)}function me(e,t={}){let{merge:n,key:r=`id`}=t,i=x(e);return e=>{if(!b(e)||!b(i))return i;let t=O(i,{[D]:e},D,n,r);return t===void 0?e:t}}var k=new WeakMap,A={get(e,t){if(t===_)return e;let n=e[t];if(t===i||t===r||t===v||t===y||t===`__proto__`)return n;let a;return b(n)?k.get(n)||(k.set(n,a=new Proxy(n,A)),a):n},set(e,t,n){return T(e,t,x(n)),!0},deleteProperty(e,t){return T(e,t,void 0,!0),!0}};function he(e){return t=>{if(b(t)){let n;(n=k.get(t))||k.set(t,n=new Proxy(t,A)),e(n)}return t}}var[ge,_e]=e(!0),[ve,j]=e(!0),[ye,M]=e(!1),[be,N]=e(!1),[xe,Se]=e(!1),[Ce,P]=e(``),F;function we(e){F=e}function I(e){P(e),j(!0),requestAnimationFrame(()=>{F?.focus();let t=e.length;F?.setSelectionRange(t,t)})}function Te(){_e(e=>!e)}function Ee(){j(e=>!e)}function De(){M(e=>!e)}function Oe(){N(e=>!e)}var{log:L,warn:R}=f(`customUi`),z=[`own`,`reserved`,`empty`,`foreign`],B=`SCUI`,ke=15e3,V=32,H=40,Ae=64,je=50,Me=128,Ne=[`room`,`selection`,`tile`],Pe=[`button`,`select`,`status`,`header`],Fe=/^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*)*$/,[U,Ie]=e(null),[Le,Re]=e(``),[ze,W]=e(null),[Be,G]=e(null),[Ve,K]=e(!1);function He(){let e=g(),t=ne();if(t)return t.userId===e?._id?`own`:`foreign`;let n=te();return n?n.user===e?._id?`reserved`:`foreign`:`empty`}function Ue(e,t,n){if(!e.obj?.includes(t))return!1;if(e.owner!==void 0){if(n===null)return!1;let t=n===g()?._id;if(e.owner===`own`?!t:t)return!1}let r=e.showIf?.room;return!(r!==void 0&&!r.includes(He()))}function q(){return`${o.customUiSegment}:${c(u.url)??``}`}function J(){return`${o.customUiShard}:${c(u.url)??``}`}function We(){let e=l(q());if(e===null)return null;let t=Number(e);return Number.isInteger(t)&&t>=0&&t<=99?t:null}function Ge(e){e===null?d(q()):s(q(),String(e)),Ie(e),X()}function Ke(e){let t=e.trim();t?s(J(),t):d(J()),Re(t),X()}function Y(e,t,n={}){let r=n.allowItems??!0;if(e===void 0)return[];if(!Array.isArray(e))throw Error(`"${t}" must be an array`);if(e.length>V)throw Error(`"${t}" has more than ${V} elements`);return e.map((e,i)=>{let a=`${t}[${i}]`;if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`${a} must be an object`);let o=e,s=o.type===void 0?`button`:o.type;if(!Pe.includes(s))throw Error(`${a}.type may only be ${Pe.join(`, `)}`);if(n.objectMode&&s!==`button`&&s!==`select`)throw Error(`${a}: only buttons and selects are allowed in "objects"`);if(s===`header`&&!r)throw Error(`${a}: headers cannot be nested inside items`);if(typeof o.label!=`string`||!o.label.trim())throw Error(`${a}.label is missing`);let c={type:s,label:o.label.trim().slice(0,H),confirm:o.confirm===!0};if(c.type===`button`||c.type===`select`){if(typeof o.cmd!=`string`||!o.cmd.trim())throw Error(`${a}.cmd is missing`);c.cmd=o.cmd.trim().slice(0,Ae)}if(c.type===`select`){if(!Array.isArray(o.options)||o.options.length===0||o.options.some(e=>typeof e!=`string`||!e.trim()))throw Error(`${a}.options must be a non-empty array of strings`);if(o.options.length>je)throw Error(`${a}.options has more than ${je} entries`);c.options=o.options.map(e=>e.trim().slice(0,H))}if(c.type===`status`){if(typeof o.path!=`string`||!o.path.trim()||o.path.trim().length>Me||/\s/.test(o.path.trim()))throw Error(`${a}.path must be a memory path like "stats.energy"`);c.path=o.path.trim()}if(o.items!==void 0){if(c.type!==`header`)throw Error(`${a}.items is only allowed on headers`);c.items=Y(o.items,`${a}.items`,{allowItems:!1})}if(n.objectMode){let e=Array.isArray(o.obj)?o.obj:[o.obj];if(o.obj===void 0||e.length===0||e.some(e=>typeof e!=`string`||!e.trim()))throw Error(`${a}.obj must name one or more object types (e.g. "creep")`);if(c.obj=e.map(e=>e.trim()),o.owner!==void 0){if(o.owner!==`own`&&o.owner!==`foreign`)throw Error(`${a}.owner may only be "own" or "foreign"`);c.owner=o.owner}}if(o.needs!==void 0){if(!Array.isArray(o.needs)||o.needs.some(e=>!Ne.includes(e)))throw Error(`${a}.needs may only contain ${Ne.join(`, `)}`);c.needs=o.needs}if(o.showIf!==void 0){if(typeof o.showIf!=`object`||o.showIf===null||Array.isArray(o.showIf))throw Error(`${a}.showIf must be an object`);let e=o.showIf,t={};if(e.selType!==void 0){if(typeof e.selType!=`string`||!e.selType.trim())throw Error(`${a}.showIf.selType must be a string`);t.selType=e.selType.trim()}if(e.room!==void 0){let n=Array.isArray(e.room)?e.room:[e.room];if(n.length===0||n.some(e=>!z.includes(e)))throw Error(`${a}.showIf.room may only contain ${z.join(`, `)}`);t.room=n}c.showIf=t}return c})}function qe(e){if(!e||!e.trim())throw Error(`segment is empty`);let t;try{t=JSON.parse(e)}catch{throw Error(`segment is not valid JSON`)}if(typeof t!=`object`||!t||Array.isArray(t))throw Error(`segment must hold a JSON object`);let n=t;if(n.v!==1)throw Error(`unsupported config version (expected "v": 1)`);if(typeof n.handler!=`string`||!Fe.test(n.handler))throw Error(`"handler" must be a function name like "uiCommand"`);return{handler:n.handler,map:Y(n.map,`map`),room:Y(n.room,`room`),objects:Y(n.objects,`objects`,{allowItems:!1,objectMode:!0})}}async function X(){let e=m(),t=U();if(!e||t===null){W(null),G(null);return}K(!0);try{W(qe((await e.http.user.memory.segment.get(t,Le()||null)).data)),G(null),L(`loaded custom UI from segment ${t}`)}catch(e){W(null),G(`Segment ${t}: ${e.message}`),R(`config load failed:`,e)}finally{K(!1)}}var Z=new Map,[Je,Ye]=e(new Set);function Q(){Ye(new Set(Z.keys()))}var $=null;function Xe(e){return!e.includes(`<`)&&!e.includes(`&`)?e.trim():(new DOMParser().parseFromString(e,`text/html`).body.textContent??``).trim()}function Ze(e){return U()!==null&&Qe(e)!==null}function Qe(e){if(!e.includes(B))return null;let t=Xe(e),n=t.indexOf(B);if(n===-1)return null;let r=t.indexOf(`{`,n),i=t.lastIndexOf(`}`);if(r===-1||i<=r)return null;let a=t.slice(r,i+1);for(let e of[a,a.replace(/\\"/g,`"`)])try{let t=JSON.parse(e);if(typeof t==`object`&&t)return t}catch{}return null}function $e(e,t){let n=!1;if(typeof e.err==`string`?(h(e.err,`error`),n=!0):typeof e.msg==`string`&&(h(e.msg,`success`),n=!0),typeof e.room==`string`){let r=typeof e.shard==`string`?e.shard:t.shard;m()?.stores.navigation.navigateTo(e.room,r),n=!0}typeof e.console==`string`&&(I(e.console),n=!0),e.reload===!0&&(X(),n=!0),n||h(`${t.cmd}: done`,`success`)}function et(e){for(let t of[...e.log??[],...e.results??[]]){if(!t.includes(B))continue;let e=Qe(t);if(!e){R(`marker found but line not parseable:`,t);continue}if(typeof e.id!=`string`){R(`response has no "id":`,t);continue}let n=Z.get(e.id);if(!n){R(`response id "${e.id}" matches no pending command`);continue}window.clearTimeout(n.timer),Z.delete(e.id),Q(),$e(e,n)}}function tt(e,t,n){let r=m(),i=ze();if(!r||!i||!e.cmd)return null;let a=e.cmd,o=Math.random().toString(36).slice(2,10),s=`${i.handler}(${JSON.stringify({id:o,cmd:a,...n===void 0?{}:{value:n},ctx:t})})`,c=window.setTimeout(()=>{Z.delete(o),Q(),h(`${a}: no response`,`error`)},ke);return Z.set(o,{cmd:a,shard:t.shard,timer:c}),Q(),L(`dispatch:`,s),r.http.user.console(s,t.shard).catch(e=>{window.clearTimeout(c),Z.delete(o),Q(),h(`${a}: ${e.message}`,`error`)}),o}function nt(){if(p())return;let e=m();e&&(Ie(We()),Re(l(J())??``),$=new ee,$.add(e.stores.user.subscribe(`console`)),$.add(e.stores.user.on(`user:console`,e=>{et(e.messages)})),X())}function rt(){$?.dispose(),$=null;for(let e of Z.values())window.clearTimeout(e.timer);Z.clear(),Q(),W(null),G(null),K(!1)}export{Ee as A,M as C,ge as D,xe as E,he as F,me as I,De as M,Oe as N,ye as O,fe as P,Se as S,ve as T,Le as _,Ze as a,we as b,qe as c,Ge as d,Ke as f,U as g,Ve as h,nt as i,Te as j,be as k,Je as l,Be as m,tt as n,X as o,ze as p,rt as r,Ue as s,z as t,He as u,Ce as v,N as w,P as x,I as y};
|