summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModLoading/ModMetadata.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-04-03 11:39:58 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-04-03 11:39:58 -0400
commit2d8f916053a1b4b039a41a8bbe8018ebe2654022 (patch)
tree7fa7ab3fdb278453c60caca70a6aa4dd735dcea9 /src/SMAPI/Framework/ModLoading/ModMetadata.cs
parent60b563267ea7bc308d7eda55477f61fa063b069a (diff)
downloadSMAPI-2d8f916053a1b4b039a41a8bbe8018ebe2654022.tar.gz
SMAPI-2d8f916053a1b4b039a41a8bbe8018ebe2654022.tar.bz2
SMAPI-2d8f916053a1b4b039a41a8bbe8018ebe2654022.zip
log failed root dependencies in their own group
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/ModMetadata.cs')
-rw-r--r--src/SMAPI/Framework/ModLoading/ModMetadata.cs53
1 files changed, 40 insertions, 13 deletions
diff --git a/src/SMAPI/Framework/ModLoading/ModMetadata.cs b/src/SMAPI/Framework/ModLoading/ModMetadata.cs
index b4de3d6c..0d89fd20 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 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;
+ }
}
}