forked from noxious/client
Map object isometric placement
This commit is contained in:
parent
efeae337ab
commit
554497ecbc
@ -5,7 +5,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { PlacedMapObject, TextureData } from '@/application/types'
|
import type { PlacedMapObject, TextureData } from '@/application/types'
|
||||||
import { loadTexture } from '@/composables/gameComposable'
|
import { loadTexture } from '@/composables/gameComposable'
|
||||||
import { calculateIsometricDepth, tileToWorldX, tileToWorldY } from '@/composables/mapComposable'
|
import { calculateIsometricDepth } from '@/composables/mapComposable'
|
||||||
import { useGameStore } from '@/stores/gameStore'
|
import { useGameStore } from '@/stores/gameStore'
|
||||||
import { Image, useScene } from 'phavuer'
|
import { Image, useScene } from 'phavuer'
|
||||||
import { computed, onMounted } from 'vue'
|
import { computed, onMounted } from 'vue'
|
||||||
@ -31,22 +31,13 @@ const imageProps = computed(() => ({
|
|||||||
originY: props.placedMapObject.mapObject.originY
|
originY: props.placedMapObject.mapObject.originY
|
||||||
}))
|
}))
|
||||||
|
|
||||||
function calculateObjectPlacement(mapObj: PlacedMapObject, tileCenterSnap: boolean) : {x: number; y: number} {
|
function calculateObjectPlacement(mapObj: PlacedMapObject) : {x: number; y: number} {
|
||||||
let position : {x: number; y: number}
|
let position = { x: mapObj.positionX, y: mapObj.positionY }
|
||||||
if (tileCenterSnap) {
|
|
||||||
let halfTileWidth = config.tile_size.width/2
|
let halfTileWidth = config.tile_size.width/2
|
||||||
let halfTileHeight = config.tile_size.height/2
|
let halfTileHeight = config.tile_size.height/2
|
||||||
position = {
|
|
||||||
x: Math.ceil((mapObj.positionX-config.tile_size.height)/halfTileWidth) * halfTileWidth,
|
|
||||||
y: Math.ceil((mapObj.positionY-config.tile_size.height)/halfTileWidth) * halfTileWidth,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
position = { x: mapObj.positionX, y: mapObj.positionY }
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
x: position.x-mapObj.mapObject.frameWidth/2,
|
x: position.x-mapObj.mapObject.frameWidth/2,
|
||||||
y: position.y-mapObj.mapObject.frameHeight/2
|
y: position.y-mapObj.mapObject.frameHeight/2-halfTileHeight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<MapTiles ref="mapTiles" @tileMap:create="tileMap = $event" />
|
<MapTiles ref="mapTiles" @tileMap:create="tileMap = $event" />
|
||||||
<PlacedMapObjects ref="mapObjects" v-if="tileMap" />
|
<PlacedMapObjects ref="mapObjects" v-if="tileMap" :tileMap />
|
||||||
<MapEventTiles ref="eventTiles" v-if="tileMap" :tileMap="tileMap as Phaser.Tilemaps.Tilemap" />
|
<MapEventTiles ref="eventTiles" v-if="tileMap" :tileMap />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
@ -11,13 +11,22 @@ import SelectedPlacedMapObjectComponent from '@/components/gameMaster/mapEditor/
|
|||||||
import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
|
import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
|
||||||
import { useScene } from 'phavuer'
|
import { useScene } from 'phavuer'
|
||||||
import { ref, watch } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
|
import { getTile, tileToWorldX, tileToWorldY } from '@/composables/mapComposable'
|
||||||
|
import Tilemap = Phaser.Tilemaps.Tilemap
|
||||||
|
|
||||||
const scene = useScene()
|
const scene = useScene()
|
||||||
const mapEditor = useMapEditorComposable()
|
const mapEditor = useMapEditorComposable()
|
||||||
|
|
||||||
defineExpose({ handlePointer })
|
defineExpose({ handlePointer })
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
tileMap: Tilemap
|
||||||
|
}>()
|
||||||
|
|
||||||
function pencil(pointer: Phaser.Input.Pointer, map: MapT) {
|
function pencil(pointer: Phaser.Input.Pointer, map: MapT) {
|
||||||
|
const tile = getTile(props.tileMap, pointer.worldX, pointer.worldY)
|
||||||
|
if (!tile) return
|
||||||
|
|
||||||
// Check if object already exists on position
|
// Check if object already exists on position
|
||||||
const existingPlacedMapObject = findInMap(pointer, map)
|
const existingPlacedMapObject = findInMap(pointer, map)
|
||||||
if (existingPlacedMapObject) return
|
if (existingPlacedMapObject) return
|
||||||
@ -29,8 +38,8 @@ function pencil(pointer: Phaser.Input.Pointer, map: MapT) {
|
|||||||
map: map,
|
map: map,
|
||||||
mapObject: mapEditor.selectedMapObject.value,
|
mapObject: mapEditor.selectedMapObject.value,
|
||||||
isRotated: false,
|
isRotated: false,
|
||||||
positionX: pointer.worldX,
|
positionX: tileToWorldX(props.tileMap, tile.x, tile.y),
|
||||||
positionY: pointer.worldY
|
positionY: tileToWorldY(props.tileMap, tile.x, tile.y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add new object to mapObjects
|
// Add new object to mapObjects
|
||||||
|
@ -98,18 +98,17 @@ function save() {
|
|||||||
if (!currentMap) return
|
if (!currentMap) return
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
mapId: currentMap.id,
|
mapId: {...currentMap},
|
||||||
name: currentMap.name,
|
name: currentMap.name,
|
||||||
width: currentMap.width,
|
width: currentMap.width,
|
||||||
height: currentMap.height,
|
height: currentMap.height,
|
||||||
tiles: currentMap.tiles,
|
tiles: {...currentMap.tiles},
|
||||||
pvp: currentMap.pvp,
|
pvp: currentMap.pvp,
|
||||||
mapEffects: currentMap.mapEffects?.map(({ id, effect, strength }) => ({ id, effect, strength })) ?? [],
|
mapEffects: {...currentMap.mapEffects},
|
||||||
mapEventTiles: currentMap.mapEventTiles?.map(({ id, type, positionX, positionY, teleport }) => ({ id, type, positionX, positionY, teleport: {...teleport} })),
|
mapEventTiles: {...currentMap.mapEventTiles},
|
||||||
placedMapObjects: currentMap.placedMapObjects?.map(({ id, mapObject, depth, isRotated, positionX, positionY }) => ({ id, mapObject: {...mapObject}, depth, isRotated, positionX, positionY })) ?? []
|
placedMapObjects: currentMap.placedMapObjects?.map(({ id, mapObject, depth, isRotated, positionX, positionY }) => ({ id, mapObject: {...mapObject}, depth, isRotated, positionX, positionY })) ?? []
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(data.placedMapObjects)
|
|
||||||
gameStore.connection?.emit('gm:map:update', data, (response: MapT) => {
|
gameStore.connection?.emit('gm:map:update', data, (response: MapT) => {
|
||||||
mapStorage.update(response.id, response)
|
mapStorage.update(response.id, response)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user