forked from noxious/client
Bug fixes for updating zone width and height (realtime now), removed redundant code from camera composable, improved zone editor tool modal logics.
This commit is contained in:
parent
717fb1646c
commit
bb08aaa9bc
10
package-lock.json
generated
10
package-lock.json
generated
@ -5630,9 +5630,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/postcss": {
|
"node_modules/postcss": {
|
||||||
"version": "8.4.45",
|
"version": "8.4.47",
|
||||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.45.tgz",
|
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.47.tgz",
|
||||||
"integrity": "sha512-7KTLTdzdZZYscUc65XmjFiB73vBhBfbPztCYdUNvlaso9PrzjzcmjqBPR0lNGkcVlcO4BjiO5rK/qNz+XAen1Q==",
|
"integrity": "sha512-56rxCq7G/XfB4EkXq9Egn5GCqugWvDFjafDOThIdMBsI15iqPqR5r15TfSr1YPYeEI19YeaXMCbY6u88Y76GLQ==",
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"type": "opencollective",
|
"type": "opencollective",
|
||||||
@ -5650,8 +5650,8 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"nanoid": "^3.3.7",
|
"nanoid": "^3.3.7",
|
||||||
"picocolors": "^1.0.1",
|
"picocolors": "^1.1.0",
|
||||||
"source-map-js": "^1.2.0"
|
"source-map-js": "^1.2.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^10 || ^12 || >=14"
|
"node": "^10 || ^12 || >=14"
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<Toolbar :layer="tiles" @eraser="eraser" @pencil="pencil" @paint="paint" @clear="clear" @save="save" />
|
||||||
|
<ZoneList v-if="zoneEditorStore.isZoneListModalShown" />
|
||||||
|
|
||||||
|
<template v-if="zoneEditorStore.zone">
|
||||||
|
<Tiles />
|
||||||
|
<Objects />
|
||||||
|
<ZoneSettings />
|
||||||
|
<TeleportModal v-if="shouldShowTeleportModal" />
|
||||||
<TilemapLayerC :tilemap="zoneTilemap as Tilemap" :tileset="tileArray as any" :layerIndex="0" :cull-padding="10" />
|
<TilemapLayerC :tilemap="zoneTilemap as Tilemap" :tileset="tileArray as any" :layerIndex="0" :cull-padding="10" />
|
||||||
<Controls :layer="tiles as TilemapLayer" />
|
<Controls :layer="tiles as TilemapLayer" />
|
||||||
|
|
||||||
@ -10,24 +18,19 @@
|
|||||||
<Image v-for="tile in zoneEventTiles" :key="tile.id" v-bind="getEventTileImageProps(tile)" />
|
<Image v-for="tile in zoneEventTiles" :key="tile.id" v-bind="getEventTileImageProps(tile)" />
|
||||||
</Container>
|
</Container>
|
||||||
|
|
||||||
<Toolbar :layer="tiles" @eraser="eraser" @pencil="pencil" @paint="paint" @clear="clear" @save="save" />
|
|
||||||
<SelectedZoneObject v-if="zoneEditorStore.selectedZoneObject" @update_depth="updateZoneObjectDepth" @delete="deleteZoneObject" @move="handleMove" />
|
<SelectedZoneObject v-if="zoneEditorStore.selectedZoneObject" @update_depth="updateZoneObjectDepth" @delete="deleteZoneObject" @move="handleMove" />
|
||||||
<Tiles v-if="zoneEditorStore.isTileListModalShown" />
|
</template>
|
||||||
<Objects v-if="zoneEditorStore.isObjectListModalShown" />
|
|
||||||
<ZoneSettings v-if="zoneEditorStore.isSettingsModalShown" />
|
|
||||||
<ZoneList v-if="zoneEditorStore.isZoneListModalShown" />
|
|
||||||
<TeleportModal v-if="shouldShowTeleportModal" />
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onBeforeMount, onBeforeUnmount, ref, watch } from 'vue'
|
import { computed, onBeforeMount, onUnmounted, ref, watch } from 'vue'
|
||||||
import { Container, Image, TilemapLayer as TilemapLayerC, useScene } from 'phavuer'
|
import { Container, Image, TilemapLayer as TilemapLayerC, useScene } from 'phavuer'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { useGameStore } from '@/stores/game'
|
import { useGameStore } from '@/stores/game'
|
||||||
import { useZoneEditorStore } from '@/stores/zoneEditor'
|
import { useZoneEditorStore } from '@/stores/zoneEditor'
|
||||||
import { useAssetStore } from '@/stores/assets'
|
import { useAssetStore } from '@/stores/assets'
|
||||||
import { placeTile, setAllTiles, sortByDepth, tileToWorldX, tileToWorldY } from '@/services/zone'
|
import { placeTile, setAllTiles, sortByDepth, tileToWorldX, tileToWorldY } from '@/services/zone'
|
||||||
import { ZoneEventTileType, type ZoneObject, type ZoneEventTile } from '@/types'
|
import { ZoneEventTileType, type ZoneObject, type ZoneEventTile, type Zone } from '@/types'
|
||||||
import { uuidv4 } from '@/utilities'
|
import { uuidv4 } from '@/utilities'
|
||||||
import config from '@/config'
|
import config from '@/config'
|
||||||
|
|
||||||
@ -78,7 +81,9 @@ function createTileLayer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createTileArray() {
|
function createTileArray() {
|
||||||
return Array.from({ length: zone.value?.width ?? 0 }, () => Array.from({ length: zone.value?.height ?? 0 }, () => 'blank_tile'))
|
return Array.from({ length: zoneTilemap.value.height || 0 }, () =>
|
||||||
|
Array.from({ length: zoneTilemap.value.width || 0 }, () => 'blank_tile')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getObjectImageProps(object: ZoneObject) {
|
function getObjectImageProps(object: ZoneObject) {
|
||||||
@ -166,36 +171,59 @@ function addZoneEventTile(tile: Phaser.Tilemaps.Tile) {
|
|||||||
|
|
||||||
function paint() {
|
function paint() {
|
||||||
if (!selectedTile.value) return
|
if (!selectedTile.value) return
|
||||||
tileArray.value.forEach((row, y) =>
|
|
||||||
row.forEach((_, x) => {
|
// Ensure tileArray is initialized with correct dimensions
|
||||||
placeTile(zoneTilemap.value as Tilemap, tiles.value as TilemapLayer, x, y, selectedTile.value!.id)
|
if (!tileArray.value || tileArray.value.length !== zoneTilemap.value.height) {
|
||||||
tileArray.value[y][x] = selectedTile.value!.id
|
tileArray.value = Array.from({ length: zoneTilemap.value.height }, () =>
|
||||||
})
|
Array.from({ length: zoneTilemap.value.width }, () => 'blank_tile')
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set all tiles in the tilemap to the selected tile's id
|
||||||
|
for (let y = 0; y < zoneTilemap.value.height; y++) {
|
||||||
|
if (!tileArray.value[y]) {
|
||||||
|
tileArray.value[y] = Array(zoneTilemap.value.width).fill('blank_tile')
|
||||||
|
}
|
||||||
|
for (let x = 0; x < zoneTilemap.value.width; x++) {
|
||||||
|
placeTile(zoneTilemap.value as Tilemap, tiles.value as TilemapLayer, x, y, selectedTile.value.id)
|
||||||
|
tileArray.value[y][x] = selectedTile.value.id
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
if (!zone.value) return
|
if (!zone.value) return
|
||||||
console.log('update')
|
|
||||||
const data = {
|
const data = {
|
||||||
zoneId: zone.value.id,
|
zoneId: zone.value.id,
|
||||||
name: zone.value.name,
|
name: zoneEditorStore.zoneSettings.name,
|
||||||
width: zone.value.width,
|
width: zoneEditorStore.zoneSettings.width,
|
||||||
height: zone.value.height,
|
height: zoneEditorStore.zoneSettings.height,
|
||||||
tiles: tileArray.value,
|
tiles: tileArray.value,
|
||||||
pvp: zone.value.pvp,
|
pvp: zone.value.pvp,
|
||||||
zoneEventTiles: zoneEventTiles.value.map(({ id, zoneId, type, positionX, positionY, teleport }) => ({ id, zoneId, type, positionX, positionY, teleport })),
|
zoneEventTiles: zoneEventTiles.value.map(({ id, zoneId, type, positionX, positionY, teleport }) => ({ id, zoneId, type, positionX, positionY, teleport })),
|
||||||
zoneObjects: zoneObjects.value.map(({ id, zoneId, objectId, depth, positionX, positionY }) => ({ id, zoneId, objectId, depth, positionX, positionY }))
|
zoneObjects: zoneObjects.value.map(({ id, zoneId, objectId, depth, positionX, positionY }) => ({ id, zoneId, objectId, depth, positionX, positionY }))
|
||||||
}
|
}
|
||||||
gameStore.connection?.emit('gm:zone_editor:zone:update', data)
|
|
||||||
if (zoneEditorStore.isSettingsModalShown) {
|
if (zoneEditorStore.isSettingsModalShown) {
|
||||||
zoneEditorStore.toggleSettingsModal()
|
zoneEditorStore.toggleSettingsModal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gameStore.connection?.emit('gm:zone_editor:zone:update', data, (response: Zone) => {
|
||||||
|
zoneEditorStore.setZone(response)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function clear() {
|
function clear() {
|
||||||
tileArray.value.forEach((row, y) => row.forEach((_, x) => placeTile(zoneTilemap.value as Tilemap, tiles.value as TilemapLayer, x, y, 'blank_tile')))
|
for (let y = 0; y < zoneTilemap.value.height; y++) {
|
||||||
tileArray.value = createTileArray()
|
if (!tileArray.value[y]) {
|
||||||
|
tileArray.value[y] = Array(zoneTilemap.value.width).fill('blank_tile')
|
||||||
|
}
|
||||||
|
for (let x = 0; x < zoneTilemap.value.width; x++) {
|
||||||
|
placeTile(zoneTilemap.value as Tilemap, tiles.value as TilemapLayer, x, y, 'blank_tile')
|
||||||
|
tileArray.value[y][x] = 'blank_tile'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
zoneEventTiles.value = []
|
zoneEventTiles.value = []
|
||||||
zoneObjects.value = []
|
zoneObjects.value = []
|
||||||
}
|
}
|
||||||
@ -229,7 +257,7 @@ onBeforeMount(() => {
|
|||||||
scene.cameras.main.centerOn(centerX, centerY)
|
scene.cameras.main.centerOn(centerX, centerY)
|
||||||
})
|
})
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onUnmounted(() => {
|
||||||
zoneEventTiles.value = []
|
zoneEventTiles.value = []
|
||||||
zoneObjects.value = []
|
zoneObjects.value = []
|
||||||
tiles.value?.destroy()
|
tiles.value?.destroy()
|
||||||
@ -273,6 +301,7 @@ watch(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const setSelectedZoneObject = (zoneObject: ZoneObject | null) => {
|
const setSelectedZoneObject = (zoneObject: ZoneObject | null) => {
|
||||||
|
console.log('setSelectedZoneObject', zoneObject)
|
||||||
if (!zoneObject) return
|
if (!zoneObject) return
|
||||||
// Check if tool is move or return
|
// Check if tool is move or return
|
||||||
if (zoneEditorStore.tool !== 'move') return
|
if (zoneEditorStore.tool !== 'move') return
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<Teleport to="body">
|
<Teleport to="body">
|
||||||
<Modal v-if="isModalOpen" @modal:close="() => (zoneEditorStore.isObjectListModalShown = false)" :isModalOpen="true" :modal-width="645" :modal-height="260">
|
<Modal :isModalOpen="zoneEditorStore.isObjectListModalShown" :modal-width="645" :modal-height="260" @modal:close="() => (zoneEditorStore.isObjectListModalShown = false)">
|
||||||
<template #modalHeader>
|
<template #modalHeader>
|
||||||
<h3 class="text-lg">Objects</h3>
|
<h3 class="text-lg">Objects</h3>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<Teleport to="body">
|
<Teleport to="body">
|
||||||
<Modal v-if="isModalOpen" @modal:close="() => (zoneEditorStore.isTileListModalShown = false)" :isModalOpen="true" :modal-width="645" :modal-height="600">
|
<Modal :isModalOpen="zoneEditorStore.isTileListModalShown" :modal-width="645" :modal-height="600" @modal:close="() => (zoneEditorStore.isTileListModalShown = false)">
|
||||||
<template #modalHeader>
|
<template #modalHeader>
|
||||||
<h3 class="text-lg">Tiles</h3>
|
<h3 class="text-lg">Tiles</h3>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<Modal :is-modal-open="true" @modal:close="() => zoneEditorStore.toggleSettingsModal()" :modal-width="300" :modal-height="350" :is-resizable="false">
|
<Modal :is-modal-open="zoneEditorStore.isSettingsModalShown" @modal:close="() => zoneEditorStore.toggleSettingsModal()" :modal-width="300" :modal-height="350" :is-resizable="false">
|
||||||
<template #modalHeader>
|
<template #modalHeader>
|
||||||
<h3 class="m-0 font-medium shrink-0">Zone settings</h3>
|
<h3 class="m-0 font-medium shrink-0">Zone settings</h3>
|
||||||
</template>
|
</template>
|
||||||
@ -41,10 +41,15 @@ import { useZoneEditorStore } from '@/stores/zoneEditor.ts'
|
|||||||
|
|
||||||
const zoneEditorStore = useZoneEditorStore()
|
const zoneEditorStore = useZoneEditorStore()
|
||||||
|
|
||||||
const name = ref(zoneEditorStore.zone?.name)
|
zoneEditorStore.setZoneName(zoneEditorStore.zone.name)
|
||||||
const width = ref(zoneEditorStore.zone?.width)
|
zoneEditorStore.setZoneWidth(zoneEditorStore.zone.width)
|
||||||
const height = ref(zoneEditorStore.zone?.height)
|
zoneEditorStore.setZoneHeight(zoneEditorStore.zone.height)
|
||||||
const pvp = ref(zoneEditorStore.zone?.pvp)
|
zoneEditorStore.setZonePvp(zoneEditorStore.zone.pvp)
|
||||||
|
|
||||||
|
const name = ref(zoneEditorStore.zoneSettings.name)
|
||||||
|
const width = ref(zoneEditorStore.zoneSettings.width)
|
||||||
|
const height = ref(zoneEditorStore.zoneSettings.height)
|
||||||
|
const pvp = ref(zoneEditorStore.zoneSettings.pvp)
|
||||||
|
|
||||||
watch(name, (value) => {
|
watch(name, (value) => {
|
||||||
zoneEditorStore.setZoneName(value)
|
zoneEditorStore.setZoneName(value)
|
||||||
|
@ -5,35 +5,17 @@ export function useCameraControls(scene: Phaser.Scene): any {
|
|||||||
const gameStore = useGameStore()
|
const gameStore = useGameStore()
|
||||||
const camera = ref(scene.cameras.main)
|
const camera = ref(scene.cameras.main)
|
||||||
const isDragging = ref(false)
|
const isDragging = ref(false)
|
||||||
let pointerDownTimer: number | null | NodeJS.Timeout = null
|
|
||||||
let pointerUpTimer: number | null | NodeJS.Timeout = null
|
|
||||||
|
|
||||||
const DRAG_DELAY = 150
|
|
||||||
const MOVE_RESET_DELAY = 100
|
|
||||||
|
|
||||||
function onPointerDown(pointer: Phaser.Input.Pointer) {
|
function onPointerDown(pointer: Phaser.Input.Pointer) {
|
||||||
if (pointer.event instanceof MouseEvent || pointer.event.shiftKey) {
|
if (pointer.event instanceof MouseEvent || pointer.event.shiftKey) {
|
||||||
pointerDownTimer = setTimeout(() => {
|
|
||||||
isDragging.value = true
|
isDragging.value = true
|
||||||
gameStore.setMovingCamera(true)
|
gameStore.setMovingCamera(true)
|
||||||
}, DRAG_DELAY)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPointerUp() {
|
function onPointerUp() {
|
||||||
if (pointerDownTimer) {
|
|
||||||
clearTimeout(pointerDownTimer)
|
|
||||||
pointerDownTimer = null
|
|
||||||
}
|
|
||||||
isDragging.value = false
|
isDragging.value = false
|
||||||
|
|
||||||
if (pointerUpTimer) {
|
|
||||||
clearTimeout(pointerUpTimer)
|
|
||||||
}
|
|
||||||
|
|
||||||
pointerUpTimer = setTimeout(() => {
|
|
||||||
gameStore.setMovingCamera(false)
|
gameStore.setMovingCamera(false)
|
||||||
}, MOVE_RESET_DELAY)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scene.input.on(Phaser.Input.Events.POINTER_DOWN, onPointerDown)
|
scene.input.on(Phaser.Input.Events.POINTER_DOWN, onPointerDown)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const dev: boolean = false
|
const dev: boolean = true
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'New Quest',
|
name: 'New Quest',
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
<div v-if="zoneEditorStore.active">
|
<div v-if="zoneEditorStore.active">
|
||||||
<Game :config="gameConfig" @create="createGame">
|
<Game :config="gameConfig" @create="createGame">
|
||||||
<Scene name="main" @preload="preloadScene" @create="createScene">
|
<Scene name="main" @preload="preloadScene" @create="createScene">
|
||||||
<ZoneEditor v-if="isLoaded" :key="zoneEditorStore.zone?.id ?? 0" />
|
<ZoneEditor v-if="isLoaded" :key="JSON.stringify(zoneEditorStore.zone)" />
|
||||||
</Scene>
|
</Scene>
|
||||||
</Game>
|
</Game>
|
||||||
</div>
|
</div>
|
||||||
|
@ -27,6 +27,12 @@ export const useZoneEditorStore = defineStore('zoneEditor', {
|
|||||||
isZoneListModalShown: false,
|
isZoneListModalShown: false,
|
||||||
isCreateZoneModalShown: false,
|
isCreateZoneModalShown: false,
|
||||||
isSettingsModalShown: false,
|
isSettingsModalShown: false,
|
||||||
|
zoneSettings: {
|
||||||
|
name: '',
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
pvp: false
|
||||||
|
},
|
||||||
teleportSettings: {
|
teleportSettings: {
|
||||||
toZoneId: 0,
|
toZoneId: 0,
|
||||||
toPositionX: 0,
|
toPositionX: 0,
|
||||||
@ -38,28 +44,21 @@ export const useZoneEditorStore = defineStore('zoneEditor', {
|
|||||||
if (this.active) this.reset()
|
if (this.active) this.reset()
|
||||||
this.active = !this.active
|
this.active = !this.active
|
||||||
},
|
},
|
||||||
setZone(zone: Zone) {
|
setZone(zone: Zone | null) {
|
||||||
this.zone = zone
|
this.zone = zone
|
||||||
},
|
},
|
||||||
setZoneName(name: string) {
|
setZoneName(name: string) {
|
||||||
if (this.zone) {
|
this.zoneSettings.name = name
|
||||||
this.zone.name = name
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
setZoneWidth(width: number) {
|
setZoneWidth(width: number) {
|
||||||
if (this.zone) {
|
this.zoneSettings.width = width
|
||||||
this.zone.width = width
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
setZoneHeight(height: number) {
|
setZoneHeight(height: number) {
|
||||||
if (this.zone) {
|
this.zoneSettings.height = height
|
||||||
this.zone.height = height
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
setZonePvp(pvp: boolean) {
|
setZonePvp(pvp: boolean) {
|
||||||
if (this.zone) {
|
if (!this.zone) return
|
||||||
this.zone.pvp = pvp
|
this.zone.pvp = pvp
|
||||||
}
|
|
||||||
},
|
},
|
||||||
setTool(tool: string) {
|
setTool(tool: string) {
|
||||||
this.tool = tool
|
this.tool = tool
|
||||||
@ -86,9 +85,6 @@ export const useZoneEditorStore = defineStore('zoneEditor', {
|
|||||||
this.selectedObject = object
|
this.selectedObject = object
|
||||||
},
|
},
|
||||||
setSelectedZoneObject(zoneObject: ZoneObject | null) {
|
setSelectedZoneObject(zoneObject: ZoneObject | null) {
|
||||||
const gameStore = useGameStore() // Access the gameStore
|
|
||||||
if (gameStore.isMovingCamera) return // Step 2: Check isMovingCamera before proceeding
|
|
||||||
|
|
||||||
this.selectedZoneObject = zoneObject
|
this.selectedZoneObject = zoneObject
|
||||||
},
|
},
|
||||||
setObjectDepth(depth: number) {
|
setObjectDepth(depth: number) {
|
||||||
@ -108,6 +104,7 @@ export const useZoneEditorStore = defineStore('zoneEditor', {
|
|||||||
this.teleportSettings = teleportSettings
|
this.teleportSettings = teleportSettings
|
||||||
},
|
},
|
||||||
reset() {
|
reset() {
|
||||||
|
// this.zone = null
|
||||||
this.zoneList = []
|
this.zoneList = []
|
||||||
this.tileList = []
|
this.tileList = []
|
||||||
this.objectList = []
|
this.objectList = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user