fix gaffe with spritesheets

This commit is contained in:
shweet committed 2026-05-25 22:23:27 -04:00
1 parent 93707b234c
commit 8a48eece86
6 files changed
+83 -18

No files matched your search

+44 -4
View File
@@ -118,15 +118,55 @@ namespace anm2ed::util::path
return path;
}
std::filesystem::path lower_case_backslash_handle(const std::filesystem::path& path)
std::filesystem::path backslash_handle(const std::filesystem::path& path)
{
auto newPath = path;
if (is_exist(newPath)) return newPath;
newPath = backslash_replace(newPath);
if (is_exist(newPath)) return newPath;
newPath = to_lower(newPath);
return newPath;
}
std::filesystem::path case_insensitive_find(const std::filesystem::path& path)
{
auto handledPath = backslash_handle(path);
if (is_exist(handledPath)) return handledPath;
auto resolvedPath = handledPath.root_path();
for (const auto& part : handledPath.relative_path())
{
auto candidate = resolvedPath / part;
if (is_exist(candidate))
{
resolvedPath = candidate;
continue;
}
auto parent = resolvedPath.empty() ? std::filesystem::path(".") : resolvedPath;
std::error_code ec{};
bool isFound{};
if (std::filesystem::is_directory(parent, ec))
{
auto partLower = to_lower(part);
std::filesystem::directory_iterator it(parent, ec);
std::filesystem::directory_iterator end{};
for (; !ec && it != end; it.increment(ec))
if (to_lower(it->path().filename()) == partLower)
{
resolvedPath /= it->path().filename();
isFound = true;
break;
}
}
if (!isFound) resolvedPath = candidate;
}
if (is_exist(resolvedPath)) return resolvedPath;
auto lowerPath = to_lower(handledPath);
if (is_exist(lowerPath)) return lowerPath;
return handledPath;
}
}
+2 -1
View File
@@ -18,5 +18,6 @@ namespace anm2ed::util::path
bool ensure_directory(const std::filesystem::path&);
std::filesystem::path lower_case_backslash_handle(const std::filesystem::path&);
std::filesystem::path backslash_handle(const std::filesystem::path&);
std::filesystem::path case_insensitive_find(const std::filesystem::path&);
}