From 83ee9c26492123bd9e2036feda3c106bf2164482 Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 19 Aug 2025 13:25:12 +0200 Subject: [PATCH] integrat animated_sprite amb ResourceHelper --- source/animated_sprite.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/source/animated_sprite.cpp b/source/animated_sprite.cpp index 90e8f64..92adf3b 100644 --- a/source/animated_sprite.cpp +++ b/source/animated_sprite.cpp @@ -10,21 +10,39 @@ #include // Para pair #include "texture.h" // Para Texture +#include "resource_helper.h" // Para ResourceHelper #include "utils.h" // Para printWithDots // Carga las animaciones en un vector(Animations) desde un fichero auto loadAnimationsFromFile(const std::string& file_path) -> AnimationsFileBuffer { - std::ifstream file(file_path); - if (!file) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str()); - throw std::runtime_error("Fichero no encontrado: " + file_path); + // Intentar cargar desde ResourceHelper primero + auto resource_data = ResourceHelper::loadFile(file_path); + std::istringstream stream; + bool using_resource_data = false; + + if (!resource_data.empty()) { + std::string content(resource_data.begin(), resource_data.end()); + stream.str(content); + using_resource_data = true; } + + // Fallback a archivo directo + std::ifstream file; + if (!using_resource_data) { + file.open(file_path); + if (!file) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str()); + throw std::runtime_error("Fichero no encontrado: " + file_path); + } + } + + std::istream& input_stream = using_resource_data ? stream : static_cast(file); printWithDots("Animation : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]"); std::vector buffer; std::string line; - while (std::getline(file, line)) { + while (std::getline(input_stream, line)) { if (!line.empty()) { buffer.push_back(line); }