Move URL generation to Util

This commit is contained in:
James Lyne 2021-05-24 16:40:03 +01:00
parent 5550f7e220
commit 6567cfd850
2 changed files with 22 additions and 7 deletions

View File

@ -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<State, State> & 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 {

View File

@ -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";
@ -328,3 +328,19 @@ 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}`;
}