integrades mes clases amb ResourceHelper

mogudes les dades de la demo a resource.pack
This commit is contained in:
2025-08-19 13:08:37 +02:00
parent 8cfe28922c
commit 6bf8490776
9 changed files with 116 additions and 30 deletions

View File

@@ -225,22 +225,30 @@ auto Texture::loadSurface(const std::string &file_path) -> std::shared_ptr<Surfa
// Libera la superficie actual
unloadSurface();
// Abrir el archivo usando std::ifstream para manejo automático del recurso
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
std::streamsize size = file.tellg();
file.seekg(0, std::ios::beg);
// Obtener el tamaño del archivo
std::streamsize size = file.tellg();
file.seekg(0, std::ios::beg);
// Leer el contenido del archivo en un buffer
std::vector<Uint8> buffer(size);
if (!file.read(reinterpret_cast<char *>(buffer.data()), size)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al leer el fichero %s", file_path.c_str());
throw std::runtime_error("Error al leer el fichero: " + file_path);
// Leer el contenido del archivo en un buffer
buffer.resize(size);
if (!file.read(reinterpret_cast<char *>(buffer.data()), size)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al leer el fichero %s", file_path.c_str());
throw std::runtime_error("Error al leer el fichero: " + file_path);
}
}
// Crear un objeto Gif y llamar a la función loadGif