Allow partial updates of component settings

This commit is contained in:
James Lyne 2021-07-28 22:16:26 +01:00
parent d04226e3ec
commit 110c75f9a3
2 changed files with 22 additions and 5 deletions

16
src/index.d.ts vendored
View File

@ -264,6 +264,22 @@ interface LiveAtlasComponentConfig {
login: boolean; login: boolean;
} }
interface LiveAtlasPartialComponentConfig {
markers?: {
showLabels: boolean;
};
playerMarkers?: LiveAtlasPlayerMarkerConfig;
coordinatesControl?: CoordinatesControlOptions;
clockControl?: ClockControlOptions;
linkControl?: boolean;
layerControl?: boolean;
logoControls?: Array<LogoControlOptions>;
chatBox?: LiveAtlasChatBoxConfig;
chatSending?: LiveAtlasChatSendingConfig;
chatBalloons?: boolean;
login?: boolean;
}
interface LiveAtlasPlayerMarkerConfig { interface LiveAtlasPlayerMarkerConfig {
hideByDefault: boolean; hideByDefault: boolean;
layerName: string; layerName: string;

View File

@ -39,8 +39,7 @@ import {
LiveAtlasMarker, LiveAtlasMarker,
LiveAtlasMarkerSet, LiveAtlasMarkerSet,
LiveAtlasServerDefinition, LiveAtlasServerDefinition,
LiveAtlasComponentConfig, LiveAtlasServerConfig, LiveAtlasChat, LiveAtlasPartialComponentConfig, LiveAtlasComponentConfig
LiveAtlasServerConfig, LiveAtlasChat
} from "@/index"; } from "@/index";
import DynmapMapProvider from "@/providers/DynmapMapProvider"; import DynmapMapProvider from "@/providers/DynmapMapProvider";
@ -57,7 +56,7 @@ export type Mutations<S = State> = {
[MutationTypes.SET_SERVER_MESSAGES](state: S, messages: LiveAtlasServerMessageConfig): void [MutationTypes.SET_SERVER_MESSAGES](state: S, messages: LiveAtlasServerMessageConfig): void
[MutationTypes.SET_WORLDS](state: S, worlds: Array<LiveAtlasWorldDefinition>): void [MutationTypes.SET_WORLDS](state: S, worlds: Array<LiveAtlasWorldDefinition>): void
[MutationTypes.CLEAR_WORLDS](state: S): 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<string, LiveAtlasMarkerSet>): void [MutationTypes.SET_MARKER_SETS](state: S, worlds: Map<string, LiveAtlasMarkerSet>): void
[MutationTypes.CLEAR_MARKER_SETS](state: S): void [MutationTypes.CLEAR_MARKER_SETS](state: S): void
[MutationTypes.ADD_WORLD](state: S, world: LiveAtlasWorldDefinition): void [MutationTypes.ADD_WORLD](state: S, world: LiveAtlasWorldDefinition): void
@ -222,8 +221,10 @@ export const mutations: MutationTree<State> & Mutations = {
state.currentWorldState.thundering = false; state.currentWorldState.thundering = false;
}, },
//Sets the state and settings of optional components, from the initial config fetch //Updates the state of optional components (chat, link button, etc)
[MutationTypes.SET_COMPONENTS](state: State, components: LiveAtlasComponentConfig) { //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); state.components = Object.assign(state.components, components);
}, },