Fix day/night maps. Fixes #9

This commit is contained in:
James Lyne 2021-02-01 00:16:13 +00:00
parent 7a73b3846d
commit 58ad360f84
2 changed files with 17 additions and 1 deletions

View File

@ -22,6 +22,7 @@ import {useStore} from "@/store";
import {HDMapType} from "@/leaflet/mapType/HDMapType"; import {HDMapType} from "@/leaflet/mapType/HDMapType";
import {MutationTypes} from "@/store/mutation-types"; import {MutationTypes} from "@/store/mutation-types";
import {ActionTypes} from "@/store/action-types"; import {ActionTypes} from "@/store/action-types";
import {getMinecraftTime} from "@/util";
export default defineComponent({ export default defineComponent({
props: { props: {
@ -44,9 +45,11 @@ export default defineComponent({
stopUpdateWatch: Function; stopUpdateWatch: Function;
const store = useStore(), const store = useStore(),
night = computed(() => getMinecraftTime(store.state.currentWorldState.timeOfDay).night),
layer = new HDMapType({ layer = new HDMapType({
errorTileUrl: 'images/blank.png', errorTileUrl: 'images/blank.png',
mapSettings: Object.freeze(JSON.parse(JSON.stringify(props.map))), mapSettings: Object.freeze(JSON.parse(JSON.stringify(props.map))),
night: night.value,
}), }),
pendingUpdates = computed(() => !!store.state.pendingTileUpdates.length), pendingUpdates = computed(() => !!store.state.pendingTileUpdates.length),
active = computed(() => props.map === store.state.currentMap), active = computed(() => props.map === store.state.currentMap),
@ -86,6 +89,11 @@ export default defineComponent({
}; };
watch(active, (newValue) => newValue ? enableLayer() : disableLayer()); watch(active, (newValue) => newValue ? enableLayer() : disableLayer());
watch(night, (newValue) => {
if(props.map.nightAndDay && active.value) {
layer.setNight(newValue);
}
});
if(active.value) { if(active.value) {
enableLayer(); enableLayer();

View File

@ -24,6 +24,7 @@ import {Coordinate, DynmapWorldMap} from "@/dynmap";
export interface DynmapTileLayerOptions extends TileLayerOptions { export interface DynmapTileLayerOptions extends TileLayerOptions {
mapSettings: DynmapWorldMap; mapSettings: DynmapWorldMap;
errorTileUrl: string; errorTileUrl: string;
night?: boolean;
} }
export interface DynmapTileLayer extends TileLayer { export interface DynmapTileLayer extends TileLayer {
@ -245,7 +246,7 @@ export class DynmapTileLayer extends TileLayer {
return { return {
prefix: this._mapSettings.prefix, prefix: this._mapSettings.prefix,
nightday: /*(this._mapSettings.nightAndDay && this.options.dynmap.serverday) ? '_day' :*/ '', nightday: (this._mapSettings.nightAndDay && !this.options.night) ? '_day' : '',
scaledx: x >> 5, scaledx: x >> 5,
scaledy: y >> 5, scaledy: y >> 5,
zoom: this.zoomprefix(zoomoutlevel), zoom: this.zoomprefix(zoomoutlevel),
@ -259,4 +260,11 @@ export class DynmapTileLayer extends TileLayer {
getProjection(): DynmapProjection { getProjection(): DynmapProjection {
return this._projection; return this._projection;
} }
setNight(night: boolean) {
if(this.options.night !== night) {
this.options.night = night;
this.redraw();
}
}
} }