diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs
index 93b6d9f3..84fff250 100644
--- a/src/SMAPI/Framework/ContentCoordinator.cs
+++ b/src/SMAPI/Framework/ContentCoordinator.cs
@@ -691,12 +691,9 @@ namespace StardewModdingAPI.Framework
/// The asset info.
private IAssetInfo GetLegacyAssetInfo(IAssetInfo asset)
{
- if (!this.TryGetLegacyAssetName(asset.Name, out IAssetName legacyName))
- return asset;
-
return new AssetInfo(
- locale: null,
- assetName: legacyName,
+ locale: this.GetLegacyLocale(asset),
+ assetName: this.GetLegacyAssetName(asset.Name),
type: asset.DataType,
getNormalizedPath: this.MainContentManager.AssertAndNormalizeAssetName
);
@@ -706,49 +703,45 @@ namespace StardewModdingAPI.Framework
/// The asset data.
private IAssetData GetLegacyAssetData(IAssetData asset)
{
- if (!this.TryGetLegacyAssetName(asset.Name, out IAssetName legacyName))
- return asset;
+ return new AssetDataForObject(
+ locale: this.GetLegacyLocale(asset),
+ assetName: this.GetLegacyAssetName(asset.Name),
+ data: asset.Data,
+ getNormalizedPath: this.MainContentManager.AssertAndNormalizeAssetName,
+ reflection: this.Reflection,
+ onDataReplaced: asset.ReplaceWith
+ );
+ }
- return asset.Name.LocaleCode == null
- ? asset
- : new AssetDataForObject(
- locale: null,
- assetName: legacyName,
- data: asset.Data,
- getNormalizedPath: this.MainContentManager.AssertAndNormalizeAssetName,
- reflection: this.Reflection,
- onDataReplaced: asset.ReplaceWith
- );
+ /// Get the value compatible with legacy and instances, which expect the locale to default to the current game locale or an empty string.
+ /// The non-legacy asset info to map.
+ private string GetLegacyLocale(IAssetInfo asset)
+ {
+ return asset.Locale ?? this.GetLocale();
}
/// Get an asset name compatible with legacy and instances, which always expect the base name.
/// The asset name to map.
- /// The legacy asset name (or the if no change is needed).
- /// Returns whether any change is needed for legacy compatibility.
- private bool TryGetLegacyAssetName(IAssetName asset, out IAssetName newAsset)
+ /// Returns the legacy asset name if needed, or the if no change is needed.
+ private IAssetName GetLegacyAssetName(IAssetName asset)
{
// strip _international suffix
const string internationalSuffix = "_international";
if (asset.Name.EndsWith(internationalSuffix))
{
- newAsset = new AssetName(
+ return new AssetName(
baseName: asset.Name[..^internationalSuffix.Length],
localeCode: null,
languageCode: null
);
- return true;
}
// else strip locale
if (asset.LocaleCode != null)
- {
- newAsset = new AssetName(asset.BaseName, null, null);
- return true;
- }
+ return new AssetName(asset.BaseName, null, null);
// else no change needed
- newAsset = asset;
- return false;
+ return asset;
}
}
}
diff --git a/src/SMAPI/IAssetInfo.cs b/src/SMAPI/IAssetInfo.cs
index 4d651a72..44fd91a5 100644
--- a/src/SMAPI/IAssetInfo.cs
+++ b/src/SMAPI/IAssetInfo.cs
@@ -9,10 +9,11 @@ namespace StardewModdingAPI
** Accessors
*********/
/// The content's locale code, if the content is localized.
+ /// LEGACY NOTE: when reading this field from an or implementation, for non-localized assets it will return the current game locale (or an empty string for English) instead of null.
string? Locale { get; }
/// The asset name being read.
- /// NOTE: when reading this field from an or implementation, it's always equivalent to for backwards compatibility.
+ /// LEGACY NOTE: when reading this field from an or implementation, it's always equivalent to for backwards compatibility.
public IAssetName Name { get; }
/// The with any locale codes stripped.