From 6065a9c77e779309a6ef01f3cdbf03f9c94017db Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Sun, 7 Jul 2024 12:29:49 +0200 Subject: [PATCH] Make zone loading dynamic --- .../utilities/zoneEditor/ZoneEditor.vue | 249 +++++++++++------- .../utilities/zoneEditor/ZoneList.vue | 8 +- src/services/zone.ts | 13 + src/stores/zoneEditor.ts | 45 +--- 4 files changed, 176 insertions(+), 139 deletions(-) diff --git a/src/components/utilities/zoneEditor/ZoneEditor.vue b/src/components/utilities/zoneEditor/ZoneEditor.vue index 2f6807a..06b49fc 100644 --- a/src/components/utilities/zoneEditor/ZoneEditor.vue +++ b/src/components/utilities/zoneEditor/ZoneEditor.vue @@ -1,16 +1,21 @@ + \ No newline at end of file diff --git a/src/components/utilities/zoneEditor/ZoneList.vue b/src/components/utilities/zoneEditor/ZoneList.vue index 4737473..2094afe 100644 --- a/src/components/utilities/zoneEditor/ZoneList.vue +++ b/src/components/utilities/zoneEditor/ZoneList.vue @@ -51,9 +51,11 @@ function fetchZones() { function loadZone(id: number) { console.log('loadZone', id) - socket.connection.emit('gm:zone_editor:zone:load', { zoneId: id }, () => { - zoneEditorStore.toggleZoneListModal() - }) + socket.connection.emit('gm:zone_editor:zone:request', { zoneId: id }, (response: Zone) => { + console.log('!!zone', response) + zoneEditorStore.setZone(response) + }); + zoneEditorStore.toggleZoneListModal() } function deleteZone(id: number) { diff --git a/src/services/zone.ts b/src/services/zone.ts index 5b359c8..88fc555 100644 --- a/src/services/zone.ts +++ b/src/services/zone.ts @@ -32,4 +32,17 @@ export function placeTile(zone: Tilemap, layer: TilemapLayer, x: number, y: numb layer.putTileAt(tileImg.firstgid, x, y) } +export function getTiles(zone: Tilemap): string[][] { + const tiles = [] + for (let y = 0; y < zone.height; y++) { + const row = [] + for (let x = 0; x < zone.width; x++) { + const tile = zone.getTileAt(x, y) + row.push(!tile?.index ? 'blank_tile' : zone.tilesets[tile.index].name) + } + tiles.push(row) + } + return tiles +} + export function generateTilemap(scene: Phaser.Scene, width: number, height: number) {} diff --git a/src/stores/zoneEditor.ts b/src/stores/zoneEditor.ts index 4cd54a3..6bbea89 100644 --- a/src/stores/zoneEditor.ts +++ b/src/stores/zoneEditor.ts @@ -1,19 +1,14 @@ import { defineStore } from 'pinia' -import type { Object, ZoneObject } from '@/types' +import type { Object, ZoneObject, Zone } from '@/types' export const useZoneEditorStore = defineStore('zoneEditor', { state: () => ({ active: true, - name: '', - width: 10, - height: 10, + zone: null as Zone | null, tool: 'move', drawMode: 'tile', tileList: [] as string[], - tiles: [] as string[][], objectList: [] as Object[], - objects: [] as ZoneObject[], - selectedTile: '', selectedObject: null as Object | null, isZoneListModalShown: false, @@ -24,14 +19,8 @@ export const useZoneEditorStore = defineStore('zoneEditor', { toggleActive() { this.active = !this.active }, - setName(name: string) { - this.name = name - }, - setWidth(width: number) { - this.width = width - }, - setHeight(height: number) { - this.height = height + setZone(zone: Zone) { + this.zone = zone }, setTool(tool: string) { this.tool = tool @@ -42,21 +31,9 @@ export const useZoneEditorStore = defineStore('zoneEditor', { setTileList(tiles: string[]) { this.tileList = tiles }, - setTiles(tiles: string[][]) { - this.tiles = tiles - }, - updateTile(x: number, y: number, tile: string) { - this.tiles[y][x] = tile - }, setObjectList(objects: Object[]) { this.objectList = objects }, - setObjects(objects: ZoneObject[]) { - this.objects = objects - }, - updateObject(index: number, object: ZoneObject) { - this.objects[index] = object - }, setSelectedTile(tile: string) { this.selectedTile = tile }, @@ -74,13 +51,9 @@ export const useZoneEditorStore = defineStore('zoneEditor', { this.isCreateZoneModalShown = !this.isCreateZoneModalShown }, reset() { - this.name = '' - this.width = 10 - this.height = 10 + this.zone = null this.tileList = [] - this.tiles = [] this.objectList = [] - this.objects = [] this.tool = 'move' this.drawMode = 'tile' this.selectedTile = '' @@ -90,10 +63,4 @@ export const useZoneEditorStore = defineStore('zoneEditor', { this.isCreateZoneModalShown = false } } -}) - -/** - * Resources: - * https://www.html5gamedevs.com/topic/21908-phaser-is-there-any-tutorial-on-how-to-do-an-isometric-game/ - * http://murdochcarpenter.com/isometric-starling-part-i/ - */ +}) \ No newline at end of file