1
0
forked from noxious/client

Renamed hair > characterHair, split character logic (chat bubble, healthbar etc) into separate components for better DX

This commit is contained in:
2024-11-24 15:13:11 +01:00
parent 89d83efca4
commit f7b8c235d8
10 changed files with 153 additions and 75 deletions

View File

@ -0,0 +1,50 @@
<template>
<Image v-bind="imageProps" v-if="gameStore.getLoadedAsset(props.zoneCharacter.character.characterHair?.spriteId)" ref="image" />
</template>
<script lang="ts" setup>
import { computed } from 'vue'
import { Image, refObj, useScene } from 'phavuer'
import type { Sprite as SpriteT, ZoneCharacter } from '@/types'
import { loadSpriteTextures } from '@/composables/gameComposable'
import { useGameStore } from '@/stores/gameStore'
const props = defineProps<{
zoneCharacter: ZoneCharacter
currentX: number
currentY: number
}>()
const gameStore = useGameStore()
const scene = useScene()
const image = refObj<Phaser.GameObjects.Image>()
const isFlippedX = computed(() => [6, 4].includes(props.zoneCharacter.character.rotation ?? 0))
const texture = computed(() => {
const { rotation, characterHair } = props.zoneCharacter.character
const spriteId = characterHair?.sprite?.id
const direction = [0, 6].includes(rotation) ? 'back' : 'front'
return `${spriteId}-${direction}`
})
const imageProps = computed(() => ({
depth: 1,
x: props.currentX,
y: props.currentY,
flipX: false,
texture: texture.value,
}))
loadSpriteTextures(scene, props.zoneCharacter.character.characterHair?.sprite as SpriteT)
.then(() => {
console.log(texture.value)
image.value!.setTexture(texture.value!)
image.value!.setFlipX(isFlippedX.value)
})
.catch((error) => {
console.error('Error loading texture:', error)
})
</script>