Move URL generation to Util
This commit is contained in:
parent
5550f7e220
commit
6567cfd850
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
import {GetterTree} from "vuex";
|
import {GetterTree} from "vuex";
|
||||||
import {State} from "@/store/state";
|
import {State} from "@/store/state";
|
||||||
import {getMinecraftTime} from "@/util";
|
import {getMinecraftTime, getUrlForLocation} from "@/util";
|
||||||
import {LiveAtlasDynmapServerDefinition} from "@/index";
|
import {LiveAtlasDynmapServerDefinition} from "@/index";
|
||||||
|
|
||||||
export type Getters = {
|
export type Getters = {
|
||||||
@ -63,17 +63,16 @@ export const getters: GetterTree<State, State> & Getters = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
url(state: State): string {
|
url(state: State): string {
|
||||||
const x = Math.round(state.currentLocation.x),
|
const x = state.currentLocation.x,
|
||||||
y = Math.round(state.currentLocation.y),
|
y = state.currentLocation.y,
|
||||||
z = Math.round(state.currentLocation.z),
|
z = state.currentLocation.z,
|
||||||
locationString = `${x},${y},${z}`,
|
|
||||||
zoom = state.currentZoom;
|
zoom = state.currentZoom;
|
||||||
|
|
||||||
if(!state.currentWorld || !state.currentMap) {
|
if(!state.currentWorld || !state.currentMap) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return `#${state.currentWorld.name};${state.currentMap.name};${locationString};${zoom}`;
|
return getUrlForLocation(state.currentWorld, state.currentMap, {x,y,z}, zoom);
|
||||||
},
|
},
|
||||||
|
|
||||||
serverConfig(state: State): LiveAtlasDynmapServerDefinition {
|
serverConfig(state: State): LiveAtlasDynmapServerDefinition {
|
||||||
|
18
src/util.ts
18
src/util.ts
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import API from '@/api';
|
import API from '@/api';
|
||||||
import {DynmapPlayer, DynmapUrlConfig} from "@/dynmap";
|
import {DynmapPlayer, DynmapUrlConfig, DynmapWorld, DynmapWorldMap} from "@/dynmap";
|
||||||
import {useStore} from "@/store";
|
import {useStore} from "@/store";
|
||||||
import {LiveAtlasDynmapServerDefinition, LiveAtlasServerDefinition} from "@/index";
|
import {LiveAtlasDynmapServerDefinition, LiveAtlasServerDefinition} from "@/index";
|
||||||
import ConfigurationError from "@/errors/ConfigurationError";
|
import ConfigurationError from "@/errors/ConfigurationError";
|
||||||
@ -328,3 +328,19 @@ export const getAPI = () => {
|
|||||||
|
|
||||||
return API;
|
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