From 10da283f02aa66c26dd9cb8c13ab2b2f2f81cd98 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Wed, 7 Aug 2024 20:10:45 +0100 Subject: [PATCH] Add initial support for case sensitivity --- project/code/Mission.cs | 45 +++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/project/code/Mission.cs b/project/code/Mission.cs index bea09a7..98082bd 100644 --- a/project/code/Mission.cs +++ b/project/code/Mission.cs @@ -370,13 +370,21 @@ public partial class Mission : Node3D private void LoadTextures(TxList textureList) { + var options = new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive }; + var dirPaths = Directory.GetDirectories(FileName.GetBaseDir(), "fam", options); + var fmFamFiles = Array.Empty(); + if (!dirPaths.IsEmpty()) + { + fmFamFiles = Directory.GetFiles(dirPaths[0], "*", SearchOption.AllDirectories); + } + // TODO: This has hardcoded .png extension and relies on you placing extracted and converted images in godot user directory // TODO: Use PathJoin var count = textureList.ItemCount; for (var i = 0; i < count; i++) { var item = textureList.Items[i]; - var path = "/"; + var path = ""; for (var j = 0; j < item.Tokens.Length; j++) { var token = item.Tokens[j]; @@ -387,22 +395,33 @@ public partial class Mission : Node3D path += $"{textureList.Tokens[token - 1]}/"; } - path += item.Name + ".png"; // Hardcoded extension! + path += item.Name; - // TODO: It's case sensitive :) - var fmFamPath = Path.GetDirectoryName(FileName).PathJoin(path); - if (File.Exists(fmFamPath)) + var foundInFmPath = false; + foreach (var famFile in fmFamFiles) { - path = fmFamPath; + var baseName = famFile.GetBaseName().ToLower(); + var ext = famFile.GetExtension().ToLower(); + // TODO: godot supports more than png + if (baseName.EndsWith(path.ToLower()) && ext == "png") + { + foundInFmPath = true; + path = famFile; + break; + } } - else if (File.Exists(ProjectSettings.GlobalizePath($"user://textures{path}"))) + + if (!foundInFmPath) { - path = ProjectSettings.GlobalizePath($"user://textures{path}"); - } - else - { - GD.Print($"Failed to find texture: {path}"); - path = "user://textures/jorge.png"; + if (File.Exists(ProjectSettings.GlobalizePath($"user://textures/{path}.png"))) + { + path = ProjectSettings.GlobalizePath($"user://textures/{path}.png"); + } + else + { + GD.Print($"Failed to find texture: {path}"); + path = "user://textures/jorge.png"; + } } if (Dump) GD.Print($"Loading texture: {path}");