Refactor mutations

- Remove some unused mutations
- Move CLEAR_PLAYERS into RESET
- Clear chat history in RESET
This commit is contained in:
James Lyne 2021-08-31 15:03:02 +01:00
parent 9fd53d754e
commit 8deabad47b
3 changed files with 8 additions and 30 deletions

View File

@ -24,7 +24,6 @@ export enum MutationTypes {
SET_WORLDS = 'setWorlds', SET_WORLDS = 'setWorlds',
SET_COMPONENTS = 'setComponents', SET_COMPONENTS = 'setComponents',
SET_MARKER_SETS = 'setMarkerSets', SET_MARKER_SETS = 'setMarkerSets',
ADD_WORLD = 'addWorld',
SET_WORLD_STATE = 'setWorldState', SET_WORLD_STATE = 'setWorldState',
ADD_MARKER_SET_UPDATES = 'addMarkerSetUpdates', ADD_MARKER_SET_UPDATES = 'addMarkerSetUpdates',
ADD_TILE_UPDATES = 'addTileUpdates', ADD_TILE_UPDATES = 'addTileUpdates',
@ -36,7 +35,6 @@ export enum MutationTypes {
POP_TILE_UPDATES = 'popTileUpdates', POP_TILE_UPDATES = 'popTileUpdates',
SET_MAX_PLAYERS = 'setMaxPlayers', SET_MAX_PLAYERS = 'setMaxPlayers',
SET_PLAYERS_ASYNC = 'setPlayersAsync', SET_PLAYERS_ASYNC = 'setPlayersAsync',
CLEAR_PLAYERS = 'clearPlayers',
SYNC_PLAYERS = 'syncPlayers', SYNC_PLAYERS = 'syncPlayers',
SET_CURRENT_SERVER = 'setCurrentServer', SET_CURRENT_SERVER = 'setCurrentServer',
@ -59,7 +57,6 @@ export enum MutationTypes {
HIDE_UI_MODAL = 'hideUIModal', HIDE_UI_MODAL = 'hideUIModal',
TOGGLE_SIDEBAR_SECTION_COLLAPSED_STATE = 'toggleSidebarSectionCollapsedState', TOGGLE_SIDEBAR_SECTION_COLLAPSED_STATE = 'toggleSidebarSectionCollapsedState',
SET_SIDEBAR_SECTION_COLLAPSED_STATE = 'setSidebarSectionCollapsedState',
SET_LOGGED_IN = 'setLoggedIn', SET_LOGGED_IN = 'setLoggedIn',
RESET = 'reset' RESET = 'reset'

View File

@ -58,7 +58,6 @@ export type Mutations<S = State> = {
[MutationTypes.SET_WORLDS](state: S, worlds: Array<LiveAtlasWorldDefinition>): void [MutationTypes.SET_WORLDS](state: S, worlds: Array<LiveAtlasWorldDefinition>): void
[MutationTypes.SET_COMPONENTS](state: S, components: LiveAtlasPartialComponentConfig | 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.ADD_WORLD](state: S, world: LiveAtlasWorldDefinition): void
[MutationTypes.SET_WORLD_STATE](state: S, worldState: LiveAtlasWorldState): void [MutationTypes.SET_WORLD_STATE](state: S, worldState: LiveAtlasWorldState): void
[MutationTypes.ADD_MARKER_SET_UPDATES](state: S, updates: Map<string, DynmapMarkerSetUpdates>): void [MutationTypes.ADD_MARKER_SET_UPDATES](state: S, updates: Map<string, DynmapMarkerSetUpdates>): void
[MutationTypes.ADD_TILE_UPDATES](state: S, updates: Array<DynmapTileUpdate>): void [MutationTypes.ADD_TILE_UPDATES](state: S, updates: Array<DynmapTileUpdate>): void
@ -73,7 +72,6 @@ export type Mutations<S = State> = {
[MutationTypes.SET_MAX_PLAYERS](state: S, maxPlayers: number): void [MutationTypes.SET_MAX_PLAYERS](state: S, maxPlayers: number): void
[MutationTypes.SET_PLAYERS_ASYNC](state: S, players: Set<LiveAtlasPlayer>): Set<LiveAtlasPlayer> [MutationTypes.SET_PLAYERS_ASYNC](state: S, players: Set<LiveAtlasPlayer>): Set<LiveAtlasPlayer>
[MutationTypes.SYNC_PLAYERS](state: S, keep: Set<string>): void [MutationTypes.SYNC_PLAYERS](state: S, keep: Set<string>): void
[MutationTypes.CLEAR_PLAYERS](state: S): void
[MutationTypes.SET_CURRENT_SERVER](state: S, server: string): void [MutationTypes.SET_CURRENT_SERVER](state: S, server: string): void
[MutationTypes.SET_CURRENT_MAP](state: S, payload: CurrentMapPayload): void [MutationTypes.SET_CURRENT_MAP](state: S, payload: CurrentMapPayload): void
[MutationTypes.SET_CURRENT_LOCATION](state: S, payload: Coordinate): void [MutationTypes.SET_CURRENT_LOCATION](state: S, payload: Coordinate): void
@ -92,7 +90,6 @@ export type Mutations<S = State> = {
[MutationTypes.HIDE_UI_MODAL](state: S, payload: LiveAtlasUIModal): void [MutationTypes.HIDE_UI_MODAL](state: S, payload: LiveAtlasUIModal): void
[MutationTypes.TOGGLE_SIDEBAR_SECTION_COLLAPSED_STATE](state: S, section: LiveAtlasSidebarSection): 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.SET_LOGGED_IN](state: S, payload: boolean): void
[MutationTypes.RESET](state: S): void [MutationTypes.RESET](state: S): void
@ -255,10 +252,6 @@ export const mutations: MutationTree<State> & Mutations = {
} }
}, },
[MutationTypes.ADD_WORLD](state: State, world: LiveAtlasWorldDefinition) {
state.worlds.set(world.name, world);
},
//Sets the current world state an update fetch //Sets the current world state an update fetch
[MutationTypes.SET_WORLD_STATE](state: State, worldState: LiveAtlasWorldState) { [MutationTypes.SET_WORLD_STATE](state: State, worldState: LiveAtlasWorldState) {
state.currentWorldState = Object.assign(state.currentWorldState, worldState); state.currentWorldState = Object.assign(state.currentWorldState, worldState);
@ -481,14 +474,6 @@ export const mutations: MutationTree<State> & 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 //Sets the currently active server
[MutationTypes.SET_CURRENT_SERVER](state: State, serverName) { [MutationTypes.SET_CURRENT_SERVER](state: State, serverName) {
if(!state.servers.has(serverName)) { if(!state.servers.has(serverName)) {
@ -627,20 +612,18 @@ export const mutations: MutationTree<State> & 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 { [MutationTypes.SET_LOGGED_IN](state: State, payload: boolean): void {
state.loggedIn = payload; state.loggedIn = payload;
}, },
//Cleanup for switching servers or reloading the configuration //Cleanup for switching servers or reloading the configuration
[MutationTypes.RESET](state: State): void { [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.maxPlayers = 0;
state.parsedUrl = undefined; state.parsedUrl = undefined;
state.currentWorld = undefined; state.currentWorld = undefined;
@ -655,9 +638,6 @@ export const mutations: MutationTree<State> & Mutations = {
state.currentZoom = 0; state.currentZoom = 0;
state.currentLocation = {x: 0, y: 0, z: 0}; state.currentLocation = {x: 0, y: 0, z: 0};
state.followTarget = undefined;
state.panTarget = undefined;
state.currentWorldState.timeOfDay = 0; state.currentWorldState.timeOfDay = 0;
state.currentWorldState.raining = false; state.currentWorldState.raining = false;
state.currentWorldState.thundering = false; state.currentWorldState.thundering = false;
@ -677,5 +657,6 @@ export const mutations: MutationTree<State> & Mutations = {
state.components.login = false; state.components.login = false;
state.ui.visibleModal = undefined; state.ui.visibleModal = undefined;
state.chat.messages = [];
} }
} }

View File

@ -220,7 +220,7 @@ export const state: State = {
//Chat balloons showing messages above player markers //Chat balloons showing messages above player markers
chatBalloons: false, chatBalloons: false,
//Login/registering (not currently implemented) //Login/registering
login: false, login: false,
}, },