Add initial support for case sensitivity

This commit is contained in:
Jarrod Doyle 2024-08-07 20:10:45 +01:00
parent aaf93477d0
commit 10da283f02
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 32 additions and 13 deletions

View File

@ -370,13 +370,21 @@ public partial class Mission : Node3D
private void LoadTextures(TxList textureList) private void LoadTextures(TxList textureList)
{ {
var options = new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive };
var dirPaths = Directory.GetDirectories(FileName.GetBaseDir(), "fam", options);
var fmFamFiles = Array.Empty<string>();
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: This has hardcoded .png extension and relies on you placing extracted and converted images in godot user directory
// TODO: Use PathJoin // TODO: Use PathJoin
var count = textureList.ItemCount; var count = textureList.ItemCount;
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
{ {
var item = textureList.Items[i]; var item = textureList.Items[i];
var path = "/"; var path = "";
for (var j = 0; j < item.Tokens.Length; j++) for (var j = 0; j < item.Tokens.Length; j++)
{ {
var token = item.Tokens[j]; var token = item.Tokens[j];
@ -387,22 +395,33 @@ public partial class Mission : Node3D
path += $"{textureList.Tokens[token - 1]}/"; path += $"{textureList.Tokens[token - 1]}/";
} }
path += item.Name + ".png"; // Hardcoded extension! path += item.Name;
// TODO: It's case sensitive :) var foundInFmPath = false;
var fmFamPath = Path.GetDirectoryName(FileName).PathJoin(path); foreach (var famFile in fmFamFiles)
if (File.Exists(fmFamPath))
{ {
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}"); if (File.Exists(ProjectSettings.GlobalizePath($"user://textures/{path}.png")))
} {
else path = ProjectSettings.GlobalizePath($"user://textures/{path}.png");
{ }
GD.Print($"Failed to find texture: {path}"); else
path = "user://textures/jorge.png"; {
GD.Print($"Failed to find texture: {path}");
path = "user://textures/jorge.png";
}
} }
if (Dump) GD.Print($"Loading texture: {path}"); if (Dump) GD.Print($"Loading texture: {path}");