This commit is contained in:
2026-05-31 14:36:07 +02:00
parent b4ac00dcdd
commit 69c941b0e1
41 changed files with 39 additions and 324 deletions

15
Scripts/EventBus.cs Normal file
View File

@@ -0,0 +1,15 @@
using Godot;
namespace NodeWar.scripts;
public partial class EventBus : Node
{
[Signal]
public delegate void GameStartedEventHandler();
[Signal]
public delegate void GameEndedEventHandler(bool win);
[Signal]
public delegate void SelectionChangedEventHandler(string infoText);
}

1
Scripts/EventBus.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://462ni70mp6n1

9
Scripts/Extensions.cs Normal file
View File

@@ -0,0 +1,9 @@
namespace NodeWar.scripts;
public static class Extensions
{
public static float ToFloat(this double value)
{
return (float)value;
}
}

View File

@@ -0,0 +1 @@
uid://be5lfbu6by5ia

8
Scripts/Faction.cs Normal file
View File

@@ -0,0 +1,8 @@
namespace NodeWar.scripts;
public enum Faction
{
Neutral,
Player,
Computer,
}

1
Scripts/Faction.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://dqdhwvcshjo6p

View File

@@ -0,0 +1,6 @@
using Godot;
namespace NodeWar.Scripts.Globals;
[Autoload]
public partial class Autoloads { }

View File

@@ -0,0 +1 @@
uid://qs5yr2w7pldh

View File

@@ -0,0 +1,6 @@
using Godot;
namespace NodeWar.Scripts.Globals;
[InputMap]
public static partial class MyInput;

View File

@@ -0,0 +1 @@
uid://kd6fd7h745qu

6
Scripts/Globals/MyRes.cs Normal file
View File

@@ -0,0 +1,6 @@
using Godot;
namespace NodeWar.Scripts.Globals;
[ResourceTree("/")]
public static partial class MyRes;

View File

@@ -0,0 +1 @@
uid://ctul4f2nwmc3f

39
Scripts/Gui/Gui.cs Normal file
View File

@@ -0,0 +1,39 @@
using System.Globalization;
using Godot;
using GodotUtilities;
using NodeWar.Scripts.Globals;
namespace NodeWar.Scripts.Gui;
[Scene]
public partial class Gui : Control
{
[Node]
private Label _infoLabel;
[Node]
private Label _energyGeneration;
[Node]
private Label _energyConsumption;
[Node]
private Label _energyStorage;
public override void _Ready()
{
_energyGeneration.Text = 1f.ToString(CultureInfo.InvariantCulture);
_energyConsumption.Text = 0f.ToString(CultureInfo.InvariantCulture);
_energyStorage.Text = 100f.ToString(CultureInfo.InvariantCulture);
Autoloads.EventBus.SelectionChanged += text => _infoLabel.Text = text;
}
public override void _Notification(int what)
{
if (what == NotificationSceneInstantiated)
{
WireNodes();
}
}
}

1
Scripts/Gui/Gui.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://7jql2b33svuv

102
Scripts/Gui/Gui.tscn Normal file
View File

@@ -0,0 +1,102 @@
[gd_scene format=3 uid="uid://b1a13w4ckxnub"]
[ext_resource type="Script" uid="uid://7jql2b33svuv" path="res://Scripts/Gui/Gui.cs" id="1_80edf"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_80edf"]
bg_color = Color(0.7245737, 0.5838865, 0, 1)
corner_radius_top_left = 8
corner_radius_top_right = 8
corner_radius_bottom_right = 8
corner_radius_bottom_left = 8
[sub_resource type="LabelSettings" id="LabelSettings_k6omp"]
line_spacing = -2.0
font_size = 14
[node name="GUI" type="Control" unique_id=1209092314]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_80edf")
[node name="Top" type="PanelContainer" parent="." unique_id=1900556325]
layout_mode = 0
offset_left = 8.0
offset_top = 8.0
offset_right = 406.0
offset_bottom = 58.0
[node name="MarginContainer" type="MarginContainer" parent="Top" unique_id=653072330]
layout_mode = 2
theme_override_constants/margin_left = 8
theme_override_constants/margin_right = 8
[node name="HBoxContainer" type="HBoxContainer" parent="Top/MarginContainer" unique_id=1812335530]
layout_mode = 2
theme_override_constants/separation = 4
[node name="VBoxContainer" type="VBoxContainer" parent="Top/MarginContainer/HBoxContainer" unique_id=523855758]
custom_minimum_size = Vector2(54, 0)
layout_mode = 2
theme_override_constants/separation = -4
alignment = 1
[node name="EnergyGeneration" type="Label" parent="Top/MarginContainer/HBoxContainer/VBoxContainer" unique_id=358814115]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 8
text = "XX.XX"
[node name="EnergyConsumption" type="Label" parent="Top/MarginContainer/HBoxContainer/VBoxContainer" unique_id=343891974]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 8
theme_override_colors/font_color = Color(0.8701904, 0, 0.20575893, 1)
text = "-XX.XX"
[node name="EnergyProgressBar" type="ProgressBar" parent="Top/MarginContainer/HBoxContainer" unique_id=1761250517]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 25)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 4
theme_override_styles/fill = SubResource("StyleBoxFlat_80edf")
value = 37.15
show_percentage = false
[node name="EnergyStorage" type="Label" parent="Top/MarginContainer/HBoxContainer" unique_id=1992827443]
unique_name_in_owner = true
custom_minimum_size = Vector2(80, 0)
layout_mode = 2
size_flags_horizontal = 0
text = "MM,MMM"
[node name="PanelContainer" type="PanelContainer" parent="." unique_id=2071011957]
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 3.0
offset_top = -140.0
offset_right = 153.0
offset_bottom = -3.0
grow_vertical = 0
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer" unique_id=14334117]
layout_mode = 2
theme_override_constants/margin_left = 4
theme_override_constants/margin_top = 4
theme_override_constants/margin_right = 4
theme_override_constants/margin_bottom = 4
[node name="InfoLabel" type="Label" parent="PanelContainer/MarginContainer" unique_id=1653366042]
unique_name_in_owner = true
custom_minimum_size = Vector2(100, 100)
layout_mode = 2
size_flags_vertical = 1
label_settings = SubResource("LabelSettings_k6omp")
autowrap_mode = 3
text_overrun_behavior = 3

299
Scripts/LinePath2D.cs Normal file
View File

@@ -0,0 +1,299 @@
namespace NodeWar.scripts;
using Godot;
[Tool]
[GlobalClass]
public partial class LinePath2D : Path2D
{
private const bool ShouldCreateDefaultCurve = true;
private const bool ShouldCreateDefaultProfile = true;
// Size in pixels of the default curve
private const int DefaultCurveSize = 400;
// Size in pixels of the default curve width
private const float DefaultCurveWidth = 25.0f;
private Line2D _line = new();
[ExportCategory("LinePath2D")]
[Export]
public Curve2D LinePathCurve
{
get => Curve;
set
{
if (Curve != null)
Curve.Changed -= BuildLine;
Curve = value;
if (Curve != null)
Curve.Changed += BuildLine;
BuildLine();
}
}
/// <summary>
/// Sets the width of the curve.
/// </summary>
[Export]
public float Width
{
get => _line?.Width ?? DefaultCurveWidth;
set
{
if (_line == null)
return;
_line.Width = value;
}
}
/// <summary>
/// Use this Curve to modify the line width profile.
/// </summary>
[Export]
public Curve WidthProfile
{
get => _line?.WidthCurve;
set
{
if (_line == null)
return;
_line.WidthCurve = value;
}
}
[ExportGroup("Fill", "Fill")]
[Export]
public Color FillDefaultColor
{
get => _line?.DefaultColor ?? Colors.White;
set
{
if (_line != null)
_line.DefaultColor = value;
}
}
/// <summary>
/// Fill the path with a gradient.
/// </summary>
[Export]
public Gradient FillGradient
{
get => _line?.Gradient;
set
{
if (_line != null)
_line.Gradient = value;
}
}
/// <summary>
/// Fill the path with a texture.
/// </summary>
[Export]
public Texture2D FillTexture
{
get => _line?.Texture;
set
{
if (_line != null)
_line.Texture = value;
}
}
/// <summary>
/// Change the texture fill mode.
/// </summary>
[Export]
public Line2D.LineTextureMode FillTextureMode
{
get => _line?.TextureMode ?? Line2D.LineTextureMode.None;
set
{
if (_line != null)
_line.TextureMode = value;
}
}
[ExportGroup("Capping", "Cap")]
[Export]
public Line2D.LineJointMode CapJointMode
{
get => _line?.JointMode ?? Line2D.LineJointMode.Sharp;
set
{
if (_line != null)
_line.JointMode = value;
}
}
/// <summary>
/// The style of the beginning of the polyline.
/// </summary>
[Export]
public Line2D.LineCapMode CapBeginCap
{
get => _line?.BeginCapMode ?? Line2D.LineCapMode.None;
set
{
if (_line != null)
_line.BeginCapMode = value;
}
}
/// <summary>
/// The style of the ending of the polyline.
/// </summary>
[Export]
public Line2D.LineCapMode CapEndCap
{
get => _line?.EndCapMode ?? Line2D.LineCapMode.None;
set
{
if (_line != null)
_line.EndCapMode = value;
}
}
/// <summary>
/// If true and the polyline has more than two segments,
/// the first and the last point will be connected by a segment.
/// </summary>
[Export]
public bool CapCloseCurve
{
get => _line?.Closed ?? false;
set
{
if (_line != null)
_line.Closed = value;
}
}
[ExportGroup("Border", "Border")]
[Export]
public float BorderSharpLimit
{
get => _line?.SharpLimit ?? 2.0f;
set
{
if (_line != null)
_line.SharpLimit = value;
}
}
/// <summary>
/// The smoothness of the rounded joints and caps.
/// </summary>
[Export]
public int BorderRoundPrecision
{
get => _line?.RoundPrecision ?? 8;
set
{
if (_line != null)
_line.RoundPrecision = value;
}
}
/// <summary>
/// If true the polyline border will be antialiased.
/// Note: Antialiased polylines are not accelerated by batching.
/// </summary>
[Export]
public bool BorderAntialiased
{
get => _line?.Antialiased ?? false;
set
{
if (_line != null)
_line.Antialiased = value;
}
}
public override void _Ready()
{
ClearDuplicatedInternalChildren();
_line.SetMeta("__lp2d_internal__", true);
AddChild(_line);
if (Curve == null || Curve.PointCount < 2)
Curve = CreateDefaultCurve(DefaultCurveSize);
_line.WidthCurve ??= CreateDefaultProfile(DefaultCurveWidth);
BuildLine();
if (Curve != null)
{
Curve.Changed -= BuildLine;
Curve.Changed += BuildLine;
}
}
public override void _ExitTree()
{
if (Curve != null)
Curve.Changed -= BuildLine;
}
private Curve2D CreateDefaultCurve(int size)
{
if (!ShouldCreateDefaultCurve)
return null;
var curve = new Curve2D();
curve.AddPoint(Vector2.Zero, Vector2.Zero, new Vector2(size, 0));
curve.AddPoint(new Vector2(size, size), new Vector2(-size, 0), Vector2.Zero);
return curve;
}
private static Curve CreateDefaultProfile(float size)
{
if (!ShouldCreateDefaultProfile)
return null;
var curve = new Curve();
curve.AddPoint(Vector2.Zero);
curve.AddPoint(new Vector2(0.5f, 1.0f));
curve.AddPoint(new Vector2(1.0f, 0.0f));
return curve;
}
private void BuildLine()
{
if (_line == null)
return;
if (Curve == null || Curve.PointCount < 2)
{
_line.ClearPoints();
return;
}
_line.Points = Curve.GetBakedPoints();
}
private void ClearDuplicatedInternalChildren()
{
foreach (var child in GetChildren())
{
if (child.GetMeta("__lp2d_internal__", false).AsBool())
child.QueueFree();
}
}
}

View File

@@ -0,0 +1 @@
uid://u63irakc1xbq