diff --git a/Slimepire.csproj.DotSettings b/Slimepire.csproj.DotSettings new file mode 100644 index 0000000..5139ed5 --- /dev/null +++ b/Slimepire.csproj.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/src/Core/EnergyManager.cs b/src/Core/EnergyManager.cs deleted file mode 100644 index b071941..0000000 --- a/src/Core/EnergyManager.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Godot; -using Slimepire.Gameplay.Components; - -namespace Slimepire.Core; - -[Singleton] -public partial class EnergyManager -{ - private List _energyProducers = []; - private List _energyStorages = []; - - public void RegisterEnergyProducer(EnergyProducer energyProducer) - { - _energyProducers.Add(energyProducer); - } - - public void RemoveEnergyProducer(EnergyProducer energyProducer) - { - _energyProducers.Remove(energyProducer); - } - - public void RegisterEnergyStorage(EnergyStorage energyStorage) - { - _energyStorages.Add(energyStorage); - } - - public void RemoveEnergyStorage(EnergyStorage energyStorage) - { - _energyStorages.Remove(energyStorage); - } - - public void TransferEnergy(float energy) - { - foreach (var energyStorage in _energyStorages) - { - if (energyStorage.Energy + energy <= energyStorage.MaxEnergy) - { - energyStorage.AcceptEnergy(energy); - } - } - } - - public void RequestEnergy(float energy) { } -} diff --git a/src/Core/EnergyManager.cs.uid b/src/Core/EnergyManager.cs.uid deleted file mode 100644 index 03d6593..0000000 --- a/src/Core/EnergyManager.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://boaiqjlh7qq3o diff --git a/src/Gameplay/Components/Energy/EnergyProducer.cs b/src/Gameplay/Components/Energy/EnergyProducer.cs new file mode 100644 index 0000000..1be0e4a --- /dev/null +++ b/src/Gameplay/Components/Energy/EnergyProducer.cs @@ -0,0 +1,17 @@ +using Godot; + +namespace Slimepire.Gameplay.Components; + +public partial class EnergyProducer : Node +{ + [Export] + public EnergyStorage EnergyStorage = null!; + + [Export] + public float ProductionRate = 1; + + public override void _Process(double delta) + { + EnergyStorage.Energy += ProductionRate * (float)delta; + } +} diff --git a/src/Gameplay/Components/EnergyProducer.cs.uid b/src/Gameplay/Components/Energy/EnergyProducer.cs.uid similarity index 100% rename from src/Gameplay/Components/EnergyProducer.cs.uid rename to src/Gameplay/Components/Energy/EnergyProducer.cs.uid diff --git a/src/Gameplay/Components/EnergyProducer.tscn b/src/Gameplay/Components/Energy/EnergyProducer.tscn similarity index 75% rename from src/Gameplay/Components/EnergyProducer.tscn rename to src/Gameplay/Components/Energy/EnergyProducer.tscn index ed98467..a2291da 100644 --- a/src/Gameplay/Components/EnergyProducer.tscn +++ b/src/Gameplay/Components/Energy/EnergyProducer.tscn @@ -1,6 +1,6 @@ [gd_scene format=3 uid="uid://t0gdf172f65v"] -[ext_resource type="Script" uid="uid://bku1vey63ew65" path="res://src/Gameplay/Components/EnergyProducer.cs" id="1_4q7h4"] +[ext_resource type="Script" uid="uid://bku1vey63ew65" path="res://src/Gameplay/Components/Energy/EnergyProducer.cs" id="1_4q7h4"] [node name="EnergyProducer" type="Node" unique_id=1184182162] script = ExtResource("1_4q7h4") diff --git a/src/Gameplay/Components/Energy/EnergyStorage.cs b/src/Gameplay/Components/Energy/EnergyStorage.cs new file mode 100644 index 0000000..67ba8e9 --- /dev/null +++ b/src/Gameplay/Components/Energy/EnergyStorage.cs @@ -0,0 +1,47 @@ +using Godot; + +namespace Slimepire.Gameplay.Components; + +[GlobalClass] +public partial class EnergyStorage : Node +{ + [Export] + public Label EnergyLabel = null!; + + [Export] + public float MaxEnergy = 100; + + public float Energy + { + get; + set + { + if (field + value > MaxEnergy) + { + field = MaxEnergy; + } + else + { + field += value; + } + + field = value; + UpdateLabel(); + } + } + + public override void _Ready() + { + UpdateLabel(); + } + + public override void _ExitTree() + { + // EnergyManager.Instance.RemoveEnergyStorage(this); + } + + private void UpdateLabel() + { + EnergyLabel.Text = $"{Energy:0}/{MaxEnergy}"; + } +} diff --git a/src/Gameplay/Components/EnergyStorage.cs.uid b/src/Gameplay/Components/Energy/EnergyStorage.cs.uid similarity index 100% rename from src/Gameplay/Components/EnergyStorage.cs.uid rename to src/Gameplay/Components/Energy/EnergyStorage.cs.uid diff --git a/src/Gameplay/Components/EnergyStorage.tscn b/src/Gameplay/Components/Energy/EnergyStorage.tscn similarity index 75% rename from src/Gameplay/Components/EnergyStorage.tscn rename to src/Gameplay/Components/Energy/EnergyStorage.tscn index 86690ad..9ee6b60 100644 --- a/src/Gameplay/Components/EnergyStorage.tscn +++ b/src/Gameplay/Components/Energy/EnergyStorage.tscn @@ -1,6 +1,6 @@ [gd_scene format=3 uid="uid://by6iw05ovnhq8"] -[ext_resource type="Script" uid="uid://dgkeo1wsicv13" path="res://src/Gameplay/Components/EnergyStorage.cs" id="1_vetx7"] +[ext_resource type="Script" uid="uid://dgkeo1wsicv13" path="res://src/Gameplay/Components/Energy/EnergyStorage.cs" id="1_vetx7"] [node name="EnergyStorage" type="Node" unique_id=1765924301] script = ExtResource("1_vetx7") diff --git a/src/Gameplay/Components/EnergyProducer.cs b/src/Gameplay/Components/EnergyProducer.cs deleted file mode 100644 index 00080ee..0000000 --- a/src/Gameplay/Components/EnergyProducer.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Godot; -using Slimepire.Core; - -namespace Slimepire.Gameplay.Components; - -public partial class EnergyProducer : Node -{ - [Export] - public float ProductionRate = 1; - - private float _energy; - - public override void _Ready() - { - EnergyManager.Instance.RegisterEnergyProducer(this); - } - - public override void _Process(double delta) - { - _energy += ProductionRate * (float)delta; - if (_energy > 1) - { - EnergyManager.Instance.TransferEnergy(_energy); - _energy = 0; - } - } - - public override void _ExitTree() - { - EnergyManager.Instance.RemoveEnergyProducer(this); - } -} diff --git a/src/Gameplay/Components/EnergyStorage.cs b/src/Gameplay/Components/EnergyStorage.cs deleted file mode 100644 index 1268b2d..0000000 --- a/src/Gameplay/Components/EnergyStorage.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Godot; -using Slimepire.Core; - -namespace Slimepire.Gameplay.Components; - -public partial class EnergyStorage : Node -{ - [Export] - public float MaxEnergy = 100; - - public float Energy { get; private set; } - - public override void _Ready() - { - EnergyManager.Instance.RegisterEnergyStorage(this); - } - - public override void _ExitTree() - { - EnergyManager.Instance.RemoveEnergyStorage(this); - } - - public float AcceptEnergy(float energy) - { - Energy += energy; - return Energy; - } -} diff --git a/src/Gameplay/Nodules/BasicNodule/BasicNodule.tscn b/src/Gameplay/Nodules/BasicNodule/BasicNodule.tscn index 6112a69..cb90c7c 100644 --- a/src/Gameplay/Nodules/BasicNodule/BasicNodule.tscn +++ b/src/Gameplay/Nodules/BasicNodule/BasicNodule.tscn @@ -37,19 +37,11 @@ animations = [{ "speed": 2.0 }] -[sub_resource type="LabelSettings" id="LabelSettings_x44k2"] -font_size = 12 -outline_size = 3 -outline_color = Color(0, 0, 0, 1) -shadow_size = 3 -shadow_color = Color(0, 0, 0, 1) - -[node name="BasicNodule" type="Node2D" unique_id=1637542829 node_paths=PackedStringArray("_tubeConnectionArea", "_gfx", "_energyLabel")] +[node name="BasicNodule" type="Node2D" unique_id=1637542829 node_paths=PackedStringArray("_tubeConnectionArea", "_gfx")] z_index = 1 script = ExtResource("1_wbqr8") _tubeConnectionArea = NodePath("TubeConnectionArea") _gfx = NodePath("Gfx") -_energyLabel = NodePath("EnergyLabel") [node name="TubeConnectionArea" parent="." unique_id=1821668398 instance=ExtResource("2_dehe6")] @@ -64,18 +56,3 @@ texture_filter = 1 sprite_frames = SubResource("SpriteFrames_xyjsl") autoplay = "default" frame_progress = 0.120879106 - -[node name="EnergyLabel" type="Label" parent="." unique_id=466024399] -unique_name_in_owner = true -anchors_preset = 5 -anchor_left = 0.5 -anchor_right = 0.5 -offset_left = -20.0 -offset_top = 14.0 -offset_right = 20.0 -offset_bottom = 31.0 -grow_horizontal = 2 -text = "5" -label_settings = SubResource("LabelSettings_x44k2") -horizontal_alignment = 1 -vertical_alignment = 1 diff --git a/src/Gameplay/Nodules/Nodule.cs b/src/Gameplay/Nodules/Nodule.cs index a3fa7e8..ed95375 100644 --- a/src/Gameplay/Nodules/Nodule.cs +++ b/src/Gameplay/Nodules/Nodule.cs @@ -11,9 +11,6 @@ public partial class Nodule : Node2D [Export] private AnimatedSprite2D _gfx = null!; - [Export] - private Label _energyLabel = null!; - public List Connections { get; } = []; protected AnimatedSprite2D Gfx => _gfx; diff --git a/src/Gameplay/Nodules/RootNodule/RootNodule.tscn b/src/Gameplay/Nodules/RootNodule/RootNodule.tscn index ce1f9c7..b3e5ce6 100644 --- a/src/Gameplay/Nodules/RootNodule/RootNodule.tscn +++ b/src/Gameplay/Nodules/RootNodule/RootNodule.tscn @@ -2,6 +2,8 @@ [ext_resource type="PackedScene" uid="uid://bjesfu1mfx8l5" path="res://src/Gameplay/Components/TubeConnectionArea.tscn" id="1_b03xe"] [ext_resource type="Script" uid="uid://y4cpi50hsaj4" path="res://src/Gameplay/Nodules/RootNodule/RootNodule.cs" id="1_root"] +[ext_resource type="PackedScene" uid="uid://t0gdf172f65v" path="res://src/Gameplay/Components/Energy/EnergyProducer.tscn" id="2_cy5pc"] +[ext_resource type="PackedScene" uid="uid://by6iw05ovnhq8" path="res://src/Gameplay/Components/Energy/EnergyStorage.tscn" id="2_gke5o"] [ext_resource type="PackedScene" uid="uid://3x5pqm4t5cbl" path="res://src/Gameplay/Components/GrowArea.tscn" id="2_tg6hi"] [ext_resource type="Texture2D" uid="uid://tomd3kojw0qy" path="res://assets/root_nodule.png" id="3_b03xe"] @@ -26,12 +28,17 @@ outline_color = Color(0, 0, 0, 1) shadow_size = 3 shadow_color = Color(0, 0, 0, 1) -[node name="RootNodule" type="Node2D" unique_id=1797926942 node_paths=PackedStringArray("_tubeConnectionArea", "_gfx", "_energyLabel")] +[node name="RootNodule" type="Node2D" unique_id=1797926942 node_paths=PackedStringArray("_tubeConnectionArea", "_gfx")] z_index = 1 script = ExtResource("1_root") _tubeConnectionArea = NodePath("TubeConnectionArea") _gfx = NodePath("Gfx") -_energyLabel = NodePath("EnergyLabel") + +[node name="EnergyProducer" parent="." unique_id=1184182162 node_paths=PackedStringArray("EnergyStorage") instance=ExtResource("2_cy5pc")] +EnergyStorage = NodePath("../EnergyStorage") + +[node name="EnergyStorage" parent="." unique_id=1765924301 node_paths=PackedStringArray("EnergyLabel") instance=ExtResource("2_gke5o")] +EnergyLabel = NodePath("../EnergyLabel") [node name="TubeConnectionArea" parent="." unique_id=1821668398 instance=ExtResource("1_b03xe")]