Walking works again but needs to be improved
This commit is contained in:
parent
540425ca44
commit
8191a039c9
@ -29,7 +29,7 @@ enum Direction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
layer: Phaser.Tilemaps.TilemapLayer
|
layer: Phaser.Tilemaps.Tilemap
|
||||||
zoneCharacter: ZoneCharacter
|
zoneCharacter: ZoneCharacter
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
@ -127,15 +127,23 @@ const updateSprite = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.zoneCharacter.character,
|
() => ({
|
||||||
(newChar, oldChar) => {
|
x: props.zoneCharacter.character.positionX,
|
||||||
if (!newChar) return
|
y: props.zoneCharacter.character.positionY,
|
||||||
|
isMoving: props.zoneCharacter.isMoving,
|
||||||
|
rotation: props.zoneCharacter.character.rotation
|
||||||
|
}),
|
||||||
|
(newValues, oldValues) => {
|
||||||
|
if (!newValues) return
|
||||||
|
|
||||||
if (!oldChar || newChar.positionX !== oldChar.positionX || newChar.positionY !== oldChar.positionY) {
|
if (!oldValues || newValues.x !== oldValues.x || newValues.y !== oldValues.y) {
|
||||||
const direction = !oldChar ? Direction.POSITIVE : calcDirection(oldChar.positionX, oldChar.positionY, newChar.positionX, newChar.positionY)
|
const direction = !oldValues
|
||||||
updatePosition(newChar.positionX, newChar.positionY, direction)
|
? Direction.POSITIVE
|
||||||
}
|
: calcDirection(oldValues.x, oldValues.y, newValues.x, newValues.y)
|
||||||
|
updatePosition(newValues.x, newValues.y, direction)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{ deep: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
watch(() => props.zoneCharacter, updateSprite)
|
watch(() => props.zoneCharacter, updateSprite)
|
||||||
|
@ -44,7 +44,7 @@ gameStore.connection!.on('zone:character:leave', (characterId: number) => {
|
|||||||
zoneStore.removeCharacter(characterId)
|
zoneStore.removeCharacter(characterId)
|
||||||
})
|
})
|
||||||
|
|
||||||
gameStore.connection!.on('zone:character:move', (data: { id: number; positionX: number; positionY: number; rotation: number; isMoving: boolean }) => {
|
gameStore.connection!.on('zone:character:move', (data: { characterId: number; positionX: number; positionY: number; rotation: number; isMoving: boolean }) => {
|
||||||
zoneStore.updateCharacterPosition(data)
|
zoneStore.updateCharacterPosition(data)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -40,8 +40,8 @@ export const useZoneStore = defineStore('zone', {
|
|||||||
setCharacterLoaded(loaded: boolean) {
|
setCharacterLoaded(loaded: boolean) {
|
||||||
this.characterLoaded = loaded
|
this.characterLoaded = loaded
|
||||||
},
|
},
|
||||||
updateCharacterPosition(data: { id: number; positionX: number; positionY: number; rotation: number; isMoving: boolean }) {
|
updateCharacterPosition(data: { characterId: number; positionX: number; positionY: number; rotation: number; isMoving: boolean }) {
|
||||||
const character = this.characters.find((char) => char.character.id === data.id)
|
const character = this.characters.find((char) => char.character.id === data.characterId)
|
||||||
if (character) {
|
if (character) {
|
||||||
character.character.positionX = data.positionX
|
character.character.positionX = data.positionX
|
||||||
character.character.positionY = data.positionY
|
character.character.positionY = data.positionY
|
||||||
|
Loading…
x
Reference in New Issue
Block a user