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 --- src/SMAPI/Framework/ModHelpers/ModHelper.cs | 34 ++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'src/SMAPI/Framework/ModHelpers') 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. -- cgit