using System.IO;
using FSO.Files.Utils;
namespace FSO.Files.Formats.IFF.Chunks
{
///
/// This chunk type holds a number of constants that behavior code can refer to.
/// Labels may be provided for them in a TRCN chunk with the same ID.
///
public class BCON : IffChunk
{
public byte Flags;
public ushort[] Constants = new ushort[0];
///
/// Reads a BCON chunk from a stream.
///
/// An Iff instance.
/// A Stream instance holding a BCON.
public override void Read(IffFile iff, Stream stream)
{
using (var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN))
{
var num = io.ReadByte();
Flags = io.ReadByte();
Constants = new ushort[num];
for (var i = 0; i < num; i++)
{
Constants[i] = io.ReadUInt16();
}
}
}
public override bool Write(IffFile iff, Stream stream)
{
using (var io = IoWriter.FromStream(stream, ByteOrder.LITTLE_ENDIAN))
{
io.WriteByte((byte)Constants.Length);
io.WriteByte(Flags);
foreach (var c in Constants)
{
io.WriteUInt16(c);
}
return true;
}
}
}
}