adjust ModContentManager.HandleUnknownFileTypes to let mods patch it

This commit is contained in:
Jesse Plamondon-Willard 2023-03-26 13:32:33 -04:00
parent c0ac58f277
commit c2e9aad698
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 7 additions and 4 deletions

View File

@ -18,6 +18,7 @@
* For mod authors: * For mod authors:
* Added `IsActiveForScreen()` method to `PerScreen<T>`. * 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)). * 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. * Fixed `Context.IsWorldReady` being editable by mods.
## 3.18.2 ## 3.18.2

View File

@ -130,7 +130,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
".png" => this.LoadImageFile<T>(assetName, file), ".png" => this.LoadImageFile<T>(assetName, file),
".tbin" or ".tmx" => this.LoadMapFile<T>(assetName, file), ".tbin" or ".tmx" => this.LoadMapFile<T>(assetName, file),
".xnb" => this.LoadXnbFile<T>(assetName), ".xnb" => this.LoadXnbFile<T>(assetName),
_ => this.HandleUnknownFileType<T>(assetName, file) _ => (T)this.HandleUnknownFileType(assetName, file, typeof(T))
}; };
} }
catch (Exception ex) 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> /// <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="assetName">The asset name relative to the loader root directory.</param>
/// <param name="file">The file to load.</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'."); 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> /// <summary>Assert that the asset type is compatible with one of the allowed types.</summary>