energy manager noch nicht fertig...
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
"uuid": "a2238a3b-e854-43e3-9655-fc856d21892b",
|
"uuid": "a2238a3b-e854-43e3-9655-fc856d21892b",
|
||||||
"title": "Todo",
|
"title": "Todo",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
|
"e2e29c87-042f-49e3-9c98-7ca6b258bcb7",
|
||||||
"36c8edc5-2708-440d-9bce-eaac534c3d84",
|
"36c8edc5-2708-440d-9bce-eaac534c3d84",
|
||||||
"49ef942e-e48b-4e79-9b61-756e061a0e1d",
|
"49ef942e-e48b-4e79-9b61-756e061a0e1d",
|
||||||
"3159b7fd-92d2-44e1-ab42-99e871e6fc77",
|
"3159b7fd-92d2-44e1-ab42-99e871e6fc77",
|
||||||
@@ -42,7 +43,7 @@
|
|||||||
{
|
{
|
||||||
"uuid": "36c8edc5-2708-440d-9bce-eaac534c3d84",
|
"uuid": "36c8edc5-2708-440d-9bce-eaac534c3d84",
|
||||||
"title": "EnergyManager",
|
"title": "EnergyManager",
|
||||||
"description": "",
|
"description": "soll es so ein Equilibrium geben, bei dem sich die Energie im System immer gleichmäßig verteilt?\n\nODER\n\n\"Saugen\" Depots Energie ein und Baustellen und Consumer requesten Energie von der nähsten Quelle/Depot?",
|
||||||
"category": "4bec2406-dc3d-416b-b6c4-d8fd7425b2b5",
|
"category": "4bec2406-dc3d-416b-b6c4-d8fd7425b2b5",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
@@ -78,6 +79,13 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"category": "4bec2406-dc3d-416b-b6c4-d8fd7425b2b5",
|
"category": "4bec2406-dc3d-416b-b6c4-d8fd7425b2b5",
|
||||||
"steps": []
|
"steps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uuid": "e2e29c87-042f-49e3-9c98-7ca6b258bcb7",
|
||||||
|
"title": "Nodules in einzelnen Scenes anstatt Resources und so",
|
||||||
|
"description": "",
|
||||||
|
"category": "4bec2406-dc3d-416b-b6c4-d8fd7425b2b5",
|
||||||
|
"steps": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"layout": {
|
"layout": {
|
||||||
|
|||||||
44
src/Core/EnergyManager.cs
Normal file
44
src/Core/EnergyManager.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using Godot;
|
||||||
|
using Slimepire.Gameplay.Nodules.Components;
|
||||||
|
|
||||||
|
namespace Slimepire.Core;
|
||||||
|
|
||||||
|
[Singleton]
|
||||||
|
public partial class EnergyManager
|
||||||
|
{
|
||||||
|
private List<EnergyProducer> _energyProducers = [];
|
||||||
|
private List<EnergyStorage> _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) { }
|
||||||
|
}
|
||||||
1
src/Core/EnergyManager.cs.uid
Normal file
1
src/Core/EnergyManager.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://boaiqjlh7qq3o
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
[gd_resource type="Resource" script_class="NoduleResource" format=3 uid="uid://0d8vif4ejtp1"]
|
[gd_resource type="Resource" script_class="NoduleResource" format=3 uid="uid://0d8vif4ejtp1"]
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://ds1idectpqbnh" path="res://assets/energy_storage_nodule.png" id="1_237jx"]
|
[ext_resource type="Texture2D" uid="uid://ds1idectpqbnh" path="res://assets/energy_storage_nodule.png" id="1_237jx"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://by6iw05ovnhq8" path="res://src/Gameplay/Nodules/Components/EnergyStorage.tscn" id="1_dusyu"]
|
||||||
[ext_resource type="Script" uid="uid://bnf6qmk64i2wj" path="res://src/Data/NoduleResource.cs" id="2_dusyu"]
|
[ext_resource type="Script" uid="uid://bnf6qmk64i2wj" path="res://src/Data/NoduleResource.cs" id="2_dusyu"]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_dusyu"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_dusyu"]
|
||||||
@@ -38,4 +39,5 @@ SpriteFrames = SubResource("SpriteFrames_j6wbi")
|
|||||||
Color = Color(0.60033447, 0.5019659, 0.0981792, 1)
|
Color = Color(0.60033447, 0.5019659, 0.0981792, 1)
|
||||||
NoduleName = "Energy Nodule"
|
NoduleName = "Energy Nodule"
|
||||||
MaxEnergy = 100.0
|
MaxEnergy = 100.0
|
||||||
|
Components = Array[PackedScene]([ExtResource("1_dusyu")])
|
||||||
metadata/_custom_type_script = "uid://bnf6qmk64i2wj"
|
metadata/_custom_type_script = "uid://bnf6qmk64i2wj"
|
||||||
|
|||||||
@@ -13,10 +13,4 @@ public partial class NoduleResource : Resource
|
|||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public string NoduleName = "Nodule";
|
public string NoduleName = "Nodule";
|
||||||
|
|
||||||
[Export]
|
|
||||||
public float MaxEnergy;
|
|
||||||
|
|
||||||
[Export]
|
|
||||||
public float EnergyRegenRate;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,5 @@ script = ExtResource("1_otepm")
|
|||||||
SpriteFrames = SubResource("SpriteFrames_x44k2")
|
SpriteFrames = SubResource("SpriteFrames_x44k2")
|
||||||
Color = Color(0.2642648, 0.46582836, 0.36528692, 1)
|
Color = Color(0.2642648, 0.46582836, 0.36528692, 1)
|
||||||
NoduleName = "Simple Nodule"
|
NoduleName = "Simple Nodule"
|
||||||
MaxEnergy = 2.0
|
NoduleType = 1
|
||||||
EnergyRegenRate = 0.1
|
|
||||||
metadata/_custom_type_script = "uid://bnf6qmk64i2wj"
|
metadata/_custom_type_script = "uid://bnf6qmk64i2wj"
|
||||||
|
|||||||
32
src/Gameplay/Nodules/Components/EnergyProducer.cs
Normal file
32
src/Gameplay/Nodules/Components/EnergyProducer.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using Godot;
|
||||||
|
using Slimepire.Core;
|
||||||
|
|
||||||
|
namespace Slimepire.Gameplay.Nodules.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
1
src/Gameplay/Nodules/Components/EnergyProducer.cs.uid
Normal file
1
src/Gameplay/Nodules/Components/EnergyProducer.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://bku1vey63ew65
|
||||||
6
src/Gameplay/Nodules/Components/EnergyProducer.tscn
Normal file
6
src/Gameplay/Nodules/Components/EnergyProducer.tscn
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[gd_scene format=3 uid="uid://t0gdf172f65v"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://bku1vey63ew65" path="res://src/Gameplay/Nodules/Components/EnergyProducer.cs" id="1_4q7h4"]
|
||||||
|
|
||||||
|
[node name="EnergyProducer" type="Node" unique_id=1184182162]
|
||||||
|
script = ExtResource("1_4q7h4")
|
||||||
28
src/Gameplay/Nodules/Components/EnergyStorage.cs
Normal file
28
src/Gameplay/Nodules/Components/EnergyStorage.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using Godot;
|
||||||
|
using Slimepire.Core;
|
||||||
|
|
||||||
|
namespace Slimepire.Gameplay.Nodules.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
1
src/Gameplay/Nodules/Components/EnergyStorage.cs.uid
Normal file
1
src/Gameplay/Nodules/Components/EnergyStorage.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://dgkeo1wsicv13
|
||||||
6
src/Gameplay/Nodules/Components/EnergyStorage.tscn
Normal file
6
src/Gameplay/Nodules/Components/EnergyStorage.tscn
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[gd_scene format=3 uid="uid://by6iw05ovnhq8"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://dgkeo1wsicv13" path="res://src/Gameplay/Nodules/Components/EnergyStorage.cs" id="1_vetx7"]
|
||||||
|
|
||||||
|
[node name="EnergyStorage" type="Node" unique_id=1765924301]
|
||||||
|
script = ExtResource("1_vetx7")
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
using Godot;
|
|
||||||
|
|
||||||
namespace Slimepire.Gameplay.Nodules;
|
|
||||||
|
|
||||||
[SceneTree]
|
|
||||||
public partial class Mitochondria : Node2D
|
|
||||||
{
|
|
||||||
public float Energy { get; set; } = 0;
|
|
||||||
public float MaxEnergy { get; set; } = 100;
|
|
||||||
public float EnergyRegenRate { get; set; } = 1;
|
|
||||||
|
|
||||||
public override void _Process(double delta)
|
|
||||||
{
|
|
||||||
if (Energy < MaxEnergy)
|
|
||||||
{
|
|
||||||
Energy += EnergyRegenRate * (float)delta;
|
|
||||||
}
|
|
||||||
GPUParticles2D.Amount = (int)Energy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
uid://h50qndjmmq4d
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -25,6 +25,7 @@ public partial class Nodule : Node2D
|
|||||||
{
|
{
|
||||||
Gfx.SpriteFrames = NoduleResource.SpriteFrames;
|
Gfx.SpriteFrames = NoduleResource.SpriteFrames;
|
||||||
Gfx.SelfModulate = NoduleResource.Color;
|
Gfx.SelfModulate = NoduleResource.Color;
|
||||||
|
Gfx.Play();
|
||||||
|
|
||||||
ClickArea.MouseEntered += ClickAreaOnMouseEntered;
|
ClickArea.MouseEntered += ClickAreaOnMouseEntered;
|
||||||
ClickArea.MouseExited += ClickAreaOnMouseExited;
|
ClickArea.MouseExited += ClickAreaOnMouseExited;
|
||||||
@@ -37,11 +38,6 @@ public partial class Nodule : Node2D
|
|||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
if (energy < NoduleResource.MaxEnergy)
|
|
||||||
{
|
|
||||||
energy += NoduleResource.EnergyRegenRate * (float)delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
EnergyLabel.Text = energy.ToString("F2");
|
EnergyLabel.Text = energy.ToString("F2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
[ext_resource type="Script" uid="uid://cmpl0if164dba" path="res://src/Gameplay/Nodules/Nodule.cs" id="1_yembh"]
|
[ext_resource type="Script" uid="uid://cmpl0if164dba" path="res://src/Gameplay/Nodules/Nodule.cs" id="1_yembh"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cecg47efx7gw8" path="res://assets/simple_nodule.png" id="2_7qt20"]
|
[ext_resource type="Texture2D" uid="uid://cecg47efx7gw8" path="res://assets/simple_nodule.png" id="2_7qt20"]
|
||||||
[ext_resource type="PackedScene" uid="uid://c11xdoiv2ch3w" path="res://src/Gameplay/Nodules/Mitochondria.tscn" id="3_x44k2"]
|
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_7qt20"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_7qt20"]
|
||||||
radius = 15.0
|
radius = 15.0
|
||||||
@@ -61,8 +60,7 @@ unique_name_in_owner = true
|
|||||||
texture_filter = 1
|
texture_filter = 1
|
||||||
sprite_frames = SubResource("SpriteFrames_xyjsl")
|
sprite_frames = SubResource("SpriteFrames_xyjsl")
|
||||||
autoplay = "default"
|
autoplay = "default"
|
||||||
frame = 1
|
frame_progress = 0.120879106
|
||||||
frame_progress = 0.9100785
|
|
||||||
|
|
||||||
[node name="TubeConnectionArea" type="Area2D" parent="." unique_id=339547035]
|
[node name="TubeConnectionArea" type="Area2D" parent="." unique_id=339547035]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
@@ -73,10 +71,6 @@ collision_mask = 2
|
|||||||
shape = SubResource("CircleShape2D_x44k2")
|
shape = SubResource("CircleShape2D_x44k2")
|
||||||
debug_color = Color(0.38922516, 0.6054754, 0.25354394, 0.41960785)
|
debug_color = Color(0.38922516, 0.6054754, 0.25354394, 0.41960785)
|
||||||
|
|
||||||
[node name="Mitochondria" parent="." unique_id=954228490 instance=ExtResource("3_x44k2")]
|
|
||||||
process_mode = 4
|
|
||||||
visible = false
|
|
||||||
|
|
||||||
[node name="EnergyLabel" type="Label" parent="." unique_id=466024399]
|
[node name="EnergyLabel" type="Label" parent="." unique_id=466024399]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
anchors_preset = 5
|
anchors_preset = 5
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
extends Node2D
|
|
||||||
|
|
||||||
var clicked_inside := false
|
|
||||||
|
|
||||||
func _unhandled_input(event: InputEvent) -> void:
|
|
||||||
if event is InputEventMouseButton:
|
|
||||||
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed == true:
|
|
||||||
clicked_inside = true
|
|
||||||
get_viewport().set_input_as_handled()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
uid://bvl0487nflq0q
|
|
||||||
Reference in New Issue
Block a user