Toggle build

🐛 Fix world gen tiles didn't align with placed ones
This commit is contained in:
2025-08-29 13:46:18 +08:00
parent 8073ed23c0
commit 885d2c0075
3 changed files with 31 additions and 3 deletions

View File

@@ -376,14 +376,16 @@ public partial class NaturalResourceGenerator : Node2D
return false;
}
var instance = scene.Instantiate() as Node2D;
if (instance == null)
if (scene.Instantiate() is not Node2D instance)
{
GD.PrintErr($"{LogPrefix} Failed to instantiate scene for: {tileType}");
return false;
}
instance.GlobalPosition = GridUtils.GridToWorld(cell);
// Use the same positioning logic as PlacementManager
var rotatedSize = building.GetRotatedSize(0f); // 0f for no rotation
var offset = GridUtils.GetCenterOffset(rotatedSize, 0f); // 0f for no rotation
instance.GlobalPosition = GridUtils.GridToWorld(cell) + offset;
instance.ZIndex = (int)building.Layer;
AddChild(instance);
Grid.OccupyArea(cell, instance, building.Size, 0f, building.Layer);