Make GameVersion a byte enum

This commit is contained in:
Kurt 2022-09-24 19:23:23 -07:00
parent 19d062480a
commit 7cbde296f8
4 changed files with 9 additions and 12 deletions

View File

@ -1,14 +1,14 @@
namespace PKHeX.Core;
namespace PKHeX.Core;
/// <summary>
/// Game Version ID enum shared between actual Version IDs and lumped version groupings.
/// </summary>
public enum GameVersion
public enum GameVersion : byte
{
#region Indicators for method empty arguments & result indication. Not stored values.
Invalid = -2,
Any = -1,
Unknown = 0,
Any = 0,
Unknown = byte.MaxValue - 1,
Invalid = byte.MaxValue,
#endregion
// The following values are IDs stored within PKM data, and can also identify individual games.

View File

@ -11,9 +11,6 @@ internal static class MoveList
{
internal static void GetCurrentMoves(PKM pk, ushort species, byte form, GameVersion gameSource, int lvl, Span<ushort> moves)
{
if (gameSource == Any)
gameSource = (GameVersion)pk.Version;
_ = gameSource switch
{
GSC or GS => Get(moves, LevelUpGS, species, lvl, pk.Format),

View File

@ -1,4 +1,4 @@
namespace PKHeX.Core;
namespace PKHeX.Core;
/// <summary>
/// Interface that exposes a <see cref="Version"/> to see which version the data originated in.
@ -17,7 +17,7 @@ public static partial class Extensions
public static GameVersion GetCompatibleVersion(this IVersion ver, GameVersion prefer)
{
if (ver.CanBeReceivedBy(prefer) || ver.Version <= GameVersion.Unknown)
if (ver.CanBeReceivedBy(prefer) || ver.Version == GameVersion.Any)
return prefer;
return ver.GetSingleVersion();
}

View File

@ -206,8 +206,8 @@ private static GameVersion GetRandomVersion(GameVersion version)
return version switch
{
GameVersion.FRLG => GameVersion.FR + Util.Rand.Next(2), // or LG
GameVersion.RS or GameVersion.RSE => GameVersion.S + Util.Rand.Next(2), // or R
GameVersion.FRLG => Util.Rand.Next(2) == 0 ? GameVersion.FR : GameVersion.LG,
GameVersion.RS or GameVersion.RSE => Util.Rand.Next(2) == 0 ? GameVersion.R : GameVersion.S,
GameVersion.COLO or GameVersion.XD => GameVersion.CXD,
_ => throw new Exception($"Unknown GameVersion: {version}"),
};