2018-05-19 19:07:50 +00:00
|
|
|
using System;
|
2019-03-23 17:36:28 +00:00
|
|
|
using System.Collections.Generic;
|
2022-01-03 05:35:59 +00:00
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2018-05-19 19:07:50 +00:00
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Generation 7 Evolution Branch Entries
|
|
|
|
/// </summary>
|
2019-03-23 17:36:28 +00:00
|
|
|
public static class EvolutionSet7
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
|
|
|
private const int SIZE = 8;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
private static EvolutionMethod[] GetMethods(ReadOnlySpan<byte> data)
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
2019-03-23 17:36:28 +00:00
|
|
|
var evos = new EvolutionMethod[data.Length / SIZE];
|
2018-05-19 19:07:50 +00:00
|
|
|
for (int i = 0; i < data.Length; i += SIZE)
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
var entry = data.Slice(i, SIZE);
|
|
|
|
evos[i / SIZE] = ReadEvolution(entry);
|
2018-05-19 19:07:50 +00:00
|
|
|
}
|
2019-03-23 17:36:28 +00:00
|
|
|
return evos;
|
|
|
|
}
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
private static EvolutionMethod ReadEvolution(ReadOnlySpan<byte> entry)
|
|
|
|
{
|
|
|
|
var method = ReadUInt16LittleEndian(entry);
|
|
|
|
var arg = ReadUInt16LittleEndian(entry[2..]);
|
|
|
|
var species = ReadUInt16LittleEndian(entry[4..]);
|
|
|
|
var form = (sbyte)entry[6];
|
|
|
|
var level = entry[7];
|
|
|
|
return new EvolutionMethod(method, species, argument: arg, level: level, form: form);
|
|
|
|
}
|
|
|
|
|
2019-03-23 17:36:28 +00:00
|
|
|
public static IReadOnlyList<EvolutionMethod[]> GetArray(IReadOnlyList<byte[]> data)
|
|
|
|
{
|
|
|
|
var evos = new EvolutionMethod[data.Count][];
|
|
|
|
for (int i = 0; i < evos.Length; i++)
|
|
|
|
evos[i] = GetMethods(data[i]);
|
|
|
|
return evos;
|
2018-05-19 19:07:50 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-03 05:35:59 +00:00
|
|
|
}
|