From ecc03e7ffd51dc1f256db0e1772300445a5caffb Mon Sep 17 00:00:00 2001 From: Arne Kiesewetter Date: Mon, 26 Aug 2024 17:31:56 +0200 Subject: [PATCH] Add priorities for config sections --- MonkeyLoader/Configuration/Config.cs | 4 ++-- MonkeyLoader/Configuration/ConfigSection.cs | 10 ++++++++-- MonkeyLoader/Logging/LoggingConfig.cs | 3 +++ MonkeyLoader/Meta/LocationConfigSection.cs | 3 +++ MonkeyLoader/NuGet/NuGetConfigSection.cs | 9 ++++++--- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/MonkeyLoader/Configuration/Config.cs b/MonkeyLoader/Configuration/Config.cs index 8c58c27..470e4c1 100644 --- a/MonkeyLoader/Configuration/Config.cs +++ b/MonkeyLoader/Configuration/Config.cs @@ -29,7 +29,7 @@ public sealed class Config : INestedIdentifiable, private readonly JObject _loadedConfig; - private readonly HashSet _sections = new(); + private readonly HashSet _sections = []; /// /// Gets the config keys defined in this configuration. @@ -62,7 +62,7 @@ public sealed class Config : INestedIdentifiable, /// /// Gets all loaded sections of this config. /// - public IEnumerable Sections => _sections.AsSafeEnumerable(); + public IEnumerable Sections => _sections.OrderByDescending(section => section.Priority).ThenBy(section => section.Name); /// /// Gets or sets a configuration value for the given key, diff --git a/MonkeyLoader/Configuration/ConfigSection.cs b/MonkeyLoader/Configuration/ConfigSection.cs index c427f87..a4ee51b 100644 --- a/MonkeyLoader/Configuration/ConfigSection.cs +++ b/MonkeyLoader/Configuration/ConfigSection.cs @@ -21,12 +21,12 @@ namespace MonkeyLoader.Configuration /// /// Use your mod's instance to load sections. /// - public abstract class ConfigSection : INestedIdentifiable, IIdentifiableOwner + public abstract class ConfigSection : INestedIdentifiable, IIdentifiableOwner, IPrioritizable { /// /// Stores the s tracked by this section. /// - protected readonly HashSet keys = new(); + protected readonly HashSet keys = []; private readonly Lazy _fullId; @@ -84,6 +84,12 @@ public abstract class ConfigSection : INestedIdentifiable, IIdentifiable Config INestedIdentifiable.Parent => Config; + /// + /// Controls in which order the sections of a are listed. + /// + /// + public virtual int Priority => 0; + /// /// Gets whether this config section is allowed to be saved.
/// This can be false if something went wrong while loading it. diff --git a/MonkeyLoader/Logging/LoggingConfig.cs b/MonkeyLoader/Logging/LoggingConfig.cs index 9516f8f..4bb30be 100644 --- a/MonkeyLoader/Logging/LoggingConfig.cs +++ b/MonkeyLoader/Logging/LoggingConfig.cs @@ -56,6 +56,9 @@ internal set public LoggingLevel Level => LevelKey; + /// + public override int Priority => 30; + public bool ShouldCleanLogDirectory => ShouldWriteLogFile && FilesToPreserve > 0; [MemberNotNullWhen(true, nameof(DirectoryPath), nameof(CurrentLogFilePath))] diff --git a/MonkeyLoader/Meta/LocationConfigSection.cs b/MonkeyLoader/Meta/LocationConfigSection.cs index 1e8f6d1..8c71e67 100644 --- a/MonkeyLoader/Meta/LocationConfigSection.cs +++ b/MonkeyLoader/Meta/LocationConfigSection.cs @@ -59,6 +59,9 @@ public string PatchedAssemblies set => PatchedAssembliesKey.SetValue(value, SetEventLabel); } + /// + public override int Priority => 20; + /// public override Version Version { get; } = new Version(1, 0); diff --git a/MonkeyLoader/NuGet/NuGetConfigSection.cs b/MonkeyLoader/NuGet/NuGetConfigSection.cs index a75b2af..23a2187 100644 --- a/MonkeyLoader/NuGet/NuGetConfigSection.cs +++ b/MonkeyLoader/NuGet/NuGetConfigSection.cs @@ -19,6 +19,9 @@ public sealed class NuGetConfigSection : ConfigSection /// public override string Description { get; } = "Contains definitions for how to use which NuGet feeds."; + /// + public override string Id { get; } = "NuGet"; + /// /// Gets whether checking NuGet feeds to load mod's library dependencies is enabled. /// @@ -37,9 +40,6 @@ public bool LoadingModsEnabled set => Config.SetValue(EnableLoadingModsKey, value); } - /// - public override string Id { get; } = "NuGet"; - /// /// Gets the NuGet feeds to check for game packs. /// @@ -67,6 +67,9 @@ public List NuGetModSources set => Config.SetValue(NuGetModSourcesKey, value); } + /// + public override int Priority => 10; + /// public override Version Version { get; } = new Version(1, 0); }