From 9478fe1d6506b6ab7c48caf5adb9e95dc1ef2042 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 8 Sep 2024 21:57:11 -0400 Subject: [PATCH] just use base path instead --- Winch.Examples/ExampleItems/Loader.cs | 2 ++ Winch/Core/ModAssembly.cs | 9 ++++----- Winch/Core/ModAssemblyLoader.cs | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Winch.Examples/ExampleItems/Loader.cs b/Winch.Examples/ExampleItems/Loader.cs index c42ed0d6..a9675006 100644 --- a/Winch.Examples/ExampleItems/Loader.cs +++ b/Winch.Examples/ExampleItems/Loader.cs @@ -9,6 +9,8 @@ namespace ExampleItems; public static class Loader { + public static string BasePath => ModAssemblyLoader.GetCurrentMod().BasePath; + public static ExampleSaveParticipant Participant = new ExampleSaveParticipant(); public static ItemData MilkBucket => ItemUtil.GetModdedItemData("exampleitems.milk"); diff --git a/Winch/Core/ModAssembly.cs b/Winch/Core/ModAssembly.cs index 33df79af..378172ab 100644 --- a/Winch/Core/ModAssembly.cs +++ b/Winch/Core/ModAssembly.cs @@ -17,9 +17,8 @@ public class ModAssembly public Assembly? LoadedAssembly { get; private set; } public string AssetsPath => Path.Combine(BasePath, "Assets"); - public string AssemblyLocation => LoadedAssembly != null ? ReflectionUtil.GetAssemblyDirectoryPath(LoadedAssembly) : string.Empty; - public string AssemblyFolderName => LoadedAssembly != null ? ReflectionUtil.GetAssemblyDirectoryName(LoadedAssembly) : string.Empty; public string AssemblyName => LoadedAssembly != null ? LoadedAssembly.GetName().Name : string.Empty; + public string BasePathFolderName => Path.GetFileName(BasePath); public string GUID => Metadata.ContainsKey("ModGUID") ? Metadata["ModGUID"].ToString() : throw new MissingFieldException("No 'ModGUID' field found in Mod Metadata."); public string AssemblyRelativePath => Metadata.ContainsKey("ModAssembly") ? Metadata["ModAssembly"].ToString() : throw new MissingFieldException("Property 'ModAssembly' not found in mod_meta.json"); public string Name => Metadata.ContainsKey("Name") ? Metadata["Name"].ToString().Spaced() : string.Empty; @@ -32,9 +31,9 @@ public class ModAssembly public string Preload => Metadata.ContainsKey("Preload") ? Metadata["Preload"].ToString() : string.Empty; public string Entrypoint => Metadata.ContainsKey("Entrypoint") ? Metadata["Entrypoint"].ToString() : string.Empty; public bool ApplyPatches => Metadata.ContainsKey("ApplyPatches") && (bool)Metadata["ApplyPatches"]; - public ModConfig? Config => ModConfig.TryGetConfig(AssemblyFolderName, out var config) ? config : null; - public bool DefaultConfig => ModConfig.HasDefaultConfig(AssemblyFolderName); - public ModConfig GetConfig() => ModConfig.GetConfig(AssemblyFolderName); + public ModConfig? Config => ModConfig.TryGetConfig(BasePathFolderName, out var config) ? config : null; + public bool DefaultConfig => ModConfig.HasDefaultConfig(BasePathFolderName); + public ModConfig GetConfig() => ModConfig.GetConfig(BasePathFolderName); private ModAssembly(string basePath) { BasePath = basePath; diff --git a/Winch/Core/ModAssemblyLoader.cs b/Winch/Core/ModAssemblyLoader.cs index 633e0cb7..d8e68408 100644 --- a/Winch/Core/ModAssemblyLoader.cs +++ b/Winch/Core/ModAssemblyLoader.cs @@ -20,7 +20,7 @@ public static class ModAssemblyLoader static ModAssemblyLoader() { - ModConfig.GetRelevantModName = GetCurrentModAssemblyFolderName; + ModConfig.GetRelevantModName = GetCurrentModFolderName; } internal static void LoadModAssemblies() @@ -185,9 +185,9 @@ public static ModAssembly GetCurrentMod() return ReflectionUtil.GetRelevantModAssembly(); } - internal static string GetCurrentModAssemblyFolderName() + internal static string GetCurrentModFolderName() { - return GetCurrentMod()?.AssemblyFolderName ?? string.Empty; + return GetCurrentMod()?.BasePathFolderName ?? string.Empty; } ///