Update resource values and unlock new miracles; refactor tier loading logic
This commit is contained in:
@@ -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)
|
||||
|
@@ -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);
|
||||
|
@@ -28,9 +28,9 @@ public partial class GameBus : Node
|
||||
public override void _EnterTree()
|
||||
{
|
||||
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");
|
||||
AllMiracles = MiracleLoader.LoadAllMiracles();
|
||||
FollowerTiers = TierLoader.LoadTiers("res://Mods/Tiers/follower_tiers.json", "user://Mods/Tiers/follower_tiers.json");
|
||||
HutTiers = TierLoader.LoadTiers("res://Mods/Tiers/hut_tiers.json","user://Mods/Tiers/hut_tiers.json");
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
|
Reference in New Issue
Block a user