keep old XNB file extension behavior for backwards compatibility (#766)

This commit is contained in:
Jesse Plamondon-Willard 2022-04-01 00:33:35 -04:00
parent 1d3c99cc25
commit 6ad8ca932e
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
4 changed files with 23 additions and 17 deletions

View File

@ -53,6 +53,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pathoschild/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=premultiplied/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=premultiply/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Prenormalize/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=prerelease/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=pufferchick/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=rewriter/@EntryIndexedValue">True</s:Boolean>

View File

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

View File

@ -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" };
@ -75,12 +72,6 @@ namespace StardewModdingAPI.Framework.ContentManagers
return file.Exists;
}
/// <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)
{
@ -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;

View File

@ -95,8 +95,6 @@ namespace StardewModdingAPI.Metadata
.Distinct()
.ToDictionary(name => name, _ => false);
this.Monitor.Log($"Propagating: {propagatedAssets.Keys.OrderBy(p => p.Name, StringComparer.OrdinalIgnoreCase)}", LogLevel.Alert);
// group into optimized lists
var buckets = assets.GroupBy(p =>
{