millorat printWithDots() i Resource::List per a calcular el nom de fitxer mes llarg correctament
Some checks failed
Release / build-windows (push) Has been cancelled
Release / create-release (push) Has been cancelled
Release / build-linux (push) Has been cancelled

This commit is contained in:
2025-11-23 22:18:41 +01:00
parent 1a6185b3aa
commit 59e6af62ba
10 changed files with 45 additions and 17 deletions

View File

@@ -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::Data>(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<Text>(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());
}
}

View File

@@ -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

View File

@@ -39,6 +39,7 @@ class List {
[[nodiscard]] auto loadData(const std::string& filename) const -> std::vector<uint8_t>; // Carga datos del archivo
[[nodiscard]] auto getListByType(Type type) const -> std::vector<std::string>;
[[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<std::string, Item> 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