diff --git a/source/core/rendering/surface.cpp b/source/core/rendering/surface.cpp index a566672..7014b71 100644 --- a/source/core/rendering/surface.cpp +++ b/source/core/rendering/surface.cpp @@ -16,7 +16,9 @@ #include "core/rendering/gif.hpp" // Para Gif #include "core/rendering/screen.hpp" // Para Screen +#include "core/resources/resource_list.hpp" // Para Resource::List::get()->getPrintWidth #include "core/resources/resource_helper.hpp" // Para ResourceHelper +#include "utils/utils.hpp" // Para printWithDots // Carga una paleta desde un archivo .gif auto loadPalette(const std::string& file_path) -> Palette { @@ -37,7 +39,7 @@ auto loadPalette(const std::string& file_path) -> Palette { std::copy_n(pal.begin(), std::min(pal.size(), palette.size()), palette.begin()); // Mensaje de depuración - printWithDots("Palette : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]"); + printWithDots("Palette : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]", Resource::List::get()->getPrintWidth()); return palette; } @@ -86,7 +88,7 @@ auto readPalFile(const std::string& file_path) -> Palette { } } - printWithDots("Palette : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]"); + printWithDots("Palette : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]", Resource::List::get()->getPrintWidth()); return palette; } @@ -128,7 +130,7 @@ auto Surface::loadSurface(const std::string& file_path) -> SurfaceData { std::memcpy(pixels.get(), raw_pixels.data(), pixel_count); // Crear y devolver directamente el objeto SurfaceData - printWithDots("Surface : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]"); + printWithDots("Surface : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]", Resource::List::get()->getPrintWidth()); return {static_cast(w), static_cast(h), pixels}; } diff --git a/source/core/rendering/surface_animated_sprite.cpp b/source/core/rendering/surface_animated_sprite.cpp index 9fb95ab..533e800 100644 --- a/source/core/rendering/surface_animated_sprite.cpp +++ b/source/core/rendering/surface_animated_sprite.cpp @@ -8,7 +8,8 @@ #include #include "core/rendering/surface.hpp" // Para Surface -#include "core/resources/resource_cache.hpp" // Para Resource +#include "core/resources/resource_cache.hpp" // Para Resource::Cache +#include "core/resources/resource_list.hpp" // Para Resource::List::get()->getPrintWidth #include "core/resources/resource_helper.hpp" // Para ResourceHelper #include "external/fkyaml_node.hpp" // Para fkyaml::node #include "utils/utils.hpp" // Para printWithDots @@ -46,7 +47,7 @@ auto SurfaceAnimatedSprite::loadAnimationsFromYAML(const std::string& file_path, throw std::runtime_error("Animation file not found: " + file_path); } - printWithDots("Animation : ", FILE_NAME, "[ LOADED ]"); + printWithDots("Animation : ", FILE_NAME, "[ LOADED ]", Resource::List::get()->getPrintWidth()); // Parse YAML from string std::string yaml_content(file_data.begin(), file_data.end()); diff --git a/source/core/rendering/text.cpp b/source/core/rendering/text.cpp index e1bd377..fd40d87 100644 --- a/source/core/rendering/text.cpp +++ b/source/core/rendering/text.cpp @@ -11,6 +11,7 @@ #include "core/rendering/screen.hpp" // Para Screen #include "core/rendering/surface.hpp" // Para Surface #include "core/rendering/surface_sprite.hpp" // Para SSprite +#include "core/resources/resource_list.hpp" // Para Resource::List::get()->getPrintWidth #include "core/resources/resource_helper.hpp" // Para ResourceHelper #include "utils/utils.hpp" // Para getFileName, stringToColor, printWithDots @@ -75,7 +76,7 @@ auto Text::loadTextFile(const std::string& file_path) -> std::shared_ptr { line_read++; }; - printWithDots("Text File : ", getFileName(file_path), "[ LOADED ]"); + printWithDots("Text File : ", getFileName(file_path), "[ LOADED ]", Resource::List::get()->getPrintWidth()); // Establece las coordenadas para cada caracter ascii de la cadena y su ancho for (int i = 32; i < 128; ++i) { diff --git a/source/core/rendering/texture.cpp b/source/core/rendering/texture.cpp index 443c322..b5b3306 100644 --- a/source/core/rendering/texture.cpp +++ b/source/core/rendering/texture.cpp @@ -9,7 +9,8 @@ #include #include // Para vector -#include "utils/utils.hpp" // Para getFileName, ColorRGB, printWithDots +#include "core/resources/resource_list.hpp" // Para Resource::List::get()->getPrintWidth +#include "utils/utils.hpp" // Para getFileName, ColorRGB, printWithDots #define STB_IMAGE_IMPLEMENTATION #include "external/stb_image.h" // para stbi_failure_reason, stbi_image_free @@ -51,7 +52,7 @@ auto Texture::loadFromFile(const std::string& file_path) -> bool { std::cerr << "Error: Fichero no encontrado " << getFileName(file_path) << '\n'; throw std::runtime_error("Fichero no encontrado: " + getFileName(file_path)); } - printWithDots("Image : ", getFileName(file_path), "[ LOADED ]"); + printWithDots("Image : ", getFileName(file_path), "[ LOADED ]", Resource::List::get()->getPrintWidth()); int pitch; SDL_PixelFormat pixel_format; diff --git a/source/core/resources/resource_cache.cpp b/source/core/resources/resource_cache.cpp index 2bd3984..0f8c5bb 100644 --- a/source/core/resources/resource_cache.cpp +++ b/source/core/resources/resource_cache.cpp @@ -212,7 +212,7 @@ void Cache::loadSounds() { } sounds_.emplace_back(SoundResource{.name = name, .sound = sound}); - printWithDots("Sound : ", name, "[ LOADED ]"); + printWithDots("Sound : ", name, "[ LOADED ]", List::get()->getPrintWidth()); updateLoadingProgress(); } catch (const std::exception& e) { throwLoadError("SOUND", l, e); @@ -247,7 +247,7 @@ void Cache::loadMusics() { } musics_.emplace_back(MusicResource{.name = name, .music = music}); - printWithDots("Music : ", name, "[ LOADED ]"); + printWithDots("Music : ", name, "[ LOADED ]", List::get()->getPrintWidth()); updateLoadingProgress(1); } catch (const std::exception& e) { throwLoadError("MUSIC", l, e); @@ -325,7 +325,7 @@ void Cache::loadAnimations() { } animations_.emplace_back(AnimationResource{.name = name, .yaml_data = yaml_bytes}); - printWithDots("Animation : ", name, "[ LOADED ]"); + printWithDots("Animation : ", name, "[ LOADED ]", List::get()->getPrintWidth()); updateLoadingProgress(); } catch (const std::exception& e) { throwLoadError("ANIMATION", l, e); @@ -343,7 +343,7 @@ void Cache::loadRooms() { try { auto name = getFileName(l); rooms_.emplace_back(RoomResource{.name = name, .room = std::make_shared(Room::loadYAML(l))}); - printWithDots("Room : ", name, "[ LOADED ]"); + printWithDots("Room : ", name, "[ LOADED ]", List::get()->getPrintWidth()); updateLoadingProgress(); } catch (const std::exception& e) { throwLoadError("ROOM", l, e); @@ -369,7 +369,7 @@ void Cache::createText() { for (const auto& res_info : resources) { texts_.emplace_back(TextResource{.name = res_info.key, .text = std::make_shared(getSurface(res_info.texture_file), getTextFile(res_info.text_file))}); - printWithDots("Text : ", res_info.key, "[ DONE ]"); + printWithDots("Text : ", res_info.key, "[ DONE ]", List::get()->getPrintWidth()); } } diff --git a/source/core/resources/resource_list.cpp b/source/core/resources/resource_list.cpp index 645b41c..bbc1c74 100644 --- a/source/core/resources/resource_list.cpp +++ b/source/core/resources/resource_list.cpp @@ -144,6 +144,9 @@ void List::loadFromString(const std::string& config_content, const std::string& std::cout << "Loaded " << file_list_.size() << " assets from YAML config" << '\n'; + // Calcular el ancho para printWithDots basándose en los nombres de archivo + calculatePrintWidth(); + } catch (const fkyaml::exception& e) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "YAML parsing error: %s", @@ -317,4 +320,21 @@ auto List::parseOptions(const std::string& options, bool& required, bool& absolu } } +// Calcula el ancho para printWithDots basándose en el nombre de archivo más largo +void List::calculatePrintWidth() { + size_t max_filename_length = 0; + + for (const auto& [filename, item] : file_list_) { + if (filename.length() > max_filename_length) { + max_filename_length = filename.length(); + } + } + + // Ancho total = prefijo más largo (12: "Animation : ") + nombre + 2 puntos mínimos + sufijo (10: "[ LOADED ]") + constexpr size_t MAX_PREFIX_LENGTH = 12; // "Animation : " o "Text File : " + constexpr size_t SUFFIX_LENGTH = 10; // "[ LOADED ]" + constexpr size_t MIN_DOTS = 2; // Mínimo de puntos + print_width_ = MAX_PREFIX_LENGTH + max_filename_length + MIN_DOTS + SUFFIX_LENGTH; +} + } // namespace Resource diff --git a/source/core/resources/resource_list.hpp b/source/core/resources/resource_list.hpp index 8988fa0..086e454 100644 --- a/source/core/resources/resource_list.hpp +++ b/source/core/resources/resource_list.hpp @@ -39,6 +39,7 @@ class List { [[nodiscard]] auto loadData(const std::string& filename) const -> std::vector; // Carga datos del archivo [[nodiscard]] auto getListByType(Type type) const -> std::vector; [[nodiscard]] auto exists(const std::string& filename) const -> bool; // Verifica si un asset existe + [[nodiscard]] auto getPrintWidth() const -> size_t { return print_width_; } // Ancho para printWithDots private: // --- Estructuras privadas --- @@ -56,6 +57,7 @@ class List { // --- Variables internas --- std::unordered_map file_list_; // Mapa para búsqueda O(1) std::string executable_path_; // Ruta del ejecutable + size_t print_width_{50}; // Ancho para printWithDots (calculado dinámicamente) // --- Métodos internos --- [[nodiscard]] static auto getTypeName(Type type) -> std::string; // Obtiene el nombre del tipo @@ -63,6 +65,7 @@ class List { void addToMap(const std::string& file_path, Type type, bool required, bool absolute); // Añade archivo al mapa [[nodiscard]] static auto replaceVariables(const std::string& path, const std::string& prefix, const std::string& system_folder) -> std::string; // Reemplaza variables en la ruta static auto parseOptions(const std::string& options, bool& required, bool& absolute) -> void; // Parsea opciones + void calculatePrintWidth(); // Calcula el ancho para printWithDots // --- Constructores y destructor privados (singleton) --- explicit List(std::string executable_path) // Constructor privado diff --git a/source/project.h b/source/project.h index ffe7b44..115ccfe 100644 --- a/source/project.h +++ b/source/project.h @@ -5,5 +5,5 @@ constexpr const char* NAME = "pollo"; constexpr const char* LONG_NAME = "Los pollos hermanos"; constexpr const char* VERSION = "0.1"; constexpr const char* COPYRIGHT = "@2025 JailDesigner"; -constexpr const char* GIT_HASH = "4aa6693"; +constexpr const char* GIT_HASH = "1a6185b"; } // namespace Project diff --git a/source/utils/utils.cpp b/source/utils/utils.cpp index 4af21de..fb8197a 100644 --- a/source/utils/utils.cpp +++ b/source/utils/utils.cpp @@ -320,11 +320,11 @@ auto getPath(const std::string& full_path) -> std::string { } // Imprime por pantalla una linea de texto de tamaño fijo rellena con puntos -void printWithDots(const std::string& text1, const std::string& text2, const std::string& text3) { +void printWithDots(const std::string& text1, const std::string& text2, const std::string& text3, size_t width) { std::cout.setf(std::ios::left, std::ios::adjustfield); std::cout << text1; - std::cout.width(50 - text1.length() - text3.length()); + std::cout.width(static_cast(width - text1.length() - text3.length())); std::cout.fill('.'); std::cout << text2; diff --git a/source/utils/utils.hpp b/source/utils/utils.hpp index d48d2e8..d482f47 100644 --- a/source/utils/utils.hpp +++ b/source/utils/utils.hpp @@ -78,4 +78,4 @@ auto getPath(const std::string& full_path) -> std::string; // Extrae directorio void fillTextureWithColor(SDL_Renderer* renderer, SDL_Texture* texture, Uint8 r, Uint8 g, Uint8 b, Uint8 a); // Rellena textura // OUTPUT Y UTILIDADES DE CONSOLA -void printWithDots(const std::string& text1, const std::string& text2, const std::string& text3); // Imprime línea con puntos \ No newline at end of file +void printWithDots(const std::string& text1, const std::string& text2, const std::string& text3, size_t width); // Imprime línea con puntos \ No newline at end of file