From 9e7c77f1f4bb9bc244a8227d932a28999b022471 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 21 May 2017 17:29:40 -0400 Subject: enable mod dependencies (#285) --- release-notes.md | 8 ++++++-- src/StardewModdingAPI.Tests/ModResolverTests.cs | 8 -------- src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs | 4 ---- src/StardewModdingAPI/Framework/Models/Manifest.cs | 2 -- src/StardewModdingAPI/IManifest.cs | 2 -- src/StardewModdingAPI/Program.cs | 2 -- 6 files changed, 6 insertions(+), 20 deletions(-) diff --git a/release-notes.md b/release-notes.md index 7fee542c..ec05d4c3 100644 --- a/release-notes.md +++ b/release-notes.md @@ -14,8 +14,12 @@ For mod developers: See [log](https://github.com/Pathoschild/SMAPI/compare/1.13.1...1.14). For players: -* SMAPI now shows a friendly message when it can't detect the game. -* SMAPI now shows a friendly message when you have Stardew Valley 1.11 or earlier (which aren't compatible). +* SMAPI now shows a friendly error when it can't detect the game. +* SMAPI now shows a friendly error when you have Stardew Valley 1.11 or earlier (which aren't compatible). +* SMAPI now shows a friendly error if a mod dependency is missing (if it's listed in the mod's manifest). + +For modders: +* You can now list mod dependencies in the `manifest.json`. SMAPI will make sure your dependencies are loaded before your mod, and will show a friendly error if a dependency is missing. ## 1.13.1 See [log](https://github.com/Pathoschild/SMAPI/compare/1.13...1.13.1). diff --git a/src/StardewModdingAPI.Tests/ModResolverTests.cs b/src/StardewModdingAPI.Tests/ModResolverTests.cs index 8cf5a29e..c0545cd6 100644 --- a/src/StardewModdingAPI.Tests/ModResolverTests.cs +++ b/src/StardewModdingAPI.Tests/ModResolverTests.cs @@ -71,9 +71,7 @@ namespace StardewModdingAPI.Tests [nameof(IManifest.UniqueID)] = $"{Sample.String()}.{Sample.String()}", [nameof(IManifest.EntryDll)] = $"{Sample.String()}.dll", [nameof(IManifest.MinimumApiVersion)] = $"{Sample.Int()}.{Sample.Int()}-{Sample.String()}", -#if EXPERIMENTAL [nameof(IManifest.Dependencies)] = new[] { originalDependency }, -#endif ["ExtraString"] = Sample.String(), ["ExtraInt"] = Sample.Int() }; @@ -110,11 +108,9 @@ namespace StardewModdingAPI.Tests Assert.AreEqual(original["ExtraString"], mod.Manifest.ExtraFields["ExtraString"], "The manifest's extra fields should contain an 'ExtraString' value."); Assert.AreEqual(original["ExtraInt"], mod.Manifest.ExtraFields["ExtraInt"], "The manifest's extra fields should contain an 'ExtraInt' value."); -#if EXPERIMENTAL Assert.IsNotNull(mod.Manifest.Dependencies, "The dependencies field should not be null."); Assert.AreEqual(1, mod.Manifest.Dependencies.Length, "The dependencies field should contain one value."); Assert.AreEqual(originalDependency[nameof(IManifestDependency.UniqueID)], mod.Manifest.Dependencies[0].UniqueID, "The first dependency's unique ID doesn't match."); -#endif } /**** @@ -216,7 +212,6 @@ namespace StardewModdingAPI.Tests // if Moq doesn't throw a method-not-setup exception, the validation didn't override the status. } -#if EXPERIMENTAL /**** ** ProcessDependencies ****/ @@ -345,7 +340,6 @@ namespace StardewModdingAPI.Tests modD.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny()), Times.Once, "Mod D was expected to fail since it's part of a dependency loop."); modE.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny()), Times.Once, "Mod E was expected to fail since it's part of a dependency loop."); } -#endif /********* @@ -368,7 +362,6 @@ namespace StardewModdingAPI.Tests return manifest; } -#if EXPERIMENTAL /// Get a randomised basic manifest. /// The mod's name and unique ID. /// The dependencies this mod requires. @@ -395,6 +388,5 @@ namespace StardewModdingAPI.Tests } return mod; } -#endif } } diff --git a/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs b/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs index 2c68a639..21aebeb1 100644 --- a/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs +++ b/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs @@ -126,7 +126,6 @@ namespace StardewModdingAPI.Framework.ModLoading } } -#if EXPERIMENTAL /// Sort the given mods by the order they should be loaded. /// The mods to process. public IEnumerable ProcessDependencies(IEnumerable mods) @@ -149,13 +148,11 @@ namespace StardewModdingAPI.Framework.ModLoading return sortedMods.Reverse(); } -#endif /********* ** Private methods *********/ -#if EXPERIMENTAL /// Sort a mod's dependencies by the order they should be loaded, and remove any mods that can't be loaded due to missing or conflicting dependencies. /// The full list of mods being validated. /// The mod whose dependencies to process. @@ -270,7 +267,6 @@ namespace StardewModdingAPI.Framework.ModLoading return states[mod] = ModDependencyStatus.Sorted; } } -#endif /// Get all mod folders in a root folder, passing through empty folders as needed. /// The root folder path to search. diff --git a/src/StardewModdingAPI/Framework/Models/Manifest.cs b/src/StardewModdingAPI/Framework/Models/Manifest.cs index 53384852..be781585 100644 --- a/src/StardewModdingAPI/Framework/Models/Manifest.cs +++ b/src/StardewModdingAPI/Framework/Models/Manifest.cs @@ -30,11 +30,9 @@ namespace StardewModdingAPI.Framework.Models /// The name of the DLL in the directory that has the method. public string EntryDll { get; set; } -#if EXPERIMENTAL /// The other mods that must be loaded before this mod. [JsonConverter(typeof(ManifestFieldConverter))] public IManifestDependency[] Dependencies { get; set; } -#endif /// The unique mod ID. public string UniqueID { get; set; } diff --git a/src/StardewModdingAPI/IManifest.cs b/src/StardewModdingAPI/IManifest.cs index c036fdd3..9533aadb 100644 --- a/src/StardewModdingAPI/IManifest.cs +++ b/src/StardewModdingAPI/IManifest.cs @@ -29,10 +29,8 @@ namespace StardewModdingAPI /// The name of the DLL in the directory that has the method. string EntryDll { get; } -#if EXPERIMENTAL /// The other mods that must be loaded before this mod. IManifestDependency[] Dependencies { get; } -#endif /// Any manifest fields which didn't match a valid field. IDictionary ExtraFields { get; } diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 21717cc3..4df63456 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -402,10 +402,8 @@ namespace StardewModdingAPI } } -#if EXPERIMENTAL // process dependencies mods = resolver.ProcessDependencies(mods).ToArray(); -#endif // load mods modsLoaded = this.LoadMods(mods, new JsonHelper(), (SContentManager)Game1.content, deprecationWarnings); -- cgit