pkNX/pkNX.Structures/Evolution/ZukanEvolutionTable.cs
Kurt 2578ba073c Refactoring
File scoped namespaces for all lib projects
netstandard2.0 => net6; now uniform. bye netframework!
2022-10-01 17:08:17 -07:00

39 lines
1001 B
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();
}
}