Options: load i save ja no necesiten el fitxer com a parametre

This commit is contained in:
2025-06-14 17:57:47 +02:00
parent eee398802f
commit c8999bff68
3 changed files with 29 additions and 25 deletions

View File

@@ -7,6 +7,7 @@
#include "input.h" // Para InputDeviceToUse
#include "lang.h" // Para Code
#include "utils.h" // Para boolToString, stringToBool, getFileName
#include "asset.h"
namespace Options
{
@@ -30,6 +31,7 @@ namespace Options
// Inicializa las opciones del programa
void init()
{
// Opciones de ventana
window.caption = "Coffee Crisis Arcade Edition";
window.size = 2;
@@ -48,12 +50,13 @@ namespace Options
audio.sound.enabled = true;
audio.sound.volume = 50;
// Opciones de juego
// Opciones de configuracion
settings.difficulty = DifficultyCode::NORMAL;
settings.language = Lang::Code::VALENCIAN;
settings.autofire = true;
settings.shutdown_enabled = false;
settings.clearLastHiScoreEntries();
settings.config_file = Asset::get()->get("config.txt");
// Opciones de control
controllers.clear();
@@ -69,7 +72,7 @@ namespace Options
}
// Carga el fichero de configuración
bool loadFromFile(std::string file_path)
bool loadFromFile()
{
// Inicializa las opciones del programa
init();
@@ -78,13 +81,13 @@ namespace Options
bool success = true;
// Variables para manejar el fichero
std::ifstream file(file_path);
std::ifstream file(settings.config_file);
// Si el fichero se puede abrir
if (file.good())
{
// Procesa el fichero línea a línea
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nReading file: %s", getFileName(file_path).c_str());
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nReading file: %s", getFileName(settings.config_file).c_str());
std::string line;
while (std::getline(file, line))
{
@@ -107,7 +110,7 @@ namespace Options
else
{
// Crea el fichero con los valores por defecto
saveToFile(file_path);
saveToFile();
}
// Normaliza los valores
@@ -122,17 +125,17 @@ namespace Options
}
// Guarda el fichero de configuración
bool saveToFile(std::string file_path)
bool saveToFile()
{
std::ofstream file(file_path);
std::ofstream file(settings.config_file);
if (!file.good())
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: %s can't be opened", getFileName(file_path).c_str());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: %s can't be opened", getFileName(settings.config_file).c_str());
return false;
}
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Writing file: %s", getFileName(file_path).c_str());
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Writing file: %s", getFileName(settings.config_file).c_str());
applyPendingChanges();