diff --git a/MonkeyLoader/Configuration/Config.cs b/MonkeyLoader/Configuration/Config.cs index b55c9d1..8c58c27 100644 --- a/MonkeyLoader/Configuration/Config.cs +++ b/MonkeyLoader/Configuration/Config.cs @@ -174,6 +174,17 @@ public TSection LoadSection(TSection section) where TSection : ConfigS return section; } + /// + /// Removes the value of all of this configuration's sections' keys and resets them to their default. + /// + public void Reset() + { + Logger.Warn(() => $"Resetting config: {FullId}"); + + foreach (var section in Sections) + section.Reset(); + } + /// /// Persists this configuration to disk. /// diff --git a/MonkeyLoader/Configuration/ConfigSection.cs b/MonkeyLoader/Configuration/ConfigSection.cs index d53ec84..c427f87 100644 --- a/MonkeyLoader/Configuration/ConfigSection.cs +++ b/MonkeyLoader/Configuration/ConfigSection.cs @@ -193,6 +193,17 @@ public void OnItemChanged(IConfigKeyChangedEventArgs configKeyChangedEventArgs) Config.OnItemChanged(configKeyChangedEventArgs); } + /// + /// Removes the value of all keys of this config section and resets them to their default. + /// + public void Reset() + { + Logger.Warn(() => $"Resetting config section: {FullId}"); + + foreach (var configKey in keys) + configKey.Reset(); + } + /// /// Determines if this config section contains an item matching the /// and returns the optional match as . diff --git a/MonkeyLoader/Configuration/DefiningConfigKey.cs b/MonkeyLoader/Configuration/DefiningConfigKey.cs index 73bc345..f4ff197 100644 --- a/MonkeyLoader/Configuration/DefiningConfigKey.cs +++ b/MonkeyLoader/Configuration/DefiningConfigKey.cs @@ -203,6 +203,19 @@ IEnumerator>> IEnumerable GetValue(); + /// + public void Reset() + { + Logger.Info(() => $"Resetting config key: {FullId}"); + + var hadValue = HasValue; + var oldValue = _value; + + HasValue = TryComputeDefault(out _value); + + OnChanged(hadValue, oldValue, nameof(Reset)); + } + /// public void SetValue(T value, string? eventLabel = null) { @@ -473,6 +486,11 @@ public interface IDefiningConfigKey : ITypedConfigKey, IEntityThe item's internal value or its type's default. public object? GetValue(); + /// + /// Removes this config item's value and attempts to reset it back to its default. + /// + public void Reset(); + /// /// Set the config item's internal value to the given one. /// diff --git a/MonkeyLoader/MonkeyLoader.csproj b/MonkeyLoader/MonkeyLoader.csproj index 2eb715b..0c9f496 100644 --- a/MonkeyLoader/MonkeyLoader.csproj +++ b/MonkeyLoader/MonkeyLoader.csproj @@ -11,7 +11,7 @@ True MonkeyLoader Banane9 - 0.22.6-beta + 0.22.7-beta A convenience and extendability focused mod loader using NuGet packages. README.md LGPL-3.0-or-later