using static PKHeX.Core.TrainerIDFormat;
namespace PKHeX.Core;
///
/// Object has Trainer ownership with a way to show the Trainer ID.
///
public interface ITrainerID
{
///
/// Format the stored Trainer ID is shown to the player.
///
TrainerIDFormat TrainerIDDisplayFormat { get; }
}
public enum TrainerIDFormat
{
///
/// Don't use me.
///
None,
///
/// 16-bit Trainer ID
///
/// Generations 1-2 only. Secret ID did not exist.
SixteenBitSingle,
///
/// 16-bit Trainer ID, 16-bit Secret ID
///
/// Generations 3-6, and Generation 1-2 transferred 7+.
SixteenBit,
///
/// 32-bit Trainer ID, showing the lowest 6 digits.
///
/// Generation 7 origin onward.
SixDigit,
}
public static class TrainerIDExtensions
{
///
/// Detects the correct to use for the input .
///
public static TrainerIDFormat GetTrainerIDFormat(this ITrainerID tr) => tr switch
{
PKM { Format: <= 2 } => SixteenBitSingle,
PKM { Version: 0 } pk => pk.Format >= 7 ? SixDigit : SixteenBit,
IGeneration sv => sv.Generation >= 7 ? SixDigit : SixteenBit,
_ => SixteenBit,
};
/// String format specifier for TID.
public const string TID7 = "D6";
/// String format specifier for SID.
public const string SID7 = "D4";
/// String format specifier for TID.
public const string TID16 = "D5";
/// String format specifier for SID.
public const string SID16 = "D5";
///
/// Gets the string format specifier to use for the requested format TID.
///
public static string GetTrainerIDFormatStringTID(this TrainerIDFormat format) => format switch
{
SixDigit => TID7,
_ => TID16,
};
///
/// Gets the string format specifier to use for the requested format SID.
///
public static string GetTrainerIDFormatStringSID(this TrainerIDFormat format) => format switch
{
SixDigit => SID7,
_ => SID16,
};
}