diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-02-16 23:12:01 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-02-16 23:12:01 -0500 |
commit | 8a1982326799dfe7f3d078beba32348befa1c9e6 (patch) | |
tree | d904aa73098f5e9577532fd1d03908e2e78f26d0 /src | |
parent | 9b3dd42cbf62a8524ac390d9418cf961c502868a (diff) | |
download | SMAPI-8a1982326799dfe7f3d078beba32348befa1c9e6.tar.gz SMAPI-8a1982326799dfe7f3d078beba32348befa1c9e6.tar.bz2 SMAPI-8a1982326799dfe7f3d078beba32348befa1c9e6.zip |
add mod page URL to missing-dependency errors (#437)
Diffstat (limited to 'src')
-rw-r--r-- | src/SMAPI/Framework/ModData/ModDatabase.cs | 58 | ||||
-rw-r--r-- | src/SMAPI/Framework/ModLoading/ModResolver.cs | 5 | ||||
-rw-r--r-- | src/SMAPI/Program.cs | 2 | ||||
-rw-r--r-- | src/SMAPI/StardewModdingAPI.config.json | 12 |
4 files changed, 61 insertions, 16 deletions
diff --git a/src/SMAPI/Framework/ModData/ModDatabase.cs b/src/SMAPI/Framework/ModData/ModDatabase.cs index af067f8f..332c5c48 100644 --- a/src/SMAPI/Framework/ModData/ModDatabase.cs +++ b/src/SMAPI/Framework/ModData/ModDatabase.cs @@ -15,19 +15,24 @@ namespace StardewModdingAPI.Framework.ModData /// <summary>The underlying mod data records indexed by default display name.</summary> private readonly IDictionary<string, ModDataRecord> Records; + /// <summary>Get an update URL for an update key (if valid).</summary> + private readonly Func<string, string> GetUpdateUrl; + /********* ** Public methods *********/ /// <summary>Construct an empty instance.</summary> public ModDatabase() - : this(new Dictionary<string, ModDataRecord>()) { } + : this(new Dictionary<string, ModDataRecord>(), key => null) { } /// <summary>Construct an instance.</summary> /// <param name="records">The underlying mod data records indexed by default display name.</param> - public ModDatabase(IDictionary<string, ModDataRecord> records) + /// <param name="getUpdateUrl">Get an update URL for an update key (if valid).</param> + public ModDatabase(IDictionary<string, ModDataRecord> records, Func<string, string> getUpdateUrl) { this.Records = records; + this.GetUpdateUrl = getUpdateUrl; } /// <summary>Get a parsed representation of the <see cref="ModDataRecord.Fields"/> which match a given manifest.</summary> @@ -74,21 +79,54 @@ namespace StardewModdingAPI.Framework.ModData /// <param name="id">The unique mod ID.</param> public string GetDisplayNameFor(string id) { - foreach (var entry in this.Records) - { - if (entry.Value.ID != null && entry.Value.ID.Equals(id, StringComparison.InvariantCultureIgnoreCase)) - return entry.Key; - } + return this.TryGetRaw(id, out string displayName, out ModDataRecord _) + ? displayName + : null; + } - return null; + /// <summary>Get the mod page URL for a mod (if available).</summary> + /// <param name="id">The unique mod ID.</param> + public string GetModPageUrlFor(string id) + { + // get raw record + if (!this.TryGetRaw(id, out string _, out ModDataRecord record)) + return null; + + // get update key + ModDataField updateKeyField = record.GetFields().FirstOrDefault(p => p.Key == ModDataFieldKey.UpdateKey); + if (updateKeyField == null) + return null; + + // get update URL + return this.GetUpdateUrl(updateKeyField.Value); } /********* ** Private models *********/ - /// <summary>Get the data record matching a given manifest.</summary> - /// <param name="manifest">The mod manifest.</param> + /// <summary>Get a raw data record.</summary> + /// <param name="id">The mod ID to match.</param> + /// <param name="displayName">The mod's default display name.</param> + /// <param name="record">The raw mod record.</param> + private bool TryGetRaw(string id, out string displayName, out ModDataRecord record) + { + foreach (var entry in this.Records) + { + if (entry.Value.ID != null && entry.Value.ID.Equals(id, StringComparison.InvariantCultureIgnoreCase)) + { + displayName = entry.Key; + record = entry.Value; + return true; + } + } + + displayName = null; + record = null; + return false; + } + /// <summary>Get a raw data record.</summary> + /// <param name="manifest">The mod manifest whose fields to match.</param> /// <param name="displayName">The mod's default display name.</param> /// <param name="record">The raw mod record.</param> private bool TryGetRaw(IManifest manifest, out string displayName, out ModDataRecord record) diff --git a/src/SMAPI/Framework/ModLoading/ModResolver.cs b/src/SMAPI/Framework/ModLoading/ModResolver.cs index 99d86bf8..b46ee117 100644 --- a/src/SMAPI/Framework/ModLoading/ModResolver.cs +++ b/src/SMAPI/Framework/ModLoading/ModResolver.cs @@ -272,8 +272,11 @@ namespace StardewModdingAPI.Framework.ModLoading from entry in dependencies where entry.IsRequired && entry.Mod == null let displayName = modDatabase.GetDisplayNameFor(entry.ID) ?? entry.ID + let modUrl = modDatabase.GetModPageUrlFor(entry.ID) orderby displayName - select displayName + select modUrl != null + ? $"{displayName}: {modUrl}" + : displayName ).ToArray(); if (failedModNames.Any()) { diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 85bc83a7..275876dd 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -351,7 +351,7 @@ namespace StardewModdingAPI this.Monitor.Log("SMAPI found problems in your game's content files which are likely to cause errors or crashes. Consider uninstalling XNB mods or reinstalling the game.", LogLevel.Error); // load mod data - ModDatabase modDatabase = new ModDatabase(this.Settings.ModData); + ModDatabase modDatabase = new ModDatabase(this.Settings.ModData, Constants.GetUpdateUrl); // load mods { diff --git a/src/SMAPI/StardewModdingAPI.config.json b/src/SMAPI/StardewModdingAPI.config.json index ff5b1f9d..a9d3673c 100644 --- a/src/SMAPI/StardewModdingAPI.config.json +++ b/src/SMAPI/StardewModdingAPI.config.json @@ -458,7 +458,8 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha }, "Custom Crops": { - "ID": "spacechase0.CustomCrops" + "ID": "spacechase0.CustomCrops", + "Default | UpdateKey": "Nexus:1592" }, "Custom Element Handler": { @@ -515,7 +516,8 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha }, "Custom NPC": { - "ID": "Platonymous.CustomNPC" + "ID": "Platonymous.CustomNPC", + "Default | UpdateKey": "Nexus:1607" }, "Custom Shops Redux": { @@ -890,7 +892,8 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha }, "Json Assets": { - "ID": "spacechase0.JsonAssets" + "ID": "spacechase0.JsonAssets", + "Default | UpdateKey": "Nexus:1720" }, "Junimo Farm": { @@ -1172,7 +1175,8 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha }, "PyTK - Platonymous Toolkit": { - "ID": "Platonymous.Toolkit" + "ID": "Platonymous.Toolkit", + "Default | UpdateKey": "Nexus:1726" }, "Point-and-Plant": { |