PKHeX/PKHeX.Core/PKM/Util/Language.cs
Kurt 88830e0d00
Update from .NET Framework 4.6 to .NET 7 (#3729)
Updates from net46->net7, dropping support for mono in favor of using the latest runtime (along with the performance/API improvements). Releases will be posted as 64bit only for now.

Refactors a good amount of internal API methods to be more performant and more customizable for future updates & fixes.

Adds functionality for Batch Editor commands to `>`, `<` and <=/>=

TID/SID properties renamed to TID16/SID16 for clarity; other properties exposed for Gen7 / display variants.

Main window has a new layout to account for DPI scaling (8 point grid)

Fixed: Tatsugiri and Paldean Tauros now output Showdown form names as Showdown expects
Changed: Gen9 species now interact based on the confirmed National Dex IDs (closes #3724)
Fixed: Pokedex set all no longer clears species with unavailable non-base forms (closes #3720)
Changed: Hyper Training suggestions now apply for level 50 in SV. (closes #3714)
Fixed: B2/W2 hatched egg met locations exclusive to specific versions are now explicitly checked (closes #3691)
Added: Properties for ribbon/mark count (closes #3659)
Fixed: Traded SV eggs are now checked correctly (closes #3692)
2023-01-21 20:02:33 -08:00

96 lines
3.6 KiB
C#

using System;
using static PKHeX.Core.LanguageID;
namespace PKHeX.Core;
/// <summary>
/// Logic relating to <see cref="LanguageID"/> values.
/// </summary>
public static class Language
{
private static ReadOnlySpan<byte> Languages => new[]
{
(byte)Japanese,
(byte)English,
(byte)French,
(byte)Italian,
(byte)German,
(byte)Spanish,
(byte)Korean, // GS
(byte)ChineseS,
(byte)ChineseT,
};
// check Korean for the VC case, never possible to match string outside of this case
private static ReadOnlySpan<byte> Languages_GB => Languages[..7]; // [..KOR]
private static ReadOnlySpan<byte> Languages_3 => Languages[..6]; // [..KOR)
private const LanguageID SafeLanguage = English;
public static ReadOnlySpan<byte> GetAvailableGameLanguages(int generation = PKX.Generation) => generation switch
{
1 => Languages_3, // No KOR
2 => Languages_GB,
3 => Languages_3, // No KOR
4 or 5 or 6 => Languages_GB,
_ => Languages,
};
private static bool HasLanguage(ReadOnlySpan<byte> permitted, byte language) => permitted.Contains(language);
public static LanguageID GetSafeLanguage(int generation, LanguageID prefer, GameVersion game = GameVersion.Any) => generation switch
{
1 when game == GameVersion.BU => Japanese,
1 => HasLanguage(Languages_3, (byte)prefer) ? prefer : SafeLanguage,
2 => HasLanguage(Languages_GB, (byte)prefer) && (prefer != Korean || game == GameVersion.C) ? prefer : SafeLanguage,
3 => HasLanguage(Languages_3 , (byte)prefer) ? prefer : SafeLanguage,
4 or 5 or 6 => HasLanguage(Languages_GB, (byte)prefer) ? prefer : SafeLanguage,
_ => HasLanguage(Languages, (byte)prefer) ? prefer : SafeLanguage,
};
public static string GetLanguage2CharName(this LanguageID language) => language switch
{
Japanese => "ja",
French => "fr",
Italian => "it",
German => "de",
Spanish => "es",
Korean => "ko",
ChineseS or ChineseT => "zh",
_ => GameLanguage.DefaultLanguage,
};
/// <summary>
/// Gets the Main Series language ID from a GameCube (C/XD) language ID.
/// </summary>
/// <param name="value">GameCube (C/XD) language ID.</param>
/// <returns>Main Series language ID.</returns>
/// <remarks>If no conversion is possible or maps to the same value, the input <see cref="value"/> is returned.</remarks>
public static byte GetMainLangIDfromGC(byte value) => (LanguageGC)value switch
{
LanguageGC.German => (byte)German,
LanguageGC.French => (byte)French,
LanguageGC.Italian => (byte)Italian,
LanguageGC.Spanish => (byte)Spanish,
LanguageGC.UNUSED_6 => (byte)UNUSED_6,
_ => value,
};
/// <summary>
/// Gets the GameCube (C/XD) language ID from a Main Series language ID.
/// </summary>
/// <param name="value">Main Series language ID.</param>
/// <returns>GameCube (C/XD) language ID.</returns>
/// <remarks>If no conversion is possible or maps to the same value, the input <see cref="value"/> is returned.</remarks>
public static byte GetGCLangIDfromMain(byte value) => (LanguageID)value switch
{
French => (byte)LanguageGC.French,
Italian => (byte)LanguageGC.Italian,
German => (byte)LanguageGC.German,
UNUSED_6 => (byte)LanguageGC.UNUSED_6,
Spanish => (byte)LanguageGC.Spanish,
_ => value,
};
}