This commit is contained in:
2025-11-03 09:58:19 +01:00
parent 3f1c737247
commit d4030ec1bc
4 changed files with 26 additions and 30 deletions
+12 -14
View File
@@ -10,8 +10,7 @@
#include "resource_loader.hpp"
namespace Jdd {
namespace ResourceHelper {
namespace Jdd::ResourceHelper {
static bool resource_system_initialized = false;
@@ -106,7 +105,7 @@ auto getPackPath(const std::string& asset_path) -> std::string {
std::string path = asset_path;
// Convert backslashes to forward slashes
std::replace(path.begin(), path.end(), '\\', '/');
std::ranges::replace(path, '\\', '/');
// Remove leading slashes
while (!path.empty() && path[0] == '/') {
@@ -114,25 +113,25 @@ auto getPackPath(const std::string& asset_path) -> std::string {
}
// Remove "./" prefix if present
if (path.find("./") == 0) {
if (path.starts_with("./")) {
path = path.substr(2);
}
// Remove "../" prefixes (for macOS bundle paths in development)
while (path.find("../") == 0) {
while (path.starts_with("../")) {
path = path.substr(3);
}
// Remove "Resources/" prefix if present (for macOS bundle)
const std::string resources_prefix = "Resources/";
if (path.find(resources_prefix) == 0) {
path = path.substr(resources_prefix.length());
const std::string RESOURCES_PREFIX = "Resources/";
if (path.starts_with(RESOURCES_PREFIX)) {
path = path.substr(RESOURCES_PREFIX.length());
}
// Remove "data/" prefix if present
const std::string data_prefix = "data/";
if (path.find(data_prefix) == 0) {
path = path.substr(data_prefix.length());
const std::string DATA_PREFIX = "data/";
if (path.starts_with(DATA_PREFIX)) {
path = path.substr(DATA_PREFIX.length());
}
return path;
@@ -141,7 +140,7 @@ auto getPackPath(const std::string& asset_path) -> std::string {
// Check if file should use resource pack
auto shouldUseResourcePack(const std::string& filepath) -> bool {
std::string path = filepath;
std::replace(path.begin(), path.end(), '\\', '/');
std::ranges::replace(path, '\\', '/');
// Don't use pack for most config files (except config/assets.txt which is loaded
// directly via ResourceLoader::loadAssetsConfig() in release builds)
@@ -174,5 +173,4 @@ auto isPackLoaded() -> bool {
return ResourceLoader::get().isPackLoaded();
}
} // namespace ResourceHelper
} // namespace Jdd
} // namespace Jdd::ResourceHelper