From 0428ff26d57338dd8726c6ba76e803610b60ab73 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 17 Aug 2025 16:28:30 +0200 Subject: [PATCH] options.h ara gasta defaults.h --- source/defaults.h | 33 +++++++++++++++++++ source/options.h | 84 +++++++++++++++++------------------------------ 2 files changed, 64 insertions(+), 53 deletions(-) diff --git a/source/defaults.h b/source/defaults.h index 126c7b5..39f4a39 100644 --- a/source/defaults.h +++ b/source/defaults.h @@ -1,5 +1,7 @@ #pragma once +#include // Para SDL_ScaleMode + #include #include "color.h" @@ -200,4 +202,35 @@ constexpr const char* PLAYER0 = "66323FFF"; constexpr const char* PLAYER1 = "422028FF"; } // namespace OutlineColor } // namespace Player + +// --- OPTIONS --- +namespace Options { +// Window +constexpr const char* WINDOW_CAPTION = "Coffee Crisis Arcade Edition"; +constexpr int WINDOW_ZOOM = 2; +constexpr int WINDOW_MAX_ZOOM = 2; + +// Video +constexpr SDL_ScaleMode VIDEO_SCALE_MODE = SDL_ScaleMode::SDL_SCALEMODE_NEAREST; +constexpr bool VIDEO_FULLSCREEN = false; +constexpr bool VIDEO_VSYNC = true; +constexpr bool VIDEO_INTEGER_SCALE = true; +constexpr bool VIDEO_SHADERS = false; + +// Music +constexpr bool MUSIC_ENABLED = true; +constexpr int MUSIC_VOLUME = 100; + +// Sound +constexpr bool SOUND_ENABLED = true; +constexpr int SOUND_VOLUME = 100; + +// Audio +constexpr bool AUDIO_ENABLED = true; +constexpr int AUDIO_VOLUME = 100; + +// Settings +constexpr bool SETTINGS_AUTOFIRE = true; +constexpr bool SETTINGS_SHUTDOWN_ENABLED = false; +} // namespace Options } // namespace GameDefaults \ No newline at end of file diff --git a/source/options.h b/source/options.h index a1ec95d..940eab3 100644 --- a/source/options.h +++ b/source/options.h @@ -11,9 +11,10 @@ #include // Para out_of_range, invalid_argument #include // Para char_traits, string, allocator, operator==, swap, operator<<, basic_string, stoi #include // Para string_view -#include -#include // Para vector +#include // Para swap +#include // Para vector +#include "defaults.h" // Para GameDefaults #include "difficulty.h" // Para Code #include "input.h" // Para Input #include "lang.h" // Para Code @@ -25,66 +26,46 @@ namespace Options { // --- Estructuras --- struct Window { - std::string caption; // Texto que aparece en la barra de título de la ventana - int zoom{2}; // Valor por el que se multiplica el tamaño de la ventana - int max_zoom{2}; // Tamaño máximo para que la ventana no sea mayor que la pantalla - - // Constructor por defecto con valores iniciales - Window() - : caption("Coffee Crisis Arcade Edition") {} + std::string caption = GameDefaults::Options::WINDOW_CAPTION; // Texto que aparece en la barra de título de la ventana + int zoom = GameDefaults::Options::WINDOW_ZOOM; // Valor por el que se multiplica el tamaño de la ventana + int max_zoom = GameDefaults::Options::WINDOW_MAX_ZOOM; // Tamaño máximo para que la ventana no sea mayor que la pantalla }; struct Video { - SDL_ScaleMode scale_mode{SDL_ScaleMode::SDL_SCALEMODE_NEAREST}; // Filtro usado para el escalado de la imagen - bool fullscreen{false}; // Indica si se usa pantalla completa - bool vsync{true}; // Indica si se usa vsync - bool integer_scale{true}; // Indica si se usa escalado entero - bool shaders{false}; // Indica si se usan shaders para los filtros de vídeo - std::string info; // Información sobre el modo de vídeo - - // Constructor por defecto con valores iniciales - Video() = default; + SDL_ScaleMode scale_mode = GameDefaults::Options::VIDEO_SCALE_MODE; // Filtro usado para el escalado de la imagen + bool fullscreen = GameDefaults::Options::VIDEO_FULLSCREEN; // Indica si se usa pantalla completa + bool vsync = GameDefaults::Options::VIDEO_VSYNC; // Indica si se usa vsync + bool integer_scale = GameDefaults::Options::VIDEO_INTEGER_SCALE; // Indica si se usa escalado entero + bool shaders = GameDefaults::Options::VIDEO_SHADERS; // Indica si se usan shaders para los filtros de vídeo + std::string info; // Información sobre el modo de vídeo }; struct Music { - bool enabled{true}; // Indica si la música suena o no - int volume{100}; // Volumen de la música - - // Constructor por defecto - Music() = default; + bool enabled = GameDefaults::Options::MUSIC_ENABLED; // Indica si la música suena o no + int volume = GameDefaults::Options::MUSIC_VOLUME; // Volumen de la música }; struct Sound { - bool enabled{true}; // Indica si los sonidos suenan o no - int volume{100}; // Volumen de los sonidos - - // Constructor por defecto - Sound() = default; + bool enabled = GameDefaults::Options::SOUND_ENABLED; // Indica si los sonidos suenan o no + int volume = GameDefaults::Options::SOUND_VOLUME; // Volumen de los sonidos }; struct Audio { - Music music; // Opciones para la música - Sound sound; // Opciones para los efectos de sonido - bool enabled{true}; // Indica si el audio está activo o no - int volume{100}; // Volumen general del audio - - // Constructor por defecto - Audio() = default; + Music music; // Opciones para la música + Sound sound; // Opciones para los efectos de sonido + bool enabled = GameDefaults::Options::AUDIO_ENABLED; // Indica si el audio está activo o no + int volume = GameDefaults::Options::AUDIO_VOLUME; // Volumen general del audio }; struct Settings { - Difficulty::Code difficulty{Difficulty::Code::NORMAL}; // Dificultad del juego - Lang::Code language{Lang::Code::VALENCIAN}; // Idioma usado en el juego - bool autofire{true}; // Indicador de autofire - bool shutdown_enabled{false}; // Especifica si se puede apagar el sistema - Table hi_score_table; // Tabla de mejores puntuaciones - std::vector glowing_entries; // Últimas posiciones de entrada en la tabla - std::string config_file; // Ruta al fichero donde guardar la configuración y las opciones del juego - std::string controllers_file; // Ruta al fichero con las configuraciones de los mandos - - // Constructor por defecto con valores iniciales - Settings() - : glowing_entries({ManageHiScoreTable::NO_ENTRY, ManageHiScoreTable::NO_ENTRY}) {} + Difficulty::Code difficulty = Difficulty::Code::NORMAL; // Dificultad del juego + Lang::Code language = Lang::Code::VALENCIAN; // Idioma usado en el juego + bool autofire = GameDefaults::Options::SETTINGS_AUTOFIRE; // Indicador de autofire + bool shutdown_enabled = GameDefaults::Options::SETTINGS_SHUTDOWN_ENABLED; // Especifica si se puede apagar el sistema + Table hi_score_table; // Tabla de mejores puntuaciones + std::vector glowing_entries = {ManageHiScoreTable::NO_ENTRY, ManageHiScoreTable::NO_ENTRY}; // Últimas posiciones de entrada en la tabla + std::string config_file; // Ruta al fichero donde guardar la configuración y las opciones del juego + std::string controllers_file; // Ruta al fichero con las configuraciones de los mandos // Reinicia las últimas entradas de puntuación void clearLastHiScoreEntries() { @@ -288,12 +269,9 @@ struct Keyboard { }; struct PendingChanges { - Lang::Code new_language{Lang::Code::VALENCIAN}; // Idioma en espera de aplicar - Difficulty::Code new_difficulty{Difficulty::Code::NORMAL}; // Dificultad en espera de aplicar - bool has_pending_changes{false}; // Indica si hay cambios pendientes - - // Constructor por defecto con valores iniciales - PendingChanges() = default; + Lang::Code new_language = Lang::Code::VALENCIAN; // Idioma en espera de aplicar + Difficulty::Code new_difficulty = Difficulty::Code::NORMAL; // Dificultad en espera de aplicar + bool has_pending_changes = false; // Indica si hay cambios pendientes }; // --- Variables ---