65 lines
1.3 KiB
C#
65 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using Godot;
|
|
|
|
namespace NodeWar;
|
|
|
|
public partial class BuildManager : Node
|
|
{
|
|
public bool IsBuilding { get; set; }
|
|
|
|
private Nodule BuildingNodule { get; set; }
|
|
|
|
private Dictionary<NoduleConnection, Root> NoduleConnections { get; set; } = new();
|
|
|
|
public static BuildManager Instance { get; private set; }
|
|
|
|
public override void _Ready()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (Input.IsActionJustPressed(Scripts.Globals.MyInput.Build) && !IsBuilding)
|
|
{
|
|
StartBuilding();
|
|
}
|
|
}
|
|
|
|
private void StartBuilding()
|
|
{
|
|
BuildingNodule = Instantiator.Instantiate<Nodule>();
|
|
|
|
IsBuilding = true;
|
|
BuildingNodule.BuildMode = true;
|
|
|
|
BuildingNodule.NoduleBuilt += () =>
|
|
{
|
|
IsBuilding = false;
|
|
BuildingNodule = null;
|
|
};
|
|
|
|
BuildingNodule.BuildingCanceled += () =>
|
|
{
|
|
IsBuilding = false;
|
|
BuildingNodule = null;
|
|
};
|
|
|
|
GetParent().AddChild(BuildingNodule);
|
|
}
|
|
|
|
public void RegisterConnection(Nodule a, Nodule b)
|
|
{
|
|
if (!NoduleConnections.ContainsKey(new NoduleConnection { A = a, B = b }))
|
|
{
|
|
var root = Instantiator.Instantiate<Root>();
|
|
GetParent().AddChild(root);
|
|
|
|
root.ConnectNodules(a, b);
|
|
root.GlobalPosition = a.GlobalPosition;
|
|
|
|
NoduleConnections.Add(new NoduleConnection { A = a, B = b }, root);
|
|
}
|
|
}
|
|
}
|