From 314a92b67b9e691d52bb9cfa0b45ed3142eb4424 Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 28 Mar 2018 20:34:58 -0700 Subject: [PATCH] Extend core api add copy/fetch new --- PKHeX.Core/Legality/Structures/IGeneration.cs | 5 +++++ PKHeX.Core/Legality/Structures/ITrainerInfo.cs | 17 +++++++++++++++++ PKHeX.Core/PKM/PKMConverter.cs | 5 +++++ 3 files changed, 27 insertions(+) diff --git a/PKHeX.Core/Legality/Structures/IGeneration.cs b/PKHeX.Core/Legality/Structures/IGeneration.cs index 76a452a51..8a5145355 100644 --- a/PKHeX.Core/Legality/Structures/IGeneration.cs +++ b/PKHeX.Core/Legality/Structures/IGeneration.cs @@ -7,4 +7,9 @@ internal interface IGeneration { int Generation { get; set; } } + + public static partial class Extensions + { + internal static PKM GetBlank(this IGeneration gen) => PKMConverter.GetBlank(gen.Generation); + } } diff --git a/PKHeX.Core/Legality/Structures/ITrainerInfo.cs b/PKHeX.Core/Legality/Structures/ITrainerInfo.cs index f5d927af8..2207eca36 100644 --- a/PKHeX.Core/Legality/Structures/ITrainerInfo.cs +++ b/PKHeX.Core/Legality/Structures/ITrainerInfo.cs @@ -18,4 +18,21 @@ public interface ITrainerInfo int Generation { get; } } + + public static partial class Extensions + { + public static void ApplyToPKM(this ITrainerInfo info, PKM pk) + { + pk.OT_Name = info.OT; + pk.TID = info.TID; + pk.SID = info.SID; + pk.OT_Gender = info.Gender; + pk.Language = info.Language; + pk.Version = info.Game; + + pk.Country = info.Country; + pk.Region = info.SubRegion; + pk.ConsoleRegion = info.ConsoleRegion; + } + } } \ No newline at end of file diff --git a/PKHeX.Core/PKM/PKMConverter.cs b/PKHeX.Core/PKM/PKMConverter.cs index 839fcad27..5be1aa59b 100644 --- a/PKHeX.Core/PKM/PKMConverter.cs +++ b/PKHeX.Core/PKM/PKMConverter.cs @@ -458,5 +458,10 @@ public static PKM GetBlank(Type t) var argCount = constructors.First().GetParameters().Length; return (PKM)Activator.CreateInstance(t, new object[argCount]); } + public static PKM GetBlank(int gen) + { + var type = Type.GetType($"PKHeX.Core.PK{gen}"); + return GetBlank(type); + } } }