From 5e243e52016fc305bcef9f55d0e4a83dc696b8b9 Mon Sep 17 00:00:00 2001 From: Andrei Date: Thu, 13 Feb 2025 12:19:09 -0600 Subject: [PATCH] Fixed object moving when its not supposed to --- .../mapEditor/mapPartials/PlacedMapObjects.vue | 12 ++++++------ src/components/screens/MapEditor.vue | 16 +--------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/components/gameMaster/mapEditor/mapPartials/PlacedMapObjects.vue b/src/components/gameMaster/mapEditor/mapPartials/PlacedMapObjects.vue index eafafd8..9d38117 100644 --- a/src/components/gameMaster/mapEditor/mapPartials/PlacedMapObjects.vue +++ b/src/components/gameMaster/mapEditor/mapPartials/PlacedMapObjects.vue @@ -39,8 +39,8 @@ const props = defineProps<{ const previewPosition = ref({ x: 0, y: 0 }) const previewPlacedMapObject = computed(() => ({ - id: mapEditor.selectedMapObject.value?.id ?? uuidv4(), - mapObject: mapEditor.selectedMapObject.value?.id, + id: mapEditor.selectedMapObject.value!.id, + mapObject: mapEditor.selectedMapObject.value!, isRotated: false, positionX: previewPosition.value.x, positionY: previewPosition.value.y @@ -118,13 +118,14 @@ function moveMapObject(id: string, map: MapT) { } scene.input.on(Phaser.Input.Events.POINTER_MOVE, handlePointerMove) + scene.input.on(Phaser.Input.Events.POINTER_UP, handlePointerUp) function handlePointerUp(pointer: Phaser.Input.Pointer) { scene.input.off(Phaser.Input.Events.POINTER_MOVE, handlePointerMove) const tile = getTile(props.tileMap, pointer.worldX, pointer.worldY) if (!tile) return - + console.log(id) map.placedMapObjects.map((placed) => { if (placed.id === id) { placed.positionX = tile.x @@ -132,10 +133,9 @@ function moveMapObject(id: string, map: MapT) { }}) mapEditor.movingPlacedObject.value = null + emit('updateAndCommit', map) + scene.input.off(Phaser.Input.Events.POINTER_UP, handlePointerUp) } - emit('updateAndCommit', map) - - scene.input.on(Phaser.Input.Events.POINTER_UP, handlePointerUp) } function rotatePlacedMapObject(id: string, map: MapT) { diff --git a/src/components/screens/MapEditor.vue b/src/components/screens/MapEditor.vue index b92cefa..dff2a13 100644 --- a/src/components/screens/MapEditor.vue +++ b/src/components/screens/MapEditor.vue @@ -6,19 +6,6 @@
- @@ -101,8 +88,7 @@ function save() { const data = { ...currentMap, - mapId: currentMap.id, - placedMapObjects: currentMap.placedMapObjects.map(({ id, mapObject, depth, isRotated, positionX, positionY }) => ({ id, mapObject, depth, isRotated, positionX, positionY })) ?? [] + mapId: currentMap.id } gameStore.connection?.emit('gm:map:update', data, (response: MapT) => {