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)
|
||||
{
|
||||
// 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 dirPaths = Directory.GetDirectories(FileName.GetBaseDir(), "fam", options);
|
||||
var fmFamFiles = Array.Empty<string>();
|
||||
if (!dirPaths.IsEmpty())
|
||||
var dirPaths = Directory.GetDirectories(baseDir, "fam", options);
|
||||
options.RecurseSubdirectories = true;
|
||||
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
|
||||
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];
|
||||
|
@ -397,31 +407,18 @@ public partial class Mission : Node3D
|
|||
}
|
||||
path += item.Name;
|
||||
|
||||
var foundInFmPath = false;
|
||||
foreach (var famFile in fmFamFiles)
|
||||
if (texturePaths.TryGetValue(path.ToLower(), out var newPath))
|
||||
{
|
||||
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;
|
||||
}
|
||||
path = newPath;
|
||||
}
|
||||
|
||||
if (!foundInFmPath)
|
||||
else if (File.Exists(ProjectSettings.GlobalizePath($"user://textures{path}.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";
|
||||
}
|
||||
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