From 8deabad47bb042928a5b1e2db09e784348418488 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Tue, 31 Aug 2021 15:03:02 +0100 Subject: [PATCH] Refactor mutations - Remove some unused mutations - Move CLEAR_PLAYERS into RESET - Clear chat history in RESET --- src/store/mutation-types.ts | 3 --- src/store/mutations.ts | 33 +++++++-------------------------- src/store/state.ts | 2 +- 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/store/mutation-types.ts b/src/store/mutation-types.ts index c626991..418e873 100644 --- a/src/store/mutation-types.ts +++ b/src/store/mutation-types.ts @@ -24,7 +24,6 @@ export enum MutationTypes { SET_WORLDS = 'setWorlds', SET_COMPONENTS = 'setComponents', SET_MARKER_SETS = 'setMarkerSets', - ADD_WORLD = 'addWorld', SET_WORLD_STATE = 'setWorldState', ADD_MARKER_SET_UPDATES = 'addMarkerSetUpdates', ADD_TILE_UPDATES = 'addTileUpdates', @@ -36,7 +35,6 @@ export enum MutationTypes { POP_TILE_UPDATES = 'popTileUpdates', SET_MAX_PLAYERS = 'setMaxPlayers', SET_PLAYERS_ASYNC = 'setPlayersAsync', - CLEAR_PLAYERS = 'clearPlayers', SYNC_PLAYERS = 'syncPlayers', SET_CURRENT_SERVER = 'setCurrentServer', @@ -59,7 +57,6 @@ export enum MutationTypes { HIDE_UI_MODAL = 'hideUIModal', TOGGLE_SIDEBAR_SECTION_COLLAPSED_STATE = 'toggleSidebarSectionCollapsedState', - SET_SIDEBAR_SECTION_COLLAPSED_STATE = 'setSidebarSectionCollapsedState', SET_LOGGED_IN = 'setLoggedIn', RESET = 'reset' diff --git a/src/store/mutations.ts b/src/store/mutations.ts index 2e116b7..41f5bf5 100644 --- a/src/store/mutations.ts +++ b/src/store/mutations.ts @@ -58,7 +58,6 @@ export type Mutations = { [MutationTypes.SET_WORLDS](state: S, worlds: Array): void [MutationTypes.SET_COMPONENTS](state: S, components: LiveAtlasPartialComponentConfig | LiveAtlasComponentConfig): void [MutationTypes.SET_MARKER_SETS](state: S, worlds: Map): void - [MutationTypes.ADD_WORLD](state: S, world: LiveAtlasWorldDefinition): void [MutationTypes.SET_WORLD_STATE](state: S, worldState: LiveAtlasWorldState): void [MutationTypes.ADD_MARKER_SET_UPDATES](state: S, updates: Map): void [MutationTypes.ADD_TILE_UPDATES](state: S, updates: Array): void @@ -73,7 +72,6 @@ export type Mutations = { [MutationTypes.SET_MAX_PLAYERS](state: S, maxPlayers: number): void [MutationTypes.SET_PLAYERS_ASYNC](state: S, players: Set): Set [MutationTypes.SYNC_PLAYERS](state: S, keep: Set): void - [MutationTypes.CLEAR_PLAYERS](state: S): void [MutationTypes.SET_CURRENT_SERVER](state: S, server: string): void [MutationTypes.SET_CURRENT_MAP](state: S, payload: CurrentMapPayload): void [MutationTypes.SET_CURRENT_LOCATION](state: S, payload: Coordinate): void @@ -92,7 +90,6 @@ export type Mutations = { [MutationTypes.HIDE_UI_MODAL](state: S, payload: LiveAtlasUIModal): void [MutationTypes.TOGGLE_SIDEBAR_SECTION_COLLAPSED_STATE](state: S, section: LiveAtlasSidebarSection): void - [MutationTypes.SET_SIDEBAR_SECTION_COLLAPSED_STATE](state: S, payload: {section: LiveAtlasSidebarSection, state: boolean}): void [MutationTypes.SET_LOGGED_IN](state: S, payload: boolean): void [MutationTypes.RESET](state: S): void @@ -255,10 +252,6 @@ export const mutations: MutationTree & Mutations = { } }, - [MutationTypes.ADD_WORLD](state: State, world: LiveAtlasWorldDefinition) { - state.worlds.set(world.name, world); - }, - //Sets the current world state an update fetch [MutationTypes.SET_WORLD_STATE](state: State, worldState: LiveAtlasWorldState) { state.currentWorldState = Object.assign(state.currentWorldState, worldState); @@ -481,14 +474,6 @@ export const mutations: MutationTree & Mutations = { } }, - //Removes all players not found in the provided keep set - [MutationTypes.CLEAR_PLAYERS](state: State) { - state.followTarget = undefined; - state.panTarget = undefined; - state.players.clear(); - state.sortedPlayers.splice(0, state.sortedPlayers.length); - }, - //Sets the currently active server [MutationTypes.SET_CURRENT_SERVER](state: State, serverName) { if(!state.servers.has(serverName)) { @@ -627,20 +612,18 @@ export const mutations: MutationTree & Mutations = { } }, - [MutationTypes.SET_SIDEBAR_SECTION_COLLAPSED_STATE](state: State, payload: {section: LiveAtlasSidebarSection, state: boolean}): void { - if (payload.state) { - state.ui.sidebar.collapsedSections.delete(payload.section); - } else { - state.ui.sidebar.collapsedSections.add(payload.section); - } - }, - [MutationTypes.SET_LOGGED_IN](state: State, payload: boolean): void { state.loggedIn = payload; }, //Cleanup for switching servers or reloading the configuration [MutationTypes.RESET](state: State): void { + state.followTarget = undefined; + state.panTarget = undefined; + + state.players.clear(); + state.sortedPlayers.splice(0, state.sortedPlayers.length); + state.maxPlayers = 0; state.parsedUrl = undefined; state.currentWorld = undefined; @@ -655,9 +638,6 @@ export const mutations: MutationTree & Mutations = { state.currentZoom = 0; state.currentLocation = {x: 0, y: 0, z: 0}; - state.followTarget = undefined; - state.panTarget = undefined; - state.currentWorldState.timeOfDay = 0; state.currentWorldState.raining = false; state.currentWorldState.thundering = false; @@ -677,5 +657,6 @@ export const mutations: MutationTree & Mutations = { state.components.login = false; state.ui.visibleModal = undefined; + state.chat.messages = []; } } diff --git a/src/store/state.ts b/src/store/state.ts index 2d52f8b..b8616c5 100644 --- a/src/store/state.ts +++ b/src/store/state.ts @@ -220,7 +220,7 @@ export const state: State = { //Chat balloons showing messages above player markers chatBalloons: false, - //Login/registering (not currently implemented) + //Login/registering login: false, },