better case insentitive checks
This commit is contained in:
parent
10da283f02
commit
64dde9509d
|
@ -370,21 +370,31 @@ public partial class Mission : Node3D
|
||||||
|
|
||||||
private void LoadTextures(TxList textureList)
|
private void LoadTextures(TxList textureList)
|
||||||
{
|
{
|
||||||
|
// TODO: This has hardcoded .png extension and relies on you placing extracted and converted images in godot user directory
|
||||||
|
|
||||||
|
// Collect all the fm textures here to help with case sensitivity :)
|
||||||
|
// TODO: Only do this on case sensitive systems?
|
||||||
|
var baseDir = FileName.GetBaseDir();
|
||||||
var options = new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive };
|
var options = new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive };
|
||||||
var dirPaths = Directory.GetDirectories(FileName.GetBaseDir(), "fam", options);
|
var dirPaths = Directory.GetDirectories(baseDir, "fam", options);
|
||||||
var fmFamFiles = Array.Empty<string>();
|
options.RecurseSubdirectories = true;
|
||||||
if (!dirPaths.IsEmpty())
|
var texturePaths = new Dictionary<string, string>();
|
||||||
|
foreach (var dirPath in dirPaths)
|
||||||
{
|
{
|
||||||
fmFamFiles = Directory.GetFiles(dirPaths[0], "*", SearchOption.AllDirectories);
|
var paths = Directory.GetFiles(dirPath, "*.png", options);
|
||||||
|
foreach (var path in paths)
|
||||||
|
{
|
||||||
|
var key = path.TrimPrefix(baseDir).GetBaseName().ToLower();
|
||||||
|
texturePaths.Add(key, path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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];
|
||||||
|
@ -397,31 +407,18 @@ public partial class Mission : Node3D
|
||||||
}
|
}
|
||||||
path += item.Name;
|
path += item.Name;
|
||||||
|
|
||||||
var foundInFmPath = false;
|
if (texturePaths.TryGetValue(path.ToLower(), out var newPath))
|
||||||
foreach (var famFile in fmFamFiles)
|
|
||||||
{
|
{
|
||||||
var baseName = famFile.GetBaseName().ToLower();
|
path = newPath;
|
||||||
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}.png")))
|
||||||
if (!foundInFmPath)
|
|
||||||
{
|
{
|
||||||
if (File.Exists(ProjectSettings.GlobalizePath($"user://textures/{path}.png")))
|
path = ProjectSettings.GlobalizePath($"user://textures{path}.png");
|
||||||
{
|
}
|
||||||
path = ProjectSettings.GlobalizePath($"user://textures/{path}.png");
|
else
|
||||||
}
|
{
|
||||||
else
|
GD.Print($"Failed to find texture: {path}");
|
||||||
{
|
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}");
|
||||||
|
|
Loading…
Reference in New Issue