From 1508ed111d1b4ba43811672173fffdd2892590ae Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sat, 10 Aug 2024 13:15:06 +0100 Subject: [PATCH] Load TGA textures --- project/code/Mission.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/project/code/Mission.cs b/project/code/Mission.cs index e303988..553badb 100644 --- a/project/code/Mission.cs +++ b/project/code/Mission.cs @@ -7,6 +7,7 @@ using RectpackSharp; using System; using System.Collections.Generic; using System.IO; +using System.Linq; namespace KeepersCompound; @@ -367,6 +368,11 @@ public partial class Mission : Node3D private void LoadTextures(TxList textureList) { + static string PathToKey(string baseDir, string path) + { + return path.TrimPrefix(baseDir).GetBaseName().ToLower(); + } + // TODO: This has hardcoded .png extension and relies on you placing extracted and converted images in godot user directory // Collect all the fm textures here to help with case sensitivity :) @@ -376,13 +382,19 @@ public partial class Mission : Node3D var dirPaths = Directory.GetDirectories(baseDir, "fam", options); options.RecurseSubdirectories = true; var texturePaths = new Dictionary(); + + // Godot doesn't support runtime DDS :) + // TODO: Load DDS BMP PCX GIF CEL + string[] validExtensions = { "png", "tga" }; foreach (var dirPath in dirPaths) { - var paths = Directory.GetFiles(dirPath, "*.png", options); - foreach (var path in paths) + foreach (var path in Directory.EnumerateFiles(dirPath, "*", options)) { - var key = path.TrimPrefix(baseDir).GetBaseName().ToLower(); - texturePaths.Add(key, path); + if (validExtensions.Contains(path.GetExtension().ToLower())) + { + // TODO: This only adds the first one found rather than the highest priority + texturePaths.TryAdd(PathToKey(baseDir, path), path); + } } }