From 441ded8c9a9e3dea39cb180df429d3fcc5f3cc96 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 9 Dec 2018 18:52:21 -0500 Subject: fix error when a mod makes invalid changes to an NPC schedule --- src/SMAPI/Framework/ContentCoordinator.cs | 2 +- src/SMAPI/Metadata/CoreAssetPropagator.cs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs index 08a32a9b..7e256939 100644 --- a/src/SMAPI/Framework/ContentCoordinator.cs +++ b/src/SMAPI/Framework/ContentCoordinator.cs @@ -81,7 +81,7 @@ namespace StardewModdingAPI.Framework this.ContentManagers.Add( this.MainContentManager = new GameContentManager("Game1.content", serviceProvider, rootDirectory, currentCulture, this, monitor, reflection, this.OnDisposing) ); - this.CoreAssets = new CoreAssetPropagator(this.MainContentManager.AssertAndNormaliseAssetName, reflection); + this.CoreAssets = new CoreAssetPropagator(this.MainContentManager.AssertAndNormaliseAssetName, reflection, monitor); } /// Get a new content manager which handles reading files from the game content folder with support for interception. diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 90629d7f..4667be7e 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -31,6 +31,9 @@ namespace StardewModdingAPI.Metadata /// Simplifies access to private game code. private readonly Reflector Reflection; + /// Encapsulates monitoring and logging. + private readonly IMonitor Monitor; + /********* ** Public methods @@ -38,10 +41,12 @@ namespace StardewModdingAPI.Metadata /// Initialise the core asset data. /// Normalises an asset key to match the cache key. /// Simplifies access to private code. - public CoreAssetPropagator(Func getNormalisedPath, Reflector reflection) + /// Encapsulates monitoring and logging. + public CoreAssetPropagator(Func getNormalisedPath, Reflector reflection, IMonitor monitor) { this.GetNormalisedPath = getNormalisedPath; this.Reflection = reflection; + this.Monitor = monitor; } /// Reload one of the game's core assets (if applicable). @@ -619,6 +624,11 @@ namespace StardewModdingAPI.Metadata { // reload schedule villager.Schedule = villager.getSchedule(Game1.dayOfMonth); + if (villager.Schedule == null) + { + this.Monitor.Log($"A mod set an invalid schedule for {villager.Name ?? key}, so the NPC may not behave correctly.", LogLevel.Warn); + return true; + } // switch to new schedule if needed int lastScheduleTime = villager.Schedule.Keys.Where(p => p <= Game1.timeOfDay).OrderByDescending(p => p).FirstOrDefault(); -- cgit From 3fef9bb2a5cc39fc6ba15199b0889fae5533c5f0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 9 Dec 2018 19:35:38 -0500 Subject: fix 'begin must be called' sprite batch errors when using Display.RenderedWorld event --- docs/release-notes.md | 1 + src/SMAPI/Framework/SGame.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/docs/release-notes.md b/docs/release-notes.md index 63343d0a..6033b141 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -2,6 +2,7 @@ ## Upcoming release * For players: * Fixed error when a mod makes invalid changes to an NPC schedule. + * Fixed `Display.RenderedWorld` event broken in SMAPI 2.9.1. ## 2.9.1 * For players: diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 7b3335b7..4d790d9f 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -1422,8 +1422,8 @@ namespace StardewModdingAPI.Framework } Game1.spriteBatch.End(); } - this.Events.RenderedWorld.RaiseEmpty(); Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null); + this.Events.RenderedWorld.RaiseEmpty(); if (Game1.drawGrid) { int num1 = -Game1.viewport.X % 64; -- cgit From cd277e915f85260c8af665b5aeb44368badf06e8 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 13 Dec 2018 00:34:28 -0500 Subject: fix NPCDisposition asset propagation breaking NPC data --- docs/release-notes.md | 1 + src/SMAPI/Metadata/CoreAssetPropagator.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/docs/release-notes.md b/docs/release-notes.md index 6033b141..6c10b4ac 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -2,6 +2,7 @@ ## Upcoming release * For players: * Fixed error when a mod makes invalid changes to an NPC schedule. + * Fixed invalid NPC data propagated when a mod changes NPC dispositions. * Fixed `Display.RenderedWorld` event broken in SMAPI 2.9.1. ## 2.9.1 diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 4667be7e..a44ab7d1 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -504,7 +504,7 @@ namespace StardewModdingAPI.Metadata if (!character.isVillager() || !dispositions.ContainsKey(character.Name)) continue; - NPC clone = new NPC(null, Vector2.Zero, 0, character.Name); + NPC clone = new NPC(null, character.Position, character.DefaultMap, character.FacingDirection, character.Name, null, character.Portrait, eventActor: false); character.Age = clone.Age; character.Manners = clone.Manners; character.SocialAnxiety = clone.SocialAnxiety; -- cgit From e447ce225f46f60131519a1ff77dfddf520696bb Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 13 Dec 2018 01:16:38 -0500 Subject: add content pack API --- docs/release-notes.md | 3 + src/SMAPI/Framework/ModHelpers/CommandHelper.cs | 2 +- .../Framework/ModHelpers/ContentPackHelper.cs | 82 ++++++++++++++++++++++ src/SMAPI/Framework/ModHelpers/ModHelper.cs | 59 +++------------- src/SMAPI/Framework/SCore.cs | 5 +- src/SMAPI/ICommandHelper.cs | 2 +- src/SMAPI/IContentPackHelper.cs | 27 +++++++ src/SMAPI/IModHelper.cs | 22 ++---- src/SMAPI/StardewModdingAPI.csproj | 2 + 9 files changed, 136 insertions(+), 68 deletions(-) create mode 100644 src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs create mode 100644 src/SMAPI/IContentPackHelper.cs (limited to 'src') diff --git a/docs/release-notes.md b/docs/release-notes.md index 6c10b4ac..de0bdf71 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -5,6 +5,9 @@ * Fixed invalid NPC data propagated when a mod changes NPC dispositions. * Fixed `Display.RenderedWorld` event broken in SMAPI 2.9.1. +* For modders: + * Added dedicated content pack API. + ## 2.9.1 * For players: * Fixed crash in SMAPI 2.9 when constructing certain buildings. diff --git a/src/SMAPI/Framework/ModHelpers/CommandHelper.cs b/src/SMAPI/Framework/ModHelpers/CommandHelper.cs index 5a3304f3..a4fd21c1 100644 --- a/src/SMAPI/Framework/ModHelpers/CommandHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/CommandHelper.cs @@ -6,7 +6,7 @@ namespace StardewModdingAPI.Framework.ModHelpers internal class CommandHelper : BaseHelper, ICommandHelper { /********* - ** Accessors + ** Properties *********/ /// The mod using this instance. private readonly IModMetadata Mod; diff --git a/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs new file mode 100644 index 00000000..c4b86cda --- /dev/null +++ b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.IO; +using StardewModdingAPI.Toolkit.Serialisation.Models; + +namespace StardewModdingAPI.Framework.ModHelpers +{ + /// Provides an API for managing content packs. + internal class ContentPackHelper : BaseHelper, IContentPackHelper + { + /********* + ** Properties + *********/ + /// The content packs loaded for this mod. + private readonly Lazy ContentPacks; + + /// Create a temporary content pack. + private readonly Func CreateContentPack; + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The unique ID of the relevant mod. + /// The content packs loaded for this mod. + /// Create a temporary content pack. + public ContentPackHelper(string modID, Lazy contentPacks, Func createContentPack) + : base(modID) + { + this.ContentPacks = contentPacks; + this.CreateContentPack = createContentPack; + } + + /// Get all content packs loaded for this mod. + public IEnumerable GetOwned() + { + return this.ContentPacks.Value; + } + + /// Create a temporary content pack to read files from a directory. This will generate fake manifest data; any manifest.json in the directory will be ignored. 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. + public IContentPack CreateFake(string directoryPath) + { + string id = Guid.NewGuid().ToString("N"); + return this.CreateFake(directoryPath, id, id, id, id, new SemanticVersion(1, 0, 0)); + } + + /// 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. + public IContentPack CreateFake(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) + { + // validate + if (string.IsNullOrWhiteSpace(directoryPath)) + throw new ArgumentNullException(nameof(directoryPath)); + if (string.IsNullOrWhiteSpace(id)) + throw new ArgumentNullException(nameof(id)); + if (string.IsNullOrWhiteSpace(name)) + throw new ArgumentNullException(nameof(name)); + if (!Directory.Exists(directoryPath)) + throw new ArgumentException($"Can't create content pack for directory path '{directoryPath}' because no such directory exists."); + + // create manifest + IManifest manifest = new Manifest( + uniqueID: id, + name: name, + author: author, + description: description, + version: version, + contentPackFor: this.ModID + ); + + // create content pack + return this.CreateContentPack(directoryPath, manifest); + } + } +} diff --git a/src/SMAPI/Framework/ModHelpers/ModHelper.cs b/src/SMAPI/Framework/ModHelpers/ModHelper.cs index 070d9c65..87d405e9 100644 --- a/src/SMAPI/Framework/ModHelpers/ModHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ModHelper.cs @@ -15,12 +15,6 @@ namespace StardewModdingAPI.Framework.ModHelpers /********* ** Properties *********/ - /// The content packs loaded for this mod. - private readonly Lazy ContentPacks; - - /// Create a transitional content pack. - private readonly Func CreateContentPack; - #if !SMAPI_3_0_STRICT /// Manages deprecation warnings. private readonly DeprecationManager DeprecationManager; @@ -44,6 +38,9 @@ namespace StardewModdingAPI.Framework.ModHelpers /// An API for loading content assets. public IContentHelper Content { get; } + /// An API for managing content packs. + public IContentPackHelper ContentPacks { get; } + /// An API for reading and writing persistent mod data. public IDataHelper Data { get; } @@ -76,18 +73,17 @@ namespace StardewModdingAPI.Framework.ModHelpers /// Manages the game's input state. /// Manages access to events raised by SMAPI. /// An API for loading content assets. + /// An API for managing content packs. /// An API for managing console commands. /// An API for reading and writing persistent mod data. /// an API for fetching metadata about loaded mods. /// An API for accessing private game code. /// Provides multiplayer utilities. /// An API for reading translations stored in the mod's i18n folder. - /// The content packs loaded for this mod. - /// Create a transitional content pack. /// Manages deprecation warnings. /// An argument is null or empty. /// The path does not exist on disk. - public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, SInputState inputState, IModEvents events, IContentHelper contentHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper, Func contentPacks, Func createContentPack, DeprecationManager deprecationManager) + public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, SInputState inputState, IModEvents events, IContentHelper contentHelper, IContentPackHelper contentPackHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper, DeprecationManager deprecationManager) : base(modID) { // validate directory @@ -99,6 +95,7 @@ namespace StardewModdingAPI.Framework.ModHelpers // initialise this.DirectoryPath = modDirectory; this.Content = contentHelper ?? throw new ArgumentNullException(nameof(contentHelper)); + this.ContentPacks = contentPackHelper ?? throw new ArgumentNullException(nameof(contentPackHelper)); this.Data = dataHelper ?? throw new ArgumentNullException(nameof(dataHelper)); this.Input = new InputHelper(modID, inputState); this.ModRegistry = modRegistry ?? throw new ArgumentNullException(nameof(modRegistry)); @@ -106,8 +103,6 @@ namespace StardewModdingAPI.Framework.ModHelpers this.Reflection = reflectionHelper ?? throw new ArgumentNullException(nameof(reflectionHelper)); this.Multiplayer = multiplayer ?? throw new ArgumentNullException(nameof(multiplayer)); this.Translation = translationHelper ?? throw new ArgumentNullException(nameof(translationHelper)); - this.ContentPacks = new Lazy(contentPacks); - this.CreateContentPack = createContentPack; this.Events = events; #if !SMAPI_3_0_STRICT this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper)); @@ -171,39 +166,6 @@ namespace StardewModdingAPI.Framework.ModHelpers /**** ** 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. - public IContentPack CreateTemporaryContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) - { - // validate - if (string.IsNullOrWhiteSpace(directoryPath)) - throw new ArgumentNullException(nameof(directoryPath)); - if (string.IsNullOrWhiteSpace(id)) - throw new ArgumentNullException(nameof(id)); - if (string.IsNullOrWhiteSpace(name)) - throw new ArgumentNullException(nameof(name)); - if (!Directory.Exists(directoryPath)) - throw new ArgumentException($"Can't create content pack for directory path '{directoryPath}' because no such directory exists."); - - // create manifest - IManifest manifest = new Manifest( - uniqueID: id, - name: name, - author: author, - description: description, - version: version, - contentPackFor: this.ModID - ); - - // 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. @@ -212,19 +174,20 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The content pack description. /// The content pack author's name. /// The content pack version. - [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.CreateTemporaryContentPack) + " instead")] + [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.CreateFake) + " 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); + return this.ContentPacks.CreateFake(directoryPath, id, name, description, author, version); } -#endif /// Get all content packs loaded for this mod. + [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.GetOwned) + " instead")] public IEnumerable GetContentPacks() { - return this.ContentPacks.Value; + return this.ContentPacks.GetOwned(); } +#endif /**** ** Disposal diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 800b9c09..76b091d0 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -1014,20 +1014,21 @@ namespace StardewModdingAPI.Framework IModEvents events = new ModEvents(mod, this.EventManager); ICommandHelper commandHelper = new CommandHelper(mod, this.GameInstance.CommandManager); IContentHelper contentHelper = new ContentHelper(contentCore, mod.DirectoryPath, manifest.UniqueID, mod.DisplayName, monitor); + IContentPackHelper contentPackHelper = new ContentPackHelper(manifest.UniqueID, new Lazy(GetContentPacks), CreateFakeContentPack); IDataHelper dataHelper = new DataHelper(manifest.UniqueID, mod.DirectoryPath, jsonHelper); IReflectionHelper reflectionHelper = new ReflectionHelper(manifest.UniqueID, mod.DisplayName, this.Reflection, this.DeprecationManager); IModRegistry modRegistryHelper = new ModRegistryHelper(manifest.UniqueID, this.ModRegistry, proxyFactory, monitor); IMultiplayerHelper multiplayerHelper = new MultiplayerHelper(manifest.UniqueID, this.GameInstance.Multiplayer); ITranslationHelper translationHelper = new TranslationHelper(manifest.UniqueID, manifest.Name, contentCore.GetLocale(), contentCore.Language); - IContentPack CreateTransitionalContentPack(string packDirPath, IManifest packManifest) + IContentPack CreateFakeContentPack(string packDirPath, IManifest packManifest) { IMonitor packMonitor = this.GetSecondaryMonitor(packManifest.Name); IContentHelper packContentHelper = new ContentHelper(contentCore, packDirPath, packManifest.UniqueID, packManifest.Name, packMonitor); return new ContentPack(packDirPath, packManifest, packContentHelper, this.Toolkit.JsonHelper); } - modHelper = new ModHelper(manifest.UniqueID, mod.DirectoryPath, this.Toolkit.JsonHelper, this.GameInstance.Input, events, contentHelper, commandHelper, dataHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper, GetContentPacks, CreateTransitionalContentPack, this.DeprecationManager); + modHelper = new ModHelper(manifest.UniqueID, mod.DirectoryPath, this.Toolkit.JsonHelper, this.GameInstance.Input, events, contentHelper, contentPackHelper, commandHelper, dataHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper, this.DeprecationManager); } // init mod diff --git a/src/SMAPI/ICommandHelper.cs b/src/SMAPI/ICommandHelper.cs index fb562e32..196e1051 100644 --- a/src/SMAPI/ICommandHelper.cs +++ b/src/SMAPI/ICommandHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace StardewModdingAPI { diff --git a/src/SMAPI/IContentPackHelper.cs b/src/SMAPI/IContentPackHelper.cs new file mode 100644 index 00000000..0c734432 --- /dev/null +++ b/src/SMAPI/IContentPackHelper.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; + +namespace StardewModdingAPI +{ + /// Provides an API for managing content packs. + public interface IContentPackHelper : IModLinked + { + /********* + ** Public methods + *********/ + /// Get all content packs loaded for this mod. + IEnumerable GetOwned(); + + /// 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. + IContentPack CreateFake(string directoryPath); + + /// 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 CreateFake(string directoryPath, string id, string name, string description, string author, ISemanticVersion version); + } +} diff --git a/src/SMAPI/IModHelper.cs b/src/SMAPI/IModHelper.cs index fbe3d51f..21bc5727 100644 --- a/src/SMAPI/IModHelper.cs +++ b/src/SMAPI/IModHelper.cs @@ -22,6 +22,9 @@ namespace StardewModdingAPI /// An API for loading content assets. IContentHelper Content { get; } + /// An API for managing content packs. + IContentPackHelper ContentPacks { get; } + /// An API for reading and writing persistent mod data. IDataHelper Data { get; } @@ -73,21 +76,7 @@ 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. @@ -95,11 +84,12 @@ namespace StardewModdingAPI /// The content pack description. /// The content pack author's name. /// The content pack version. - [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.CreateTemporaryContentPack) + " instead")] + [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.CreateFake) + " instead")] IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version); -#endif /// Get all content packs loaded for this mod. + [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.GetOwned) + " instead")] IEnumerable GetContentPacks(); +#endif } } diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index 49a88f37..2c769f41 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -174,6 +174,7 @@ + @@ -207,6 +208,7 @@ + -- cgit From 11787f9fea35ee8597c8a4c028b9c3be42751463 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 13 Dec 2018 01:26:54 -0500 Subject: tweak new API method name --- src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs | 4 ++-- src/SMAPI/Framework/ModHelpers/ModHelper.cs | 2 +- src/SMAPI/IContentPackHelper.cs | 2 +- src/SMAPI/IModHelper.cs | 5 ++++- 4 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs index c4b86cda..4bd28b36 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs @@ -43,7 +43,7 @@ namespace StardewModdingAPI.Framework.ModHelpers public IContentPack CreateFake(string directoryPath) { string id = Guid.NewGuid().ToString("N"); - return this.CreateFake(directoryPath, id, id, id, id, new SemanticVersion(1, 0, 0)); + return this.CreateTemporary(directoryPath, id, id, id, id, new SemanticVersion(1, 0, 0)); } /// 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. @@ -53,7 +53,7 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The content pack description. /// The content pack author's name. /// The content pack version. - public IContentPack CreateFake(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) + public IContentPack CreateTemporary(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) { // validate if (string.IsNullOrWhiteSpace(directoryPath)) diff --git a/src/SMAPI/Framework/ModHelpers/ModHelper.cs b/src/SMAPI/Framework/ModHelpers/ModHelper.cs index 87d405e9..0dbc5fd7 100644 --- a/src/SMAPI/Framework/ModHelpers/ModHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ModHelper.cs @@ -174,7 +174,7 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The content pack description. /// The content pack author's name. /// The content pack version. - [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.CreateFake) + " instead")] + [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.CreateTemporary) + " 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); diff --git a/src/SMAPI/IContentPackHelper.cs b/src/SMAPI/IContentPackHelper.cs index 0c734432..6cce964c 100644 --- a/src/SMAPI/IContentPackHelper.cs +++ b/src/SMAPI/IContentPackHelper.cs @@ -22,6 +22,6 @@ namespace StardewModdingAPI /// The content pack description. /// The content pack author's name. /// The content pack version. - IContentPack CreateFake(string directoryPath, string id, string name, string description, string author, ISemanticVersion version); + IContentPack CreateTemporary(string directoryPath, string id, string name, string description, string author, ISemanticVersion version); } } diff --git a/src/SMAPI/IModHelper.cs b/src/SMAPI/IModHelper.cs index 21bc5727..0220b4f7 100644 --- a/src/SMAPI/IModHelper.cs +++ b/src/SMAPI/IModHelper.cs @@ -77,6 +77,9 @@ namespace StardewModdingAPI [Obsolete("Use " + nameof(IModHelper.Data) + "." + nameof(IDataHelper.WriteJsonFile) + " instead")] void WriteJsonFile(string path, TModel model) where TModel : class; + /**** + ** 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. /// The absolute directory path containing the content pack files. /// The content pack's unique ID. @@ -84,7 +87,7 @@ namespace StardewModdingAPI /// The content pack description. /// The content pack author's name. /// The content pack version. - [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.CreateFake) + " instead")] + [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.CreateTemporary) + " instead")] IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version); /// Get all content packs loaded for this mod. -- cgit From 6045351395f6b74846a2b18b131f662b88641569 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 13 Dec 2018 02:00:30 -0500 Subject: simplify access to deprecation manager for deprecation warnings --- src/SMAPI/Events/ContentEvents.cs | 9 +--- src/SMAPI/Events/ControlEvents.cs | 23 ++++------ src/SMAPI/Events/GameEvents.cs | 23 ++++------ src/SMAPI/Events/GraphicsEvents.cs | 21 ++++----- src/SMAPI/Events/InputEvents.cs | 11 ++--- src/SMAPI/Events/LocationEvents.cs | 13 ++---- src/SMAPI/Events/MenuEvents.cs | 11 ++--- src/SMAPI/Events/MineEvents.cs | 9 +--- src/SMAPI/Events/MultiplayerEvents.cs | 15 +++---- src/SMAPI/Events/PlayerEvents.cs | 13 ++---- src/SMAPI/Events/SaveEvents.cs | 19 +++----- src/SMAPI/Events/SpecialisedEvents.cs | 9 +--- src/SMAPI/Events/TimeEvents.cs | 11 ++--- src/SMAPI/Framework/ModHelpers/ModHelper.cs | 17 ++------ src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs | 7 +-- src/SMAPI/Framework/SCore.cs | 51 +++++++++++----------- src/SMAPI/SemanticVersion.cs | 5 +-- 17 files changed, 92 insertions(+), 175 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Events/ContentEvents.cs b/src/SMAPI/Events/ContentEvents.cs index 99369cae..1a2dd526 100644 --- a/src/SMAPI/Events/ContentEvents.cs +++ b/src/SMAPI/Events/ContentEvents.cs @@ -15,9 +15,6 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; - /// Manages deprecation warnings. - private static DeprecationManager DeprecationManager; - /********* ** Events @@ -27,7 +24,7 @@ namespace StardewModdingAPI.Events { add { - ContentEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); ContentEvents.EventManager.Legacy_LocaleChanged.Add(value); } remove => ContentEvents.EventManager.Legacy_LocaleChanged.Remove(value); @@ -39,11 +36,9 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - /// Manages deprecation warnings. - internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) + internal static void Init(EventManager eventManager) { ContentEvents.EventManager = eventManager; - ContentEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/ControlEvents.cs b/src/SMAPI/Events/ControlEvents.cs index 5626ff81..be849f95 100644 --- a/src/SMAPI/Events/ControlEvents.cs +++ b/src/SMAPI/Events/ControlEvents.cs @@ -16,9 +16,6 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; - /// Manages deprecation warnings. - private static DeprecationManager DeprecationManager; - /********* ** Events @@ -28,7 +25,7 @@ namespace StardewModdingAPI.Events { add { - ControlEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); ControlEvents.EventManager.Legacy_KeyboardChanged.Add(value); } remove => ControlEvents.EventManager.Legacy_KeyboardChanged.Remove(value); @@ -39,7 +36,7 @@ namespace StardewModdingAPI.Events { add { - ControlEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); ControlEvents.EventManager.Legacy_KeyPressed.Add(value); } remove => ControlEvents.EventManager.Legacy_KeyPressed.Remove(value); @@ -50,7 +47,7 @@ namespace StardewModdingAPI.Events { add { - ControlEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); ControlEvents.EventManager.Legacy_KeyReleased.Add(value); } remove => ControlEvents.EventManager.Legacy_KeyReleased.Remove(value); @@ -61,7 +58,7 @@ namespace StardewModdingAPI.Events { add { - ControlEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); ControlEvents.EventManager.Legacy_MouseChanged.Add(value); } remove => ControlEvents.EventManager.Legacy_MouseChanged.Remove(value); @@ -72,7 +69,7 @@ namespace StardewModdingAPI.Events { add { - ControlEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); ControlEvents.EventManager.Legacy_ControllerButtonPressed.Add(value); } remove => ControlEvents.EventManager.Legacy_ControllerButtonPressed.Remove(value); @@ -83,7 +80,7 @@ namespace StardewModdingAPI.Events { add { - ControlEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); ControlEvents.EventManager.Legacy_ControllerButtonReleased.Add(value); } remove => ControlEvents.EventManager.Legacy_ControllerButtonReleased.Remove(value); @@ -94,7 +91,7 @@ namespace StardewModdingAPI.Events { add { - ControlEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); ControlEvents.EventManager.Legacy_ControllerTriggerPressed.Add(value); } remove => ControlEvents.EventManager.Legacy_ControllerTriggerPressed.Remove(value); @@ -105,7 +102,7 @@ namespace StardewModdingAPI.Events { add { - ControlEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); ControlEvents.EventManager.Legacy_ControllerTriggerReleased.Add(value); } remove => ControlEvents.EventManager.Legacy_ControllerTriggerReleased.Remove(value); @@ -117,11 +114,9 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - /// Manages deprecation warnings. - internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) + internal static void Init(EventManager eventManager) { ControlEvents.EventManager = eventManager; - ControlEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/GameEvents.cs b/src/SMAPI/Events/GameEvents.cs index 39b77f99..6069a185 100644 --- a/src/SMAPI/Events/GameEvents.cs +++ b/src/SMAPI/Events/GameEvents.cs @@ -15,9 +15,6 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; - /// Manages deprecation warnings. - private static DeprecationManager DeprecationManager; - /********* ** Events @@ -27,7 +24,7 @@ namespace StardewModdingAPI.Events { add { - GameEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GameEvents.EventManager.Legacy_UpdateTick.Add(value); } remove => GameEvents.EventManager.Legacy_UpdateTick.Remove(value); @@ -38,7 +35,7 @@ namespace StardewModdingAPI.Events { add { - GameEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GameEvents.EventManager.Legacy_SecondUpdateTick.Add(value); } remove => GameEvents.EventManager.Legacy_SecondUpdateTick.Remove(value); @@ -49,7 +46,7 @@ namespace StardewModdingAPI.Events { add { - GameEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GameEvents.EventManager.Legacy_FourthUpdateTick.Add(value); } remove => GameEvents.EventManager.Legacy_FourthUpdateTick.Remove(value); @@ -60,7 +57,7 @@ namespace StardewModdingAPI.Events { add { - GameEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GameEvents.EventManager.Legacy_EighthUpdateTick.Add(value); } remove => GameEvents.EventManager.Legacy_EighthUpdateTick.Remove(value); @@ -71,7 +68,7 @@ namespace StardewModdingAPI.Events { add { - GameEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GameEvents.EventManager.Legacy_QuarterSecondTick.Add(value); } remove => GameEvents.EventManager.Legacy_QuarterSecondTick.Remove(value); @@ -82,7 +79,7 @@ namespace StardewModdingAPI.Events { add { - GameEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GameEvents.EventManager.Legacy_HalfSecondTick.Add(value); } remove => GameEvents.EventManager.Legacy_HalfSecondTick.Remove(value); @@ -93,7 +90,7 @@ namespace StardewModdingAPI.Events { add { - GameEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GameEvents.EventManager.Legacy_OneSecondTick.Add(value); } remove => GameEvents.EventManager.Legacy_OneSecondTick.Remove(value); @@ -104,7 +101,7 @@ namespace StardewModdingAPI.Events { add { - GameEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GameEvents.EventManager.Legacy_FirstUpdateTick.Add(value); } remove => GameEvents.EventManager.Legacy_FirstUpdateTick.Remove(value); @@ -116,11 +113,9 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - /// Manages deprecation warnings. - internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) + internal static void Init(EventManager eventManager) { GameEvents.EventManager = eventManager; - GameEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/GraphicsEvents.cs b/src/SMAPI/Events/GraphicsEvents.cs index be29bf11..88a32c3f 100644 --- a/src/SMAPI/Events/GraphicsEvents.cs +++ b/src/SMAPI/Events/GraphicsEvents.cs @@ -15,9 +15,6 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; - /// Manages deprecation warnings. - private static DeprecationManager DeprecationManager; - /********* ** Events @@ -27,7 +24,7 @@ namespace StardewModdingAPI.Events { add { - GraphicsEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GraphicsEvents.EventManager.Legacy_Resize.Add(value); } remove => GraphicsEvents.EventManager.Legacy_Resize.Remove(value); @@ -41,7 +38,7 @@ namespace StardewModdingAPI.Events { add { - GraphicsEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GraphicsEvents.EventManager.Legacy_OnPreRenderEvent.Add(value); } remove => GraphicsEvents.EventManager.Legacy_OnPreRenderEvent.Remove(value); @@ -52,7 +49,7 @@ namespace StardewModdingAPI.Events { add { - GraphicsEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GraphicsEvents.EventManager.Legacy_OnPostRenderEvent.Add(value); } remove => GraphicsEvents.EventManager.Legacy_OnPostRenderEvent.Remove(value); @@ -66,7 +63,7 @@ namespace StardewModdingAPI.Events { add { - GraphicsEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GraphicsEvents.EventManager.Legacy_OnPreRenderHudEvent.Add(value); } remove => GraphicsEvents.EventManager.Legacy_OnPreRenderHudEvent.Remove(value); @@ -77,7 +74,7 @@ namespace StardewModdingAPI.Events { add { - GraphicsEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GraphicsEvents.EventManager.Legacy_OnPostRenderHudEvent.Add(value); } remove => GraphicsEvents.EventManager.Legacy_OnPostRenderHudEvent.Remove(value); @@ -91,7 +88,7 @@ namespace StardewModdingAPI.Events { add { - GraphicsEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GraphicsEvents.EventManager.Legacy_OnPreRenderGuiEvent.Add(value); } remove => GraphicsEvents.EventManager.Legacy_OnPreRenderGuiEvent.Remove(value); @@ -102,7 +99,7 @@ namespace StardewModdingAPI.Events { add { - GraphicsEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); GraphicsEvents.EventManager.Legacy_OnPostRenderGuiEvent.Add(value); } remove => GraphicsEvents.EventManager.Legacy_OnPostRenderGuiEvent.Remove(value); @@ -114,11 +111,9 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - /// Manages deprecation warnings. - internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) + internal static void Init(EventManager eventManager) { GraphicsEvents.EventManager = eventManager; - GraphicsEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/InputEvents.cs b/src/SMAPI/Events/InputEvents.cs index 255b9c8a..900e53ea 100644 --- a/src/SMAPI/Events/InputEvents.cs +++ b/src/SMAPI/Events/InputEvents.cs @@ -15,9 +15,6 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; - /// Manages deprecation warnings. - private static DeprecationManager DeprecationManager; - /********* ** Events @@ -27,7 +24,7 @@ namespace StardewModdingAPI.Events { add { - InputEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); InputEvents.EventManager.Legacy_ButtonPressed.Add(value); } remove => InputEvents.EventManager.Legacy_ButtonPressed.Remove(value); @@ -38,7 +35,7 @@ namespace StardewModdingAPI.Events { add { - InputEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); InputEvents.EventManager.Legacy_ButtonReleased.Add(value); } remove => InputEvents.EventManager.Legacy_ButtonReleased.Remove(value); @@ -50,11 +47,9 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - /// Manages deprecation warnings. - internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) + internal static void Init(EventManager eventManager) { InputEvents.EventManager = eventManager; - InputEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/LocationEvents.cs b/src/SMAPI/Events/LocationEvents.cs index e0bcd853..5eb228b7 100644 --- a/src/SMAPI/Events/LocationEvents.cs +++ b/src/SMAPI/Events/LocationEvents.cs @@ -15,9 +15,6 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; - /// Manages deprecation warnings. - private static DeprecationManager DeprecationManager; - /********* ** Events @@ -27,7 +24,7 @@ namespace StardewModdingAPI.Events { add { - LocationEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); LocationEvents.EventManager.Legacy_LocationsChanged.Add(value); } remove => LocationEvents.EventManager.Legacy_LocationsChanged.Remove(value); @@ -38,7 +35,7 @@ namespace StardewModdingAPI.Events { add { - LocationEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); LocationEvents.EventManager.Legacy_BuildingsChanged.Add(value); } remove => LocationEvents.EventManager.Legacy_BuildingsChanged.Remove(value); @@ -49,7 +46,7 @@ namespace StardewModdingAPI.Events { add { - LocationEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); LocationEvents.EventManager.Legacy_ObjectsChanged.Add(value); } remove => LocationEvents.EventManager.Legacy_ObjectsChanged.Remove(value); @@ -61,11 +58,9 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - /// Manages deprecation warnings. - internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) + internal static void Init(EventManager eventManager) { LocationEvents.EventManager = eventManager; - LocationEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/MenuEvents.cs b/src/SMAPI/Events/MenuEvents.cs index e36cb498..914948dd 100644 --- a/src/SMAPI/Events/MenuEvents.cs +++ b/src/SMAPI/Events/MenuEvents.cs @@ -15,9 +15,6 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; - /// Manages deprecation warnings. - private static DeprecationManager DeprecationManager; - /********* ** Events @@ -27,7 +24,7 @@ namespace StardewModdingAPI.Events { add { - MenuEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); MenuEvents.EventManager.Legacy_MenuChanged.Add(value); } remove => MenuEvents.EventManager.Legacy_MenuChanged.Remove(value); @@ -38,7 +35,7 @@ namespace StardewModdingAPI.Events { add { - MenuEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); MenuEvents.EventManager.Legacy_MenuClosed.Add(value); } remove => MenuEvents.EventManager.Legacy_MenuClosed.Remove(value); @@ -50,11 +47,9 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - /// Manages deprecation warnings. - internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) + internal static void Init(EventManager eventManager) { MenuEvents.EventManager = eventManager; - MenuEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/MineEvents.cs b/src/SMAPI/Events/MineEvents.cs index 954c844a..fd35237e 100644 --- a/src/SMAPI/Events/MineEvents.cs +++ b/src/SMAPI/Events/MineEvents.cs @@ -15,9 +15,6 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; - /// Manages deprecation warnings. - private static DeprecationManager DeprecationManager; - /********* ** Events @@ -27,7 +24,7 @@ namespace StardewModdingAPI.Events { add { - MineEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); MineEvents.EventManager.Legacy_MineLevelChanged.Add(value); } remove => MineEvents.EventManager.Legacy_MineLevelChanged.Remove(value); @@ -39,11 +36,9 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - /// Manages deprecation warnings. - internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) + internal static void Init(EventManager eventManager) { MineEvents.EventManager = eventManager; - MineEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/MultiplayerEvents.cs b/src/SMAPI/Events/MultiplayerEvents.cs index 7e8328a4..5e6a22dc 100644 --- a/src/SMAPI/Events/MultiplayerEvents.cs +++ b/src/SMAPI/Events/MultiplayerEvents.cs @@ -15,9 +15,6 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; - /// Manages deprecation warnings. - private static DeprecationManager DeprecationManager; - /********* ** Events @@ -27,7 +24,7 @@ namespace StardewModdingAPI.Events { add { - MultiplayerEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); MultiplayerEvents.EventManager.Legacy_BeforeMainSync.Add(value); } remove => MultiplayerEvents.EventManager.Legacy_BeforeMainSync.Remove(value); @@ -38,7 +35,7 @@ namespace StardewModdingAPI.Events { add { - MultiplayerEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); MultiplayerEvents.EventManager.Legacy_AfterMainSync.Add(value); } remove => MultiplayerEvents.EventManager.Legacy_AfterMainSync.Remove(value); @@ -49,7 +46,7 @@ namespace StardewModdingAPI.Events { add { - MultiplayerEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); MultiplayerEvents.EventManager.Legacy_BeforeMainBroadcast.Add(value); } remove => MultiplayerEvents.EventManager.Legacy_BeforeMainBroadcast.Remove(value); @@ -60,7 +57,7 @@ namespace StardewModdingAPI.Events { add { - MultiplayerEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); MultiplayerEvents.EventManager.Legacy_AfterMainBroadcast.Add(value); } remove => MultiplayerEvents.EventManager.Legacy_AfterMainBroadcast.Remove(value); @@ -72,11 +69,9 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - /// Manages deprecation warnings. - internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) + internal static void Init(EventManager eventManager) { MultiplayerEvents.EventManager = eventManager; - MultiplayerEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/PlayerEvents.cs b/src/SMAPI/Events/PlayerEvents.cs index 1193675f..98bc3da5 100644 --- a/src/SMAPI/Events/PlayerEvents.cs +++ b/src/SMAPI/Events/PlayerEvents.cs @@ -15,9 +15,6 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; - /// Manages deprecation warnings. - private static DeprecationManager DeprecationManager; - /********* ** Events @@ -27,7 +24,7 @@ namespace StardewModdingAPI.Events { add { - PlayerEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); PlayerEvents.EventManager.Legacy_InventoryChanged.Add(value); } remove => PlayerEvents.EventManager.Legacy_InventoryChanged.Remove(value); @@ -38,7 +35,7 @@ namespace StardewModdingAPI.Events { add { - PlayerEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); PlayerEvents.EventManager.Legacy_LeveledUp.Add(value); } remove => PlayerEvents.EventManager.Legacy_LeveledUp.Remove(value); @@ -49,7 +46,7 @@ namespace StardewModdingAPI.Events { add { - PlayerEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); PlayerEvents.EventManager.Legacy_PlayerWarped.Add(value); } remove => PlayerEvents.EventManager.Legacy_PlayerWarped.Remove(value); @@ -62,11 +59,9 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - /// Manages deprecation warnings. - internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) + internal static void Init(EventManager eventManager) { PlayerEvents.EventManager = eventManager; - PlayerEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/SaveEvents.cs b/src/SMAPI/Events/SaveEvents.cs index 156d3047..959fb5d2 100644 --- a/src/SMAPI/Events/SaveEvents.cs +++ b/src/SMAPI/Events/SaveEvents.cs @@ -15,9 +15,6 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; - /// Manages deprecation warnings. - private static DeprecationManager DeprecationManager; - /********* ** Events @@ -27,7 +24,7 @@ namespace StardewModdingAPI.Events { add { - SaveEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); SaveEvents.EventManager.Legacy_BeforeCreateSave.Add(value); } remove => SaveEvents.EventManager.Legacy_BeforeCreateSave.Remove(value); @@ -38,7 +35,7 @@ namespace StardewModdingAPI.Events { add { - SaveEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); SaveEvents.EventManager.Legacy_AfterCreateSave.Add(value); } remove => SaveEvents.EventManager.Legacy_AfterCreateSave.Remove(value); @@ -49,7 +46,7 @@ namespace StardewModdingAPI.Events { add { - SaveEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); SaveEvents.EventManager.Legacy_BeforeSave.Add(value); } remove => SaveEvents.EventManager.Legacy_BeforeSave.Remove(value); @@ -60,7 +57,7 @@ namespace StardewModdingAPI.Events { add { - SaveEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); SaveEvents.EventManager.Legacy_AfterSave.Add(value); } remove => SaveEvents.EventManager.Legacy_AfterSave.Remove(value); @@ -71,7 +68,7 @@ namespace StardewModdingAPI.Events { add { - SaveEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); SaveEvents.EventManager.Legacy_AfterLoad.Add(value); } remove => SaveEvents.EventManager.Legacy_AfterLoad.Remove(value); @@ -82,7 +79,7 @@ namespace StardewModdingAPI.Events { add { - SaveEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); SaveEvents.EventManager.Legacy_AfterReturnToTitle.Add(value); } remove => SaveEvents.EventManager.Legacy_AfterReturnToTitle.Remove(value); @@ -94,11 +91,9 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - /// Manages deprecation warnings. - internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) + internal static void Init(EventManager eventManager) { SaveEvents.EventManager = eventManager; - SaveEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/SpecialisedEvents.cs b/src/SMAPI/Events/SpecialisedEvents.cs index 0dd726e9..2c6d0230 100644 --- a/src/SMAPI/Events/SpecialisedEvents.cs +++ b/src/SMAPI/Events/SpecialisedEvents.cs @@ -15,9 +15,6 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; - /// Manages deprecation warnings. - private static DeprecationManager DeprecationManager; - /********* ** Events @@ -27,7 +24,7 @@ namespace StardewModdingAPI.Events { add { - SpecialisedEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); SpecialisedEvents.EventManager.Legacy_UnvalidatedUpdateTick.Add(value); } remove => SpecialisedEvents.EventManager.Legacy_UnvalidatedUpdateTick.Remove(value); @@ -39,11 +36,9 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - /// Manages deprecation warnings. - internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) + internal static void Init(EventManager eventManager) { SpecialisedEvents.EventManager = eventManager; - SpecialisedEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/TimeEvents.cs b/src/SMAPI/Events/TimeEvents.cs index 61491dc8..40892491 100644 --- a/src/SMAPI/Events/TimeEvents.cs +++ b/src/SMAPI/Events/TimeEvents.cs @@ -15,9 +15,6 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; - /// Manages deprecation warnings. - private static DeprecationManager DeprecationManager; - /********* ** Events @@ -27,7 +24,7 @@ namespace StardewModdingAPI.Events { add { - TimeEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); TimeEvents.EventManager.Legacy_AfterDayStarted.Add(value); } remove => TimeEvents.EventManager.Legacy_AfterDayStarted.Remove(value); @@ -38,7 +35,7 @@ namespace StardewModdingAPI.Events { add { - TimeEvents.DeprecationManager.WarnForOldEvents(); + SCore.DeprecationManager.WarnForOldEvents(); TimeEvents.EventManager.Legacy_TimeOfDayChanged.Add(value); } remove => TimeEvents.EventManager.Legacy_TimeOfDayChanged.Remove(value); @@ -50,11 +47,9 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - /// Manages deprecation warnings. - internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) + internal static void Init(EventManager eventManager) { TimeEvents.EventManager = eventManager; - TimeEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Framework/ModHelpers/ModHelper.cs b/src/SMAPI/Framework/ModHelpers/ModHelper.cs index 0dbc5fd7..ca872e32 100644 --- a/src/SMAPI/Framework/ModHelpers/ModHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ModHelper.cs @@ -12,15 +12,6 @@ namespace StardewModdingAPI.Framework.ModHelpers /// Provides simplified APIs for writing mods. internal class ModHelper : BaseHelper, IModHelper, IDisposable { - /********* - ** Properties - *********/ -#if !SMAPI_3_0_STRICT - /// Manages deprecation warnings. - private readonly DeprecationManager DeprecationManager; -#endif - - /********* ** Accessors *********/ @@ -80,10 +71,9 @@ namespace StardewModdingAPI.Framework.ModHelpers /// An API for accessing private game code. /// Provides multiplayer utilities. /// An API for reading translations stored in the mod's i18n folder. - /// Manages deprecation warnings. /// An argument is null or empty. /// The path does not exist on disk. - public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, SInputState inputState, IModEvents events, IContentHelper contentHelper, IContentPackHelper contentPackHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper, DeprecationManager deprecationManager) + public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, SInputState inputState, IModEvents events, IContentHelper contentHelper, IContentPackHelper contentPackHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper) : base(modID) { // validate directory @@ -106,7 +96,6 @@ namespace StardewModdingAPI.Framework.ModHelpers this.Events = events; #if !SMAPI_3_0_STRICT this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper)); - this.DeprecationManager = deprecationManager; #endif } @@ -177,8 +166,8 @@ namespace StardewModdingAPI.Framework.ModHelpers [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.CreateTemporary) + " 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.ContentPacks.CreateFake(directoryPath, id, name, description, author, version); + SCore.DeprecationManager.Warn($"{nameof(IModHelper)}.{nameof(IModHelper.CreateTransitionalContentPack)}", "2.5", DeprecationLevel.Notice); + return this.ContentPacks.CreateTemporary(directoryPath, id, name, description, author, version); } /// Get all content packs loaded for this mod. diff --git a/src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs b/src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs index 648d6742..cfe2ddbe 100644 --- a/src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs @@ -17,9 +17,6 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The mod name for error messages. private readonly string ModName; - /// Manages deprecation warnings. - private readonly DeprecationManager DeprecationManager; - /********* ** Public methods @@ -28,13 +25,11 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The unique ID of the relevant mod. /// The mod name for error messages. /// The underlying reflection helper. - /// Manages deprecation warnings. - public ReflectionHelper(string modID, string modName, Reflector reflector, DeprecationManager deprecationManager) + public ReflectionHelper(string modID, string modName, Reflector reflector) : base(modID) { this.ModName = modName; this.Reflector = reflector; - this.DeprecationManager = deprecationManager; } /// Get an instance field. diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 76b091d0..3749bab4 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -75,10 +75,6 @@ namespace StardewModdingAPI.Framework /// This is initialised after the game starts. private readonly ModRegistry ModRegistry = new ModRegistry(); - /// Manages deprecation warnings. - /// This is initialised after the game starts. - private readonly DeprecationManager DeprecationManager; - /// Manages SMAPI events for mods. private readonly EventManager EventManager; @@ -120,6 +116,14 @@ namespace StardewModdingAPI.Framework private string ModsPath => Constants.ModsPath; + /********* + ** Accessors + *********/ + /// Manages deprecation warnings. + /// This is initialised after the game starts. This is accessed directly because it's not part of the normal class model. + internal static DeprecationManager DeprecationManager { get; private set; } + + /********* ** Public methods *********/ @@ -148,15 +152,12 @@ namespace StardewModdingAPI.Framework }; this.MonitorForGame = this.GetSecondaryMonitor("game"); this.EventManager = new EventManager(this.Monitor, this.ModRegistry); - this.DeprecationManager = new DeprecationManager(this.Monitor, this.ModRegistry); + SCore.DeprecationManager = new DeprecationManager(this.Monitor, this.ModRegistry); // redirect direct console output if (this.MonitorForGame.WriteToConsole) this.ConsoleManager.OnMessageIntercepted += message => this.HandleConsoleMessage(this.MonitorForGame, message); - // inject deprecation managers - SemanticVersion.DeprecationManager = this.DeprecationManager; - // init logging this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {EnvironmentUtility.GetFriendlyPlatformName(Constants.Platform)}", LogLevel.Info); this.Monitor.Log($"Mods go here: {modsPath}"); @@ -196,19 +197,19 @@ namespace StardewModdingAPI.Framework { #if !SMAPI_3_0_STRICT // hook up events - ContentEvents.Init(this.EventManager, this.DeprecationManager); - ControlEvents.Init(this.EventManager, this.DeprecationManager); - GameEvents.Init(this.EventManager, this.DeprecationManager); - GraphicsEvents.Init(this.EventManager, this.DeprecationManager); - InputEvents.Init(this.EventManager, this.DeprecationManager); - LocationEvents.Init(this.EventManager, this.DeprecationManager); - MenuEvents.Init(this.EventManager, this.DeprecationManager); - MineEvents.Init(this.EventManager, this.DeprecationManager); - MultiplayerEvents.Init(this.EventManager, this.DeprecationManager); - PlayerEvents.Init(this.EventManager, this.DeprecationManager); - SaveEvents.Init(this.EventManager, this.DeprecationManager); - SpecialisedEvents.Init(this.EventManager, this.DeprecationManager); - TimeEvents.Init(this.EventManager, this.DeprecationManager); + ContentEvents.Init(this.EventManager); + ControlEvents.Init(this.EventManager); + GameEvents.Init(this.EventManager); + GraphicsEvents.Init(this.EventManager); + InputEvents.Init(this.EventManager); + LocationEvents.Init(this.EventManager); + MenuEvents.Init(this.EventManager); + MineEvents.Init(this.EventManager); + MultiplayerEvents.Init(this.EventManager); + PlayerEvents.Init(this.EventManager); + SaveEvents.Init(this.EventManager); + SpecialisedEvents.Init(this.EventManager); + TimeEvents.Init(this.EventManager); #endif // init JSON parser @@ -232,7 +233,7 @@ namespace StardewModdingAPI.Framework // override game SGame.ConstructorHack = new SGameConstructorHack(this.Monitor, this.Reflection, this.Toolkit.JsonHelper); - this.GameInstance = new SGame(this.Monitor, this.MonitorForGame, this.Reflection, this.EventManager, this.Toolkit.JsonHelper, this.ModRegistry, this.DeprecationManager, this.OnLocaleChanged, this.InitialiseAfterGameStart, this.Dispose); + this.GameInstance = new SGame(this.Monitor, this.MonitorForGame, this.Reflection, this.EventManager, this.Toolkit.JsonHelper, this.ModRegistry, SCore.DeprecationManager, this.OnLocaleChanged, this.InitialiseAfterGameStart, this.Dispose); StardewValley.Program.gamePtr = this.GameInstance; // add exit handler @@ -920,7 +921,7 @@ namespace StardewModdingAPI.Framework // add deprecation warning for old version format { if (mod.Manifest?.Version is Toolkit.SemanticVersion version && version.IsLegacyFormat) - this.DeprecationManager.Warn(mod.DisplayName, "non-string manifest version", "2.8", DeprecationLevel.Notice); + SCore.DeprecationManager.Warn(mod.DisplayName, "non-string manifest version", "2.8", DeprecationLevel.Notice); } #endif @@ -1016,7 +1017,7 @@ namespace StardewModdingAPI.Framework IContentHelper contentHelper = new ContentHelper(contentCore, mod.DirectoryPath, manifest.UniqueID, mod.DisplayName, monitor); IContentPackHelper contentPackHelper = new ContentPackHelper(manifest.UniqueID, new Lazy(GetContentPacks), CreateFakeContentPack); IDataHelper dataHelper = new DataHelper(manifest.UniqueID, mod.DirectoryPath, jsonHelper); - IReflectionHelper reflectionHelper = new ReflectionHelper(manifest.UniqueID, mod.DisplayName, this.Reflection, this.DeprecationManager); + IReflectionHelper reflectionHelper = new ReflectionHelper(manifest.UniqueID, mod.DisplayName, this.Reflection); IModRegistry modRegistryHelper = new ModRegistryHelper(manifest.UniqueID, this.ModRegistry, proxyFactory, monitor); IMultiplayerHelper multiplayerHelper = new MultiplayerHelper(manifest.UniqueID, this.GameInstance.Multiplayer); ITranslationHelper translationHelper = new TranslationHelper(manifest.UniqueID, manifest.Name, contentCore.GetLocale(), contentCore.Language); @@ -1028,7 +1029,7 @@ namespace StardewModdingAPI.Framework return new ContentPack(packDirPath, packManifest, packContentHelper, this.Toolkit.JsonHelper); } - modHelper = new ModHelper(manifest.UniqueID, mod.DirectoryPath, this.Toolkit.JsonHelper, this.GameInstance.Input, events, contentHelper, contentPackHelper, commandHelper, dataHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper, this.DeprecationManager); + modHelper = new ModHelper(manifest.UniqueID, mod.DirectoryPath, this.Toolkit.JsonHelper, this.GameInstance.Input, events, contentHelper, contentPackHelper, commandHelper, dataHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper); } // init mod diff --git a/src/SMAPI/SemanticVersion.cs b/src/SMAPI/SemanticVersion.cs index f75105df..4fc6c219 100644 --- a/src/SMAPI/SemanticVersion.cs +++ b/src/SMAPI/SemanticVersion.cs @@ -13,9 +13,6 @@ namespace StardewModdingAPI /// The underlying semantic version implementation. private readonly ISemanticVersion Version; - /// Manages deprecation warnings. - internal static DeprecationManager DeprecationManager { get; set; } - /********* ** Accessors @@ -36,7 +33,7 @@ namespace StardewModdingAPI { get { - SemanticVersion.DeprecationManager?.Warn($"{nameof(ISemanticVersion)}.{nameof(ISemanticVersion.Build)}", "2.8", DeprecationLevel.Notice); + SCore.DeprecationManager?.Warn($"{nameof(ISemanticVersion)}.{nameof(ISemanticVersion.Build)}", "2.8", DeprecationLevel.Notice); return this.Version.PrereleaseTag; } } -- cgit From fd47e992dbdbf4298fd9130b8ef9bfcf52fcab19 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 13 Dec 2018 02:01:23 -0500 Subject: deprecate assetData.AsDictionary().Set --- docs/release-notes.md | 2 ++ src/SMAPI/Framework/Content/AssetDataForDictionary.cs | 8 ++++++++ src/SMAPI/IAssetDataForDictionary.cs | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/docs/release-notes.md b/docs/release-notes.md index de0bdf71..e51ff0a5 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -7,6 +7,8 @@ * For modders: * Added dedicated content pack API. + * **Deprecations:** + * The `assetData.AsDictionary().Set` methods are deprecated and will be removed in SMAPI 3.0. Mods should access the `Data` property directly instead. ## 2.9.1 * For players: diff --git a/src/SMAPI/Framework/Content/AssetDataForDictionary.cs b/src/SMAPI/Framework/Content/AssetDataForDictionary.cs index 7b80875f..9bd70711 100644 --- a/src/SMAPI/Framework/Content/AssetDataForDictionary.cs +++ b/src/SMAPI/Framework/Content/AssetDataForDictionary.cs @@ -19,28 +19,36 @@ namespace StardewModdingAPI.Framework.Content public AssetDataForDictionary(string locale, string assetName, IDictionary data, Func getNormalisedPath, Action> onDataReplaced) : base(locale, assetName, data, getNormalisedPath, onDataReplaced) { } +#if !SMAPI_3_0_STRICT /// Add or replace an entry in the dictionary. /// The entry key. /// The entry value. + [Obsolete("Access " + nameof(AssetData>.Data) + "field directly.")] public void Set(TKey key, TValue value) { + SCore.DeprecationManager.Warn($"AssetDataForDictionary.{nameof(Set)}", "2.10", DeprecationLevel.Notice); this.Data[key] = value; } /// Add or replace an entry in the dictionary. /// The entry key. /// A callback which accepts the current value and returns the new value. + [Obsolete("Access " + nameof(AssetData>.Data) + "field directly.")] public void Set(TKey key, Func value) { + SCore.DeprecationManager.Warn($"AssetDataForDictionary.{nameof(Set)}", "2.10", DeprecationLevel.Notice); this.Data[key] = value(this.Data[key]); } /// Dynamically replace values in the dictionary. /// A lambda which takes the current key and value for an entry, and returns the new value. + [Obsolete("Access " + nameof(AssetData>.Data) + "field directly.")] public void Set(Func replacer) { + SCore.DeprecationManager.Warn($"AssetDataForDictionary.{nameof(Set)}", "2.10", DeprecationLevel.Notice); foreach (var pair in this.Data.ToArray()) this.Data[pair.Key] = replacer(pair.Key, pair.Value); } +#endif } } diff --git a/src/SMAPI/IAssetDataForDictionary.cs b/src/SMAPI/IAssetDataForDictionary.cs index 53c24346..911599d9 100644 --- a/src/SMAPI/IAssetDataForDictionary.cs +++ b/src/SMAPI/IAssetDataForDictionary.cs @@ -1,26 +1,32 @@ -using System; +using System; using System.Collections.Generic; +using StardewModdingAPI.Framework.Content; namespace StardewModdingAPI { /// Encapsulates access and changes to dictionary content being read from a data file. public interface IAssetDataForDictionary : IAssetData> { +#if !SMAPI_3_0_STRICT /********* ** Public methods *********/ /// Add or replace an entry in the dictionary. /// The entry key. /// The entry value. + [Obsolete("Access " + nameof(AssetData>.Data) + "field directly.")] void Set(TKey key, TValue value); /// Add or replace an entry in the dictionary. /// The entry key. /// A callback which accepts the current value and returns the new value. + [Obsolete("Access " + nameof(AssetData>.Data) + "field directly.")] void Set(TKey key, Func value); /// Dynamically replace values in the dictionary. /// A lambda which takes the current key and value for an entry, and returns the new value. + [Obsolete("Access " + nameof(AssetData>.Data) + "field directly.")] void Set(Func replacer); +#endif } } -- cgit From 95b1dedb667d1fe2fd9ee89ece342bacbdd3be48 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 13 Dec 2018 02:11:06 -0500 Subject: clarify docblock --- src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs | 2 +- src/SMAPI/IContentPackHelper.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs index 4bd28b36..26c4648c 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs @@ -38,7 +38,7 @@ namespace StardewModdingAPI.Framework.ModHelpers return this.ContentPacks.Value; } - /// Create a temporary content pack to read files from a directory. This will generate fake manifest data; any manifest.json in the directory will be ignored. Temporary content packs will not appear in the SMAPI log and update checks will not be performed. + /// Create a temporary content pack to read files from a directory, using randomised manifest fields. This will generate fake manifest data; any manifest.json in the directory will be ignored. 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. public IContentPack CreateFake(string directoryPath) { diff --git a/src/SMAPI/IContentPackHelper.cs b/src/SMAPI/IContentPackHelper.cs index 6cce964c..e4949f58 100644 --- a/src/SMAPI/IContentPackHelper.cs +++ b/src/SMAPI/IContentPackHelper.cs @@ -11,7 +11,7 @@ namespace StardewModdingAPI /// Get all content packs loaded for this mod. IEnumerable GetOwned(); - /// 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. + /// Create a temporary content pack to read files from a directory, using randomised manifest fields. 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. IContentPack CreateFake(string directoryPath); -- cgit From 8eee91c67db0f09e9c604c7b4a2809e5bc937258 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 14 Dec 2018 00:23:48 -0500 Subject: fix game launch error logged as 'SMAPI' --- docs/release-notes.md | 1 + src/SMAPI/Framework/SCore.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/docs/release-notes.md b/docs/release-notes.md index e51ff0a5..9df18098 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -4,6 +4,7 @@ * Fixed error when a mod makes invalid changes to an NPC schedule. * Fixed invalid NPC data propagated when a mod changes NPC dispositions. * Fixed `Display.RenderedWorld` event broken in SMAPI 2.9.1. + * Fixed game launch crash logged as `SMAPI` instead of `game`. * For modders: * Added dedicated content pack API. diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 3749bab4..e43d3f8b 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -315,7 +315,7 @@ namespace StardewModdingAPI.Framework } catch (Exception ex) { - this.Monitor.Log($"The game failed unexpectedly: {ex.GetLogSummary()}", LogLevel.Error); + this.MonitorForGame.Log($"The game failed to launch: {ex.GetLogSummary()}", LogLevel.Error); this.PressAnyKeyToExit(); } finally -- cgit From 0d26285da12156c6304c1ff4458bd0b62e6e8dca Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 14 Dec 2018 00:42:00 -0500 Subject: add friendly error when the game can't find its Content\XACT folder --- docs/release-notes.md | 1 + src/SMAPI.Web/Startup.cs | 1 + src/SMAPI/Framework/SCore.cs | 6 ++++++ 3 files changed, 8 insertions(+) (limited to 'src') diff --git a/docs/release-notes.md b/docs/release-notes.md index 9df18098..c3b11d7f 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,6 +1,7 @@ # Release notes ## Upcoming release * For players: + * Fixed cryptic error message when the game isn't installed correctly. * Fixed error when a mod makes invalid changes to an NPC schedule. * Fixed invalid NPC data propagated when a mod changes NPC dispositions. * Fixed `Display.RenderedWorld` event broken in SMAPI 2.9.1. diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index 0bd71d26..4e3aaed3 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -165,6 +165,7 @@ namespace StardewModdingAPI.Web redirects.Add(new RedirectToUrlRule(@"^/3\.0\.?$", "https://stardewvalleywiki.com/Modding:Migrate_to_SMAPI_3.0")); redirects.Add(new RedirectToUrlRule(@"^/docs\.?$", "https://stardewvalleywiki.com/Modding:Index")); redirects.Add(new RedirectToUrlRule(@"^/install\.?$", "https://stardewvalleywiki.com/Modding:Player_Guide/Getting_Started#Install_SMAPI")); + redirects.Add(new RedirectToUrlRule(@"^/troubleshoot(.*)$", "https://stardewvalleywiki.com/Modding:Player_Guide/Troubleshooting$1")); // redirect legacy canimod.com URLs var wikiRedirects = new Dictionary diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index e43d3f8b..3bc0aca4 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -313,6 +313,12 @@ namespace StardewModdingAPI.Framework this.Monitor.Log($"Technical details: {ex.GetLogSummary()}", LogLevel.Trace); this.PressAnyKeyToExit(); } + catch (FileNotFoundException ex) when (ex.Message == "Could not find file 'C:\\Program Files (x86)\\Steam\\SteamApps\\common\\Stardew Valley\\Content\\XACT\\FarmerSounds.xgs'.") // path in error is hardcoded regardless of install path + { + this.Monitor.Log("The game can't find its Content\\XACT\\FarmerSounds.xgs file. You can usually fix this by resetting your content files (see https://smapi.io/troubleshoot#reset-content ), or by uninstalling and reinstalling the game.", LogLevel.Error); + this.Monitor.Log($"Technical details: {ex.GetLogSummary()}", LogLevel.Trace); + this.PressAnyKeyToExit(); + } catch (Exception ex) { this.MonitorForGame.Log($"The game failed to launch: {ex.GetLogSummary()}", LogLevel.Error); -- cgit From c6135e0759fc0f50c873b0278f006aeb7e67e712 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 14 Dec 2018 18:58:06 -0500 Subject: clarify trace message --- src/SMAPI/Framework/ContentManagers/GameContentManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs index 4f3b6fbc..81732d3f 100644 --- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs @@ -238,7 +238,7 @@ namespace StardewModdingAPI.Framework.ContentManagers try { editor.Edit(asset); - this.Monitor.Log($"{mod.DisplayName} intercepted {info.AssetName}.", LogLevel.Trace); + this.Monitor.Log($"{mod.DisplayName} edited {info.AssetName}.", LogLevel.Trace); } catch (Exception ex) { -- cgit From 5f620e14fa331b0721bd4044011363477dc79ef5 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 15 Dec 2018 00:18:51 -0500 Subject: add SMAPI 3.0 readiness to API data (#606) --- docs/release-notes.md | 3 ++ src/SMAPI.Web/ViewModels/ModModel.cs | 8 ++++++ src/SMAPI.Web/Views/Mods/Index.cshtml | 14 ++++++++- src/SMAPI.Web/wwwroot/Content/js/mods.js | 33 +++++++++++++++++++++- .../Clients/WebApi/ModExtendedMetadataModel.cs | 12 ++++++++ .../Framework/Clients/Wiki/WikiClient.cs | 21 +++++++++----- .../Framework/Clients/Wiki/WikiModEntry.cs | 6 ++++ .../Framework/Clients/Wiki/WikiSmapi3Status.cs | 18 ++++++++++++ 8 files changed, 106 insertions(+), 9 deletions(-) create mode 100644 src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiSmapi3Status.cs (limited to 'src') diff --git a/docs/release-notes.md b/docs/release-notes.md index 0e426bfd..fa7f4109 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -13,6 +13,9 @@ * **Deprecations:** * The `assetData.AsDictionary().Set` methods are deprecated and will be removed in SMAPI 3.0. Mods should access the `Data` property directly instead. +* FOR SMAPI developers: + * Added SMAPI 3.0 readiness to mod API data. + ## 2.9.1 * For players: * Fixed crash in SMAPI 2.9 when constructing certain buildings. diff --git a/src/SMAPI.Web/ViewModels/ModModel.cs b/src/SMAPI.Web/ViewModels/ModModel.cs index 5c1840fc..f1a52f98 100644 --- a/src/SMAPI.Web/ViewModels/ModModel.cs +++ b/src/SMAPI.Web/ViewModels/ModModel.cs @@ -31,6 +31,12 @@ namespace StardewModdingAPI.Web.ViewModels /// The compatibility status for the beta version of the game. public ModCompatibilityModel BetaCompatibility { get; set; } + /// Whether the mod is ready for the upcoming SMAPI 3.0. + public string Smapi3Status { get; set; } + + /// A URL related to the . + public string Smapi3Url { get; set; } + /// Links to the available mod pages. public ModLinkModel[] ModPages { get; set; } @@ -59,6 +65,8 @@ namespace StardewModdingAPI.Web.ViewModels this.SourceUrl = this.GetSourceUrl(entry); this.Compatibility = new ModCompatibilityModel(entry.Compatibility); this.BetaCompatibility = entry.BetaCompatibility != null ? new ModCompatibilityModel(entry.BetaCompatibility) : null; + this.Smapi3Status = entry.Smapi3Status.ToString().ToLower(); + this.Smapi3Url = entry.Smapi3Url; this.ModPages = this.GetModPageUrls(entry).ToArray(); this.Warnings = entry.Warnings; this.Slug = entry.Anchor; diff --git a/src/SMAPI.Web/Views/Mods/Index.cshtml b/src/SMAPI.Web/Views/Mods/Index.cshtml index a49a24d9..67034322 100644 --- a/src/SMAPI.Web/Views/Mods/Index.cshtml +++ b/src/SMAPI.Web/Views/Mods/Index.cshtml @@ -45,7 +45,10 @@
- {{visibleStats.total}} mods shown ({{Math.round((visibleStats.compatible + visibleStats.workaround) / visibleStats.total * 100)}}% compatible or have a workaround, {{Math.round((visibleStats.soon + visibleStats.broken) / visibleStats.total * 100)}}% broken, {{Math.round(visibleStats.abandoned / visibleStats.total * 100)}}% obsolete). +
+ {{visibleStats.total}} mods shown ({{Math.round((visibleStats.compatible + visibleStats.workaround) / visibleStats.total * 100)}}% compatible or have a workaround, {{Math.round((visibleStats.soon + visibleStats.broken) / visibleStats.total * 100)}}% broken, {{Math.round(visibleStats.abandoned / visibleStats.total * 100)}}% obsolete).
+ SMAPI 3.0 (upcoming): {{Math.round(visibleStats.smapi3_ok / visibleStats.total * 100)}}% ready, {{Math.round(visibleStats.smapi3_soon / visibleStats.total * 100)}}% soon, {{Math.round(visibleStats.smapi3_broken / visibleStats.total * 100)}}% broken, {{Math.round(visibleStats.smapi3_unknown / visibleStats.total * 100)}}% unknown. +
No matching mods found.
@@ -57,6 +60,7 @@ + @@ -88,6 +92,14 @@ sourceno source + diff --git a/src/SMAPI.Web/wwwroot/Content/js/mods.js b/src/SMAPI.Web/wwwroot/Content/js/mods.js index f7a8501e..23c7aa7e 100644 --- a/src/SMAPI.Web/wwwroot/Content/js/mods.js +++ b/src/SMAPI.Web/wwwroot/Content/js/mods.js @@ -11,7 +11,11 @@ smapi.modList = function (mods) { soon: 0, broken: 0, abandoned: 0, - invalid: 0 + invalid: 0, + smapi3_unknown: 0, + smapi3_ok: 0, + smapi3_broken: 0, + smapi3_soon: 0 }; var data = { mods: mods, @@ -88,6 +92,28 @@ smapi.modList = function (mods) { id: "show-custom", value: true } + }, + "SMAPI 3.0": { + ok: { + label: "ready", + id: "show-smapi-3-ready", + value: true + }, + soon: { + label: "soon", + id: "show-smapi-3-soon", + value: true + }, + broken: { + label: "broken", + id: "show-smapi-3-broken", + value: true + }, + unknown: { + label: "unknown", + id: "show-smapi-3-unknown", + value: true + } } }, search: "" @@ -154,6 +180,7 @@ smapi.modList = function (mods) { if (mod.Visible) { stats.total++; stats[this.getCompatibilityGroup(mod)]++; + stats["smapi3_" + mod.Smapi3Status]++; } } }, @@ -179,6 +206,10 @@ smapi.modList = function (mods) { if (filters.status[status] && !filters.status[status].value) return false; + // check SMAPI 3.0 compatibility + if (filters["SMAPI 3.0"][mod.Smapi3Status] && !filters["SMAPI 3.0"][mod.Smapi3Status].value) + return false; + // check download sites var ignoreSites = []; diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModExtendedMetadataModel.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModExtendedMetadataModel.cs index c9d9f916..45b46ea6 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModExtendedMetadataModel.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModExtendedMetadataModel.cs @@ -40,6 +40,15 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi /// The custom mod page URL (if applicable). public string CustomUrl { get; set; } + /**** + ** SMAPI 3.0 readiness + ****/ + /// Whether the mod is ready for the upcoming SMAPI 3.0. + public WikiSmapi3Status Smapi3Status { get; set; } + + /// A URL related to the . + public string Smapi3Url { get; set; } + /**** ** Stable compatibility ****/ @@ -85,6 +94,9 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi this.CustomSourceUrl = wiki.CustomSourceUrl; this.CustomUrl = wiki.CustomUrl; + this.Smapi3Status = wiki.Smapi3Status; + this.Smapi3Url = wiki.Smapi3Url; + this.CompatibilityStatus = wiki.Compatibility.Status; this.CompatibilitySummary = wiki.Compatibility.Summary; diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs index 91078b08..19a4292f 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs @@ -102,7 +102,7 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki // parse stable compatibility WikiCompatibilityInfo compatibility = new WikiCompatibilityInfo { - Status = this.GetAttributeAsStatus(node, "data-status") ?? WikiCompatibilityStatus.Ok, + Status = this.GetAttributeAsEnum(node, "data-status") ?? WikiCompatibilityStatus.Ok, BrokeIn = this.GetAttribute(node, "data-broke-in"), UnofficialVersion = this.GetAttributeAsSemanticVersion(node, "data-unofficial-version"), UnofficialUrl = this.GetAttribute(node, "data-unofficial-url"), @@ -112,7 +112,7 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki // parse beta compatibility WikiCompatibilityInfo betaCompatibility = null; { - WikiCompatibilityStatus? betaStatus = this.GetAttributeAsStatus(node, "data-beta-status"); + WikiCompatibilityStatus? betaStatus = this.GetAttributeAsEnum(node, "data-beta-status"); if (betaStatus.HasValue) { betaCompatibility = new WikiCompatibilityInfo @@ -126,6 +126,10 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki } } + // parse SMAPI 3.0 readiness status + WikiSmapi3Status smapi3Status = this.GetAttributeAsEnum(node, "data-smapi-3-status") ?? WikiSmapi3Status.Unknown; + string smapi3Url = this.GetAttribute(node, "data-smapi-3-url"); + // yield model yield return new WikiModEntry { @@ -140,6 +144,8 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki CustomUrl = customUrl, Compatibility = compatibility, BetaCompatibility = betaCompatibility, + Smapi3Status = smapi3Status, + Smapi3Url = smapi3Url, Warnings = warnings, Anchor = anchor }; @@ -169,17 +175,18 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki : new string[0]; } - /// Get an attribute value and parse it as a compatibility status. + /// Get an attribute value and parse it as an enum value. + /// The enum type. /// The element whose attributes to read. /// The attribute name. - private WikiCompatibilityStatus? GetAttributeAsStatus(HtmlNode element, string name) + private TEnum? GetAttributeAsEnum(HtmlNode element, string name) where TEnum : struct { string raw = this.GetAttribute(element, name); if (raw == null) return null; - if (!Enum.TryParse(raw, true, out WikiCompatibilityStatus status)) - throw new InvalidOperationException($"Unknown status '{raw}' when parsing compatibility list."); - return status; + if (!Enum.TryParse(raw, true, out TEnum value) && Enum.IsDefined(typeof(TEnum), value)) + throw new InvalidOperationException($"Unknown {typeof(TEnum).Name} value '{raw}' when parsing compatibility list."); + return value; } /// Get an attribute value and parse it as a semantic version. diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModEntry.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModEntry.cs index f7b7839b..b71269fe 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModEntry.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModEntry.cs @@ -39,6 +39,12 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki /// The mod's compatibility with the latest beta version of the game (if any). public WikiCompatibilityInfo BetaCompatibility { get; set; } + /// Whether the mod is ready for the upcoming SMAPI 3.0. + public WikiSmapi3Status Smapi3Status { get; set; } + + /// A URL related to the . + public string Smapi3Url { get; set; } + /// Whether a Stardew Valley or SMAPI beta which affects mod compatibility is in progress. If this is true, should be used for beta versions of SMAPI instead of . public bool HasBetaInfo => this.BetaCompatibility != null; diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiSmapi3Status.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiSmapi3Status.cs new file mode 100644 index 00000000..879cfd8a --- /dev/null +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiSmapi3Status.cs @@ -0,0 +1,18 @@ +namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki +{ + /// Whether a mod is ready for the upcoming SMAPI 3.0. + public enum WikiSmapi3Status + { + /// The mod's compatibility status is unknown. + Unknown = 0, + + /// The mod is compatible with the upcoming SMAPI 3.0. + Ok = 1, + + /// The mod will break in SMAPI 3.0. + Broken = 2, + + /// The mod has a pull request submitted for SMAPI 3.0 compatibility. + Soon = 3 + } +} -- cgit From 39341d772e99492f239ad8aff09cca8760ff5b83 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 15 Dec 2018 13:33:22 -0500 Subject: prevent invalid items from crashing the game --- docs/README.md | 6 ++-- docs/release-notes.md | 3 +- src/SMAPI/Framework/SCore.cs | 3 +- src/SMAPI/Patches/ObjectErrorPatch.cs | 55 +++++++++++++++++++++++++++++++++++ src/SMAPI/StardewModdingAPI.csproj | 1 + 5 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 src/SMAPI/Patches/ObjectErrorPatch.cs (limited to 'src') diff --git a/docs/README.md b/docs/README.md index b8e3b50b..e4220de2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ -**SMAPI** is an open-source modding API for [Stardew Valley](https://stardewvalley.net/) that lets -you play the game with mods. It's safely installed alongside the game's executable, and doesn't -change any of your game files. It serves eight main purposes: +**SMAPI** is an open-source modding framework and API for [Stardew Valley](https://stardewvalley.net/) +that lets you play the game with mods. It's safely installed alongside the game's executable, and +doesn't change any of your game files. It serves eight main purposes: 1. **Load mods into the game.** _SMAPI loads mods when the game is starting up so they can interact with it. (Code mods aren't diff --git a/docs/release-notes.md b/docs/release-notes.md index fa7f4109..bcbdee22 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,6 +1,7 @@ # Release notes ## Upcoming release * For players: + * SMAPI now prevents invalid items from crashing the game on hover. * Fixed cryptic error message when the game isn't installed correctly. * Fixed error when a mod makes invalid changes to an NPC schedule. * Fixed invalid NPC data propagated when a mod changes NPC dispositions. @@ -10,7 +11,7 @@ * For modders: * Added dedicated content pack API. - * **Deprecations:** + * **Deprecations:** * The `assetData.AsDictionary().Set` methods are deprecated and will be removed in SMAPI 3.0. Mods should access the `Data` property directly instead. * FOR SMAPI developers: diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 3bc0aca4..679838ba 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -184,7 +184,8 @@ namespace StardewModdingAPI.Framework // apply game patches new GamePatcher(this.Monitor).Apply( - new DialogueErrorPatch(this.MonitorForGame, this.Reflection) + new DialogueErrorPatch(this.MonitorForGame, this.Reflection), + new ObjectErrorPatch() ); } diff --git a/src/SMAPI/Patches/ObjectErrorPatch.cs b/src/SMAPI/Patches/ObjectErrorPatch.cs new file mode 100644 index 00000000..2cbb60c5 --- /dev/null +++ b/src/SMAPI/Patches/ObjectErrorPatch.cs @@ -0,0 +1,55 @@ +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using Harmony; +using StardewModdingAPI.Framework.Patching; +using StardewValley; +using SObject = StardewValley.Object; + +namespace StardewModdingAPI.Patches +{ + /// A Harmony patch for which intercepts crashes due to the item no longer existing. + internal class ObjectErrorPatch : IHarmonyPatch + { + /********* + ** Accessors + *********/ + /// A unique name for this patch. + public string Name => $"{nameof(ObjectErrorPatch)}"; + + + /********* + ** Public methods + *********/ + /// Apply the Harmony patch. + /// The Harmony instance. + public void Apply(HarmonyInstance harmony) + { + MethodInfo method = AccessTools.Method(typeof(SObject), nameof(SObject.getDescription)); + MethodInfo prefix = AccessTools.Method(this.GetType(), nameof(ObjectErrorPatch.Prefix)); + + harmony.Patch(method, new HarmonyMethod(prefix), null); + } + + + /********* + ** Private methods + *********/ + /// The method to call instead of . + /// The instance being patched. + /// The patched method's return value. + /// Returns whether to execute the original method. + /// This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments. + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument names are defined by Harmony.")] + private static bool Prefix(SObject __instance, ref string __result) + { + // invalid bigcraftables crash instead of showing '???' like invalid non-bigcraftables + if (!__instance.IsRecipe && __instance.bigCraftable.Value && !Game1.bigCraftablesInformation.ContainsKey(__instance.ParentSheetIndex)) + { + __result = "???"; + return false; + } + + return false; + } + } +} diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index 2c769f41..3f1a273d 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -326,6 +326,7 @@ + -- cgit From 0130416bd1d54f243252ebe00f78c185342ab9d3 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 15 Dec 2018 14:35:39 -0500 Subject: show SMAPI 3.0 readiness for unofficial updates too (#606) --- src/SMAPI.Web/Views/Mods/Index.cshtml | 6 +++--- src/SMAPI.Web/wwwroot/Content/js/mods.js | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/SMAPI.Web/Views/Mods/Index.cshtml b/src/SMAPI.Web/Views/Mods/Index.cshtml index 67034322..a6c94cf1 100644 --- a/src/SMAPI.Web/Views/Mods/Index.cshtml +++ b/src/SMAPI.Web/Views/Mods/Index.cshtml @@ -65,7 +65,7 @@ - + - +
compatibility broke in code3.0  
+ + #
{{mod.Name}} (aka {{mod.AlternateNames}}) @@ -87,13 +87,13 @@
⚠ {{warning}}
source no source -