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);

View File

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

View File

@@ -104,6 +104,10 @@ auto Stats::loadFromFile(const std::string& file_path, std::vector<StatsData>& 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;