forked from noxious/client
Map service fix attempt
This commit is contained in:
parent
a9cedba4e0
commit
f83d5eabee
@ -71,34 +71,16 @@ export const calculateIsometricDepth = (positionX: number, positionY: number, wi
|
||||
}
|
||||
|
||||
async function loadTileTextures(tiles: TileT[], scene: Phaser.Scene) {
|
||||
const tileStorage = new TileStorage()
|
||||
|
||||
// Process all tiles in parallel using Promise.all
|
||||
await Promise.all(
|
||||
tiles.map(async (tileData) => {
|
||||
try {
|
||||
// Get complete tile data if needed
|
||||
const tile = !tileData.id || !tileData.updatedAt ? await tileStorage.getById(tileData.id) : tileData
|
||||
|
||||
// Skip if tile data couldn't be retrieved
|
||||
if (!tile?.id) {
|
||||
console.warn(`Failed to load tile data for ID: ${tileData.id}`)
|
||||
return
|
||||
}
|
||||
|
||||
const textureData: TextureData = {
|
||||
key: tile.id,
|
||||
data: `/textures/tiles/${tile.id}.png`,
|
||||
group: 'tiles',
|
||||
updatedAt: tile.updatedAt
|
||||
}
|
||||
|
||||
await loadTexture(scene, textureData)
|
||||
} catch (error) {
|
||||
console.error(`Error loading texture for tile ${tileData.id}:`, error)
|
||||
}
|
||||
})
|
||||
)
|
||||
// Load each tile into the scene
|
||||
for (let tile of tiles) {
|
||||
const textureData = {
|
||||
key: tile.id,
|
||||
data: '/textures/tiles/' + tile.id + '.png',
|
||||
group: 'tiles',
|
||||
updatedAt: tile.updatedAt
|
||||
} as TextureData
|
||||
await loadTexture(scene, textureData)
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadTileTexturesFromMapTileArray(map_id: string, scene: Phaser.Scene) {
|
||||
@ -110,6 +92,7 @@ export async function loadTileTexturesFromMapTileArray(map_id: string, scene: Ph
|
||||
|
||||
const tileArray = unduplicateArray(map.tiles)
|
||||
const tiles = await tileStorage.getByIds(tileArray)
|
||||
if (!tiles) return
|
||||
|
||||
await loadTileTextures(tiles, scene)
|
||||
}
|
||||
@ -117,6 +100,7 @@ export async function loadTileTexturesFromMapTileArray(map_id: string, scene: Ph
|
||||
export async function loadAllTileTextures(scene: Phaser.Scene) {
|
||||
const tileStorage = new TileStorage()
|
||||
const tiles = await tileStorage.getAll()
|
||||
if (!tiles) return
|
||||
|
||||
await loadTileTextures(tiles, scene)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user