✨ Toggle build
🐛 Fix world gen tiles didn't align with placed ones
This commit is contained in:
@@ -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();
|
||||
|
Reference in New Issue
Block a user