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:
parent
841ec0f3df
commit
ff9dcb91b0
@ -3,13 +3,12 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import config from '@/application/config'
|
|
||||||
import Controls from '@/components/utilities/Controls.vue'
|
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 { useMapEditorComposable } from '@/composables/useMapEditorComposable'
|
||||||
import { TileStorage } from '@/storage/storages'
|
import { TileStorage } from '@/storage/storages'
|
||||||
import { useScene } from 'phavuer'
|
import { useScene } from 'phavuer'
|
||||||
import { onMounted, onUnmounted, ref, shallowRef, watch } from 'vue'
|
import { onMounted, ref, watch } from 'vue'
|
||||||
|
|
||||||
const emit = defineEmits(['tileMap:create'])
|
const emit = defineEmits(['tileMap:create'])
|
||||||
const scene = useScene()
|
const scene = useScene()
|
||||||
|
@ -10,8 +10,8 @@ import PlacedMapObject from '@/components/game/map/partials/PlacedMapObject.vue'
|
|||||||
import SelectedPlacedMapObjectComponent from '@/components/gameMaster/mapEditor/partials/SelectedPlacedMapObject.vue'
|
import SelectedPlacedMapObjectComponent from '@/components/gameMaster/mapEditor/partials/SelectedPlacedMapObject.vue'
|
||||||
import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
|
import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
|
||||||
import { useScene } from 'phavuer'
|
import { useScene } from 'phavuer'
|
||||||
import { ref, watch } from 'vue'
|
import { watch } from 'vue'
|
||||||
import { getTile, tileToWorldX, tileToWorldY } from '@/composables/mapComposable'
|
import { getTile } from '@/composables/mapComposable'
|
||||||
import Tilemap = Phaser.Tilemaps.Tilemap
|
import Tilemap = Phaser.Tilemaps.Tilemap
|
||||||
import TilemapLayer = Phaser.Tilemaps.TilemapLayer
|
import TilemapLayer = Phaser.Tilemaps.TilemapLayer
|
||||||
|
|
||||||
@ -30,8 +30,9 @@ function pencil(pointer: Phaser.Input.Pointer, map: MapT) {
|
|||||||
if (!tile) return
|
if (!tile) return
|
||||||
|
|
||||||
// Check if object already exists on position
|
// Check if object already exists on position
|
||||||
const existingPlacedMapObject = findInMap(pointer, map)
|
const existingPlacedMapObject = findObjectByPointer(pointer, map)
|
||||||
if (existingPlacedMapObject) return
|
if (existingPlacedMapObject) return
|
||||||
|
|
||||||
if (!mapEditor.selectedMapObject.value) return
|
if (!mapEditor.selectedMapObject.value) return
|
||||||
|
|
||||||
const newPlacedMapObject: PlacedMapObjectT = {
|
const newPlacedMapObject: PlacedMapObjectT = {
|
||||||
@ -52,20 +53,23 @@ function pencil(pointer: Phaser.Input.Pointer, map: MapT) {
|
|||||||
|
|
||||||
function eraser(pointer: Phaser.Input.Pointer, map: MapT) {
|
function eraser(pointer: Phaser.Input.Pointer, map: MapT) {
|
||||||
// Check if object already exists on position
|
// Check if object already exists on position
|
||||||
const existingPlacedMapObject = findInMap(pointer, map)
|
const existingPlacedMapObject = findObjectByPointer(pointer, map)
|
||||||
if (!existingPlacedMapObject) return
|
if (!existingPlacedMapObject) return
|
||||||
|
|
||||||
// Remove existing object
|
// Remove existing object
|
||||||
map.placedMapObjects = map.placedMapObjects.filter((placedMapObject) => placedMapObject.id !== existingPlacedMapObject.id)
|
map.placedMapObjects = map.placedMapObjects.filter((placedMapObject) => placedMapObject.id !== existingPlacedMapObject.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
function findInMap(pointer: Phaser.Input.Pointer, map: MapT) {
|
function findObjectByPointer(pointer: Phaser.Input.Pointer, map: MapT) : PlacedMapObjectT | undefined {
|
||||||
return map.placedMapObjects.find((placedMapObject) => placedMapObject.positionX === pointer.worldX && placedMapObject.positionY === pointer.worldY)
|
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) {
|
function objectPicker(pointer: Phaser.Input.Pointer, map: MapT) {
|
||||||
// Check if object already exists on position
|
// Check if object already exists on position
|
||||||
const existingPlacedMapObject = findInMap(pointer, map)
|
const existingPlacedMapObject = findObjectByPointer(pointer, map)
|
||||||
if (!existingPlacedMapObject) return
|
if (!existingPlacedMapObject) return
|
||||||
|
|
||||||
// Select the object
|
// Select the object
|
||||||
|
Loading…
x
Reference in New Issue
Block a user