Load TGA textures

This commit is contained in:
Jarrod Doyle 2024-08-10 13:15:06 +01:00
parent 1b661cbc7f
commit 1508ed111d
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 16 additions and 4 deletions

View File

@ -7,6 +7,7 @@ using RectpackSharp;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
namespace KeepersCompound; namespace KeepersCompound;
@ -367,6 +368,11 @@ public partial class Mission : Node3D
private void LoadTextures(TxList textureList) 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 // 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 :) // 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); var dirPaths = Directory.GetDirectories(baseDir, "fam", options);
options.RecurseSubdirectories = true; options.RecurseSubdirectories = true;
var texturePaths = new Dictionary<string, string>(); var texturePaths = new Dictionary<string, string>();
// Godot doesn't support runtime DDS :)
// TODO: Load DDS BMP PCX GIF CEL
string[] validExtensions = { "png", "tga" };
foreach (var dirPath in dirPaths) foreach (var dirPath in dirPaths)
{ {
var paths = Directory.GetFiles(dirPath, "*.png", options); foreach (var path in Directory.EnumerateFiles(dirPath, "*", options))
foreach (var path in paths)
{ {
var key = path.TrimPrefix(baseDir).GetBaseName().ToLower(); if (validExtensions.Contains(path.GetExtension().ToLower()))
texturePaths.Add(key, path); {
// TODO: This only adds the first one found rather than the highest priority
texturePaths.TryAdd(PathToKey(baseDir, path), path);
}
} }
} }