Refactoring of modalShown booleans
This commit is contained in:
@ -9,10 +9,10 @@ import TilemapLayer = Phaser.Tilemaps.TilemapLayer
|
||||
import Tileset = Phaser.Tilemaps.Tileset
|
||||
import Tile = Phaser.Tilemaps.Tile
|
||||
|
||||
import type { Tile as TileT } from '@/application/types'
|
||||
|
||||
export function getTile(layer: TilemapLayer | Tilemap, positionX: number, positionY: number): Tile | null {
|
||||
const tile = layer?.getTileAtWorldXY(positionX, positionY)
|
||||
if (!tile) return null
|
||||
return tile
|
||||
return layer.getTileAtWorldXY(positionX, positionY)
|
||||
}
|
||||
|
||||
export function tileToWorldXY(layer: TilemapLayer | Tilemap, positionX: number, positionY: number) {
|
||||
@ -77,14 +77,18 @@ export const calculateIsometricDepth = (positionX: number, positionY: number, wi
|
||||
return baseDepth + (width + height) / (2 * config.tile_size.width)
|
||||
}
|
||||
|
||||
export function FlattenMapArray(tiles: string[][]) {
|
||||
const normalArray = []
|
||||
|
||||
for (const row of tiles) {
|
||||
normalArray.push(...row)
|
||||
async function getTiles(tiles: TileT[], scene: Phaser.Scene) {
|
||||
// Load each tile into the scene
|
||||
for (const tile of tiles) {
|
||||
if (!tile) continue
|
||||
const textureData = {
|
||||
key: tile.id,
|
||||
data: '/textures/tiles/' + tile.id + '.png',
|
||||
group: 'tiles',
|
||||
updatedAt: tile.updatedAt
|
||||
} as TextureData
|
||||
await loadTexture(scene, textureData)
|
||||
}
|
||||
|
||||
return normalArray
|
||||
}
|
||||
|
||||
export async function loadMapTilesIntoScene(map_id: UUID, scene: Phaser.Scene) {
|
||||
@ -93,50 +97,22 @@ export async function loadMapTilesIntoScene(map_id: UUID, scene: Phaser.Scene) {
|
||||
const map = await mapStorage.get(map_id)
|
||||
if (!map) return
|
||||
|
||||
const tileArray = unduplicateArray(FlattenMapArray(map.tiles))
|
||||
const tileArray = unduplicateArray(map.tiles)
|
||||
const tiles = await tileStorage.getByIds(tileArray)
|
||||
|
||||
// Load each tile into the scene
|
||||
for (const 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)
|
||||
}
|
||||
await getTiles(tiles, scene)
|
||||
}
|
||||
|
||||
export async function loadTilesIntoScene(tileIds: string[], scene: Phaser.Scene) {
|
||||
const tileStorage = new TileStorage()
|
||||
|
||||
const tiles = await tileStorage.getByIds(tileIds)
|
||||
|
||||
// Load each tile into the scene
|
||||
for (const 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)
|
||||
}
|
||||
await getTiles(tiles, scene)
|
||||
}
|
||||
|
||||
export async function loadAllTilesIntoScene(scene: Phaser.Scene) {
|
||||
const tileStorage = new TileStorage()
|
||||
const tiles = await tileStorage.getAll()
|
||||
|
||||
// Load each tile into the scene
|
||||
for (const 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)
|
||||
}
|
||||
getTiles(tiles, scene)
|
||||
}
|
||||
|
Reference in New Issue
Block a user