Improve server switch process

This commit is contained in:
James Lyne 2021-05-17 20:28:33 +01:00
parent 97fed3fed2
commit f3913ef96b
6 changed files with 18 additions and 45 deletions

View File

@ -54,7 +54,7 @@ export default defineComponent({
loadConfiguration = () => {
return store.dispatch(ActionTypes.LOAD_CONFIGURATION, undefined).then(() => {
startUpdates();
window.hideSplash();
requestAnimationFrame(window.hideSplash);
}).catch(e => {
console.error('Failed to load server configuration: ', e);
window.showSplashError(e, false, ++configAttempts.value);
@ -117,7 +117,6 @@ export default defineComponent({
stopUpdates();
window.history.replaceState({}, '', newServer);
store.commit(MutationTypes.CLEAR_PARSED_URL, undefined);
store.commit(MutationTypes.CLEAR_CURRENT_ZOOM, undefined);
loadConfiguration();
});

View File

@ -226,7 +226,7 @@ export default defineComponent({
this.updateChatBalloon();
},
currentWorld(newValue) {
if(newValue.name === this.player.location.world) {
if(newValue && newValue.name === this.player.location.world) {
this.enableLayer();
} else if(this.markerVisible) {
this.disableLayer();

View File

@ -41,9 +41,7 @@ window.showSplash = function() {
splash.hidden = false;
requestAnimationFrame(function() {
if(splash) {
splash.style.opacity = '1';
}
splash.style.opacity = '1';
});
};
@ -100,8 +98,6 @@ API.validateConfiguration().then((config) => {
store.commit(MutationTypes.SET_CURRENT_SERVER, config.keys().next().value);
}
console.log(store.state.currentServer);
const app = createApp(App).use(store);
// app.config.performance = true;

View File

@ -78,11 +78,11 @@ export interface Actions {
export const actions: ActionTree<State, State> & Actions = {
[ActionTypes.LOAD_CONFIGURATION]({commit, state}): Promise<DynmapConfigurationResponse> {
commit(MutationTypes.CLEAR_MARKER_SETS, undefined);
//Cleanup in case we are switching servers
commit(MutationTypes.CLEAR_PLAYERS, undefined);
commit(MutationTypes.CLEAR_CURRENT_MAP, undefined);
return API.getConfiguration().then(config => {
commit(MutationTypes.CLEAR_WORLDS, undefined);
commit(MutationTypes.SET_CONFIGURATION, config.config);
commit(MutationTypes.SET_MESSAGES, config.messages);
commit(MutationTypes.SET_WORLDS, config.worlds);

View File

@ -21,9 +21,7 @@ export enum MutationTypes {
SET_WORLDS = 'setWorlds',
SET_COMPONENTS = 'setComponents',
SET_MARKER_SETS = 'setMarkerSets',
CLEAR_MARKER_SETS = 'clearMarkerSets',
ADD_WORLD = 'addWorld',
CLEAR_WORLDS = 'clearWorlds',
SET_WORLD_STATE = 'setWorldState',
SET_UPDATE_TIMESTAMP = 'setUpdateTimestamp',
ADD_MARKER_SET_UPDATES = 'addMarkerSetUpdates',
@ -44,9 +42,9 @@ export enum MutationTypes {
SET_CURRENT_PROJECTION = 'setCurrentProjection',
SET_CURRENT_LOCATION = 'setCurrentLocation',
SET_CURRENT_ZOOM = 'setCurrentZoom',
CLEAR_CURRENT_ZOOM = 'clearCurrentZoom',
SET_PARSED_URL = 'setParsedUrl',
CLEAR_PARSED_URL = 'clearParsedUrl',
CLEAR_CURRENT_MAP = 'clearCurrentMap',
SET_FOLLOW_TARGET = 'setFollowTarget',
SET_PAN_TARGET = 'setPanTarget',

View File

@ -46,9 +46,7 @@ export type Mutations<S = State> = {
[MutationTypes.SET_WORLDS](state: S, worlds: Array<DynmapWorld>): void
[MutationTypes.SET_COMPONENTS](state: S, worlds: DynmapComponentConfig): void
[MutationTypes.SET_MARKER_SETS](state: S, worlds: Map<string, DynmapMarkerSet>): void
[MutationTypes.CLEAR_MARKER_SETS](state: S): void
[MutationTypes.ADD_WORLD](state: S, world: DynmapWorld): void
[MutationTypes.CLEAR_WORLDS](state: S): void
[MutationTypes.SET_WORLD_STATE](state: S, worldState: DynmapWorldState): void
[MutationTypes.SET_UPDATE_TIMESTAMP](state: S, time: Date): void
[MutationTypes.ADD_MARKER_SET_UPDATES](state: S, updates: Map<string, DynmapMarkerSetUpdates>): void
@ -70,9 +68,9 @@ export type Mutations<S = State> = {
[MutationTypes.SET_CURRENT_PROJECTION](state: S, payload: DynmapProjection): void
[MutationTypes.SET_CURRENT_LOCATION](state: S, payload: Coordinate): void
[MutationTypes.SET_CURRENT_ZOOM](state: S, payload: number): void
[MutationTypes.CLEAR_CURRENT_ZOOM](state: S): void
[MutationTypes.SET_PARSED_URL](state: S, payload: DynmapParsedUrl): void
[MutationTypes.CLEAR_PARSED_URL](state: S): void
[MutationTypes.CLEAR_CURRENT_MAP](state: S): void
[MutationTypes.SET_FOLLOW_TARGET](state: S, payload: DynmapPlayer): void
[MutationTypes.SET_PAN_TARGET](state: S, payload: DynmapPlayer): void
[MutationTypes.CLEAR_FOLLOW_TARGET](state: S, a?: void): void
@ -145,31 +143,10 @@ export const mutations: MutationTree<State> & Mutations = {
}
},
//Sets the existing marker sets from the last marker fetch
[MutationTypes.CLEAR_MARKER_SETS](state: State) {
state.markerSets.clear();
state.pendingSetUpdates.clear();
},
[MutationTypes.ADD_WORLD](state: State, world: DynmapWorld) {
state.worlds.set(world.name, world);
},
[MutationTypes.CLEAR_WORLDS](state: State) {
console.log('??????');
state.worlds.clear();
state.maps.clear();
state.currentMap = undefined;
state.currentWorld = undefined;
state.followTarget = undefined;
state.panTarget = undefined;
state.currentWorldState.timeOfDay = 0;
state.currentWorldState.raining = false;
state.currentWorldState.thundering = false;
},
//Sets the current world state an update fetch
[MutationTypes.SET_WORLD_STATE](state: State, worldState: DynmapWorldState) {
state.currentWorldState = Object.assign(state.currentWorldState, worldState);
@ -383,10 +360,7 @@ export const mutations: MutationTree<State> & Mutations = {
[MutationTypes.CLEAR_PLAYERS](state: State) {
state.followTarget = undefined;
state.panTarget = undefined;
for(const [key, player] of state.players) {
state.players.delete(key);
}
state.players.clear();
},
//Sets the currently active server
@ -437,15 +411,21 @@ export const mutations: MutationTree<State> & Mutations = {
state.currentZoom = payload;
},
[MutationTypes.CLEAR_CURRENT_ZOOM](state: State) {
state.currentZoom = 0;
},
//Sets the result of parsing the current map url, if present and valid
[MutationTypes.SET_PARSED_URL](state: State, payload: DynmapParsedUrl) {
state.parsedUrl = payload;
},
//Clear the current map/world
[MutationTypes.CLEAR_CURRENT_MAP](state: State) {
state.markerSets.clear();
state.pendingSetUpdates.clear();
state.pendingTileUpdates = [];
state.currentWorld = undefined;
state.currentMap = undefined;
},
//Clear any existing parsed url
[MutationTypes.CLEAR_PARSED_URL](state: State) {
state.parsedUrl = {