diff options
Diffstat (limited to 'src/SMAPI/Framework/ModLoading')
3 files changed, 43 insertions, 16 deletions
diff --git a/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs b/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs index a948213b..baffc50e 100644 --- a/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs +++ b/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs @@ -20,7 +20,7 @@ namespace StardewModdingAPI.Framework.ModLoading /// <summary>The instruction is compatible, but affects the save serializer in a way that may make saves unloadable without the mod.</summary> DetectedSaveSerializer, - /// <summary>The instruction is compatible, but uses the <c>dynamic</c> keyword which won't work on Linux/Mac.</summary> + /// <summary>The instruction is compatible, but uses the <c>dynamic</c> keyword which won't work on Linux/macOS.</summary> DetectedDynamic, /// <summary>The instruction is compatible, but references <see cref="ISpecializedEvents.UnvalidatedUpdateTicking"/> or <see cref="ISpecializedEvents.UnvalidatedUpdateTicked"/> which may impact stability.</summary> diff --git a/src/SMAPI/Framework/ModLoading/ModMetadata.cs b/src/SMAPI/Framework/ModLoading/ModMetadata.cs index b4de3d6c..17e6d59a 100644 --- a/src/SMAPI/Framework/ModLoading/ModMetadata.cs +++ b/src/SMAPI/Framework/ModLoading/ModMetadata.cs @@ -19,6 +19,9 @@ namespace StardewModdingAPI.Framework.ModLoading /// <summary>The non-error issues with the mod, including warnings suppressed by the data record.</summary> private ModWarning ActualWarnings = ModWarning.None; + /// <summary>The mod IDs which are listed as a requirement by this mod. The value for each pair indicates whether the dependency is required (i.e. not an optional dependency).</summary> + private readonly Lazy<IDictionary<string, bool>> Dependencies; + /********* ** Accessors @@ -100,6 +103,8 @@ namespace StardewModdingAPI.Framework.ModLoading this.Manifest = manifest; this.DataRecord = dataRecord; this.IsIgnored = isIgnored; + + this.Dependencies = new Lazy<IDictionary<string, bool>>(this.ExtractDependencies); } /// <inheritdoc /> @@ -199,23 +204,21 @@ namespace StardewModdingAPI.Framework.ModLoading } /// <inheritdoc /> - public IEnumerable<string> GetRequiredModIds(bool includeOptional = false) + public bool HasRequiredModId(string modId, bool includeOptional) { - HashSet<string> required = new HashSet<string>(StringComparer.OrdinalIgnoreCase); + return + this.Dependencies.Value.TryGetValue(modId, out bool isRequired) + && (includeOptional || isRequired); + } - // yield dependencies - if (this.Manifest?.Dependencies != null) + /// <inheritdoc /> + public IEnumerable<string> GetRequiredModIds(bool includeOptional = false) + { + foreach (var pair in this.Dependencies.Value) { - foreach (var entry in this.Manifest?.Dependencies) - { - if ((entry.IsRequired || includeOptional) && required.Add(entry.UniqueID)) - yield return entry.UniqueID; - } + if (includeOptional || pair.Value) + yield return pair.Key; } - - // yield content pack parent - if (this.Manifest?.ContentPackFor?.UniqueID != null && required.Add(this.Manifest.ContentPackFor.UniqueID)) - yield return this.Manifest.ContentPackFor.UniqueID; } /// <inheritdoc /> @@ -237,5 +240,29 @@ namespace StardewModdingAPI.Framework.ModLoading string rootFolderName = Path.GetFileName(this.RootPath) ?? ""; return Path.Combine(rootFolderName, this.RelativeDirectoryPath); } + + + /********* + ** Private methods + *********/ + /// <summary>Extract mod IDs from the manifest that must be installed to load this mod.</summary> + /// <returns>Returns a dictionary of mod ID => is required (i.e. not an optional dependency).</returns> + public IDictionary<string, bool> ExtractDependencies() + { + var ids = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase); + + // yield dependencies + if (this.Manifest?.Dependencies != null) + { + foreach (var entry in this.Manifest?.Dependencies) + ids[entry.UniqueID] = entry.IsRequired; + } + + // yield content pack parent + if (this.Manifest?.ContentPackFor?.UniqueID != null) + ids[this.Manifest.ContentPackFor.UniqueID] = true; + + return ids; + } } } diff --git a/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchFacade.cs b/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchFacade.cs index cf71af77..aefd1c20 100644 --- a/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchFacade.cs +++ b/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchFacade.cs @@ -4,10 +4,10 @@ using Microsoft.Xna.Framework.Graphics; namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades { - /// <summary>Provides <see cref="SpriteBatch"/> method signatures that can be injected into mod code for compatibility between Linux/Mac or Windows.</summary> + /// <summary>Provides <see cref="SpriteBatch"/> method signatures that can be injected into mod code for compatibility between Linux/macOS or Windows.</summary> /// <remarks>This is public to support SMAPI rewriting and should not be referenced directly by mods.</remarks> [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = "Used via assembly rewriting")] - [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Linux/Mac.")] + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Linux/macOS.")] [SuppressMessage("ReSharper", "CS1591", Justification = "Documentation not needed for facade classes.")] public class SpriteBatchFacade : SpriteBatch { |