PKHeX/PKHeX.Core/PKM/Shared/EntityFormat.cs
Kurt 5bcccc6d92
HOME 2.0.0: Handle conversion behavior & restrictions (#3506)
* Revises legality checks to account for traveling between the three game islands (PLA/BDSP/SWSH)
* Adds conversion mechanisms between the three formats, as well as flexible conversion options to backfill missing data (thanks GameFreak/ILCA for opting for lossy conversion instead of updating the games).
* Adds API abstractions for HOME data storage format (EKH/PKH format 1, aka EH1/PH1).
* Revises some APIs for better usage:
  - `PKM` now exposes a `Context` to indicate the isolation context for legality purposes.
  - Some method signatures have changed to accept `Context` or `GameVersion` instead of a vague `int` for Generation.
  - Evolution History is now tracked in the Legality parse for specific contexts, rather than only per generation.
2022-05-30 21:43:52 -07:00

59 lines
1.7 KiB
C#

using System;
using static PKHeX.Core.EntityContext;
namespace PKHeX.Core;
/// <summary>
/// "Context" is an existence island; data format restricts the types of changes that can be made (such as evolving).
/// </summary>
/// <remarks>
/// Starting in the 8th generation games, entities can move between games with wildly different evolution rules.
/// Previous implementations of a "Format Generation" were unable to differentiate if a class object was present in one of these different-rule contexts.
/// The "Format Generation" is still a useful generalization to check if certain fields are present in the entity data, or if certain mutations are possible.
/// </remarks>
public enum EntityContext
{
Invalid = 0,
Gen1 = 1,
Gen2 = 2,
Gen3 = 3,
Gen4 = 4,
Gen5 = 5,
Gen6 = 6,
Gen7 = 7,
Gen8 = 8,
SplitInvalid,
Gen7b,
Gen8a,
Gen8b,
}
public static class EntityContextExtensions
{
public static int Generation(this EntityContext value) => value < SplitInvalid ? (int)value : value switch
{
Gen7b => 7,
Gen8a => 8,
Gen8b => 8,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, null),
};
public static GameVersion GetSingleGameVersion(this EntityContext value) => value switch
{
Gen1 => GameVersion.RD,
Gen2 => GameVersion.C,
Gen3 => GameVersion.E,
Gen4 => GameVersion.SS,
Gen5 => GameVersion.W2,
Gen6 => GameVersion.AS,
Gen7 => GameVersion.UM,
Gen8 => GameVersion.SH,
Gen7b => GameVersion.GP,
Gen8a => GameVersion.PLA,
Gen8b => GameVersion.BD,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, null),
};
}