From a623179039c0b675eb132b7fec6ca3117109de90 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Sun, 13 Jun 2021 00:52:56 +0100 Subject: [PATCH] Respect dynmap append_to_world setting (Fixes #28) --- src/api.ts | 49 ++++++++++++++---------- src/components/sidebar/WorldListItem.vue | 2 +- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/api.ts b/src/api.ts index 32e1148..54ae88b 100644 --- a/src/api.ts +++ b/src/api.ts @@ -104,14 +104,37 @@ function buildMessagesConfig(response: any): LiveAtlasMessageConfig { } function buildWorlds(response: any): Array { - const worlds: Array = []; + const worlds: Map = new Map(); + + //Get all the worlds first so we can handle append_to_world properly + (response.worlds || []).forEach((world: any) => { + worlds.set(world.name, { + seaLevel: world.sealevel || 64, + name: world.name, + protected: world.protected || false, + title: world.title || '', + height: world.height || 256, + center: { + x: world.center.x || 0, + y: world.center.y || 0, + z: world.center.z || 0 + }, + maps: new Map(), + }); + }); (response.worlds || []).forEach((world: any) => { - const maps: Map = new Map(); - (world.maps || []).forEach((map: any) => { - maps.set(map.name, { - world: world, + const worldName = map.append_to_world || world.name, + w = worlds.get(worldName); + + if(!w) { + console.warn(`Ignoring map '${map.name}' associated with non-existent world '${worldName}'`); + return; + } + + w.maps.set(map.name, { + world: world, //Ignore append_to_world here otherwise things break background: map.background || '#000000', backgroundDay: map.backgroundday || '#000000', backgroundNight: map.backgroundnight || '#000000', @@ -128,23 +151,9 @@ function buildWorlds(response: any): Array { extraZoomLevels: map.mapzoomin || 0, }); }); - - worlds.push({ - seaLevel: world.sealevel || 64, - name: world.name || '(Unnamed world)', - protected: world.protected || false, - title: world.title || '', - height: world.height || 256, - center: { - x: world.center.x || 0, - y: world.center.y || 0, - z: world.center.z || 0 - }, - maps, - }); }); - return worlds; + return Array.from(worlds.values()); } function buildComponents(response: any): DynmapComponentConfig { diff --git a/src/components/sidebar/WorldListItem.vue b/src/components/sidebar/WorldListItem.vue index 78238f8..0e932a7 100644 --- a/src/components/sidebar/WorldListItem.vue +++ b/src/components/sidebar/WorldListItem.vue @@ -66,7 +66,7 @@ export default defineComponent({ currentMap: { get() { const store = useStore(); - return store.state.currentMap ? [store.state.currentMap.world.name, store.state.currentMap.name] : undefined; + return store.state.currentMap ? [store.state.currentWorld.name, store.state.currentMap.name] : undefined; }, set(value: string[]) { useStore().commit(MutationTypes.SET_CURRENT_MAP, {worldName: value[0], mapName: value[1]});