1
0
forked from noxious/client

tile editor wip

This commit is contained in:
Dennis Postma 2024-06-13 22:55:29 +02:00
parent 4bc076d55d
commit b36c8117e7
5 changed files with 51 additions and 24 deletions

View File

@ -28,13 +28,13 @@
</select> </select>
</button> </button>
<div class="divider"></div> <div class="divider"></div>
<button @click="() => zoneEditorStore.toggleZoneSettings()"> <button @click="() => zoneEditorStore.toggleSettingsModal()">
<img src="/assets/icons/zoneEditor/gear.svg" alt="Zone settings" /> <img src="/assets/icons/zoneEditor/gear.svg" alt="Zone settings" />
</button> </button>
</div> </div>
<div class="buttons"> <div class="buttons">
<button class="btn-cyan">Save</button>
<button class="btn-cyan">Load</button> <button class="btn-cyan">Load</button>
<button class="btn-cyan">Save</button>
<button class="btn-cyan" @click="clear">Clear</button> <button class="btn-cyan" @click="clear">Clear</button>
<button class="btn-cyan" @click="() => zoneEditorStore.toggleActive()">Exit</button> <button class="btn-cyan" @click="() => zoneEditorStore.toggleActive()">Exit</button>
</div> </div>

View File

@ -4,7 +4,7 @@
<Toolbar :layer="layer" @eraser="eraser" @pencil="pencil" /> <Toolbar :layer="layer" @eraser="eraser" @pencil="pencil" />
<Tiles v-if="zoneEditorStore.tool === 'pencil' || zoneEditorStore.tool === 'eraser'" /> <Tiles v-if="zoneEditorStore.tool === 'pencil' || zoneEditorStore.tool === 'eraser'" />
<Walls v-if="zoneEditorStore.tool === 'pencil' || zoneEditorStore.tool === 'eraser'" /> <Walls v-if="zoneEditorStore.tool === 'pencil' || zoneEditorStore.tool === 'eraser'" />
<ZoneSettings v-if="zoneEditorStore.zoneSettingsOpen" /> <ZoneSettings v-if="zoneEditorStore.isSettingsModalShown" />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@ -21,6 +21,7 @@ import { useZoneEditorStore } from '@/stores/zoneEditor'
import ZoneSettings from '@/components/utilities/zoneEditor/ZoneSettings.vue' import ZoneSettings from '@/components/utilities/zoneEditor/ZoneSettings.vue'
import Walls from '@/components/utilities/zoneEditor/Walls.vue' import Walls from '@/components/utilities/zoneEditor/Walls.vue'
import { generateTilemap } from '@/services/zone' import { generateTilemap } from '@/services/zone'
import type { Zone } from '@/types'
// Phavuer logic // Phavuer logic
let scene = useScene() let scene = useScene()
@ -54,10 +55,11 @@ watch(
{ deep: true } { deep: true }
) )
socket.connection.on('gm:zone_editor:zone:load', (data) => { socket.connection.on('gm:zone_editor:zone:load', (data: Zone) => {
tileMap = generateTilemap(scene, data.zone.width, data.zone.height); tileMap = generateTilemap(scene, data.width, data.height);
zoneEditorStore.setZoneSettings(data.zone) zoneEditorStore.setName(data.name)
zoneEditorStore.setTiles(data.zone.tiles) zoneEditorStore.setWidth(data.width)
zoneEditorStore.setTiles(data.tiles)
}) })
function eraser(tile: Phaser.Tilemaps.Tile) { function eraser(tile: Phaser.Tilemaps.Tile) {

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal :isModalOpen="true" @modal:close="() => zoneEditorStore.toggleZoneSettings()"> <Modal :isModalOpen="true" @modal:close="() => zoneEditorStore.toggleSettingsModal()">
<template #modalHeader> <template #modalHeader>
<h3 class="modal-title">Zone settings</h3> <h3 class="modal-title">Zone settings</h3>
</template> </template>
@ -9,15 +9,15 @@
<div class="form-fields"> <div class="form-fields">
<div> <div>
<label for="name">Name</label> <label for="name">Name</label>
<input name="name" id="name" /> <input v-model="name" name="name" id="name" />
</div> </div>
<div> <div>
<label for="name">Width</label> <label for="name">Width</label>
<input name="name" id="name" /> <input v-model="width" name="name" id="name" />
</div> </div>
<div> <div>
<label for="name">Height</label> <label for="name">Height</label>
<input name="name" id="name" /> <input v-model="height" name="name" id="name" />
</div> </div>
<div> <div>
<label for="name">PVP enabled</label> <label for="name">PVP enabled</label>
@ -30,9 +30,26 @@
</template> </template>
<script setup> <script setup>
import { ref } from 'vue' import { ref, watch } from 'vue'
import Modal from '@/components/utilities/Modal.vue' import Modal from '@/components/utilities/Modal.vue'
import { useZoneEditorStore } from '@/stores/zoneEditor' import { useZoneEditorStore } from '@/stores/zoneEditor'
const zoneEditorStore = useZoneEditorStore() const zoneEditorStore = useZoneEditorStore()
const name = ref(zoneEditorStore.name)
const width = ref(zoneEditorStore.width)
const height = ref(zoneEditorStore.height)
watch(name, (value) => {
zoneEditorStore.setName(value)
})
watch(width, (value) => {
zoneEditorStore.setWidth(value)
})
watch(height, (value) => {
zoneEditorStore.setHeight(value)
})
</script> </script>

View File

@ -1,23 +1,32 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import config from '@/config'
import {type Zone} from '@/types'
export const useZoneEditorStore = defineStore('zoneEditor', { export const useZoneEditorStore = defineStore('zoneEditor', {
state: () => ({ state: () => ({
active: false, active: false,
name: '',
width: 10,
height: 10,
tiles: [] as number[][], tiles: [] as number[][],
tool: 'move', tool: 'move',
drawMode: 'tile', drawMode: 'tile',
selectedTile: null, selectedTile: null,
selectedWall: null, selectedWall: null,
selectedDecoration: null, selectedDecoration: null,
zoneSettings: null as Zone | null, isSettingsModalShown: false
zoneSettingsOpen: false
}), }),
actions: { actions: {
toggleActive() { toggleActive() {
this.active = !this.active this.active = !this.active
}, },
setName(name: string) {
this.name = name
},
setWidth(width: number) {
this.width = width
},
setHeight(height: number) {
this.height = height
},
setTiles(tiles: number[][]) { setTiles(tiles: number[][]) {
this.tiles = tiles this.tiles = tiles
}, },
@ -36,21 +45,20 @@ export const useZoneEditorStore = defineStore('zoneEditor', {
setSelectedDecoration(decoration: any) { setSelectedDecoration(decoration: any) {
this.selectedDecoration = decoration this.selectedDecoration = decoration
}, },
setZoneSettings(zone: Zone) { toggleSettingsModal() {
this.zoneSettings = zone this.isSettingsModalShown = !this.isSettingsModalShown
},
toggleZoneSettings() {
this.zoneSettingsOpen = !this.zoneSettingsOpen
}, },
reset() { reset() {
this.name = ''
this.width = 10
this.height = 10
this.tiles = [] this.tiles = []
this.tool = 'move' this.tool = 'move'
this.drawMode = 'tile' this.drawMode = 'tile'
this.selectedTile = null this.selectedTile = null
this.selectedWall = null this.selectedWall = null
this.selectedDecoration = null this.selectedDecoration = null
this.zoneSettings = null this.isSettingsModalShown = false
this.zoneSettingsOpen = false
} }
} }
}) })

View File

@ -33,7 +33,7 @@ export type Zone = {
name: string name: string
width: number width: number
height: number height: number
tiles: Record<string, any> tiles: number[][]
characters: Character[] characters: Character[]
chats: Chat[] chats: Chat[]
} }