Compare commits
2 Commits
88647b1c41
...
c72353716f
Author | SHA1 | Date | |
---|---|---|---|
c72353716f | |||
1cc941d893 |
@@ -4,4 +4,7 @@
|
|||||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
<RootNamespace>AceFieldNewHorizon</RootNamespace>
|
<RootNamespace>AceFieldNewHorizon</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="SimpleInjector" Version="5.5.0" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@@ -1,38 +1,24 @@
|
|||||||
[gd_scene load_steps=8 format=3 uid="uid://c22aprj452aha"]
|
[gd_scene load_steps=6 format=3 uid="uid://c22aprj452aha"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://cudpc3w17mbsw" path="res://Scripts/System/GridManager.cs" id="1_knkkn"]
|
|
||||||
[ext_resource type="Script" uid="uid://dfi2snip78eq6" path="res://Scripts/System/ResourceManager.cs" id="1_pl8e4"]
|
|
||||||
[ext_resource type="Script" uid="uid://cfbj72nm0eovg" path="res://Scripts/System/BuildingRegistry.cs" id="1_sxhdm"]
|
|
||||||
[ext_resource type="Script" uid="uid://cugfbvw70clgd" path="res://Scripts/System/NaturalResourceGenerator.cs" id="2_oss8w"]
|
[ext_resource type="Script" uid="uid://cugfbvw70clgd" path="res://Scripts/System/NaturalResourceGenerator.cs" id="2_oss8w"]
|
||||||
[ext_resource type="Script" uid="uid://bx1wj7gn6vrqe" path="res://Scripts/System/PlacementManager.cs" id="2_sxhdm"]
|
[ext_resource type="Script" uid="uid://bx1wj7gn6vrqe" path="res://Scripts/System/PlacementManager.cs" id="2_sxhdm"]
|
||||||
[ext_resource type="PackedScene" uid="uid://doxy60afddg1m" path="res://Scenes/Entities/Player.tscn" id="3_oss8w"]
|
[ext_resource type="PackedScene" uid="uid://doxy60afddg1m" path="res://Scenes/Entities/Player.tscn" id="3_oss8w"]
|
||||||
[ext_resource type="PackedScene" uid="uid://xwkplaxmye3v" path="res://Scenes/System/ItemPickup.tscn" id="7_is6ib"]
|
[ext_resource type="PackedScene" uid="uid://xwkplaxmye3v" path="res://Scenes/System/ItemPickup.tscn" id="7_is6ib"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://byv2vu0k2drdd" path="res://Scenes/System/HUD.tscn" id="8_hud_scene"]
|
||||||
|
|
||||||
[node name="Root" type="Node2D"]
|
[node name="Root" type="Node2D"]
|
||||||
|
|
||||||
[node name="ResourceSystem" type="Node" parent="."]
|
[node name="NaturalResourceGenerator" type="Node2D" parent="."]
|
||||||
script = ExtResource("1_pl8e4")
|
|
||||||
|
|
||||||
[node name="BuildingRegistry" type="Node" parent="."]
|
|
||||||
script = ExtResource("1_sxhdm")
|
|
||||||
|
|
||||||
[node name="NaturalResourceGenerator" type="Node2D" parent="." node_paths=PackedStringArray("Grid", "Registry")]
|
|
||||||
script = ExtResource("2_oss8w")
|
script = ExtResource("2_oss8w")
|
||||||
Grid = NodePath("../GridSystem")
|
|
||||||
Registry = NodePath("../BuildingRegistry")
|
|
||||||
|
|
||||||
[node name="GridSystem" type="Node2D" parent="."]
|
[node name="PlacementSystem" type="Node2D" parent="."]
|
||||||
script = ExtResource("1_knkkn")
|
|
||||||
|
|
||||||
[node name="PlacementSystem" type="Node2D" parent="." node_paths=PackedStringArray("Grid", "Inventory", "Registry")]
|
|
||||||
script = ExtResource("2_sxhdm")
|
script = ExtResource("2_sxhdm")
|
||||||
Grid = NodePath("../GridSystem")
|
|
||||||
Inventory = NodePath("../ResourceSystem")
|
|
||||||
Registry = NodePath("../BuildingRegistry")
|
|
||||||
|
|
||||||
[node name="Player" parent="." node_paths=PackedStringArray("Inventory") instance=ExtResource("3_oss8w")]
|
[node name="Player" parent="." node_paths=PackedStringArray("Inventory") instance=ExtResource("3_oss8w")]
|
||||||
scale = Vector2(0.35, 0.35)
|
scale = Vector2(0.35, 0.35)
|
||||||
Inventory = NodePath("../ResourceSystem")
|
Inventory = NodePath("")
|
||||||
|
|
||||||
|
[node name="HUD" parent="." instance=ExtResource("8_hud_scene")]
|
||||||
|
|
||||||
[node name="ItemPickup" parent="." instance=ExtResource("7_is6ib")]
|
[node name="ItemPickup" parent="." instance=ExtResource("7_is6ib")]
|
||||||
position = Vector2(-496, -245)
|
position = Vector2(-496, -245)
|
||||||
|
13
Scenes/System/HUD.tscn
Normal file
13
Scenes/System/HUD.tscn
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[gd_scene load_steps=2 format=3 uid="uid://byv2vu0k2drdd"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://ddoqqcg77f60v" path="res://Scripts/System/Hud.cs" id="1_yw4ou"]
|
||||||
|
|
||||||
|
[node name="HUD" type="CanvasLayer"]
|
||||||
|
script = ExtResource("1_yw4ou")
|
||||||
|
|
||||||
|
[node name="ResourceDisplay" type="VBoxContainer" parent="."]
|
||||||
|
layout_mode = 0
|
||||||
|
offset_left = 10.0
|
||||||
|
offset_top = 10.0
|
||||||
|
offset_right = 100.0
|
||||||
|
offset_bottom = 100.0
|
14
Scripts/AutoLoad/DIInitializer.cs
Normal file
14
Scripts/AutoLoad/DIInitializer.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using Godot;
|
||||||
|
using AceFieldNewHorizon.Scripts.System;
|
||||||
|
|
||||||
|
namespace AceFieldNewHorizon.Scripts.AutoLoad;
|
||||||
|
|
||||||
|
public partial class DIInitializer : Node
|
||||||
|
{
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
// Initialize the Simple Injector container as early as possible
|
||||||
|
DependencyInjection.Initialize();
|
||||||
|
GD.Print("[DIInitializer] Dependency Injection container initialized via AutoLoad.");
|
||||||
|
}
|
||||||
|
}
|
1
Scripts/AutoLoad/DIInitializer.cs.uid
Normal file
1
Scripts/AutoLoad/DIInitializer.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://cr2a8w6ur4uei
|
@@ -20,7 +20,7 @@ public partial class Player : CharacterBody2D
|
|||||||
[Export] public float ZoomDecay = 0.9f;
|
[Export] public float ZoomDecay = 0.9f;
|
||||||
[Export] public float ZoomSmoothing = 10.0f;
|
[Export] public float ZoomSmoothing = 10.0f;
|
||||||
|
|
||||||
[Export] public ResourceManager Inventory;
|
public ResourceManager Inventory { get; private set; }
|
||||||
|
|
||||||
private Camera2D _camera;
|
private Camera2D _camera;
|
||||||
private Vector2 _cameraTargetZoom = Vector2.One;
|
private Vector2 _cameraTargetZoom = Vector2.One;
|
||||||
@@ -33,6 +33,8 @@ public partial class Player : CharacterBody2D
|
|||||||
_camera = GetNode<Camera2D>("Camera2D");
|
_camera = GetNode<Camera2D>("Camera2D");
|
||||||
_cameraTargetZoom = _camera.Zoom;
|
_cameraTargetZoom = _camera.Zoom;
|
||||||
|
|
||||||
|
Inventory = DependencyInjection.Container.GetInstance<ResourceManager>();
|
||||||
|
|
||||||
AddToGroup(ItemPickup.PickupGroupName);
|
AddToGroup(ItemPickup.PickupGroupName);
|
||||||
AddToGroup(NaturalResourceGenerator.ChunkTrackerGroupName);
|
AddToGroup(NaturalResourceGenerator.ChunkTrackerGroupName);
|
||||||
}
|
}
|
||||||
|
27
Scripts/Root.cs
Normal file
27
Scripts/Root.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using Godot;
|
||||||
|
using AceFieldNewHorizon.Scripts.System;
|
||||||
|
using SimpleInjector;
|
||||||
|
|
||||||
|
namespace AceFieldNewHorizon.Scripts;
|
||||||
|
|
||||||
|
public partial class Root : Node
|
||||||
|
{
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
// Dependency Injection container is now initialized via AutoLoad (DIInitializer.cs).
|
||||||
|
|
||||||
|
// Get references to the main system nodes from the scene tree
|
||||||
|
// and inject their dependencies.
|
||||||
|
// This assumes these nodes are direct children or easily accessible.
|
||||||
|
// You might need to adjust paths based on your scene setup.
|
||||||
|
|
||||||
|
// Example:
|
||||||
|
// var resourceManager = GetNode<ResourceManager>("ResourceSystem"); // Assuming ResourceManager is a child of Root
|
||||||
|
// DependencyInjection.Container.InjectProperties(resourceManager); // If ResourceManager had properties to inject
|
||||||
|
|
||||||
|
// For now, we'll manually resolve and assign for the main system nodes.
|
||||||
|
// The actual injection will happen in the _Ready methods of the system nodes themselves,
|
||||||
|
// by resolving from the static container.
|
||||||
|
// This is a common pattern when Godot instantiates the nodes.
|
||||||
|
}
|
||||||
|
}
|
1
Scripts/Root.cs.uid
Normal file
1
Scripts/Root.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://dmint8ii0oj5g
|
@@ -40,15 +40,15 @@ public record BuildingData(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class BuildingRegistry : Node
|
public class BuildingRegistry
|
||||||
{
|
{
|
||||||
private Dictionary<string, BuildingData> _registry = new();
|
private Dictionary<string, BuildingData> _registry = new();
|
||||||
|
|
||||||
[Export] public string JsonPath { get; set; } = "res://Data/Buildings.json";
|
|
||||||
|
|
||||||
public override void _Ready()
|
public BuildingRegistry(string jsonPath)
|
||||||
{
|
{
|
||||||
LoadFromJson(JsonPath);
|
LoadFromJson(jsonPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadFromJson(string path)
|
public void LoadFromJson(string path)
|
||||||
|
23
Scripts/System/DependencyInjection.cs
Normal file
23
Scripts/System/DependencyInjection.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using Godot;
|
||||||
|
using Container = SimpleInjector.Container;
|
||||||
|
|
||||||
|
namespace AceFieldNewHorizon.Scripts.System;
|
||||||
|
|
||||||
|
public static class DependencyInjection
|
||||||
|
{
|
||||||
|
public static Container Container { get; private set; }
|
||||||
|
|
||||||
|
public static void Initialize()
|
||||||
|
{
|
||||||
|
Container = new Container();
|
||||||
|
|
||||||
|
// Register your system services here
|
||||||
|
// As singletons, since they are typically unique global managers
|
||||||
|
Container.RegisterSingleton<ResourceManager>();
|
||||||
|
Container.RegisterSingleton<GridManager>();
|
||||||
|
Container.RegisterSingleton(() => new BuildingRegistry("res://Data/Buildings.json"));
|
||||||
|
|
||||||
|
Container.Verify();
|
||||||
|
GD.Print("[DI] Simple Injector container initialized and verified.");
|
||||||
|
}
|
||||||
|
}
|
1
Scripts/System/DependencyInjection.cs.uid
Normal file
1
Scripts/System/DependencyInjection.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://hppsxnesg0ys
|
64
Scripts/System/Hud.cs
Normal file
64
Scripts/System/Hud.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using Godot;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AceFieldNewHorizon.Scripts.System;
|
||||||
|
|
||||||
|
public partial class Hud : CanvasLayer
|
||||||
|
{
|
||||||
|
private ResourceManager _resourceManager;
|
||||||
|
private VBoxContainer _resourceDisplay;
|
||||||
|
private readonly Dictionary<string, Label> _resourceLabels = new();
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
_resourceDisplay = GetNode<VBoxContainer>("ResourceDisplay");
|
||||||
|
|
||||||
|
_resourceManager = DependencyInjection.Container.GetInstance<ResourceManager>();
|
||||||
|
if (_resourceManager == null)
|
||||||
|
{
|
||||||
|
GD.PushError("ResourceSystem not found in the scene tree!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_resourceManager.OnResourceChanged += UpdateResourceDisplay;
|
||||||
|
|
||||||
|
// Initialize display with current resources
|
||||||
|
foreach (var entry in _resourceManager.GetAllResources())
|
||||||
|
{
|
||||||
|
UpdateResourceDisplay(entry.Key, entry.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateResourceDisplay(string resourceId, int newAmount)
|
||||||
|
{
|
||||||
|
if (!_resourceLabels.TryGetValue(resourceId, out Label label))
|
||||||
|
{
|
||||||
|
label = new Label();
|
||||||
|
_resourceDisplay.AddChild(label);
|
||||||
|
_resourceLabels.Add(resourceId, label);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newAmount <= 0)
|
||||||
|
{
|
||||||
|
// Remove label if resource amount is zero or less
|
||||||
|
if (label.GetParent() != null)
|
||||||
|
{
|
||||||
|
_resourceDisplay.RemoveChild(label);
|
||||||
|
}
|
||||||
|
_resourceLabels.Remove(resourceId);
|
||||||
|
label.QueueFree(); // Free the label from memory
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
label.Text = $"{resourceId}: {newAmount}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _ExitTree()
|
||||||
|
{
|
||||||
|
if (_resourceManager != null)
|
||||||
|
{
|
||||||
|
_resourceManager.OnResourceChanged -= UpdateResourceDisplay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
Scripts/System/Hud.cs.uid
Normal file
1
Scripts/System/Hud.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://ddoqqcg77f60v
|
@@ -12,8 +12,8 @@ public partial class NaturalResourceGenerator : Node2D
|
|||||||
{
|
{
|
||||||
public const string ChunkTrackerGroupName = "NrgTrackingTarget";
|
public const string ChunkTrackerGroupName = "NrgTrackingTarget";
|
||||||
|
|
||||||
[Export] public GridManager Grid { get; set; }
|
public GridManager Grid { get; private set; }
|
||||||
[Export] public BuildingRegistry Registry { get; set; }
|
public BuildingRegistry Registry { get; private set; }
|
||||||
|
|
||||||
[Export] public int ChunkSize = 16;
|
[Export] public int ChunkSize = 16;
|
||||||
[Export] public int LoadDistance = 2; // Number of chunks to load in each direction
|
[Export] public int LoadDistance = 2; // Number of chunks to load in each direction
|
||||||
@@ -43,6 +43,8 @@ public partial class NaturalResourceGenerator : Node2D
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
|
Grid = DependencyInjection.Container.GetInstance<GridManager>();
|
||||||
|
Registry = DependencyInjection.Container.GetInstance<BuildingRegistry>();
|
||||||
_rng = new RandomNumberGenerator();
|
_rng = new RandomNumberGenerator();
|
||||||
_rng.Seed = (ulong)(Seed != 0 ? Seed : (int)GD.Randi());
|
_rng.Seed = (ulong)(Seed != 0 ? Seed : (int)GD.Randi());
|
||||||
|
|
||||||
|
@@ -8,9 +8,9 @@ namespace AceFieldNewHorizon.Scripts.System;
|
|||||||
|
|
||||||
public partial class PlacementManager : Node2D
|
public partial class PlacementManager : Node2D
|
||||||
{
|
{
|
||||||
[Export] public GridManager Grid { get; set; }
|
public GridManager Grid { get; private set; }
|
||||||
[Export] public ResourceManager Inventory { get; set; }
|
public ResourceManager Inventory { get; private set; }
|
||||||
[Export] public BuildingRegistry Registry { get; set; }
|
public BuildingRegistry Registry { get; private set; }
|
||||||
|
|
||||||
[Export] public int MaxConcurrentBuilds { get; set; } = 6; // Make it adjustable in editor
|
[Export] public int MaxConcurrentBuilds { get; set; } = 6; // Make it adjustable in editor
|
||||||
[Export] public bool Enabled { get; set; } = true;
|
[Export] public bool Enabled { get; set; } = true;
|
||||||
@@ -30,6 +30,10 @@ public partial class PlacementManager : Node2D
|
|||||||
{
|
{
|
||||||
base._Ready();
|
base._Ready();
|
||||||
|
|
||||||
|
Grid = DependencyInjection.Container.GetInstance<GridManager>();
|
||||||
|
Inventory = DependencyInjection.Container.GetInstance<ResourceManager>();
|
||||||
|
Registry = DependencyInjection.Container.GetInstance<BuildingRegistry>();
|
||||||
|
|
||||||
// Setup completion sound
|
// Setup completion sound
|
||||||
_completionSound = CreateAudioPlayer("res://Sounds/Events/ConstructionComplete.wav");
|
_completionSound = CreateAudioPlayer("res://Sounds/Events/ConstructionComplete.wav");
|
||||||
_buildingSound = CreateAudioPlayer("res://Sounds/Events/Building.wav");
|
_buildingSound = CreateAudioPlayer("res://Sounds/Events/Building.wav");
|
||||||
|
@@ -15,6 +15,11 @@ run/main_scene="uid://c22aprj452aha"
|
|||||||
config/features=PackedStringArray("4.4", "C#", "GL Compatibility")
|
config/features=PackedStringArray("4.4", "C#", "GL Compatibility")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
[autoload]
|
||||||
|
|
||||||
|
ResourceManager="res://Scripts/System/ResourceManager.cs"
|
||||||
|
DiInitializer="*res://Scripts/AutoLoad/DIInitializer.cs"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
window/size/viewport_width=1920
|
window/size/viewport_width=1920
|
||||||
|
Reference in New Issue
Block a user