namespace PKHeX.Core;
///
/// Caches a reference to the most recently loaded trainer data.
///
/// Useful for sourcing trainer info for the ConvertTo methods.
public static class RecentTrainerCache
{
private static ITrainerInfo Trainer = new SimpleTrainerInfo();
private static IRegionOrigin Trainer67 = new SimpleTrainerInfo(GameVersion.SN);
private static IRegionOrigin GetTrainer3DS(ITrainerInfo tr) => tr as IRegionOrigin ?? Trainer67;
/// Most recently loaded .
public static string OT_Name => Trainer.OT;
/// Most recently loaded .
public static int OT_Gender => Trainer.Gender;
/// Most recently loaded .
public static int Language => Trainer.Language;
/// Most recently loaded .
public static int Format => Trainer.Generation;
/// Most recently loaded .
public static int Game => Trainer.Game;
/// Most recently loaded .
public static EntityContext Context => Trainer.Context;
///
/// Updates the cache with the most recently loaded trainer reference.
///
///
public static void SetRecentTrainer(ITrainerInfo trainer)
{
Trainer = trainer;
if (trainer is IRegionOrigin g67)
Trainer67 = g67;
}
///
public static void SetConsoleRegionData3DS(IRegionOrigin pk) => SetConsoleRegionData3DS(pk, Trainer);
///
public static void SetFirstCountryRegion(IGeoTrack pk) => SetFirstCountryRegion(pk, Trainer);
///
/// Fetches an trainer to apply details to the input .
///
/// Entity to apply details to.
/// Trainer that is receiving the entity.
public static void SetConsoleRegionData3DS(IRegionOrigin pk, ITrainerInfo trainer)
{
var tr = GetTrainer3DS(trainer);
pk.ConsoleRegion = tr.ConsoleRegion;
pk.Country = tr.Country;
pk.Region = tr.Region;
}
///
/// Fetches an trainer to apply details to the input .
///
/// Entity to apply details to.
/// Trainer that is receiving the entity.
public static void SetFirstCountryRegion(IGeoTrack pk, ITrainerInfo trainer)
{
var tr = GetTrainer3DS(trainer);
pk.Geo1_Country = tr.Country;
pk.Geo1_Region = tr.Region;
}
}