Building regisery instead of single building

This commit is contained in:
2025-08-26 22:35:23 +08:00
parent 980e130cd0
commit 4f92df9865
5 changed files with 96 additions and 8 deletions

View File

@@ -5,11 +5,23 @@ namespace AceFieldNewHorizon.Scripts.System;
public partial class PlacementManager : Node2D
{
[Export] public PackedScene BuildingScene { get; set; }
[Export] public GridManager Grid { get; set; }
[Export] public BuildingRegistry Registry { get; set; }
private string _currentBuildingId = "wall";
private Vector2I _hoveredCell;
private BaseTile _ghostBuilding;
public void SetCurrentBuilding(string buildingId)
{
_currentBuildingId = buildingId;
// Replace ghost immediately
if (_ghostBuilding == null) return;
_ghostBuilding.QueueFree();
_ghostBuilding = null;
}
public override void _Process(double delta)
{
@@ -19,7 +31,10 @@ public partial class PlacementManager : Node2D
if (_ghostBuilding == null)
{
_ghostBuilding = (BaseTile)BuildingScene.Instantiate();
var scene = Registry.GetScene(_currentBuildingId);
if (scene == null) return;
_ghostBuilding = (BaseTile)scene.Instantiate();
_ghostBuilding.SetGhostMode(true);
AddChild(_ghostBuilding);
}
@@ -46,10 +61,13 @@ public partial class PlacementManager : Node2D
// Left click to place
if (Input.IsActionPressed("build_tile") && canPlace)
{
var scene = Registry.GetScene(_currentBuildingId);
if (scene == null) return;
_ghostBuilding.FinalizePlacement();
Grid.OccupyCell(_hoveredCell, _ghostBuilding);
_ghostBuilding = (BaseTile)BuildingScene.Instantiate();
_ghostBuilding = (BaseTile)scene.Instantiate();
_ghostBuilding.SetGhostMode(true);
AddChild(_ghostBuilding);
}