From bb2fde18292352471501887013ca2b7f60a9dc25 Mon Sep 17 00:00:00 2001 From: Michał Dolaś Date: Wed, 9 Nov 2022 17:25:25 +0100 Subject: Added ModsToLoadFirst/Last to SMAPI config, along with the implementation --- src/SMAPI/SMAPI.config.json | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/SMAPI/SMAPI.config.json') diff --git a/src/SMAPI/SMAPI.config.json b/src/SMAPI/SMAPI.config.json index 635e3add..1a342df2 100644 --- a/src/SMAPI/SMAPI.config.json +++ b/src/SMAPI/SMAPI.config.json @@ -141,5 +141,15 @@ copy all the settings, or you may cause bugs due to overridden changes in future "SMAPI.ConsoleCommands", "SMAPI.ErrorHandler", "SMAPI.SaveBackup" - ] + ], + + /** + * The mod IDs SMAPI should try to load first, before any other mods not included in this list. + */ + "ModsToLoadFirst": [], + + /** + * The mod IDs SMAPI should try to load last, after all other mods not included in this list. + */ + "ModsToLoadLast": [] } -- cgit From 42b4b6b6a4ae1bb59182857b383539b24b063215 Mon Sep 17 00:00:00 2001 From: Michał Dolaś Date: Wed, 9 Nov 2022 19:50:32 +0100 Subject: Renamed first/last to early/late; ignoring mods declared as both and warning about those --- src/SMAPI/Framework/ModLoading/ModResolver.cs | 16 ++++++++-------- src/SMAPI/Framework/Models/SConfig.cs | 18 +++++++++--------- src/SMAPI/Framework/SCore.cs | 15 +++++++++------ src/SMAPI/SMAPI.config.json | 8 ++++---- 4 files changed, 30 insertions(+), 27 deletions(-) (limited to 'src/SMAPI/SMAPI.config.json') diff --git a/src/SMAPI/Framework/ModLoading/ModResolver.cs b/src/SMAPI/Framework/ModLoading/ModResolver.cs index b90f9ba5..f9ba73c4 100644 --- a/src/SMAPI/Framework/ModLoading/ModResolver.cs +++ b/src/SMAPI/Framework/ModLoading/ModResolver.cs @@ -245,9 +245,9 @@ namespace StardewModdingAPI.Framework.ModLoading /// Sort the given mods by the order they should be loaded. /// The mods to process. /// Handles access to SMAPI's internal mod metadata list. - /// The mod IDs SMAPI should try to load first, before any other mods not included in this list. - /// The mod IDs SMAPI should try to load last, after all other mods not included in this list. - public IEnumerable ProcessDependencies(IEnumerable mods, IReadOnlyList modIdsToLoadFirst, IReadOnlyList modIdsToLoadLast, ModDatabase modDatabase) + /// The mod IDs SMAPI should try to load early, before any other mods not included in this list. + /// The mod IDs SMAPI should try to load late, after all other mods not included in this list. + public IEnumerable ProcessDependencies(IEnumerable mods, IReadOnlyList modIdsToLoadEarly, IReadOnlyList modIdsToLoadLate, ModDatabase modDatabase) { // initialize metadata mods = mods.ToArray(); @@ -263,14 +263,14 @@ namespace StardewModdingAPI.Framework.ModLoading // sort mods IModMetadata[] allMods = mods.ToArray(); - IModMetadata[] modsToLoadFirst = allMods.Where(m => modIdsToLoadFirst.Contains(m.Manifest.UniqueID)).ToArray(); - IModMetadata[] modsToLoadLast = allMods.Where(m => modIdsToLoadLast.Contains(m.Manifest.UniqueID)).ToArray(); - IModMetadata[] modsToLoadAsUsual = allMods.Where(m => !modsToLoadFirst.Contains(m) && !modsToLoadLast.Contains(m)).ToArray(); + IModMetadata[] modsToLoadEarly = allMods.Where(m => modIdsToLoadEarly.Contains(m.Manifest.UniqueID) && !modIdsToLoadLate.Contains(m.Manifest.UniqueID)).ToArray(); + IModMetadata[] modsToLoadLate = allMods.Where(m => modIdsToLoadLate.Contains(m.Manifest.UniqueID) && !modIdsToLoadEarly.Contains(m.Manifest.UniqueID)).ToArray(); + IModMetadata[] modsToLoadAsUsual = allMods.Where(m => !modsToLoadEarly.Contains(m) && !modsToLoadLate.Contains(m)).ToArray(); List orderSortedMods = new(); - orderSortedMods.AddRange(modsToLoadFirst); + orderSortedMods.AddRange(modsToLoadEarly); orderSortedMods.AddRange(modsToLoadAsUsual); - orderSortedMods.AddRange(modsToLoadLast); + orderSortedMods.AddRange(modsToLoadLate); foreach (IModMetadata mod in orderSortedMods) this.ProcessDependencies(orderSortedMods, modDatabase, mod, states, sortedMods, new List()); diff --git a/src/SMAPI/Framework/Models/SConfig.cs b/src/SMAPI/Framework/Models/SConfig.cs index ddd721d5..40d3450f 100644 --- a/src/SMAPI/Framework/Models/SConfig.cs +++ b/src/SMAPI/Framework/Models/SConfig.cs @@ -82,11 +82,11 @@ namespace StardewModdingAPI.Framework.Models /// The mod IDs SMAPI should ignore when performing update checks or validating update keys. public HashSet SuppressUpdateChecks { get; set; } - /// The mod IDs SMAPI should try to load first, before any other mods not included in this list. - public List ModsToLoadFirst { get; set; } + /// The mod IDs SMAPI should try to load early, before any other mods not included in this list. + public List ModsToLoadEarly { get; set; } - /// The mod IDs SMAPI should try to load last, after all other mods not included in this list. - public List ModsToLoadLast { get; set; } + /// The mod IDs SMAPI should try to load late, after all other mods not included in this list. + public List ModsToLoadLate { get; set; } /******** @@ -106,9 +106,9 @@ namespace StardewModdingAPI.Framework.Models /// The colors to use for text written to the SMAPI console. /// Whether to prevent mods from enabling Harmony's debug mode, which impacts performance and creates a file on your desktop. Debug mode should never be enabled by a released mod. /// The mod IDs SMAPI should ignore when performing update checks or validating update keys. - /// The mod IDs SMAPI should try to load first, before any other mods not included in this list. - /// The mod IDs SMAPI should try to load last, after all other mods not included in this list. - public SConfig(bool developerMode, bool? checkForUpdates, bool? paranoidWarnings, bool? useBetaChannel, string gitHubProjectName, string webApiBaseUrl, string[]? verboseLogging, bool? rewriteMods, bool? useCaseInsensitivePaths, bool? logNetworkTraffic, ColorSchemeConfig consoleColors, bool? suppressHarmonyDebugMode, string[]? suppressUpdateChecks, string[]? modsToLoadFirst, string[]? modsToLoadLast) + /// The mod IDs SMAPI should try to load early, before any other mods not included in this list. + /// The mod IDs SMAPI should try to load late, after all other mods not included in this list. + public SConfig(bool developerMode, bool? checkForUpdates, bool? paranoidWarnings, bool? useBetaChannel, string gitHubProjectName, string webApiBaseUrl, string[]? verboseLogging, bool? rewriteMods, bool? useCaseInsensitivePaths, bool? logNetworkTraffic, ColorSchemeConfig consoleColors, bool? suppressHarmonyDebugMode, string[]? suppressUpdateChecks, string[]? modsToLoadEarly, string[]? modsToLoadLate) { this.DeveloperMode = developerMode; this.CheckForUpdates = checkForUpdates ?? (bool)SConfig.DefaultValues[nameof(this.CheckForUpdates)]; @@ -123,8 +123,8 @@ namespace StardewModdingAPI.Framework.Models this.ConsoleColors = consoleColors; this.SuppressHarmonyDebugMode = suppressHarmonyDebugMode ?? (bool)SConfig.DefaultValues[nameof(this.SuppressHarmonyDebugMode)]; this.SuppressUpdateChecks = new HashSet(suppressUpdateChecks ?? Array.Empty(), StringComparer.OrdinalIgnoreCase); - this.ModsToLoadFirst = new List(modsToLoadFirst ?? Array.Empty()); - this.ModsToLoadLast = new List(modsToLoadLast ?? Array.Empty()); + this.ModsToLoadEarly = new List(modsToLoadEarly ?? Array.Empty()); + this.ModsToLoadLate = new List(modsToLoadLate ?? Array.Empty()); } /// Override the value of . diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 7bd60490..9e91924e 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -423,17 +423,20 @@ namespace StardewModdingAPI.Framework this.Monitor.Log($" Skipped {mod.GetRelativePathWithRoot()} (folder name starts with a dot)."); mods = mods.Where(p => !p.IsIgnored).ToArray(); - // warn about mods that should load first or last which are not found at all - foreach (string modId in this.Settings.ModsToLoadFirst) + // warn about mods that should load early or late which are not found at all, or both + foreach (string modId in this.Settings.ModsToLoadEarly) if (!mods.Any(m => m.Manifest.UniqueID == modId)) - this.Monitor.Log($" SMAPI configuration specifies a mod {modId} that should load first, but it could not be found.", LogLevel.Warn); - foreach (string modId in this.Settings.ModsToLoadLast) + this.Monitor.Log($" SMAPI configuration specifies a mod {modId} that should load early, but it could not be found.", LogLevel.Warn); + foreach (string modId in this.Settings.ModsToLoadLate) if (!mods.Any(m => m.Manifest.UniqueID == modId)) - this.Monitor.Log($" SMAPI configuration specifies a mod {modId} that should load last, but it could not be found.", LogLevel.Warn); + this.Monitor.Log($" SMAPI configuration specifies a mod {modId} that should load late, but it could not be found.", LogLevel.Warn); + foreach (string modId in this.Settings.ModsToLoadEarly) + if (this.Settings.ModsToLoadLate.Contains(modId)) + this.Monitor.Log($" SMAPI configuration specifies a mod {modId} that should load both early and late - this will be ignored.", LogLevel.Warn); // load mods resolver.ValidateManifests(mods, Constants.ApiVersion, toolkit.GetUpdateUrl, getFileLookup: this.GetFileLookup); - mods = resolver.ProcessDependencies(mods, this.Settings.ModsToLoadFirst, this.Settings.ModsToLoadLast, modDatabase).ToArray(); + mods = resolver.ProcessDependencies(mods, this.Settings.ModsToLoadEarly, this.Settings.ModsToLoadLate, modDatabase).ToArray(); this.LoadMods(mods, this.Toolkit.JsonHelper, this.ContentCore, modDatabase); // check for software likely to cause issues diff --git a/src/SMAPI/SMAPI.config.json b/src/SMAPI/SMAPI.config.json index 1a342df2..68645d24 100644 --- a/src/SMAPI/SMAPI.config.json +++ b/src/SMAPI/SMAPI.config.json @@ -144,12 +144,12 @@ copy all the settings, or you may cause bugs due to overridden changes in future ], /** - * The mod IDs SMAPI should try to load first, before any other mods not included in this list. + * The mod IDs SMAPI should try to load early, before any other mods not included in this list. */ - "ModsToLoadFirst": [], + "ModsToLoadEarly": [], /** - * The mod IDs SMAPI should try to load last, after all other mods not included in this list. + * The mod IDs SMAPI should try to load late, after all other mods not included in this list. */ - "ModsToLoadLast": [] + "ModsToLoadLate": [] } -- cgit From 3059794622e4442bf289dde7b4f533d8021d3bf7 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 11 Nov 2022 01:22:46 -0500 Subject: adjust warning messages & log header when load order is edited --- src/SMAPI/Framework/Models/SConfig.cs | 6 ++++++ src/SMAPI/Framework/SCore.cs | 22 ++++++++++------------ src/SMAPI/SMAPI.config.json | 12 +++++++----- 3 files changed, 23 insertions(+), 17 deletions(-) (limited to 'src/SMAPI/SMAPI.config.json') diff --git a/src/SMAPI/Framework/Models/SConfig.cs b/src/SMAPI/Framework/Models/SConfig.cs index ee2dc18d..158831a9 100644 --- a/src/SMAPI/Framework/Models/SConfig.cs +++ b/src/SMAPI/Framework/Models/SConfig.cs @@ -146,6 +146,12 @@ namespace StardewModdingAPI.Framework.Models custom[name] = value; } + if (this.ModsToLoadEarly.Any()) + custom[nameof(this.ModsToLoadEarly)] = $"[{string.Join(", ", this.ModsToLoadEarly)}]"; + + if (this.ModsToLoadLate.Any()) + custom[nameof(this.ModsToLoadLate)] = $"[{string.Join(", ", this.ModsToLoadLate)}]"; + if (!this.SuppressUpdateChecks.SetEquals(SConfig.DefaultSuppressUpdateChecks)) custom[nameof(this.SuppressUpdateChecks)] = $"[{string.Join(", ", this.SuppressUpdateChecks)}]"; diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index fb835002..7f564a28 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -427,18 +427,16 @@ namespace StardewModdingAPI.Framework { HashSet installedIds = new HashSet(mods.Select(p => p.Manifest.UniqueID), StringComparer.OrdinalIgnoreCase); - foreach (string modId in this.Settings.ModsToLoadEarly) - { - if (!installedIds.Contains(modId)) - this.Monitor.Log($" SMAPI configuration specifies a mod {modId} that should load early, but it could not be found or was skipped.", LogLevel.Warn); - } - foreach (string modId in this.Settings.ModsToLoadLate) - { - if (this.Settings.ModsToLoadEarly.Contains(modId)) - this.Monitor.Log($" SMAPI configuration specifies a mod {modId} that should load both early and late - this will be ignored.", LogLevel.Warn); - else if (!installedIds.Contains(modId)) - this.Monitor.Log($" SMAPI configuration specifies a mod {modId} that should load late, but it could not be found or was skipped.", LogLevel.Warn); - } + string[] missingEarlyMods = this.Settings.ModsToLoadEarly.Where(id => !installedIds.Contains(id)).OrderBy(p => p, StringComparer.OrdinalIgnoreCase).ToArray(); + string[] missingLateMods = this.Settings.ModsToLoadLate.Where(id => !installedIds.Contains(id)).OrderBy(p => p, StringComparer.OrdinalIgnoreCase).ToArray(); + string[] duplicateMods = this.Settings.ModsToLoadLate.Where(id => this.Settings.ModsToLoadEarly.Contains(id)).OrderBy(p => p, StringComparer.OrdinalIgnoreCase).ToArray(); + + if (missingEarlyMods.Any()) + this.Monitor.Log($" The 'smapi-internal/config.json' file lists mod IDs in {nameof(this.Settings.ModsToLoadEarly)} which aren't installed: '{string.Join("', '", missingEarlyMods)}'.", LogLevel.Warn); + if (missingLateMods.Any()) + this.Monitor.Log($" The 'smapi-internal/config.json' file lists mod IDs in {nameof(this.Settings.ModsToLoadLate)} which aren't installed: '{string.Join("', '", missingLateMods)}'.", LogLevel.Warn); + if (duplicateMods.Any()) + this.Monitor.Log($" The 'smapi-internal/config.json' file lists mod IDs which are in both {nameof(this.Settings.ModsToLoadEarly)} and {nameof(this.Settings.ModsToLoadLate)}: '{string.Join("', '", duplicateMods)}'. These will be loaded early.", LogLevel.Warn); } // load mods diff --git a/src/SMAPI/SMAPI.config.json b/src/SMAPI/SMAPI.config.json index 68645d24..0ab68a7d 100644 --- a/src/SMAPI/SMAPI.config.json +++ b/src/SMAPI/SMAPI.config.json @@ -144,12 +144,14 @@ copy all the settings, or you may cause bugs due to overridden changes in future ], /** - * The mod IDs SMAPI should try to load early, before any other mods not included in this list. + * The mod IDs SMAPI should load before any other mods (except those needed to load them) + * or after any other mods. + * + * This lets you manually fix the load order if needed, but this is a last resort — SMAPI + * automatically adjusts the load order based on mods' dependencies, so needing to manually + * edit the order is usually a problem with one or both mods' metadata that can be reported to + * the mod author. */ "ModsToLoadEarly": [], - - /** - * The mod IDs SMAPI should try to load late, after all other mods not included in this list. - */ "ModsToLoadLate": [] } -- cgit