summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ContentManagers
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework/ContentManagers')
-rw-r--r--src/SMAPI/Framework/ContentManagers/BaseContentManager.cs22
-rw-r--r--src/SMAPI/Framework/ContentManagers/ModContentManager.cs15
2 files changed, 22 insertions, 15 deletions
diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
index f41a9354..2d921cc3 100644
--- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
@@ -104,20 +104,21 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <inheritdoc />
[Obsolete("This method is implemented for the base game and should not be used directly. To load an asset from the underlying content manager directly, use " + nameof(BaseContentManager.RawLoad) + " instead.")]
- public override T LoadBase<T>(string assetName)
+ public sealed override T LoadBase<T>(string assetName)
{
return this.Load<T>(assetName, LanguageCode.en);
}
/// <inheritdoc />
- public override T Load<T>(string assetName)
+ public sealed override T Load<T>(string assetName)
{
return this.Load<T>(assetName, this.Language);
}
/// <inheritdoc />
- public override T Load<T>(string assetName, LanguageCode language)
+ public sealed override T Load<T>(string assetName, LanguageCode language)
{
+ assetName = this.PrenormalizeRawAssetName(assetName);
IAssetName parsedName = this.Coordinator.ParseAssetName(assetName);
return this.LoadLocalized<T>(parsedName, language, useCache: true);
}
@@ -276,6 +277,21 @@ namespace StardewModdingAPI.Framework.ContentManagers
/*********
** Private methods
*********/
+ /// <summary>Apply initial normalization to a raw asset name before it's parsed.</summary>
+ /// <param name="assetName">The asset name to normalize.</param>
+ private string PrenormalizeRawAssetName(string assetName)
+ {
+ // trim
+ assetName = assetName?.Trim();
+
+ // For legacy reasons, mods can pass .xnb file extensions to the content pipeline which
+ // are then stripped. This will be re-added as needed when reading from raw files.
+ if (assetName?.EndsWith(".xnb") == true)
+ assetName = assetName[..^".xnb".Length];
+
+ return assetName;
+ }
+
/// <summary>Normalize path separators in a file path. For asset keys, see <see cref="AssertAndNormalizeAssetName"/> instead.</summary>
/// <param name="path">The file path to normalize.</param>
[Pure]
diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
index 2a5a3f16..63b40d66 100644
--- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
@@ -32,9 +32,6 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <summary>The game content manager used for map tilesheets not provided by the mod.</summary>
private readonly IContentManager GameContentManager;
- /// <summary>The language code for language-agnostic mod assets.</summary>
- private readonly LanguageCode DefaultLanguage = Constants.DefaultLanguage;
-
/// <summary>If a map tilesheet's image source has no file extensions, the file extensions to check for in the local mod folder.</summary>
private readonly string[] LocalTilesheetExtensions = { ".png", ".xnb" };
@@ -76,12 +73,6 @@ namespace StardewModdingAPI.Framework.ContentManagers
}
/// <inheritdoc />
- public override T Load<T>(string assetName)
- {
- return this.Load<T>(assetName, this.DefaultLanguage);
- }
-
- /// <inheritdoc />
public override T LoadExact<T>(IAssetName assetName, bool useCache)
{
// disable caching
@@ -222,14 +213,14 @@ namespace StardewModdingAPI.Framework.ContentManagers
private FileInfo GetModFile(string path)
{
// try exact match
- FileInfo file = new FileInfo(Path.Combine(this.FullRootDirectory, path));
+ FileInfo file = new(Path.Combine(this.FullRootDirectory, path));
// try with default extension
- if (!file.Exists && file.Extension == string.Empty)
+ if (!file.Exists)
{
foreach (string extension in this.LocalTilesheetExtensions)
{
- FileInfo result = new FileInfo(file.FullName + extension);
+ FileInfo result = new(file.FullName + extension);
if (result.Exists)
{
file = result;