pkNX/pkNX.Structures/Evolution/ZukanEvolutionTable.cs
2018-11-13 19:44:43 -08:00

42 lines
1.2 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();
}
}
}
}