From 369522fda328b9fc7eebbd8a7043f70dc33a3e68 Mon Sep 17 00:00:00 2001
From: Colin Kallemein <cakallemein@gmail.com>
Date: Fri, 7 Feb 2025 20:37:11 +0100
Subject: [PATCH] #321 - Show corresponding list when drawMode is selected &
 vice versa

Synced with main, cleaned up unused consts
---
 .../mapEditor/partials/ListPanel.vue          | 22 +++++++++++++++++--
 .../gameMaster/mapEditor/partials/Toolbar.vue |  4 ----
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/components/gameMaster/mapEditor/partials/ListPanel.vue b/src/components/gameMaster/mapEditor/partials/ListPanel.vue
index fb9e776..a739330 100644
--- a/src/components/gameMaster/mapEditor/partials/ListPanel.vue
+++ b/src/components/gameMaster/mapEditor/partials/ListPanel.vue
@@ -27,14 +27,16 @@
 </template>
 
 <script setup lang="ts">
-import config from '@/application/config'
 import type { Tile } from '@/application/types'
 import { TileStorage } from '@/storage/storages'
 import { liveQuery } from 'dexie'
-import { computed, onMounted, onUnmounted, ref } from 'vue'
+import { onMounted, onUnmounted, ref, watch } from 'vue'
+import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
 import TileList from '@/components/gameMaster/mapEditor/partials/lists/TileList.vue'
 import ObjectList from '@/components/gameMaster/mapEditor/partials/lists/MapObjectList.vue'
 
+const mapEditor = useMapEditorComposable()
+
 const isOpen = ref(false)
 const tileStorage = new TileStorage()
 const searchQuery = ref('')
@@ -47,6 +49,22 @@ defineExpose({
   toggle: () => (isOpen.value = !isOpen.value)
 })
 
+watch(lists, (list) => {
+  if (list === 'tiles') {
+    mapEditor.setDrawMode('tile')
+  } else if (list === 'objects') {
+    mapEditor.setDrawMode('map_object')
+  }
+})
+
+watch(() => mapEditor.drawMode.value, (list) => {
+  if (list === 'tile') {
+    lists.value = 'tiles'
+  } else if (list === 'map_object') {
+    lists.value = 'objects'
+  }
+})
+
 let subscription: any = null
 
 onMounted(() => {
diff --git a/src/components/gameMaster/mapEditor/partials/Toolbar.vue b/src/components/gameMaster/mapEditor/partials/Toolbar.vue
index a667245..ae91329 100644
--- a/src/components/gameMaster/mapEditor/partials/Toolbar.vue
+++ b/src/components/gameMaster/mapEditor/partials/Toolbar.vue
@@ -112,12 +112,8 @@ const toolbar = ref(null)
 const isMapEditorSettingsModalOpen = ref(false)
 const selectPencilOpen = ref(false)
 const selectEraserOpen = ref(false)
-const tileListShown = ref(false)
-const mapObjectListShown = ref(false)
 const checkboxValue = ref<Boolean>(false)
 
-defineExpose({ tileListShown, mapObjectListShown })
-
 // drawMode
 function setDrawMode(value: string) {
   if (mapEditor.tool.value === 'paint' || mapEditor.tool.value === 'pencil' || mapEditor.tool.value === 'eraser') {