asd
This commit is contained in:
@@ -3,58 +3,50 @@ using Godot;
|
||||
|
||||
namespace NodeWar;
|
||||
|
||||
[Singleton]
|
||||
public partial class BuildManager : Node
|
||||
{
|
||||
public bool Building { get; set; } = false;
|
||||
private bool Building { get; set; }
|
||||
|
||||
public Nodule BuildingNodule { get; set; }
|
||||
|
||||
public override void _Ready() { }
|
||||
|
||||
[Export]
|
||||
private PackedScene _noduleScene;
|
||||
|
||||
[Export]
|
||||
private PackedScene _rootScene;
|
||||
private Nodule BuildingNodule { get; set; }
|
||||
|
||||
private Dictionary<NoduleConnection, Root> NoduleConnections { get; set; } = new();
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("build") && !Building)
|
||||
if (Input.IsActionJustPressed(MyInput.Build) && !Building)
|
||||
{
|
||||
Building = true;
|
||||
BuildingNodule = _noduleScene.Instantiate<Nodule>();
|
||||
BuildingNodule.BuildMode = true;
|
||||
|
||||
BuildingNodule.NoduleBuilt += () =>
|
||||
{
|
||||
Building = false;
|
||||
|
||||
// try connecting built nodule to connected ones
|
||||
foreach (var connectedNodule in BuildingNodule.ConnectedNodules)
|
||||
{
|
||||
RegisterConnection(BuildingNodule, connectedNodule);
|
||||
}
|
||||
|
||||
BuildingNodule = null;
|
||||
};
|
||||
|
||||
BuildingNodule.BuildingCanceled += () =>
|
||||
{
|
||||
Building = false;
|
||||
BuildingNodule = null;
|
||||
};
|
||||
|
||||
GetParent().AddChild(BuildingNodule);
|
||||
StartBuilding();
|
||||
}
|
||||
}
|
||||
|
||||
private void StartBuilding()
|
||||
{
|
||||
BuildingNodule = Instantiator.Instantiate<Nodule>();
|
||||
|
||||
Building = true;
|
||||
BuildingNodule.BuildMode = true;
|
||||
|
||||
BuildingNodule.NoduleBuilt += () =>
|
||||
{
|
||||
Building = false;
|
||||
BuildingNodule = null;
|
||||
};
|
||||
|
||||
BuildingNodule.BuildingCanceled += () =>
|
||||
{
|
||||
Building = false;
|
||||
BuildingNodule = null;
|
||||
};
|
||||
|
||||
GetParent().AddChild(BuildingNodule);
|
||||
}
|
||||
|
||||
public void RegisterConnection(Nodule a, Nodule b)
|
||||
{
|
||||
if (!NoduleConnections.ContainsKey(new NoduleConnection { A = a, B = b }))
|
||||
{
|
||||
var root = _rootScene.Instantiate<Root>();
|
||||
var root = Instantiator.Instantiate<Root>();
|
||||
GetParent().AddChild(root);
|
||||
|
||||
root.ConnectNodules(a, b);
|
||||
|
||||
Reference in New Issue
Block a user