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) {
|
async function loadTileTextures(tiles: TileT[], scene: Phaser.Scene) {
|
||||||
const tileStorage = new TileStorage()
|
// Load each tile into the scene
|
||||||
|
for (let tile of tiles) {
|
||||||
// Process all tiles in parallel using Promise.all
|
const textureData = {
|
||||||
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,
|
key: tile.id,
|
||||||
data: `/textures/tiles/${tile.id}.png`,
|
data: '/textures/tiles/' + tile.id + '.png',
|
||||||
group: 'tiles',
|
group: 'tiles',
|
||||||
updatedAt: tile.updatedAt
|
updatedAt: tile.updatedAt
|
||||||
}
|
} as TextureData
|
||||||
|
|
||||||
await loadTexture(scene, textureData)
|
await loadTexture(scene, textureData)
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error loading texture for tile ${tileData.id}:`, error)
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadTileTexturesFromMapTileArray(map_id: string, scene: Phaser.Scene) {
|
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 tileArray = unduplicateArray(map.tiles)
|
||||||
const tiles = await tileStorage.getByIds(tileArray)
|
const tiles = await tileStorage.getByIds(tileArray)
|
||||||
|
if (!tiles) return
|
||||||
|
|
||||||
await loadTileTextures(tiles, scene)
|
await loadTileTextures(tiles, scene)
|
||||||
}
|
}
|
||||||
@ -117,6 +100,7 @@ export async function loadTileTexturesFromMapTileArray(map_id: string, scene: Ph
|
|||||||
export async function loadAllTileTextures(scene: Phaser.Scene) {
|
export async function loadAllTileTextures(scene: Phaser.Scene) {
|
||||||
const tileStorage = new TileStorage()
|
const tileStorage = new TileStorage()
|
||||||
const tiles = await tileStorage.getAll()
|
const tiles = await tileStorage.getAll()
|
||||||
|
if (!tiles) return
|
||||||
|
|
||||||
await loadTileTextures(tiles, scene)
|
await loadTileTextures(tiles, scene)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user