Move URL generation to Util
This commit is contained in:
parent
5550f7e220
commit
6567cfd850
@ -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 {
|
||||
|
18
src/util.ts
18
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}`;
|
||||
}
|
Loading…
Reference in New Issue
Block a user