Add initial support for case sensitivity
This commit is contained in:
parent
aaf93477d0
commit
10da283f02
|
@ -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}");
|
||||
|
|
Loading…
Reference in New Issue