From 110c75f9a33c1a63d477cd4ca6fd9cf702132377 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Wed, 28 Jul 2021 22:16:26 +0100 Subject: [PATCH] Allow partial updates of component settings --- src/index.d.ts | 16 ++++++++++++++++ src/store/mutations.ts | 11 ++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index 8edcc45..3b9777d 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -264,6 +264,22 @@ interface LiveAtlasComponentConfig { login: boolean; } +interface LiveAtlasPartialComponentConfig { + markers?: { + showLabels: boolean; + }; + playerMarkers?: LiveAtlasPlayerMarkerConfig; + coordinatesControl?: CoordinatesControlOptions; + clockControl?: ClockControlOptions; + linkControl?: boolean; + layerControl?: boolean; + logoControls?: Array; + chatBox?: LiveAtlasChatBoxConfig; + chatSending?: LiveAtlasChatSendingConfig; + chatBalloons?: boolean; + login?: boolean; +} + interface LiveAtlasPlayerMarkerConfig { hideByDefault: boolean; layerName: string; diff --git a/src/store/mutations.ts b/src/store/mutations.ts index e99f411..e6cf181 100644 --- a/src/store/mutations.ts +++ b/src/store/mutations.ts @@ -39,8 +39,7 @@ import { LiveAtlasMarker, LiveAtlasMarkerSet, LiveAtlasServerDefinition, - LiveAtlasComponentConfig, - LiveAtlasServerConfig, LiveAtlasChat + LiveAtlasServerConfig, LiveAtlasChat, LiveAtlasPartialComponentConfig, LiveAtlasComponentConfig } from "@/index"; import DynmapMapProvider from "@/providers/DynmapMapProvider"; @@ -57,7 +56,7 @@ export type Mutations = { [MutationTypes.SET_SERVER_MESSAGES](state: S, messages: LiveAtlasServerMessageConfig): void [MutationTypes.SET_WORLDS](state: S, worlds: Array): void [MutationTypes.CLEAR_WORLDS](state: S): void - [MutationTypes.SET_COMPONENTS](state: S, worlds: LiveAtlasComponentConfig): void + [MutationTypes.SET_COMPONENTS](state: S, components: LiveAtlasPartialComponentConfig | LiveAtlasComponentConfig): void [MutationTypes.SET_MARKER_SETS](state: S, worlds: Map): void [MutationTypes.CLEAR_MARKER_SETS](state: S): void [MutationTypes.ADD_WORLD](state: S, world: LiveAtlasWorldDefinition): void @@ -222,8 +221,10 @@ export const mutations: MutationTree & Mutations = { state.currentWorldState.thundering = false; }, - //Sets the state and settings of optional components, from the initial config fetch - [MutationTypes.SET_COMPONENTS](state: State, components: LiveAtlasComponentConfig) { + //Updates the state of optional components (chat, link button, etc) + //Can be called with a LiveAtlasComponentConfig object to replace the whole state + //or a LiveAtlasPartialComponentConfig object for partial updates to the existing state + [MutationTypes.SET_COMPONENTS](state: State, components: LiveAtlasPartialComponentConfig | LiveAtlasComponentConfig) { state.components = Object.assign(state.components, components); },