diff --git a/Scenes/Main/Main.tscn b/Scenes/Main/Main.tscn index d1e7d75..6338772 100644 --- a/Scenes/Main/Main.tscn +++ b/Scenes/Main/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=28 format=3 uid="uid://bfil8sd154327"] +[gd_scene load_steps=20 format=3 uid="uid://bfil8sd154327"] [ext_resource type="Script" uid="uid://t71ewkpa5uqs" path="res://Scenes/Main/Main.cs" id="1_p8rbg"] [ext_resource type="Script" uid="uid://b77vh831r1e3c" path="res://Scenes/Main/MiraclePanel.cs" id="2_hcu3t"] @@ -14,16 +14,8 @@ [ext_resource type="AudioStream" uid="uid://dv0i7xw8o5ac0" path="res://Sfx/UI_SFX_Pack_61_5.wav" id="8_4etfk"] [ext_resource type="Script" uid="uid://dj2wyrq07gfp2" path="res://Scripts/Components/PopulationVisualizer.cs" id="8_cv8e0"] [ext_resource type="PackedScene" uid="uid://8w7tvsgkev1y" path="res://Scenes/tree.tscn" id="8_hcu3t"] -[ext_resource type="Resource" uid="uid://8ooxfo2wdbhu" path="res://Resources/Tiers/Followers/follower_tier_1.tres" id="9_hkvnm"] [ext_resource type="Shader" uid="uid://bf8nk145fjkgh" path="res://Shaders/corruption_shader.gdshader" id="9_wgovn"] -[ext_resource type="Resource" uid="uid://cejeb3467iiyl" path="res://Resources/Tiers/Followers/follower_tier_2.tres" id="10_5ci8a"] [ext_resource type="PackedScene" uid="uid://cqkye7yykakns" path="res://Scenes/Followers/FollowerMarker.tscn" id="11_5ci8a"] -[ext_resource type="Resource" uid="uid://q0rha23lx4wl" path="res://Resources/Tiers/Followers/follower_tier_3.tres" id="11_18xdc"] -[ext_resource type="Resource" uid="uid://i1oo0q84q8ps" path="res://Resources/Tiers/Followers/follower_tier_4.tres" id="12_epx8f"] -[ext_resource type="Resource" uid="uid://bwu8k7cyjhf8c" path="res://Resources/Tiers/Followers/follower_tier_5.tres" id="13_hcu3t"] -[ext_resource type="Resource" uid="uid://bbkbssvptkyvh" path="res://Resources/Tiers/Huts/hut_tier_1.tres" id="14_18xdc"] -[ext_resource type="Resource" uid="uid://co2sdpwpajjqi" path="res://Resources/Tiers/Huts/hut_tier_2.tres" id="15_epx8f"] -[ext_resource type="Resource" uid="uid://b8k30qsd434dp" path="res://Resources/Tiers/Huts/hut_tier_3.tres" id="16_hcu3t"] [ext_resource type="Script" uid="uid://furbvcmw31bx" path="res://Scripts/Components/ForestVisualizer.cs" id="18_qdkat"] [ext_resource type="Script" uid="uid://cw8gpeaq3yfjn" path="res://Scripts/Components/RoadManager.cs" id="19_qdkat"] @@ -5557,14 +5549,13 @@ position = Vector2(243.12, -124.88) script = ExtResource("8_cv8e0") _markersContainer = NodePath("../Followers Markers") _unitsPerMarker = 1 -_tiers = Array[Object]([ExtResource("9_hkvnm"), ExtResource("10_5ci8a"), ExtResource("11_18xdc"), ExtResource("12_epx8f"), ExtResource("13_hcu3t")]) metadata/_custom_type_script = "uid://dj2wyrq07gfp2" [node name="HutPopulationVisualizer" type="Node" parent="." node_paths=PackedStringArray("_markersContainer")] script = ExtResource("8_cv8e0") _markersContainer = NodePath("../Hut Markers") _unitsPerMarker = 1 -_tiers = Array[Object]([ExtResource("14_18xdc"), ExtResource("15_epx8f"), ExtResource("16_hcu3t")]) +Category = 1 metadata/_custom_type_script = "uid://dj2wyrq07gfp2" [node name="ForestVisualizer" type="Node" parent="." node_paths=PackedStringArray("_treesContainer")] diff --git a/Scripts/Components/PopulationVisualizer.cs b/Scripts/Components/PopulationVisualizer.cs index afa9ff7..043789b 100644 --- a/Scripts/Components/PopulationVisualizer.cs +++ b/Scripts/Components/PopulationVisualizer.cs @@ -9,10 +9,13 @@ namespace ParasiticGod.Scripts.Components; [GlobalClass] public partial class PopulationVisualizer : Node { + public enum VisualCategory { Followers, Huts } + [Export] private Node2D _markersContainer; [Export] private int _unitsPerMarker = 5; - [Export] private Array _tiers; + [Export] public VisualCategory Category { get; private set; } + private List _tiers; private readonly List _markers = []; private long _lastKnownUnitCount = -1; private int _lastKnownTierIndex = -1; @@ -20,6 +23,19 @@ public partial class PopulationVisualizer : Node public override void _Ready() { + switch (Category) + { + case VisualCategory.Followers: + _tiers = GameBus.Instance.FollowerTiers; + break; + case VisualCategory.Huts: + _tiers = GameBus.Instance.HutTiers; + break; + default: + GD.PushError($"PopulationVisualizer has an invalid category: {Category}"); + return; + } + foreach (var child in _markersContainer.GetChildren()) { if (child is FollowerMarker marker) @@ -40,7 +56,12 @@ public partial class PopulationVisualizer : Node { if (_isUpdating) return; - var currentUnitCount = (long)newState.Get(Stat.Followers); + long currentUnitCount = Category switch + { + VisualCategory.Followers => (long)newState.Get(Stat.Followers), + VisualCategory.Huts => (long)newState.Get(Stat.Followers), + _ => 0 + }; var currentMarkersToShow = (int)currentUnitCount / _unitsPerMarker; var lastMarkersToShow = (int)_lastKnownUnitCount / _unitsPerMarker; diff --git a/Scripts/Core/TierDefinition.cs b/Scripts/Core/TierDefinition.cs index b4e58d3..3b92d47 100644 --- a/Scripts/Core/TierDefinition.cs +++ b/Scripts/Core/TierDefinition.cs @@ -5,6 +5,7 @@ namespace ParasiticGod.Scripts.Core; [GlobalClass] public partial class TierDefinition : Resource { - [Export] public PackedScene Scene { get; private set; } - [Export] public long Threshold { get; private set; } + [Export] public PackedScene Scene { get; set; } + [Export] public long Threshold { get; set; } + [Export] public Follower.FollowerTier TierEnum { get; set; } } \ No newline at end of file diff --git a/Scripts/Core/TierDto.cs b/Scripts/Core/TierDto.cs new file mode 100644 index 0000000..f6c5202 --- /dev/null +++ b/Scripts/Core/TierDto.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; + +namespace ParasiticGod.Scripts.Core; + +public class TierDto +{ + public Follower.FollowerTier TierEnum { get; set; } + public long Threshold { get; set; } + public string ScenePath { get; set; } +} + +public class TierListDto +{ + public List Tiers { get; set; } +} \ No newline at end of file diff --git a/Scripts/Core/TierDto.cs.uid b/Scripts/Core/TierDto.cs.uid new file mode 100644 index 0000000..bc62934 --- /dev/null +++ b/Scripts/Core/TierDto.cs.uid @@ -0,0 +1 @@ +uid://4432c2r3q5vv diff --git a/Scripts/Core/TierLoader.cs b/Scripts/Core/TierLoader.cs new file mode 100644 index 0000000..dff6bcc --- /dev/null +++ b/Scripts/Core/TierLoader.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using System.Linq; +using Godot; +using Newtonsoft.Json; + +namespace ParasiticGod.Scripts.Core; + +public static class TierLoader +{ + public static List LoadTiersFromFile(string filePath) + { + var loadedTiers = new List(); + + var fileContent = FileAccess.GetFileAsString(filePath); + if (string.IsNullOrEmpty(fileContent)) + { + GD.PushError($"Failed to read tier file or file is empty: {filePath}"); + return loadedTiers; + } + + var tierListDto = JsonConvert.DeserializeObject(fileContent); + if (tierListDto?.Tiers == null) + { + GD.PushError($"Failed to deserialize tier list JSON or 'Tiers' array is missing: {filePath}"); + return loadedTiers; + } + + foreach (var dto in tierListDto.Tiers) + { + var tierDef = new TierDefinition + { + Threshold = dto.Threshold, + TierEnum = dto.TierEnum, + Scene = GD.Load(dto.ScenePath) + }; + loadedTiers.Add(tierDef); + } + + GD.Print($"Loaded {loadedTiers.Count} follower tiers from {filePath}"); + return loadedTiers.OrderBy(t => t.Threshold).ToList(); + } +} \ No newline at end of file diff --git a/Scripts/Core/TierLoader.cs.uid b/Scripts/Core/TierLoader.cs.uid new file mode 100644 index 0000000..9d70a13 --- /dev/null +++ b/Scripts/Core/TierLoader.cs.uid @@ -0,0 +1 @@ +uid://hgx8qu7etqhm diff --git a/Scripts/Singletons/GameBus.cs b/Scripts/Singletons/GameBus.cs index 5a362b1..c51090b 100644 --- a/Scripts/Singletons/GameBus.cs +++ b/Scripts/Singletons/GameBus.cs @@ -10,6 +10,8 @@ public partial class GameBus : Node { public static GameBus Instance { get; private set; } public Dictionary AllMiracles { get; private set; } + public List FollowerTiers { get; private set; } + public List HutTiers { get; private set; } private readonly GameState _gameState = new(); private readonly GameLogic _gameLogic = new(); @@ -27,6 +29,8 @@ public partial class GameBus : Node { Instance = this; AllMiracles = MiracleLoader.LoadMiraclesFromDirectory("user://Mods/Miracles"); + FollowerTiers = TierLoader.LoadTiersFromFile("user://Mods/Tiers/follower_tiers.json"); + HutTiers = TierLoader.LoadTiersFromFile("user://Mods/Tiers/hut_tiers.json"); } public override void _ExitTree()