diff --git a/src/components/zone/Zone.vue b/src/components/zone/Zone.vue index fb28308..6b38d48 100644 --- a/src/components/zone/Zone.vue +++ b/src/components/zone/Zone.vue @@ -8,7 +8,7 @@ import { useScene } from 'phavuer' import { useGameStore } from '@/stores/gameStore' import { useZoneStore } from '@/stores/zoneStore' -import { onBeforeMount, onBeforeUnmount, ref } from 'vue' +import { onBeforeMount, onBeforeUnmount, onMounted, ref } from 'vue' import type { Character as CharacterT, Zone as ZoneT, ExtendedCharacter as ExtendedCharacterT } from '@/types' import Tiles from '@/components/zone/Tiles.vue' import Objects from '@/components/zone/Objects.vue' @@ -48,6 +48,8 @@ gameStore.connection!.on('zone:character:teleport', async (data: zoneLoadData) = }) gameStore.connection!.on('zone:character:join', async (data: ExtendedCharacterT) => { + // If data is from the current user, don't add it to the store + if (data.id === gameStore.character?.id) return zoneStore.addCharacter(data) }) @@ -59,12 +61,7 @@ gameStore.connection!.on('character:move', (data: ExtendedCharacterT) => { zoneStore.updateCharacter(data) }) -onBeforeMount(() => { - /** - * @TODO, when returning from the zone editor, the emit is not s - */ - console.log('before mount') - +onMounted(() => { gameStore.connection!.emit('zone:character:join', async (response: zoneLoadData) => { // Fetch assets for new zone await gameStore.fetchZoneAssets(response.zone.id) diff --git a/src/stores/zoneStore.ts b/src/stores/zoneStore.ts index 80e2b14..c54f38f 100644 --- a/src/stores/zoneStore.ts +++ b/src/stores/zoneStore.ts @@ -42,7 +42,8 @@ export const useZoneStore = defineStore('zone', { }, reset() { this.zone = null - ;(this.characters = []), (this.characterLoaded = false) + this.characters = [] + this.characterLoaded = false } } })