diff --git a/project/code/LGS/Database/File.cs b/project/code/LGS/Database/File.cs index c83afef..af363ba 100644 --- a/project/code/LGS/Database/File.cs +++ b/project/code/LGS/Database/File.cs @@ -98,6 +98,7 @@ public class DbFile { // "AI_ROOM_DB" => new AiRoomDb(), // "AICONVERSE" => new AiConverseChunk(), + "TXLIST" => new TxList(), "WREXT" => new WorldRep(), _ => new GenericChunk(), }; diff --git a/project/code/Mission.cs b/project/code/Mission.cs index f897bd0..ba400e9 100644 --- a/project/code/Mission.cs +++ b/project/code/Mission.cs @@ -6,6 +6,7 @@ using KeepersCompound.TMV.UI; using RectpackSharp; using System; using System.Collections.Generic; +using System.IO; namespace KeepersCompound; @@ -18,11 +19,16 @@ public partial class Mission : Node3D public bool Build = false; [Export] public bool Clear = false; + [Export] + public bool Dump = false; DbFile _file; + List _textures; // TODO: Make these textures :) public override void _Ready() { + _textures = new List(); + var missionSelector = GetNode("%MissionSelector") as MissionSelector; missionSelector.LoadMission += (string path) => { @@ -69,6 +75,10 @@ public partial class Mission : Node3D ClearMap(); _file = new(FileName); + var textureList = (TxList)_file.Chunks["TXLIST"]; + // LoadTextures(textureList); + if (Dump) DumpTextureList(textureList); + var wr = (WorldRep)_file.Chunks["WREXT"]; foreach (var cell in wr.Cells) @@ -152,6 +162,10 @@ public partial class Mission : Node3D rawColour += lightmap.GetPixel(l, x, y); } var colour = new Color(MathF.Min(rawColour.X, 1.0f), MathF.Min(rawColour.Y, 1.0f), MathF.Min(rawColour.Z, 1.0f), MathF.Min(rawColour.W, 1.0f)); + + // !HACK: lol just overwriting the lightmap :xdd: + // var texIdx = cell.RenderPolys[rect.Id].TextureId; + // colour = _textures[texIdx].GetPixel((int)x, (int)y); image.SetPixel((int)(rect.X + x), (int)(rect.Y + y), colour); } } @@ -289,4 +303,58 @@ public partial class Mission : Node3D return uvIdxs; } + + private void LoadTextures(TxList textureList) + { + // TODO: This has hardcoded .png extension and relies on you placing extracted and converted images in godot user directory + var count = textureList.ItemCount; + for (var i = 0; i < count; i++) + { + var item = textureList.Items[i]; + var path = "/"; + for (var j = 0; j < item.Tokens.Length; j++) + { + var token = item.Tokens[j]; + if (token == 0) + { + break; + } + + path += $"{textureList.Tokens[token - 1]}/"; + } + path += item.Name + ".png"; // Hardcoded extension! + + if (File.Exists(FileName + path)) + { + path = FileName + path; + } + else if (File.Exists(ProjectSettings.GlobalizePath($"user://textures{path}"))) + { + path = ProjectSettings.GlobalizePath($"user://textures{path}"); + } + else + { + path = "user://textures/jorge.png"; + } + + if (Dump) GD.Print($"Loading texture: {path}"); + // _textures.Add(ImageTexture.CreateFromImage(Image.LoadFromFile(path))); + _textures.Add(Image.LoadFromFile(path)); + } + } + + private static void DumpTextureList(TxList textureList) + { + GD.Print($"TXLIST:\n BlockSize: {textureList.BlockSize}\n ItemCount: {textureList.ItemCount}\n TokenCount: {textureList.TokenCount}\n Tokens:"); + for (var i = 0; i < textureList.TokenCount; i++) + { + GD.Print($" {i}: {textureList.Tokens[i]}"); + } + GD.Print($" Items:"); + for (var i = 0; i < textureList.ItemCount; i++) + { + var item = textureList.Items[i]; + GD.Print($" {i}:\n Tokens: [{item.Tokens[0]}, {item.Tokens[1]}, {item.Tokens[2]}, {item.Tokens[3]}]\n Name: {item.Name}"); + } + } } \ No newline at end of file diff --git a/project/scenes/main.tscn b/project/scenes/main.tscn index 24e5572..a7e066d 100644 --- a/project/scenes/main.tscn +++ b/project/scenes/main.tscn @@ -15,6 +15,7 @@ ssao_enabled = true transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.110309, 0.187101, -0.461656) script = ExtResource("1_xhqt7") FileName = "/home/jarrod/Dev/thief/de-specs/test_data/rose-garden.mis" +Dump = true [node name="Camera3D" type="Camera3D" parent="."] script = ExtResource("2_w5otl")