diff --git a/src/components/gameMaster/mapEditor/Map.vue b/src/components/gameMaster/mapEditor/Map.vue index 2a926ae..7acceb7 100644 --- a/src/components/gameMaster/mapEditor/Map.vue +++ b/src/components/gameMaster/mapEditor/Map.vue @@ -1,30 +1,109 @@ diff --git a/src/components/gameMaster/mapEditor/mapPartials/PlacedMapObjects.vue b/src/components/gameMaster/mapEditor/mapPartials/PlacedMapObjects.vue index 515d79f..278a799 100644 --- a/src/components/gameMaster/mapEditor/mapPartials/PlacedMapObjects.vue +++ b/src/components/gameMaster/mapEditor/mapPartials/PlacedMapObjects.vue @@ -16,7 +16,7 @@ import { uuidv4 } from '@/application/utilities' import PlacedMapObject from '@/components/game/map/partials/PlacedMapObject.vue' import SelectedPlacedMapObjectComponent from '@/components/gameMaster/mapEditor/partials/SelectedPlacedMapObject.vue' import { useMapEditorComposable } from '@/composables/useMapEditorComposable' -import { getTile } from '@/services/mapService' +import { cloneArray, getTile } from '@/services/mapService' import { useScene } from 'phavuer' import { computed, onMounted, onUnmounted, ref } from 'vue' @@ -27,7 +27,9 @@ const scene = useScene() const mapEditor = useMapEditorComposable() const map = computed(() => mapEditor.currentMap.value!) -defineExpose({ handlePointer }) +defineExpose({ handlePointer, finalizeCommand }) + +const emit = defineEmits(['createCommand']) const props = defineProps<{ tileMap: Tilemap @@ -71,6 +73,9 @@ function pencil(pointer: Phaser.Input.Pointer, map: MapT) { // Add new object to mapObjects map.placedMapObjects.push(newPlacedMapObject) + + createCommandUpdate(newPlacedMapObject, 'place') + mapEditor.selectedPlacedObject.value = newPlacedMapObject } @@ -79,6 +84,8 @@ function eraser(pointer: Phaser.Input.Pointer, map: MapT) { const existingPlacedMapObject = findObjectByPointer(pointer, map) if (!existingPlacedMapObject) return + createCommandUpdate(existingPlacedMapObject, 'delete') + // Remove existing object map.placedMapObjects = map.placedMapObjects.filter((placedMapObject) => placedMapObject.id !== existingPlacedMapObject.id) } @@ -102,11 +109,15 @@ function objectPicker(pointer: Phaser.Input.Pointer, map: MapT) { function moveMapObject(id: string, map: MapT) { mapEditor.movingPlacedObject.value = map.placedMapObjects.find((object) => object.id === id) as PlacedMapObjectT + let t: Tile + function handlePointerMove(pointer: Phaser.Input.Pointer) { if (!mapEditor.movingPlacedObject.value) return const tile = getTile(props.tileMap, pointer.worldX, pointer.worldY) if (!tile) return + t = tile + mapEditor.movingPlacedObject.value.positionX = tile.x mapEditor.movingPlacedObject.value.positionY = tile.y } @@ -116,6 +127,9 @@ function moveMapObject(id: string, map: MapT) { function handlePointerUp() { scene.input.off(Phaser.Input.Events.POINTER_MOVE, handlePointerMove) mapEditor.movingPlacedObject.value = null + + createCommandUpdate(mapEditor.movingPlacedObject.value!, 'move', new Vector2(t.x, t.y)) + finalizeCommand() } scene.input.on(Phaser.Input.Events.POINTER_UP, handlePointerUp) @@ -128,6 +142,13 @@ function rotatePlacedMapObject(id: string, map: MapT) { function deletePlacedMapObject(id: string, map: MapT) { let mapE = mapEditor.currentMap.value! + + const foundObject = mapE.placedMapObjects.find((obj) => obj.id === id) + if (!foundObject) return + + createCommandUpdate(foundObject, 'delete') + finalizeCommand() + mapE.placedMapObjects = map.placedMapObjects.filter((object) => object.id !== id) mapEditor.selectedPlacedObject.value = null } diff --git a/src/components/gameMaster/mapEditor/partials/Toolbar.vue b/src/components/gameMaster/mapEditor/partials/Toolbar.vue index 78c8e73..42a5843 100644 --- a/src/components/gameMaster/mapEditor/partials/Toolbar.vue +++ b/src/components/gameMaster/mapEditor/partials/Toolbar.vue @@ -150,6 +150,7 @@ function handleClick(tool: string) { mapEditor.setTool(tool) selectPencilOpen.value = tool === 'pencil' ? !selectPencilOpen.value : false selectEraserOpen.value = tool === 'eraser' ? !selectEraserOpen.value : false + } function cycleToolMode(tool: 'pencil' | 'eraser') { diff --git a/src/components/screens/MapEditor.vue b/src/components/screens/MapEditor.vue index 0f5bbdf..71cef1e 100644 --- a/src/components/screens/MapEditor.vue +++ b/src/components/screens/MapEditor.vue @@ -34,6 +34,7 @@ import { MapStorage } from '@/storage/storages' import { useGameStore } from '@/stores/gameStore' import { Game, Scene } from 'phavuer' import { ref, useTemplateRef } from 'vue' +import teleportModal from '@/components/gameMaster/mapEditor/partials/TeleportModal.vue' const mapStorage = new MapStorage() const mapEditor = useMapEditorComposable() @@ -41,6 +42,7 @@ const gameStore = useGameStore() const mapModal = useTemplateRef('mapModal') const mapSettingsModal = useTemplateRef('mapSettingsModal') +const teleportSettings = useTemplateRef('teleportModal') const isLoaded = ref(false) @@ -86,15 +88,9 @@ function save() { if (!currentMap) return const data = { + ...currentMap, mapId: currentMap.id, - name: currentMap.name, - width: currentMap.width, - height: currentMap.height, - tiles: currentMap.tiles, - pvp: currentMap.pvp, - mapEffects: currentMap.mapEffects, - mapEventTiles: currentMap.mapEventTiles, - placedMapObjects: currentMap.placedMapObjects.map(({ id, mapObject, isRotated, positionX, positionY }) => ({ id, mapObject, isRotated, positionX, positionY })) ?? [] + placedMapObjects: currentMap.placedMapObjects.map(({ id, mapObject, depth, isRotated, positionX, positionY }) => ({ id, mapObject, depth, isRotated, positionX, positionY })) ?? [] } gameStore.connection?.emit('gm:map:update', data, (response: MapT) => { diff --git a/src/services/mapService.ts b/src/services/mapService.ts index c07f9ee..fd4d1bf 100644 --- a/src/services/mapService.ts +++ b/src/services/mapService.ts @@ -151,3 +151,8 @@ export function createTileLayer(tileMap: Phaser.Tilemaps.Tilemap, tilesArray: st return layer } + +//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