1
0
forked from noxious/client

Forgot to push

This commit is contained in:
Dennis Postma 2024-09-16 20:51:48 +02:00
parent a8184449c5
commit 6bc0c7ab3f
2 changed files with 24 additions and 6 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="flex justify-center items-center h-dvh relative"> <div v-if="assetsLoaded" class="flex justify-center items-center h-dvh relative">
<GmTools v-if="isLoaded && gameStore.character?.role === 'gm'" /> <GmTools v-if="isLoaded && gameStore.character?.role === 'gm'" />
<GmPanel v-if="isLoaded && gameStore.character?.role === 'gm'" /> <GmPanel v-if="isLoaded && gameStore.character?.role === 'gm'" />
<Inventory /> <Inventory />
@ -37,7 +37,7 @@
<script setup lang="ts"> <script setup lang="ts">
import config from '@/config' import config from '@/config'
import 'phaser' import 'phaser'
import { watch, ref, onBeforeUnmount } from 'vue' import { watch, ref, onBeforeUnmount, onMounted } from 'vue'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { Game, Scene } from 'phavuer' import { Game, Scene } from 'phavuer'
import { useGameStore } from '@/stores/game' import { useGameStore } from '@/stores/game'
@ -56,6 +56,7 @@ const gameStore = useGameStore()
const zoneEditorStore = useZoneEditorStore() const zoneEditorStore = useZoneEditorStore()
const assetStore = useAssetStore() const assetStore = useAssetStore()
const isLoaded = ref(false) const isLoaded = ref(false)
const assetsLoaded = ref(false)
const { assets } = storeToRefs(assetStore) const { assets } = storeToRefs(assetStore)
const gameConfig = { const gameConfig = {
@ -82,6 +83,11 @@ const createGame = (game: Phaser.Game) => {
}) })
} }
onMounted(async () => {
await assetStore.fetchAssetsByZoneId(gameStore.character?.zoneId);
assetsLoaded.value = true;
})
const preloadScene = (scene: Phaser.Scene) => { const preloadScene = (scene: Phaser.Scene) => {
/** /**
* Create loading bar * Create loading bar
@ -158,11 +164,11 @@ const createScene = (scene: Phaser.Scene) => {
* Watch for changes in assets and reload them * Watch for changes in assets and reload them
*/ */
watch(assets, (newAssets) => { watch(assets, (newAssets) => {
newAssets.forEach((asset) => { // newAssets.forEach((asset) => {
scene.load.image(asset.key, config.server_endpoint + asset.url) // scene.load.image(asset.key, config.server_endpoint + asset.url)
}) // })
scene.load.start() // scene.load.start()
// scene.load.once('complete', () => {}) // scene.load.once('complete', () => {})
}) })
} }

View File

@ -21,6 +21,18 @@ export const useAssetStore = defineStore('assets', {
console.error('Error fetching assets:', error) console.error('Error fetching assets:', error)
return false return false
}) })
},
fetchAssetsByZoneId(zoneId: number) {
return fetch(config.server_endpoint + '/assets/' + zoneId)
.then((response) => response.json())
.then((assets) => {
this.setAssets(assets)
return true
})
.catch((error) => {
console.error('Error fetching assets:', error)
return false
})
} }
} }
}) })