internal GraphicArchive(int paletteIndex, AssetLoader loader, int[] sizes = null)
: base(loader)
{
State state = State.Get(this);
PaletteAsset palette = state.GetPalette(paletteIndex);
using (BinaryReader reader = loader.Reader) {
byte forceSizeCode = reader.ReadByte();
int forceSize = 0;
if (forceSizeCode == 2)
{
forceSize = reader.ReadByte();
}
else if (forceSizeCode != 1)
{
throw new InvalidDataException();
}
int count = reader.ReadUInt16();
int[] offsets = reader.ReadArrayInt32(count + 1);
for (int index = 0; index < count; index++)
{
int length = offsets[index + 1] - offsets[index];
reader.BaseStream.Position = offsets[index];
int width = -1, height = -1;
if (sizes != null && index * 2 < sizes.Length)
{
width = sizes[index * 2 + 0];
height = sizes[index * 2 + 1];
}
else if (forceSize != 0)
{
width = height = forceSize;
}
new Graphic(this, loader, index, length, width, height, palette);
}
}
}