♻️ Optimizations of the various system

🍱 Retexture of the enemy portal
This commit is contained in:
2025-08-31 18:26:45 +08:00
parent 09511b37c9
commit b424aafeab
16 changed files with 497 additions and 399 deletions

View File

@@ -428,32 +428,28 @@ public static class GridManagerExtensions
public static (Vector2I Position, Vector2I Size, float Rotation)? GetBuildingInfoAtCell(this GridManager grid,
Vector2I cell, GridLayer layer)
{
if (grid.GetTileAtCell(cell, layer) is { } building)
if (grid.GetTileAtCell(cell, layer) is not { } building) return null;
// Find the top-left position of the building
for (var x = 0; x < 100; x++) // Arbitrary max size
{
// Find the top-left position of the building
for (int x = 0; x < 100; x++) // Arbitrary max size
for (var y = 0; y < 100; y++)
{
for (int y = 0; y < 100; y++)
{
var checkCell = new Vector2I(cell.X - x, cell.Y - y);
if (grid.GetTileAtCell(checkCell, layer) == building)
{
// Found the top-left corner, now find the size
var size = Vector2I.One;
// Search right
while (grid.GetTileAtCell(new Vector2I(checkCell.X + size.X, checkCell.Y), layer) ==
building)
size.X++;
// Search down
while (grid.GetTileAtCell(new Vector2I(checkCell.X, checkCell.Y + size.Y), layer) ==
building)
size.Y++;
var checkCell = new Vector2I(cell.X - x, cell.Y - y);
if (grid.GetTileAtCell(checkCell, layer) != building) continue;
// Found the top-left corner, now find the size
var size = Vector2I.One;
// Search right
while (grid.GetTileAtCell(new Vector2I(checkCell.X + size.X, checkCell.Y), layer) ==
building)
size.X++;
// Search down
while (grid.GetTileAtCell(new Vector2I(checkCell.X, checkCell.Y + size.Y), layer) ==
building)
size.Y++;
// Get rotation from the first cell
var rotation = 0f; // You'll need to store rotation in GridManager to make this work
return (checkCell, size, rotation);
}
}
// Get rotation from the first cell
var rotation = 0f; // You'll need to store rotation in Grid to make this work
return (checkCell, size, rotation);
}
}