corregides les lectures de fitxers de text en windows. fallava per culpa del final de linea

This commit is contained in:
2025-11-01 18:55:07 +01:00
parent 139d56f8b5
commit 7441fa2b6b
4 changed files with 44 additions and 4 deletions

View File

@@ -30,10 +30,14 @@ auto loadAnimationsFromFile(const std::string& file_path) -> Animations {
std::vector<std::string> 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;
}

View File

@@ -41,17 +41,37 @@ auto loadTextFile(const std::string& file_path) -> std::shared_ptr<TextFile> {
// 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);