Added option to set rotation on teleport tiles

This commit is contained in:
Dennis Postma 2024-09-23 14:02:00 +02:00
parent 2f555636bc
commit 0f01a4ec7c
4 changed files with 35 additions and 28 deletions

View File

@ -170,7 +170,8 @@ function addZoneEventTile(tile: Phaser.Tilemaps.Tile) {
? { ? {
toZoneId: zoneEditorStore.teleportSettings.toZoneId, toZoneId: zoneEditorStore.teleportSettings.toZoneId,
toPositionX: zoneEditorStore.teleportSettings.toPositionX, toPositionX: zoneEditorStore.teleportSettings.toPositionX,
toPositionY: zoneEditorStore.teleportSettings.toPositionY toPositionY: zoneEditorStore.teleportSettings.toPositionY,
toRotation: zoneEditorStore.teleportSettings.toRotation
} }
: undefined : undefined
} }
@ -215,6 +216,7 @@ function save() {
} }
gameStore.connection?.emit('gm:zone_editor:zone:update', data, (response: Zone) => { gameStore.connection?.emit('gm:zone_editor:zone:update', data, (response: Zone) => {
console.log('zone updated')
zoneEditorStore.setZone(response) zoneEditorStore.setZone(response)
}) })
} }

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal :is-modal-open="true" @modal:close="() => zoneEditorStore.setTool('move')" :modal-width="300" :modal-height="250" :is-resizable="false"> <Modal :is-modal-open="true" @modal:close="() => zoneEditorStore.setTool('move')" :modal-width="300" :modal-height="350" :is-resizable="false">
<template #modalHeader> <template #modalHeader>
<h3 class="m-0 font-medium shrink-0">Teleport settings</h3> <h3 class="m-0 font-medium shrink-0">Teleport settings</h3>
</template> </template>
@ -16,6 +16,15 @@
<label for="positionY">Position Y</label> <label for="positionY">Position Y</label>
<input class="input-cyan" v-model="toPositionY" name="positionY" id="positionY" type="number" /> <input class="input-cyan" v-model="toPositionY" name="positionY" id="positionY" type="number" />
</div> </div>
<div class="form-field-full">
<label for="rotation">Rotation</label>
<select v-model="toRotation" class="input-cyan" name="rotation" id="rotation">
<option :value="0">North</option>
<option :value="2">East</option>
<option :value="4">South</option>
<option :value="6">West</option>
</select>
</div>
<div class="form-field-full"> <div class="form-field-full">
<label for="toZoneId">Zone to teleport to</label> <label for="toZoneId">Zone to teleport to</label>
<select v-model="toZoneId" class="input-cyan" name="toZoneId" id="toZoneId"> <select v-model="toZoneId" class="input-cyan" name="toZoneId" id="toZoneId">
@ -40,9 +49,7 @@ import type { Zone } from '@/types'
const zoneEditorStore = useZoneEditorStore() const zoneEditorStore = useZoneEditorStore()
const gameStore = useGameStore() const gameStore = useGameStore()
onMounted(async () => { onMounted(fetchZones)
fetchZones()
})
function fetchZones() { function fetchZones() {
gameStore.connection?.emit('gm:zone_editor:zone:list', {}, (response: Zone[]) => { gameStore.connection?.emit('gm:zone_editor:zone:list', {}, (response: Zone[]) => {
@ -50,31 +57,26 @@ function fetchZones() {
}) })
} }
const toPositionX = ref(zoneEditorStore.teleportSettings.toPositionX) const { toPositionX, toPositionY, toRotation, toZoneId } = useRefTeleportSettings()
const toPositionY = ref(zoneEditorStore.teleportSettings.toPositionY)
const toZoneId = ref(zoneEditorStore.teleportSettings.toZoneId)
watch(toZoneId, (value) => { function useRefTeleportSettings() {
const settings = zoneEditorStore.teleportSettings
return {
toPositionX: ref(settings.toPositionX),
toPositionY: ref(settings.toPositionY),
toRotation: ref(settings.toRotation),
toZoneId: ref(settings.toZoneId)
}
}
watch([toPositionX, toPositionY, toRotation, toZoneId], updateTeleportSettings)
function updateTeleportSettings() {
zoneEditorStore.setTeleportSettings({ zoneEditorStore.setTeleportSettings({
toPositionX: toPositionX.value, toPositionX: toPositionX.value,
toPositionY: toPositionY.value, toPositionY: toPositionY.value,
toZoneId: value toRotation: toRotation.value,
})
})
watch(toPositionX, (value) => {
zoneEditorStore.setTeleportSettings({
toPositionX: value,
toPositionY: toPositionY.value,
toZoneId: toZoneId.value toZoneId: toZoneId.value
}) })
}) }
watch(toPositionY, (value) => {
zoneEditorStore.setTeleportSettings({
toPositionX: toPositionX.value,
toPositionY: value,
toZoneId: toZoneId.value
})
})
</script> </script>

View File

@ -6,6 +6,7 @@ type TeleportSettings = {
toZoneId: number toZoneId: number
toPositionX: number toPositionX: number
toPositionY: number toPositionY: number
toRotation: number
} }
export const useZoneEditorStore = defineStore('zoneEditor', { export const useZoneEditorStore = defineStore('zoneEditor', {
@ -36,7 +37,8 @@ export const useZoneEditorStore = defineStore('zoneEditor', {
teleportSettings: { teleportSettings: {
toZoneId: 0, toZoneId: 0,
toPositionX: 0, toPositionX: 0,
toPositionY: 0 toPositionY: 0,
toRotation: 0
} }
}), }),
actions: { actions: {

View File

@ -95,6 +95,7 @@ export type ZoneEventTileTeleport = {
toZone: Zone toZone: Zone
toPositionX: number toPositionX: number
toPositionY: number toPositionY: number
toRotation: number
} }
export type User = { export type User = {