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

@@ -11,11 +11,15 @@ public partial class PlacementManager : Node2D
[Export] public GridManager Grid { get; set; }
[Export] public ResourceManager Inventory { get; set; }
[Export] public BuildingRegistry Registry { get; set; }
[Export] public int MaxConcurrentBuilds { get; set; } = 6; // Make it adjustable in editor
[Export] public bool Enabled { get; set; } = true;
[Export] public StringName ToggleBuildAction { get; set; } = "toggle_build";
private static readonly List<string> BuildableTiles = ["wall", "miner"];
private readonly Dictionary<Node2D, BuildTask> _buildTasks = new();
private AudioStreamPlayer _completionSound;
private Node2D _currentGhost; // Keep track of the current ghost building
public override void _Ready()
{
@@ -153,6 +157,8 @@ public partial class PlacementManager : Node2D
public override void _Process(double delta)
{
if (!Enabled) return;
// Snap mouse to grid
var mousePos = GetGlobalMousePosition();
var newHoveredCell = GridUtils.WorldToGrid(mousePos);
@@ -267,6 +273,21 @@ public partial class PlacementManager : Node2D
}
}
public override void _Input(InputEvent @event)
{
if (@event.IsActionPressed(ToggleBuildAction))
{
Enabled = !Enabled;
// Hide ghost building when disabling
if (!Enabled && _ghostBuilding != null && _ghostBuilding.IsInsideTree())
{
_ghostBuilding.QueueFree();
_ghostBuilding = null;
}
}
}
public override void _ExitTree()
{
base._ExitTree();