corregida la carrega de config.txt

This commit is contained in:
2025-11-01 19:10:51 +01:00
parent 7441fa2b6b
commit 1dd750ba0c

View File

@@ -14,6 +14,7 @@
#include <utility> // Para pair #include <utility> // Para pair
#include "utils/utils.hpp" // Para stringToBool, boolToString, safeStoi #include "utils/utils.hpp" // Para stringToBool, boolToString, safeStoi
#include "game/defaults.hpp" // Para GameDefaults::VERSION
namespace Options { namespace Options {
// Declaración de funciones internas // Declaración de funciones internas
@@ -97,8 +98,8 @@ auto readConfigFile(const std::string& file_path) -> bool {
// Carga las opciones desde un fichero // Carga las opciones desde un fichero
auto loadFromFile(const std::string& file_path) -> bool { auto loadFromFile(const std::string& file_path) -> bool {
// Versión actual del fichero // Versión esperada del fichero
const std::string CONFIG_VERSION = version; const std::string CONFIG_VERSION = GameDefaults::VERSION;
version = ""; version = "";
// Intenta leer el fichero // Intenta leer el fichero
@@ -144,9 +145,6 @@ auto saveToFile(const std::string& file_path) -> bool {
file << "# Versión de la configuración\n"; file << "# Versión de la configuración\n";
file << "version " << version << "\n"; file << "version " << version << "\n";
file << "\n## CONTROL\n";
file << "# Esquema de control: 0 = Cursores, 1 = OPQ, 2 = WAD\n";
file << "keys " << static_cast<int>(keys) << "\n";
file << "\n## WINDOW\n"; file << "\n## WINDOW\n";
file << "# Zoom de la ventana: 1 = Normal, 2 = Doble, 3 = Triple, ...\n"; file << "# Zoom de la ventana: 1 = Normal, 2 = Doble, 3 = Triple, ...\n";
@@ -183,6 +181,10 @@ auto saveToFile(const std::string& file_path) -> bool {
auto setOptions(const std::string& var, const std::string& value) -> bool { auto setOptions(const std::string& var, const std::string& value) -> bool {
static const std::unordered_map<std::string, std::function<void(const std::string&)>> OPTION_HANDLERS = { static const std::unordered_map<std::string, std::function<void(const std::string&)>> OPTION_HANDLERS = {
{"version", [](const std::string& v) { version = v; }}, {"version", [](const std::string& v) { version = v; }},
{"keys", [](const std::string& v) {
// Parámetro obsoleto, se ignora silenciosamente para compatibilidad con archivos antiguos
(void)v;
}},
{"window.zoom", [](const std::string& v) { {"window.zoom", [](const std::string& v) {
int val = safeStoi(v, GameDefaults::WINDOW_ZOOM); int val = safeStoi(v, GameDefaults::WINDOW_ZOOM);
if (val > 0) { if (val > 0) {