screeps-client 0.12.2 → 0.13.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-CgFwZdry.js → CodePanel-CLT8cs2H.js} +1 -1
- package/dist/embedded/_client/{MapRenderer-BIugaYyt.js → MapRenderer-BvfpJvGb.js} +1 -1
- package/dist/{standalone/_client/MapViewer-COdsMuye.js → embedded/_client/MapViewer-DFpBb4w4.js} +1 -1
- package/dist/embedded/_client/clientStore-Bsp3grc8.js +2 -0
- package/dist/embedded/_client/index-DxoJa-to.js +18 -0
- package/dist/embedded/_client/src-DGV5lg9g.js +2 -0
- package/dist/embedded/_client/{src-Df9fXZby.js → src-TYHOEQPY.js} +1 -1
- package/dist/embedded/index.html +4 -4
- package/dist/standalone/_client/{CodePanel-CuVWVfrb.js → CodePanel-1vYxRD2N.js} +1 -1
- package/dist/standalone/_client/{MapRenderer-DyIJKwPC.js → MapRenderer-b8FMSs3l.js} +1 -1
- package/dist/{xxscreeps-mod/_client/MapViewer-CI0hW6b6.js → standalone/_client/MapViewer-B-FCtjUb.js} +1 -1
- package/dist/standalone/_client/clientStore-Dto6IEkm.js +2 -0
- package/dist/standalone/_client/index-CmHGseHl.js +18 -0
- package/dist/standalone/_client/{src-Br0nU_Z4.js → src-CBSP2mk_.js} +1 -1
- package/dist/standalone/_client/src-CK_prN2V.js +2 -0
- package/dist/standalone/index.html +4 -4
- package/dist/xxscreeps-mod/_client/{CodePanel-D84eibLe.js → CodePanel-B4BzS7aW.js} +1 -1
- package/dist/xxscreeps-mod/_client/{MapRenderer-C1RRZ_lc.js → MapRenderer-DLoooMtw.js} +1 -1
- package/dist/{embedded/_client/MapViewer-CcdKq0z8.js → xxscreeps-mod/_client/MapViewer-DbkDSvOH.js} +1 -1
- package/dist/xxscreeps-mod/_client/clientStore-CWoexgUt.js +2 -0
- package/dist/xxscreeps-mod/_client/index-DO8F8wMU.js +18 -0
- package/dist/xxscreeps-mod/_client/{src-DO_MHviu.js → src-47pdn8l4.js} +1 -1
- package/dist/xxscreeps-mod/_client/src-CJvmzAdR.js +2 -0
- package/dist/xxscreeps-mod/index.html +4 -4
- package/package.json +1 -1
- package/dist/embedded/_client/clientStore-WqbvVt9g.js +0 -2
- package/dist/embedded/_client/index-BQNPWMvV.js +0 -18
- package/dist/embedded/_client/src-Jwtz4qDC.js +0 -2
- package/dist/standalone/_client/clientStore-ZaX4LUce.js +0 -2
- package/dist/standalone/_client/index-bznOpMx_.js +0 -18
- package/dist/standalone/_client/src-CRRsf3N_.js +0 -2
- package/dist/xxscreeps-mod/_client/clientStore-BMhdZHSz.js +0 -2
- package/dist/xxscreeps-mod/_client/index-Crb_GYOh.js +0 -18
- package/dist/xxscreeps-mod/_client/src--XLK9p6c.js +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_client/decompress-DhdK5fhG.js","_client/decompress-CWkNrR0q.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{x as e}from"./vendor-pixi-DHGNQ8y2.js";import{n as t,t as n}from"./decompress-CWkNrR0q.js";var r;function i(e){r=e}function a(){return r??globalThis.fetch}var o=class e{fn;constructor(e){this.fn=e}static create(t){return t===!0?new e(console.debug.bind(console)):typeof t==`function`?new e(t):new e(null)}child(t){if(!this.fn)return this;let n=this.fn;return new e((...e)=>n(`[screeps:${t}]`,...e))}log(...e){this.fn?.(...e)}};function s(e){return{signin:(t,n)=>e.request(`POST`,`/api/auth/signin`,{email:t,password:n}),me:()=>e.request(`GET`,`/api/auth/me`),queryToken:t=>e.request(`GET`,`/api/auth/query-token`,{token:t}),steamTicket:(t,n)=>e.request(`POST`,`/api/auth/steam-ticket`,{ticket:t,...n==null?{}:{useNativeAuth:n}}),modInfo:()=>e.request(`GET`,`/api/authmod`)}}function c(e){return{list:()=>e.request(`GET`,`/api/game/power-creeps/list`),create:(t,n)=>e.request(`POST`,`/api/game/power-creeps/create`,{name:t,className:n}),delete:t=>e.request(`POST`,`/api/game/power-creeps/delete`,{id:t}),cancelDelete:t=>e.request(`POST`,`/api/game/power-creeps/cancel-delete`,{id:t}),upgrade:(t,n)=>e.request(`POST`,`/api/game/power-creeps/upgrade`,{id:t,powers:n}),rename:(t,n)=>e.request(`POST`,`/api/game/power-creeps/rename`,{id:t,name:n}),experimentation:()=>e.request(`POST`,`/api/game/power-creeps/experimentation`)}}function l(e,t){return t&&(e.shard=t),e}function u(e,t){return{roomTerrain:(t,n)=>e.request(`GET`,`/api/game/room-terrain`,l({room:t,encoded:1},n)),roomObjects:(t,n)=>e.request(`GET`,`/api/game/room-objects`,l({room:t},n)),roomDecorations:t?()=>Promise.resolve(t):(t,n)=>e.request(`GET`,`/api/game/room-decorations`,l({room:t},n)),roomStatus:(t,n)=>e.request(`GET`,`/api/game/room-status`,l({room:t},n)),roomOverview:(t,n=8,r)=>e.request(`GET`,`/api/game/room-overview`,l({room:t,interval:n},r)),time:t=>e.request(`GET`,`/api/game/time`,l({},t)),worldSize:t=>e.request(`GET`,`/api/game/world-size`,l({},t)),mapStats:(t,n,r)=>e.request(`POST`,`/api/game/map-stats`,l({rooms:t,statName:n},r)),roomsTerrain:(t,n)=>{let r=new URLSearchParams({encoded:`true`});return n&&r.set(`shard`,n),e.request(`POST`,`/api/game/rooms?${r}`,{rooms:t})},createFlag:(t,n,r,i,a,o,s)=>e.request(`POST`,`/api/game/create-flag`,l({room:t,x:n,y:r,name:i,color:a,secondaryColor:o},s)),genUniqueFlagName:()=>e.request(`POST`,`/api/game/gen-unique-flag-name`),checkUniqueFlagName:t=>e.request(`POST`,`/api/game/check-unique-flag-name`,{name:t}),changeFlagColor:(t,n,r,i)=>e.request(`POST`,`/api/game/change-flag-color`,{room:t,name:n,color:r,secondaryColor:i}),removeFlag:(t,n)=>e.request(`POST`,`/api/game/remove-flag`,{room:t,name:n}),genUniqueObjectName:(t,n)=>e.request(`POST`,`/api/game/gen-unique-object-name`,l({type:t},n)),checkUniqueObjectName:(t,n,r)=>e.request(`POST`,`/api/game/check-unique-object-name`,l({type:t,name:n},r)),placeSpawn:(t,n,r,i,a)=>e.request(`POST`,`/api/game/place-spawn`,l({room:t,x:n,y:r,...i?{name:i}:{}},a)),createConstruction:(t,n,r,i,a,o)=>e.request(`POST`,`/api/game/create-construction`,l({room:t,x:n,y:r,structureType:i,...a?{name:a}:{}},o)),removeConstructionSite:(t,n,r)=>e.request(`POST`,`/api/game/add-object-intent`,l({_id:`room`,room:t,name:`removeConstructionSite`,intent:n.map(e=>({id:e,roomName:t}))},r)),addObjectIntent:(t,n,r,i,a)=>e.request(`POST`,`/api/game/add-object-intent`,l({_id:t,room:n,name:r,intent:i},a)),addGlobalIntent:(t,n)=>e.request(`POST`,`/api/game/add-global-intent`,{name:t,intent:n}),roomHistory:(t,n,r)=>r?e.request(`GET`,`/room-history/${encodeURIComponent(r)}/${encodeURIComponent(t)}/${n}.json`):e.request(`GET`,`/room-history`,{room:t,time:n}),setNotifyWhenAttacked:(t,n)=>e.request(`POST`,`/api/game/set-notify-when-attacked`,{_id:t,enabled:n}),createInvader:(t,n,r,i,a,o)=>e.request(`POST`,`/api/game/create-invader`,{room:t,x:n,y:r,size:i,type:a,...o==null?{}:{boosted:o}}),removeInvader:t=>e.request(`POST`,`/api/game/remove-invader`,{_id:t}),tick:()=>e.request(`GET`,`/api/game/tick`),powerCreeps:c(e),market:{ordersIndex:t=>e.request(`GET`,`/api/game/market/orders-index`,l({},t)),myOrders:()=>e.request(`GET`,`/api/game/market/my-orders`),orders:(t,n)=>e.request(`GET`,`/api/game/market/orders`,l({resourceType:t},n)),stats:(t,n)=>e.request(`GET`,`/api/game/market/stats`,l({resourceType:t},n))},shards:{info:()=>e.request(`GET`,`/api/game/shards/info`)}}}function d(e){return{send:(t,n)=>e.request(`POST`,`/api/user/messages/send`,{respondent:t,text:n}),list:t=>e.request(`GET`,`/api/user/messages/list`,{respondent:t}),index:()=>e.request(`GET`,`/api/user/messages/index`),markRead:t=>e.request(`POST`,`/api/user/messages/mark-read`,{id:t}),unreadCount:()=>e.request(`GET`,`/api/user/messages/unread-count`)}}function f(e,t){return t&&(e.shard=t),e}function p(e){return{branches:()=>e.request(`GET`,`/api/user/branches`),code:{get:t=>e.request(`GET`,`/api/user/code`,t?{branch:t}:{}),set:(t,n)=>e.request(`POST`,`/api/user/code`,{branch:t,modules:n,_hash:Date.now()})},memory:{get:(t,n)=>e.request(`GET`,`/api/user/memory`,f({path:t},n)),set:(t,n,r)=>e.request(`POST`,`/api/user/memory`,f({path:t,value:n},r)),segment:{get:(t,n)=>e.request(`GET`,`/api/user/memory-segment`,f({segment:t},n)),set:(t,n,r)=>e.request(`POST`,`/api/user/memory-segment`,f({segment:t,data:n},r))}},console:(t,n)=>e.request(`POST`,`/api/user/console`,f({expression:t},n)),stats:(t,n)=>e.request(`GET`,`/api/user/stats`,n==null?{interval:t}:{interval:t,id:n},{silent:!0}),rooms:t=>e.request(`GET`,`/api/user/rooms`,{id:t},{silent:!0}),overview:(t,n)=>e.request(`GET`,`/api/user/overview`,{interval:t,statName:n},{silent:!0}),worldStatus:()=>e.request(`GET`,`/api/user/world-status`),worldStartRoom:t=>e.request(`GET`,`/api/user/world-start-room`,f({},t)),find:t=>e.request(`GET`,`/api/user/find`,t),moneyHistory:t=>e.request(`GET`,`/api/user/money-history`,t==null?{}:{page:t}),respawn:()=>e.request(`POST`,`/api/user/respawn`),respawnProhibitedRooms:()=>e.request(`GET`,`/api/user/respawn-prohibited-rooms`),badge:t=>e.request(`POST`,`/api/user/badge`,{badge:t}),setActiveBranch:(t,n)=>e.request(`POST`,`/api/user/set-active-branch`,{activeName:t,branch:n}),cloneBranch:(t,n,r)=>e.request(`POST`,`/api/user/clone-branch`,{newName:t,...n?{branch:n}:{},...r==null?{}:{defaultModules:r}}),deleteBranch:t=>e.request(`POST`,`/api/user/delete-branch`,{branch:t}),notifyPrefs:t=>e.request(`POST`,`/api/user/notify-prefs`,t),tutorialDone:()=>e.request(`POST`,`/api/user/tutorial-done`),email:t=>e.request(`POST`,`/api/user/email`,{email:t}),setSteamVisible:t=>e.request(`POST`,`/api/user/set-steam-visible`,{visible:t}),password:(t,n)=>e.request(`POST`,`/api/user/password`,{password:t,...n==null?{}:{oldPassword:n}}),messages:d(e)}}function m(e){return{list:(t=10,n=`world`,r=0,i)=>e.request(`GET`,`/api/leaderboard/list`,{limit:t,mode:n,offset:r,season:i}),find:(t,n=`world`,r=``)=>e.request(`GET`,`/api/leaderboard/find`,{username:t,mode:n,season:r},{silent:!0}),seasons:()=>e.request(`GET`,`/api/leaderboard/seasons`)}}function ee(e){return{pvp:(t=100)=>e.request(`GET`,`/api/experimental/pvp`,{interval:t}),nukes:()=>e.request(`GET`,`/api/experimental/nukes`)}}function te(e){return{checkEmail:t=>e.request(`GET`,`/api/register/check-email`,{email:t}),checkUsername:t=>e.request(`GET`,`/api/register/check-username`,{username:t}),setUsername:(t,n)=>e.request(`POST`,`/api/register/set-username`,{username:t,...n==null?{}:{email:n}}),submit:(t,n,r,i)=>e.request(`POST`,`/api/register/submit`,{username:t,email:n,password:r,...i==null?{}:{modules:i}})}}var h=class extends EventTarget{baseUrl;authStrategy;logger;serverPassword;token=null;rateLimits=new Map;authenticating=!1;auth;register;game;user;leaderboard;experimental;constructor(e){super(),this.baseUrl=e.url.endsWith(`/`)?e.url:`${e.url}/`,this.authStrategy=e.auth,this.logger=e.logger??o.create(),this.serverPassword=e.serverPassword??null,this.auth=s(this),this.register=te(this),this.game=u(this,e.decorationsMock),this.user=p(this),this.leaderboard=m(this),this.experimental=ee(this)}emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}on(e,t){let n=e=>t(e.detail);return this.addEventListener(e,n),{dispose:()=>{this.removeEventListener(e,n)}}}async authenticate(){this.logger.log(`authenticate`),this.authenticating=!0;try{this.token=await this.authStrategy.authenticate(this),this.logger.log(`authenticated`)}finally{this.authenticating=!1}}setToken(e){this.token=e}async request(e,t,r,i={}){this.logger.log(e,t);let o=new URL(t.startsWith(`/`)?t.slice(1):t,this.baseUrl),s={};this.token&&(s[`X-Token`]=this.token,s[`X-Username`]=this.token),this.serverPassword&&(s[`X-Server-Password`]=this.serverPassword);let c={method:e,headers:s};if(e===`GET`&&r)for(let[e,t]of Object.entries(r))t!=null&&o.searchParams.set(e,String(t));else r&&(s[`Content-Type`]=`application/json`,c.body=JSON.stringify(r));let l=await a()(o.toString(),c),u=l.headers.get(`x-token`);if(u&&(this.authStrategy.supportsTokenRefresh??!0)&&(this.token=u,this.emit(`http:tokenRefresh`,{token:u})),this.updateRateLimit(t,l),l.status===401&&!i.isRetry&&!this.authenticating)return await this.authenticate(),this.request(e,t,r,{...i,isRetry:!0});if(!l.ok&&l.status!==304){let n=``;try{n=await l.text()}catch{}let r=Error(`HTTP ${l.status}: ${n}`);throw this.emit(`http:error`,{method:e,path:t,status:l.status,error:r,silent:i.silent}),r}this.emit(`http:success`,{method:e,path:t,status:l.status});let d=await l.json();if(typeof d.error==`string`){let n=Error(`Screeps API error: ${d.error}`);throw this.emit(`http:error`,{method:e,path:t,status:l.status,error:n,silent:i.silent}),n}return typeof d.data==`string`&&d.data.startsWith(`gz:`)&&(d.data=await n(d.data)),d}updateRateLimit(e,t){let n=t.headers.get(`x-ratelimit-limit`),r=t.headers.get(`x-ratelimit-remaining`),i=t.headers.get(`x-ratelimit-reset`);n&&r&&i&&this.rateLimits.set(e,{limit:parseInt(n,10),remaining:parseInt(r,10),reset:parseInt(i,10)})}};async function g(e){let n=typeof e==`string`?e:e.data;if(n.startsWith(`gz:`)&&(n=JSON.stringify(await t(n))),n.startsWith(`[`)){let[e,t]=JSON.parse(n);return{kind:`channel`,message:{channel:e,data:t}}}let[r,...i]=n.split(` `);switch(r){case`auth`:return{kind:`server`,command:{type:`auth`,status:i[0],token:i[1]}};case`time`:return{kind:`server`,command:{type:`time`,time:parseInt(i[0],10)}};case`protocol`:return{kind:`server`,command:{type:`protocol`,protocol:parseInt(i[0],10)}};case`package`:return{kind:`server`,command:{type:`package`,package:parseInt(i[0],10)}};default:throw Error(`Unknown server command: ${r}`)}}var _=class{wsUrl;WS;logger;ws=null;token=null;authed=!1;_connected=!1;reconnecting=!1;authSub=null;queue=[];subs=new Map;listeners=new Map;MAX_RETRIES=10;MAX_DELAY_MS=6e4;_intentionalClose=!1;constructor(e){let t=e.url.replace(/^http/,`ws`).replace(/\/$/,``);this.wsUrl=`${t}/socket/websocket`,this.WS=e.WebSocket??globalThis.WebSocket,this.logger=e.logger??o.create()}get isConnected(){return this._connected}setToken(e){this.token=e}connect(e){return this.logger.log(`connect`,this.wsUrl),this.reconnecting||(this._intentionalClose=!1),this.token=e,this.authSub?.dispose(),this.authSub=null,new Promise((e,t)=>{this.ws=new this.WS(this.wsUrl),this.ws.onopen=()=>{this.logger.log(`WebSocket opened`),this._connected=!0,this.reconnecting=!1,this.rawSend(`auth ${this.token}`),this.authSub=this.once(`auth`,n=>{let r=n;if(r.status===`ok`){for(this.logger.log(`auth ok`),this.authed=!0,r.token&&(this.token=r.token,this.emit(`socket:tokenRefresh`,{token:r.token}));this.queue.length;)this.rawSend(this.queue.shift());this.emit(`connected`,{}),e()}else this.logger.log(`auth failed`),t(Error(`WebSocket auth failed`))})},this.ws.onclose=()=>{this.logger.log(`WebSocket closed`),this._connected=!1,this.authed=!1,this.authSub?.dispose(),this.authSub=null,this.emit(`disconnected`,{willReconnect:this.reconnecting}),this.scheduleReconnect()},this.ws.onerror=e=>{this._connected||t(e)},this.ws.onmessage=e=>{this.handleMessage(e).catch(t=>{let n=typeof e.data==`string`?e.data.slice(0,200):`(binary)`;this.logger.log(`message parse error`,t instanceof Error?t.stack??t.message:String(t),`raw:`,n),this.emit(`socket:error`,t instanceof Error?t:Error(String(t)))})}})}disconnect(){this.logger.log(`disconnect`),this._intentionalClose=!0,this.reconnecting=!1,this.ws?.close(),this.ws=null,this._connected=!1,this.authed=!1,this.queue.length=0}activeSubs(){return Array.from(this.subs.entries()).map(([e,t])=>`${e}(${t})`).join(`, `)||`(none)`}subscribe(e){let t=this.subs.get(e)??0;return this.subs.set(e,t+1),t===0?(this.logger.log(`subscribe`,e,`active:`,this.activeSubs()),this.sendOrQueue(`subscribe ${e}`)):this.logger.log(`subscribe`,e,`(refs: ${t+1})`,`active:`,this.activeSubs()),{dispose:()=>this.doUnsubscribe(e)}}on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),{dispose:()=>{this.listeners.get(e)?.delete(t)}}}once(e,t){let n=this.on(e,e=>{n.dispose(),t(e)});return n}doUnsubscribe(e){let t=this.subs.get(e)??0;t<=1?(this.subs.delete(e),this.authed&&this.rawSend(`unsubscribe ${e}`),this.logger.log(`unsubscribe`,e,`active:`,this.activeSubs())):(this.subs.set(e,t-1),this.logger.log(`unsubscribe`,e,`(refs: ${t-1})`,`active:`,this.activeSubs()))}rawSend(e){this.ws?.send(e)}sendOrQueue(e){this.authed?this.rawSend(e):this.queue.push(e)}emit(e,t){this.listeners.get(e)?.forEach(n=>{try{n(t)}catch(t){this.logger.log(`listener error on channel`,e,t instanceof Error?t.stack??t.message:String(t))}})}async handleMessage(e){let t=await g(e);t.kind===`server`?this.emit(t.command.type,t.command):this.emit(t.message.channel,t.message.data)}async scheduleReconnect(){if(this.reconnecting||this._intentionalClose)return;if(!this.token){this.reconnecting=!1;return}this.reconnecting=!0;let e=0;for(;e<this.MAX_RETRIES&&this.reconnecting&&!this._intentionalClose;){let t=Math.min(2**e*100,this.MAX_DELAY_MS);if(this.logger.log(`reconnect attempt ${e+1}/${this.MAX_RETRIES} in ${t}ms`),await new Promise(e=>setTimeout(e,t)),!this.reconnecting||this._intentionalClose)return;try{if(await this.connect(this.token),this._intentionalClose){this.ws?.close(),this.ws=null;return}for(let e of this.subs.keys())this.rawSend(`subscribe ${e}`);return}catch{e++}}this.reconnecting=!1,e>=this.MAX_RETRIES&&!this._intentionalClose&&this.emit(`socket:error`,Error(`WebSocket reconnection failed after ${this.MAX_RETRIES} retries`))}},ne=class{memory=new Map;storage;namespace;constructor(e,t){this.namespace=e,this.storage=t}memKey(e){return`${this.namespace}/${e}`}get(e){let t=this.memory.get(this.memKey(e));if(t){if(t.expires!==void 0&&Date.now()>t.expires){this.memory.delete(this.memKey(e));return}return t.data}}set(e,t,n){this.memory.set(this.memKey(e),{data:t,expires:n===void 0?void 0:Date.now()+n})}delete(e){this.memory.delete(this.memKey(e))}async getPersistent(e){return this.storage?this.storage.get(`${this.namespace}/${e}`):null}async setPersistent(e,t){this.storage&&await this.storage.set(`${this.namespace}/${e}`,t)}async deletePersistent(e){this.storage&&await this.storage.delete(`${this.namespace}/${e}`)}clearMemory(){this.memory.clear()}async clearPersistent(){this.storage&&await this.storage.clear()}async clearAll(){this.clearMemory(),await this.clearPersistent()}},v=class extends EventTarget{logger;constructor(e){super(),this.logger=e??o.create()}emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}on(e,t){this.logger.log(`on "${e}"`);let n=e=>t(e.detail);return this.addEventListener(e,n),{dispose:()=>{this.logger.log(`off "${e}"`),this.removeEventListener(e,n)}}}},y=function(e){return e[e.Plain=0]=`Plain`,e[e.Wall=1]=`Wall`,e[e.Swamp=2]=`Swamp`,e}({}),b=class e{raw;constructor(e){this.raw=e}static fromEncodedString(t){let n=new Uint8Array(2500);for(let e=0;e<2500;e++){let r=parseInt(t[e],10);n[e]=r===3?1:r}return new e(n)}get(e,t){return this.raw[t*50+e]}};function x(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function S(e,t){let n={...e};for(let e in t){let r=t[e];r===null?delete n[e]:x(r)&&x(n[e])?n[e]=S(n[e],r):n[e]=r}return n}var re=class extends v{http;socket;cache;roomObjects=new Map;roomUsers=new Map;roomSubCount=new Map;lastFlagsString=new Map;parseFlagsString(e,t){if(!e||e.length===0)return[];let n=[],r=e.split(`|`);for(let e of r){let r=e.split(`~`);if(r.length!==5)continue;let[i,a,o,s,c]=r,l=parseInt(a,10),u=parseInt(o,10),d=parseInt(s,10),f=parseInt(c,10);isNaN(l)||isNaN(u)||isNaN(d)||isNaN(f)||n.push({_id:i,type:`flag`,room:t,name:i,x:d,y:f,color:l,secondaryColor:u})}return n}constructor(e,t,n,r){super(r),this.http=e,this.socket=t,this.cache=n}async terrain(e,t){let n=`terrain/${t}/${e}`,r=this.cache.get(n);if(r)return this.logger.log(`terrain`,e,t,`(memory cache hit)`),r;let i=await this.cache.getPersistent(n);if(i){this.logger.log(`terrain`,e,t,`(persistent cache hit)`);let r=new b(i);return this.cache.set(n,r),r}this.logger.log(`terrain`,e,t,`(fetching)`);let a=(await this.http.game.roomTerrain(e,t??void 0)).terrain[0];if(!a)throw Error(`No terrain data for room ${e} shard ${t}`);let o=b.fromEncodedString(a.terrain);return this.cache.set(n,o),await this.cache.setPersistent(n,o.raw),this.emit(`room:terrainavailable`,{room:e,shard:t,terrain:o}),o}async terrainBulk(e,t){let n=new Map,r=[];for(let i of e){let e=this.cache.get(`terrain/${t}/${i}`);e?n.set(i,e):r.push(i)}if(r.length===0)return n;let i=[];if(await Promise.all(r.map(async e=>{let r=`terrain/${t}/${e}`,a=await this.cache.getPersistent(r);if(a){let t=new b(a);this.cache.set(r,t),n.set(e,t)}else i.push(e)})),i.length===0)return n;this.logger.log(`terrainBulk`,`fetching ${i.length} rooms`,t);let a=await this.http.game.roomsTerrain(i,t??void 0);return await Promise.all(a.rooms.map(async e=>{let r=b.fromEncodedString(e.terrain),i=`terrain/${t}/${e.room}`;this.cache.set(i,r),await this.cache.setPersistent(i,r.raw),this.emit(`room:terrainavailable`,{room:e.room,shard:t,terrain:r}),n.set(e.room,r)})),n}objects(e,t){let n=this.roomObjects.get(`${e}/${t}`);return n?{...n}:null}async fetchObjects(e,t){let n=`${e}/${t}`,r=await this.http.game.roomObjects(e,t??void 0),i={};for(let e of r.objects)e&&typeof e==`object`&&`_id`in e&&(i[e._id]=e);this.roomObjects.set(n,i);let a=this.roomUsers.get(n);this.emit(`room:update`,{room:e,shard:t,gameTime:void 0,objects:i,diff:i,visual:``,users:a})}activeRooms(){return Array.from(this.roomSubCount.entries()).map(([e,t])=>`${e}(${t})`).join(`, `)||`(none)`}subscribe(e,t){let n=`${e}/${t}`,r=this.roomSubCount.get(n)??0;this.roomSubCount.set(n,r+1),this.logger.log(`subscribe`,e,t,`(refs: ${r+1})`,`active:`,this.activeRooms());let i=t?`room:${t}/${e}`:`room:${e}`,a=t?`err@room:${t}/${e}`:`err@room:${e}`,o=this.socket.subscribe(i),s=this.socket.on(a,n=>{let r=typeof n==`string`?n:JSON.stringify(n);this.logger.log(`room error`,e,t,r),this.emit(`room:error`,{room:e,shard:t,message:r})}),c=this.socket.on(i,r=>{let i=r,a={...this.roomObjects.get(n)??{}};if(i.objects==null)i.objects===null&&this.logger.log(`room update has null objects field`,e,t,`gameTime: ${i.gameTime}`);else for(let[e,t]of Object.entries(i.objects))t===null?delete a[e]:a[e]?a[e]=S(a[e],t):a[e]=t;let o={...i.objects??{}};if(`flags`in i){let t=i.flags??``;if(t!==(this.lastFlagsString.get(n)??``)){this.lastFlagsString.set(n,t);let r=this.parseFlagsString(t,e),i=new Map;for(let e of r)i.set(e.name,e);for(let t in a)a[t]?.type===`flag`&&!i.has(t)&&(delete a[t],o[t]=null,this.logger.log(`[flag:room] removed ${t} @ ${e}`));for(let[t,n]of i){let r=a[t];(!r||r.x!==n.x||r.y!==n.y||r.color!==n.color||r.secondaryColor!==n.secondaryColor)&&(a[t]=n,o[t]=n,this.logger.log(`[flag:room] ${r?`changed`:`added`} ${t} @ ${e} (${n.x},${n.y})`))}}}if(i.users){let e=this.roomUsers.get(n)??{};this.roomUsers.set(n,{...e,...i.users})}this.roomObjects.set(n,a);let s=this.roomUsers.get(n);this.emit(`room:update`,{room:e,shard:t,gameTime:i.gameTime,objects:a,diff:o,visual:i.visual??``,users:s})});return{dispose:()=>{o.dispose(),c.dispose(),s.dispose();let r=(this.roomSubCount.get(n)??1)-1;r<=0?(this.roomSubCount.delete(n),this.roomObjects.delete(n),this.roomUsers.delete(n),this.lastFlagsString.delete(n),this.logger.log(`unsubscribe`,e,t,`(last ref)`,`active:`,this.activeRooms())):(this.roomSubCount.set(n,r),this.logger.log(`unsubscribe`,e,t,`(refs: ${r})`,`active:`,this.activeRooms()))}}}},ie=class extends v{http;socket;cache;console=[];maxConsoleSize;_cpu=null;get cpu(){return this._cpu}_userInfo=null;get userInfo(){return this._userInfo}_userId=null;get userId(){return this._userId}_worldStatus=null;get worldStatusValue(){return this._worldStatus}_mePromise=null;constructor(e,t,n,r,i=100){super(r),this.http=e,this.socket=t,this.cache=n,this.maxConsoleSize=i}async me(){let e=this.cache.get(`user/me`);return e?(this._userId=e._id,this._userInfo=e,e):this._mePromise?this._mePromise:(this.logger.log(`fetch me`),this._mePromise=this.http.auth.me().then(e=>{let t=e;return this._userId=t._id,this._userInfo=t,this.cache.set(`user/me`,t,6e4),this.emit(`user:me`,t),t}).finally(()=>{this._mePromise=null}),this._mePromise)}async refreshMe(){return this.logger.log(`refresh me`),this.cache.delete(`user/me`),this.me()}async worldStatus(){let e=this.cache.get(`user/worldStatus`);if(e)return this._worldStatus=e,e;this.logger.log(`fetch world status`);let t=await this.http.user.worldStatus();return this._worldStatus=t.status,this.cache.set(`user/worldStatus`,t.status,6e4),this.emit(`user:worldStatus`,{status:t.status}),t.status}async refreshWorldStatus(){return this.logger.log(`refresh world status`),this.cache.delete(`user/worldStatus`),this.worldStatus()}subscribe(e){this.logger.log(`subscribe`,e);let t=null,n=null,r=!1;return(async()=>{try{let i=this._userId??(await this.me())._id;if(r)return;let a=`user:${i}/${e}`;t=this.socket.subscribe(a),n=this.socket.on(a,t=>{if(e===`cpu`)this._cpu=t,this.emit(`user:cpu`,this._cpu);else if(e===`console`){let e=t,n={log:e.messages?.log??[],results:e.messages?.results??[],error:e.messages?.error??[]};e.error&&n.error.push(e.error),this.console.push(n),this.console.length>this.maxConsoleSize&&this.console.splice(0,this.console.length-this.maxConsoleSize),this.emit(`user:console`,{messages:n})}else e===`code`&&this.emit(`user:code`,t)})}catch(e){r||this.dispatchEvent(new ErrorEvent(`error`,{error:e instanceof Error?e:Error(String(e))}))}})(),{dispose:()=>{this.logger.log(`unsubscribe`,e),r=!0,t?.dispose(),n?.dispose()}}}subscribeMemory(t,n){this.logger.log(`subscribe memory`,t);let r=null,i=null,a=!1;return(async()=>{try{let o=this._userId??(await this.me())._id;if(a)return;let s=`user:${o}/memory/${n?`${n}/`:``}${t}`;r=this.socket.subscribe(s),i=this.socket.on(s,r=>{if(typeof r==`string`&&r.startsWith(`gz:`)){(async()=>{try{let{decompressZlib:i}=await e(async()=>{let{decompressZlib:e}=await import(`./decompress-DhdK5fhG.js`);return{decompressZlib:e}},__vite__mapDeps([0,1])),a=await i(r);this.emit(`user:memory`,{path:t,shard:n??null,value:a})}catch(e){this.logger.log(`memory decompress failed`,e)}})();return}if(r===`[object Object]`){this.logger.log(`memory object placeholder`,t),this.emit(`user:memory`,{path:t,shard:n??null,value:{__screeps_object__:!0}});return}let i=r;if(r===`undefined`)i=void 0;else if(typeof r==`string`)try{i=JSON.parse(r)}catch{}this.logger.log(`memory value received`,t,i),this.emit(`user:memory`,{path:t,shard:n??null,value:i})})}catch(e){a||this.dispatchEvent(new ErrorEvent(`error`,{error:e instanceof Error?e:Error(String(e))}))}})(),{dispose:()=>{this.logger.log(`unsubscribe memory`,t),a=!0,r?.dispose(),i?.dispose()}}}subscribeMapVisual(e){this.logger.log(`subscribe mapVisual`,e);let t=null,n=null,r=!1;return(async()=>{try{let i=this._userId??(await this.me())._id;if(r)return;let a=e?`mapVisual:${i}/${e}`:`mapVisual:${i}`;t=this.socket.subscribe(a),n=this.socket.on(a,t=>{this.emit(`user:mapVisual`,{shard:e,data:typeof t==`string`?t:``})})}catch(e){r||this.dispatchEvent(new ErrorEvent(`error`,{error:e instanceof Error?e:Error(String(e))}))}})(),{dispose:()=>{this.logger.log(`unsubscribe mapVisual`,e),r=!0,t?.dispose(),n?.dispose()}}}subscribeUserStream(){this.logger.log(`subscribe user stream`);let e=null,t=null,n=!1;return(async()=>{try{let r=this._userId??(await this.me())._id;if(n)return;let i=`user:${r}`;e=this.socket.subscribe(i),t=this.socket.on(i,e=>{let t=e;if(t&&typeof t==`object`&&`flags`in t){let e=t.flags;if(e&&typeof e==`object`)for(let[t,n]of Object.entries(e)){let e=n;if(e&&typeof e==`object`){let n=e.room??`unknown`,r=e.x??`?`,i=e.y??`?`;this.logger.log(`[flag:user] ${t} @ ${n} (${r},${i})`)}}}this.emit(`user:stream`,t)})}catch(e){n||this.dispatchEvent(new ErrorEvent(`error`,{error:e instanceof Error?e:Error(String(e))}))}})(),{dispose:()=>{this.logger.log(`unsubscribe user stream`),n=!0,e?.dispose(),t?.dispose()}}}},ae=class extends v{http;cache;socketSubs=[];_version=null;get versionInfo(){return this._version}get isPrivateServer(){return this._version?(this._version.serverData?.shards?.length??0)===0:null}_shards=null;get shardList(){return this._shards}constructor(e,t,n,r){super(r),this.http=e,this.cache=n,this.socketSubs.push(t.on(`connected`,()=>{this.emit(`server:connected`,{})})),this.socketSubs.push(t.on(`disconnected`,e=>{let t=e;this.emit(`server:disconnected`,{willReconnect:t.willReconnect})})),this.socketSubs.push(t.on(`socket:error`,e=>{this.emit(`server:error`,{error:e instanceof Error?e:Error(String(e))})}))}destroy(){for(let e of this.socketSubs)e.dispose();this.socketSubs.length=0}async version(){let e=this.cache.get(`server/version`);if(e)return e;let t=await this.http.request(`GET`,`/api/version`);return this._version=t,this.cache.set(`server/version`,t,5*6e4),this.emit(`server:version`,t),t}async refreshVersion(){return this.cache.delete(`server/version`),this.version()}async shards(){let e=this.cache.get(`server/shards`);if(e)return e;let t=await this.http.request(`GET`,`/api/game/shards/info`);return this._shards=t.shards,this.cache.set(`server/shards`,t.shards,5*6e4),this.emit(`server:shards`,t.shards),t.shards}async refreshShards(){return this.cache.delete(`server/shards`),this.shards()}async worldInfo(e){let t=`server/world/${e??`default`}`,n=this.cache.get(t);if(n)return n;let r={};e&&(r.shard=e);let{width:i,height:a}=await this.http.request(`GET`,`/api/game/world-size`,r);this.logger.log(`worldInfo shard=${e??`none`} — raw size: ${i}x${a}`);let o=-i,s=-1,c=-a,l=-1;try{let e=(await this.http.request(`POST`,`/api/game/map-stats`,{rooms:[`W0N0`,`E0N0`,`W0S0`,`E0S0`],statName:`owner0`,...r})).stats??{},t=[`W0N0`,`E0N0`,`W0S0`,`E0S0`].filter(t=>t in e);this.logger.log(`worldInfo corner probe — found: [${t.length?t.join(`, `):`none`}]`);let n=`E0N0`in e||`E0S0`in e,u=`W0N0`in e||`W0S0`in e,d=`W0S0`in e||`E0S0`in e,f=`W0N0`in e||`E0N0`in e;n&&u?(o=-Math.ceil(i/2),s=Math.floor(i/2)-1):n&&(o=0,s=i-1),d&&f?(c=-Math.ceil(a/2),l=Math.floor(a/2)-1):d&&(c=0,l=a-1)}catch(e){this.logger.log(`worldInfo corner probe failed — keeping W/N defaults:`,e)}this.logger.log(`worldInfo computed bounds — x: [${o}, ${s}] y: [${c}, ${l}]`);let u={shard:e??null,width:i,height:a,minX:o,maxX:s,minY:c,maxY:l};return this.cache.set(t,u,10*6e4),u}invalidateWorldInfo(e){this.cache.delete(`server/world/${e??`default`}`)}},oe=class{memory=new Map;adapter;maxEntries;namespace;accessSeq=0;constructor(e){this.adapter=e.adapter,this.maxEntries=e.maxEntries,this.namespace=e.namespace}key(e,t){return`${t??`_`}/${e}`}adapterKey(e){return`map2/${e}`}tick(){return++this.accessSeq}serialize(e){let t={data:e.data,lastSeen:e.lastSeen,lastAccess:e.lastAccess};return new TextEncoder().encode(JSON.stringify(t))}deserialize(e){try{return JSON.parse(new TextDecoder().decode(e))}catch{return null}}getMemory(e,t){let n=this.memory.get(this.key(e,t));return n?(n.lastAccess=this.tick(),n.data):null}async get(e,t){let n=this.getMemory(e,t);if(n)return n;if(!this.adapter)return null;let r=this.key(e,t),i=await this.adapter.get(this.adapterKey(r));if(!i)return null;let a=this.deserialize(i);return a?(this.memory.set(r,{data:a.data,lastSeen:a.lastSeen,lastAccess:this.tick()}),a.data):null}async put(e,t,n){let r=this.key(e,t),i={data:n,lastSeen:Date.now(),lastAccess:this.tick()};this.memory.set(r,i),await this.pruneIfNeeded(),this.adapter&&await this.adapter.set(this.adapterKey(r),this.serialize(i))}async pruneIfNeeded(){if(this.memory.size<=this.maxEntries)return;let e=[...this.memory.entries()].sort((e,t)=>e[1].lastAccess-t[1].lastAccess).slice(0,this.memory.size-this.maxEntries);for(let[t]of e)this.memory.delete(t),this.adapter&&await this.adapter.delete(this.adapterKey(t))}};function C(e){let t=Object.keys(e).sort(),n={};for(let r of t){let t=e[r];n[r]=t?[...t].sort((e,t)=>e[0]-t[0]||e[1]-t[1]):null}return JSON.stringify(n)}var w=class extends v{socket;storage;maxSubscriptions;active=new Map;waitlist=[];keyStates=new Map;warnedAboutWaitlist=!1;constructor(e,t,n={},r){super(r),this.socket=e,this.storage=t,this.maxSubscriptions=n.maxSubscriptions??500,this.socket.on(`connected`,()=>this.onReconnect())}map2data(e,t){return this.storage.getMemory(e,t)}subscribeMap2(e,t){let n=`${e}/${t}`,r=this.active.get(n);if(r){r.refCount++,this.logger.log(`subscribeMap2`,e,t,`(active, refs: ${r.refCount})`);let i=this.getOrCreateKeyState(n,`active`);return this.emitWarmStart(e,t),this.makeSubscription(e,t,n,i)}let i=this.waitlist.find(e=>e.key===n);if(i){i.refCount++,this.logger.log(`subscribeMap2`,e,t,`(pending, refs: ${i.refCount})`);let r=this.getOrCreateKeyState(n,`pending`);return this.emitWarmStart(e,t),this.makeSubscription(e,t,n,r)}if(this.active.size<this.maxSubscriptions){this.activateKey(e,t,n,1),this.logger.log(`subscribeMap2`,e,t,`(new active)`);let r=this.getOrCreateKeyState(n,`active`);return this.emit(`room:map2state`,{room:e,shard:t,status:`active`}),this.emitWarmStart(e,t),this.makeSubscription(e,t,n,r)}this.waitlist.push({key:n,room:e,shard:t,refCount:1}),this.logger.log(`subscribeMap2`,e,t,`(new pending)`);let a=this.getOrCreateKeyState(n,`pending`);return this.emit(`room:map2state`,{room:e,shard:t,status:`pending`}),this.emitWarmStart(e,t),this.warnedAboutWaitlist||=(this.logger.log(`subscription limit (${this.maxSubscriptions}) reached — `,`some rooms are on a waitlist and will be promoted as slots free up.`),!0),this.makeSubscription(e,t,n,a)}activateKey(e,t,n,r){let i=t?`roomMap2:${t}/${e}`:`roomMap2:${e}`,a=this.socket.subscribe(i),o=this.storage.getMemory(e,t),s={room:e,shard:t,refCount:r,socketSub:a,listenerSub:void 0,lastHash:o?C(o):null};s.listenerSub=this.socket.on(i,n=>{let r=n,i=C(r);s.lastHash!==i&&(s.lastHash=i,this.storage.put(e,t,r),this.emit(`room:map2update`,{room:e,shard:t,data:r,source:`live`}))}),this.active.set(n,s)}promoteNext(){let e=this.waitlist.shift();if(!e)return;this.activateKey(e.room,e.shard,e.key,e.refCount),this.logger.log(`promoteNext`,e.room,e.shard,`(promoted from waitlist)`);let t=this.keyStates.get(e.key);t&&(t.status=`active`,t.statusHandlers.forEach(e=>e(`active`))),this.emit(`room:map2state`,{room:e.room,shard:e.shard,status:`active`})}getOrCreateKeyState(e,t){let n=this.keyStates.get(e);return n||(n={status:t,statusHandlers:new Set},this.keyStates.set(e,n)),n}makeSubscription(e,t,n,r){let i=!1;return{status:()=>r.status,cachedData:()=>this.storage.getMemory(e,t),onStatusChange:e=>(r.statusHandlers.add(e),{dispose:()=>{r.statusHandlers.delete(e)}}),dispose:()=>{i||(i=!0,this.disposeSubscription(e,t,n))}}}disposeSubscription(e,t,n){let r=this.waitlist.findIndex(e=>e.key===n);if(r>=0){let i=this.waitlist[r];i.refCount--,this.logger.log(`unsubscribeMap2`,e,t,`(pending, refs: ${i.refCount})`),i.refCount<=0&&(this.waitlist.splice(r,1),this.keyStates.delete(n),this.logger.log(`unsubscribeMap2`,e,t,`(removed from waitlist)`));return}let i=this.active.get(n);i&&(i.refCount--,this.logger.log(`unsubscribeMap2`,e,t,`(active, refs: ${i.refCount})`),i.refCount<=0&&(i.socketSub.dispose(),i.listenerSub.dispose(),this.active.delete(n),this.keyStates.delete(n),this.logger.log(`unsubscribeMap2`,e,t,`(deactivated, promoting next)`),this.promoteNext()))}emitWarmStart(e,t){let n=`${e}/${t}`,r=this.storage.getMemory(e,t);r?queueMicrotask(()=>{this.isSubscribed(n)&&this.emit(`room:map2update`,{room:e,shard:t,data:r,source:`cache`})}):this.storage.get(e,t).then(r=>{r&&this.isSubscribed(n)&&this.emit(`room:map2update`,{room:e,shard:t,data:r,source:`cache`})})}onReconnect(){this.logger.log(`onReconnect —`,this.active.size,`active,`,this.waitlist.length,`pending`);for(let e of this.active.values())e.lastHash=null,this.emit(`room:map2state`,{room:e.room,shard:e.shard,status:`active`});for(let e of this.waitlist)this.emit(`room:map2state`,{room:e.room,shard:e.shard,status:`pending`})}isSubscribed(e){return this.active.has(e)||this.waitlist.some(t=>t.key===e)}},T=class extends v{http;debounceMs;minIntervalMs;pending=new Map;timer=null;lastFlushTime=0;constructor(e,t=100,n=500,r){super(r),this.http=e,this.debounceMs=t,this.minIntervalMs=n}request(e,t,n){if(e.length===0)return;let r=JSON.stringify([t,n??`shard0`]),i=this.pending.get(r);i||(i={rooms:new Set,statName:t,shard:n??`shard0`},this.pending.set(r,i));for(let t of e)i.rooms.add(t);this.timer&&clearTimeout(this.timer);let a=Date.now()-this.lastFlushTime,o=Math.max(this.debounceMs,this.minIntervalMs-a);this.timer=setTimeout(()=>this.flush(),o)}async flush(){let e=new Map(this.pending);this.pending.clear(),this.timer=null,this.lastFlushTime=Date.now();for(let[,t]of e){let e=[...t.rooms];try{let n=await this.http.request(`POST`,`/api/game/map-stats`,{rooms:e,statName:t.statName,shard:t.shard}),r=n.users??{};for(let[e,i]of Object.entries(n.stats)){let n=this.buildData(i,r);this.emit(`mapStats:room`,{room:e,shard:t.shard===`shard0`?null:t.shard,stat:n})}for(let r of e)n.stats[r]||this.emit(`mapStats:room`,{room:r,shard:t.shard===`shard0`?null:t.shard,stat:{}})}catch(e){this.logger.log(`mapStats fetch failed:`,e)}}}buildData(e,t){let n,r;for(let t=0;t<3;t++){let i=e[`minerals${t}`];if(i){n=i.type,r=i.density;break}}let i=e.own?.user,a=e.sign?.user;return{own:e.own,mineral:n,density:r,username:i?t[i]?.username:void 0,safeMode:e.safeMode,badge:i?t[i]?.badge:void 0,status:e.status,sign:e.sign?{user:e.sign.user,text:e.sign.text,datetime:e.sign.datetime,username:a?t[a]?.username:void 0,badge:a?t[a]?.badge:void 0}:void 0}}},E=class extends v{_history=[];_index=-1;maxHistory;constructor(e=50,t){super(t),this.maxHistory=e}navigateTo(e,t){this._history=this._history.slice(0,this._index+1),this._history.push({room:e,shard:t}),this._history.length>this.maxHistory?this._history.shift():this._index++,this.emit(`navigation:change`,this.current())}back(){return this.canBack()?(this._index--,this.emit(`navigation:change`,this.current()),!0):!1}forward(){return this.canForward()?(this._index++,this.emit(`navigation:change`,this.current()),!0):!1}canBack(){return this._index>0}canForward(){return this._index<this._history.length-1}current(){return{room:this._history[this._index]?.room??null,shard:this._history[this._index]?.shard??null,index:this._index,history:[...this._history]}}},D=class{http;socket;stores;cache;logger;tokenRefreshIntervalMs;tokenSyncSubs=[];tokenRefreshTimer=null;refreshInFlight=!1;constructor(e){let t;try{t=new URL(e.url).hostname}catch{throw TypeError(`ScreepsClient: invalid url "${e.url}"`)}this.logger=o.create(e.debug),this.logger.log(`[screeps:client] init ${e.url}`),this.cache=new ne(t,e.storage??null),this.http=new h({url:e.url,auth:e.auth,logger:this.logger.child(`http`),serverPassword:e.serverPassword,decorationsMock:e.decorationsMock}),this.socket=new _({url:e.url,WebSocket:e.WebSocket,logger:this.logger.child(`socket`)});let n=new oe({adapter:e.storage??null,namespace:t,maxEntries:e.map2?.maxCacheEntries??1e4});this.stores={room:new re(this.http,this.socket,this.cache,this.logger.child(`room`)),user:new ie(this.http,this.socket,this.cache,this.logger.child(`user`)),server:new ae(this.http,this.socket,this.cache,this.logger.child(`server`)),map:new w(this.socket,n,{maxSubscriptions:e.map2?.maxSubscriptions??500},this.logger.child(`map`)),mapStats:new T(this.http,100,500,this.logger.child(`mapStats`)),navigation:new E(50,this.logger.child(`navigation`))},this.tokenRefreshIntervalMs=e.tokenRefresh===!1?null:e.tokenRefresh?.intervalMs??3e4,this.wireTokenSync(e.auth.supportsTokenRefresh??!0)}wireTokenSync(e){e&&(this.tokenSyncSubs.push(this.http.on(`http:tokenRefresh`,({token:e})=>{this.socket.setToken(e)})),this.tokenSyncSubs.push(this.socket.on(`socket:tokenRefresh`,e=>{let t=e;this.http.setToken(t.token)})))}get isConnected(){return this.socket.isConnected}async connect(){this.logger.log(`[screeps:client] connect`),await this.http.authenticate(),await this.socket.connect(this.http.token),await Promise.all([this.stores.user.me(),this.stores.user.worldStatus(),this.stores.server.version()]),this.startTokenRefresh()}disconnect(){this.logger.log(`[screeps:client] disconnect`),this.stopTokenRefresh(),this.socket.disconnect()}startTokenRefresh(){this.tokenRefreshIntervalMs!==null&&this.tokenRefreshTimer===null&&(this.tokenRefreshTimer=setInterval(()=>{this.refreshTokenNow()},this.tokenRefreshIntervalMs))}stopTokenRefresh(){this.tokenRefreshTimer!==null&&(clearInterval(this.tokenRefreshTimer),this.tokenRefreshTimer=null)}async refreshTokenNow(){if(!this.refreshInFlight){this.refreshInFlight=!0;try{this.logger.log(`[screeps:client] world status refresh`),await this.stores.user.refreshWorldStatus()}catch(e){this.logger.log(`[screeps:client] world status refresh failed`,e)}finally{this.refreshInFlight=!1}}}async clearCache(){this.logger.log(`[screeps:client] clearCache`),await this.cache.clearAll()}},O=class{supportsTokenRefresh=!1;token;constructor(e){this.token=e.token}async authenticate(e){return this.token}},k=class{email;password;constructor(e){this.email=e.email,this.password=e.password}async authenticate(e){return(await e.auth.signin(this.email,this.password)).token}},A=class{async authenticate(e){return`guest`}},j=class{ticket;useNativeAuth;constructor(e){this.ticket=e.ticket,this.useNativeAuth=e.useNativeAuth}async authenticate(e){return(await e.auth.steamTicket(this.ticket,this.useNativeAuth)).token}},M=1,N=`data`,P=class{namespace;db=null;openPromise=null;constructor(e){this.namespace=e}get dbName(){return`screeps:${this.namespace}`}open(){return this.db?Promise.resolve(this.db):(this.openPromise||=new Promise((e,t)=>{let n=indexedDB.open(this.dbName,M);n.onupgradeneeded=()=>{n.result.createObjectStore(N)},n.onsuccess=()=>{this.db=n.result,this.openPromise=null,e(n.result)},n.onerror=()=>t(n.error),n.onblocked=()=>t(Error(`IndexedDB open blocked: ${this.dbName}`))}),this.openPromise)}async get(e){let t=await this.open();return new Promise((n,r)=>{let i=t.transaction(N,`readonly`).objectStore(N).get(e);i.onsuccess=()=>n(i.result??null),i.onerror=()=>r(i.error)})}async set(e,t){let n=await this.open();return new Promise((r,i)=>{let a=n.transaction(N,`readwrite`).objectStore(N).put(t,e);a.onsuccess=()=>r(),a.onerror=()=>i(a.error)})}async delete(e){let t=await this.open();return new Promise((n,r)=>{let i=t.transaction(N,`readwrite`).objectStore(N).delete(e);i.onsuccess=()=>n(),i.onerror=()=>r(i.error)})}async clear(){let e=await this.open();return new Promise((t,n)=>{let r=e.transaction(N,`readwrite`).objectStore(N).clear();r.onsuccess=()=>t(),r.onerror=()=>n(r.error)})}},F=class{async get(e){return null}async set(e,t){}async delete(e){}async clear(){}},I=class{subs=[];add(e){this.subs.push(e)}dispose(){for(let e of this.subs)e.dispose();this.subs.length=0}},L=5*6e4;function R(e,t){try{return`screeps:${e}:${new URL(t).hostname}`}catch{return`screeps:${e}:${t}`}}function z(e){if(typeof sessionStorage>`u`)return null;try{let t=sessionStorage.getItem(e);if(!t)return null;let n=JSON.parse(t);return Date.now()>n.expires?(sessionStorage.removeItem(e),null):n.data}catch{return null}}function B(e,t){if(!(typeof sessionStorage>`u`))try{sessionStorage.setItem(e,JSON.stringify({data:t,expires:Date.now()+L}))}catch{}}function V(e){return e.endsWith(`/`)?e:`${e}/`}async function H(e){let t=R(`version`,e),n=z(t);if(n)return n;let r=await a()(`${V(e)}api/version`);if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.json();return B(t,i),i}async function U(e){let t=R(`authmod`,e),n=z(t);if(n)return n;let r=await a()(`${V(e)}api/authmod`);if(!r.ok)return null;let i=await r.json();return i.ok?(B(t,i),i):null}async function W(e,t){let n=new URLSearchParams({username:t}),r=await a()(`${V(e)}api/register/check-username?${n}`);if(!r.ok)throw Error(`HTTP ${r.status}`);return r.json()}async function G(e,t){let n=new URLSearchParams({email:t}),r=await a()(`${V(e)}api/register/check-email?${n}`);if(!r.ok)throw Error(`HTTP ${r.status}`);return r.json()}async function K(e,t,n,r){let i=await a()(`${V(e)}api/register/submit`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({username:t,email:n,password:r})});if(!i.ok)throw Error(`HTTP ${i.status}`);return i.json()}function q(e,t){return e.serverData.features.find(e=>e.name===t)}function se(e){return q(e,`screepsmod-auth`)}var ce={ok:1,decorations:[{_id:`5fd719f496a97dbdd2f57bea`,user:`58356f6fc8012784246abb7e`,active:{strokeWidth:`30`,foregroundColor:`#6A88FF`,foregroundAlpha:1,backgroundColor:`#5261A0`,backgroundBrightness:`1`,strokeColor:`#465EC4`,strokeBrightness:`1`,strokeLighting:`1`,foregroundBrightness:`1`,world:!0,tileScale:1,shard:`shard1`,room:`E2S49`},decoration:{_id:`5eea71d952fdab816c74e50c`,graphics:[],description:`звездочки`,rarityMultiplier:1,type:`wallLandscape`,foregroundUrl:`https://s3.amazonaws.com/static.screeps.com/decorations/0e53bc662a2688275b9c6766cf946031b19bf0b.png`,theme:`5e908ece62339b0045ac2d0e`,rarity:4,name:`W-00031:WI:X`,group:`5edf121e1f95b4047880e2ef`,steamItemDefId:4415,enabled:!0,groupDescription:`Controllable brightness.`,preview:{original:`https://s3.amazonaws.com/static.screeps.com/decorations/6c5533fd1f83ecadb8cf105fdda95fa4687114b.png`,"128x128":`https://s3.amazonaws.com/static.screeps.com/decorations/919410fbd3c74c697d7396ba0636b2d33ca3fa5.png`,"256x256":`https://s3.amazonaws.com/static.screeps.com/decorations/16f3453e69387abfe110050532d9e7c67e8fc41.png`}}},{_id:`60086a96a6ad8c744554e05c`,user:`58356f6fc8012784246abb7e`,active:{floorBackgroundColor:`#F67BFF`,floorBackgroundBrightness:.98,floorForegroundColor:`#F67BFF`,floorForegroundAlpha:.87,swampColor:`#4073A3`,swampStrokeColor:`#CC7DD2`,swampStrokeWidth:30,roadsColor:`#E9A7EE`,roadsBrightness:.41,tileScale:1,floorForegroundBrightness:.42,world:!0,shard:`shard1`,room:`E2S49`},decoration:{_id:`5eea668452fdab5ea674e1ca`,graphics:[],description:`калейдоскоп`,rarityMultiplier:1,type:`floorLandscape`,floorForegroundUrl:`https://s3.amazonaws.com/static.screeps.com/decorations/7e3d680d2f48b1ff244a95e564275536fe4ed61.png`,theme:`5e908ed162339b0045ac2d0f`,rarity:4,name:`F-00065:AL:X`,group:`5ee9016d961c4e27734cf301`,steamItemDefId:3606,enabled:!0,groupDescription:`Adjustable brightness.`,preview:{original:`https://s3.amazonaws.com/static.screeps.com/decorations/da7256631a2a2c8568221ad1f0bef0bb5525a7.png`,"128x128":`https://s3.amazonaws.com/static.screeps.com/decorations/3c0f0da6b41e413bdc4f66a01eed62b5b252c29.png`,"256x256":`https://s3.amazonaws.com/static.screeps.com/decorations/80c9978b58403e13b4a28f47ef1422e895c04fe.png`}}},{_id:`5fbab429b2f60e0fae891bcb`,user:`58356f6fc8012784246abb7e`,active:{lighting:!0,position:`below`,width:256,height:256,syncRotate:!0,animation:`blink`,brightness:`1`,nameFilter:`ecarry*`,exclude:!1,firstColor:`#FFFFFF`,firstAlpha:1,secondColor:`#FFFFFF`,secondAlpha:`1`,flip:!1,color:`#1fe265`,alpha:.79},decoration:{_id:`5f2ab6c1ad10bf3222df1b4f`,graphics:[{url:`https://s3.amazonaws.com/static.screeps.com/decorations/a23d96123d27bf163babe0a29a54de003aea568.svg`,color:`color`,alpha:`alpha`,visible:``}],description:`38.svg`,rarityMultiplier:1,type:`creep`,theme:`5ee3db64961c4e98dc4cf121`,rarity:5,name:`C-00071:CC:X`,group:`5eec306d0042094b2845f7d6`,steamItemDefId:57779,enabled:!0,groupDescription:`Choose your own color.`,preview:{original:`https://s3.amazonaws.com/static.screeps.com/decorations/3a7853ca055d7ae5738852f6f73f27389594e2e.png`,"128x128":`https://s3.amazonaws.com/static.screeps.com/decorations/8557cffe9216525092427f90b9847ef5bdcd6c8.png`,"256x256":`https://s3.amazonaws.com/static.screeps.com/decorations/e198e4f909cdb99f11a8cc7bc9f7e7a733faeca.png`}}}]},J={1:{calc(e=0){let t=0,n=0;e>0&&(t=e*30/100),e<0&&(n=-e*30/100),this.path1=`M 50 ${100-t} L ${n} 50 H ${100-n} Z`,this.path2=`M ${n} 50 H ${100-n} L 50 ${t} Z`}},2:{calc(e=0){let t=0,n=0;e>0&&(t=e*30/100),e<0&&(n=-e*30/100),this.path1=`M ${t} ${n} L 50 50 L ${100-t} ${n} V -1 H -1 Z`,this.path2=`M ${t} ${100-n} L 50 50 L ${100-t} ${100-n} V 101 H -1 Z`}},3:{calc(e=0){let t=Math.PI/4+Math.PI/4*(e+100)/200,n=-Math.PI/2,r=Math.PI/2+Math.PI/3,i=Math.PI/2-Math.PI/3;this.path1=`M 50 50 L ${50+100*Math.cos(n-t/2)} ${50+100*Math.sin(n-t/2)} L ${50+100*Math.cos(n+t/2)} ${50+100*Math.sin(n+t/2)} Z`,this.path2=`M 50 50 L ${50+100*Math.cos(r-t/2)} ${50+100*Math.sin(r-t/2)} L ${50+100*Math.cos(r+t/2)} ${50+100*Math.sin(r+t/2)} Z M 50 50 L ${50+100*Math.cos(i-t/2)} ${50+100*Math.sin(i-t/2)} L ${50+100*Math.cos(i+t/2)} ${50+100*Math.sin(i+t/2)}`},flip:`rotate180`},4:{calc(e=0){e+=100;let t=50-e*30/200,n=50+e*30/200;this.path1=`M 0 ${n} H 100 V 100 H 0 Z`,this.path2=e>0?`M 0 ${t} H 100 V ${n} H 0 Z`:``},flip:`rotate90`},5:{calc(e=0){e+=100;let t=50-e*10/200-10,n=50+e*10/200+10;this.path1=`M ${t} 0 H ${n} V 100 H ${t} Z`,this.path2=`M 0 ${t} H 100 V ${n} H 0 Z`},flip:`rotate45`},6:{calc(e=0){let t=5+(e+100)*8/200;this.path1=`M ${50-t} 0 H ${50+t} V 100 H ${50-t}`,this.path2=`M ${20-t} 0 H ${20+t} V 100 H ${20-t} Z M ${80-t} 0 H ${80+t} V 100 H ${80-t} Z`},flip:`rotate90`},7:{calc(e=0){let t=20+e*10/100;this.path1=`M 0 50 Q 25 30 50 50 T 100 50 V 100 H 0 Z`,this.path2=`M 0 ${50-t} Q 25 ${30-t} 50 ${50-t} T 100 ${50-t} V ${50+t} Q 75 ${70+t} 50 ${50+t} T 0 ${50+t} Z`},flip:`rotate90`},8:{calc(e=0){let t=e*20/100;this.path1=`M 0 50 H 100 V 100 H 0 Z`,this.path2=`M 0 50 Q 50 ${t} 100 50 Q 50 ${100-t} 0 50 Z`},flip:`rotate90`},9:{calc(e=0){let t=0,n=50;e>0&&(t+=e/100*20),e<0&&(n+=e/100*30),this.path1=`M 50 ${t} L 100 ${t+70} V 101 H 0 V ${t+70} Z`,this.path2=`M 50 ${t+n} L 100 ${t+n+70} V 101 H 0 V ${t+n+70} Z`},flip:`rotate180`},10:{calc(e=0){let t=30,n=7;e>0&&(t+=e*50/100),e<0&&(n-=e*20/100),this.path1=`M ${50+n+t} ${50-t} A ${t} ${t} 0 0 0 ${50+n+t} ${50+t} H 101 V ${50-t} Z`,this.path2=`M ${50-n-t} ${50-t} A ${t} ${t} 0 0 1 ${50-n-t} ${50+t} H -1 V ${50-t} Z`},flip:`rotate90`},11:{calc(e=0){let t=30,n=30,r=50-50*Math.cos(Math.PI/4),i=50-50*Math.sin(Math.PI/4);e>0&&(t+=e*25/100,n+=e*25/100),e<0&&(n-=e*50/100),this.path1=`M ${r} ${i} Q ${t} 50 ${r} ${100-i} H 0 V ${i} Z M ${100-r} ${i} Q ${100-t} 50 ${100-r} ${100-i} H 100 V ${i} Z`,this.path2=`M ${r} ${i} Q 50 ${n} ${100-r} ${i} V 0 H ${r} Z M ${r} ${100-i} Q 50 ${100-n} ${100-r} ${100-i} V 100 H ${r} Z`},flip:`rotate90`},12:{calc(e=0){let t=30,n=35;e>0&&(t+=e*30/100),e<0&&(n+=e*15/100),this.path1=`M 0 ${t} H 100 V 100 H 0 Z`,this.path2=`M 0 ${t} H ${n} V 100 H 0 Z M 100 ${t} H ${100-n} V 100 H 100 Z`},flip:`rotate180`},13:{calc(e=0){let t=30,n=0;e>0&&(t+=e*50/100),e<0&&(n-=e*20/100),this.path1=`M 0 0 H 50 V 100 H 0 Z`,this.path2=`M ${50-t} ${50-n-t} A ${t} ${t} 0 0 0 ${50+t} ${50-t-n} V 0 H ${50-t} Z`},flip:`rotate180`},14:{calc(e=0){let t=Math.PI/4;t+=e*Math.PI/4/100,this.path1=`M 50 0 Q 50 50 ${50+50*Math.cos(t)} ${50+50*Math.sin(t)} H 100 V 0 H 50 Z`,this.path2=`M 50 0 Q 50 50 ${50-50*Math.cos(t)} ${50+50*Math.sin(t)} H 0 V 0 H 50 Z`},flip:`rotate180`},15:{calc(e=0){let t=13+e*6/100;this.path1=`M ${-30-t} 110 A ${80+t} ${80+t} 0 0 1 ${130+t} 110 H ${130-t} A ${80-t} ${80-t} 0 1 0 ${-30+t} 110`,this.path2=`M ${5-t} 110 A ${45+t} ${45+t} 0 0 1 ${95+t} 110 H ${95-t} A ${45-t} ${45-t} 0 1 0 ${5+t} 110`},flip:`rotate180`},16:{calc(e=0){let t=30*Math.PI/180,n=25;e>0&&(t+=30*Math.PI/180*e/100),e<0&&(n+=e*25/100),this.path1=``;for(let e=0;e<3;e++){let r=e*Math.PI*2/3+t/2-Math.PI/2,i=e*Math.PI*2/3-t/2-Math.PI/2;this.path1+=`M ${50+100*Math.cos(r)} ${50+100*Math.sin(r)} L ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} L ${50+n*Math.cos(i)} ${50+n*Math.sin(i)} A ${n} ${n} 0 0 1 ${50+n*Math.cos(r)} ${50+n*Math.sin(r)} Z`}this.path2=``;for(let e=0;e<3;e++){let r=e*Math.PI*2/3+t/2+Math.PI/2,i=e*Math.PI*2/3-t/2+Math.PI/2;this.path2+=`M ${50+100*Math.cos(r)} ${50+100*Math.sin(r)} L ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} L ${50+n*Math.cos(i)} ${50+n*Math.sin(i)} A ${n} ${n} 0 0 1 ${50+n*Math.cos(r)} ${50+n*Math.sin(r)} Z`}}},17:{calc(e=0){let t=35,n=45;e>0&&(t+=e*20/100),e<0&&(n-=e*30/100),this.path1=`M 50 45 L ${50-t} ${n+45} H ${50+t} Z`,this.path2=`M 50 0 L ${50-t} ${n} H ${50+t} Z`}},18:{calc(e=0){let t=90*Math.PI/180,n=10;e>0&&(t-=60/180*Math.PI*e/100),e<0&&(n-=e*15/100),this.path1=``,this.path2=``;for(let e=0;e<3;e++){let r=Math.PI*2/3*e+t/2-Math.PI/2,i=Math.PI*2/3*e-t/2-Math.PI/2,a=`M ${50+100*Math.cos(r)} ${50+100*Math.sin(r)} L ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} L ${50+n*Math.cos((r+i)/2)} ${50+n*Math.sin((r+i)/2)} Z`;e?this.path2+=a:this.path1+=a}},flip:`rotate180`},19:{calc(e=0){let t=20,n=60;n+=e*20/100,t+=e*20/100,this.path1=`M 50 -10 L ${50-n} 100 H ${50+n} Z`,this.path2=``,t>0&&(this.path2=`M 50 0 L ${50-t} 100 H ${50+t} Z`)},flip:`rotate180`},20:{calc(e=0){let t=10,n=20;e>0&&(t+=e*20/100),e<0&&(n+=e*40/100),this.path1=`M 0 ${50-n} H ${50-t} V 100 H 0 Z`,this.path2=`M ${50+t} 0 V ${50+n} H 100 V 0 Z`},flip:`rotate90`},21:{calc(e=0){let t=40,n=50;e>0&&(t-=e*20/100),e<0&&(n+=e*20/100),this.path1=`M 50 ${n} Q ${50+t} 0 50 0 T 50 ${n} Z M 50 ${100-n} Q ${50+t} 100 50 100 T 50 ${100-n} Z`,this.path2=`M ${n} 50 Q 0 ${50+t} 0 50 T ${n} 50 Z M ${100-n} 50 Q 100 ${50+t} 100 50 T ${100-n} 50 Z`},flip:`rotate45`},22:{calc(e=0){let t=20;t+=e*10/100,this.path1=`M ${50-t} ${50-t} H ${50+t} V ${50+t} H ${50-t} Z`,this.path2=``;for(let e=-4;e<4;e++)for(let n=-4;n<4;n++){let r=(e+n)%2;this.path2+=`M ${50-t-t*2*e} ${50-t-t*2*(n+r)} h ${-t*2} v ${t*2} h ${t*2} Z`}},flip:`rotate45`},23:{calc(e=0){let t=17,n=25;e>0&&(t+=e*35/100),e<0&&(n-=e*23/100),this.path1=``;for(let e=-4;e<=4;e++)this.path1+=`M ${50-t*e*2} ${50-n} l ${-t} ${-n} l ${-t} ${n} l ${t} ${n} Z`;this.path2=``;for(let e=-4;e<=4;e++)this.path2+=`M ${50-t*e*2} ${50+n} l ${-t} ${-n} l ${-t} ${n} l ${t} ${n} Z`},flip:`rotate90`},24:{calc(e=0){let t=50,n=45;e>0&&(t+=e*60/100),e<0&&(n+=e*30/100),this.path1=`M 0 ${n} L 50 70 L 100 ${n} V 100 H 0 Z`,this.path2=`M 50 0 L ${50+t} 100 H 100 V ${n} L 50 70 L 0 ${n} V 100 H ${50-t} Z`},flip:`rotate180`}};function Y(e){let t=Math.round(e).toString(16);return t.length<2?`0`+t:t}function X(e,t,n){let r=(1-Math.abs(2*n-1))*t,i=e/60,a=r*(1-Math.abs(i%2-1)),o=0,s=0,c=0;!Number.isNaN(e)&&e!=null&&(i>=0&&i<1?(o=r,s=a,c=0):i>=1&&i<2?(o=a,s=r,c=0):i>=2&&i<3?(o=0,s=r,c=a):i>=3&&i<4?(o=0,s=a,c=r):i>=4&&i<5?(o=a,s=0,c=r):i>=5&&i<6&&(o=r,s=0,c=a));let l=n-r/2,u=(o+l)*255,d=(s+l)*255,f=(c+l)*255;return`#`+Y(u)+Y(d)+Y(f)}function Z(){let e=[],t=0;e.push({index:t++,rgb:X(0,0,.8)});for(let n=0;n<19;n++)e.push({index:t++,rgb:X(n*360/19,.6,.8)});e.push({index:t++,rgb:X(0,0,.5)});for(let n=0;n<19;n++)e.push({index:t++,rgb:X(n*360/19,.7,.5)});e.push({index:t++,rgb:X(0,0,.3)});for(let n=0;n<19;n++)e.push({index:t++,rgb:X(n*360/19,.4,.3)});e.push({index:t++,rgb:X(0,0,.1)});for(let n=0;n<19;n++)e.push({index:t++,rgb:X(n*360/19,.5,.1)});return e}var Q=Z();function $(e){if(typeof e==`string`)return e;if(typeof e==`number`){let t=Q[e];return t?t.rgb:`#000000`}return`#000000`}function le(e){let t=$(e.color1),n=$(e.color2),r=$(e.color3),i=e.param??0;if(typeof e.type==`number`){let t=J[e.type];t&&t.calc(i)}let a=0;if(e.flip&&typeof e.type==`number`){let t=J[e.type];t?.flip===`rotate180`&&(a=180),t?.flip===`rotate90`&&(a=90),t?.flip===`rotate45`&&(a=45)}let o,s;if(typeof e.type==`number`){let t=J[e.type];o=t?.path1??``,s=t?.path2??``}else o=e.type.path1,s=e.type.path2;let c=`<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 100 100" shape-rendering="geometricPrecision">`;return c+=`<defs><clipPath id="clip"><circle cx="50" cy="50" r="50"/></clipPath></defs>`,c+=`<g transform="rotate(${a} 50 50)">`,c+=`<rect x="0" y="0" width="100" height="100" fill="${t}" clip-path="url(#clip)"/>`,o&&(c+=`<path d="${o}" fill="${n}" clip-path="url(#clip)"/>`),s&&(c+=`<path d="${s}" fill="${r}" clip-path="url(#clip)"/>`),c+=`<circle cx="50" cy="50" r="47.5" fill="transparent" stroke="#000" stroke-width="5"/>`,c+=`</g></svg>`,c}export{i as S,O as _,W as a,y as b,se as c,I as d,F as f,k as g,A as h,G as i,q as l,j as m,Q as n,U as o,P as p,ce as r,H as s,le as t,K as u,D as v,o as x,b as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e,_ as t,a as n,b as r,c as i,d as a,f as o,g as s,h as c,i as l,l as u,m as d,n as f,o as p,p as m,r as h,s as g,t as _,u as v,v as y,x as b,y as x}from"./src-
|
|
1
|
+
import{S as e,_ as t,a as n,b as r,c as i,d as a,f as o,g as s,h as c,i as l,l as u,m as d,n as f,o as p,p as m,r as h,s as g,t as _,u as v,v as y,x as b,y as x}from"./src-DGV5lg9g.js";export{f as BadgeColors,c as GuestAuth,m as IndexedDBStorage,b as Logger,o as NullStorage,s as PasswordAuth,h as ROOM_DECORATIONS_MOCK,x as RoomTerrain,y as ScreepsClient,d as SteamTicketAuth,a as SubscriptionGroup,r as TerrainType,t as TokenAuth,_ as badgeToSvg,l as checkEmail,n as checkUsername,p as fetchAuthModInfo,g as fetchServerVersion,i as getScreepsmodAuth,u as getServerFeature,v as registerUser,e as setFetch};
|
package/dist/embedded/index.html
CHANGED
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
to { opacity: 1; transform: translate(-50%, -50%); }
|
|
27
27
|
}
|
|
28
28
|
</style>
|
|
29
|
-
<script type="module" crossorigin src="/client/_client/index-
|
|
29
|
+
<script type="module" crossorigin src="/client/_client/index-DxoJa-to.js"></script>
|
|
30
30
|
<link rel="modulepreload" crossorigin href="/client/_client/rolldown-runtime-Bh1tDfsg.js">
|
|
31
31
|
<link rel="modulepreload" crossorigin href="/client/_client/vendor-pixi-DHGNQ8y2.js">
|
|
32
32
|
<link rel="modulepreload" crossorigin href="/client/_client/vendor-codemirror-B6f_i0wP.js">
|
|
33
33
|
<link rel="modulepreload" crossorigin href="/client/_client/decompress-CWkNrR0q.js">
|
|
34
|
-
<link rel="modulepreload" crossorigin href="/client/_client/src-
|
|
35
|
-
<link rel="modulepreload" crossorigin href="/client/_client/clientStore-
|
|
36
|
-
<link rel="modulepreload" crossorigin href="/client/_client/MapRenderer-
|
|
34
|
+
<link rel="modulepreload" crossorigin href="/client/_client/src-DGV5lg9g.js">
|
|
35
|
+
<link rel="modulepreload" crossorigin href="/client/_client/clientStore-Bsp3grc8.js">
|
|
36
|
+
<link rel="modulepreload" crossorigin href="/client/_client/MapRenderer-BvfpJvGb.js">
|
|
37
37
|
</head>
|
|
38
38
|
<body>
|
|
39
39
|
<div id="root"></div>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e,_ as t,a as n,d as r,g as i,i as a,n as o,o as s,p as c,r as l,t as u,y as d}from"./vendor-codemirror-B6f_i0wP.js";import{$ as f,G as p,K as m,M as h,X as g,et as _,n as v,z as y}from"./clientStore-
|
|
1
|
+
import{S as e,_ as t,a as n,d as r,g as i,i as a,n as o,o as s,p as c,r as l,t as u,y as d}from"./vendor-codemirror-B6f_i0wP.js";import{$ as f,G as p,K as m,M as h,X as g,et as _,n as v,z as y}from"./clientStore-Dto6IEkm.js";var b=f(`<span style=font-size:11px;color:#e3b341>Unsaved changes`),x=f(`<div style="padding:12px 10px;font-size:12px;color:#484f58;font-style:italic">Loading…`),S=f(`<div style=flex:1;display:flex;align-items:center;justify-content:center;color:#484f58;font-size:13px;font-style:italic>`),C=f(`<div style=position:absolute;inset:0px;background:#0d1117;z-index:100;display:flex;flex-direction:column;overflow:hidden><div style="display:flex;align-items:center;gap:12px;padding:10px 16px;border-bottom:1px solid #30363d;flex-shrink:0"><span style=font-size:15px;font-weight:600;color:#c9d1d9>Code</span><select style="background:#010409;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:4px 8px;font-size:12px;cursor:pointer"></select><div style=flex:1></div><button style="padding:5px 14px;border-radius:4px;border:1px solid #238636;font-size:12px;font-weight:600"></button><button style="background:transparent;border:none;color:#8b949e;font-size:18px;cursor:pointer;line-height:1;padding:2px 6px">✕</button></div><div style=flex:1;display:flex;overflow:hidden><div style="width:180px;flex-shrink:0;border-right:1px solid #21262d;display:flex;flex-direction:column;overflow:hidden"><div style="padding:6px 10px;font-size:10px;font-weight:700;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;border-bottom:1px solid #21262d;flex-shrink:0">Modules</div><div style=flex:1;overflow:auto></div></div><div style=flex:1;display:flex;flex-direction:column;overflow:hidden><div style="padding:5px 14px;font-size:12px;color:#8b949e;border-bottom:1px solid #21262d;flex-shrink:0;font-family:monospace;background:#0d1117">.js</div><div style=flex:1;overflow:hidden;flex-direction:column>`),w=f(`<option>`),T=f(`<div style="padding:7px 12px;font-size:12px;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis">`),{error:E}=h(`code`),D=s.theme({"&":{height:`100%`},".cm-scroller":{"font-family":`'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace`,"font-size":`13px`,"line-height":`1.6`,overflow:`auto`},".cm-gutters":{background:`#0d1117`,"border-right":`1px solid #21262d`},".cm-lineNumbers .cm-gutterElement":{color:`#484f58`,"min-width":`3em`},".cm-activeLineGutter":{background:`#161b22`},".cm-activeLine":{background:`#161b22`}}),O=[l,o(),u,D];function k(o){let[s,l]=e([]),[u,f]=e(``),[p,h]=e({}),[D,k]=e(``),[A,j]=e(!1),[M,N]=e(!1),[P,F]=e(!1),I=()=>Object.keys(p()),{editorView:L,ref:R,createExtension:z}=n({onValueChange:e=>{let t=D();!t||p()[t]===e||(h(n=>({...n,[t]:e})),F(!0))}});a(L,()=>p()[D()]??``),z(O),t(()=>{let e=v();e&&e.http.user.branches().then(e=>{l(e.list);let t=e.list.find(e=>e.activeWorld)??e.list[0];t&&f(t.branch)}).catch(e=>{E(`branches failed:`,e),y(`Failed to load branches`,`error`)})}),t(()=>{let e=u(),t=v();!e||!t||(j(!0),h({}),k(``),F(!1),t.http.user.code.get(e).then(e=>{let t=e.modules??{};h(t),k(Object.keys(t)[0]??``)}).catch(e=>{E(`get failed:`,e),y(`Failed to load code`,`error`)}).finally(()=>j(!1)))});let B=()=>{let e=v(),t=u();!e||!t||(N(!0),e.http.user.code.set(t,p()).then(()=>{y(`Code saved`,`success`),F(!1)}).catch(e=>{E(`set failed:`,e),y(`Failed to save code`,`error`)}).finally(()=>N(!1)))};return(()=>{var e=C(),t=e.firstChild,n=t.firstChild.nextSibling,a=n.nextSibling.nextSibling,l=a.nextSibling,p=t.nextSibling.firstChild,h=p.firstChild.nextSibling,v=p.nextSibling,y=v.firstChild,E=y.firstChild,O=y.nextSibling;return n.addEventListener(`change`,e=>f(e.currentTarget.value)),m(n,i(r,{get each(){return s()},children:e=>(()=>{var t=w();return m(t,()=>e.branch,null),m(t,()=>e.activeWorld?` ★`:``,null),d(()=>t.value=e.branch),t})()})),m(t,i(c,{get when(){return P()},get children(){return b()}}),a),a.$$click=B,m(a,()=>M()?`Saving…`:`Save`),l.$$click=()=>o.onClose(),m(h,i(c,{get when(){return A()},get children(){return x()}}),null),m(h,i(r,{get each(){return I()},children:e=>(()=>{var t=T();return t.$$click=()=>k(e),m(t,e),d(n=>{var r=D()===e?`#1f3158`:`transparent`,i=D()===e?`#58a6ff`:`#c9d1d9`,a=`2px solid ${D()===e?`#388bfd`:`transparent`}`;return r!==n.e&&g(t,`background`,n.e=r),i!==n.t&&g(t,`color`,n.t=i),a!==n.a&&g(t,`border-left`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),null),m(y,D,E),_(R,O),m(v,i(c,{get when(){return!D()},get children(){var e=S();return m(e,()=>A()?`Loading code…`:`Select a module`),e}}),null),d(e=>{var t=M()||A()||!P(),n=M()||!P()?`#161b22`:`#1a3a2a`,r=M()||!P()?`#484f58`:`#3fb950`,i=M()||!P()?`default`:`pointer`,o=D()?`block`:`none`,s=D()?`flex`:`none`;return t!==e.e&&(a.disabled=e.e=t),n!==e.t&&g(a,`background`,e.t=n),r!==e.a&&g(a,`color`,e.a=r),i!==e.o&&g(a,`cursor`,e.o=i),o!==e.i&&g(y,`display`,e.i=o),s!==e.n&&g(O,`display`,e.n=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),d(()=>n.value=u()),e})()}p([`click`]);export{k as CodePanel};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{D as e,S as t}from"./vendor-codemirror-B6f_i0wP.js";import{M as n,N as r,P as i,x as a}from"./clientStore-
|
|
1
|
+
import{D as e,S as t}from"./vendor-codemirror-B6f_i0wP.js";import{M as n,N as r,P as i,x as a}from"./clientStore-Dto6IEkm.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-DuICDnEc.js";import{t as m}from"./src-CK_prN2V.js";var h=856343,g=1448738,_=1843496,ee=3421243,te=h,v=7039337,ne=3159613,re=1579032,ie=2631720,ae=2632986,oe=2500383,se=2771488,ce={tough:5000268,move:11122630,work:16770413,carry:7829367,attack:16332866,ranged_attack:6127794,heal:6684002,claim:12164347},y=5809919,b=7979263,x=4176208,S=9147550,C=13801762,le=10711543,ue=16218298,w=16273737,T=15763518,de=2172461,fe=v,pe=13226457,me=12283502,he=[16777215,16711680,8388736,255,65535,32768,16776960,16753920,10824234,8421504,16777215],ge={creep:T,spawn:y,extension:b,tower:x,container:S,storage:C,link:le,rampart:y,road:fe,constructedWall:de,extractor:S,lab:ue,terminal:C,observer:b,powerSpawn:T,nuker:w,factory:S,invaderCore:w,source:C,mineral:b,deposit:C,controller:y,powerBank:T,portal:le},E=16771195,_e=E,ve=b,ye=E,be=b,xe=E,Se=E,Ce=w,we=x,Te=b,Ee=16777215,De=9419667,Oe=7245682,ke=12116924,Ae=12283502,je=9787480,Me=14721184,Ne=_,Pe=13684944,Fe=4067858,Ie=14440008,Le=11940394,Re=1579032,ze=5592405,Be=11184810,Ve=9419667,D=16771195,O=16069959,He=7105644,Ue={energy:D,power:O,H:13421772,O:16777215,U:5822457,L:62626,K:10514943,Z:16631694,X:11568379,G:16777215},We={biomass:8695826,metal:9793372,mist:14314485,silicon:5023717},Ge=5617743,Ke=9099642,qe=11680314,Je=14049376;function Ye(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>t(r),r.onerror=n,r.src=e})}var k=class{cache=new Map;pending=new Map;getKey(e){return JSON.stringify(e)}has(e){return this.cache.has(this.getKey(e))}getOrCreate(e){let t=this.getKey(e),n=this.cache.get(t);if(n)return Promise.resolve(n);let r=this.pending.get(t);if(r)return r;let i=this.buildTexture(e,t);return this.pending.set(t,i),i.then(()=>{this.pending.delete(t)}).catch(()=>{this.pending.delete(t)}),i}async buildTexture(e,t){let n=m(e),r=new Blob([n],{type:`image/svg+xml;charset=utf-8`}),i=URL.createObjectURL(r);try{let e=window.devicePixelRatio||1,n=128*Math.max(2,e),r=await Ye(i),a=document.createElement(`canvas`);a.width=n,a.height=n,a.getContext(`2d`).drawImage(r,0,0,n,n);let o=p.from(a);return this.cache.set(t,o),o}finally{URL.revokeObjectURL(i)}}destroy(){for(let e of this.cache.values())e.destroyed||e.destroy(!0);this.cache.clear(),this.pending.clear()}};function A(e,n){let r=localStorage.getItem(e),[i,a]=t(r===null?n:r===`true`);return[i,t=>{a(t),localStorage.setItem(e,String(t))}]}function Xe(e,n){let[r,i]=t(localStorage.getItem(e)??n);return[r,t=>{i(t),localStorage.setItem(e,t)}]}var[Ze,Qe]=A(a.widescreenMode,!0),[$e,et]=A(a.showCreepLabels,!0),[tt,nt]=A(a.showMapRoomNames,!1),[rt,it]=A(a.showUnclaimableRooms,!0),[at,ot]=A(a.terrainEffects,!0),[st,ct]=A(a.showRoomDecorations,!1),[lt,ut]=A(a.roomDarkOverlay,!0),[dt,ft]=A(a.showRoomVisuals,!0),[pt,mt]=Xe(a.spriteTheme,`default`),[ht,gt]=A(a.showMapVisuals,!0),j=i(),_t=j?`?v=${encodeURIComponent(j)}`:``,M={id:`default`,name:`Default`,atlasUrl:`${r()}/themes/default/sprite-0.json${_t}`,sprites:{storage:{layers:[{frame:`storage/shell`,tint:`owner`},{frame:`storage/fill`}],tileScale:1.75}},controller:{backgroundFrame:`controller/background`,segmentFrame:`controller/segment`,tileScale:2},flag:{mainFrame:`flag/main`,secondFrame:`flag/second`,tileScale:3,zIndex:5},tombstone:{shellFrame:`grave/shell`,crossFrame:`grave/cross`,tileScale:1,zIndex:4},deposit:{tileScale:1.2},mineral:{tileScale:2.6},tower:{ringFrame:`tower/ring`,bodyFrame:`tower/body`,tileScale:2.5,fill:{x:-39,yMin:-25,width:78,heightMax:58,rx:12,ry:12}}},vt=class{cache=new Map;pending=new Map;frames=new Map;getOrLoad(e){let t=this.cache.get(e);if(t)return Promise.resolve(t);let n=this.pending.get(e);if(n)return n;let r=s.load(e).then(t=>(this.cache.set(e,t),this.frames.set(e,yt(t)),this.pending.delete(e),t)).catch(t=>{throw this.pending.delete(e),t});return this.pending.set(e,r),r}getTexture(e,t){return this.frames.get(e)?.[t]}destroy(){for(let[,e]of this.cache){for(let t of e.linkedSheets??[])t.destroy(!0);e.destroy(!0)}this.cache.clear(),this.frames.clear(),this.pending.clear()}};function yt(e){let t={...e.textures};for(let n of e.linkedSheets??[])Object.assign(t,n.textures);return t}var N=new vt;function bt(e,t,n){return isNaN(n.minX)||isNaN(n.maxX)||isNaN(n.minY)||isNaN(n.maxY)?!0:e>=n.minX&&e<=n.maxX&&t>=n.minY&&t<=n.maxY}function P(e){let t=e.match(/^([WE])(\d+)([NS])(\d+)$/);if(!t)return null;let[,n,r,i,a]=t;return{x:n===`W`?-(parseInt(r,10)+1):parseInt(r,10),y:i===`N`?-(parseInt(a,10)+1):parseInt(a,10)}}function F(e,t){let n=e<0?`W`:`E`,r=t<0?`N`:`S`;return`${n}${e<0?-e-1:e}${r}${t<0?-t-1:t}`}function xt(e){return e===0||e<0&&(e+1)%10==0||e>0&&e%10==0}function St(e,t){return xt(e)||xt(t)}function Ct(e,t){let n=e<0?Math.abs(e+1)%10:Math.abs(e)%10,r=t<0?Math.abs(t+1)%10:Math.abs(t)%10;return n>=4&&n<=6&&r>=4&&r<=6}function wt(e){let t=e;if(!t)return!1;let n=t.tagName??``;return n===`INPUT`||n===`TEXTAREA`?!0:t.isContentEditable===!0}function Tt(t){let n=e=>{if(wt(e.target))return;let n=t.currentRoom(),r=n?P(n):null;if(!r)return;let i=t.worldBounds(),a=(e,t)=>!i||bt(e,t,i);switch(e.key){case`ArrowLeft`:e.preventDefault(),a(r.x-1,r.y)&&t.onMove(r.x-1,r.y);break;case`ArrowRight`:e.preventDefault(),a(r.x+1,r.y)&&t.onMove(r.x+1,r.y);break;case`ArrowUp`:e.preventDefault(),a(r.x,r.y-1)&&t.onMove(r.x,r.y-1);break;case`ArrowDown`:e.preventDefault(),a(r.x,r.y+1)&&t.onMove(r.x,r.y+1);break}};window.addEventListener(`keydown`,n),e(()=>window.removeEventListener(`keydown`,n))}var[Et,Dt]=t(`owner`),I=3,Ot=I*50,L=4;function R(e,t,n){let r=P(e);return r?[r.x*Ot+t*I,r.y*Ot+n*I]:null}var z=3*I,B=2.5*I,V=1*I,H=2*I;function U(e,t,n,r){let i=!0,a=n;for(let o=0;o<t.length-1;o++){let[s,c]=t[o],[l,u]=t[o+1],d=l-s,f=u-c,p=Math.sqrt(d*d+f*f);if(p<.001)continue;let m=d/p,h=f/p,g=0;for(;g<p;){let t=Math.min(a,p-g);if(i){let n=s+m*g,r=c+h*g;e.moveTo(n,r),e.lineTo(n+m*t,r+h*t)}g+=t,a-=t,a<.001&&(i=!i,a=i?n:r)}}}function kt(e,t,n){let r=Math.max(32,Math.ceil(2*Math.PI*n/2)),i=[];for(let a=0;a<=r;a++){let o=a/r*2*Math.PI;i.push([e+Math.cos(o)*n,t+Math.sin(o)*n])}return i}var At=class{container;g;constructor(){this.container=new o,this.container.label=`mapVisuals`,this.g=new u,this.container.addChild(this.g)}update(e){let t=this.container.removeChildren();for(let e of t)e!==this.g&&e.destroy();if(this.g.clear(),this.container.addChild(this.g),!e)return;let n=this.g;for(let t of e.split(`
|
|
2
2
|
`)){if(!t.trim())continue;let e;try{e=JSON.parse(t)}catch{continue}let r=e.s??{},i=r.opacity??.5;switch(e.t){case`l`:this.drawLine(n,e,r,i);break;case`c`:this.drawCircle(n,e,r,i);break;case`r`:this.drawRect(n,e,r,i);break;case`p`:this.drawPoly(n,e,r,i);break;case`t`:this.drawText(e,r,i);break}}}clear(){let e=this.container.removeChildren();for(let t of e)t!==this.g&&t.destroy();this.g.clear(),this.container.addChild(this.g)}drawLine(e,t,n,r){let i=R(t.n1,t.x1,t.y1),a=R(t.n2,t.x2,t.y2);if(!i||!a)return;let o=n.color??`#ffffff`,s=(n.width??.5)*I;n.lineStyle===`dashed`?U(e,[i,a],z*(n.width??.5),B*(n.width??.5)):n.lineStyle===`dotted`?U(e,[i,a],V*(n.width??.5),H*(n.width??.5)):(e.moveTo(i[0],i[1]),e.lineTo(a[0],a[1])),e.stroke({color:o,width:s,alpha:r})}drawCircle(e,t,n,r){let i=R(t.n,t.x,t.y);if(!i)return;let[a,o]=i,s=(n.radius??10)*I,c=!!(n.fill&&n.fill!==`transparent`),l=!!(n.stroke&&n.strokeWidth),u=(n.strokeWidth??.5)*I;c&&(e.circle(a,o,s),e.fill({color:n.fill,alpha:r})),l&&(n.lineStyle===`dashed`?U(e,kt(a,o,s),z*(n.strokeWidth??.5),B*(n.strokeWidth??.5)):n.lineStyle===`dotted`?U(e,kt(a,o,s),V*(n.strokeWidth??.5),H*(n.strokeWidth??.5)):e.circle(a,o,s),e.stroke({color:n.stroke,width:u,alpha:r}))}drawRect(e,t,n,r){let i=R(t.n,t.x,t.y),a=R(t.n,t.x+t.w,t.y),o=R(t.n,t.x+t.w,t.y+t.h),s=R(t.n,t.x,t.y+t.h);if(!i||!a||!o||!s)return;let c=!!(n.fill&&n.fill!==`transparent`),l=!!(n.stroke&&n.strokeWidth),u=[i,a,o,s,i],d=u.flatMap(e=>e),f=(n.strokeWidth??.5)*I;c&&(e.poly(d.slice(0,8),!0),e.fill({color:n.fill,alpha:r})),l&&(n.lineStyle===`dashed`?U(e,u,z*(n.strokeWidth??.5),B*(n.strokeWidth??.5)):n.lineStyle===`dotted`?U(e,u,V*(n.strokeWidth??.5),H*(n.strokeWidth??.5)):e.poly(d.slice(0,8),!0),e.stroke({color:n.stroke,width:f,alpha:r}))}drawPoly(e,t,n,r){if(!t.points||t.points.length===0)return;let i=!!(n.fill&&n.fill!==`transparent`),a=!!(n.stroke&&n.strokeWidth);if(!i&&!a)return;let o=[];for(let{n:e,x:n,y:r}of t.points){let t=R(e,n,r);if(!t)return;o.push(t)}let s=o.flatMap(e=>e),c=(n.strokeWidth??.5)*I;if(i&&(e.poly(s,!0),e.fill({color:n.fill,alpha:r})),a){if(n.lineStyle===`dashed`){let t=o[0],r=o[o.length-1];U(e,t[0]===r[0]&&t[1]===r[1]?o:[...o,t],z*(n.strokeWidth??.5),B*(n.strokeWidth??.5))}else if(n.lineStyle===`dotted`){let t=o[0],r=o[o.length-1];U(e,t[0]===r[0]&&t[1]===r[1]?o:[...o,t],V*(n.strokeWidth??.5),H*(n.strokeWidth??.5))}else e.poly(s,!0);e.stroke({color:n.stroke,width:c,alpha:r})}}drawText(e,t,n){let r=R(e.n,e.x,e.y);if(!r)return;let[i,a]=r,o=t.fontSize??10,s=t.fontFamily??`sans-serif`,c=o*I,l=t.align??`center`,p=new f({fill:t.color??`#ffffff`,fontSize:c*L,fontFamily:s,align:l,...t.fontStyle?{fontStyle:t.fontStyle}:{},...t.fontVariant?{fontVariant:t.fontVariant}:{},...t.stroke&&t.strokeWidth?{stroke:{color:t.stroke,width:t.strokeWidth*I*L}}:{}});if(t.backgroundColor&&t.backgroundColor!==`transparent`){let r=(t.backgroundPadding??2)*I,o=new d({text:e.text,style:p});o.scale.set(1/L);let s=o.width,c=o.height;o.destroy();let f=i-(l===`center`?.5:+(l===`right`))*s-r,m=a-c/2-r,h=new u;h.rect(f,m,s+r*2,c+r*2),h.fill({color:t.backgroundColor,alpha:n}),this.container.addChild(h)}let m=new d({text:e.text,style:p});m.scale.set(1/L),m.anchor.x=l===`center`?.5:+(l===`right`),m.anchor.y=.5,m.position.set(i,a),m.alpha=n,this.container.addChild(m)}destroy(){let e=this.container.removeChildren();for(let t of e)t!==this.g&&t.destroy();this.g.destroy(),this.container.destroy()}},{warn:jt}=n(`terrainCache`),Mt=`screeps-terrain-v1`;async function Nt(e,t,n){try{let r=await caches.open(Mt),i=`/terrain/${e}_${t}_z${n}.webp`,a=new Request(i),o=await r.match(a);if(o){let e=await o.arrayBuffer(),t=o.headers.get(`Content-Type`)??`image/webp`;return new Blob([e],{type:t})}}catch(e){jt(`get failed:`,e)}return null}async function Pt(e,t,n,r){try{let i=await caches.open(Mt),a=`/terrain/${e}_${t}_z${n}.webp`,o=new Request(a),s=new Response(r);await i.put(o,s)}catch(e){jt(`save failed:`,e)}}var W=null;async function Ft(e){if(W!==!1)try{let t=await createImageBitmap(e);return W=!0,t}catch(e){if(W===!0)throw e;W=!1}let t=URL.createObjectURL(e);try{let e=new Image;return e.src=t,await e.decode(),await createImageBitmap(e)}finally{URL.revokeObjectURL(t)}}function It(e){return new Worker(`/_client/terrain.worker-CiQZPqa4.js`,{name:e?.name})}var Lt=2962235,Rt=856343,zt=4020797,Bt=v,G=4486980,Vt=8921634,Ht=x,Ut=me,Wt=[{key:`s`,color:E,radius:2.5},{key:`c`,color:16777215,radius:2},{key:`m`,color:b,radius:2},{key:`k`,color:T,radius:2},{key:`pb`,color:16720418,radius:2.5},{key:`d`,color:16777215,radius:2.5}],Gt=new Set([`w`,`r`,`pb`,`p`,`s`,`c`,`m`,`k`,`d`]);function Kt(e){return`#`+e.toString(16).padStart(6,`0`)}var{warn:K}=n(`MapRenderer`),q=3,J=q*50,qt=[50,60,70,80,90,100,105,120],Y=1,X=.5,Z=50,Jt=2600,Yt=5,Q=.2,$=5,Xt=[80,104,128,160],Zt=class{app;world;boundsGraphics=null;selectionGraphics=null;safeModeGraphics=null;mapVisualLayer=null;safeModeRooms=new Set;activeRooms=new Map;roomPool=[];terrainBaked=new Set;terrainData=new Map;worker;pendingBakes=new Map;nextBakeId=0;currentShard=`shard0`;callbacks;resizeObserver=null;_destroyed=!1;showRoomNames=!1;worldBoundsSet=null;lastVisibleBounds=null;animTargetX=0;animTargetY=0;isAnimating=!1;overlayMode=`owner`;showUnclaimableOverlay=!0;isDragging=!1;hasDragged=!1;dragStartX=0;dragStartY=0;dragWorldX=0;dragWorldY=0;isPinching=!1;pinchPivotWorldX=0;pinchPivotWorldY=0;pinchStartDist=0;pinchStartScale=0;lastVisibleKey=``;visibleDebounceTimer=null;selectedRoom=null;currentUserId=null;badgeCache=new k;constructor(e){this.app=new l,this.callbacks=e,this.worker=new It,this.worker.onmessage=e=>{let t=e.data;if(t.kind===`cache`){Pt(t.shard,t.roomName,t.lod,new Blob([t.cacheBytes],{type:t.cacheType||`image/webp`}));return}let n=this.pendingBakes.get(t.id);n&&(this.pendingBakes.delete(t.id),n.resolve(t.bitmap))}}async init(e){let t=e.parentElement??e,{width:n,height:r}=t.getBoundingClientRect();await this.app.init({canvas:e,width:n,height:r,background:te,antialias:!1,preference:`webgl`}),this.resizeObserver=new ResizeObserver(e=>{let{width:t,height:n}=e[0].contentRect,r=this.app.screen.width,i=this.app.screen.height;this.app.renderer.resize(t,n),this.world.x+=(t-r)/2,this.world.y+=(n-i)/2}),this.resizeObserver.observe(t),this.world=new o,this.app.stage.addChild(this.world),this.boundsGraphics=new u,this.world.addChild(this.boundsGraphics),this.selectionGraphics=new u,this.world.addChild(this.selectionGraphics),this.safeModeGraphics=new u,this.world.addChild(this.safeModeGraphics),this.mapVisualLayer=new At,this.world.addChild(this.mapVisualLayer.container),this.setupInteraction(),this.app.ticker.add(()=>{if(this.isAnimating){let e=this.animTargetX-this.world.x,t=this.animTargetY-this.world.y;Math.abs(e)<.5&&Math.abs(t)<.5?(this.world.x=this.animTargetX,this.world.y=this.animTargetY,this.isAnimating=!1):(this.world.x+=e*.2,this.world.y+=t*.2)}this.checkVisibleRooms()})}get zoom(){return this.world?.scale.x??1}setZoom(e){if(!this.world||(e=Math.max(Q,Math.min($,e)),e===this.world.scale.x))return;let t=this.app.screen.width/2,n=this.app.screen.height/2;this.applyZoomAt(e,t,n)}applyZoomAt(e,t,n){let r=this.world.scale.x,i=this.getLOD(),a=this.zoom>=Y,o=this.zoom>=X,s=(t-this.world.x)/r,c=(n-this.world.y)/r;this.world.scale.set(e),this.world.x=t-s*e,this.world.y=n-c*e,this.getLOD()!==i&&this.applyLOD(),(e>=Y!==a||e>=.5!==o)&&this.updateAllNameLabels(),this.updateAllRoomScales(e),this.callbacks.onZoomChanged?.(e),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode()}centerOn(e,t,n=!1){let r=e*J+J/2,i=t*J+J/2,a=this.world.scale.x,o=this.app.screen.width/2-r*a,s=this.app.screen.height/2-i*a;n?(this.animTargetX=o,this.animTargetY=s,this.isAnimating=!0):(this.isAnimating=!1,this.world.x=o,this.world.y=s)}async getTerrainBitmap(e,t,n){let r=this.currentShard;try{let i=await Nt(r,e,t);if(i)return await Ft(i);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:r}),await o}catch(e){return K(`error getting terrain bitmap:`,e),null}}async setRoomTerrain(e,t){let n=t.raw,r=!1;for(let e=0;e<n.length;e++)if(n[e]!==0){r=!0;break}if(!r){this.terrainBaked.add(e);return}let i=this.getOrCreate(e),a=this.getLOD();this.terrainData.set(e,n);let o=await this.getTerrainBitmap(e,a,n);if(!o)return;if(!this.activeRooms.has(e)){o.close();return}let s=p.from(o);a===0?(i.texLo&&!i.texLo.destroyed&&(i.terrainSprite.texture===i.texLo&&(i.terrainSprite.texture=p.EMPTY),i.texLo.destroy(!0)),i.texLo=s):(i.texHi&&!i.texHi.destroyed&&(i.terrainSprite.texture===i.texHi&&(i.terrainSprite.texture=p.EMPTY),i.texHi.destroy(!0)),i.texHi=s),i.terrainSprite.width=J,i.terrainSprite.height=J,this.terrainBaked.add(e),this.ensureCurrentLod(e,i)}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 this.getTerrainBitmap(e,+!!n,i).then(r=>{if(!r)return;if(!this.activeRooms.has(e)){r.close();return}let i=p.from(r);n?t.texHi=i:t.texLo=i,this.getLOD()===1===n&&(t.terrainSprite.texture=i)})}async applyLOD(){let e=[];for(let[t,n]of this.activeRooms){if(!this.terrainBaked.has(t))continue;let r=this.ensureCurrentLod(t,n);r&&e.push(r)}await Promise.all(e)}setRoomMap2(e,t,n=`live`){let r=this.getOrCreate(e);r.lastMap2Data=t,r.lastMap2Source=n,this.drawMap2(r,t,n)}drawMap2(e,t,n){let r=e.map2Graphics;r.alpha=n===`cache`?.6:1;let i=q;r.clear();let a=t.r??[];for(let[e,t]of a)r.rect(e*i,t*i,i,i);a.length&&r.fill(Bt);let o=t.w??[];for(let[e,t]of o)r.rect(e*i+.5,t*i+.5,i-1,i-1);o.length&&r.fill(e.ownerState===`other`?Vt:G);for(let e of Wt){let n=t[e.key]??[];for(let[t,a]of n)r.circle((t+.5)*i,(a+.5)*i,e.radius);n.length&&r.fill(e.color)}let s=t;for(let e in s){if(Gt.has(e))continue;let t=s[e];if(!Array.isArray(t)||t.length===0)continue;for(let[e,n]of t)r.circle((e+.5)*i,(n+.5)*i,1);let n=e===this.currentUserId?Ht:Ut;r.fill(n)}}clearRoomMap2(e){this.activeRooms.get(e)?.map2Graphics.clear()}clearAllMap2(){for(let e of this.activeRooms.values())e.map2Graphics.clear()}setRoomOwned(e,t){let n=this.activeRooms.get(e);if(!n)return;n.ownerState!==t&&(n.ownerState=t,n.lastMap2Data&&this.drawMap2(n,n.lastMap2Data,n.lastMap2Source??`live`));let r=n.ownerOverlay;r.clear(),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=this.showUnclaimableOverlay}setUnclaimableOverlayVisible(e){if(this.showUnclaimableOverlay!==e){this.showUnclaimableOverlay=e;for(let t of this.activeRooms.values())t.ownerOverlay.visible=e}}async setRoomBadge(e,t,n){let r=this.activeRooms.get(e);if(r){if(!t){r.badgeSprite&&=(r.container.removeChild(r.badgeSprite),r.badgeSprite.destroy(),void 0),r.badgeLevel=void 0;return}try{let i=await this.badgeCache.getOrCreate(t);if(!this.activeRooms.has(e))return;if(r.badgeSprite){if(r.badgeSprite.texture===i){r.badgeLevel=n,this.applyBadgeSize(r,this.zoom),this.applyOverlayMode(r);return}r.badgeSprite.texture=i}else{let e=new c(i);e.anchor.set(.5),e.x=J/2,e.y=J/2;let t=r.container.getChildIndex(r.nameLabel);r.container.addChildAt(e,t),r.badgeSprite=e}r.badgeLevel=n,this.applyBadgeSize(r,this.zoom),this.applyOverlayMode(r)}catch(t){K(`failed to load badge for`,e,t)}}}applyBadgeSize(e,t){if(!e.badgeSprite||e.badgeLevel===void 0)return;let n=(qt[e.badgeLevel-1]??24)*Math.min(1,t);e.badgeSprite.width=n/t,e.badgeSprite.height=n/t}setOverlayMode(e){if(this.overlayMode!==e){this.overlayMode=e;for(let e of this.activeRooms.values())this.applyOverlayMode(e)}}setRoomMineral(e,t,n){let r=this.activeRooms.get(e);if(r){if(!t||!n){r.mineralSprite&&=(r.container.removeChild(r.mineralSprite),r.mineralSprite.destroy(),void 0),r.mineralType=void 0,r.mineralDensity=void 0;return}if(r.mineralDensity=n,!r.mineralSprite||r.mineralType!==t){r.mineralSprite&&(r.container.removeChild(r.mineralSprite),r.mineralSprite.destroy());let e=`mineral/${t}`,n=new c;n.anchor.set(.5),n.x=J/2,n.y=J/2;let i=r.container.getChildIndex(r.nameLabel);r.container.addChildAt(n,i),r.mineralSprite=n,r.mineralType=t;let a=N.getTexture(M.atlasUrl,e);a?n.texture=a:N.getOrLoad(M.atlasUrl).then(t=>{n.destroyed||(n.texture=t.textures[e]??p.EMPTY)}).catch(()=>{})}this.applyMineralSize(r,this.zoom),this.applyOverlayMode(r)}}applyOverlayMode(e){e.badgeSprite&&(e.badgeSprite.visible=this.overlayMode===`owner`),e.mineralSprite&&(e.mineralSprite.visible=this.overlayMode===`mineral`)}applyMineralSize(e,t){if(!e.mineralSprite||e.mineralDensity===void 0)return;let n=Xt[e.mineralDensity-1]??52,r=14/t,i=Math.max(n,r);e.mineralSprite.width=i,e.mineralSprite.height=i}updateNameLabelScale(e,t){let n=.3/Math.sqrt(t),r=12/(36*t);e.nameLabel.scale.set(Math.max(n,r))}updateAllRoomScales(e){for(let t of this.activeRooms.values())this.applyBadgeSize(t,e),this.updateNameLabelScale(t,e),this.applyMineralSize(t,e)}setCurrentUser(e){this.currentUserId=e}setMapVisual(e){this.mapVisualLayer?.update(e),this.mapVisualLayer&&(this.world.removeChild(this.mapVisualLayer.container),this.world.addChild(this.mapVisualLayer.container))}clearMapVisual(){this.mapVisualLayer?.clear()}setMapVisualVisible(e){this.mapVisualLayer&&(this.mapVisualLayer.container.visible=e)}setSelectedRoom(e){if(this.selectedRoom=e,!this.selectionGraphics||(this.selectionGraphics.clear(),this.world.removeChild(this.selectionGraphics),this.world.addChild(this.selectionGraphics),!e))return;let t=P(e);if(!t)return;let n=t.x*J,r=t.y*J;this.selectionGraphics.rect(n,r,J,J);let i=Math.max(2,Math.ceil(2/this.zoom));this.selectionGraphics.stroke({color:16777215,width:i,alignment:0})}setRoomSafeMode(e,t){t?this.safeModeRooms.add(e):this.safeModeRooms.delete(e),this.redrawSafeMode()}redrawSafeMode(){if(!this.safeModeGraphics||(this.safeModeGraphics.clear(),this.safeModeRooms.size===0))return;let e=Math.max(1,Math.ceil(1/this.zoom));for(let t of this.safeModeRooms){let n=P(t);if(!n)continue;let r=n.x*J,i=n.y*J;this.safeModeGraphics.rect(r,i,J,J),this.safeModeGraphics.stroke({color:16776960,width:e,alignment:1,alpha:.5})}this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)}setBounds(e,t,n,r){if(!this.boundsGraphics)return;this.worldBoundsSet={minX:e,maxX:t,minY:n,maxY:r},this.boundsGraphics.clear();let i=e*J,a=n*J,o=(t-e+1)*J,s=(r-n+1)*J;this.boundsGraphics.rect(i,a,o,s),this.boundsGraphics.stroke({color:ne,width:6,alignment:0}),this.updateAllNameLabels()}clearBounds(){this.worldBoundsSet=null,this.boundsGraphics?.clear(),this.updateAllNameLabels()}setShowRoomNames(e){this.showRoomNames=e,this.updateAllNameLabels()}hasRoom(e){return this.terrainBaked.has(e)}markRoomFetched(e){this.terrainBaked.add(e)}clearRoom(e){let t=this.activeRooms.get(e);t&&(t.texLo&&!t.texLo.destroyed&&t.texLo.destroy(!0),t.texHi&&!t.texHi.destroyed&&t.texHi.destroy(!0),t.texLo=null,t.texHi=null,t.terrainSprite.texture=p.EMPTY,t.map2Graphics.clear(),t.ownerOverlay.clear(),t.badgeSprite&&=(t.container.removeChild(t.badgeSprite),t.badgeSprite.destroy(),void 0),t.mineralSprite&&=(t.container.removeChild(t.mineralSprite),t.mineralSprite.destroy(),void 0),t.mineralType=void 0,t.mineralDensity=void 0,t.container.visible=!1,this.safeModeRooms.delete(e),this.terrainBaked.delete(e),this.terrainData.delete(e),this.activeRooms.delete(e),this.roomPool.length<Jt?this.roomPool.push(t):(this.world.removeChild(t.container),t.container.destroy({children:!0,context:!0})))}clearInvisibleRooms(e){let t=this.lastVisibleBounds;for(let n of[...this.activeRooms.keys()])if(!e.has(n)){if(t){let e=P(n);if(e&&e.x>=t.rxMin-Z&&e.x<=t.rxMax+Z&&e.y>=t.ryMin-Z&&e.y<=t.ryMax+Z)continue}this.clearRoom(n)}}destroy(){if(!this._destroyed){this._destroyed=!0,this.resizeObserver?.disconnect(),this.resizeObserver=null,this.visibleDebounceTimer!==null&&(clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=null);for(let[,e]of this.activeRooms)e.texLo&&!e.texLo.destroyed&&e.texLo.destroy(!0),e.texHi&&!e.texHi.destroyed&&e.texHi.destroy(!0);this.activeRooms.clear(),this.safeModeRooms.clear();for(let e of this.roomPool)e.texLo&&!e.texLo.destroyed&&e.texLo.destroy(!0),e.texHi&&!e.texHi.destroyed&&e.texHi.destroy(!0);this.roomPool.length=0,this.terrainBaked.clear(),this.terrainData.clear(),this.worker.terminate(),this.pendingBakes.clear(),this.badgeCache.destroy(),this.mapVisualLayer?.destroy(),this.mapVisualLayer=null;try{this.app.destroy(!1,{children:!0,context:!0})}catch(e){K(`destroy error (ignored):`,e)}}}getOrCreate(e){let t=this.activeRooms.get(e);if(t)return t;let n=P(e);if(!n)throw Error(`MapRenderer: invalid room "${e}"`);let r;if(this.roomPool.length>0)r=this.roomPool.pop();else{let e=new o;e.cullable=!0;let t=new c(p.EMPTY),n=new u,i=new u;e.addChild(t),e.addChild(n),e.addChild(i);let a=new d({text:``,style:{fontSize:36,fill:9147550,fontFamily:`ui-monospace, monospace`}});a.scale.set(.25),a.x=2,a.y=2,e.addChild(a),this.world.addChild(e),r={container:e,terrainSprite:t,texLo:null,texHi:null,map2Graphics:n,ownerOverlay:i,ownerState:`none`,nameLabel:a}}return r.container.x=n.x*J,r.container.y=n.y*J,r.container.visible=!0,r.nameLabel.text=e,r.nameLabel.visible=this.showRoomNames&&this.zoom>=.5&&this.nameLabelShouldShow(n.x,n.y),this.updateNameLabelScale(r,this.zoom),r.badgeSprite&&(r.container.removeChild(r.badgeSprite),r.badgeSprite.destroy(),r.badgeSprite=void 0),r.mineralSprite&&(r.container.removeChild(r.mineralSprite),r.mineralSprite.destroy(),r.mineralSprite=void 0),r.mineralType=void 0,r.mineralDensity=void 0,this.safeModeGraphics&&(this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)),this.selectionGraphics&&(this.world.removeChild(this.selectionGraphics),this.world.addChild(this.selectionGraphics)),this.activeRooms.set(e,r),r}nameLabelShouldShow(e,t){let n=this.worldBoundsSet;return!(n&&(e<n.minX||e>n.maxX||t<n.minY||t>n.maxY))}updateAllNameLabels(){let e=this.showRoomNames&&this.zoom>=.5;for(let[t,n]of this.activeRooms){if(!e){n.nameLabel.visible=!1;continue}let r=P(t);r&&(n.nameLabel.visible=this.nameLabelShouldShow(r.x,r.y))}}setupInteraction(){let e=this.app.canvas;e.style.touchAction=`none`,e.style.userSelect=`none`;let t=new Map;e.addEventListener(`pointermove`,n=>{if(!t.has(n.pointerId)){if(!this.isDragging&&!this.isPinching){let t=e.getBoundingClientRect();this.emitHover(n.clientX-t.left,n.clientY-t.top)}return}if(t.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.isPinching&&t.size===2){let n=[...t.values()],r=e.getBoundingClientRect(),i=(n[0].x+n[1].x)/2-r.left,a=(n[0].y+n[1].y)/2-r.top,o=Math.hypot(n[1].x-n[0].x,n[1].y-n[0].y),s=Math.max(Q,Math.min($,this.pinchStartScale*(o/this.pinchStartDist))),c=this.getLOD(),l=this.zoom>=Y,u=this.zoom>=X;this.world.scale.set(s),this.world.x=i-this.pinchPivotWorldX*s,this.world.y=a-this.pinchPivotWorldY*s,this.getLOD()!==c&&this.applyLOD(),(s>=Y!==l||s>=.5!==u)&&this.updateAllNameLabels(),this.updateAllRoomScales(s),this.callbacks.onZoomChanged?.(s),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode();return}if(this.isDragging){let e=n.clientX-this.dragStartX,t=n.clientY-this.dragStartY;(Math.abs(e)>3||Math.abs(t)>3)&&(this.hasDragged=!0);let r=this.worldBoundsSet;if(r){let n=this.world.scale.x,i=50-(r.maxX+1)*J*n,a=this.app.screen.width-50-r.minX*J*n,o=50-(r.maxY+1)*J*n,s=this.app.screen.height-50-r.minY*J*n;this.world.x=this.rubberBand(this.dragWorldX+e,i,a),this.world.y=this.rubberBand(this.dragWorldY+t,o,s)}else this.world.x=this.dragWorldX+e,this.world.y=this.dragWorldY+t}}),e.addEventListener(`pointerleave`,()=>{!this.isDragging&&!this.isPinching&&this.callbacks.onRoomHover(null)}),e.addEventListener(`pointerdown`,n=>{if(n.preventDefault(),this.isAnimating=!1,t.set(n.pointerId,{x:n.clientX,y:n.clientY}),e.setPointerCapture(n.pointerId),t.size>=2){this.isDragging=!1,this.isPinching=!0;let n=[...t.values()],r=e.getBoundingClientRect(),i=(n[0].x+n[1].x)/2-r.left,a=(n[0].y+n[1].y)/2-r.top;this.pinchStartDist=Math.hypot(n[1].x-n[0].x,n[1].y-n[0].y),this.pinchStartScale=this.world.scale.x,this.pinchPivotWorldX=(i-this.world.x)/this.pinchStartScale,this.pinchPivotWorldY=(a-this.world.y)/this.pinchStartScale}else this.isPinching=!1,this.isDragging=!0,this.hasDragged=!1,this.dragStartX=n.clientX,this.dragStartY=n.clientY,this.dragWorldX=this.world.x,this.dragWorldY=this.world.y}),e.addEventListener(`pointerup`,n=>{if(t.delete(n.pointerId),e.releasePointerCapture(n.pointerId),this.isPinching){t.size<2&&(this.isPinching=!1,this.isDragging=!1,this.springBack());return}if(this.isDragging){if(this.isDragging=!1,!this.hasDragged){let t=e.getBoundingClientRect(),r=this.screenToRoom(n.clientX-t.left,n.clientY-t.top);r&&this.callbacks.onRoomClick(r)}this.springBack()}}),e.addEventListener(`pointercancel`,n=>{t.delete(n.pointerId),e.releasePointerCapture(n.pointerId),(this.isPinching||this.isDragging)&&(this.isPinching=!1,this.isDragging=!1,this.springBack())}),e.addEventListener(`wheel`,e=>{if(e.preventDefault(),this.isDragging||this.isPinching)return;this.isAnimating=!1;let t=this.world.scale.x,n=e.deltaY<0?1.1:.9,r=Math.max(Q,Math.min($,t*n));this.applyZoomAt(r,e.offsetX,e.offsetY)},{passive:!1})}rubberBand(e,t,n){let r=n-t;if(r<=0||e>=t&&e<=n)return e;let i=.55;return e<t?t-(1-1/((t-e)*i/r+1))*r*i:n+(1-1/((e-n)*i/r+1))*r*i}springBack(){let e=this.worldBoundsSet;if(!e)return;let t=this.world.scale.x,n=this.app.screen.width,r=this.app.screen.height,i=this.world.x+e.minX*J*t,a=this.world.x+(e.maxX+1)*J*t,o=this.world.y+e.minY*J*t,s=this.world.y+(e.maxY+1)*J*t,c=this.world.x,l=this.world.y;a<50?c+=50-a:i>n-50&&(c-=i-(n-50)),s<50?l+=50-s:o>r-50&&(l-=o-(r-50)),(c!==this.world.x||l!==this.world.y)&&(this.animTargetX=c,this.animTargetY=l,this.isAnimating=!0)}screenToRoom(e,t){let n=this.world.scale.x,r=(e-this.world.x)/n,i=(t-this.world.y)/n;return F(Math.floor(r/J),Math.floor(i/J))}emitHover(e,t){this.callbacks.onRoomHover(this.screenToRoom(e,t))}lastCheckX=0;lastCheckY=0;lastCheckScale=0;checkVisibleRooms(){let e=this.world.scale.x,t=this.world.x,n=this.world.y;if(this.lastCheckX===t&&this.lastCheckY===n&&this.lastCheckScale===e)return;this.lastCheckX=t,this.lastCheckY=n,this.lastCheckScale=e;let r=-t/e,i=-n/e,a=(this.app.screen.width-t)/e,o=(this.app.screen.height-n)/e,s=Math.floor(r/J)-1,c=Math.ceil(a/J),l=Math.floor(i/J)-1,u=Math.ceil(o/J);this.lastVisibleBounds={rxMin:s,rxMax:c,ryMin:l,ryMax:u};let d=[],f=this.worldBoundsSet,p=f?Math.max(s,f.minX):s,m=f?Math.min(c,f.maxX):c,h=f?Math.max(l,f.minY):l,g=f?Math.min(u,f.maxY):u;for(let e=p;e<=m;e++)for(let t=h;t<=g;t++){let n=F(e,t);n&&d.push(n)}let _=`${s},${l},${c},${u}`;_!==this.lastVisibleKey&&(this.lastVisibleKey=_,this.visibleDebounceTimer!==null&&clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=setTimeout(()=>{this.visibleDebounceTimer=null,this.callbacks.onVisibleRoomsChanged(d)},Yt))}};export{xe as $,ft as A,O as At,rt as B,ae as Bt,M as C,fe as Ct,nt as D,ze as Dt,et as E,D as Et,$e as F,He as Ft,ye as G,at as H,re as Ht,tt as I,ne as It,Se as J,_e as K,ht as L,ee as Lt,mt as M,qe as Mt,ot as N,Je as Nt,gt as O,Be as Ot,Qe as P,Ke as Pt,Te as Q,st as R,v as Rt,N as S,S as St,ut as T,Re as Tt,Ze as U,ie as Ut,pt as V,se as Vt,k as W,Ce as X,be as Y,we as Z,F as _,Ie as _t,Lt as a,Ne as at,bt as b,pe as bt,Ut as c,Me as ct,G as d,ke as dt,ve as et,Kt as f,We as ft,wt as g,Le as gt,Tt as h,Fe as ht,Gt as i,Pe as it,it as j,Ge as jt,ct as k,Ve as kt,Ht as l,De as lt,Dt as m,he as mt,X as n,h as nt,Bt as o,Ae as ot,Et as p,E as pt,Ee as q,Wt as r,ce as rt,zt as s,je as st,Zt as t,g as tt,Rt as u,Oe as ut,St as v,ge as vt,lt as w,Ue as wt,P as x,me as xt,Ct as y,b as yt,dt as z,oe as zt};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e,O as t,S as n,_ as r}from"./vendor-codemirror-B6f_i0wP.js";import{$ as i,M as a,et as o,n as s,p as c,v as l,y as u}from"./clientStore-
|
|
1
|
+
import{D as e,O as t,S as n,_ as r}from"./vendor-codemirror-B6f_i0wP.js";import{$ as i,M as a,et as o,n as s,p as c,v as l,y as u}from"./clientStore-Dto6IEkm.js";import{B as d,I as f,L as p,_ as m,b as h,h as g,p as _,t as v,v as y,x as b,y as x}from"./MapRenderer-b8FMSs3l.js";var S=i(`<div style=width:100%;height:100%;position:relative><canvas style=display:block>`),{log:C,error:w}=a(`map`);function T(i){let a,T=null,[E,D]=n([]),[O,k]=n(1),[A,j]=n(i.originRoom??null),M=null,N=null,P=new Map,F=new Map,I=new Map,L=new Map,R=e=>{let t=u();if(!t)return!0;let n=b(e);return!!n&&h(n.x,n.y,t)},z=e=>{let t=F.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}},B=[],V=null,H=new Set,U=()=>{V=null;let e=s();if(!e||!T)return;let t=new Set(E());if(B=B.filter(e=>t.has(e)&&!T.hasRoom(e)&&!H.has(e)),B.length===0)return;let n=B.splice(0,200);for(let e of n)H.add(e);e.stores.room.terrainBulk(n,i.shard).then(async e=>{let t=[];for(let[n,r]of e){let e=T?.setRoomTerrain(n,r);e&&t.push(e);let i=I.get(n);i!==void 0&&T?.setRoomOwned(n,i)}for(let t of n)e.has(t)||T?.markRoomFetched(t);await Promise.all(t)}).catch(e=>w(`terrain fetch failed:`,e)).finally(()=>{for(let e of n)H.delete(e);B.length>0&&(V=setTimeout(U,0))})};return r(()=>{s(),i.shard,F.clear(),I.clear()}),t(()=>{a&&(async()=>{if(T=new v({onRoomHover:e=>{i.onHoveredRoomChanged?.(e?z(e):null)},onRoomClick:e=>{A()===e?R(e)&&setTimeout(()=>i.onNavigateToRoom(e),0):(j(e),T?.setSelectedRoom(e),i.onSelectedRoomChanged?.(z(e)))},onVisibleRoomsChanged:e=>{let t=e.length===0;N!==t&&(N=t,C(t?`zoom out — too many rooms visible, terrain loading paused`:`zoom in — terrain loading active, ${e.length} rooms visible`)),D(e)},onZoomChanged:e=>{k(e),i.onZoomChanged?.(e)}}),await T.init(a),!T)return;i.initialZoom!==void 0&&i.initialZoom>0&&T.setZoom(i.initialZoom),i.onZoomChanged?.(T.zoom);let e=u();if(e&&T.setBounds(e.minX,e.maxX,e.minY,e.maxY),i.originRoom){let e=b(i.originRoom);e&&T.centerOn(e.x,e.y),T.setSelectedRoom(i.originRoom),i.onSelectedRoomChanged?.(z(i.originRoom))}else{let e=s();if(e)try{let t=await e.http.user.worldStartRoom(i.shard??`shard0`);if(!T)return;let n=Array.isArray(t?.room)?t.room[0]:t?.room;if(typeof n==`string`){let e=b(n);e&&T.centerOn(e.x,e.y)}}catch(e){w(`worldStartRoom failed:`,e)}}})()}),e(()=>{V!==null&&(clearTimeout(V),V=null),B=[],H.clear();for(let e of P.values())e.dispose();P.clear(),T?.destroy(),T=null}),r(()=>{g({currentRoom:A,worldBounds:u,onMove:(e,t)=>{let n=m(e,t);j(n),T?.setSelectedRoom(n),T?.centerOn(e,t,!0),i.onSelectedRoomChanged?.(z(n)),i.onHoveredRoomChanged?.(z(n))}});let t=e=>{let t=e.target?.tagName??``,n=e.target?.isContentEditable??!1;if(!(t===`INPUT`||t===`TEXTAREA`||n)&&e.key===`m`){let e=A();e&&R(e)&&i.onNavigateToRoom(e)}};window.addEventListener(`keydown`,t),e(()=>window.removeEventListener(`keydown`,t))}),r(()=>{let e=s(),t=E(),n=i.shard;if(!e||t.length===0)return;let r=new Set(t),a=t.filter(e=>!T?.hasRoom(e)&&!H.has(e));if(a.length>0){let e=t.reduce((e,t)=>e+(b(t)?.x??0),0)/t.length,n=t.reduce((e,t)=>e+(b(t)?.y??0),0)/t.length;B=a.slice().sort((t,r)=>{let i=b(t),a=b(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)}),V===null&&(V=setTimeout(U,0))}e.stores.mapStats.request(t,`owner0`,n??void 0);let o=O()>=.4;if(o!==M&&(M=o,i.onSubscriptionStateChanged?.(o),o||T?.clearAllMap2()),o){let r=new Set(t.map(e=>`${e}/${n}`));for(let[e,t]of P)r.has(e)||(t.dispose(),P.delete(e),T?.clearRoomMap2(e.split(`/`)[0]));for(let r of t){let t=`${r}/${n}`;P.has(t)||P.set(t,e.stores.map.subscribeMap2(r,n))}}else{for(let[,e]of P)e.dispose();P.clear()}T?.clearInvisibleRooms(r)}),r(()=>{T?.setShowRoomNames(f()),T&&(T.currentShard=i.shard??`shard0`)}),r(()=>{T?.setUnclaimableOverlayVisible(d())}),r(()=>{T?.setMapVisualVisible(p())}),r(()=>{T?.setOverlayMode(_())}),r(()=>{let e=s(),t=i.shard;e&&e.stores.server.worldInfo(t??void 0).then(e=>{C(`worldInfo(shard=${t??`none`}) — x: [${e.minX}, ${e.maxX}] y: [${e.minY}, ${e.maxY}]`),c(e)}).catch(e=>{C(`worldInfo(shard=${t??`none`}) failed:`,e)})}),r(()=>{T?.setCurrentUser(l()?._id??null)}),r(()=>{let e=u();e?(T?.setBounds(e.minX,e.maxX,e.minY,e.maxY),C(`worldBounds applied — shard: ${i.shard??`none`} x: [${e.minX}, ${e.maxX}] y: [${e.minY}, ${e.maxY}] (fetched for shard: ${e.shard??`none`})`)):(T?.clearBounds(),C(`worldBounds — none (shard: ${i.shard??`none`})`))}),r(()=>{let t=s();if(!t)return;let n=t.stores.user.subscribeMapVisual(i.shard),r=t.stores.user.on(`user:mapVisual`,({shard:e,data:t})=>{e===i.shard&&(t?T?.setMapVisual(t):T?.clearMapVisual())});e(()=>{n.dispose(),r.dispose()})}),r(()=>{let t=s();if(!t)return;let n=t.stores.map.on(`room:map2update`,({room:e,shard:t,data:n,source:r})=>{t===i.shard&&T?.setRoomMap2(e,n,r)});e(()=>n.dispose())}),r(()=>{let t=s();if(!t)return;let n=l()?._id,r=new Set(E()),a=t.stores.mapStats.on(`mapStats:room`,({room:e,stat:t})=>{F.set(e,t);let a=b(e),o=a?y(a.x,a.y)||x(a.x,a.y):!1,s=t.status===`out of borders`,c=!!(t.own&&t.own.user===n),l=!!(t.own&&t.own.user!==n),u=c?`own`:o||s||l?`other`:`none`;I.set(e,u),r.has(e)&&(T?.setRoomOwned(e,u),T?.setRoomSafeMode(e,!!t.safeMode)),T?.setRoomMineral(e,t.mineral,t.density);let d=t.badge?JSON.stringify(t.badge):``;L.get(e)!==d&&(L.set(e,d),T?.setRoomBadge(e,t.badge,t.own?.level)),A()===e&&i.onSelectedRoomChanged?.(z(e))});e(()=>a.dispose())}),(()=>{var e=S(),t=e.firstChild;return o(e=>a=e,t),e})()}export{T as MapViewer};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_client/src-CBSP2mk_.js","_client/src-CK_prN2V.js","_client/vendor-pixi-DuICDnEc.js","_client/rolldown-runtime-Bh1tDfsg.js","_client/decompress-CWkNrR0q.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{A as e,S as t,j as n,k as r,s as i,v as a,x as o,y as s}from"./vendor-codemirror-B6f_i0wP.js";import{x as c}from"./vendor-pixi-DuICDnEc.js";import{_ as l,g as u,h as d,p as ee,v as te}from"./src-CK_prN2V.js";var ne=new Set([`className`,`value`,`readOnly`,`noValidate`,`formNoValidate`,`isMap`,`noModule`,`playsInline`,`adAuctionHeaders`,`allowFullscreen`,`browsingTopics`,`defaultChecked`,`defaultMuted`,`defaultSelected`,`disablePictureInPicture`,`disableRemotePlayback`,`preservesPitch`,`shadowRootClonable`,`shadowRootCustomElementRegistry`,`shadowRootDelegatesFocus`,`shadowRootSerializable`,`sharedStorageWritable`,...`allowfullscreen.async.alpha.autofocus.autoplay.checked.controls.default.disabled.formnovalidate.hidden.indeterminate.inert.ismap.loop.multiple.muted.nomodule.novalidate.open.playsinline.readonly.required.reversed.seamless.selected.adauctionheaders.browsingtopics.credentialless.defaultchecked.defaultmuted.defaultselected.defer.disablepictureinpicture.disableremoteplayback.preservespitch.shadowrootclonable.shadowrootcustomelementregistry.shadowrootdelegatesfocus.shadowrootserializable.sharedstoragewritable`.split(`.`)]),re=new Set([`innerHTML`,`textContent`,`innerText`,`children`]),ie=Object.assign(Object.create(null),{className:`class`,htmlFor:`for`}),ae=Object.assign(Object.create(null),{class:`className`,novalidate:{$:`noValidate`,FORM:1},formnovalidate:{$:`formNoValidate`,BUTTON:1,INPUT:1},ismap:{$:`isMap`,IMG:1},nomodule:{$:`noModule`,SCRIPT:1},playsinline:{$:`playsInline`,VIDEO:1},readonly:{$:`readOnly`,INPUT:1,TEXTAREA:1},adauctionheaders:{$:`adAuctionHeaders`,IFRAME:1},allowfullscreen:{$:`allowFullscreen`,IFRAME:1},browsingtopics:{$:`browsingTopics`,IMG:1},defaultchecked:{$:`defaultChecked`,INPUT:1},defaultmuted:{$:`defaultMuted`,AUDIO:1,VIDEO:1},defaultselected:{$:`defaultSelected`,OPTION:1},disablepictureinpicture:{$:`disablePictureInPicture`,VIDEO:1},disableremoteplayback:{$:`disableRemotePlayback`,AUDIO:1,VIDEO:1},preservespitch:{$:`preservesPitch`,AUDIO:1,VIDEO:1},shadowrootclonable:{$:`shadowRootClonable`,TEMPLATE:1},shadowrootdelegatesfocus:{$:`shadowRootDelegatesFocus`,TEMPLATE:1},shadowrootserializable:{$:`shadowRootSerializable`,TEMPLATE:1},sharedstoragewritable:{$:`sharedStorageWritable`,IFRAME:1,IMG:1}});function oe(e,t){let n=ae[e];return typeof n==`object`?n[t]?n.$:void 0:n}var se=new Set([`beforeinput`,`click`,`dblclick`,`contextmenu`,`focusin`,`focusout`,`input`,`keydown`,`keyup`,`mousedown`,`mousemove`,`mouseout`,`mouseover`,`mouseup`,`pointerdown`,`pointermove`,`pointerout`,`pointerover`,`pointerup`,`touchend`,`touchmove`,`touchstart`]),ce=new Set(`altGlyph.altGlyphDef.altGlyphItem.animate.animateColor.animateMotion.animateTransform.circle.clipPath.color-profile.cursor.defs.desc.ellipse.feBlend.feColorMatrix.feComponentTransfer.feComposite.feConvolveMatrix.feDiffuseLighting.feDisplacementMap.feDistantLight.feDropShadow.feFlood.feFuncA.feFuncB.feFuncG.feFuncR.feGaussianBlur.feImage.feMerge.feMergeNode.feMorphology.feOffset.fePointLight.feSpecularLighting.feSpotLight.feTile.feTurbulence.filter.font.font-face.font-face-format.font-face-name.font-face-src.font-face-uri.foreignObject.g.glyph.glyphRef.hkern.image.line.linearGradient.marker.mask.metadata.missing-glyph.mpath.path.pattern.polygon.polyline.radialGradient.rect.set.stop.svg.switch.symbol.text.textPath.tref.tspan.use.view.vkern`.split(`.`)),le={xlink:`http://www.w3.org/1999/xlink`,xml:`http://www.w3.org/XML/1998/namespace`},ue=e=>a(()=>e());function de(e,t,n){let r=n.length,i=t.length,a=r,o=0,s=0,c=t[i-1].nextSibling,l=null;for(;o<i||s<a;){if(t[o]===n[s]){o++,s++;continue}for(;t[i-1]===n[a-1];)i--,a--;if(i===o){let t=a<r?s?n[s-1].nextSibling:n[a-s]:c;for(;s<a;)e.insertBefore(n[s++],t)}else if(a===s)for(;o<i;)(!l||!l.has(t[o]))&&t[o].remove(),o++;else if(t[o]===n[a-1]&&n[s]===t[i-1]){let r=t[--i].nextSibling;e.insertBefore(n[s++],t[o++].nextSibling),e.insertBefore(n[--a],r),t[i]=n[a]}else{if(!l){l=new Map;let e=s;for(;e<a;)l.set(n[e],e++)}let r=l.get(t[o]);if(r!=null)if(s<r&&r<a){let c=o,u=1,d;for(;++c<i&&c<a&&!((d=l.get(t[c]))==null||d!==r+u);)u++;if(u>r-s){let i=t[o];for(;s<r;)e.insertBefore(n[s++],i)}else e.replaceChild(n[s++],t[o++])}else o++;else t[o++].remove()}}}var 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 o(r=>{i=r,t===document?e():Se(t,e(),t.firstChild?null:void 0,n)},r.owner),()=>{i(),t.textContent=``}}function me(e,t,r,i){let a,o=()=>{if(g())throw Error(`Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration.`);let t=i?document.createElementNS(`http://www.w3.org/1998/Math/MathML`,`template`):document.createElement(`template`);return t.innerHTML=e,r?t.content.firstChild.firstChild:i?t.firstChild:t.content.firstChild},s=t?()=>n(()=>document.importNode(a||=o(),!0)):()=>(a||=o()).cloneNode(!0);return s.cloneNode=s,s}function 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,Oe))}}function f(e,t,n){g(e)||(n==null?e.removeAttribute(t):e.setAttribute(t,n))}function ge(e,t,n,r){g(e)||(r==null?e.removeAttributeNS(t,n):e.setAttributeNS(t,n,r))}function _e(e,t,n){g(e)||(n?e.setAttribute(t,``):e.removeAttribute(t))}function ve(e,t){g(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]||(Ee(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||(Ee(e,i,!0),n[i]=o)}return n}function p(e,t,n){if(!t)return n?f(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 m(e,t={},n,r){let i={};return r||s(()=>i.children=_(e,t.children,i.children)),s(()=>typeof t.ref==`function`&&h(t.ref,e)),s(()=>Ce(e,t,n,!0,i,!0)),i}function h(e,t,r){return n(()=>e(t,r))}function Se(e,t,n,r){if(n!==void 0&&!r&&(r=[]),typeof t!=`function`)return _(e,t,r,n);s(r=>_(e,t(),r,n),r)}function Ce(e,t,n,r,i={},a=!1){t||={};for(let r in i)if(!(r in t)){if(r===`children`)continue;i[r]=De(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]=De(e,o,s,i[o],n,a,t)}}function we(e){let t,n,i=g();if(!i||!(t=r.registry.get(n=ke()))){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 g(e){return!!r.context&&!r.done&&(!e||e.isConnected)}function Te(e){return e.toLowerCase().replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function Ee(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 De(e,t,n,r,i,a,o){let s,c,l,u,d;if(t===`style`)return p(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:`)f(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(g(e))return n;t===`class`||t===`className`?ve(e,n):s&&!c&&!l?e[Te(t)]=n:e[u||t]=n}else{let r=i&&t.indexOf(`:`)>-1&&le[t.split(`:`)[0]];r?ge(e,r,t,n):f(e,ie[t]||t,n)}return n}function Oe(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,t,n,r,i){let a=g(e);if(a){!n&&(n=[...e.childNodes]);let t=[];for(let e=0;e<n.length;e++){let r=n[e];r.nodeType===8&&r.data.slice(0,2)===`!$`?r.remove():t.push(r)}n=t}for(;typeof n==`function`;)n=n();if(t===n)return n;let o=typeof t,c=r!==void 0;if(e=c&&n[0]&&n[0].parentNode||e,o===`string`||o===`number`){if(a||o===`number`&&(t=t.toString(),t===n))return n;if(c){let i=n[0];i&&i.nodeType===3?i.data!==t&&(i.data=t):i=document.createTextNode(t),n=b(e,n,r,i)}else n=n!==``&&typeof n==`string`?e.firstChild.data=t:e.textContent=t}else if(t==null||o===`boolean`){if(a)return n;n=b(e,n,r)}else if(o===`function`)return s(()=>{let i=t();for(;typeof i==`function`;)i=i();n=_(e,i,n,r)}),()=>n;else if(Array.isArray(t)){let o=[],l=n&&Array.isArray(n);if(v(o,t,n,i))return s(()=>n=_(e,o,n,r,!0)),()=>n;if(a){if(!o.length)return n;if(r===void 0)return n=[...e.childNodes];let t=o[0];if(t.parentNode!==e)return n;let i=[t];for(;(t=t.nextSibling)!==r;)i.push(t);return n=i}if(o.length===0){if(n=b(e,n,r),c)return n}else l?n.length===0?y(e,o,r):de(e,n,o):(n&&b(e),y(e,o));n=o}else if(t.nodeType){if(a&&t.parentNode)return n=c?[t]:t;if(Array.isArray(n)){if(c)return n=b(e,n,r,t);b(e,n,null,t)}else n==null||n===``||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);n=t}else console.warn(`Unrecognized value. Skipped inserting`,t);return n}function 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 y(e,t,n=null){for(let r=0,i=t.length;r<i;r++)e.insertBefore(t[r],n)}function b(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 ke(){return r.getNextContextId()}var Ae=`http://www.w3.org/2000/svg`;function je(e,t=!1,n=void 0){return t?document.createElementNS(Ae,e):document.createElement(e,{is:n})}function Me(e,t){let o=a(e);return a(()=>{let e=o();switch(typeof e){case`function`:return Object.assign(e,{[i]:!0}),n(()=>e(t));case`string`:let a=ce.has(e),o=r.context?we():je(e,a,n(()=>t.is));return m(o,t,a),o}})}function Ne(t){let[,n]=e(t,[`component`]);return Me(()=>t.component,n)}function x(){return typeof window<`u`&&window.__TAURI_INTERNALS__!=null}var S=!1;async function Pe(){if(S)return;let[{fetch:e},{setFetch:t}]=await Promise.all([c(()=>import(`./dist-js-CmlkNKgN.js`),[]),c(()=>import(`./src-CBSP2mk_.js`),__vite__mapDeps([0,1,2,3,4]))]);t(e),S=!0}var[Fe,C]=t([]),Ie=0;function w(e,t=`success`,n=4e3){let r=Ie++;C(i=>[...i,{id:r,message:e,type:t,duration:n}]),setTimeout(()=>{C(e=>e.filter(e=>e.id!==r))},n)}var Le=!1;function T(){return typeof window>`u`?!1:window.location.pathname.startsWith(`/client`)}function Re(){return Le}function E(){return window.location.origin}function ze(){return`0.13.0`}function Be(){return typeof window>`u`?null:window.__SCREEPS_CLIENT_EMBEDDED__??null}function Ve(){return`/`.replace(/\/$/,``)}function He(e){let t=`[${e}]`;return{log:()=>{},warn:()=>{},error:(...e)=>console.error(t,...e)}}function D(){return x()?localStorage:sessionStorage}var Ue={room:`screeps:room`,shard:`screeps:shard`,sidebarWidth:`screeps:sidebarWidth`,consoleHeight:`screeps:consoleHeight`,consoleSplit:`screeps:consoleSplit`,consoleWeights:`screeps:consoleWeights`,memoryWatches:`screeps:memoryWatches`,mapZoom:`screeps:mapZoom`,widescreenMode:`screeps:settings:widescreenMode`,showCreepLabels:`screeps:settings:showCreepLabels`,showMapRoomNames:`screeps:settings:showMapRoomNames`,showUnclaimableRooms:`screeps:settings:showUnclaimableRooms`,terrainEffects:`screeps:settings:terrainEffects`,showRoomDecorations:`screeps:settings:showRoomDecorations`,roomDarkOverlay:`screeps:settings:roomDarkOverlay`,showRoomVisuals:`screeps:settings:showRoomVisuals`,spriteTheme:`screeps:settings:spriteTheme`,showMapVisuals:`screeps:settings:showMapVisuals`},O={url:`screeps:url`,token:`screeps:token`,serverPassword:`screeps:serverPassword`,authMethod:`screeps:authMethod`};function We(e){return localStorage.getItem(e)}function Ge(e,t){localStorage.setItem(e,t)}function Ke(e){localStorage.removeItem(e)}function qe(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 Je(e,t){localStorage.setItem(e,String(t))}function Ye(e,t){let n=localStorage.getItem(e);if(n===null)return t;try{return JSON.parse(n)}catch{return t}}function Xe(e,t){localStorage.setItem(e,JSON.stringify(t))}function k(e){return D().getItem(e)}function A(e,t){D().setItem(e,t)}function j(e){D().removeItem(e)}async function Ze(){if(localStorage.clear(),indexedDB.databases){let e=await indexedDB.databases();await Promise.all(e.map(e=>e.name?new Promise(t=>{let n=indexedDB.deleteDatabase(e.name);n.onsuccess=()=>t(),n.onerror=()=>t(),n.onblocked=()=>t()}):Promise.resolve()))}if(`caches`in window){let e=await caches.keys();await Promise.all(e.map(e=>caches.delete(e)))}}var{log:M}=He(`client`),[N,P]=t(null),[Qe,F]=t(`idle`),[$e,I]=t(null),[et,L]=t(null),[R,z]=t(null),[tt,B]=t(null),[nt,V]=t(null),[rt,H]=t(!1),[it,U]=t(null),[at,W]=t(null),[ot,G]=t({}),[st,K]=t(null),ct=1e3,lt=15e3,q=null,J=0;function ut(){q===null&&(M(`world status polling: start`),q=setInterval(()=>{let e=N();e&&e.stores.user.refreshWorldStatus().catch(()=>{})},ct))}function dt(){q!==null&&(M(`world status polling: stop`),clearInterval(q),q=null)}function Y(e){e===`empty`||e===`lost`||Date.now()<J?ut():dt()}function ft(){J=Date.now()+lt,ut()}var X=-1,Z=-1,Q=[],pt=5;function mt(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>pt&&Q.shift();let t=Q.reduce((e,t)=>e+t,0)/Q.length;V(Math.round(t))}}X=e,Z=t}function ht(){X=-1,Z=-1,Q.length=0,V(null)}var gt=()=>{let e=R();return e?(e.serverData?.shards?.length??0)===0:null};async function $(e){T()&&(e={...e,url:E()}),M(`connecting to ${e.url} (auth: ${e.auth})`),F(`connecting`),I(null);try{let t;if(e.auth===`guest`)t=new d,H(!0);else if(e.auth===`password`){if(!e.email||!e.password)throw Error(`Email and password are required`);t=new u({email:e.email,password:e.password})}else{if(!e.token)throw Error(`Token is required`);t=new l({token:e.token})}let n=new te({url:e.url,auth:t,storage:e.storage??new ee(`screeps-client`),debug:!1,serverPassword:e.serverPassword});n.http.on(`http:tokenRefresh`,({token:e})=>{M(`token refreshed`),A(O.token,e)}),n.http.on(`http:error`,({method:e,path:t,error:n,silent:r})=>{M(`http error:`,e,t,n.message),r||w(`Request failed: ${e} ${t} — ${n.message}`,`error`,6e3)}),n.stores.server.on(`server:disconnected`,e=>{M(`server disconnected (willReconnect: ${e.willReconnect})`),e.willReconnect||(F(`idle`),P(null),L(null),z(null),J=0,Y(null))}),n.stores.server.on(`server:error`,e=>{M(`server error:`,e.error.message),I(e.error.message),F(`error`)}),n.stores.user.on(`user:me`,e=>{M(`user: ${e.username} (id: ${e._id})`),L(e)}),n.stores.server.on(`server:version`,e=>{M(`server version: ${e.package??`unknown`}`),z(e)}),n.stores.user.on(`user:stream`,e=>{if(e&&typeof e==`object`&&`flags`in e){let t=e.flags;t&&typeof t==`object`&&G(t)}}),n.stores.user.on(`user:worldStatus`,({status:e})=>{M(`world status: ${e}`),K(e),Y(e)}),await n.connect(),n.stores.user.subscribeUserStream(),P(n),F(`connected`),M(`connected to ${e.url}`),A(O.url,e.url);let r=e.authMethod??e.auth;U(r),A(O.authMethod,r),n.http.token&&A(O.token,n.http.token),e.serverPassword?A(O.serverPassword,e.serverPassword):j(O.serverPassword)}catch(e){let t=e instanceof Error?e.message:String(e);throw M(`connection failed:`,t),I(t),F(`error`),P(null),e}}async function _t(){let e=T()?E():k(O.url),t=k(O.token);if(!e||!t)return;let n=k(O.serverPassword)??void 0,r=k(O.authMethod);M(`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{M(`auto-connect failed — clearing stored token`),j(O.token)}}function vt(){M(`disconnecting`);let e=N();e&&e.disconnect(),P(null),F(`idle`),I(null),L(null),z(null),B(null),H(!1),U(null),W(null),G({}),K(null),J=0,Y(null),ht(),j(O.token),j(O.url),j(O.serverPassword),j(O.authMethod)}export{me as $,Je as A,Fe as B,Ze as C,We as D,k as E,Be as F,he as G,x as H,E as I,pe as J,Se as K,T as L,He as M,Ve as N,Ke as O,ze as P,p as Q,Re as R,O as S,qe as T,Ne as U,Pe as V,ye as W,xe as X,f as Y,m as Z,ot as _,$e as a,st as b,rt as c,R as d,h as et,B as f,_t as g,nt as h,vt as i,Ge as j,Xe as k,gt as l,Qe as m,N as n,ft as o,W as p,ue as q,$ as r,tt as s,it as t,mt as u,et as v,Ye as w,Ue as x,at as y,w as z};
|