Update resource values and unlock new miracles; refactor tier loading logic

This commit is contained in:
2025-08-23 16:10:57 +02:00
parent cd715a24cb
commit 9da3b02a46
18 changed files with 149 additions and 140 deletions

View File

@@ -1,5 +1,4 @@
using System;
using System.Text.Json;
using Godot;
using Godot.Collections;
using Newtonsoft.Json;
@@ -18,13 +17,27 @@ public static class MiracleLoader
{ "UnlockMiracle", typeof(UnlockMiracleEffect) },
{ "DestroySelf", typeof(DestroySelfEffect) }
};
public static System.Collections.Generic.Dictionary<string, MiracleDefinition> LoadMiraclesFromDirectory(string path)
public static System.Collections.Generic.Dictionary<string, MiracleDefinition> LoadAllMiracles()
{
var loadedMiracles = new System.Collections.Generic.Dictionary<string, MiracleDefinition>();
using var dir = DirAccess.Open(path);
if (dir == null) return loadedMiracles;
LoadMiraclesFromPath("res://Mods/Miracles", loadedMiracles);
LoadMiraclesFromPath("user://Mods/Miracles", loadedMiracles);
GD.Print($"Finished loading. Total unique miracles: {loadedMiracles.Count}");
return loadedMiracles;
}
private static void LoadMiraclesFromPath(string path, System.Collections.Generic.Dictionary<string, MiracleDefinition> miracles)
{
if (!DirAccess.DirExistsAbsolute(path))
{
GD.Print($"Mod directory not found, skipping: {path}");
return;
}
using var dir = DirAccess.Open(path);
dir.ListDirBegin();
var fileName = dir.GetNext();
while (!string.IsNullOrEmpty(fileName))
@@ -33,17 +46,15 @@ public static class MiracleLoader
{
var filePath = path.PathJoin(fileName);
var fileNameNoExt = fileName.GetBaseName();
var miracle = LoadMiracleFromFile(filePath, fileNameNoExt); // Pass the ID
var miracle = LoadMiracleFromFile(filePath, fileNameNoExt);
if (miracle != null)
{
loadedMiracles.Add(fileNameNoExt, miracle);
// Add or overwrite the miracle in the dictionary.
miracles[fileNameNoExt] = miracle;
}
}
fileName = dir.GetNext();
}
GD.Print($"Loaded {loadedMiracles.Count} miracles from {path}");
return loadedMiracles;
}
private static MiracleDefinition LoadMiracleFromFile(string filePath, string miracleId)

View File

@@ -7,7 +7,21 @@ namespace ParasiticGod.Scripts.Core;
public static class TierLoader
{
public static List<TierDefinition> LoadTiersFromFile(string filePath)
public static List<TierDefinition> LoadTiers(string baseFilePath, string userFilePath)
{
// Prioritize the user's file. If it exists, load it.
if (FileAccess.FileExists(userFilePath))
{
GD.Print($"Loading user tier file: {userFilePath}");
return LoadTierListFromFile(userFilePath);
}
// Otherwise, fall back to the base game's file.
GD.Print($"Loading base tier file: {baseFilePath}");
return LoadTierListFromFile(baseFilePath);
}
private static List<TierDefinition> LoadTierListFromFile(string filePath)
{
var loadedTiers = new List<TierDefinition>();
@@ -27,17 +41,25 @@ public static class TierLoader
foreach (var dto in tierListDto.Tiers)
{
var image = Image.LoadFromFile(dto.ImagePath);
if (image == null)
Texture2D texture = null;
if (dto.ImagePath.StartsWith("res://"))
{
GD.PushError($"Failed to load image at path: {dto.ImagePath}");
continue;
texture = GD.Load<Texture2D>(dto.ImagePath);
}
else if (dto.ImagePath.StartsWith("user://"))
{
var image = Image.LoadFromFile(dto.ImagePath);
if (image != null)
{
texture = ImageTexture.CreateFromImage(image);
}
}
var tierDef = new TierDefinition
{
Threshold = dto.Threshold,
TierEnum = dto.TierEnum,
Texture = ImageTexture.CreateFromImage(image),
Texture = texture,
Scale = new Vector2(dto.Scale.X, dto.Scale.Y)
};
loadedTiers.Add(tierDef);