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)
{
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: 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}");