eliminat Options::console

This commit is contained in:
2026-03-29 18:14:51 +02:00
parent fd9be2066d
commit 3b233f0e12
6 changed files with 34 additions and 111 deletions

View File

@@ -5,7 +5,6 @@
#include <string> #include <string>
#include "external/fkyaml_node.hpp" // Para fkyaml::node #include "external/fkyaml_node.hpp" // Para fkyaml::node
#include "game/options.hpp" // Para Options::console
// [SINGLETON] // [SINGLETON]
Locale* Locale::instance = nullptr; Locale* Locale::instance = nullptr;
@@ -34,9 +33,7 @@ auto Locale::get(const std::string& key) const -> std::string { // NOLINT(reada
return it->second; return it->second;
} }
if (Options::console) { std::cerr << "Locale: clave no encontrada: " << key << '\n';
std::cerr << "Locale: clave no encontrada: " << key << '\n';
}
return key; return key;
} }
@@ -61,17 +58,13 @@ void Locale::flatten(const void* node_ptr, const std::string& prefix) { // NOLI
// Carga las traducciones desde el fichero YAML indicado // Carga las traducciones desde el fichero YAML indicado
void Locale::loadFromFile(const std::string& file_path) { // NOLINT(readability-convert-member-functions-to-static) void Locale::loadFromFile(const std::string& file_path) { // NOLINT(readability-convert-member-functions-to-static)
if (file_path.empty()) { if (file_path.empty()) {
if (Options::console) { std::cerr << "Locale: ruta de fichero vacía, sin traducciones cargadas\n";
std::cerr << "Locale: ruta de fichero vacía, sin traducciones cargadas\n";
}
return; return;
} }
std::ifstream file(file_path); std::ifstream file(file_path);
if (!file.is_open()) { if (!file.is_open()) {
if (Options::console) { std::cerr << "Locale: no se puede abrir " << file_path << '\n';
std::cerr << "Locale: no se puede abrir " << file_path << '\n';
}
return; return;
} }
@@ -79,12 +72,8 @@ void Locale::loadFromFile(const std::string& file_path) { // NOLINT(readability
auto yaml = fkyaml::node::deserialize(file); auto yaml = fkyaml::node::deserialize(file);
flatten(&yaml, ""); flatten(&yaml, "");
if (Options::console) { std::cout << "Locale: " << strings_.size() << " traducciones cargadas desde " << file_path << '\n';
std::cout << "Locale: " << strings_.size() << " traducciones cargadas desde " << file_path << '\n';
}
} catch (const fkyaml::exception& e) { } catch (const fkyaml::exception& e) {
if (Options::console) { std::cerr << "Locale: error al parsear YAML: " << e.what() << '\n';
std::cerr << "Locale: error al parsear YAML: " << e.what() << '\n';
}
} }
} }

View File

@@ -64,9 +64,7 @@ Screen::Screen()
game_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, Options::game.width, Options::game.height); game_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, Options::game.width, Options::game.height);
if (game_texture_ == nullptr) { if (game_texture_ == nullptr) {
// Registrar el error si está habilitado // Registrar el error si está habilitado
if (Options::console) { std::cerr << "Error: game_texture_ could not be created!\nSDL Error: " << SDL_GetError() << '\n';
std::cerr << "Error: game_texture_ could not be created!\nSDL Error: " << SDL_GetError() << '\n';
}
} }
SDL_SetTextureScaleMode(game_texture_, SDL_SCALEMODE_NEAREST); SDL_SetTextureScaleMode(game_texture_, SDL_SCALEMODE_NEAREST);
@@ -74,9 +72,7 @@ Screen::Screen()
border_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, Options::game.width + (Options::video.border.width * 2), Options::game.height + (Options::video.border.height * 2)); border_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, Options::game.width + (Options::video.border.width * 2), Options::game.height + (Options::video.border.height * 2));
if (border_texture_ == nullptr) { if (border_texture_ == nullptr) {
// Registrar el error si está habilitado // Registrar el error si está habilitado
if (Options::console) { std::cerr << "Error: border_texture_ could not be created!\nSDL Error: " << SDL_GetError() << '\n';
std::cerr << "Error: border_texture_ could not be created!\nSDL Error: " << SDL_GetError() << '\n';
}
} }
SDL_SetTextureScaleMode(border_texture_, SDL_SCALEMODE_NEAREST); SDL_SetTextureScaleMode(border_texture_, SDL_SCALEMODE_NEAREST);
@@ -469,9 +465,9 @@ void Screen::textureToRenderer() {
// Renderiza todos los overlays (orden: último dibujado queda encima) // Renderiza todos los overlays (orden: último dibujado queda encima)
void Screen::renderOverlays() { void Screen::renderOverlays() {
renderNotifications(); // Notifier (abajo) renderNotifications(); // Notifier (abajo)
if (RenderInfo::get() != nullptr) { RenderInfo::get()->render(); } // RenderInfo (medio) if (RenderInfo::get() != nullptr) { RenderInfo::get()->render(); } // RenderInfo (medio)
if (Console::get() != nullptr) { Console::get()->render(); } // Console (encima) if (Console::get() != nullptr) { Console::get()->render(); } // Console (encima)
} }
// Localiza la paleta dentro del vector de paletas // Localiza la paleta dentro del vector de paletas

View File

@@ -47,9 +47,6 @@
Director::Director() { Director::Director() {
std::cout << "Game start" << '\n'; std::cout << "Game start" << '\n';
// Crea e inicializa las opciones del programa
Options::init();
// Obtiene la ruta del ejecutable // Obtiene la ruta del ejecutable
std::string base = SDL_GetBasePath(); std::string base = SDL_GetBasePath();
if (!base.empty() && base.back() == '/') base.pop_back(); if (!base.empty() && base.back() == '/') base.pop_back();

View File

@@ -106,33 +106,25 @@ void Cheevos::loadFromFile() { // NOLINT(readability-convert-member-functions-t
// El fichero no existe // El fichero no existe
if (!file) { 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) // Crea el fichero en modo escritura (binario)
std::ofstream new_file(file_, std::ios::binary); std::ofstream new_file(file_, std::ios::binary);
if (new_file) { if (new_file) {
if (Options::console) { std::cout << "New " << file_ << " created!" << '\n';
std::cout << "New " << file_ << " created!" << '\n';
}
// Guarda la información // Guarda la información
for (const auto& cheevo : cheevos_list_) { for (const auto& cheevo : cheevos_list_) {
new_file.write(reinterpret_cast<const char*>(&cheevo.completed), sizeof(bool)); new_file.write(reinterpret_cast<const char*>(&cheevo.completed), sizeof(bool));
} }
} else { } else {
if (Options::console) { std::cerr << "Error: Unable to create " << file_ << "!" << '\n';
std::cerr << "Error: Unable to create " << file_ << "!" << '\n';
}
} }
} }
// El fichero existe // El fichero existe
else { else {
if (Options::console) { std::cout << "Reading " << file_ << '\n';
std::cout << "Reading " << file_ << '\n';
}
// Carga los datos // Carga los datos
for (auto& cheevo : cheevos_list_) { for (auto& cheevo : cheevos_list_) {
@@ -154,9 +146,7 @@ void Cheevos::saveToFile() {
// Cierra el fichero // Cierra el fichero
SDL_CloseIO(file); SDL_CloseIO(file);
} else { } else {
if (Options::console) { std::cout << "Error: Unable to save file! " << SDL_GetError() << '\n';
std::cout << "Error: Unable to save file! " << SDL_GetError() << '\n';
}
} }
} }

View File

@@ -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 // Establece la ruta del fichero de configuración
void setConfigFile(const std::string& path) { void setConfigFile(const std::string& path) {
config_file_path = path; config_file_path = path;
@@ -641,9 +632,7 @@ namespace Options {
// Intenta abrir y leer el fichero // Intenta abrir y leer el fichero
std::ifstream file(config_file_path); std::ifstream file(config_file_path);
if (!file.good()) { 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(); saveToFile();
return true; return true;
} }
@@ -653,9 +642,7 @@ namespace Options {
file.close(); file.close();
try { try {
if (console) { std::cout << "Reading config file: " << config_file_path << '\n';
std::cout << "Reading config file: " << config_file_path << '\n';
}
// Parsea el YAML // Parsea el YAML
auto yaml = fkyaml::node::deserialize(content); 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 // Si la versión no coincide, crea un fichero nuevo con valores por defecto
if (CONFIG_VERSION != version) { if (CONFIG_VERSION != version) {
if (console) { std::cout << "Config version mismatch (expected: " << CONFIG_VERSION << ", got: " << version << "), creating new config\n";
std::cout << "Config version mismatch (expected: " << CONFIG_VERSION << ", got: " << version << "), creating new config\n";
}
init();
saveToFile(); saveToFile();
return true; return true;
} }
@@ -685,18 +669,13 @@ namespace Options {
loadKioskConfigFromYaml(yaml); loadKioskConfigFromYaml(yaml);
loadLocalizationFromYaml(yaml); loadLocalizationFromYaml(yaml);
if (console) { std::cout << "Config file loaded successfully\n\n";
std::cout << "Config file loaded successfully\n\n";
}
return true; return true;
} catch (const fkyaml::exception& e) { } catch (const fkyaml::exception& e) {
if (console) { std::cerr << "Error parsing YAML config: " << e.what() << '\n';
std::cerr << "Error parsing YAML config: " << e.what() << '\n'; std::cerr << "Creating new config with defaults\n";
std::cerr << "Creating new config with defaults\n";
}
init();
saveToFile(); saveToFile();
return true; return true;
} }
@@ -707,15 +686,11 @@ namespace Options {
// Abre el fichero para escritura // Abre el fichero para escritura
std::ofstream file(config_file_path); std::ofstream file(config_file_path);
if (!file.is_open()) { 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; 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 // Escribe el fichero manualmente para controlar el orden y los comentarios
file << "# JailDoctor's Dilemma - Configuration File\n"; file << "# JailDoctor's Dilemma - Configuration File\n";
@@ -807,9 +782,7 @@ namespace Options {
file.close(); file.close();
if (console) { std::cout << "Config file saved successfully\n\n";
std::cout << "Config file saved successfully\n\n";
}
return true; return true;
} }
@@ -834,9 +807,7 @@ namespace Options {
std::ifstream file(postfx_file_path); std::ifstream file(postfx_file_path);
if (!file.good()) { 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(); return savePostFXToFile();
} }
@@ -877,16 +848,12 @@ namespace Options {
current_postfx_preset = 0; 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; return true;
} catch (const fkyaml::exception& e) { } 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(); return savePostFXToFile();
} }
} }
@@ -899,9 +866,7 @@ namespace Options {
std::ofstream file(postfx_file_path); std::ofstream file(postfx_file_path);
if (!file.is_open()) { 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; return false;
} }
@@ -975,9 +940,7 @@ namespace Options {
file.close(); 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 // Cargar los presets recién creados
postfx_presets.clear(); postfx_presets.clear();
@@ -1002,9 +965,7 @@ namespace Options {
std::ifstream file(crtpi_file_path); std::ifstream file(crtpi_file_path);
if (!file.good()) { 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 // Crear directorio padre si no existe
const std::filesystem::path p(crtpi_file_path); const std::filesystem::path p(crtpi_file_path);
if (p.has_parent_path()) { if (p.has_parent_path()) {
@@ -1014,9 +975,7 @@ namespace Options {
// Escribir defaults // Escribir defaults
std::ofstream out(crtpi_file_path); std::ofstream out(crtpi_file_path);
if (!out.is_open()) { 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 // 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({"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({"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_curvature: false\n";
out << " enable_sharper: false\n"; out << " enable_sharper: false\n";
out.close(); 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({"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({"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}); 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; 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; return true;
} catch (const fkyaml::exception& e) { } 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 // Cargar defaults en memoria en caso de error
crtpi_presets.clear(); 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}); 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});

View File

@@ -153,7 +153,6 @@ namespace Options {
// --- Variables globales --- // --- Variables globales ---
inline std::string version{}; // Versión del fichero de configuración. Sirve para saber si las opciones son compatibles 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 Cheat cheats{}; // Contiene trucos y ventajas para el juego
inline Game game{}; // Opciones de juego inline Game game{}; // Opciones de juego
inline Video video{}; // Opciones de video 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 inline Rendering::ShaderType current_shader{Rendering::ShaderType::POSTFX}; // Shader de post-procesado activo
// --- Funciones públicas --- // --- 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 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 loadFromFile() -> bool; // Carga las opciones desde el fichero configurado
auto saveToFile() -> bool; // Guarda las opciones al fichero configurado auto saveToFile() -> bool; // Guarda las opciones al fichero configurado