diff --git a/src/App.vue b/src/App.vue index 700735e..28be75f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -29,6 +29,7 @@ import {useStore} from "@/store"; import {ActionTypes} from "@/store/action-types"; import {parseUrl} from '@/util'; import {MutationTypes} from "@/store/mutation-types"; +import {LiveAtlasServerDefinition} from "@/index"; export default defineComponent({ name: 'App', @@ -62,7 +63,7 @@ export default defineComponent({ return; } - const error = `Failed to load server configuration for '${store.state.currentServer}'`; + const error = `Failed to load server configuration for '${store.state.currentServer.id}'`; console.error(`${error}:`, e); window.showSplashError(`${error}\n${e}`, false, ++configAttempts.value); setTimeout(() => loadConfiguration(), 1000); @@ -125,10 +126,14 @@ export default defineComponent({ watch(title, (title) => document.title = title); watch(currentUrl, (url) => window.history.replaceState({}, '', url)); - watch(currentServer, (newServer) => { + watch(currentServer, (newServer: LiveAtlasServerDefinition) => { window.showSplash(); stopUpdates(); + if(!newServer) { + return; + } + //Cleanup store.commit(MutationTypes.CLEAR_PLAYERS, undefined); store.commit(MutationTypes.CLEAR_CURRENT_MAP, undefined); @@ -136,9 +141,9 @@ export default defineComponent({ store.commit(MutationTypes.CLEAR_WORLDS, undefined); store.commit(MutationTypes.CLEAR_MARKER_SETS, undefined); - window.history.replaceState({}, '', newServer); + window.history.replaceState({}, '', newServer.id); loadConfiguration(); - }); + }, {deep: true}); watch(configurationHash, (newHash, oldHash) => { if(newHash && oldHash) { window.showSplash(); diff --git a/src/api.ts b/src/api.ts index ab4f2ca..34ecab8 100644 --- a/src/api.ts +++ b/src/api.ts @@ -30,14 +30,12 @@ import { DynmapTileUpdate, DynmapUpdate, DynmapUpdateResponse, - DynmapUpdates, DynmapUrlConfig, + DynmapUpdates, DynmapWorld, DynmapWorldMap } from "@/dynmap"; import {useStore} from "@/store"; import ChatError from "@/errors/ChatError"; -import {LiveAtlasDynmapServerDefinition, LiveAtlasServerDefinition} from "@/index"; -import ConfigurationError from "@/errors/ConfigurationError"; const titleColours = /ยง[0-9a-f]/ig; @@ -556,96 +554,6 @@ function buildUpdates(data: Array): DynmapUpdates { return updates; } -const validateLiveAtlasConfiguration = (config: any): Map => { - const check = '\nCheck your server configuration in index.html is correct.', - result = new Map(); - - if (!Object.keys(config).length) { - throw new ConfigurationError(`No servers defined. ${check}`); - } - - for (const server in config) { - if (!Object.hasOwnProperty.call(config, server)) { - continue; - } - - const serverConfig = config[server]; - - if (!serverConfig || serverConfig.constructor !== Object || !Object.keys(serverConfig).length) { - throw new ConfigurationError(`Server '${server}': Configuration missing. ${check}`); - } - - serverConfig.id = server; - serverConfig.type = 'dynmap'; - - if (!serverConfig.dynmap || serverConfig.dynmap.constructor !== Object) { - throw new ConfigurationError(`Server '${server}': Dynmap configuration object missing. ${check}`); - } - - if (!serverConfig.dynmap.configuration) { - throw new ConfigurationError(`Server '${server}': Dynmap configuration URL missing. ${check}`); - } - - if (!serverConfig.dynmap.update) { - throw new ConfigurationError(`Server '${server}': Dynmap update URL missing. ${check}`); - } - - if (!serverConfig.dynmap.markers) { - throw new ConfigurationError(`Server '${server}': Dynmap markers URL missing. ${check}`); - } - - if (!serverConfig.dynmap.tiles) { - throw new ConfigurationError(`Server '${server}': Dynmap tiles URL missing. ${check}`); - } - - if (!serverConfig.dynmap.sendmessage) { - throw new ConfigurationError(`Server '${server}': Dynmap sendmessage URL missing. ${check}`); - } - - result.set(server, serverConfig); - } - - return result; -}; - -const validateDynmapConfiguration = (config: DynmapUrlConfig): Map => { - const check = '\nCheck your standalone/config.js file exists and is being loaded correctly.'; - - if (!config) { - throw new ConfigurationError(`Dynmap configuration is missing. ${check}`); - } - - if (!config.configuration) { - throw new ConfigurationError(`Dynmap configuration URL is missing. ${check}`); - } - - if (!config.update) { - throw new ConfigurationError(`Dynmap update URL is missing. ${check}`); - } - - if (!config.markers) { - throw new ConfigurationError(`Dynmap markers URL is missing. ${check}`); - } - - if (!config.tiles) { - throw new ConfigurationError(`Dynmap tiles URL is missing. ${check}`); - } - - if (!config.sendmessage) { - throw new ConfigurationError(`Dynmap sendmessage URL is missing. ${check}`); - } - - const result = new Map(); - result.set('dynmap', { - id: 'dynmap', - label: 'dynmap', - type: 'dynmap', - dynmap: config - }); - - return result; -}; - async function fetchJSON(url: string, signal: AbortSignal) { let response, json; @@ -685,18 +593,6 @@ let configurationAbort: AbortController | undefined = undefined, updateAbort: AbortController | undefined = undefined; export default { - validateConfiguration(): Map { - if (!window.liveAtlasConfig) { - throw new ConfigurationError(`Configuration object is missing`); - } - - if (typeof window.liveAtlasConfig.servers !== 'undefined') { - return validateLiveAtlasConfiguration(window.liveAtlasConfig.servers || {}); - } - - return validateDynmapConfiguration(window.config?.url || null); - }, - async getConfiguration(): Promise { if(configurationAbort) { configurationAbort.abort(); diff --git a/src/components/map/layer/MapLayer.vue b/src/components/map/layer/MapLayer.vue index 2ea16d6..ff7686b 100644 --- a/src/components/map/layer/MapLayer.vue +++ b/src/components/map/layer/MapLayer.vue @@ -19,10 +19,10 @@ import {defineComponent, onUnmounted, computed, watch} from "@vue/runtime-core"; import {DynmapWorldMap} from "@/dynmap"; import {Map} from 'leaflet'; import {useStore} from "@/store"; -import {HDMapType} from "@/leaflet/mapType/HDMapType"; import {MutationTypes} from "@/store/mutation-types"; import {ActionTypes} from "@/store/action-types"; import {getMinecraftTime} from "@/util"; +import {DynmapTileLayer} from "@/leaflet/tileLayer/DynmapTileLayer"; export default defineComponent({ props: { @@ -46,7 +46,7 @@ export default defineComponent({ const store = useStore(), night = computed(() => getMinecraftTime(store.state.currentWorldState.timeOfDay).night), - layer = new HDMapType({ + layer = new DynmapTileLayer({ errorTileUrl: 'images/blank.png', mapSettings: Object.freeze(JSON.parse(JSON.stringify(props.map))), night: night.value, diff --git a/src/components/sidebar/ServerListItem.vue b/src/components/sidebar/ServerListItem.vue index 1388a13..d2a192d 100644 --- a/src/components/sidebar/ServerListItem.vue +++ b/src/components/sidebar/ServerListItem.vue @@ -15,8 +15,8 @@ -->