diff --git a/Autoloads.cs b/Autoloads.cs new file mode 100644 index 0000000..93950e2 --- /dev/null +++ b/Autoloads.cs @@ -0,0 +1,6 @@ +using Godot; + +namespace NodeWar; + +[Autoload] +public partial class Autoloads { } diff --git a/Autoloads.cs.uid b/Autoloads.cs.uid new file mode 100644 index 0000000..573ceb4 --- /dev/null +++ b/Autoloads.cs.uid @@ -0,0 +1 @@ +uid://djrh33q80nek diff --git a/BuildManager.cs b/BuildManager.cs new file mode 100644 index 0000000..347373c --- /dev/null +++ b/BuildManager.cs @@ -0,0 +1,66 @@ +using System.Collections.Generic; +using Godot; + +namespace NodeWar; + +public partial class BuildManager : Node +{ + public bool Building { get; set; } = false; + + public Nodule BuildingNodule { get; set; } + + public override void _Ready() { } + + [Export] + private PackedScene _noduleScene; + + [Export] + private PackedScene _rootScene; + + private Dictionary NoduleConnections { get; set; } = new(); + + public override void _Process(double delta) + { + if (Input.IsActionJustPressed("build") && !Building) + { + Building = true; + BuildingNodule = _noduleScene.Instantiate(); + 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); + } + } + + public void RegisterConnection(Nodule a, Nodule b) + { + if (!NoduleConnections.ContainsKey(new NoduleConnection { A = a, B = b })) + { + var root = _rootScene.Instantiate(); + GetParent().AddChild(root); + + root.ConnectNodules(a, b); + root.GlobalPosition = a.GlobalPosition; + + NoduleConnections.Add(new NoduleConnection { A = a, B = b }, root); + } + } +} diff --git a/BuildManager.cs.uid b/BuildManager.cs.uid new file mode 100644 index 0000000..4f95e56 --- /dev/null +++ b/BuildManager.cs.uid @@ -0,0 +1 @@ +uid://c2ufhsf60fl83 diff --git a/Gui.cs b/Gui.cs index 978e122..db46d39 100644 --- a/Gui.cs +++ b/Gui.cs @@ -1,13 +1,13 @@ using Godot; -using NodeWar.scripts; +using NodeWar; public partial class Gui : Control { private Label _infoLabel; - + public override void _Ready() { _infoLabel = GetNode