forked from noxious/client
Container based handling of placed objects
This commit is contained in:
parent
94eab073e6
commit
84b34c4f85
@ -1,5 +1,7 @@
|
||||
<template>
|
||||
<Image v-if="mapObject && gameStore.isTextureLoaded(props.placedMapObject.mapObject as string)" v-bind="imageProps" />
|
||||
<Container v-if="mapObject && gameStore.isTextureLoaded(props.placedMapObject.mapObject as string)" v-bind="containerProps">
|
||||
<Image v-bind="imageProps" />
|
||||
</Container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@ -9,8 +11,8 @@ import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
|
||||
import { calculateIsometricDepth, loadMapObjectTextures, tileToWorldXY } from '@/services/mapService'
|
||||
import { MapObjectStorage } from '@/storage/storages'
|
||||
import { useGameStore } from '@/stores/gameStore'
|
||||
import { Image, useScene } from 'phavuer'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { Container, Image, Sprite, useScene } from 'phavuer'
|
||||
import { computed, onMounted, ref, useTemplateRef, watch } from 'vue'
|
||||
|
||||
import Tilemap = Phaser.Tilemaps.Tilemap
|
||||
import TilemapLayer = Phaser.Tilemaps.TilemapLayer
|
||||
@ -28,6 +30,10 @@ const mapEditor = useMapEditorComposable()
|
||||
|
||||
const mapObject = ref<MapObject>()
|
||||
|
||||
const partitionedImages = ref<Phaser.GameObjects.Image[]>([])
|
||||
|
||||
const partitionOffsets = [1, -1]
|
||||
|
||||
async function initialize() {
|
||||
if (!props.placedMapObject.mapObject) return
|
||||
|
||||
@ -49,20 +55,33 @@ async function initialize() {
|
||||
await loadMapObjectTextures([_mapObject], scene)
|
||||
}
|
||||
|
||||
function createImagePartition(startX: number, endX: number, depthOffset: number) {
|
||||
let pos = calculateObjectPlacement(props.placedMapObject);
|
||||
const img = scene.add.image(pos.x, pos.y, mapObject.value!.id);
|
||||
img.setCrop(startX, 0, endX, mapObject.value!.frameHeight)
|
||||
img.setDepth(calculateIsometricDepth(props.placedMapObject.positionX, props.placedMapObject.positionY) + depthOffset)
|
||||
return img
|
||||
}
|
||||
|
||||
function calculateObjectPlacement(mapObj: PlacedMapObject): { x: number; y: number } {
|
||||
let position = tileToWorldXY(props.tileMapLayer, mapObj.positionX, mapObj.positionY)
|
||||
|
||||
return {
|
||||
x: position.worldPositionX - mapObject.value!.frameWidth / 2,
|
||||
y: position.worldPositionY - mapObject.value!.frameHeight / 2 + config.tile_size.height
|
||||
x: position.worldPositionX,
|
||||
y: position.worldPositionY
|
||||
}
|
||||
}
|
||||
|
||||
const containerProps = computed(() => ({
|
||||
...calculateObjectPlacement(props.placedMapObject),
|
||||
width: mapObject.value!.frameWidth,
|
||||
height: mapObject.value!.frameHeight
|
||||
}))
|
||||
|
||||
const imageProps = computed(() => ({
|
||||
alpha: mapEditor.movingPlacedObject.value?.id == props.placedMapObject.id || mapEditor.selectedMapObject.value?.id == props.placedMapObject.id ? 0.5 : 1,
|
||||
tint: mapEditor.selectedPlacedObject.value?.id == props.placedMapObject.id ? 0x00ff00 : 0xffffff,
|
||||
depth: calculateIsometricDepth(props.placedMapObject.positionX, props.placedMapObject.positionY),
|
||||
...calculateObjectPlacement(props.placedMapObject),
|
||||
flipX: props.placedMapObject.isRotated,
|
||||
texture: mapObject.value!.id,
|
||||
originX: mapObject.value!.originX,
|
||||
|
Loading…
x
Reference in New Issue
Block a user