This commit is contained in:
2024-09-19 10:26:46 +02:00
parent 3878a02b4f
commit bb83861433
3 changed files with 25 additions and 20 deletions

View File

@ -5,6 +5,7 @@
</template>
<script setup lang="ts">
import { useAssetStore } from '@/stores/assets'
import { useGameStore } from '@/stores/game'
import { useZoneStore } from '@/stores/zone'
import { onBeforeMount, onBeforeUnmount, ref, watch } from 'vue'
@ -13,6 +14,7 @@ import Tiles from '@/components/zone/Tiles.vue'
import Objects from '@/components/zone/Objects.vue'
import Characters from '@/components/zone/Characters.vue'
const assetStore = useAssetStore()
const gameStore = useGameStore()
const zoneStore = useZoneStore()
@ -23,6 +25,13 @@ type zoneLoadData = {
characters: CharacterT[]
}
/**
* Fetch assets from the server when a new zone is loaded
*/
gameStore.connection?.on('zone:character:load_assets', async (zoneId: number) => {
await assetStore.fetchAssetsByZoneId(zoneId)
})
gameStore.connection?.emit('zone:character:join', { zoneId: gameStore.character?.zoneId }, (response: zoneLoadData) => {
zoneStore.setZone(response.zone)
zoneStore.setCharacters(response.characters)