fix some map tilesheets not editable if not playing in English

This commit is contained in:
Jesse Plamondon-Willard 2018-11-28 18:37:46 -05:00
parent 924c3a5d3f
commit e58681f1bc
No known key found for this signature in database
GPG Key ID: 7D7C8097B62033CE
3 changed files with 31 additions and 3 deletions

View File

@ -8,6 +8,7 @@
* For modders:
* Reloading a map asset will now update affected locations.
* Reloading the `Data\NPCDispositions` asset will now update affected NPCs.
* Fixed some map tilesheets not editable if not playing in English.
* Fixed newlines in most manifest fields not being ignored.
* For the web UI:

View File

@ -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

View File

@ -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>