faltaven mes integracions de texture amb ResourceHelper

This commit is contained in:
2025-08-19 13:22:38 +02:00
parent 58cf78e1e3
commit 43788bb01a
3 changed files with 29 additions and 16 deletions

View File

@@ -567,7 +567,7 @@ void Resource::createPlayerTextures() {
texture->setPaletteColor(0, 19, param.player.default_shirt[player_idx].light.TO_UINT32()); 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()); texture->setPaletteColor(0, 56, param.player.outline_color[player_idx].TO_UINT32());
} else { } else {
// Crear textura nueva desde archivo // Crear textura nueva desde archivo usando ResourceHelper
texture = std::make_shared<Texture>(Screen::get()->getRenderer(), texture_file_path); texture = std::make_shared<Texture>(Screen::get()->getRenderer(), texture_file_path);
// Añadir todas las paletas // Añadir todas las paletas

View File

@@ -2,6 +2,7 @@
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <algorithm>
namespace ResourceHelper { namespace ResourceHelper {
static bool resource_system_initialized = false; static bool resource_system_initialized = false;
@@ -74,6 +75,9 @@ namespace ResourceHelper {
std::string getPackPath(const std::string& asset_path) { std::string getPackPath(const std::string& asset_path) {
std::string pack_path = 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 // Remover prefijo "data/" si existe
size_t data_pos = pack_path.find("data/"); size_t data_pos = pack_path.find("data/");
if (data_pos != std::string::npos) { if (data_pos != std::string::npos) {

View File

@@ -304,23 +304,32 @@ void Texture::setPaletteColor(int palette, int index, Uint32 color) {
auto Texture::loadPaletteFromFile(const std::string &file_path) -> Palette { auto Texture::loadPaletteFromFile(const std::string &file_path) -> Palette {
Palette palette; Palette palette;
// Abrir el archivo GIF std::vector<Uint8> 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); std::ifstream file(file_path, std::ios::binary | std::ios::ate);
if (!file) { if (!file) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str());
throw std::runtime_error("Fichero no encontrado: " + file_path); throw std::runtime_error("Fichero no encontrado: " + file_path);
} }
printWithDots("Palette : ", getFileName(file_path), "[ LOADED ]");
// Obtener el tamaño del archivo y leerlo en un buffer // Obtener el tamaño del archivo y leerlo en un buffer
std::streamsize size = file.tellg(); std::streamsize size = file.tellg();
file.seekg(0, std::ios::beg); file.seekg(0, std::ios::beg);
std::vector<Uint8> buffer(size); buffer.resize(size);
if (!file.read(reinterpret_cast<char *>(buffer.data()), size)) { if (!file.read(reinterpret_cast<char *>(buffer.data()), size)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: No se pudo leer completamente el fichero %s", file_path.c_str()); 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); throw std::runtime_error("Error al leer el fichero: " + file_path);
} }
}
printWithDots("Palette : ", getFileName(file_path), "[ LOADED ]");
// Usar la nueva función loadPalette, que devuelve un vector<uint32_t> // Usar la nueva función loadPalette, que devuelve un vector<uint32_t>
GIF::Gif gif; GIF::Gif gif;