From 7441fa2b6be9cb9c1203dbc1cc648c1e6aac9eab Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 1 Nov 2025 18:55:07 +0100 Subject: [PATCH] corregides les lectures de fitxers de text en windows. fallava per culpa del final de linea --- .../rendering/surface_animated_sprite.cpp | 12 +++++++---- source/core/rendering/text.cpp | 20 +++++++++++++++++++ source/game/gameplay/room.cpp | 12 +++++++++++ source/game/gameplay/stats.cpp | 4 ++++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/source/core/rendering/surface_animated_sprite.cpp b/source/core/rendering/surface_animated_sprite.cpp index c32157fb..621275f8 100644 --- a/source/core/rendering/surface_animated_sprite.cpp +++ b/source/core/rendering/surface_animated_sprite.cpp @@ -30,10 +30,14 @@ auto loadAnimationsFromFile(const std::string& file_path) -> Animations { std::vector buffer; std::string line; while (std::getline(stream, line)) { - if (!line.empty()) { - buffer.push_back(line); - } - } + // Eliminar \r de Windows line endings + if (!line.empty() && line.back() == '\r') { + line.pop_back(); + } + if (!line.empty()) { + buffer.push_back(line); + } + } return buffer; } diff --git a/source/core/rendering/text.cpp b/source/core/rendering/text.cpp index 74e46d5f..2bd42dab 100644 --- a/source/core/rendering/text.cpp +++ b/source/core/rendering/text.cpp @@ -41,17 +41,37 @@ auto loadTextFile(const std::string& file_path) -> std::shared_ptr { // Lee los dos primeros valores del fichero std::getline(stream, buffer); + // Remove Windows line ending if present + if (!buffer.empty() && buffer.back() == '\r') { + buffer.pop_back(); + } std::getline(stream, buffer); + // Remove Windows line ending if present + if (!buffer.empty() && buffer.back() == '\r') { + buffer.pop_back(); + } tf->box_width = std::stoi(buffer); std::getline(stream, buffer); + // Remove Windows line ending if present + if (!buffer.empty() && buffer.back() == '\r') { + buffer.pop_back(); + } std::getline(stream, buffer); + // Remove Windows line ending if present + if (!buffer.empty() && buffer.back() == '\r') { + buffer.pop_back(); + } tf->box_height = std::stoi(buffer); // lee el resto de datos del fichero auto index = 32; auto line_read = 0; while (std::getline(stream, buffer)) { + // Remove Windows line ending if present + if (!buffer.empty() && buffer.back() == '\r') { + buffer.pop_back(); + } // Almacena solo las lineas impares if (line_read % 2 == 1) { tf->offset[index++].w = std::stoi(buffer); diff --git a/source/game/gameplay/room.cpp b/source/game/gameplay/room.cpp index 67457be0..0c3a8647 100644 --- a/source/game/gameplay/room.cpp +++ b/source/game/gameplay/room.cpp @@ -1022,6 +1022,10 @@ auto Room::loadRoomFile(const std::string& file_path, bool verbose) -> Data { // Procesa el fichero linea a linea while (std::getline(stream, line)) { + // Remove Windows line ending if present + if (!line.empty() && line.back() == '\r') { + line.pop_back(); + } // Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo if (line == "[enemy]") { room.enemies.push_back(loadEnemyFromFile(stream, FILE_NAME, verbose)); @@ -1075,6 +1079,10 @@ auto Room::loadEnemyFromFile(std::istream& file, const std::string& file_name, b std::string line; do { std::getline(file, line); + // Remove Windows line ending if present + if (!line.empty() && line.back() == '\r') { + line.pop_back(); + } auto [key, value] = parseKeyValue(line); if (!setEnemy(&enemy, key, value)) { @@ -1095,6 +1103,10 @@ auto Room::loadItemFromFile(std::istream& file, const std::string& file_name, bo std::string line; do { std::getline(file, line); + // Remove Windows line ending if present + if (!line.empty() && line.back() == '\r') { + line.pop_back(); + } auto [key, value] = parseKeyValue(line); if (!setItem(&item, key, value)) { diff --git a/source/game/gameplay/stats.cpp b/source/game/gameplay/stats.cpp index ae253fa5..a5db0d06 100644 --- a/source/game/gameplay/stats.cpp +++ b/source/game/gameplay/stats.cpp @@ -104,6 +104,10 @@ auto Stats::loadFromFile(const std::string& file_path, std::vector& l std::string line; // Procesa el fichero linea a linea while (std::getline(file, line)) { + // Remove Windows line ending if present + if (!line.empty() && line.back() == '\r') { + line.pop_back(); + } // Comprueba que la linea no sea un comentario if (line.substr(0, 1) != "#") { StatsData stat;