2020-12-16 16:54:41 +00:00
|
|
|
/*
|
2021-07-25 14:12:40 +00:00
|
|
|
* Copyright 2021 James Lyne
|
2020-12-16 16:54:41 +00:00
|
|
|
*
|
2021-07-25 14:12:40 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2020-12-16 16:54:41 +00:00
|
|
|
*
|
2021-07-25 14:12:40 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2020-12-16 16:54:41 +00:00
|
|
|
*
|
2021-07-25 14:12:40 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2020-12-16 16:54:41 +00:00
|
|
|
*/
|
|
|
|
|
2020-11-23 16:16:26 +00:00
|
|
|
import {GetterTree} from "vuex";
|
|
|
|
import {State} from "@/store/state";
|
2021-05-24 15:40:03 +00:00
|
|
|
import {getMinecraftTime, getUrlForLocation} from "@/util";
|
2020-11-23 16:16:26 +00:00
|
|
|
|
|
|
|
export type Getters = {
|
2020-11-24 01:56:03 +00:00
|
|
|
playerMarkersEnabled(state: State): boolean;
|
2020-12-01 23:20:38 +00:00
|
|
|
coordinatesControlEnabled(state: State): boolean;
|
|
|
|
clockControlEnabled(state: State): boolean;
|
2021-09-08 14:23:21 +00:00
|
|
|
loginEnabled(state: State): boolean;
|
2020-12-10 02:22:29 +00:00
|
|
|
night(state: State): boolean;
|
2020-12-11 15:29:20 +00:00
|
|
|
mapBackground(state: State, getters: GetterTree<State, State> & Getters): string;
|
2020-12-13 02:50:17 +00:00
|
|
|
url(state: State, getters: GetterTree<State, State> & Getters): string;
|
2021-08-12 13:27:39 +00:00
|
|
|
pageTitle(state: State, getters: GetterTree<State, State> & Getters): string;
|
2021-07-29 18:16:37 +00:00
|
|
|
playersHeading(state: State, getters: GetterTree<State, State> & Getters): string;
|
2020-11-23 16:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const getters: GetterTree<State, State> & Getters = {
|
2020-11-24 01:56:03 +00:00
|
|
|
playerMarkersEnabled(state: State): boolean {
|
|
|
|
return state.components.playerMarkers !== undefined;
|
2020-12-01 23:20:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
coordinatesControlEnabled(state: State): boolean {
|
|
|
|
return state.components.coordinatesControl !== undefined;
|
|
|
|
},
|
|
|
|
|
|
|
|
clockControlEnabled(state: State): boolean {
|
|
|
|
return state.components.clockControl !== undefined;
|
2020-12-10 02:22:29 +00:00
|
|
|
},
|
|
|
|
|
2021-09-08 14:23:21 +00:00
|
|
|
loginEnabled(state: State): boolean {
|
|
|
|
return state.components.login || state.loginRequired;
|
|
|
|
},
|
|
|
|
|
2020-12-10 02:22:29 +00:00
|
|
|
night(state: State): boolean {
|
2021-01-26 20:37:29 +00:00
|
|
|
return getMinecraftTime(state.currentWorldState.timeOfDay).night;
|
2020-12-10 02:22:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
mapBackground(state: State): string {
|
|
|
|
if(!state.currentMap) {
|
|
|
|
return 'transparent';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(state.currentMap.nightAndDay) {
|
2021-01-26 20:37:29 +00:00
|
|
|
if(getMinecraftTime(state.currentWorldState.timeOfDay).night) {
|
2020-12-10 02:22:29 +00:00
|
|
|
return state.currentMap.backgroundNight || state.currentMap.background || 'transparent';
|
|
|
|
}
|
|
|
|
|
|
|
|
return state.currentMap.backgroundDay || state.currentMap.background || 'transparent';
|
|
|
|
}
|
|
|
|
|
|
|
|
return state.currentMap.background || 'transparent';
|
2020-12-13 02:50:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
url(state: State): string {
|
2021-05-24 15:40:03 +00:00
|
|
|
const x = state.currentLocation.x,
|
|
|
|
y = state.currentLocation.y,
|
|
|
|
z = state.currentLocation.z,
|
2020-12-13 02:50:17 +00:00
|
|
|
zoom = state.currentZoom;
|
|
|
|
|
|
|
|
if(!state.currentWorld || !state.currentMap) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2021-07-23 19:32:15 +00:00
|
|
|
return getUrlForLocation(state.currentMap, {x,y,z}, zoom);
|
2021-05-17 02:39:25 +00:00
|
|
|
},
|
2021-07-29 18:16:37 +00:00
|
|
|
|
2021-08-12 13:27:39 +00:00
|
|
|
pageTitle(state: State): string {
|
|
|
|
return state.configuration.title
|
|
|
|
.replace(/{world}/gi, state.currentWorld?.displayName || 'No world')
|
|
|
|
.replace(/{map}/gi, state.currentMap?.displayName || 'No map');
|
|
|
|
},
|
|
|
|
|
2021-07-29 18:16:37 +00:00
|
|
|
playersHeading(state: State): string {
|
|
|
|
return state.messages.playersHeading
|
|
|
|
.replace('{cur}', state.players.size.toString())
|
|
|
|
.replace('{max}', state.maxPlayers.toString());
|
|
|
|
}
|
2021-07-23 19:32:15 +00:00
|
|
|
}
|