eliminat Options::console
This commit is contained in:
@@ -106,33 +106,25 @@ void Cheevos::loadFromFile() { // NOLINT(readability-convert-member-functions-t
|
||||
|
||||
// El fichero no existe
|
||||
if (!file) {
|
||||
if (Options::console) {
|
||||
std::cout << "Warning: Unable to open " << file_ << "! Creating new file..." << '\n';
|
||||
}
|
||||
std::cout << "Warning: Unable to open " << file_ << "! Creating new file..." << '\n';
|
||||
|
||||
// Crea el fichero en modo escritura (binario)
|
||||
std::ofstream new_file(file_, std::ios::binary);
|
||||
|
||||
if (new_file) {
|
||||
if (Options::console) {
|
||||
std::cout << "New " << file_ << " created!" << '\n';
|
||||
}
|
||||
std::cout << "New " << file_ << " created!" << '\n';
|
||||
|
||||
// Guarda la información
|
||||
for (const auto& cheevo : cheevos_list_) {
|
||||
new_file.write(reinterpret_cast<const char*>(&cheevo.completed), sizeof(bool));
|
||||
}
|
||||
} else {
|
||||
if (Options::console) {
|
||||
std::cerr << "Error: Unable to create " << file_ << "!" << '\n';
|
||||
}
|
||||
std::cerr << "Error: Unable to create " << file_ << "!" << '\n';
|
||||
}
|
||||
}
|
||||
// El fichero existe
|
||||
else {
|
||||
if (Options::console) {
|
||||
std::cout << "Reading " << file_ << '\n';
|
||||
}
|
||||
std::cout << "Reading " << file_ << '\n';
|
||||
|
||||
// Carga los datos
|
||||
for (auto& cheevo : cheevos_list_) {
|
||||
@@ -154,9 +146,7 @@ void Cheevos::saveToFile() {
|
||||
// Cierra el fichero
|
||||
SDL_CloseIO(file);
|
||||
} else {
|
||||
if (Options::console) {
|
||||
std::cout << "Error: Unable to save file! " << SDL_GetError() << '\n';
|
||||
}
|
||||
std::cout << "Error: Unable to save file! " << SDL_GetError() << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -618,15 +618,6 @@ namespace Options {
|
||||
}
|
||||
}
|
||||
|
||||
// Crea e inicializa las opciones del programa
|
||||
void init() {
|
||||
#ifdef _DEBUG
|
||||
console = true;
|
||||
#else
|
||||
console = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Establece la ruta del fichero de configuración
|
||||
void setConfigFile(const std::string& path) {
|
||||
config_file_path = path;
|
||||
@@ -641,9 +632,7 @@ namespace Options {
|
||||
// Intenta abrir y leer el fichero
|
||||
std::ifstream file(config_file_path);
|
||||
if (!file.good()) {
|
||||
if (console) {
|
||||
std::cout << "Config file not found, creating default: " << config_file_path << '\n';
|
||||
}
|
||||
std::cout << "Config file not found, creating default: " << config_file_path << '\n';
|
||||
saveToFile();
|
||||
return true;
|
||||
}
|
||||
@@ -653,9 +642,7 @@ namespace Options {
|
||||
file.close();
|
||||
|
||||
try {
|
||||
if (console) {
|
||||
std::cout << "Reading config file: " << config_file_path << '\n';
|
||||
}
|
||||
std::cout << "Reading config file: " << config_file_path << '\n';
|
||||
|
||||
// Parsea el YAML
|
||||
auto yaml = fkyaml::node::deserialize(content);
|
||||
@@ -667,10 +654,7 @@ namespace Options {
|
||||
|
||||
// Si la versión no coincide, crea un fichero nuevo con valores por defecto
|
||||
if (CONFIG_VERSION != version) {
|
||||
if (console) {
|
||||
std::cout << "Config version mismatch (expected: " << CONFIG_VERSION << ", got: " << version << "), creating new config\n";
|
||||
}
|
||||
init();
|
||||
std::cout << "Config version mismatch (expected: " << CONFIG_VERSION << ", got: " << version << "), creating new config\n";
|
||||
saveToFile();
|
||||
return true;
|
||||
}
|
||||
@@ -685,18 +669,13 @@ namespace Options {
|
||||
loadKioskConfigFromYaml(yaml);
|
||||
loadLocalizationFromYaml(yaml);
|
||||
|
||||
if (console) {
|
||||
std::cout << "Config file loaded successfully\n\n";
|
||||
}
|
||||
std::cout << "Config file loaded successfully\n\n";
|
||||
|
||||
return true;
|
||||
|
||||
} catch (const fkyaml::exception& e) {
|
||||
if (console) {
|
||||
std::cerr << "Error parsing YAML config: " << e.what() << '\n';
|
||||
std::cerr << "Creating new config with defaults\n";
|
||||
}
|
||||
init();
|
||||
std::cerr << "Error parsing YAML config: " << e.what() << '\n';
|
||||
std::cerr << "Creating new config with defaults\n";
|
||||
saveToFile();
|
||||
return true;
|
||||
}
|
||||
@@ -707,15 +686,11 @@ namespace Options {
|
||||
// Abre el fichero para escritura
|
||||
std::ofstream file(config_file_path);
|
||||
if (!file.is_open()) {
|
||||
if (console) {
|
||||
std::cerr << "Error: Unable to open file " << config_file_path << " for writing\n";
|
||||
}
|
||||
std::cerr << "Error: Unable to open file " << config_file_path << " for writing\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (console) {
|
||||
std::cout << "Writing config file: " << config_file_path << '\n';
|
||||
}
|
||||
std::cout << "Writing config file: " << config_file_path << '\n';
|
||||
|
||||
// Escribe el fichero manualmente para controlar el orden y los comentarios
|
||||
file << "# JailDoctor's Dilemma - Configuration File\n";
|
||||
@@ -807,9 +782,7 @@ namespace Options {
|
||||
|
||||
file.close();
|
||||
|
||||
if (console) {
|
||||
std::cout << "Config file saved successfully\n\n";
|
||||
}
|
||||
std::cout << "Config file saved successfully\n\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -834,9 +807,7 @@ namespace Options {
|
||||
|
||||
std::ifstream file(postfx_file_path);
|
||||
if (!file.good()) {
|
||||
if (console) {
|
||||
std::cout << "PostFX file not found, creating default: " << postfx_file_path << '\n';
|
||||
}
|
||||
std::cout << "PostFX file not found, creating default: " << postfx_file_path << '\n';
|
||||
return savePostFXToFile();
|
||||
}
|
||||
|
||||
@@ -877,16 +848,12 @@ namespace Options {
|
||||
current_postfx_preset = 0;
|
||||
}
|
||||
|
||||
if (console) {
|
||||
std::cout << "PostFX file loaded: " << postfx_presets.size() << " preset(s)\n";
|
||||
}
|
||||
std::cout << "PostFX file loaded: " << postfx_presets.size() << " preset(s)\n";
|
||||
|
||||
return true;
|
||||
|
||||
} catch (const fkyaml::exception& e) {
|
||||
if (console) {
|
||||
std::cerr << "Error parsing PostFX YAML: " << e.what() << '\n';
|
||||
}
|
||||
std::cerr << "Error parsing PostFX YAML: " << e.what() << '\n';
|
||||
return savePostFXToFile();
|
||||
}
|
||||
}
|
||||
@@ -899,9 +866,7 @@ namespace Options {
|
||||
|
||||
std::ofstream file(postfx_file_path);
|
||||
if (!file.is_open()) {
|
||||
if (console) {
|
||||
std::cerr << "Error: Unable to open file " << postfx_file_path << " for writing\n";
|
||||
}
|
||||
std::cerr << "Error: Unable to open file " << postfx_file_path << " for writing\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -975,9 +940,7 @@ namespace Options {
|
||||
|
||||
file.close();
|
||||
|
||||
if (console) {
|
||||
std::cout << "PostFX file created with defaults: " << postfx_file_path << '\n';
|
||||
}
|
||||
std::cout << "PostFX file created with defaults: " << postfx_file_path << '\n';
|
||||
|
||||
// Cargar los presets recién creados
|
||||
postfx_presets.clear();
|
||||
@@ -1002,9 +965,7 @@ namespace Options {
|
||||
|
||||
std::ifstream file(crtpi_file_path);
|
||||
if (!file.good()) {
|
||||
if (console) {
|
||||
std::cout << "CrtPi file not found, creating default: " << crtpi_file_path << '\n';
|
||||
}
|
||||
std::cout << "CrtPi file not found, creating default: " << crtpi_file_path << '\n';
|
||||
// Crear directorio padre si no existe
|
||||
const std::filesystem::path p(crtpi_file_path);
|
||||
if (p.has_parent_path()) {
|
||||
@@ -1014,9 +975,7 @@ namespace Options {
|
||||
// Escribir defaults
|
||||
std::ofstream out(crtpi_file_path);
|
||||
if (!out.is_open()) {
|
||||
if (console) {
|
||||
std::cerr << "Error: Cannot create CrtPi file: " << crtpi_file_path << '\n';
|
||||
}
|
||||
std::cerr << "Error: Cannot create CrtPi file: " << crtpi_file_path << '\n';
|
||||
// Cargar defaults en memoria aunque no se pueda escribir
|
||||
crtpi_presets.push_back({"DEFAULT", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, true, true, false, false});
|
||||
crtpi_presets.push_back({"CURVED", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, true, true, true, false});
|
||||
@@ -1098,9 +1057,7 @@ namespace Options {
|
||||
out << " enable_curvature: false\n";
|
||||
out << " enable_sharper: false\n";
|
||||
out.close();
|
||||
if (console) {
|
||||
std::cout << "CrtPi file created with defaults: " << crtpi_file_path << '\n';
|
||||
}
|
||||
std::cout << "CrtPi file created with defaults: " << crtpi_file_path << '\n';
|
||||
crtpi_presets.push_back({"DEFAULT", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, true, true, false, false});
|
||||
crtpi_presets.push_back({"CURVED", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, true, true, true, false});
|
||||
crtpi_presets.push_back({"SHARP", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, false, true, false, true});
|
||||
@@ -1173,15 +1130,11 @@ namespace Options {
|
||||
current_crtpi_preset = 0;
|
||||
}
|
||||
|
||||
if (console) {
|
||||
std::cout << "CrtPi file loaded: " << crtpi_presets.size() << " preset(s)\n";
|
||||
}
|
||||
std::cout << "CrtPi file loaded: " << crtpi_presets.size() << " preset(s)\n";
|
||||
return true;
|
||||
|
||||
} catch (const fkyaml::exception& e) {
|
||||
if (console) {
|
||||
std::cerr << "Error parsing CrtPi YAML: " << e.what() << '\n';
|
||||
}
|
||||
std::cerr << "Error parsing CrtPi YAML: " << e.what() << '\n';
|
||||
// Cargar defaults en memoria en caso de error
|
||||
crtpi_presets.clear();
|
||||
crtpi_presets.push_back({"DEFAULT", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, true, true, false, false});
|
||||
|
||||
@@ -153,7 +153,6 @@ namespace Options {
|
||||
|
||||
// --- Variables globales ---
|
||||
inline std::string version{}; // Versión del fichero de configuración. Sirve para saber si las opciones son compatibles
|
||||
inline bool console{false}; // Indica si ha de mostrar información por la consola de texto
|
||||
inline Cheat cheats{}; // Contiene trucos y ventajas para el juego
|
||||
inline Game game{}; // Opciones de juego
|
||||
inline Video video{}; // Opciones de video
|
||||
@@ -184,7 +183,6 @@ namespace Options {
|
||||
inline Rendering::ShaderType current_shader{Rendering::ShaderType::POSTFX}; // Shader de post-procesado activo
|
||||
|
||||
// --- Funciones públicas ---
|
||||
void init(); // Crea e inicializa las opciones del programa
|
||||
void setConfigFile(const std::string& path); // Establece la ruta del fichero de configuración
|
||||
auto loadFromFile() -> bool; // Carga las opciones desde el fichero configurado
|
||||
auto saveToFile() -> bool; // Guarda las opciones al fichero configurado
|
||||
|
||||
Reference in New Issue
Block a user