Renamed first/last to early/late; ignoring mods declared as both and warning about those

This commit is contained in:
Michał Dolaś 2022-11-09 19:50:32 +01:00
parent bb2fde1829
commit 42b4b6b6a4
4 changed files with 30 additions and 27 deletions

View File

@ -245,9 +245,9 @@ namespace StardewModdingAPI.Framework.ModLoading
/// <summary>Sort the given mods by the order they should be loaded.</summary>
/// <param name="mods">The mods to process.</param>
/// <param name="modDatabase">Handles access to SMAPI's internal mod metadata list.</param>
/// <param name="modIdsToLoadFirst">The mod IDs SMAPI should try to load first, before any other mods not included in this list.</param>
/// <param name="modIdsToLoadLast">The mod IDs SMAPI should try to load last, after all other mods not included in this list.</param>
public IEnumerable<IModMetadata> ProcessDependencies(IEnumerable<IModMetadata> mods, IReadOnlyList<string> modIdsToLoadFirst, IReadOnlyList<string> modIdsToLoadLast, ModDatabase modDatabase)
/// <param name="modIdsToLoadEarly">The mod IDs SMAPI should try to load early, before any other mods not included in this list.</param>
/// <param name="modIdsToLoadLate">The mod IDs SMAPI should try to load late, after all other mods not included in this list.</param>
public IEnumerable<IModMetadata> ProcessDependencies(IEnumerable<IModMetadata> mods, IReadOnlyList<string> modIdsToLoadEarly, IReadOnlyList<string> 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<IModMetadata> 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<IModMetadata>());

View File

@ -82,11 +82,11 @@ namespace StardewModdingAPI.Framework.Models
/// <summary>The mod IDs SMAPI should ignore when performing update checks or validating update keys.</summary>
public HashSet<string> SuppressUpdateChecks { get; set; }
/// <summary>The mod IDs SMAPI should try to load first, before any other mods not included in this list.</summary>
public List<string> ModsToLoadFirst { get; set; }
/// <summary>The mod IDs SMAPI should try to load early, before any other mods not included in this list.</summary>
public List<string> ModsToLoadEarly { get; set; }
/// <summary>The mod IDs SMAPI should try to load last, after all other mods not included in this list.</summary>
public List<string> ModsToLoadLast { get; set; }
/// <summary>The mod IDs SMAPI should try to load late, after all other mods not included in this list.</summary>
public List<string> ModsToLoadLate { get; set; }
/********
@ -106,9 +106,9 @@ namespace StardewModdingAPI.Framework.Models
/// <param name="consoleColors">The colors to use for text written to the SMAPI console.</param>
/// <param name="suppressHarmonyDebugMode">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.</param>
/// <param name="suppressUpdateChecks">The mod IDs SMAPI should ignore when performing update checks or validating update keys.</param>
/// <param name="modsToLoadFirst">The mod IDs SMAPI should try to load first, before any other mods not included in this list.</param>
/// <param name="modsToLoadLast">The mod IDs SMAPI should try to load last, after all other mods not included in this list.</param>
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)
/// <param name="modsToLoadEarly">The mod IDs SMAPI should try to load early, before any other mods not included in this list.</param>
/// <param name="modsToLoadLate">The mod IDs SMAPI should try to load late, after all other mods not included in this list.</param>
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<string>(suppressUpdateChecks ?? Array.Empty<string>(), StringComparer.OrdinalIgnoreCase);
this.ModsToLoadFirst = new List<string>(modsToLoadFirst ?? Array.Empty<string>());
this.ModsToLoadLast = new List<string>(modsToLoadLast ?? Array.Empty<string>());
this.ModsToLoadEarly = new List<string>(modsToLoadEarly ?? Array.Empty<string>());
this.ModsToLoadLate = new List<string>(modsToLoadLate ?? Array.Empty<string>());
}
/// <summary>Override the value of <see cref="DeveloperMode"/>.</summary>

View File

@ -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

View File

@ -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": []
}