diff --git a/project/code/TMV/Mission.cs b/project/code/TMV/Mission.cs index 9dd4005..d509ae4 100644 --- a/project/code/TMV/Mission.cs +++ b/project/code/TMV/Mission.cs @@ -92,19 +92,28 @@ public partial class Mission : Node3D ClearMap(); _textureLoader = new TextureLoader(_installPaths.famPath, FileName.GetBaseDir()); - _file = new(FileName); - var textureList = (TxList)_file.Chunks["TXLIST"]; - LoadTextures(textureList); - if (Dump) DumpTextureList(textureList); - - var wr = (WorldRep)_file.Chunks["WREXT"]; - BuildMeshes(wr.Cells, wr.DataHeader.LightmapFormat == 2); + UseChunk("TXLIST", LoadTextures); + UseChunk("WREXT", BuildWrMeshes); } - private void BuildMeshes(WorldRep.Cell[] cells, bool lmHdr) + private void UseChunk(string name, Action action) { - GD.Print($"HDR: {lmHdr}"); + if (_file.Chunks.TryGetValue(name, out var value)) + { + action((T)value); + } + else + { + GD.Print($"No chunk found/loaded: {name}"); + } + } + + private void BuildWrMeshes(WorldRep worldRep) + { + var cells = worldRep.Cells; + var lmHdr = worldRep.DataHeader.LightmapFormat == 2; + GD.Print($"HDR Lightmap: {lmHdr}"); var packingRects = new List(); var surfaceDataMap = new Dictionary(); @@ -345,6 +354,8 @@ public partial class Mission : Node3D GD.Print($"Failed to load texture: {path}"); } } + + if (Dump) DumpTextureList(textureList); } private static void DumpTextureList(TxList textureList)