forked from noxious/client
npm run format
This commit is contained in:
@ -73,43 +73,43 @@ export const initializeZoneTiles = (zoneTilemap: Tilemap, tiles: Phaser.Tilemaps
|
||||
}
|
||||
|
||||
export const updateZoneTiles = (zoneTilemap: Tilemap, tiles: Phaser.Tilemaps.TilemapLayer, zone: Zone) => {
|
||||
if (zone.tiles) {
|
||||
setAllTiles(zoneTilemap, tiles, zone.tiles)
|
||||
const zoneTiles = zone.tiles
|
||||
|
||||
// Ensure zoneTiles matches the current zone dimensions, filling new spaces with 'blank_tile'
|
||||
for (let y = 0; y < zone.height; y++) {
|
||||
zoneTiles[y] = zoneTiles[y] || [] // Ensure the row exists
|
||||
for (let x = 0; x < zone.width; x++) {
|
||||
zoneTiles[y][x] = zoneTiles[y][x] || 'blank_tile' // Fill missing tiles with 'blank_tile'
|
||||
}
|
||||
}
|
||||
|
||||
// Update the tilemap with any new 'blank_tile' entries
|
||||
zoneTiles.forEach((row: any, y: any) => {
|
||||
row.forEach((tileId: any, x: any) => {
|
||||
placeTile(zoneTilemap, tiles, x, y, tileId)
|
||||
})
|
||||
})
|
||||
|
||||
return zoneTiles
|
||||
if (!zone.tiles) {
|
||||
return []
|
||||
}
|
||||
return []
|
||||
|
||||
setAllTiles(zoneTilemap, tiles, zone.tiles)
|
||||
const zoneTiles = zone.tiles
|
||||
|
||||
// Ensure zoneTiles matches the current zone dimensions, filling new spaces with 'blank_tile'
|
||||
for (let y = 0; y < zone.height; y++) {
|
||||
zoneTiles[y] = zoneTiles[y] || [] // Ensure the row exists
|
||||
for (let x = 0; x < zone.width; x++) {
|
||||
zoneTiles[y][x] = zoneTiles[y][x] || 'blank_tile' // Fill missing tiles with 'blank_tile'
|
||||
}
|
||||
}
|
||||
|
||||
// Update the tilemap with any new 'blank_tile' entries
|
||||
zoneTiles.forEach((row: any, y: any) => {
|
||||
row.forEach((tileId: any, x: any) => {
|
||||
placeTile(zoneTilemap, tiles, x, y, tileId)
|
||||
})
|
||||
})
|
||||
|
||||
return zoneTiles
|
||||
}
|
||||
|
||||
export const calculateIsometricDepth = (x: number, y: number, height: number = 0) => {
|
||||
// Adjust these values as needed for your specific isometric projection
|
||||
const isoX = x - y;
|
||||
const isoY = (x + y) / 2;
|
||||
return isoY - height * 0.1; // Subtract height to make taller objects appear behind shorter ones
|
||||
// const isoX = x - y;
|
||||
const isoY = (x + y) / 2
|
||||
return isoY - height * 0.1 // Subtract height to make taller objects appear behind shorter ones
|
||||
}
|
||||
|
||||
export const sortByIsometricDepth = <T extends { positionX: number; positionY: number; object?: { height?: number } }>(items: T[]) => {
|
||||
return [...items].sort((a, b) => {
|
||||
const aHeight = a.object?.height || 0;
|
||||
const bHeight = b.object?.height || 0;
|
||||
return calculateIsometricDepth(a.positionX, a.positionY, aHeight) - calculateIsometricDepth(b.positionX, b.positionY, bHeight);
|
||||
});
|
||||
const aHeight = a.object?.height || 0
|
||||
const bHeight = b.object?.height || 0
|
||||
return calculateIsometricDepth(a.positionX, a.positionY, aHeight) - calculateIsometricDepth(b.positionX, b.positionY, bHeight)
|
||||
})
|
||||
}
|
||||
|
||||
// Redundant, but left here for reference
|
||||
|
Reference in New Issue
Block a user