Add tier management system with JSON loading; refactor PopulationVisualizer for category handling
This commit is contained in:
@@ -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; }
|
||||
}
|
15
Scripts/Core/TierDto.cs
Normal file
15
Scripts/Core/TierDto.cs
Normal file
@@ -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<TierDto> Tiers { get; set; }
|
||||
}
|
1
Scripts/Core/TierDto.cs.uid
Normal file
1
Scripts/Core/TierDto.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://4432c2r3q5vv
|
42
Scripts/Core/TierLoader.cs
Normal file
42
Scripts/Core/TierLoader.cs
Normal file
@@ -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<TierDefinition> LoadTiersFromFile(string filePath)
|
||||
{
|
||||
var loadedTiers = new List<TierDefinition>();
|
||||
|
||||
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<TierListDto>(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<PackedScene>(dto.ScenePath)
|
||||
};
|
||||
loadedTiers.Add(tierDef);
|
||||
}
|
||||
|
||||
GD.Print($"Loaded {loadedTiers.Count} follower tiers from {filePath}");
|
||||
return loadedTiers.OrderBy(t => t.Threshold).ToList();
|
||||
}
|
||||
}
|
1
Scripts/Core/TierLoader.cs.uid
Normal file
1
Scripts/Core/TierLoader.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://hgx8qu7etqhm
|
Reference in New Issue
Block a user