From dc622c7bae24f1258a31c563e9389053c2d4bdd9 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 14 May 2026 20:42:08 +0200 Subject: [PATCH] encamina la resta de loads pel ResourceHelper i restaura SmartSprite::update --- source/core/rendering/animatedsprite.cpp | 11 +++--- source/core/rendering/smartsprite.cpp | 6 ++-- source/core/rendering/text.cpp | 44 ++++++++++++------------ source/game/ui/menu.cpp | 8 ++--- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/source/core/rendering/animatedsprite.cpp b/source/core/rendering/animatedsprite.cpp index f089116..a46e666 100644 --- a/source/core/rendering/animatedsprite.cpp +++ b/source/core/rendering/animatedsprite.cpp @@ -4,7 +4,8 @@ #include // for cout #include // for basic_stringstream -#include "core/rendering/texture.h" // for Texture +#include "core/rendering/texture.h" // for Texture +#include "core/resources/resource_helper.h" // for loadFile (pack + filesystem fallback) // Parser compartido: lee un istream con el formato .ani static auto parseAnimationStream(std::istream &file, Texture *texture, const std::string &filename, bool verbose) -> animatedSprite_t { @@ -96,11 +97,11 @@ static auto parseAnimationStream(std::istream &file, Texture *texture, const std return as; } -// Carga la animación desde un fichero +// Carga la animación desde un fichero (vía ResourceHelper: pack si està inicialitzat, filesystem si no) auto loadAnimationFromFile(Texture *texture, const std::string &filePath, bool verbose) -> animatedSprite_t { const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1); - std::ifstream file(filePath); - if (!file.good()) { + auto bytes = ResourceHelper::loadFile(filePath); + if (bytes.empty()) { if (verbose) { std::cout << "Warning: Unable to open " << filename.c_str() << " file" << '\n'; } @@ -108,7 +109,7 @@ auto loadAnimationFromFile(Texture *texture, const std::string &filePath, bool v as.texture = texture; return as; } - return parseAnimationStream(file, texture, filename, verbose); + return loadAnimationFromMemory(texture, bytes, filename, verbose); } // Carga la animación desde bytes en memoria diff --git a/source/core/rendering/smartsprite.cpp b/source/core/rendering/smartsprite.cpp index d90a761..dcd1048 100644 --- a/source/core/rendering/smartsprite.cpp +++ b/source/core/rendering/smartsprite.cpp @@ -27,8 +27,10 @@ void SmartSprite::init() { // Actualiza la posición y comprueba si ha llegado a su destino void SmartSprite::update() { if (enabled) { - // Actualiza animació + posició (delegant en AnimatedSprite::update) - AnimatedSprite::update(); + // Actualiza només la posició; els SmartSprite no usen animació de + // frames i salten deliberadament AnimatedSprite::animate(). + // NOLINTNEXTLINE(bugprone-parent-virtual-call) + MovingSprite::update(); // Comprueba el movimiento checkMove(); diff --git a/source/core/rendering/text.cpp b/source/core/rendering/text.cpp index 67482b4..89119d4 100644 --- a/source/core/rendering/text.cpp +++ b/source/core/rendering/text.cpp @@ -5,9 +5,10 @@ #include // for cout #include -#include "core/rendering/sprite.h" // for Sprite -#include "core/rendering/texture.h" // for Texture -#include "utils/utils.h" // for color_t +#include "core/rendering/sprite.h" // for Sprite +#include "core/rendering/texture.h" // for Texture +#include "core/resources/resource_helper.h" // for loadFile (pack + filesystem fallback) +#include "utils/utils.h" // for color_t // Parser compartido: rellena un textFile_t desde cualquier istream static void parseTextFileStream(std::istream &rfile, textFile_t &tf) { @@ -38,30 +39,29 @@ static void computeTextFileOffsets(textFile_t &tf) { } } -// Llena una estructuta textFile_t desde un fichero +// Llena una estructuta textFile_t desde un fichero (vía ResourceHelper: pack o filesystem) auto LoadTextFile(const std::string &file, bool verbose) -> textFile_t { - textFile_t tf; - tf.boxWidth = 0; - tf.boxHeight = 0; - for (auto &i : tf.offset) { - i.x = 0; - i.y = 0; - i.w = 0; - } - const std::string filename = file.substr(file.find_last_of("\\/") + 1); - std::ifstream rfile(file); - if (rfile.is_open() && rfile.good()) { - parseTextFileStream(rfile, tf); + auto bytes = ResourceHelper::loadFile(file); + if (bytes.empty()) { if (verbose) { - std::cout << "Text loaded: " << filename.c_str() << '\n'; + std::cout << "Warning: Unable to open " << filename.c_str() << " file" << '\n'; } - } else if (verbose) { - std::cout << "Warning: Unable to open " << filename.c_str() << " file" << '\n'; + textFile_t tf; + tf.boxWidth = 0; + tf.boxHeight = 0; + for (auto &i : tf.offset) { + i.x = 0; + i.y = 0; + i.w = 0; + } + computeTextFileOffsets(tf); + return tf; } - - computeTextFileOffsets(tf); - return tf; + if (verbose) { + std::cout << "Text loaded: " << filename.c_str() << '\n'; + } + return LoadTextFileFromMemory(bytes, verbose); } // Llena una estructura textFile_t desde bytes en memoria diff --git a/source/game/ui/menu.cpp b/source/game/ui/menu.cpp index bbd6272..f1abaab 100644 --- a/source/game/ui/menu.cpp +++ b/source/game/ui/menu.cpp @@ -147,14 +147,14 @@ bool Menu::parseFromStream(std::istream &file, const std::string &filename) { return success; } -// Carga la configuración del menu desde un archivo de texto +// Carga la configuración del menu (vía ResourceHelper: pack si està inicialitzat, filesystem si no) bool Menu::load(const std::string &file_path) { const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1); - std::ifstream file(file_path); - if (!file.good()) { + auto bytes = ResourceHelper::loadFile(file_path); + if (bytes.empty()) { return false; } - return parseFromStream(file, filename); + return loadFromBytes(bytes, filename); } // Carga el menu desde bytes en memoria