From 661e62e8b8f2415746e2cc5dcdc7a3ed96edb211 Mon Sep 17 00:00:00 2001 From: Jens Becker Date: Wed, 20 May 2026 16:34:39 +0200 Subject: [PATCH] connections --- Autoloads.cs | 6 + Autoloads.cs.uid | 1 + BuildManager.cs | 66 ++++ BuildManager.cs.uid | 1 + Gui.cs | 6 +- Node War.csproj | 24 +- Nodule.cs | 139 ++++++++ Nodule.cs.uid | 1 + NoduleConnection.cs | 19 ++ NoduleConnection.cs.uid | 1 + Root.cs | 30 ++ Root.cs.uid | 1 + scripts/TODO.md => TODO.md | 0 .../scalable_vector_shape_2d.gd | 2 - addons/linepath2d/icon.svg | 23 ++ addons/linepath2d/icon.svg.import | 43 +++ addons/linepath2d/linepath2d.gd | 248 +++++++++++++++ addons/linepath2d/linepath2d.gd.uid | 1 + addons/linepath2d/plugin.cfg | 7 + addons/linepath2d/plugin.gd | 31 ++ addons/linepath2d/plugin.gd.uid | 1 + base.tscn | 98 ------ main.tscn | 30 +- nodule.tscn | 58 ++++ project.godot | 13 +- root.tscn | 14 + scripts/Base.cs | 102 ------ scripts/Base.cs.uid | 1 - Damager.cs => scripts/Damager.cs | 0 Damager.cs.uid => scripts/Damager.cs.uid | 0 scripts/EventBus.cs | 14 +- scripts/Extensions.cs | 10 +- scripts/LinePath2D.cs | 299 ++++++++++++++++++ scripts/LinePath2D.cs.uid | 1 + scripts/Pip.cs | 6 +- 35 files changed, 1039 insertions(+), 258 deletions(-) create mode 100644 Autoloads.cs create mode 100644 Autoloads.cs.uid create mode 100644 BuildManager.cs create mode 100644 BuildManager.cs.uid create mode 100644 Nodule.cs create mode 100644 Nodule.cs.uid create mode 100644 NoduleConnection.cs create mode 100644 NoduleConnection.cs.uid create mode 100644 Root.cs create mode 100644 Root.cs.uid rename scripts/TODO.md => TODO.md (100%) create mode 100644 addons/linepath2d/icon.svg create mode 100644 addons/linepath2d/icon.svg.import create mode 100644 addons/linepath2d/linepath2d.gd create mode 100644 addons/linepath2d/linepath2d.gd.uid create mode 100644 addons/linepath2d/plugin.cfg create mode 100644 addons/linepath2d/plugin.gd create mode 100644 addons/linepath2d/plugin.gd.uid delete mode 100644 base.tscn create mode 100644 nodule.tscn create mode 100644 root.tscn delete mode 100644 scripts/Base.cs delete mode 100644 scripts/Base.cs.uid rename Damager.cs => scripts/Damager.cs (100%) rename Damager.cs.uid => scripts/Damager.cs.uid (100%) create mode 100644 scripts/LinePath2D.cs create mode 100644 scripts/LinePath2D.cs.uid 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