1
0
forked from noxious/client
This commit is contained in:
2025-01-07 22:20:46 +01:00
parent c2db9b5469
commit 574777da80
19 changed files with 385 additions and 416 deletions

View File

@ -1,13 +1,14 @@
import config from '@/application/config'
import type { HttpResponse, Sprite, SpriteAction, TextureData } from '@/application/types'
import { Textures } from '@/dexie/textures'
import { TextureStorage } from '@/storage/textureStorage'
import { useGameStore } from '@/stores/gameStore'
import { SpriteStorage } from '@/storage/storages'
const textureLoadingPromises = new Map<string, Promise<boolean>>()
export async function loadTexture(scene: Phaser.Scene, textureData: TextureData): Promise<boolean> {
const gameStore = useGameStore()
const textures = new Textures()
const textureStorage = new TextureStorage()
// Check if the texture is already loaded in Phaser
if (gameStore.game.loadedAssets.find((asset) => asset.key === textureData.key)) {
@ -22,12 +23,12 @@ export async function loadTexture(scene: Phaser.Scene, textureData: TextureData)
// Create new loading promise
const loadingPromise = (async () => {
// Check if the asset is already cached
let texture = await textures.get(textureData.key)
let texture = await textureStorage.get(textureData.key)
// If asset is not found, download it
if (!texture) {
await textures.download(textureData)
texture = await textures.get(textureData.key)
await textureStorage.download(textureData)
texture = await textureStorage.get(textureData.key)
}
// If asset is found, add it to the scene
@ -60,9 +61,12 @@ export async function loadSpriteTextures(scene: Phaser.Scene, sprite_id: string)
if (!sprite_id) return
// @TODO: Fix this
const sprite_actions: HttpResponse<any[]> = await fetch(config.server_endpoint + '/assets/list_sprite_actions/' + sprite_id).then((response) => response.json())
const spriteStorage = new SpriteStorage()
const sprite = await spriteStorage.get(sprite_id)
for await (const sprite_action of sprite_actions.data ?? []) {
if (!sprite) return
for await (const sprite_action of sprite.spriteActions) {
await loadTexture(scene, {
key: sprite_action.key,
data: sprite_action.data,

View File

@ -2,7 +2,7 @@ import config from '@/application/config'
import type { HttpResponse, TextureData, UUID } from '@/application/types'
import { unduplicateArray } from '@/application/utilities'
import { loadTexture } from '@/composables/gameComposable'
import { MapStorage } from '@/dexie/maps'
import { MapStorage } from '@/storage/storages'
import Tilemap = Phaser.Tilemaps.Tilemap
import TilemapLayer = Phaser.Tilemaps.TilemapLayer
@ -94,8 +94,6 @@ export async function loadMapTilesIntoScene(map_id: UUID, scene: Phaser.Scene) {
const tileArray = unduplicateArray(FlattenMapArray(map.tiles))
console.log(tileArray)
// Load each tile into the scene
for (const tile of tileArray) {
const textureData = {