forked from noxious/client
Minor improvements
This commit is contained in:
parent
858685fe5f
commit
8d30e3a918
@ -8,7 +8,7 @@
|
|||||||
import { useAssetStore } from '@/stores/assets'
|
import { useAssetStore } from '@/stores/assets'
|
||||||
import { useGameStore } from '@/stores/game'
|
import { useGameStore } from '@/stores/game'
|
||||||
import { useZoneStore } from '@/stores/zone'
|
import { useZoneStore } from '@/stores/zone'
|
||||||
import { onBeforeMount, onBeforeUnmount, ref, watch } from 'vue'
|
import { onBeforeMount, onBeforeUnmount, ref } from 'vue'
|
||||||
import type { Character as CharacterT, Zone as ZoneT, ExtendedCharacter as ExtendedCharacterT } from '@/types'
|
import type { Character as CharacterT, Zone as ZoneT, ExtendedCharacter as ExtendedCharacterT } from '@/types'
|
||||||
import Tiles from '@/components/zone/Tiles.vue'
|
import Tiles from '@/components/zone/Tiles.vue'
|
||||||
import Objects from '@/components/zone/Objects.vue'
|
import Objects from '@/components/zone/Objects.vue'
|
||||||
@ -25,6 +25,12 @@ type zoneLoadData = {
|
|||||||
characters: CharacterT[]
|
characters: CharacterT[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gameStore.connection?.emit('zone:character:join', { zoneId: gameStore.character!.zoneId }, (response: zoneLoadData) => {
|
||||||
|
zoneStore.setZone(response.zone)
|
||||||
|
zoneStore.setCharacters(response.characters)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Event listeners
|
||||||
/**
|
/**
|
||||||
* Fetch assets from the server when a new zone is loaded
|
* Fetch assets from the server when a new zone is loaded
|
||||||
*/
|
*/
|
||||||
@ -32,12 +38,6 @@ gameStore.connection?.on('zone:character:load_assets', async (zoneId: number) =>
|
|||||||
await assetStore.fetchAssetsByZoneId(zoneId)
|
await assetStore.fetchAssetsByZoneId(zoneId)
|
||||||
})
|
})
|
||||||
|
|
||||||
gameStore.connection?.emit('zone:character:join', { zoneId: gameStore.character!.zoneId }, (response: zoneLoadData) => {
|
|
||||||
zoneStore.setZone(response.zone)
|
|
||||||
zoneStore.setCharacters(response.characters)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Event listeners
|
|
||||||
gameStore.connection?.on('zone:teleport', (data: zoneLoadData) => {
|
gameStore.connection?.on('zone:teleport', (data: zoneLoadData) => {
|
||||||
if (zoneStore.zone?.id === data.zone.id) return
|
if (zoneStore.zone?.id === data.zone.id) return
|
||||||
zoneStore.setZone(data.zone)
|
zoneStore.setZone(data.zone)
|
||||||
|
@ -157,10 +157,11 @@ const createScene = (scene: Phaser.Scene) => {
|
|||||||
/**
|
/**
|
||||||
* Watch for changes in assets and reload them
|
* Watch for changes in assets and reload them
|
||||||
*/
|
*/
|
||||||
watch(assetStore.assets, (newAssets) => {
|
watch(() => assetStore.assets, (newAssets) => {
|
||||||
|
console.log('new assets', newAssets)
|
||||||
newAssets.forEach(() => {
|
newAssets.forEach(() => {
|
||||||
loadAssets(scene)
|
loadAssets(scene)
|
||||||
})
|
}, { deep: true })
|
||||||
|
|
||||||
scene.load.start()
|
scene.load.start()
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user