Refactor DynmapMapProvider.ts
This commit is contained in:
parent
e809f28455
commit
cba4b33e1a
@ -394,7 +394,7 @@ export default class DynmapMapProvider extends MapProvider {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildUpdates(data: Array<any>): DynmapUpdates {
|
private buildUpdates(data: Array<any>) {
|
||||||
const updates = {
|
const updates = {
|
||||||
markerSets: new Map<string, DynmapMarkerSetUpdates>(),
|
markerSets: new Map<string, DynmapMarkerSetUpdates>(),
|
||||||
tiles: [] as DynmapTileUpdate[],
|
tiles: [] as DynmapTileUpdate[],
|
||||||
@ -683,7 +683,7 @@ export default class DynmapMapProvider extends MapProvider {
|
|||||||
useStore().commit(MutationTypes.SET_MARKER_SETS, markerSets);
|
useStore().commit(MutationTypes.SET_MARKER_SETS, markerSets);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUpdate(): Promise<DynmapUpdateResponse> {
|
private async getUpdate(): Promise<void> {
|
||||||
let url = useStore().getters.serverConfig.dynmap.update;
|
let url = useStore().getters.serverConfig.dynmap.update;
|
||||||
url = url.replace('{world}', this.store.state.currentWorld!.name);
|
url = url.replace('{world}', this.store.state.currentWorld!.name);
|
||||||
url = url.replace('{timestamp}', this.updateTimestamp.getTime().toString());
|
url = url.replace('{timestamp}', this.updateTimestamp.getTime().toString());
|
||||||
@ -695,7 +695,13 @@ export default class DynmapMapProvider extends MapProvider {
|
|||||||
this.updateAbort = new AbortController();
|
this.updateAbort = new AbortController();
|
||||||
|
|
||||||
const response = await DynmapMapProvider.fetchJSON(url, this.updateAbort.signal);
|
const response = await DynmapMapProvider.fetchJSON(url, this.updateAbort.signal);
|
||||||
const players: Set<LiveAtlasPlayer> = new Set();
|
const players: Set<LiveAtlasPlayer> = new Set(),
|
||||||
|
updates = this.buildUpdates(response.updates || []),
|
||||||
|
worldState = {
|
||||||
|
timeOfDay: response.servertime || 0,
|
||||||
|
thundering: response.isThundering || false,
|
||||||
|
raining: response.hasStorm || false,
|
||||||
|
};
|
||||||
|
|
||||||
(response.players || []).forEach((player: any) => {
|
(response.players || []).forEach((player: any) => {
|
||||||
const world = player.world && player.world !== '-some-other-bogus-world-' ? player.world : undefined;
|
const world = player.world && player.world !== '-some-other-bogus-world-' ? player.world : undefined;
|
||||||
@ -735,18 +741,15 @@ export default class DynmapMapProvider extends MapProvider {
|
|||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return {
|
this.updateTimestamp = new Date(response.timestamp || 0);
|
||||||
worldState: {
|
|
||||||
timeOfDay: response.servertime || 0,
|
this.store.commit(MutationTypes.SET_WORLD_STATE, worldState);
|
||||||
thundering: response.isThundering || false,
|
this.store.commit(MutationTypes.ADD_MARKER_SET_UPDATES, updates.markerSets);
|
||||||
raining: response.hasStorm || false,
|
this.store.commit(MutationTypes.ADD_TILE_UPDATES, updates.tiles);
|
||||||
},
|
this.store.commit(MutationTypes.ADD_CHAT, updates.chat);
|
||||||
playerCount: response.count || 0,
|
this.store.commit(MutationTypes.SET_SERVER_CONFIGURATION_HASH, response.confighash || 0);
|
||||||
configHash: response.confighash || 0,
|
|
||||||
timestamp: response.timestamp || 0,
|
await this.store.dispatch(ActionTypes.SET_PLAYERS, players);
|
||||||
players,
|
|
||||||
updates: this.buildUpdates(response.updates || []),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sendChatMessage(message: string) {
|
sendChatMessage(message: string) {
|
||||||
@ -794,17 +797,7 @@ export default class DynmapMapProvider extends MapProvider {
|
|||||||
|
|
||||||
private async update() {
|
private async update() {
|
||||||
try {
|
try {
|
||||||
const update = await this.getUpdate();
|
await this.getUpdate();
|
||||||
|
|
||||||
this.updateTimestamp = new Date(update.timestamp);
|
|
||||||
|
|
||||||
this.store.commit(MutationTypes.SET_WORLD_STATE, update.worldState);
|
|
||||||
this.store.commit(MutationTypes.ADD_MARKER_SET_UPDATES, update.updates.markerSets);
|
|
||||||
this.store.commit(MutationTypes.ADD_TILE_UPDATES, update.updates.tiles);
|
|
||||||
this.store.commit(MutationTypes.ADD_CHAT, update.updates.chat);
|
|
||||||
this.store.commit(MutationTypes.SET_SERVER_CONFIGURATION_HASH, update.configHash);
|
|
||||||
|
|
||||||
await this.store.dispatch(ActionTypes.SET_PLAYERS, update.players);
|
|
||||||
} finally {
|
} finally {
|
||||||
if(this.updatesEnabled) {
|
if(this.updatesEnabled) {
|
||||||
if(this.updateTimeout) {
|
if(this.updateTimeout) {
|
||||||
|
Loading…
Reference in New Issue
Block a user