1
0
forked from noxious/client

Map object position as tile coordinates, map objects correctly snap to each tile now when moving, and fixed bug of placing objects over eachother on the same tile

This commit is contained in:
Andrei 2025-02-03 14:53:46 -06:00
parent 841ec0f3df
commit ff9dcb91b0
2 changed files with 14 additions and 11 deletions

View File

@ -3,13 +3,12 @@
</template>
<script setup lang="ts">
import config from '@/application/config'
import Controls from '@/components/utilities/Controls.vue'
import { createTileMap, createTileLayer, createTileArray, getTile, placeTile, setLayerTiles } from '@/composables/mapComposable'
import { createTileArray, getTile, placeTile, setLayerTiles } from '@/composables/mapComposable'
import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
import { TileStorage } from '@/storage/storages'
import { useScene } from 'phavuer'
import { onMounted, onUnmounted, ref, shallowRef, watch } from 'vue'
import { onMounted, ref, watch } from 'vue'
const emit = defineEmits(['tileMap:create'])
const scene = useScene()

View File

@ -10,8 +10,8 @@ import PlacedMapObject from '@/components/game/map/partials/PlacedMapObject.vue'
import SelectedPlacedMapObjectComponent from '@/components/gameMaster/mapEditor/partials/SelectedPlacedMapObject.vue'
import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
import { useScene } from 'phavuer'
import { ref, watch } from 'vue'
import { getTile, tileToWorldX, tileToWorldY } from '@/composables/mapComposable'
import { watch } from 'vue'
import { getTile } from '@/composables/mapComposable'
import Tilemap = Phaser.Tilemaps.Tilemap
import TilemapLayer = Phaser.Tilemaps.TilemapLayer
@ -30,8 +30,9 @@ function pencil(pointer: Phaser.Input.Pointer, map: MapT) {
if (!tile) return
// Check if object already exists on position
const existingPlacedMapObject = findInMap(pointer, map)
const existingPlacedMapObject = findObjectByPointer(pointer, map)
if (existingPlacedMapObject) return
if (!mapEditor.selectedMapObject.value) return
const newPlacedMapObject: PlacedMapObjectT = {
@ -52,20 +53,23 @@ function pencil(pointer: Phaser.Input.Pointer, map: MapT) {
function eraser(pointer: Phaser.Input.Pointer, map: MapT) {
// Check if object already exists on position
const existingPlacedMapObject = findInMap(pointer, map)
const existingPlacedMapObject = findObjectByPointer(pointer, map)
if (!existingPlacedMapObject) return
// Remove existing object
map.placedMapObjects = map.placedMapObjects.filter((placedMapObject) => placedMapObject.id !== existingPlacedMapObject.id)
}
function findInMap(pointer: Phaser.Input.Pointer, map: MapT) {
return map.placedMapObjects.find((placedMapObject) => placedMapObject.positionX === pointer.worldX && placedMapObject.positionY === pointer.worldY)
function findObjectByPointer(pointer: Phaser.Input.Pointer, map: MapT) : PlacedMapObjectT | undefined {
const tile = getTile(props.tileMap, pointer.worldX, pointer.worldY)
if (!tile) return undefined
return map.placedMapObjects.find((placedMapObject) => placedMapObject.positionX === tile.x && placedMapObject.positionY === tile.y)!
}
function objectPicker(pointer: Phaser.Input.Pointer, map: MapT) {
// Check if object already exists on position
const existingPlacedMapObject = findInMap(pointer, map)
const existingPlacedMapObject = findObjectByPointer(pointer, map)
if (!existingPlacedMapObject) return
// Select the object