From 6567cfd850b5884f6ed689007567dbd33c69f5d9 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Mon, 24 May 2021 16:40:03 +0100 Subject: [PATCH] Move URL generation to Util --- src/store/getters.ts | 11 +++++------ src/util.ts | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/store/getters.ts b/src/store/getters.ts index 105cbe7..361f0e9 100644 --- a/src/store/getters.ts +++ b/src/store/getters.ts @@ -16,7 +16,7 @@ import {GetterTree} from "vuex"; import {State} from "@/store/state"; -import {getMinecraftTime} from "@/util"; +import {getMinecraftTime, getUrlForLocation} from "@/util"; import {LiveAtlasDynmapServerDefinition} from "@/index"; export type Getters = { @@ -63,17 +63,16 @@ export const getters: GetterTree & Getters = { }, url(state: State): string { - const x = Math.round(state.currentLocation.x), - y = Math.round(state.currentLocation.y), - z = Math.round(state.currentLocation.z), - locationString = `${x},${y},${z}`, + const x = state.currentLocation.x, + y = state.currentLocation.y, + z = state.currentLocation.z, zoom = state.currentZoom; if(!state.currentWorld || !state.currentMap) { return ''; } - return `#${state.currentWorld.name};${state.currentMap.name};${locationString};${zoom}`; + return getUrlForLocation(state.currentWorld, state.currentMap, {x,y,z}, zoom); }, serverConfig(state: State): LiveAtlasDynmapServerDefinition { diff --git a/src/util.ts b/src/util.ts index 1128426..7edcfd0 100644 --- a/src/util.ts +++ b/src/util.ts @@ -15,7 +15,7 @@ */ import API from '@/api'; -import {DynmapPlayer, DynmapUrlConfig} from "@/dynmap"; +import {DynmapPlayer, DynmapUrlConfig, DynmapWorld, DynmapWorldMap} from "@/dynmap"; import {useStore} from "@/store"; import {LiveAtlasDynmapServerDefinition, LiveAtlasServerDefinition} from "@/index"; import ConfigurationError from "@/errors/ConfigurationError"; @@ -327,4 +327,20 @@ export const getAPI = () => { } return API; +} + +export const getUrlForLocation = (world: DynmapWorld, map: DynmapWorldMap, location: { + x: number, + y: number, + z: number }, zoom: number): string => { + const x = Math.round(location.x), + y = Math.round(location.y), + z = Math.round(location.z), + locationString = `${x},${y},${z}`; + + if(!world || !map) { + return ''; + } + + return `#${world.name};${map.name};${locationString};${zoom}`; } \ No newline at end of file