summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI/Framework/ContentManagers/GameContentManager.cs17
2 files changed, 18 insertions, 0 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 8b22b95a..f4067226 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -18,6 +18,7 @@
* **[Breaking change]** Map tilesheets are no loaded from `Content` if they can't be found in `Content/Maps`. This reflects an upcoming change in the game to delete map tilesheets under `Content`.
* Improved map tilesheet errors so they provide more info.
* Fixed dialogue propagation clearing marriage dialogue.
+ * Fixed issue where SMAPI didn't call `IAssetEditor` with the actual type if a mod loaded an asset using `content.Load<object>`.
* For the web UI:
* Updated the JSON validator and Content Patcher schema for `.tmx` support.
diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
index eecdda74..eaaf0e6f 100644
--- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
@@ -2,12 +2,15 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
+using System.Reflection;
using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI.Framework.Content;
using StardewModdingAPI.Framework.Exceptions;
using StardewModdingAPI.Framework.Reflection;
using StardewModdingAPI.Framework.Utilities;
using StardewValley;
+using xTile;
namespace StardewModdingAPI.Framework.ContentManagers
{
@@ -337,6 +340,20 @@ namespace StardewModdingAPI.Framework.ContentManagers
{
IAssetData GetNewData(object data) => new AssetDataForObject(info, data, this.AssertAndNormalizeAssetName);
+ // special case: if the asset was loaded with a more general type like 'object', call editors with the actual type instead.
+ {
+ Type actualType = asset.Data.GetType();
+ Type actualOpenType = actualType.IsGenericType ? actualType.GetGenericTypeDefinition() : null;
+
+ if (typeof(T) != actualType && (actualOpenType == typeof(Dictionary<,>) || actualOpenType == typeof(List<>) || actualType == typeof(Texture2D) || actualType == typeof(Map)))
+ {
+ return (IAssetData)this.GetType()
+ .GetMethod(nameof(this.ApplyEditors), BindingFlags.NonPublic | BindingFlags.Instance)
+ .MakeGenericMethod(actualType)
+ .Invoke(this, new object[] { info, asset });
+ }
+ }
+
// edit asset
foreach (var entry in this.Editors)
{