linter
This commit is contained in:
@@ -10,8 +10,7 @@
|
|||||||
|
|
||||||
#include "resource_loader.hpp"
|
#include "resource_loader.hpp"
|
||||||
|
|
||||||
namespace Jdd {
|
namespace Jdd::ResourceHelper {
|
||||||
namespace ResourceHelper {
|
|
||||||
|
|
||||||
static bool resource_system_initialized = false;
|
static bool resource_system_initialized = false;
|
||||||
|
|
||||||
@@ -106,7 +105,7 @@ auto getPackPath(const std::string& asset_path) -> std::string {
|
|||||||
std::string path = asset_path;
|
std::string path = asset_path;
|
||||||
|
|
||||||
// Convert backslashes to forward slashes
|
// Convert backslashes to forward slashes
|
||||||
std::replace(path.begin(), path.end(), '\\', '/');
|
std::ranges::replace(path, '\\', '/');
|
||||||
|
|
||||||
// Remove leading slashes
|
// Remove leading slashes
|
||||||
while (!path.empty() && path[0] == '/') {
|
while (!path.empty() && path[0] == '/') {
|
||||||
@@ -114,25 +113,25 @@ auto getPackPath(const std::string& asset_path) -> std::string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove "./" prefix if present
|
// Remove "./" prefix if present
|
||||||
if (path.find("./") == 0) {
|
if (path.starts_with("./")) {
|
||||||
path = path.substr(2);
|
path = path.substr(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove "../" prefixes (for macOS bundle paths in development)
|
// Remove "../" prefixes (for macOS bundle paths in development)
|
||||||
while (path.find("../") == 0) {
|
while (path.starts_with("../")) {
|
||||||
path = path.substr(3);
|
path = path.substr(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove "Resources/" prefix if present (for macOS bundle)
|
// Remove "Resources/" prefix if present (for macOS bundle)
|
||||||
const std::string resources_prefix = "Resources/";
|
const std::string RESOURCES_PREFIX = "Resources/";
|
||||||
if (path.find(resources_prefix) == 0) {
|
if (path.starts_with(RESOURCES_PREFIX)) {
|
||||||
path = path.substr(resources_prefix.length());
|
path = path.substr(RESOURCES_PREFIX.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove "data/" prefix if present
|
// Remove "data/" prefix if present
|
||||||
const std::string data_prefix = "data/";
|
const std::string DATA_PREFIX = "data/";
|
||||||
if (path.find(data_prefix) == 0) {
|
if (path.starts_with(DATA_PREFIX)) {
|
||||||
path = path.substr(data_prefix.length());
|
path = path.substr(DATA_PREFIX.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
@@ -141,7 +140,7 @@ auto getPackPath(const std::string& asset_path) -> std::string {
|
|||||||
// Check if file should use resource pack
|
// Check if file should use resource pack
|
||||||
auto shouldUseResourcePack(const std::string& filepath) -> bool {
|
auto shouldUseResourcePack(const std::string& filepath) -> bool {
|
||||||
std::string path = filepath;
|
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
|
// Don't use pack for most config files (except config/assets.txt which is loaded
|
||||||
// directly via ResourceLoader::loadAssetsConfig() in release builds)
|
// directly via ResourceLoader::loadAssetsConfig() in release builds)
|
||||||
@@ -174,5 +173,4 @@ auto isPackLoaded() -> bool {
|
|||||||
return ResourceLoader::get().isPackLoaded();
|
return ResourceLoader::get().isPackLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ResourceHelper
|
} // namespace Jdd::ResourceHelper
|
||||||
} // namespace Jdd
|
|
||||||
|
|||||||
@@ -8,8 +8,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Jdd {
|
namespace Jdd::ResourceHelper {
|
||||||
namespace ResourceHelper {
|
|
||||||
|
|
||||||
// Initialize the resource system
|
// Initialize the resource system
|
||||||
// pack_file: Path to resources.pack
|
// pack_file: Path to resources.pack
|
||||||
@@ -37,7 +36,6 @@ auto shouldUseResourcePack(const std::string& filepath) -> bool;
|
|||||||
// Check if pack is loaded
|
// Check if pack is loaded
|
||||||
auto isPackLoaded() -> bool;
|
auto isPackLoaded() -> bool;
|
||||||
|
|
||||||
} // namespace ResourceHelper
|
} // namespace Jdd::ResourceHelper
|
||||||
} // namespace Jdd
|
|
||||||
|
|
||||||
#endif // RESOURCE_HELPER_HPP
|
#endif // RESOURCE_HELPER_HPP
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ namespace Jdd {
|
|||||||
|
|
||||||
// Get singleton instance
|
// Get singleton instance
|
||||||
auto ResourceLoader::get() -> ResourceLoader& {
|
auto ResourceLoader::get() -> ResourceLoader& {
|
||||||
static ResourceLoader instance;
|
static ResourceLoader instance_;
|
||||||
return instance;
|
return instance_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize with a pack file
|
// Initialize with a pack file
|
||||||
|
|||||||
@@ -28,30 +28,30 @@ class ResourceLoader {
|
|||||||
auto resourceExists(const std::string& filename) -> bool;
|
auto resourceExists(const std::string& filename) -> bool;
|
||||||
|
|
||||||
// Check if pack is loaded
|
// Check if pack is loaded
|
||||||
auto isPackLoaded() const -> bool;
|
[[nodiscard]] auto isPackLoaded() const -> bool;
|
||||||
|
|
||||||
// Get pack statistics
|
// Get pack statistics
|
||||||
auto getPackResourceCount() const -> size_t;
|
[[nodiscard]] auto getPackResourceCount() const -> size_t;
|
||||||
|
|
||||||
// Validate pack integrity (checksum)
|
// Validate pack integrity (checksum)
|
||||||
auto validatePack() const -> bool;
|
[[nodiscard]] auto validatePack() const -> bool;
|
||||||
|
|
||||||
// Load assets.txt from pack (for release builds)
|
// Load assets.txt from pack (for release builds)
|
||||||
auto loadAssetsConfig() const -> std::string;
|
[[nodiscard]] auto loadAssetsConfig() const -> std::string;
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
|
// Disable copy/move
|
||||||
|
ResourceLoader(const ResourceLoader&) = delete;
|
||||||
|
auto operator=(const ResourceLoader&) -> ResourceLoader& = delete;
|
||||||
|
ResourceLoader(ResourceLoader&&) = delete;
|
||||||
|
auto operator=(ResourceLoader&&) -> ResourceLoader& = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ResourceLoader() = default;
|
ResourceLoader() = default;
|
||||||
~ResourceLoader() = default;
|
~ResourceLoader() = default;
|
||||||
|
|
||||||
// Disable copy/move
|
|
||||||
ResourceLoader(const ResourceLoader&) = delete;
|
|
||||||
ResourceLoader& operator=(const ResourceLoader&) = delete;
|
|
||||||
ResourceLoader(ResourceLoader&&) = delete;
|
|
||||||
ResourceLoader& operator=(ResourceLoader&&) = delete;
|
|
||||||
|
|
||||||
// Load from filesystem
|
// Load from filesystem
|
||||||
static auto loadFromFilesystem(const std::string& filepath) -> std::vector<uint8_t>;
|
static auto loadFromFilesystem(const std::string& filepath) -> std::vector<uint8_t>;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user