1
0
forked from noxious/client

asset downloading from server works now

This commit is contained in:
2024-06-30 02:04:09 +02:00
parent 270b14d8e5
commit 8c7d817bfb
2 changed files with 18 additions and 9 deletions

View File

@ -1,7 +1,6 @@
<template>
<div class="game-container">
<GmTools />
<Game class="game" :config="gameConfig" @create="createGame" v-if="!zoneEditorStore.active">
<Scene name="main" @preload="preloadScene" @create="createScene">
<div class="top-ui">
@ -64,11 +63,22 @@ const createGame = (game: Phaser.Game) => {
}
const preloadScene = (scene: Phaser.Scene) => {
/**
* @TODO
* Write logic that downloads all assets from out websocket or http server in base64 format
* Don't forget to check how intensive that operation is with sockets for performance
*/
type Asset = {
key: string
value: string
type: 'base64' | 'link'
}
socket.connection.emit('assets:download', {}, (response: Asset[]) => {
response.forEach((asset) => {
if (asset.type === 'base64') {
scene.textures.addBase64(asset.key, asset.value)
}
if (asset.type === 'link') {
scene.load.image(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')