From e1b39c42ec04561ef1b05cb488cc1a7c794f5dcd Mon Sep 17 00:00:00 2001
From: Dennis Postma <dennis@directonline.io>
Date: Tue, 5 Nov 2024 21:28:12 +0100
Subject: [PATCH] Several map editor improvements

---
 src/components/gameMaster/GmPanel.vue              |  1 -
 .../gameMaster/zoneEditor/ZoneEditor.vue           |  3 ++-
 .../gameMaster/zoneEditor/partials/TileList.vue    |  2 +-
 .../zoneEditor/zonePartials/ZoneTiles.vue          | 14 +++++++++++++-
 src/components/gui/Clock.vue                       |  2 +-
 src/stores/zoneEditorStore.ts                      |  2 ++
 6 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/components/gameMaster/GmPanel.vue b/src/components/gameMaster/GmPanel.vue
index 4f16ea4..d0a8690 100644
--- a/src/components/gameMaster/GmPanel.vue
+++ b/src/components/gameMaster/GmPanel.vue
@@ -7,7 +7,6 @@
         <button @mousedown.stop class="btn-cyan py-1.5 px-4 min-w-24">Chats</button>
         <button @mousedown.stop class="btn-cyan active py-1.5 px-4 min-w-24">Asset manager</button>
         <button class="btn-cyan py-1.5 px-4 min-w-24" type="button" @click="() => zoneEditorStore.toggleActive()">Zone manager</button>
-
       </div>
     </template>
     <template #modalBody>
diff --git a/src/components/gameMaster/zoneEditor/ZoneEditor.vue b/src/components/gameMaster/zoneEditor/ZoneEditor.vue
index cbefc96..bc0a925 100644
--- a/src/components/gameMaster/zoneEditor/ZoneEditor.vue
+++ b/src/components/gameMaster/zoneEditor/ZoneEditor.vue
@@ -18,7 +18,6 @@ import { onUnmounted, ref } from 'vue'
 import { useGameStore } from '@/stores/gameStore'
 import { useZoneEditorStore } from '@/stores/zoneEditorStore'
 import { type Zone } from '@/types'
-
 // Components
 import Toolbar from '@/components/gameMaster/zoneEditor/partials/Toolbar.vue'
 import TileList from '@/components/gameMaster/zoneEditor/partials/TileList.vue'
@@ -32,6 +31,7 @@ import ZoneEventTiles from '@/components/gameMaster/zoneEditor/zonePartials/Zone
 
 const gameStore = useGameStore()
 const zoneEditorStore = useZoneEditorStore()
+console.log(zoneEditorStore.zone)
 
 const tileMap = ref(null as Phaser.Tilemaps.Tilemap | null)
 
@@ -64,6 +64,7 @@ function save() {
   }
 
   gameStore.connection?.emit('gm:zone_editor:zone:update', data, (response: Zone) => {
+    console.log(response.updatedAt)
     zoneEditorStore.setZone(response)
   })
 }
diff --git a/src/components/gameMaster/zoneEditor/partials/TileList.vue b/src/components/gameMaster/zoneEditor/partials/TileList.vue
index 9a05bb3..7c5beb7 100644
--- a/src/components/gameMaster/zoneEditor/partials/TileList.vue
+++ b/src/components/gameMaster/zoneEditor/partials/TileList.vue
@@ -223,7 +223,7 @@ function selectTile(tile: string) {
 }
 
 function isActiveTile(tile: Tile): boolean {
-  return zoneEditorStore.selectedTile?.id === tile.id
+  return zoneEditorStore.selectedTile === tile.id
 }
 
 onMounted(async () => {
diff --git a/src/components/gameMaster/zoneEditor/zonePartials/ZoneTiles.vue b/src/components/gameMaster/zoneEditor/zonePartials/ZoneTiles.vue
index b4673c1..548c867 100644
--- a/src/components/gameMaster/zoneEditor/zonePartials/ZoneTiles.vue
+++ b/src/components/gameMaster/zoneEditor/zonePartials/ZoneTiles.vue
@@ -191,7 +191,19 @@ onMounted(() => {
   if (!zoneEditorStore.zone?.tiles) {
     return
   }
-  setLayerTiles(tileMap, tileLayer, zoneEditorStore.zone.tiles)
+
+  // First fill the entire map with blank tiles
+  const blankTiles = createTileArray(tileMap.width, tileMap.height, 'blank_tile')
+
+  // Then overlay the zone tiles on top
+  const zoneTiles = zoneEditorStore.zone.tiles
+  for (let y = 0; y < zoneTiles.length; y++) {
+    for (let x = 0; x < zoneTiles[y].length; x++) {
+      blankTiles[y][x] = zoneTiles[y][x]
+    }
+  }
+
+  setLayerTiles(tileMap, tileLayer, blankTiles)
 
   scene.input.on(Phaser.Input.Events.POINTER_MOVE, pencil)
   scene.input.on(Phaser.Input.Events.POINTER_MOVE, eraser)
diff --git a/src/components/gui/Clock.vue b/src/components/gui/Clock.vue
index 6b12059..974af87 100644
--- a/src/components/gui/Clock.vue
+++ b/src/components/gui/Clock.vue
@@ -18,4 +18,4 @@ gameStore.connection?.on('date', (data: Date) => {
 onUnmounted(() => {
   gameStore.connection?.off('date')
 })
-</script>
\ No newline at end of file
+</script>
diff --git a/src/stores/zoneEditorStore.ts b/src/stores/zoneEditorStore.ts
index 4ab1a38..6d4e949 100644
--- a/src/stores/zoneEditorStore.ts
+++ b/src/stores/zoneEditorStore.ts
@@ -123,6 +123,8 @@ export const useZoneEditorStore = defineStore('zoneEditor', {
       this.drawMode = 'tile'
       this.selectedTile = ''
       this.selectedObject = null
+      this.isTileListModalShown = false
+      this.isObjectListModalShown = false
       this.isSettingsModalShown = false
       this.isZoneListModalShown = false
       this.isCreateZoneModalShown = false