summaryrefslogtreecommitdiff
path: root/src/SMAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-11-28 18:37:46 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-11-28 18:37:46 -0500
commite58681f1bccb02a5aa079a54a981fa05e39260c9 (patch)
tree2850545215afb09666a384ae1ee5ae7f5a6921d7 /src/SMAPI
parent924c3a5d3fe6bfad483834112883156bdf202b57 (diff)
downloadSMAPI-e58681f1bccb02a5aa079a54a981fa05e39260c9.tar.gz
SMAPI-e58681f1bccb02a5aa079a54a981fa05e39260c9.tar.bz2
SMAPI-e58681f1bccb02a5aa079a54a981fa05e39260c9.zip
fix some map tilesheets not editable if not playing in English
Diffstat (limited to 'src/SMAPI')
-rw-r--r--src/SMAPI/Framework/ContentManagers/BaseContentManager.cs6
-rw-r--r--src/SMAPI/Framework/ContentManagers/GameContentManager.cs27
2 files changed, 30 insertions, 3 deletions
diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
index ed08f11c..724a6e1c 100644
--- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
@@ -32,12 +32,12 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <summary>Whether the content coordinator has been disposed.</summary>
private bool IsDisposed;
- /// <summary>The language enum values indexed by locale code.</summary>
- private readonly IDictionary<string, LanguageCode> LanguageCodes;
-
/// <summary>A callback to invoke when the content manager is being disposed.</summary>
private readonly Action<BaseContentManager> OnDisposing;
+ /// <summary>The language enum values indexed by locale code.</summary>
+ protected IDictionary<string, LanguageCode> LanguageCodes { get; }
+
/*********
** Accessors
diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
index a53840bc..4f3b6fbc 100644
--- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using StardewModdingAPI.Framework.Content;
+using StardewModdingAPI.Framework.Exceptions;
using StardewModdingAPI.Framework.Reflection;
using StardewModdingAPI.Framework.Utilities;
using StardewValley;
@@ -52,7 +53,10 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <param name="language">The language code for which to load content.</param>
public override T Load<T>(string assetName, LanguageCode language)
{
+ // normalise asset name
assetName = this.AssertAndNormaliseAssetName(assetName);
+ if (this.TryParseExplicitLanguageAssetKey(assetName, out string newAssetName, out LanguageCode newLanguage))
+ return this.Load<T>(newAssetName, newLanguage);
// get from cache
if (this.IsLoaded(assetName))
@@ -124,6 +128,29 @@ namespace StardewModdingAPI.Framework.ContentManagers
return false;
}
+ /// <summary>Parse an asset key that contains an explicit language into its asset name and language, if applicable.</summary>
+ /// <param name="rawAsset">The asset key to parse.</param>
+ /// <param name="assetName">The asset name without the language code.</param>
+ /// <param name="language">The language code removed from the asset name.</param>
+ private bool TryParseExplicitLanguageAssetKey(string rawAsset, out string assetName, out LanguageCode language)
+ {
+ if (string.IsNullOrWhiteSpace(rawAsset))
+ throw new SContentLoadException("The asset key is empty.");
+
+ // extract language code
+ int splitIndex = rawAsset.LastIndexOf('.');
+ if (splitIndex != -1 && this.LanguageCodes.TryGetValue(rawAsset.Substring(splitIndex + 1), out language))
+ {
+ assetName = rawAsset.Substring(0, splitIndex);
+ return true;
+ }
+
+ // no explicit language code found
+ assetName = rawAsset;
+ language = this.Language;
+ return false;
+ }
+
/// <summary>Load the initial asset from the registered <see cref="Loaders"/>.</summary>
/// <param name="info">The basic asset metadata.</param>
/// <returns>Returns the loaded asset metadata, or <c>null</c> if no loader matched.</returns>