eliminat Options::console
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
#include <string>
|
||||
|
||||
#include "external/fkyaml_node.hpp" // Para fkyaml::node
|
||||
#include "game/options.hpp" // Para Options::console
|
||||
|
||||
// [SINGLETON]
|
||||
Locale* Locale::instance = nullptr;
|
||||
@@ -34,9 +33,7 @@ auto Locale::get(const std::string& key) const -> std::string { // NOLINT(reada
|
||||
return it->second;
|
||||
}
|
||||
|
||||
if (Options::console) {
|
||||
std::cerr << "Locale: clave no encontrada: " << key << '\n';
|
||||
}
|
||||
std::cerr << "Locale: clave no encontrada: " << key << '\n';
|
||||
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
|
||||
void Locale::loadFromFile(const std::string& file_path) { // NOLINT(readability-convert-member-functions-to-static)
|
||||
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;
|
||||
}
|
||||
|
||||
std::ifstream file(file_path);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -79,12 +72,8 @@ void Locale::loadFromFile(const std::string& file_path) { // NOLINT(readability
|
||||
auto yaml = fkyaml::node::deserialize(file);
|
||||
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) {
|
||||
if (Options::console) {
|
||||
std::cerr << "Locale: error al parsear YAML: " << e.what() << '\n';
|
||||
}
|
||||
std::cerr << "Locale: error al parsear YAML: " << e.what() << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,9 +64,7 @@ Screen::Screen()
|
||||
game_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, Options::game.width, Options::game.height);
|
||||
if (game_texture_ == nullptr) {
|
||||
// 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);
|
||||
|
||||
@@ -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));
|
||||
if (border_texture_ == nullptr) {
|
||||
// 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);
|
||||
|
||||
@@ -469,9 +465,9 @@ void Screen::textureToRenderer() {
|
||||
|
||||
// Renderiza todos los overlays (orden: último dibujado queda encima)
|
||||
void Screen::renderOverlays() {
|
||||
renderNotifications(); // Notifier (abajo)
|
||||
if (RenderInfo::get() != nullptr) { RenderInfo::get()->render(); } // RenderInfo (medio)
|
||||
if (Console::get() != nullptr) { Console::get()->render(); } // Console (encima)
|
||||
renderNotifications(); // Notifier (abajo)
|
||||
if (RenderInfo::get() != nullptr) { RenderInfo::get()->render(); } // RenderInfo (medio)
|
||||
if (Console::get() != nullptr) { Console::get()->render(); } // Console (encima)
|
||||
}
|
||||
|
||||
// Localiza la paleta dentro del vector de paletas
|
||||
|
||||
@@ -47,9 +47,6 @@
|
||||
Director::Director() {
|
||||
std::cout << "Game start" << '\n';
|
||||
|
||||
// Crea e inicializa las opciones del programa
|
||||
Options::init();
|
||||
|
||||
// Obtiene la ruta del ejecutable
|
||||
std::string base = SDL_GetBasePath();
|
||||
if (!base.empty() && base.back() == '/') base.pop_back();
|
||||
|
||||
@@ -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