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, 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<Texture>(Screen::get()->getRenderer(), texture_file_path);
// Añadir todas las paletas

View File

@@ -2,6 +2,7 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <algorithm>
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) {

View File

@@ -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<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);
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<char *>(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<Uint8> buffer(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());
throw std::runtime_error("Error al leer el fichero: " + file_path);
}
// Usar la nueva función loadPalette, que devuelve un vector<uint32_t>
GIF::Gif gif;
std::vector<uint32_t> pal = gif.loadPalette(buffer.data());