forked from noxious/client
Map editor improvements
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<SelectedMapObject v-if="selectedMapObject" :mapObject="selectedMapObject" :movingMapObject="movingMapObject" @move="moveMapObject" @rotate="rotateMapObject" @delete="deleteMapObject" />
|
||||
<MapObject v-for="mapObject in mapEditorStore.map?.mapObjects" :tilemap="tilemap" :mapObject :selectedMapObject :movingMapObject @pointerup="clickMapObject(mapObject)" />
|
||||
<MapObject v-for="mapObject in mapEditorStore.map?.placedMapObjects" :tilemap="tilemap" :mapObject :selectedMapObject :movingMapObject @pointerup="clickMapObject(mapObject)" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@ -33,7 +33,7 @@ function pencil(pointer: Phaser.Input.Pointer) {
|
||||
if (mapEditorStore.drawMode !== 'object') return
|
||||
|
||||
// Check if there is a selected object
|
||||
if (!mapEditorStore.selectedObject) return
|
||||
if (!mapEditorStore.selectedMapObject) return
|
||||
|
||||
// Check if left mouse button is pressed
|
||||
if (!pointer.isDown) return
|
||||
@ -56,8 +56,8 @@ function pencil(pointer: Phaser.Input.Pointer) {
|
||||
id: uuidv4(),
|
||||
mapId: mapEditorStore.map.id,
|
||||
map: mapEditorStore.map,
|
||||
objectId: mapEditorStore.selectedObject.id,
|
||||
object: mapEditorStore.selectedObject,
|
||||
objectId: mapEditorStore.selectedMapObject.id,
|
||||
object: mapEditorStore.selectedMapObject,
|
||||
depth: 0,
|
||||
isRotated: false,
|
||||
positionX: tile.x,
|
||||
@ -123,11 +123,11 @@ function objectPicker(pointer: Phaser.Input.Pointer) {
|
||||
if (!tile) return
|
||||
|
||||
// Check if object already exists on position
|
||||
const existingObject = mapEditorStore.map.placedMapObjects.find((object) => object.positionX === tile.x && object.positionY === tile.y)
|
||||
if (!existingObject) return
|
||||
const existingMapObject = mapEditorStore.map.placedMapObjects.find((object) => object.positionX === tile.x && object.positionY === tile.y)
|
||||
if (!existingMapObject) return
|
||||
|
||||
// Select the object
|
||||
mapEditorStore.setSelectedObject(existingObject)
|
||||
mapEditorStore.setSelectedMapObject(existingMapObject)
|
||||
}
|
||||
|
||||
function moveMapObject(id: string) {
|
||||
@ -184,7 +184,7 @@ function clickMapObject(mapObject: MapObjectT) {
|
||||
|
||||
// If alt is pressed, select the object
|
||||
if (scene.input.activePointer.event.altKey) {
|
||||
mapEditorStore.setSelectedObject(mapObject.object)
|
||||
mapEditorStore.setSelectedMapObject(mapObject.mapObject)
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,20 +204,20 @@ onUnmounted(() => {
|
||||
scene.input.off(Phaser.Input.Events.POINTER_DOWN, objectPicker)
|
||||
})
|
||||
|
||||
// watch mapEditorStore.objectList and update originX and originY of objects in mapObjects
|
||||
// watch mapEditorStore.mapObjectList and update originX and originY of objects in mapObjects
|
||||
watch(
|
||||
() => mapEditorStore.objectList,
|
||||
() => mapEditorStore.mapObjectList,
|
||||
(newObjects) => {
|
||||
if (!mapEditorStore.map) return
|
||||
|
||||
console.log(mapEditorStore.map.placedMapObjects)
|
||||
const updatedMapObjects = mapEditorStore.map.placedMapObjects.map((mapObject) => {
|
||||
const updatedObject = newObjects.find((obj) => obj.id === mapObject.object.id)
|
||||
const updatedObject = newObjects.find((obj) => obj.id === mapObject.mapObject.id)
|
||||
if (updatedObject) {
|
||||
return {
|
||||
...mapObject,
|
||||
object: {
|
||||
...mapObject.object,
|
||||
...mapObject.mapObject,
|
||||
originX: updatedObject.originX,
|
||||
originY: updatedObject.originY
|
||||
}
|
||||
@ -232,12 +232,12 @@ watch(
|
||||
mapObjects: updatedMapObjects
|
||||
})
|
||||
|
||||
// Update selectedObject if it's set
|
||||
if (mapEditorStore.selectedObject) {
|
||||
const updatedObject = newObjects.find((obj) => obj.id === mapEditorStore.selectedObject?.id)
|
||||
// Update selectedMapObject if it's set
|
||||
if (mapEditorStore.selectedMapObject) {
|
||||
const updatedObject = newObjects.find((obj) => obj.id === mapEditorStore.selectedMapObject?.id)
|
||||
if (updatedObject) {
|
||||
mapEditorStore.setSelectedObject({
|
||||
...mapEditorStore.selectedObject,
|
||||
mapEditorStore.setSelectedMapObject({
|
||||
...mapEditorStore.selectedMapObject,
|
||||
originX: updatedObject.originX,
|
||||
originY: updatedObject.originY
|
||||
})
|
||||
|
Reference in New Issue
Block a user