From 860fe705c6809198fbf27300921aeeaa5bbf14ee Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Fri, 18 Oct 2024 19:10:41 +0200 Subject: [PATCH] Saving maps works again --- src/components/gameMaster/zoneEditor/Tiles.vue | 15 ++++++++++++++- .../gameMaster/zoneEditor/ZoneEditor.vue | 11 ++++------- src/composables/zoneComposable.ts | 14 ++++++++++++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/components/gameMaster/zoneEditor/Tiles.vue b/src/components/gameMaster/zoneEditor/Tiles.vue index 91452d5..3f1adfd 100644 --- a/src/components/gameMaster/zoneEditor/Tiles.vue +++ b/src/components/gameMaster/zoneEditor/Tiles.vue @@ -47,6 +47,9 @@ function createTileLayer() { } function pencil(pointer: Phaser.Input.Pointer) { + // Check if zone is set + if (!zoneEditorStore.zone) return + // Check if tool is pencil if (zoneEditorStore.tool !== 'pencil') return @@ -63,7 +66,11 @@ function pencil(pointer: Phaser.Input.Pointer) { const tile = getTile(tiles, pointer.worldX, pointer.worldY) if (!tile) return + // Place tile placeTile(zoneTilemap, tiles, tile.x, tile.y, zoneEditorStore.selectedTile.id) + + // Adjust zoneEditorStore.zone.tiles + zoneEditorStore.zone.tiles[tile.y][tile.x] = zoneEditorStore.selectedTile.id } function eraser(pointer: Phaser.Input.Pointer) { @@ -83,7 +90,11 @@ function eraser(pointer: Phaser.Input.Pointer) { const tile = getTile(tiles, pointer.worldX, pointer.worldY) if (!tile) return + // Place tile placeTile(zoneTilemap, tiles, tile.x, tile.y, 'blank_tile') + + // Adjust zoneEditorStore.zone.tiles + zoneEditorStore.zone.tiles[tile.y][tile.x] = 'blank_tile' } function paint(pointer: Phaser.Input.Pointer) { @@ -100,8 +111,10 @@ function paint(pointer: Phaser.Input.Pointer) { if (!pointer.isDown) return // Set new tileArray with selected tile - // tileArr setAllTiles(zoneTilemap, tiles, createTileArray(zoneTilemap.width, zoneTilemap.height, zoneEditorStore.selectedTile.id)) + + // Adjust zoneEditorStore.zone.tiles + zoneEditorStore.zone.tiles = createTileArray(zoneTilemap.width, zoneTilemap.height, zoneEditorStore.selectedTile.id) } onBeforeMount(() => { diff --git a/src/components/gameMaster/zoneEditor/ZoneEditor.vue b/src/components/gameMaster/zoneEditor/ZoneEditor.vue index 3b0fb1b..a8c3b07 100644 --- a/src/components/gameMaster/zoneEditor/ZoneEditor.vue +++ b/src/components/gameMaster/zoneEditor/ZoneEditor.vue @@ -19,7 +19,7 @@ import { useScene } from 'phavuer' import { useGameStore } from '@/stores/gameStore' import { useZoneEditorStore } from '@/stores/zoneEditorStore' import { loadAssets } from '@/composables/zoneComposable' -import { type ZoneObject, type ZoneEventTile, type Zone } from '@/types' +import { type Zone } from '@/types' // Components import Toolbar from '@/components/gameMaster/zoneEditor/partials/Toolbar.vue' @@ -37,9 +37,6 @@ const gameStore = useGameStore() const zoneEditorStore = useZoneEditorStore() const tileMap = ref(null as Phaser.Tilemaps.Tilemap | null) -const tileArray = ref([]) -const zoneObjects = ref([]) -const zoneEventTiles = ref([]) function save() { if (!zoneEditorStore.zone) return @@ -49,10 +46,10 @@ function save() { name: zoneEditorStore.zoneSettings.name, width: zoneEditorStore.zoneSettings.width, height: zoneEditorStore.zoneSettings.height, - tiles: tileArray, + tiles: zoneEditorStore.zone.tiles, pvp: zoneEditorStore.zone.pvp, - zoneEventTiles: zoneEventTiles.value.map(({ id, zoneId, type, positionX, positionY, teleport }) => ({ id, zoneId, type, positionX, positionY, teleport })), - zoneObjects: zoneObjects.value.map(({ id, zoneId, objectId, depth, isRotated, positionX, positionY }) => ({ id, zoneId, objectId, depth, isRotated, positionX, positionY })) + zoneEventTiles: zoneEditorStore.zone.zoneEventTiles.map(({ id, zoneId, type, positionX, positionY, teleport }) => ({ id, zoneId, type, positionX, positionY, teleport })), + zoneObjects: zoneEditorStore.zone.zoneObjects.map(({ id, zoneId, objectId, depth, isRotated, positionX, positionY }) => ({ id, zoneId, objectId, depth, isRotated, positionX, positionY })) } if (zoneEditorStore.isSettingsModalShown) { diff --git a/src/composables/zoneComposable.ts b/src/composables/zoneComposable.ts index d07be63..ce87011 100644 --- a/src/composables/zoneComposable.ts +++ b/src/composables/zoneComposable.ts @@ -35,9 +35,19 @@ export function tileToWorldY(layer: TilemapLayer | Tilemap, pos_x: number, pos_y return worldPoint.y + config.tile_size.y * 1.5 } +/** + * Can also be used to replace tiles + * @param zone + * @param layer + * @param x + * @param y + * @param tileName + */ export function placeTile(zone: Tilemap, layer: TilemapLayer, x: number, y: number, tileName: string) { - const tileImg = zone.getTileset(tileName) as Tileset - if (!tileImg) return + let tileImg = zone.getTileset(tileName) as Tileset + if (!tileImg) { + tileImg = zone.getTileset('blank_tile') as Tileset + } layer.putTileAt(tileImg.firstgid, x, y) }