1
0
forked from noxious/client

Update origin X and Y values in real-time

This commit is contained in:
Dennis Postma 2025-02-06 14:02:50 +01:00
parent 15b212160d
commit 7071d934b4
3 changed files with 24 additions and 4 deletions

View File

@ -10,7 +10,7 @@ import { calculateIsometricDepth, loadMapObjectTextures, tileToWorldXY } from '@
import { MapObjectStorage } from '@/storage/storages' import { MapObjectStorage } from '@/storage/storages'
import { useGameStore } from '@/stores/gameStore' import { useGameStore } from '@/stores/gameStore'
import { Image, useScene } from 'phavuer' import { Image, useScene } from 'phavuer'
import { computed, onMounted, ref } from 'vue' import { computed, onMounted, ref, watch } from 'vue'
import Tilemap = Phaser.Tilemaps.Tilemap import Tilemap = Phaser.Tilemaps.Tilemap
import TilemapLayer = Phaser.Tilemaps.TilemapLayer import TilemapLayer = Phaser.Tilemaps.TilemapLayer
@ -69,6 +69,13 @@ const imageProps = computed(() => ({
originY: mapObject.value!.originY originY: mapObject.value!.originY
})) }))
watch(
() => mapEditor.refreshMapObject.value,
async () => {
await initialize()
}
)
onMounted(async () => { onMounted(async () => {
await initialize() await initialize()
}) })

View File

@ -4,7 +4,7 @@
<button @mousedown.stop @click="handleDelete" class="btn-red py-1.5 px-4"> <button @mousedown.stop @click="handleDelete" class="btn-red py-1.5 px-4">
<img src="/assets/icons/trashcan.svg" class="w-4 h-4" alt="Delete" /> <img src="/assets/icons/trashcan.svg" class="w-4 h-4" alt="Delete" />
</button> </button>
<button @mousedown.stop @click="showMapObjectSettings = true" class="btn-indigo py-1.5 px-4"> <button @mousedown.stop @click="showMapObjectSettings = !showMapObjectSettings" class="btn-indigo py-1.5 px-4">
<img src="/assets/icons/mapEditor/gear.svg" class="w-4 h-4 invert" alt="Delete" /> <img src="/assets/icons/mapEditor/gear.svg" class="w-4 h-4 invert" alt="Delete" />
</button> </button>
<button @mousedown.stop @click="handleRotate" class="btn-cyan py-1.5 px-4">Rotate</button> <button @mousedown.stop @click="handleRotate" class="btn-cyan py-1.5 px-4">Rotate</button>
@ -12,7 +12,7 @@
</div> </div>
</div> </div>
<Modal :is-modal-open="showMapObjectSettings" :modal-height="320" bg-style="none"> <Modal :is-modal-open="showMapObjectSettings" @modal:close="showMapObjectSettings = false" :modal-height="320" bg-style="none">
<template #modalHeader> <template #modalHeader>
<h3 class="m-0 font-medium shrink-0 text-white">Map object settings</h3> <h3 class="m-0 font-medium shrink-0 text-white">Map object settings</h3>
</template> </template>
@ -90,12 +90,12 @@ async function handleUpdate() {
}, },
async (response: boolean) => { async (response: boolean) => {
if (!response) return if (!response) return
// Update mapObject in storage
await mapObjectStorage.update(mapObject.value!.id, { await mapObjectStorage.update(mapObject.value!.id, {
name: mapObjectName.value, name: mapObjectName.value,
originX: mapObjectOriginX.value, originX: mapObjectOriginX.value,
originY: mapObjectOriginY.value originY: mapObjectOriginY.value
}) })
mapEditor.triggerMapObjectRefresh() // Add this line
} }
) )
} }

View File

@ -25,6 +25,12 @@ const teleportSettings = ref<TeleportSettings>({
toRotation: 0 toRotation: 0
}) })
/**
* We can update origin X and Y in src/components/gameMaster/mapEditor/partials/SelectedPlacedMapObject.vue
* and this will trigger a refresh for spawned mao objects
*/
const refreshMapObject = ref(0)
export function useMapEditorComposable() { export function useMapEditorComposable() {
const loadMap = (map: Map) => { const loadMap = (map: Map) => {
currentMap.value = map currentMap.value = map
@ -79,6 +85,10 @@ export function useMapEditorComposable() {
shouldClearTiles.value = false shouldClearTiles.value = false
} }
function triggerMapObjectRefresh() {
refreshMapObject.value++ // Increment to trigger watchers
}
const reset = () => { const reset = () => {
tool.value = 'move' tool.value = 'move'
drawMode.value = 'tile' drawMode.value = 'tile'
@ -86,6 +96,7 @@ export function useMapEditorComposable() {
selectedTile.value = '' selectedTile.value = ''
selectedMapObject.value = null selectedMapObject.value = null
shouldClearTiles.value = false shouldClearTiles.value = false
refreshMapObject.value = 0
} }
return { return {
@ -101,6 +112,7 @@ export function useMapEditorComposable() {
selectedPlacedObject, selectedPlacedObject,
shouldClearTiles, shouldClearTiles,
teleportSettings, teleportSettings,
refreshMapObject,
// Methods // Methods
loadMap, loadMap,
@ -115,6 +127,7 @@ export function useMapEditorComposable() {
setTeleportSettings, setTeleportSettings,
triggerClearTiles, triggerClearTiles,
resetClearTilesFlag, resetClearTilesFlag,
triggerMapObjectRefresh,
reset reset
} }
} }