From 7bff12b72943db39da5e8297ce461cbce2f90a48 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Wed, 28 Jul 2021 23:50:59 +0100 Subject: [PATCH] Move maxPlayers to separate field in store, add mutation --- src/App.vue | 1 + src/components/sidebar/PlayerList.vue | 2 +- src/index.d.ts | 1 - src/providers/DynmapMapProvider.ts | 2 +- src/store/mutation-types.ts | 1 + src/store/mutations.ts | 5 +++++ src/store/state.ts | 3 ++- 7 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/App.vue b/src/App.vue index 9995c54..f22bbee 100644 --- a/src/App.vue +++ b/src/App.vue @@ -149,6 +149,7 @@ export default defineComponent({ //Cleanup store.commit(MutationTypes.CLEAR_PLAYERS, undefined); + store.commit(MutationTypes.SET_MAX_PLAYERS, 0); store.commit(MutationTypes.CLEAR_CURRENT_MAP, undefined); store.commit(MutationTypes.CLEAR_PARSED_URL, undefined); store.commit(MutationTypes.CLEAR_WORLDS, undefined); diff --git a/src/components/sidebar/PlayerList.vue b/src/components/sidebar/PlayerList.vue index 3ac6c7c..5399a14 100644 --- a/src/components/sidebar/PlayerList.vue +++ b/src/components/sidebar/PlayerList.vue @@ -69,7 +69,7 @@ export default defineComponent({ return p.name.toLowerCase().indexOf(query) > -1; }) : store.state.sortedPlayers; }), - maxPlayers = computed(() => store.state.configuration.maxPlayers), + maxPlayers = computed(() => store.state.maxPlayers || 0), onKeydown = (e: KeyboardEvent) => { e.stopImmediatePropagation(); diff --git a/src/index.d.ts b/src/index.d.ts index 3b9777d..120bdec 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -243,7 +243,6 @@ interface LiveAtlasServerConfig { followMap?: string; followZoom: number; title: string; - maxPlayers: number; grayHiddenPlayers: boolean; expandUI: boolean; } diff --git a/src/providers/DynmapMapProvider.ts b/src/providers/DynmapMapProvider.ts index 4056e07..b2fe201 100644 --- a/src/providers/DynmapMapProvider.ts +++ b/src/providers/DynmapMapProvider.ts @@ -63,7 +63,6 @@ export default class DynmapMapProvider extends MapProvider { followMap: response.followmap || undefined, followZoom: response.followzoom || 0, title: response.title.replace(titleColoursRegex, '') || 'Dynmap', - maxPlayers: response.maxcount || 0, expandUI: response.sidebaropened && response.sidebaropened !== 'false', //Sent as a string for some reason }; } @@ -641,6 +640,7 @@ export default class DynmapMapProvider extends MapProvider { this.store.commit(MutationTypes.SET_SERVER_CONFIGURATION, config); this.store.commit(MutationTypes.SET_SERVER_CONFIGURATION_HASH, response.confighash || 0); + this.store.commit(MutationTypes.SET_MAX_PLAYERS, response.maxcount || 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)); diff --git a/src/store/mutation-types.ts b/src/store/mutation-types.ts index f0f2514..2740d6c 100644 --- a/src/store/mutation-types.ts +++ b/src/store/mutation-types.ts @@ -36,6 +36,7 @@ export enum MutationTypes { POP_CIRCLE_UPDATES = 'popCircleUpdates', POP_LINE_UPDATES = 'popLineUpdates', POP_TILE_UPDATES = 'popTileUpdates', + SET_MAX_PLAYERS = 'setMaxPlayers', SET_PLAYERS_ASYNC = 'setPlayersAsync', CLEAR_PLAYERS = 'clearPlayers', SYNC_PLAYERS = 'syncPlayers', diff --git a/src/store/mutations.ts b/src/store/mutations.ts index 5f88492..1e1fca2 100644 --- a/src/store/mutations.ts +++ b/src/store/mutations.ts @@ -71,6 +71,7 @@ export type Mutations = { [MutationTypes.POP_LINE_UPDATES](state: S, payload: {markerSet: string, amount: number}): void [MutationTypes.POP_TILE_UPDATES](state: S, amount: number): void + [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 @@ -407,6 +408,10 @@ export const mutations: MutationTree & Mutations = { state.pendingTileUpdates.splice(0, amount); }, + [MutationTypes.SET_MAX_PLAYERS](state: State, maxPlayers: number) { + state.maxPlayers = maxPlayers; + }, + // Set up to 10 players at once [MutationTypes.SET_PLAYERS_ASYNC](state: State, players: Set): Set { let count = 0; diff --git a/src/store/state.ts b/src/store/state.ts index bc32ddf..d519f96 100644 --- a/src/store/state.ts +++ b/src/store/state.ts @@ -50,6 +50,7 @@ export type State = { maps: Map; players: Map; sortedPlayers: LiveAtlasSortedPlayers; + maxPlayers: number; markerSets: Map; chat: { @@ -98,7 +99,6 @@ export const state: State = { followMap: '', followZoom: 0, title: '', - maxPlayers: 0, grayHiddenPlayers: false, expandUI: false, }, @@ -153,6 +153,7 @@ export const state: State = { maps: new Map(), //Defined maps from configuration.json players: new Map(), //Online players from world.json sortedPlayers: [] as LiveAtlasSortedPlayers, //Online players from world.json, sorted by their sort property then alphabetically + maxPlayers: 0, chat: { unread: 0,