integrat Asset amb ResourceHelper

This commit is contained in:
2025-08-19 10:06:52 +02:00
parent ed077c1da5
commit 4b6b89ceb2
3 changed files with 28 additions and 5 deletions

View File

@@ -9,6 +9,7 @@
#include <stdexcept> // Para runtime_error
#include "utils.h" // Para getFileName
#include "resource_helper.h" // Para ResourceHelper
// Singleton
Asset *Asset::instance = nullptr;
@@ -139,6 +140,17 @@ auto Asset::get(const std::string &filename) const -> std::string {
return "";
}
// Carga datos del archivo usando ResourceHelper
auto Asset::loadData(const std::string &filename) const -> std::vector<uint8_t> {
auto it = file_list_.find(filename);
if (it != file_list_.end()) {
return ResourceHelper::loadFile(it->second.file);
}
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: file %s not found for data loading", filename.c_str());
return {};
}
// Verifica si un recurso existe
auto Asset::exists(const std::string &filename) const -> bool {
return file_list_.find(filename) != file_list_.end();
@@ -194,9 +206,16 @@ auto Asset::check() const -> bool {
// Comprueba que existe un fichero
auto Asset::checkFile(const std::string &path) -> bool {
std::ifstream file(path);
bool success = file.good();
file.close();
// Intentar primero con ResourceHelper
auto data = ResourceHelper::loadFile(path);
bool success = !data.empty();
// Si no se encuentra en el pack, intentar con filesystem directo
if (!success) {
std::ifstream file(path);
success = file.good();
file.close();
}
if (!success) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,