Tiles able to deconstruct

This commit is contained in:
2025-08-26 22:22:10 +08:00
parent 44cd74b07c
commit 980e130cd0
3 changed files with 27 additions and 6 deletions

View File

@@ -44,13 +44,23 @@ public partial class PlacementManager : Node2D
_ghostBuilding.SetGhostMode(canPlace);
// Left click to place
if (!Input.IsActionPressed("build_tile") || !canPlace) return;
if (Input.IsActionPressed("build_tile") && canPlace)
{
_ghostBuilding.FinalizePlacement();
Grid.OccupyCell(_hoveredCell, _ghostBuilding);
_ghostBuilding.FinalizePlacement();
Grid.OccupyCell(_hoveredCell, _ghostBuilding);
_ghostBuilding = (BaseTile)BuildingScene.Instantiate();
_ghostBuilding.SetGhostMode(true);
AddChild(_ghostBuilding);
}
_ghostBuilding = (BaseTile)BuildingScene.Instantiate();
_ghostBuilding.SetGhostMode(true);
AddChild(_ghostBuilding);
if (Input.IsActionPressed("destroy_tile") && !Grid.IsCellFree(_hoveredCell))
{
// Right click to destroy
var building = Grid.GetBuildingAtCell(_hoveredCell);
if (building == null) return;
building.QueueFree();
Grid.FreeCell(_hoveredCell);
}
}
}