Simplify some memory args

This commit is contained in:
Kurt 2022-08-24 23:29:03 -07:00
parent d3c2d77d11
commit b241c19520
4 changed files with 27 additions and 23 deletions

View file

@ -7,36 +7,35 @@ namespace PKHeX.Core;
/// </summary>
public static class Memories
{
public static readonly MemoryContext6 Memory6 = new();
public static readonly MemoryContext8 Memory8 = new();
internal static readonly HashSet<int> MemoryGeneral = new() { 1, 2, 3, 4, 19, 24, 31, 32, 33, 35, 36, 37, 38, 39, 42, 52, 59, 70, 86 };
private static readonly HashSet<int> MemorySpecific = new() { 6 };
private static readonly HashSet<int> MemoryMove = new() { 12, 16, 48, 49, 80, 81, 89 };
private static readonly HashSet<int> MemoryItem = new() { 5, 15, 26, 34, 40, 51, 84, 88 };
private static readonly HashSet<int> MemorySpecies = new() { 7, 9, 13, 14, 17, 21, 18, 25, 29, 44, 45, 50, 60, 70, 71, 72, 75, 82, 83, 87 };
private static readonly byte[] ArgTypes =
{
0, 1, 1, 1, 1, 5, 2, 3, 0, 3,
0, 0, 4, 3, 3, 5, 4, 3, 3, 1,
0, 3, 0, 0, 1, 3, 5, 0, 0, 3,
0, 1, 1, 1, 5, 1, 1, 1, 1, 1,
5, 0, 1, 0, 3, 3, 0, 0, 4, 4,
3, 5, 1, 0, 0, 0, 0, 0, 0, 1,
3, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 3, 3, 0, 0, 3, 0, 0, 0, 0,
4, 4, 3, 3, 5, 0, 1, 3, 5, 4,
};
public static MemoryArgType GetMemoryArgType(int memory, int memoryGen)
{
if (MemoryGeneral.Contains(memory)) return MemoryArgType.GeneralLocation;
if (MemorySpecific.Contains(memory))
{
if (memoryGen <= 7)
return MemoryArgType.SpecificLocation;
var arr = ArgTypes;
if ((uint)memory >= arr.Length)
return MemoryArgType.None;
var type = arr[memory];
if (memoryGen > 6 && type == (int)MemoryArgType.SpecificLocation)
return MemoryArgType.GeneralLocation;
}
if (MemoryItem.Contains(memory)) return MemoryArgType.Item;
if (MemoryMove.Contains(memory)) return MemoryArgType.Move;
if (MemorySpecies.Contains(memory)) return MemoryArgType.Species;
return MemoryArgType.None;
return (MemoryArgType)type;
}
public static MemoryContext GetContext(EntityContext context) => context.Generation() switch
{
<=7 => Memory6,
_ => Memory8,
<=7 => MemoryContext6.Instance,
_ => MemoryContext8.Instance,
};
public static IEnumerable<ushort> GetMemoryItemParams(EntityContext context) => GetContext(context).GetMemoryItemParams();

View file

@ -7,6 +7,8 @@ public sealed partial class MemoryContext6 : MemoryContext
{
private const int MAX_MEMORY_ID_XY = 64;
private const int MAX_MEMORY_ID_AO = 69;
public static readonly MemoryContext6 Instance = new();
private MemoryContext6() { }
private static ICollection<int> GetPokeCenterLocations(GameVersion game)
{

View file

@ -6,6 +6,8 @@ namespace PKHeX.Core;
public sealed partial class MemoryContext8 : MemoryContext
{
private const int MAX_MEMORY_ID_SWSH = 89;
public static readonly MemoryContext8 Instance = new();
private MemoryContext8() { }
public override IEnumerable<ushort> GetKeyItemParams() => (KeyItemMemoryArgsGen8.Values).SelectMany(z => z).Distinct();
@ -33,7 +35,8 @@ public sealed partial class MemoryContext8 : MemoryContext
public override bool IsInvalidGeneralLocationMemoryValue(byte memory, ushort variable, IEncounterTemplate enc, PKM pk)
{
if (!Memories.MemoryGeneral.Contains(memory))
var type = Memories.GetMemoryArgType(memory, 8);
if (type is not MemoryArgType.GeneralLocation)
return false;
if (memory is 1 or 2 or 3) // Encounter only