From d70d449c5c99e68677e83c66bdaf300be6b71ee2 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 25 Feb 2018 01:07:32 -0500 Subject: fix issue where replacing an asset via asset.AsImage() or asset.AsDictionary() has no effect --- src/SMAPI/Framework/Content/AssetData.cs | 12 +++++++++++- src/SMAPI/Framework/Content/AssetDataForDictionary.cs | 5 +++-- src/SMAPI/Framework/Content/AssetDataForImage.cs | 5 +++-- src/SMAPI/Framework/Content/AssetDataForObject.cs | 8 ++++---- 4 files changed, 21 insertions(+), 9 deletions(-) (limited to 'src/SMAPI') diff --git a/src/SMAPI/Framework/Content/AssetData.cs b/src/SMAPI/Framework/Content/AssetData.cs index 1ab9eebd..0a86f54d 100644 --- a/src/SMAPI/Framework/Content/AssetData.cs +++ b/src/SMAPI/Framework/Content/AssetData.cs @@ -6,6 +6,13 @@ namespace StardewModdingAPI.Framework.Content /// The interface value type. internal class AssetData : AssetInfo, IAssetData { + /********* + ** Properties + *********/ + /// A callback to invoke when the data is replaced (if any). + private readonly Action OnDataReplaced; + + /********* ** Accessors *********/ @@ -21,10 +28,12 @@ namespace StardewModdingAPI.Framework.Content /// The normalised asset name being read. /// The content data being read. /// Normalises an asset key to match the cache key. - public AssetData(string locale, string assetName, TValue data, Func getNormalisedPath) + /// A callback to invoke when the data is replaced (if any). + public AssetData(string locale, string assetName, TValue data, Func getNormalisedPath, Action onDataReplaced) : base(locale, assetName, data.GetType(), getNormalisedPath) { this.Data = data; + this.OnDataReplaced = onDataReplaced; } /// Replace the entire content value with the given value. This is generally not recommended, since it may break compatibility with other mods or different versions of the game. @@ -39,6 +48,7 @@ namespace StardewModdingAPI.Framework.Content throw new InvalidCastException($"Can't replace loaded asset of type {this.GetFriendlyTypeName(this.DataType)} with value of type {this.GetFriendlyTypeName(value.GetType())}. The new type must be compatible to prevent game errors."); this.Data = value; + this.OnDataReplaced?.Invoke(value); } } } diff --git a/src/SMAPI/Framework/Content/AssetDataForDictionary.cs b/src/SMAPI/Framework/Content/AssetDataForDictionary.cs index e9b29b12..7b80875f 100644 --- a/src/SMAPI/Framework/Content/AssetDataForDictionary.cs +++ b/src/SMAPI/Framework/Content/AssetDataForDictionary.cs @@ -15,8 +15,9 @@ namespace StardewModdingAPI.Framework.Content /// The normalised asset name being read. /// The content data being read. /// Normalises an asset key to match the cache key. - public AssetDataForDictionary(string locale, string assetName, IDictionary data, Func getNormalisedPath) - : base(locale, assetName, data, getNormalisedPath) { } + /// A callback to invoke when the data is replaced (if any). + public AssetDataForDictionary(string locale, string assetName, IDictionary data, Func getNormalisedPath, Action> onDataReplaced) + : base(locale, assetName, data, getNormalisedPath, onDataReplaced) { } /// Add or replace an entry in the dictionary. /// The entry key. diff --git a/src/SMAPI/Framework/Content/AssetDataForImage.cs b/src/SMAPI/Framework/Content/AssetDataForImage.cs index 45c5588b..c665484f 100644 --- a/src/SMAPI/Framework/Content/AssetDataForImage.cs +++ b/src/SMAPI/Framework/Content/AssetDataForImage.cs @@ -15,8 +15,9 @@ namespace StardewModdingAPI.Framework.Content /// The normalised asset name being read. /// The content data being read. /// Normalises an asset key to match the cache key. - public AssetDataForImage(string locale, string assetName, Texture2D data, Func getNormalisedPath) - : base(locale, assetName, data, getNormalisedPath) { } + /// A callback to invoke when the data is replaced (if any). + public AssetDataForImage(string locale, string assetName, Texture2D data, Func getNormalisedPath, Action onDataReplaced) + : base(locale, assetName, data, getNormalisedPath, onDataReplaced) { } /// Overwrite part of the image. /// The image to patch into the content. diff --git a/src/SMAPI/Framework/Content/AssetDataForObject.cs b/src/SMAPI/Framework/Content/AssetDataForObject.cs index f30003e4..90f9e2d4 100644 --- a/src/SMAPI/Framework/Content/AssetDataForObject.cs +++ b/src/SMAPI/Framework/Content/AssetDataForObject.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Microsoft.Xna.Framework.Graphics; @@ -16,7 +16,7 @@ namespace StardewModdingAPI.Framework.Content /// The content data being read. /// Normalises an asset key to match the cache key. public AssetDataForObject(string locale, string assetName, object data, Func getNormalisedPath) - : base(locale, assetName, data, getNormalisedPath) { } + : base(locale, assetName, data, getNormalisedPath, onDataReplaced: null) { } /// Construct an instance. /// The asset metadata. @@ -31,14 +31,14 @@ namespace StardewModdingAPI.Framework.Content /// The content being read isn't a dictionary. public IAssetDataForDictionary AsDictionary() { - return new AssetDataForDictionary(this.Locale, this.AssetName, this.GetData>(), this.GetNormalisedPath); + return new AssetDataForDictionary(this.Locale, this.AssetName, this.GetData>(), this.GetNormalisedPath, this.ReplaceWith); } /// Get a helper to manipulate the data as an image. /// The content being read isn't an image. public IAssetDataForImage AsImage() { - return new AssetDataForImage(this.Locale, this.AssetName, this.GetData(), this.GetNormalisedPath); + return new AssetDataForImage(this.Locale, this.AssetName, this.GetData(), this.GetNormalisedPath, this.ReplaceWith); } /// Get the data as a given type. -- cgit From 51118337e5e8cbb6803ffee4e7c0b411aba2b3e0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 25 Feb 2018 01:49:53 -0500 Subject: update for 2.5.2 release --- build/GlobalAssemblyInfo.cs | 4 ++-- src/SMAPI.Mods.ConsoleCommands/manifest.json | 2 +- src/SMAPI/Constants.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/SMAPI') diff --git a/build/GlobalAssemblyInfo.cs b/build/GlobalAssemblyInfo.cs index 83bf7d82..f90ab358 100644 --- a/build/GlobalAssemblyInfo.cs +++ b/build/GlobalAssemblyInfo.cs @@ -1,5 +1,5 @@ using System.Reflection; [assembly: AssemblyProduct("SMAPI")] -[assembly: AssemblyVersion("2.5.1")] -[assembly: AssemblyFileVersion("2.5.1")] +[assembly: AssemblyVersion("2.5.2")] +[assembly: AssemblyFileVersion("2.5.2")] diff --git a/src/SMAPI.Mods.ConsoleCommands/manifest.json b/src/SMAPI.Mods.ConsoleCommands/manifest.json index 645f4315..f4b3884d 100644 --- a/src/SMAPI.Mods.ConsoleCommands/manifest.json +++ b/src/SMAPI.Mods.ConsoleCommands/manifest.json @@ -1,7 +1,7 @@ { "Name": "Console Commands", "Author": "SMAPI", - "Version": "2.5.1", + "Version": "2.5.2", "Description": "Adds SMAPI console commands that let you manipulate the game.", "UniqueID": "SMAPI.ConsoleCommands", "EntryDll": "ConsoleCommands.dll" diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 3e57ded9..fe9fdf9b 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -37,7 +37,7 @@ namespace StardewModdingAPI ** Public ****/ /// SMAPI's current semantic version. - public static ISemanticVersion ApiVersion { get; } = new SemanticVersion("2.5.1"); + public static ISemanticVersion ApiVersion { get; } = new SemanticVersion("2.5.2"); /// The minimum supported version of Stardew Valley. public static ISemanticVersion MinimumGameVersion { get; } = new SemanticVersion("1.2.30"); -- cgit