pkNX/pkNX.Structures/Evolution/ZukanEvolutionTable.cs
Kurt 537ce93efa Initial c#8 update
pkNX.Sprites to be replaced with a pkhex.drawing dll once that is
updated with swsh stuff (when the time comes)
2019-10-15 18:47:20 -07:00

40 lines
1.1 KiB
C#

using System;
using System.IO;
using System.Linq;
namespace pkNX.Structures
{
public sealed class ZukanEvolutionTable
{
private const int SIZE = 0x14;
private readonly ushort[][] Table;
public ZukanEvolutionTable(byte[] data)
{
if (data.Length % SIZE != 0)
throw new ArgumentException(nameof(data) + " length should be a multiple of " + SIZE);
Table = new ushort[data.Length / SIZE][];
for (int i = 0; i < Table.Length; i++)
{
var evos = new ushort[(SIZE / 2) - 1];
for (int j = 0; j < evos.Length; j++)
evos[i] = BitConverter.ToUInt16(data, (i * SIZE) + (j * 2));
}
}
public byte[] Write()
{
using var ms = new MemoryStream();
using var bw = new BinaryWriter(ms);
foreach (var t in Table)
{
foreach (var e in t)
bw.Write(e);
bw.Write(t.Count(x => x != 0));
}
return ms.ToArray();
}
}
}