forked from noxious/client
Prepping to work on Placed map objects
This commit is contained in:
@ -8,31 +8,24 @@ import type { Map as MapT, PlacedMapObject as PlacedMapObjectT } from '@/applica
|
||||
import { uuidv4 } from '@/application/utilities'
|
||||
import PlacedMapObject from '@/components/gameMaster/mapEditor/mapPartials/PlacedMapObject.vue'
|
||||
import SelectedPlacedMapObjectComponent from '@/components/gameMaster/mapEditor/partials/SelectedPlacedMapObject.vue'
|
||||
import { getTile } from '@/composables/mapComposable'
|
||||
import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
|
||||
import { useScene } from 'phavuer'
|
||||
import { ref, watch } from 'vue'
|
||||
import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
|
||||
|
||||
const scene = useScene()
|
||||
const mapEditor = useMapEditorComposable()
|
||||
const selectedPlacedMapObject = ref<PlacedMapObjectT | null>(null)
|
||||
const movingPlacedMapObject = ref<PlacedMapObjectT | null>(null)
|
||||
|
||||
const tileLayer = ref<Phaser.Tilemaps.TilemapLayer>()
|
||||
|
||||
const props = defineProps<{
|
||||
tileMap: Phaser.Tilemaps.Tilemap
|
||||
}>()
|
||||
|
||||
defineExpose({handlePointer})
|
||||
defineExpose({ handlePointer })
|
||||
|
||||
function pencil(pointer: Phaser.Input.Pointer, map: MapT) {
|
||||
// Check if there is a tile
|
||||
const tile = getTile(tileLayer, pointer.worldX, pointer.worldY)
|
||||
if (!tile) return
|
||||
|
||||
// Check if object already exists on position
|
||||
const existingPlacedMapObject = map.placedMapObjects.find((placedMapObject) => placedMapObject.positionX === tile.x && placedMapObject.positionY === tile.y)
|
||||
const existingPlacedMapObject = findInMap(pointer, map)
|
||||
if (existingPlacedMapObject) return
|
||||
|
||||
const newPlacedMapObject: PlacedMapObjectT = {
|
||||
@ -41,8 +34,8 @@ function pencil(pointer: Phaser.Input.Pointer, map: MapT) {
|
||||
map: map,
|
||||
mapObject: mapEditor.selectedMapObject.value!,
|
||||
isRotated: false,
|
||||
positionX: tile.x,
|
||||
positionY: tile.y
|
||||
positionX: pointer.x,
|
||||
positionY: pointer.y
|
||||
}
|
||||
|
||||
// Add new object to mapObjects
|
||||
@ -50,25 +43,21 @@ function pencil(pointer: Phaser.Input.Pointer, map: MapT) {
|
||||
}
|
||||
|
||||
function eraser(pointer: Phaser.Input.Pointer, map: MapT) {
|
||||
// Check if there is a tile
|
||||
const tile = getTile(tileMapLayer, pointer.worldX, pointer.worldY)
|
||||
if (!tile) return
|
||||
|
||||
// Check if object already exists on position
|
||||
const existingPlacedMapObject = map.placedMapObjects.find((placedMapObject) => placedMapObject.positionX === tile.x && placedMapObject.positionY === tile.y)
|
||||
const existingPlacedMapObject = findInMap(pointer, map)
|
||||
if (!existingPlacedMapObject) return
|
||||
|
||||
// Remove existing object
|
||||
map.placedMapObjects = map.placedMapObjects.filter((placedMapObject) => placedMapObject.id !== existingPlacedMapObject.id)
|
||||
}
|
||||
|
||||
function objectPicker(pointer: Phaser.Input.Pointer, map: MapT) {
|
||||
// Check if there is a tile
|
||||
const tile = getTile(tileMapLayer, pointer.worldX, pointer.worldY)
|
||||
if (!tile) return
|
||||
function findInMap(pointer: Phaser.Input.Pointer, map: MapT) {
|
||||
return map.placedMapObjects.find((placedMapObject) => placedMapObject.positionX === pointer.worldX && placedMapObject.positionY === pointer.worldY)
|
||||
}
|
||||
|
||||
function objectPicker(pointer: Phaser.Input.Pointer, map: MapT) {
|
||||
// Check if object already exists on position
|
||||
const existingPlacedMapObject = map.placedMapObjects.find((placedMapObject) => placedMapObject.positionX === tile.x && placedMapObject.positionY === tile.y)
|
||||
const existingPlacedMapObject = findInMap(pointer, map)
|
||||
if (!existingPlacedMapObject) return
|
||||
|
||||
// Select the object
|
||||
@ -81,11 +70,8 @@ function moveMapObject(id: string, map: MapT) {
|
||||
function handlePointerMove(pointer: Phaser.Input.Pointer) {
|
||||
if (!movingPlacedMapObject.value) return
|
||||
|
||||
const tile = getTile(tileMapLayer, pointer.worldX, pointer.worldY)
|
||||
if (!tile) return
|
||||
|
||||
movingPlacedMapObject.value.positionX = tile.x
|
||||
movingPlacedMapObject.value.positionY = tile.y
|
||||
movingPlacedMapObject.value.positionX = pointer.worldX
|
||||
movingPlacedMapObject.value.positionY = pointer.worldY
|
||||
}
|
||||
|
||||
scene.input.on(Phaser.Input.Events.POINTER_MOVE, handlePointerMove)
|
||||
@ -149,7 +135,7 @@ function handlePointer(pointer: Phaser.Input.Pointer) {
|
||||
break
|
||||
case 'object picker':
|
||||
objectPicker(pointer, map)
|
||||
break
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user