summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2023-03-26 13:32:33 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2023-04-02 15:44:02 -0400
commitc2e9aad698774e7db9b85292da9077f8462d2f5a (patch)
treeaf5d19e7ab145dfdd4a15014b826bb5eab7d42b2
parentc0ac58f2778fd70e9937a77d3af8a06ef957d871 (diff)
downloadSMAPI-c2e9aad698774e7db9b85292da9077f8462d2f5a.tar.gz
SMAPI-c2e9aad698774e7db9b85292da9077f8462d2f5a.tar.bz2
SMAPI-c2e9aad698774e7db9b85292da9077f8462d2f5a.zip
adjust ModContentManager.HandleUnknownFileTypes to let mods patch it
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI/Framework/ContentManagers/ModContentManager.cs10
2 files changed, 7 insertions, 4 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 991f8faa..4daf97ce 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -18,6 +18,7 @@
* For mod authors:
* Added `IsActiveForScreen()` method to `PerScreen<T>`.
* Updated to [FluentHttpClient](https://github.com/Pathoschild/FluentHttpClient#readme) 4.3.0 (see [changes](https://github.com/Pathoschild/FluentHttpClient/blob/develop/RELEASE-NOTES.md#430)).
+ * Adjusted `ModContentManager.HandleUnknownFileType` to let mods patch it.
* Fixed `Context.IsWorldReady` being editable by mods.
## 3.18.2
diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
index badbd766..2c068784 100644
--- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
@@ -130,7 +130,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
".png" => this.LoadImageFile<T>(assetName, file),
".tbin" or ".tmx" => this.LoadMapFile<T>(assetName, file),
".xnb" => this.LoadXnbFile<T>(assetName),
- _ => this.HandleUnknownFileType<T>(assetName, file)
+ _ => (T)this.HandleUnknownFileType(assetName, file, typeof(T))
};
}
catch (Exception ex)
@@ -323,13 +323,15 @@ namespace StardewModdingAPI.Framework.ContentManagers
}
/// <summary>Handle a request to load a file type that isn't supported by SMAPI.</summary>
- /// <typeparam name="T">The expected file type.</typeparam>
/// <param name="assetName">The asset name relative to the loader root directory.</param>
/// <param name="file">The file to load.</param>
- private T HandleUnknownFileType<T>(IAssetName assetName, FileInfo file)
+ /// <param name="assetType">The expected file type.</param>
+ private object HandleUnknownFileType(IAssetName assetName, FileInfo file, Type assetType)
{
this.ThrowLoadError(assetName, ContentLoadErrorType.InvalidName, $"unknown file extension '{file.Extension}'; must be one of '.fnt', '.json', '.png', '.tbin', '.tmx', or '.xnb'.");
- return default;
+ return assetType.IsValueType
+ ? Activator.CreateInstance(assetType)
+ : null;
}
/// <summary>Assert that the asset type is compatible with one of the allowed types.</summary>