GamepadManager::saveToFile() no guarda el nom del mando si no existeix

This commit is contained in:
2025-08-08 21:20:40 +02:00
parent 0fc83cf9c1
commit c7f5fed797

View File

@@ -2,16 +2,16 @@
#include <SDL3/SDL.h> // Para SDL_ScaleMode
#include <algorithm> // Para copy
#include <array> // Para array
#include <cstddef> // Para size_t
#include <exception> // Para exception
#include <fstream> // Para basic_ostream, operator<<, basic_ofstream, basic_ostream::operator<<, ofstream
#include <memory> // Para shared_ptr, swap
#include <stdexcept> // Para out_of_range, invalid_argument
#include <string> // Para char_traits, string, allocator, operator==, swap, operator<<, basic_string, stoi
#include <string_view> // Para string_view
#include <vector> // Para vector
#include <algorithm> // Para copy
#include <array> // Para array
#include <cstddef> // Para size_t
#include <exception> // Para exception
#include <fstream> // Para basic_ostream, operator<<, basic_ofstream, basic_ostream::operator<<, ofstream
#include <memory> // Para shared_ptr, swap
#include <stdexcept> // Para out_of_range, invalid_argument
#include <string> // Para char_traits, string, allocator, operator==, swap, operator<<, basic_string, stoi
#include <string_view> // Para string_view
#include <vector> // Para vector
#include "difficulty.h" // Para Code
#include "input.h" // Para Input
@@ -158,11 +158,15 @@ class GamepadManager {
std::swap(gamepads_[0].path, gamepads_[1].path);
}
// Para serialización/deserialización
void saveToFile(std::ofstream& file) const {
for (size_t i = 0; i < MAX_PLAYERS; ++i) {
const auto& gamepad = gamepads_[i];
file << "controller." << i << ".name=" << gamepad.name << "\n";
// Guardar el nombre solo si hay path (mando real asignado)
if (!gamepad.path.empty()) {
file << "controller." << i << ".name=" << gamepad.name << "\n";
} else {
file << "controller." << i << ".name=\n"; // vacío
}
file << "controller." << i << ".path=" << gamepad.path << "\n";
file << "controller." << i << ".player=" << static_cast<int>(gamepad.player_id) << "\n";
}