From 43788bb01adf78ab58f13181961fd2ee05082c5d Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 19 Aug 2025 13:22:38 +0200 Subject: [PATCH] faltaven mes integracions de texture amb ResourceHelper --- source/resource.cpp | 2 +- source/resource_helper.cpp | 4 ++++ source/texture.cpp | 39 +++++++++++++++++++++++--------------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/source/resource.cpp b/source/resource.cpp index 7466996..0365f53 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -567,7 +567,7 @@ void Resource::createPlayerTextures() { texture->setPaletteColor(0, 19, param.player.default_shirt[player_idx].light.TO_UINT32()); texture->setPaletteColor(0, 56, param.player.outline_color[player_idx].TO_UINT32()); } else { - // Crear textura nueva desde archivo + // Crear textura nueva desde archivo usando ResourceHelper texture = std::make_shared(Screen::get()->getRenderer(), texture_file_path); // Añadir todas las paletas diff --git a/source/resource_helper.cpp b/source/resource_helper.cpp index 685bf9f..82af104 100644 --- a/source/resource_helper.cpp +++ b/source/resource_helper.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace ResourceHelper { static bool resource_system_initialized = false; @@ -74,6 +75,9 @@ namespace ResourceHelper { std::string getPackPath(const std::string& asset_path) { std::string pack_path = asset_path; + // Normalizar separadores de path a '/' + std::replace(pack_path.begin(), pack_path.end(), '\\', '/'); + // Remover prefijo "data/" si existe size_t data_pos = pack_path.find("data/"); if (data_pos != std::string::npos) { diff --git a/source/texture.cpp b/source/texture.cpp index b24d141..e685b23 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -304,24 +304,33 @@ void Texture::setPaletteColor(int palette, int index, Uint32 color) { auto Texture::loadPaletteFromFile(const std::string &file_path) -> Palette { Palette palette; - // Abrir el archivo GIF - std::ifstream file(file_path, std::ios::binary | std::ios::ate); - 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::vector buffer; + + // Intentar cargar desde ResourceHelper primero + auto resource_data = ResourceHelper::loadFile(file_path); + if (!resource_data.empty()) { + buffer = resource_data; + } else { + // Fallback a filesystem directo + std::ifstream file(file_path, std::ios::binary | std::ios::ate); + 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); + } + + // Obtener el tamaño del archivo y leerlo en un buffer + std::streamsize size = file.tellg(); + file.seekg(0, std::ios::beg); + + buffer.resize(size); + if (!file.read(reinterpret_cast(buffer.data()), size)) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: No se pudo leer completamente el fichero %s", file_path.c_str()); + throw std::runtime_error("Error al leer el fichero: " + file_path); + } } + printWithDots("Palette : ", getFileName(file_path), "[ LOADED ]"); - // Obtener el tamaño del archivo y leerlo en un buffer - std::streamsize size = file.tellg(); - file.seekg(0, std::ios::beg); - - std::vector buffer(size); - if (!file.read(reinterpret_cast(buffer.data()), size)) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: No se pudo leer completamente el fichero %s", file_path.c_str()); - throw std::runtime_error("Error al leer el fichero: " + file_path); - } - // Usar la nueva función loadPalette, que devuelve un vector GIF::Gif gif; std::vector pal = gif.loadPalette(buffer.data());