add backwards compatibility for loading content assets with .xnb extension

This commit is contained in:
Jesse Plamondon-Willard 2022-04-27 20:09:43 -04:00
parent 8425c82033
commit d7d8cdaa5a
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 12 additions and 1 deletions

View File

@ -76,7 +76,7 @@ namespace StardewModdingAPI.Framework.Content
{ {
key = this.NormalizePathSeparators(key); key = this.NormalizePathSeparators(key);
return key.EndsWith(".xnb", StringComparison.OrdinalIgnoreCase) return key.EndsWith(".xnb", StringComparison.OrdinalIgnoreCase)
? key.Substring(0, key.Length - 4) ? key[..^4]
: key; : key;
} }

View File

@ -118,6 +118,17 @@ namespace StardewModdingAPI.Framework.ModHelpers
switch (source) switch (source)
{ {
case ContentSource.GameContent: case ContentSource.GameContent:
if (assetName.Name.EndsWith(".xnb", StringComparison.OrdinalIgnoreCase))
{
assetName = this.ContentCore.ParseAssetName(assetName.Name[..^4], allowLocales: true);
SCore.DeprecationManager.Warn(
this.Mod,
"loading assets from the Content folder with a .xnb file extension",
"3.14.0",
DeprecationLevel.Notice
);
}
return this.GameContentManager.LoadLocalized<T>(assetName, this.CurrentLocaleConstant, useCache: false); return this.GameContentManager.LoadLocalized<T>(assetName, this.CurrentLocaleConstant, useCache: false);
case ContentSource.ModFolder: case ContentSource.ModFolder: