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)
|
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,23 +395,34 @@ 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")))
|
||||||
|
{
|
||||||
|
path = ProjectSettings.GlobalizePath($"user://textures/{path}.png");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GD.Print($"Failed to find texture: {path}");
|
GD.Print($"Failed to find texture: {path}");
|
||||||
path = "user://textures/jorge.png";
|
path = "user://textures/jorge.png";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Dump) GD.Print($"Loading texture: {path}");
|
if (Dump) GD.Print($"Loading texture: {path}");
|
||||||
_textures.Add(ImageTexture.CreateFromImage(Image.LoadFromFile(path)));
|
_textures.Add(ImageTexture.CreateFromImage(Image.LoadFromFile(path)));
|
||||||
|
|
Loading…
Reference in New Issue