Skip to content

Commit

Permalink
Remove DefaultConfig from ModAssembly
Browse files Browse the repository at this point in the history
Nobody ever used this anyways
  • Loading branch information
MegaPiggy committed Aug 12, 2024
1 parent 3381230 commit 2da8fff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
12 changes: 2 additions & 10 deletions Winch/Core/ModAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ModAssembly
public string Author => Metadata.ContainsKey("Author") ? Metadata["Author"].ToString() : string.Empty;
public string Version => Metadata.ContainsKey("Version") ? Metadata["Version"].ToString() : throw new MissingFieldException("No 'Version' field found in Mod Metadata.");
public string MinWinchVersion => Metadata.ContainsKey("MinWinchVersion") ? Metadata["MinWinchVersion"].ToString() : string.Empty;
internal string DefaultConfig => Metadata.ContainsKey("DefaultConfig") ? Metadata["DefaultConfig"].ToString() : throw new KeyNotFoundException($"No 'DefaultConfig' attribute found in mod_meta.json for {GUID}!");
public string[] Dependencies => Metadata.ContainsKey("Dependencies") ? (((JArray)Metadata["Dependencies"]).ToObject<string[]>() ?? Array.Empty<string>()) : Array.Empty<string>();
public string Preload => Metadata.ContainsKey("Preload") ? Metadata["Preload"].ToString() : string.Empty;
public string Entrypoint => Metadata.ContainsKey("Entrypoint") ? Metadata["Entrypoint"].ToString() : string.Empty;
Expand All @@ -41,6 +40,8 @@ private ModAssembly(string basePath) {

string metaText = File.ReadAllText(metaPath);
Metadata = JsonConvert.DeserializeObject<Dictionary<string, object>>(metaText) ?? throw new InvalidOperationException("Unable to parse mod_meta.json file.");

var config = Config;
}

internal static ModAssembly FromPath(string path)
Expand Down Expand Up @@ -75,9 +76,6 @@ internal void ExecuteAssembly()

WinchCore.Log.Debug($"Initializing ModAssembly {LoadedAssembly.GetName().Name}...");

if (Metadata.ContainsKey("DefaultConfig"))
ProcessDefaultConfig();

if (Metadata.ContainsKey("Dependencies"))
ProcessDependencies();

Expand Down Expand Up @@ -122,12 +120,6 @@ private void ProcessDependencies()
}
}

private void ProcessDefaultConfig()
{
string modName = Path.GetFileName(BasePath);
ModConfig.RegisterDefaultConfig(modName, DefaultConfig);
}

private void ProcessEntrypoint()
{
string entrypointSetting = Entrypoint;
Expand Down
19 changes: 9 additions & 10 deletions WinchCommon/Config/ModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ private ModConfig(string modName) : base(GetConfigPath(modName), GetDefaultConfi

internal static string GetDefaultConfig(string modName)
{
if(!DefaultConfigs.ContainsKey(modName))
if (DefaultConfigs.ContainsKey(modName))
return DefaultConfigs[modName];

var path = GetDefaultConfigPath(modName);
if (File.Exists(path))
return path;
else
{
var path = GetDefaultConfigPath(modName);
if (File.Exists(path))
return path;
else
{
//WinchCore.Log.Error($"No 'DefaultConfig' attribute found in mod_meta.json for {modName}!");
throw new KeyNotFoundException($"No 'DefaultConfig' attribute found in mod_meta.json for {modName}!");
}
//WinchCore.Log.Error($"No 'DefaultConfig' attribute found in mod_meta.json for {modName}!");
throw new KeyNotFoundException($"No '{Constants.ModDefaultConfigFileName}' file found in folder for {modName}!");
}
return DefaultConfigs[modName];
}

private static string GetBasePath(string modName)
Expand Down

0 comments on commit 2da8fff

Please sign in to comment.