Move maxPlayers to separate field in store, add mutation

This commit is contained in:
James Lyne 2021-07-28 23:50:59 +01:00
parent 4feb46c641
commit 7bff12b729
7 changed files with 11 additions and 4 deletions

View File

@ -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);

View File

@ -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();

1
src/index.d.ts vendored
View File

@ -243,7 +243,6 @@ interface LiveAtlasServerConfig {
followMap?: string;
followZoom: number;
title: string;
maxPlayers: number;
grayHiddenPlayers: boolean;
expandUI: boolean;
}

View File

@ -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));

View File

@ -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',

View File

@ -71,6 +71,7 @@ export type Mutations<S = State> = {
[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<LiveAtlasPlayer>): Set<LiveAtlasPlayer>
[MutationTypes.SYNC_PLAYERS](state: S, keep: Set<string>): void
[MutationTypes.CLEAR_PLAYERS](state: S): void
@ -407,6 +408,10 @@ export const mutations: MutationTree<State> & 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<LiveAtlasPlayer>): Set<LiveAtlasPlayer> {
let count = 0;

View File

@ -50,6 +50,7 @@ export type State = {
maps: Map<string, LiveAtlasMapDefinition>;
players: Map<string, LiveAtlasPlayer>;
sortedPlayers: LiveAtlasSortedPlayers;
maxPlayers: number;
markerSets: Map<string, LiveAtlasMarkerSet>;
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,