From 56f30093f6013f736dc5e73d107d60d846d2b913 Mon Sep 17 00:00:00 2001
From: Dennis Postma <dennis@directonline.io>
Date: Fri, 14 Feb 2025 03:04:42 +0100
Subject: [PATCH] Teleport fix WIP

---
 .../mapEditor/mapPartials/MapEventTiles.vue    |  2 ++
 .../mapEditor/mapPartials/PlacedMapObjects.vue |  2 +-
 .../mapEditor/partials/MapObjectList.vue       |  7 +------
 .../mapEditor/partials/TeleportModal.vue       | 18 +++++++++---------
 .../gameMaster/mapEditor/partials/TileList.vue |  7 +------
 src/components/screens/MapEditor.vue           |  1 +
 src/components/utilities/Debug.vue             |  4 ++--
 src/composables/useMapEditorComposable.ts      |  2 +-
 src/services/mapService.ts                     |  2 +-
 9 files changed, 19 insertions(+), 26 deletions(-)

diff --git a/src/components/gameMaster/mapEditor/mapPartials/MapEventTiles.vue b/src/components/gameMaster/mapEditor/mapPartials/MapEventTiles.vue
index 3ffbc95..726bc78 100644
--- a/src/components/gameMaster/mapEditor/mapPartials/MapEventTiles.vue
+++ b/src/components/gameMaster/mapEditor/mapPartials/MapEventTiles.vue
@@ -90,6 +90,8 @@ function pencil(pointer: Phaser.Input.Pointer, map: MapT) {
   // If teleport, check if there is a selected map
   if (mapEditor.drawMode.value === 'teleport' && !mapEditor.teleportSettings.value.toMapId) return
 
+  console.log(mapEditor.teleportSettings.value.toMapId)
+
   const newEventTile = {
     id: uuidv4() as UUID,
     mapId: map.id,
diff --git a/src/components/gameMaster/mapEditor/mapPartials/PlacedMapObjects.vue b/src/components/gameMaster/mapEditor/mapPartials/PlacedMapObjects.vue
index b65c0f6..70919d5 100644
--- a/src/components/gameMaster/mapEditor/mapPartials/PlacedMapObjects.vue
+++ b/src/components/gameMaster/mapEditor/mapPartials/PlacedMapObjects.vue
@@ -18,7 +18,7 @@ import SelectedPlacedMapObjectComponent from '@/components/gameMaster/mapEditor/
 import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
 import { getTile } from '@/services/mapService'
 import { useScene } from 'phavuer'
-import {computed, onMounted, onUnmounted, ref, watch} from 'vue'
+import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
 
 import Tilemap = Phaser.Tilemaps.Tilemap
 import TilemapLayer = Phaser.Tilemaps.TilemapLayer
diff --git a/src/components/gameMaster/mapEditor/partials/MapObjectList.vue b/src/components/gameMaster/mapEditor/partials/MapObjectList.vue
index 5f7db97..87100ec 100644
--- a/src/components/gameMaster/mapEditor/partials/MapObjectList.vue
+++ b/src/components/gameMaster/mapEditor/partials/MapObjectList.vue
@@ -9,12 +9,7 @@
             <input @mousedown.stop class="!pl-7 input-field w-full" type="text" name="search" placeholder="Search" v-model="searchQuery" />
           </div>
         </div>
-        <img
-            src="/assets/icons/mapEditor/dropdown-chevron.svg"
-            class="w-12 h-12 ml-2 cursor-pointer hover:opacity-80 -rotate-90"
-            alt="Close"
-            @click="mapEditor.setTool('move')"
-        />
+        <img src="/assets/icons/mapEditor/dropdown-chevron.svg" class="w-12 h-12 ml-2 cursor-pointer hover:opacity-80 -rotate-90" alt="Close" @click="mapEditor.setTool('move')" />
       </div>
       <div class="flex">
         <select class="input-field w-full" name="lists" v-model="mapEditor.drawMode.value" @change="(event: any) => mapEditor.setDrawMode(event.target.value)">
diff --git a/src/components/gameMaster/mapEditor/partials/TeleportModal.vue b/src/components/gameMaster/mapEditor/partials/TeleportModal.vue
index 8d4f5e1..cb04533 100644
--- a/src/components/gameMaster/mapEditor/partials/TeleportModal.vue
+++ b/src/components/gameMaster/mapEditor/partials/TeleportModal.vue
@@ -1,5 +1,5 @@
 <template>
-  <Modal v-if="showTeleportModal" ref="modalRef" @modal:close="() => mapEditorStore.setTool('move')" :modal-width="300" :modal-height="350" :is-resizable="false" bg-style="none">
+  <Modal v-if="showTeleportModal" ref="modalRef" @modal:close="() => mapEditor.setTool('move')" :modal-width="300" :modal-height="350" :is-resizable="false" bg-style="none">
     <template #modalHeader>
       <h3 class="m-0 font-medium shrink-0 text-white">Teleport settings</h3>
     </template>
@@ -26,9 +26,9 @@
             </div>
             <div class="form-field-full">
               <label for="toMap">Map to teleport to</label>
-              <select v-model="toMap" class="input-field" name="toMap" id="toMap">
+              <select v-model="toMapId" class="input-field" name="toMap" id="toMap">
                 <option :value="null">Select map</option>
-                <option v-for="map in mapList" :key="map.id" :value="map">{{ map.name }}</option>
+                <option v-for="map in mapList" :key="map.id" :value="map.id">{{ map.name }}</option>
               </select>
             </div>
           </div>
@@ -41,9 +41,9 @@
 <script setup lang="ts">
 import type { Map } from '@/application/types'
 import Modal from '@/components/utilities/Modal.vue'
+import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
+import { MapStorage } from '@/storage/storages'
 import { computed, onMounted, ref, useTemplateRef, watch } from 'vue'
-import {MapStorage} from "@/storage/storages";
-import {useMapEditorComposable} from "@/composables/useMapEditorComposable";
 
 const showTeleportModal = computed(() => mapEditor.tool.value === 'pencil' && mapEditor.drawMode.value === 'teleport')
 const mapStorage = new MapStorage()
@@ -55,7 +55,7 @@ defineExpose({
   open: () => modalRef.value?.open()
 })
 
-const { toPositionX, toPositionY, toRotation, toMap } = useRefTeleportSettings()
+const { toPositionX, toPositionY, toRotation, toMapId } = useRefTeleportSettings()
 
 function useRefTeleportSettings() {
   const settings = mapEditor.teleportSettings.value
@@ -63,18 +63,18 @@ function useRefTeleportSettings() {
     toPositionX: ref(settings.toPositionX),
     toPositionY: ref(settings.toPositionY),
     toRotation: ref(settings.toRotation),
-    toMap: ref(settings.toMapId)
+    toMapId: ref(settings.toMapId)
   }
 }
 
-watch([toPositionX, toPositionY, toRotation, toMap], updateTeleportSettings)
+watch([toPositionX, toPositionY, toRotation, toMapId], updateTeleportSettings)
 
 function updateTeleportSettings() {
   mapEditor.setTeleportSettings({
     toPositionX: toPositionX.value,
     toPositionY: toPositionY.value,
     toRotation: toRotation.value,
-    toMapId: toMap.value
+    toMapId: toMapId.value
   })
 }
 
diff --git a/src/components/gameMaster/mapEditor/partials/TileList.vue b/src/components/gameMaster/mapEditor/partials/TileList.vue
index d7e7825..896e540 100644
--- a/src/components/gameMaster/mapEditor/partials/TileList.vue
+++ b/src/components/gameMaster/mapEditor/partials/TileList.vue
@@ -9,12 +9,7 @@
             <input @mousedown.stop class="!pl-7 input-field w-full" type="text" name="search" placeholder="Search" v-model="searchQuery" />
           </div>
         </div>
-        <img
-            src="/assets/icons/mapEditor/dropdown-chevron.svg"
-            class="w-12 h-12 ml-2 cursor-pointer hover:opacity-80 -rotate-90"
-            alt="Close"
-            @click="mapEditor.setTool('move')"
-        />
+        <img src="/assets/icons/mapEditor/dropdown-chevron.svg" class="w-12 h-12 ml-2 cursor-pointer hover:opacity-80 -rotate-90" alt="Close" @click="mapEditor.setTool('move')" />
       </div>
       <div class="flex">
         <select class="input-field w-full" name="lists" v-model="mapEditor.drawMode.value" @change="(event: any) => mapEditor.setDrawMode(event.target.value)">
diff --git a/src/components/screens/MapEditor.vue b/src/components/screens/MapEditor.vue
index 5a5219d..e4ddd23 100644
--- a/src/components/screens/MapEditor.vue
+++ b/src/components/screens/MapEditor.vue
@@ -91,6 +91,7 @@ function save() {
     ...currentMap,
     mapId: currentMap.id
   }
+  console.log(data)
 
   gameStore.connection?.emit(SocketEvent.GM_MAP_UPDATE, data, (response: MapT) => {
     mapStorage.update(response.id, response)
diff --git a/src/components/utilities/Debug.vue b/src/components/utilities/Debug.vue
index c7ee9f6..745d76c 100644
--- a/src/components/utilities/Debug.vue
+++ b/src/components/utilities/Debug.vue
@@ -1,11 +1,11 @@
 <template></template>
 
 <script setup lang="ts">
+import { login } from '@/services/authenticationService'
 import { CharacterHairStorage, CharacterTypeStorage, MapObjectStorage, MapStorage, SoundStorage, SpriteStorage, TileStorage } from '@/storage/storages'
 import { TextureStorage } from '@/storage/textureStorage'
+import { useGameStore } from '@/stores/gameStore'
 import { onMounted, onUnmounted } from 'vue'
-import {login} from "@/services/authenticationService";
-import {useGameStore} from "@/stores/gameStore";
 
 const gameStore = useGameStore()
 const mapStorage = new MapStorage()
diff --git a/src/composables/useMapEditorComposable.ts b/src/composables/useMapEditorComposable.ts
index 216691a..73635e4 100644
--- a/src/composables/useMapEditorComposable.ts
+++ b/src/composables/useMapEditorComposable.ts
@@ -1,6 +1,6 @@
 import type { Map, MapObject, PlacedMapObject, UUID } from '@/application/types'
+import { useGameStore } from '@/stores/gameStore'
 import { ref } from 'vue'
-import {useGameStore} from "@/stores/gameStore";
 
 export type TeleportSettings = {
   toMapId: string
diff --git a/src/services/mapService.ts b/src/services/mapService.ts
index fd4d1bf..793faf5 100644
--- a/src/services/mapService.ts
+++ b/src/services/mapService.ts
@@ -155,4 +155,4 @@ export function createTileLayer(tileMap: Phaser.Tilemaps.Tilemap, tilesArray: st
 //Recursive Array Clone
 export function cloneArray(arr: any[]): any[] {
   return arr.map((item) => (item instanceof Array ? cloneArray(item) : item))
-}
\ No newline at end of file
+}