Works partially 💩

This commit is contained in:
Zaxiure 2024-10-15 23:48:50 +02:00
parent a6c22df528
commit a9c2b209d9
No known key found for this signature in database
3 changed files with 46 additions and 7 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<Toolbar :layer="tiles" @eraser="eraser" @pencil="pencil" @paint="paint" @clear="clear" @save="save" /> <Toolbar :layer="tiles" @eraser="eraser" @move="move" @pencil="pencil" @paint="paint" @clear="clear" @save="save" />
<ZoneList v-if="zoneEditorStore.isZoneListModalShown" /> <ZoneList v-if="zoneEditorStore.isZoneListModalShown" />
<template v-if="zoneEditorStore.zone"> <template v-if="zoneEditorStore.zone">
@ -29,7 +29,16 @@ import { Container, Image, useScene } from 'phavuer'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { useGameStore } from '@/stores/gameStore' import { useGameStore } from '@/stores/gameStore'
import { useZoneEditorStore } from '@/stores/zoneEditorStore' import { useZoneEditorStore } from '@/stores/zoneEditorStore'
import { calculateIsometricDepth, loadAssets, placeTile, setAllTiles, sortByIsometricDepth, tileToWorldX, tileToWorldY } from '@/composables/zoneComposable' import {
calculateIsometricDepth,
getTile,
loadAssets,
placeTile,
setAllTiles,
sortByIsometricDepth,
tileToWorldX,
tileToWorldY
} from '@/composables/zoneComposable'
import { ZoneEventTileType, type ZoneObject, type ZoneEventTile, type Zone } 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'
@ -45,6 +54,8 @@ import ZoneList from '@/components/gameMaster/zoneEditor/partials/ZoneList.vue'
import TeleportModal from '@/components/gameMaster/zoneEditor/partials/TeleportModal.vue' import TeleportModal from '@/components/gameMaster/zoneEditor/partials/TeleportModal.vue'
import Tilemap = Phaser.Tilemaps.Tilemap import Tilemap = Phaser.Tilemaps.Tilemap
import TilemapLayer = Phaser.Tilemaps.TilemapLayer import TilemapLayer = Phaser.Tilemaps.TilemapLayer
import InputManager = Phaser.Input.InputManager
import MouseManager = Phaser.Input.Mouse.MouseManager
/** /**
* @TODO: * @TODO:
@ -57,12 +68,12 @@ const zoneEditorStore = useZoneEditorStore()
const { objectList, zone, selectedTile, selectedObject, selectedZoneObject, eraserMode, drawMode } = storeToRefs(zoneEditorStore) const { objectList, zone, selectedTile, selectedObject, selectedZoneObject, eraserMode, drawMode } = storeToRefs(zoneEditorStore)
const movingZoneObject = ref<ZoneObject|null>(null);
const zoneTilemap = createTilemap() const zoneTilemap = createTilemap()
const tiles = createTileLayer() const tiles = createTileLayer()
const zoneObjects = ref<ZoneObject[]>([]) const zoneObjects = ref<ZoneObject[]>([])
const zoneEventTiles = ref<ZoneEventTile[]>([]) const zoneEventTiles = ref<ZoneEventTile[]>([])
let tileArray = createTileArray() let tileArray = createTileArray()
const shouldShowTeleportModal = computed(() => zoneEditorStore.tool === 'pencil' && drawMode.value === 'teleport') const shouldShowTeleportModal = computed(() => zoneEditorStore.tool === 'pencil' && drawMode.value === 'teleport')
function createTilemap() { function createTilemap() {
@ -95,6 +106,7 @@ function createTileArray() {
function getObjectImageProps(object: ZoneObject) { function getObjectImageProps(object: ZoneObject) {
return { return {
alpha: object.id === movingZoneObject.value?.id ? .5 : 1,
tint: selectedZoneObject.value?.id === object.id ? 0x00ff00 : 0xffffff, tint: selectedZoneObject.value?.id === object.id ? 0x00ff00 : 0xffffff,
x: tileToWorldX(zoneTilemap as any, object.positionX, object.positionY), x: tileToWorldX(zoneTilemap as any, object.positionX, object.positionY),
y: tileToWorldY(zoneTilemap as any, object.positionX, object.positionY), y: tileToWorldY(zoneTilemap as any, object.positionX, object.positionY),
@ -123,6 +135,10 @@ function eraser(tile: Phaser.Tilemaps.Tile) {
} }
} }
function move(_tile: Phaser.Tilemaps.Tile) {
movingZoneObject.value = null;
}
function pencil(tile: Phaser.Tilemaps.Tile) { function pencil(tile: Phaser.Tilemaps.Tile) {
if (drawMode.value === 'tile' && selectedTile.value) { if (drawMode.value === 'tile' && selectedTile.value) {
placeTile(zoneTilemap as Tilemap, tiles as TilemapLayer, tile.x, tile.y, selectedTile.value.id) placeTile(zoneTilemap as Tilemap, tiles as TilemapLayer, tile.x, tile.y, selectedTile.value.id)
@ -245,8 +261,11 @@ function deleteZoneObject(objectId: string) {
zoneObjects.value = zoneObjects.value.filter((object) => object.id !== objectId) zoneObjects.value = zoneObjects.value.filter((object) => object.id !== objectId)
} }
function handleMove() { function handleMove(objectId: string) {
console.log('move btn clicked') const object = zoneObjects.value.find((obj) => obj.id === objectId)
if (object) {
movingZoneObject.value = object;
}
} }
function handleRotate(objectId: string) { function handleRotate(objectId: string) {
@ -299,12 +318,28 @@ const setSelectedZoneObject = (zoneObject: ZoneObject | null) => {
onBeforeMount(async () => { onBeforeMount(async () => {
await gameStore.fetchAllZoneAssets() await gameStore.fetchAllZoneAssets()
await loadAssets(scene) await loadAssets(scene)
console.log('loaded assets')
tileArray.forEach((row, y) => row.forEach((_, x) => placeTile(zoneTilemap, tiles, x, y, 'blank_tile'))) tileArray.forEach((row, y) => row.forEach((_, x) => placeTile(zoneTilemap, tiles, x, y, 'blank_tile')))
if (zone.value?.tiles) { if (zone.value?.tiles) {
setAllTiles(zoneTilemap, tiles, zone.value.tiles) setAllTiles(zoneTilemap, tiles, zone.value.tiles)
tileArray = zone.value.tiles.map((row) => row.map((tileId) => tileId || 'blank_tile')) tileArray = zone.value.tiles.map((row) => row.map((tileId) => tileId || 'blank_tile'))
function handlePointerMove(pointer: Phaser.Input.Pointer) {
const { x: px, y: py } = scene.cameras.main.getWorldPoint(pointer.x, pointer.y)
const pointerTile = getTile(px, py, zoneTilemap as any)
if (pointerTile) {
console.log(pointerTile.x, pointerTile.y)
if(movingZoneObject.value) {
movingZoneObject.value.positionX = pointerTile.x
movingZoneObject.value.positionY = pointerTile.y
}
}
}
setTimeout(() => {
scene.input.on(Phaser.Input.Events.POINTER_MOVE, handlePointerMove)
})
} }
zoneEventTiles.value = zone.value?.zoneEventTiles ?? [] zoneEventTiles.value = zone.value?.zoneEventTiles ?? []

View File

@ -42,7 +42,7 @@ const handleRotate = () => {
} }
const handleMove = () => { const handleMove = () => {
emit('move') emit('move', zoneEditorStore.selectedZoneObject?.id);
} }
const handleDelete = () => { const handleDelete = () => {

View File

@ -120,7 +120,7 @@ function setEraserMode(value: string) {
} }
function clickTile(pointer: Phaser.Input.Pointer) { function clickTile(pointer: Phaser.Input.Pointer) {
if (zoneEditorStore.tool !== 'eraser' && zoneEditorStore.tool !== 'pencil' && zoneEditorStore.tool !== 'paint') return if (zoneEditorStore.tool !== 'eraser' && zoneEditorStore.tool !== 'move' && zoneEditorStore.tool !== 'pencil' && zoneEditorStore.tool !== 'paint') return
if (pointer.event.shiftKey) return if (pointer.event.shiftKey) return
const px = scene.cameras.main.worldView.x + pointer.x const px = scene.cameras.main.worldView.x + pointer.x
@ -129,6 +129,10 @@ function clickTile(pointer: Phaser.Input.Pointer) {
const pointer_tile = getTile(px, py, props.layer as TilemapLayer) as Phaser.Tilemaps.Tile const pointer_tile = getTile(px, py, props.layer as TilemapLayer) as Phaser.Tilemaps.Tile
if (!pointer_tile) return if (!pointer_tile) return
if (zoneEditorStore.tool === 'move') {
emit('move', pointer_tile)
}
if (zoneEditorStore.tool === 'eraser') { if (zoneEditorStore.tool === 'eraser') {
emit('eraser', pointer_tile) emit('eraser', pointer_tile)
} }