Add initial brush list support

This commit is contained in:
Jarrod Doyle 2024-08-23 18:55:20 +01:00
parent eaf20f7f4a
commit f118c151f3
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
2 changed files with 126 additions and 0 deletions

View File

@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Numerics;
using System.Text;
namespace KeepersCompound.LGS.Database.Chunks;
public class BrList : IChunk
{
// TODO: Add better handling of the different brush types
public record Brush
{
public enum Media
{
Room = 0xFB,
Flow = 0xFC,
Object = 0xFD,
Area = 0xFE,
Light = 0xFF,
FillSolid = 0x00,
FillAir = 0x01,
FillWater = 0x02,
Flood = 0x03,
Evaporate = 0x04,
SolidToWater = 0x05,
SolidToAir = 0x06,
AirToSolid = 0x07,
WaterToSolid = 0x08,
Blockable = 0x09,
};
public record TexInfo
{
public short id;
public ushort rot;
public short scale;
public ushort x;
public ushort y;
public TexInfo(BinaryReader reader)
{
id = reader.ReadInt16();
rot = reader.ReadUInt16();
scale = reader.ReadInt16();
x = reader.ReadUInt16();
y = reader.ReadUInt16();
}
};
public short id;
public short time;
public uint brushInfo;
public short textureId;
public Media media;
public sbyte flags;
public Vector3 position;
public Vector3 size;
public Vector3 angle;
public short currentFaceIndex;
public float gridLineSpacing;
public Vector3 gridPhaseShift;
public Vector3 gridOrientation;
public bool gridEnabled;
public byte numFaces;
public sbyte edgeSelected;
public sbyte pointSelected;
public sbyte useFlag;
public sbyte groupId;
public TexInfo[] txs;
public Brush(BinaryReader reader)
{
id = reader.ReadInt16();
time = reader.ReadInt16();
brushInfo = reader.ReadUInt32();
textureId = reader.ReadInt16();
media = (Media)reader.ReadByte();
flags = reader.ReadSByte();
position = reader.ReadVec3();
size = reader.ReadVec3();
angle = new Vector3(reader.ReadUInt16(), reader.ReadUInt16(), reader.ReadUInt16());
currentFaceIndex = reader.ReadInt16();
gridLineSpacing = reader.ReadSingle();
gridPhaseShift = reader.ReadVec3();
gridOrientation = new Vector3(reader.ReadUInt16(), reader.ReadUInt16(), reader.ReadUInt16());
gridEnabled = reader.ReadBoolean();
numFaces = reader.ReadByte();
edgeSelected = reader.ReadSByte();
pointSelected = reader.ReadSByte();
useFlag = reader.ReadSByte();
groupId = reader.ReadSByte();
reader.ReadBytes(4);
if ((sbyte)media >= 0)
{
txs = new TexInfo[numFaces];
for (var i = 0; i < numFaces; i++)
{
txs[i] = new TexInfo(reader);
}
}
else
{
txs = Array.Empty<TexInfo>();
}
}
}
public ChunkHeader Header { get; set; }
public List<Brush> Brushes { get; set; }
public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry)
{
Brushes = new List<Brush>();
while (reader.BaseStream.Position < entry.Offset + entry.Size + 24)
{
Brushes.Add(new Brush(reader));
}
}
public void WriteData(BinaryWriter writer)
{
throw new System.NotImplementedException();
}
}

View File

@ -100,6 +100,7 @@ public class DbFile
// "AICONVERSE" => new AiConverseChunk(), // "AICONVERSE" => new AiConverseChunk(),
"TXLIST" => new TxList(), "TXLIST" => new TxList(),
"WREXT" => new WorldRep(), "WREXT" => new WorldRep(),
"BRLIST" => new BrList(),
_ => new GenericChunk(), _ => new GenericChunk(),
}; };
} }