From 3744e2f1e5505c9d15fb3bc985ad147a33621048 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 3 Dec 2018 02:39:20 -0500 Subject: add SMAPI 3.0 compatibility strict mode (#606) --- src/SMAPI/Framework/ModHelpers/ModHelper.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/SMAPI/Framework/ModHelpers') diff --git a/src/SMAPI/Framework/ModHelpers/ModHelper.cs b/src/SMAPI/Framework/ModHelpers/ModHelper.cs index 5e190e55..cd7ac8ea 100644 --- a/src/SMAPI/Framework/ModHelpers/ModHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ModHelper.cs @@ -131,6 +131,7 @@ namespace StardewModdingAPI.Framework.ModHelpers this.Data.WriteJsonFile("config.json", config); } +#if !SMAPI_3_0_STRICT /**** ** Generic JSON files ****/ @@ -199,6 +200,7 @@ namespace StardewModdingAPI.Framework.ModHelpers // create content pack return this.CreateContentPack(directoryPath, manifest); } +#endif /// Get all content packs loaded for this mod. public IEnumerable GetContentPacks() -- cgit From aba15074b3d3ab6f655c976f84e9a597d0115efd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 5 Dec 2018 00:18:13 -0500 Subject: add helper.CreateTemporaryContentPack to replace deprecated transitional method --- docs/release-notes.md | 1 + src/SMAPI/Framework/ModHelpers/ModHelper.cs | 34 ++++++++++++++++++++++------- src/SMAPI/IModHelper.cs | 13 ++++++++++- 3 files changed, 39 insertions(+), 9 deletions(-) (limited to 'src/SMAPI/Framework/ModHelpers') diff --git a/docs/release-notes.md b/docs/release-notes.md index d7cb6680..6ac4e90b 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -9,6 +9,7 @@ * For modders: * Added ModDrop update keys (see [docs](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Manifest#Update_checks)). * Added `IsLocalPlayer` to new player events. + * Added `helper.CreateTemporaryContentPack` to support permanent use cases for mods using the deprecated `helper.CreateTransitionalContentPack`. * Reloading a map asset will now update affected locations. * Reloading the `Data\NPCDispositions` asset will now update affected NPCs. * Fixed world events (like `ObjectListChanged`) not working in the mines. diff --git a/src/SMAPI/Framework/ModHelpers/ModHelper.cs b/src/SMAPI/Framework/ModHelpers/ModHelper.cs index cd7ac8ea..070d9c65 100644 --- a/src/SMAPI/Framework/ModHelpers/ModHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ModHelper.cs @@ -21,8 +21,10 @@ namespace StardewModdingAPI.Framework.ModHelpers /// Create a transitional content pack. private readonly Func CreateContentPack; +#if !SMAPI_3_0_STRICT /// Manages deprecation warnings. private readonly DeprecationManager DeprecationManager; +#endif /********* @@ -31,8 +33,10 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The full path to the mod's folder. public string DirectoryPath { get; } +#if !SMAPI_3_0_STRICT /// Encapsulates SMAPI's JSON file parsing. private readonly JsonHelper JsonHelper; +#endif /// Manages access to events raised by SMAPI, which let your mod react when something happens in the game. public IModEvents Events { get; } @@ -94,7 +98,6 @@ namespace StardewModdingAPI.Framework.ModHelpers // initialise this.DirectoryPath = modDirectory; - this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper)); this.Content = contentHelper ?? throw new ArgumentNullException(nameof(contentHelper)); this.Data = dataHelper ?? throw new ArgumentNullException(nameof(dataHelper)); this.Input = new InputHelper(modID, inputState); @@ -105,8 +108,11 @@ namespace StardewModdingAPI.Framework.ModHelpers this.Translation = translationHelper ?? throw new ArgumentNullException(nameof(translationHelper)); this.ContentPacks = new Lazy(contentPacks); this.CreateContentPack = createContentPack; - this.DeprecationManager = deprecationManager; this.Events = events; +#if !SMAPI_3_0_STRICT + this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper)); + this.DeprecationManager = deprecationManager; +#endif } /**** @@ -160,23 +166,20 @@ namespace StardewModdingAPI.Framework.ModHelpers path = Path.Combine(this.DirectoryPath, PathUtilities.NormalisePathSeparators(path)); this.JsonHelper.WriteJsonFile(path, model); } +#endif /**** ** Content packs ****/ - /// Manually create a transitional content pack to support pre-SMAPI content packs. This provides a way to access legacy content packs using the SMAPI content pack APIs, but the content pack will not be visible in the log or validated by SMAPI. + /// Create a temporary content pack to read files from a directory. Temporary content packs will not appear in the SMAPI log and update checks will not be performed. /// The absolute directory path containing the content pack files. /// The content pack's unique ID. /// The content pack name. /// The content pack description. /// The content pack author's name. /// The content pack version. - [Obsolete("This method supports mods which previously had their own content packs, and shouldn't be used by new mods. It will be removed in SMAPI 3.0.")] - public IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) + public IContentPack CreateTemporaryContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) { - // raise deprecation notice - this.DeprecationManager.Warn($"{nameof(IModHelper)}.{nameof(IModHelper.CreateTransitionalContentPack)}", "2.5", DeprecationLevel.Notice); - // validate if (string.IsNullOrWhiteSpace(directoryPath)) throw new ArgumentNullException(nameof(directoryPath)); @@ -200,6 +203,21 @@ namespace StardewModdingAPI.Framework.ModHelpers // create content pack return this.CreateContentPack(directoryPath, manifest); } + +#if !SMAPI_3_0_STRICT + /// Manually create a transitional content pack to support pre-SMAPI content packs. This provides a way to access legacy content packs using the SMAPI content pack APIs, but the content pack will not be visible in the log or validated by SMAPI. + /// The absolute directory path containing the content pack files. + /// The content pack's unique ID. + /// The content pack name. + /// The content pack description. + /// The content pack author's name. + /// The content pack version. + [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.CreateTemporaryContentPack) + " instead")] + public IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) + { + this.DeprecationManager.Warn($"{nameof(IModHelper)}.{nameof(IModHelper.CreateTransitionalContentPack)}", "2.5", DeprecationLevel.Notice); + return this.CreateTemporaryContentPack(directoryPath, id, name, description, author, version); + } #endif /// Get all content packs loaded for this mod. diff --git a/src/SMAPI/IModHelper.cs b/src/SMAPI/IModHelper.cs index b7d06f56..fbe3d51f 100644 --- a/src/SMAPI/IModHelper.cs +++ b/src/SMAPI/IModHelper.cs @@ -73,10 +73,21 @@ namespace StardewModdingAPI /// The model to save. [Obsolete("Use " + nameof(IModHelper.Data) + "." + nameof(IDataHelper.WriteJsonFile) + " instead")] void WriteJsonFile(string path, TModel model) where TModel : class; +#endif /**** ** Content packs ****/ + /// Create a temporary content pack to read files from a directory. Temporary content packs will not appear in the SMAPI log and update checks will not be performed. + /// The absolute directory path containing the content pack files. + /// The content pack's unique ID. + /// The content pack name. + /// The content pack description. + /// The content pack author's name. + /// The content pack version. + IContentPack CreateTemporaryContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version); + +#if !SMAPI_3_0_STRICT /// Manually create a transitional content pack to support pre-SMAPI content packs. This provides a way to access legacy content packs using the SMAPI content pack APIs, but the content pack will not be visible in the log or validated by SMAPI. /// The absolute directory path containing the content pack files. /// The content pack's unique ID. @@ -84,7 +95,7 @@ namespace StardewModdingAPI /// The content pack description. /// The content pack author's name. /// The content pack version. - [Obsolete("This method supports mods which previously had their own content packs, and shouldn't be used by new mods. It will be removed in SMAPI 3.0.")] + [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.CreateTemporaryContentPack) + " instead")] IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version); #endif -- cgit