using System; using System.Collections.Generic; using AibisDream.Framework; namespace AibisDream.UI { /// /// Defines the Addressable key convention used by localized Obj sprites. /// Chinese uses Sprite/Obj; every other supported locale uses /// Sprite/Obj_{localeCode}. File names stay identical across locales. /// internal static class LocalizedObjSpriteNaming { internal const string DefaultLocaleCode = "zh-Hans"; internal const string DefaultAddressRoot = "Sprite/Obj"; private static readonly string[] NonDefaultLocaleCodeValues = { "en", "ja-JP", "ru", "es", "pt-BR" }; internal static IReadOnlyList NonDefaultLocaleCodes => NonDefaultLocaleCodeValues; internal static string NormalizeLogicalName(string picName) { if (string.IsNullOrEmpty(picName)) return picName; return picName.EndsWith(".png", StringComparison.OrdinalIgnoreCase) ? picName.Substring(0, picName.Length - 4) : picName; } internal static string GetAssetLocaleCode(string localeCode) { return LocalizationKit.GetLocaleKind(localeCode) switch { LocaleKind.En => "en", LocaleKind.Ja => "ja-JP", LocaleKind.Ru => "ru", LocaleKind.Es => "es", LocaleKind.PtBr => "pt-BR", _ => DefaultLocaleCode }; } internal static string GetAddressRoot(string localeCode) { string assetLocaleCode = GetAssetLocaleCode(localeCode); return string.Equals( assetLocaleCode, DefaultLocaleCode, StringComparison.Ordinal) ? DefaultAddressRoot : $"{DefaultAddressRoot}_{assetLocaleCode}"; } internal static string GetKey(string logicalName, string localeCode) { string normalizedName = NormalizeLogicalName(logicalName); return $"{GetAddressRoot(localeCode)}/{normalizedName}.png"; } internal static IReadOnlyList GetCandidateKeys( string logicalName, string localeCode) { string normalizedName = NormalizeLogicalName(logicalName); string localizedKey = GetKey(normalizedName, localeCode); string defaultKey = GetKey(normalizedName, DefaultLocaleCode); if (string.Equals(localizedKey, defaultKey, StringComparison.Ordinal)) return new[] { defaultKey }; return new[] { localizedKey, defaultKey }; } } }