forked from noxious/client
Fixed event tile erasing and moving/flipping map objects
This commit is contained in:
parent
d2b6d8dcb3
commit
adc3eba237
@ -7,7 +7,7 @@ import { MapEventTileType, type MapEventTile, type Map as MapT, type UUID } from
|
|||||||
import { uuidv4 } from '@/application/utilities'
|
import { uuidv4 } from '@/application/utilities'
|
||||||
import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
|
import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
|
||||||
import { getTile, tileToWorldX, tileToWorldY } from '@/services/mapService'
|
import { getTile, tileToWorldX, tileToWorldY } from '@/services/mapService'
|
||||||
import { Image, useScene } from 'phavuer'
|
import { Image } from 'phavuer'
|
||||||
import { shallowRef } from 'vue'
|
import { shallowRef } from 'vue'
|
||||||
|
|
||||||
const mapEditor = useMapEditorComposable()
|
const mapEditor = useMapEditorComposable()
|
||||||
@ -63,15 +63,19 @@ function pencil(pointer: Phaser.Input.Pointer, map: MapT) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function erase(pointer: Phaser.Input.Pointer, map: MapT) {
|
function erase(pointer: Phaser.Input.Pointer, map: MapT) {
|
||||||
if (!tileLayer.value) return
|
|
||||||
// Check if there is a tile
|
// Check if there is a tile
|
||||||
const tile = getTile(tileLayer.value, pointer.worldX, pointer.worldY)
|
const tile = getTile(props.tileMap, pointer.worldX, pointer.worldY)
|
||||||
if (!tile) return
|
if (!tile) return
|
||||||
|
|
||||||
// Check if event tile already exists on position
|
// Check if event tile already exists on position
|
||||||
const existingEventTile = map.mapEventTiles.find((eventTile) => eventTile.positionX === tile.x && eventTile.positionY === tile.y)
|
const existingEventTile = map.mapEventTiles.find((eventTile) => eventTile.positionX === tile.x && eventTile.positionY === tile.y)
|
||||||
if (!existingEventTile) return
|
if (!existingEventTile) return
|
||||||
|
|
||||||
|
if (mapEditor.drawMode.value !== existingEventTile.type.toLowerCase()) {
|
||||||
|
if (mapEditor.drawMode.value === 'blocking tile' && existingEventTile.type === MapEventTileType.BLOCK) null //skip this case
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove existing event tile
|
// Remove existing event tile
|
||||||
map.mapEventTiles = map.mapEventTiles.filter((eventTile) => eventTile.id !== existingEventTile.id)
|
map.mapEventTiles = map.mapEventTiles.filter((eventTile) => eventTile.id !== existingEventTile.id)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<SelectedPlacedMapObjectComponent v-if="mapEditor.selectedPlacedObject.value" :placedMapObject="mapEditor.selectedPlacedObject.value" @move="moveMapObject" @rotate="rotatePlacedMapObject" @delete="deletePlacedMapObject" />
|
<SelectedPlacedMapObjectComponent v-if="mapEditor.selectedPlacedObject.value" :map :placedMapObject="mapEditor.selectedPlacedObject.value" @move="moveMapObject" @rotate="rotatePlacedMapObject" @delete="deletePlacedMapObject" />
|
||||||
<PlacedMapObject v-for="placedMapObject in mapEditor.currentMap.value?.placedMapObjects" :tileMap :tileMapLayer :placedMapObject @pointerdown="clickPlacedMapObject(placedMapObject)" />
|
<PlacedMapObject v-for="placedMapObject in mapEditor.currentMap.value?.placedMapObjects" :tileMap :tileMapLayer :placedMapObject @pointerdown="clickPlacedMapObject(placedMapObject)" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -14,9 +14,11 @@ import { useScene } from 'phavuer'
|
|||||||
|
|
||||||
import Tilemap = Phaser.Tilemaps.Tilemap
|
import Tilemap = Phaser.Tilemaps.Tilemap
|
||||||
import TilemapLayer = Phaser.Tilemaps.TilemapLayer
|
import TilemapLayer = Phaser.Tilemaps.TilemapLayer
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
const scene = useScene()
|
const scene = useScene()
|
||||||
const mapEditor = useMapEditorComposable()
|
const mapEditor = useMapEditorComposable()
|
||||||
|
const map = computed(() => mapEditor.currentMap.value)
|
||||||
|
|
||||||
defineExpose({ handlePointer })
|
defineExpose({ handlePointer })
|
||||||
|
|
||||||
|
@ -11,23 +11,24 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { PlacedMapObject } from '@/application/types'
|
import type { PlacedMapObject, Map as MapT } from '@/application/types'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
placedMapObject: PlacedMapObject
|
placedMapObject: PlacedMapObject
|
||||||
|
map: MapT
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits(['move', 'rotate', 'delete'])
|
const emit = defineEmits(['move', 'rotate', 'delete'])
|
||||||
|
|
||||||
const handleMove = () => {
|
const handleMove = () => {
|
||||||
emit('move', props.placedMapObject.id, props.placedMapObject.map)
|
emit('move', props.placedMapObject.id, props.map)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleRotate = () => {
|
const handleRotate = () => {
|
||||||
emit('rotate', props.placedMapObject.id, props.placedMapObject.map)
|
emit('rotate', props.placedMapObject.id, props.map)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleDelete = () => {
|
const handleDelete = () => {
|
||||||
emit('delete', props.placedMapObject.id, props.placedMapObject.map)
|
emit('delete', props.placedMapObject.id, props.map)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user