From e809f284558e4bb24588c453e2cb70320380ee54 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Sat, 24 Jul 2021 04:03:36 +0100 Subject: [PATCH] (Re)move some config store properties --- src/dynmap.d.ts | 4 +--- src/leaflet/layer/LayerManager.ts | 2 +- src/providers/DynmapMapProvider.ts | 18 ++++++++---------- src/store/mutations.ts | 1 - src/store/state.ts | 6 +++--- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/dynmap.d.ts b/src/dynmap.d.ts index 4eccf09..7d31d6e 100644 --- a/src/dynmap.d.ts +++ b/src/dynmap.d.ts @@ -44,19 +44,16 @@ type DynmapUrlConfig = { } interface DynmapServerConfig { - version: string; defaultMap?: string; defaultWorld?: string; defaultZoom: number; followMap?: string; followZoom: number; - showLayerControl: boolean; title: string; loginEnabled: boolean; maxPlayers: number; grayHiddenPlayers: boolean; expandUI: boolean; - hash: number; } interface DynmapComponentConfig { @@ -65,6 +62,7 @@ interface DynmapComponentConfig { coordinatesControl?: CoordinatesControlOptions; clockControl ?: ClockControlOptions; linkControl: boolean; + layerControl: boolean; logoControls: Array; chatBox?: DynmapChatBoxConfig; chatSending?: DynmapChatSendingConfig; diff --git a/src/leaflet/layer/LayerManager.ts b/src/leaflet/layer/LayerManager.ts index 2e729a5..d383080 100644 --- a/src/leaflet/layer/LayerManager.ts +++ b/src/leaflet/layer/LayerManager.ts @@ -25,7 +25,7 @@ export default class LayerManager { private readonly map: Map; constructor(map: Map) { - const showControl = computed(() => useStore().state.configuration.showLayerControl); + const showControl = computed(() => useStore().state.components.layerControl); this.map = map; this.layerControl = new LiveAtlasLayerControl({}, {},{ position: 'topleft', diff --git a/src/providers/DynmapMapProvider.ts b/src/providers/DynmapMapProvider.ts index 9bb7f61..7488805 100644 --- a/src/providers/DynmapMapProvider.ts +++ b/src/providers/DynmapMapProvider.ts @@ -52,19 +52,16 @@ export default class DynmapMapProvider extends MapProvider { private static buildServerConfig(response: any): DynmapServerConfig { return { - version: response.dynmapversion || '', grayHiddenPlayers: response.grayplayerswhenhidden || false, defaultMap: response.defaultmap || undefined, defaultWorld: response.defaultworld || undefined, defaultZoom: response.defaultzoom || 0, followMap: response.followmap || undefined, followZoom: response.followzoom || 0, - showLayerControl: response.showlayercontrol && response.showlayercontrol !== 'false', //Sent as a string for some reason title: response.title.replace(titleColoursRegex, '') || 'Dynmap', loginEnabled: response['login-enabled'] || false, maxPlayers: response.maxcount || 0, expandUI: response.sidebaropened && response.sidebaropened !== 'false', //Sent as a string for some reason - hash: response.confighash || 0, }; } @@ -153,6 +150,7 @@ export default class DynmapMapProvider extends MapProvider { chatBalloons: false, playerMarkers: undefined, coordinatesControl: undefined, + layerControl: response.showlayercontrol && response.showlayercontrol !== 'false', //Sent as a string for some reason linkControl: false, clockControl: undefined, logoControls: [], @@ -667,16 +665,16 @@ export default class DynmapMapProvider extends MapProvider { throw new Error(response.error); } - const store = useStore(), - config = DynmapMapProvider.buildServerConfig(response); + const config = DynmapMapProvider.buildServerConfig(response); this.updateInterval = response.updaterate || 3000; - store.commit(MutationTypes.SET_SERVER_CONFIGURATION, config); - store.commit(MutationTypes.SET_SERVER_MESSAGES, DynmapMapProvider.buildMessagesConfig(response)); - store.commit(MutationTypes.SET_WORLDS, this.buildWorlds(response)); - store.commit(MutationTypes.SET_COMPONENTS, this.buildComponents(response)); - store.commit(MutationTypes.SET_LOGGED_IN, response.loggedin || false); + this.store.commit(MutationTypes.SET_SERVER_CONFIGURATION, config); + this.store.commit(MutationTypes.SET_SERVER_CONFIGURATION_HASH, response.confighash || 0); + this.store.commit(MutationTypes.SET_SERVER_MESSAGES, DynmapMapProvider.buildMessagesConfig(response)); + this.store.commit(MutationTypes.SET_WORLDS, this.buildWorlds(response)); + this.store.commit(MutationTypes.SET_COMPONENTS, this.buildComponents(response)); + this.store.commit(MutationTypes.SET_LOGGED_IN, response.loggedin || false); } async loadWorldConfiguration(): Promise { diff --git a/src/store/mutations.ts b/src/store/mutations.ts index 177e0bb..8c48b6d 100644 --- a/src/store/mutations.ts +++ b/src/store/mutations.ts @@ -158,7 +158,6 @@ export const mutations: MutationTree & Mutations = { // Sets configuration options from the initial config fetch [MutationTypes.SET_SERVER_CONFIGURATION](state: State, config: DynmapServerConfig) { state.configuration = Object.assign(state.configuration, config); - state.configurationHash = config.hash; }, // Sets configuration hash diff --git a/src/store/state.ts b/src/store/state.ts index 70ab1c5..08318dc 100644 --- a/src/store/state.ts +++ b/src/store/state.ts @@ -88,19 +88,16 @@ export const state: State = { servers: new Map(), configuration: { - version: '', defaultMap: '', defaultWorld: '', defaultZoom: 0, followMap: '', followZoom: 0, - showLayerControl: false, title: '', loginEnabled: false, maxPlayers: 0, grayHiddenPlayers: false, expandUI: false, - hash: 0, }, configurationHash: undefined, @@ -183,6 +180,9 @@ export const state: State = { //Optional "link" component. Adds button to copy url for current position linkControl: false, + //Layers control + layerControl: false, + //Optional "logo" controls. logoControls: [],