This commit is contained in:
2024-06-30 23:27:06 +02:00
parent 37460a9497
commit f0c5c81e86
5 changed files with 102 additions and 59 deletions

View File

@ -36,9 +36,12 @@ import GmTools from '@/components/utilities/GmTools.vue'
import { useSocketStore } from '@/stores/socket'
import { useZoneEditorStore } from '@/stores/zoneEditor'
import ZoneEditor from '@/components/utilities/zoneEditor/ZoneEditor.vue'
import { useAssetStore } from '@/stores/assets'
import type { Asset } from '@/types'
const socket = useSocketStore()
const zoneEditorStore = useZoneEditorStore()
const assetStore = useAssetStore()
onUnmounted(() => {
socket.disconnectSocket()
@ -64,23 +67,24 @@ const createGame = (game: Phaser.Game) => {
}
const preloadScene = (scene: Phaser.Scene) => {
type Asset = {
key: string
value: string
type: 'base64' | 'link'
}
socket.connection.emit('assets:download', {}, (response: Asset[]) => {
console.log(response);
response.forEach((asset) => {
if (asset.type === 'base64') {
scene.textures.addBase64(asset.key, asset.value)
}
if (asset.type === 'link') {
scene.load.image(asset.key, config.server_endpoint + '/assets' + asset.value)
}
assetStore.addAsset(asset)
})
})
assetStore.assets.forEach((asset) => {
if (asset.type === 'link') {
scene.load.image(asset.key, asset.value)
}
if (asset.type === 'base64') {
scene.textures.addBase64(asset.key, asset.value)
}
})
scene.load.image('tiles', '/assets/zone/tiles.png')
scene.load.image('walls', '/assets/zone/walls.png')
scene.load.image('wall1', '/assets/zone/wall1.png')