✨ Tiles able to deconstruct
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
|
||||
@@ -21,6 +22,11 @@ public partial class GridManager : Node
|
||||
{
|
||||
_grid.Remove(cell);
|
||||
}
|
||||
|
||||
public Node2D? GetBuildingAtCell(Vector2I cell)
|
||||
{
|
||||
return _grid.GetValueOrDefault(cell);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GridUtils
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user