diff --git a/source/asset.cpp b/source/asset.cpp index 6c0a408..b53b8e0 100644 --- a/source/asset.cpp +++ b/source/asset.cpp @@ -9,6 +9,7 @@ #include // 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 { + 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, diff --git a/source/asset.h b/source/asset.h index a2a4736..2237b38 100644 --- a/source/asset.h +++ b/source/asset.h @@ -4,6 +4,7 @@ #include // Para unordered_map #include // Para move #include // Para vector +#include // Para uint8_t // --- Clase Asset: gestor optimizado de recursos (singleton) --- class Asset { @@ -33,6 +34,7 @@ class Asset { void add(const std::string &file_path, Type type, bool required = true, bool absolute = false); void loadFromFile(const std::string &config_file_path, const std::string &prefix = "", const std::string &system_folder = ""); // Con soporte para variables [[nodiscard]] auto get(const std::string &filename) const -> std::string; // Mantener nombre original + [[nodiscard]] auto loadData(const std::string &filename) const -> std::vector; // Carga datos del archivo [[nodiscard]] auto check() const -> bool; [[nodiscard]] auto getListByType(Type type) const -> std::vector; [[nodiscard]] auto exists(const std::string &filename) const -> bool; // Nueva función para verificar existencia diff --git a/source/screen.cpp b/source/screen.cpp index eaa0967..e80f554 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -224,8 +224,10 @@ void Screen::renderInfo() { void Screen::loadShaders() { if (shader_source_.empty()) { const std::string GLSL_FILE = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl"; - std::ifstream f(Asset::get()->get(GLSL_FILE).c_str()); - shader_source_ = std::string((std::istreambuf_iterator(f)), std::istreambuf_iterator()); + auto data = Asset::get()->loadData(GLSL_FILE); + if (!data.empty()) { + shader_source_ = std::string(data.begin(), data.end()); + } } }