From 4c64f9f644c2349d2ca2407ce3aff736ba3fc354 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 26 Mar 2022 14:07:16 -0400 Subject: rewrite content loading to allow handling locale variants (#766, #786, #812) The game's content pipeline automatically loads localized variants if present. For example, it will try to load "Maps/cave.fr-FR", then "Maps/cave_international", then "Maps/cave". The old content API obfuscates this logic and treats them as interchangeable, which causes edge cases like bundle corruption (#812). This commit rewrites the loading logic to match the game logic when using the new content events, while maintaining the legacy behavior for the old IAssetLoader/IAssetEditor interfaces that'll be removed in SMAPI 4.0.0. --- src/SMAPI/Framework/ContentManagers/IContentManager.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/SMAPI/Framework/ContentManagers/IContentManager.cs') diff --git a/src/SMAPI/Framework/ContentManagers/IContentManager.cs b/src/SMAPI/Framework/ContentManagers/IContentManager.cs index 6d71472f..4de9a8c3 100644 --- a/src/SMAPI/Framework/ContentManagers/IContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/IContentManager.cs @@ -32,12 +32,17 @@ namespace StardewModdingAPI.Framework.ContentManagers /// The normalized asset name. bool DoesAssetExist(IAssetName assetName); - /// Load an asset that has been processed by the content pipeline. + /// Load an asset through the content pipeline, using a localized variant of the if available. /// The type of asset to load. /// The asset name relative to the loader root directory. - /// The language code for which to load content. /// Whether to read/write the loaded asset to the asset cache. - T Load(IAssetName assetName, LocalizedContentManager.LanguageCode language, bool useCache); + T LoadLocalized(IAssetName assetName, LocalizedContentManager.LanguageCode language, bool useCache); + + /// Load an asset through the content pipeline, using the exact asset name without checking for localized variants. + /// The type of asset to load. + /// The asset name relative to the loader root directory. + /// Whether to read/write the loaded asset to the asset cache. + T LoadExact(IAssetName assetName, bool useCache); /// Assert that the given key has a valid format and return a normalized form consistent with the underlying cache. /// The asset key to check. @@ -53,8 +58,7 @@ namespace StardewModdingAPI.Framework.ContentManagers /// Get whether the content manager has already loaded and cached the given asset. /// The asset path relative to the loader root directory, not including the .xnb extension. - /// The language. - bool IsLoaded(IAssetName assetName, LocalizedContentManager.LanguageCode language); + bool IsLoaded(IAssetName assetName); /// Purge matched assets from the cache. /// Matches the asset keys to invalidate. -- cgit