From 59fd909146f4a796f0cbd57f5af65a5259837af1 Mon Sep 17 00:00:00 2001 From: Arne Kiesewetter Date: Tue, 26 Nov 2024 22:18:46 +0100 Subject: [PATCH] Finish autodetection of enabled toggles --- .../ModConfigurationDefinitionBuilder.cs | 17 +++++++++++------ ...keyLoader.GamePacks.ResoniteModLoader.csproj | 2 +- .../ResoniteMod.cs | 5 ----- .../ResoniteModBase.cs | 2 +- .../RmlMod.cs | 3 --- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/MonkeyLoader.GamePacks.ResoniteModLoader/ModConfigurationDefinitionBuilder.cs b/MonkeyLoader.GamePacks.ResoniteModLoader/ModConfigurationDefinitionBuilder.cs index e412d0e..38d2f08 100644 --- a/MonkeyLoader.GamePacks.ResoniteModLoader/ModConfigurationDefinitionBuilder.cs +++ b/MonkeyLoader.GamePacks.ResoniteModLoader/ModConfigurationDefinitionBuilder.cs @@ -93,16 +93,16 @@ internal void ProcessAttributes() .Do(ProcessField); } - internal bool TryGetEnabledToggle([NotNullWhen(true)] out DefiningConfigKey? enabledToggleKey, bool remove = true) + internal bool TryGetEnabledToggle([NotNullWhen(true)] out DefiningConfigKey? enabledToggleKey, bool makeInternal = true) { enabledToggleKey = null; - ModConfigurationKey? enabledToggle = null; + ModConfigurationKey? enabledToggle = null; var potentialKeys = _keys.OfType>().ToArray(); foreach (var definitiveEnabledToggle in _definitiveEnabledToggles) { - if (potentialKeys.FirstOrDefault(key => key.Name.Equals(definitiveEnabledToggle, StringComparison.OrdinalIgnoreCase)) is ModConfigurationKey enabledKey) + if (potentialKeys.FirstOrDefault(key => key.Name.Equals(definitiveEnabledToggle, StringComparison.OrdinalIgnoreCase)) is ModConfigurationKey enabledKey) { enabledToggle = enabledKey; break; @@ -122,11 +122,16 @@ internal bool TryGetEnabledToggle([NotNullWhen(true)] out DefiningConfigKey)enabledToggle.UntypedKey; - - if (remove) + if (makeInternal && !enabledToggle.InternalAccessOnly) + { _keys.Remove(enabledToggle); + enabledToggle = new ModConfigurationKey(enabledToggle.Name, enabledToggle.Description, () => true, true); + _keys.Add(enabledToggle); + } + + enabledToggleKey = enabledToggle.Key; + return true; } diff --git a/MonkeyLoader.GamePacks.ResoniteModLoader/MonkeyLoader.GamePacks.ResoniteModLoader.csproj b/MonkeyLoader.GamePacks.ResoniteModLoader/MonkeyLoader.GamePacks.ResoniteModLoader.csproj index 530c7cb..80753e3 100644 --- a/MonkeyLoader.GamePacks.ResoniteModLoader/MonkeyLoader.GamePacks.ResoniteModLoader.csproj +++ b/MonkeyLoader.GamePacks.ResoniteModLoader/MonkeyLoader.GamePacks.ResoniteModLoader.csproj @@ -34,7 +34,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/MonkeyLoader.GamePacks.ResoniteModLoader/ResoniteMod.cs b/MonkeyLoader.GamePacks.ResoniteModLoader/ResoniteMod.cs index 0597e52..c5b2d90 100644 --- a/MonkeyLoader.GamePacks.ResoniteModLoader/ResoniteMod.cs +++ b/MonkeyLoader.GamePacks.ResoniteModLoader/ResoniteMod.cs @@ -19,11 +19,6 @@ public abstract class ResoniteMod : ResoniteModBase { private readonly Lazy _configuration; - /// - /// Gets the Enabled-Toggle config item for this mod. - /// - internal DefiningConfigKey? EnabledToggle { get; private set; } - /// protected override ModConfiguration? Configuration => _configuration.Value; diff --git a/MonkeyLoader.GamePacks.ResoniteModLoader/ResoniteModBase.cs b/MonkeyLoader.GamePacks.ResoniteModLoader/ResoniteModBase.cs index 40bea2e..a403391 100644 --- a/MonkeyLoader.GamePacks.ResoniteModLoader/ResoniteModBase.cs +++ b/MonkeyLoader.GamePacks.ResoniteModLoader/ResoniteModBase.cs @@ -54,7 +54,7 @@ public bool Enabled } /// - public IDefiningConfigKey? EnabledToggle { get; } + public IDefiningConfigKey? EnabledToggle { get; protected set; } /// public bool Failed { get; private set; } diff --git a/MonkeyLoader.GamePacks.ResoniteModLoader/RmlMod.cs b/MonkeyLoader.GamePacks.ResoniteModLoader/RmlMod.cs index e8f83e4..a140593 100644 --- a/MonkeyLoader.GamePacks.ResoniteModLoader/RmlMod.cs +++ b/MonkeyLoader.GamePacks.ResoniteModLoader/RmlMod.cs @@ -81,9 +81,6 @@ public RmlMod(MonkeyLoader.MonkeyLoader loader, string? location, bool isGamePac resoniteMod.GetConfiguration(); - if (resoniteMod.EnabledToggle is not null) - MonkeyToggles.A - // Add dependencies after refactoring MKL //foreach (var referencedAssembly in assembly.GetReferencedAssemblies()) // dependencies.Add(referencedAssembly.Name, new DependencyReference())