diff --git a/source/director.cpp b/source/director.cpp index 6ae47b4..4ed75a4 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -86,14 +86,14 @@ Director::~Director() void Director::init() { // Configuración inicial de recursos - Asset::init(executable_path_); // Inicializa el sistema de gestión de archivos - setFileList(); // Crea el índice de archivos - Options::loadOptionsFile(Asset::get()->get("config.txt")); // Carga el archivo de configuración - loadParams(); // Carga los parámetros del programa - loadScoreFile(); // Carga el archivo de puntuaciones + Asset::init(executable_path_); // Inicializa el sistema de gestión de archivos + setFileList(); // Crea el índice de archivos + Options::loadFromFile(Asset::get()->get("config.txt")); // Carga el archivo de configuración + loadParams(); // Carga los parámetros del programa + loadScoreFile(); // Carga el archivo de puntuaciones // Inicialización de subsistemas principales - Lang::setLanguage(Options::game.language); // Carga el archivo de idioma + Lang::setLanguage(Options::settings.language); // Carga el archivo de idioma Screen::init(); // Inicializa la pantalla y el sistema de renderizado Audio::init(); // Activa el sistema de audio Resource::init(); // Inicializa el sistema de gestión de recursos @@ -108,7 +108,7 @@ void Director::init() void Director::close() { // Guarda las opciones actuales en el archivo de configuración - Options::saveOptionsFile(Asset::get()->get("config.txt")); + Options::saveToFile(Asset::get()->get("config.txt")); // Libera los singletons y recursos en orden inverso al de inicialización Notifier::destroy(); // Libera el sistema de notificaciones @@ -141,7 +141,7 @@ void Director::loadParams() // Carga el fichero de puntuaciones void Director::loadScoreFile() { - auto manager = std::make_unique(Options::game.hi_score_table); + auto manager = std::make_unique(Options::settings.hi_score_table); if (overrides.clear_hi_score_table) { manager->clear(); @@ -617,9 +617,9 @@ void Director::runDemoGame() // Reinicia objetos y vuelve a la sección inicial void Director::reset() { - Options::saveOptionsFile(Asset::get()->get("config.txt")); - Options::loadOptionsFile(Asset::get()->get("config.txt")); - Lang::setLanguage(Options::game.language); + Options::saveToFile(Asset::get()->get("config.txt")); + Options::loadFromFile(Asset::get()->get("config.txt")); + Lang::setLanguage(Options::settings.language); Audio::get()->stopMusic(); Audio::get()->stopAllSounds(); if (Section::options == Section::Options::RELOAD || true) diff --git a/source/game.cpp b/source/game.cpp index 1969b55..9d6f2a7 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -107,7 +107,7 @@ Game::~Game() else { // [Modo JUEGO] Guarda puntuaciones y transita a modo título - auto manager = std::make_unique(Options::game.hi_score_table); + auto manager = std::make_unique(Options::settings.hi_score_table); manager->saveToFile(Asset::get()->get("score.bin")); Section::attract_mode = Section::AttractMode::TITLE_TO_DEMO; Audio::get()->stopMusic(); @@ -1267,10 +1267,10 @@ void Game::pause(bool value) void Game::addScoreToScoreBoard(const std::shared_ptr &player) { const auto entry = HiScoreEntry(trim(player->getRecordName()), player->getScore(), player->get1CC()); - auto manager = std::make_unique(Options::game.hi_score_table); - Options::game.last_hi_score_entry.at(player->getId() - 1) = manager->add(entry); + auto manager = std::make_unique(Options::settings.hi_score_table); + Options::settings.last_hi_score_entry.at(player->getId() - 1) = manager->add(entry); manager->saveToFile(Asset::get()->get("score.bin")); - hi_score_.name = Options::game.hi_score_table.front().name; + hi_score_.name = Options::settings.hi_score_table.front().name; } // Saca del estado de GAME OVER al jugador si el otro está activo @@ -1443,7 +1443,7 @@ void Game::handleFireInput(const std::shared_ptr &player, BulletType bul Audio::get()->playSound("bullet.wav"); // Establece un tiempo de espera para el próximo disparo. - const int cooldown = player->isPowerUp() ? 5 : Options::game.autofire ? 10 + const int cooldown = player->isPowerUp() ? 5 : Options::settings.autofire ? 10 : 7; player->setFireCooldown(cooldown); } @@ -1476,7 +1476,7 @@ void Game::handlePlayersInput() void Game::handleNormalPlayerInput(const std::shared_ptr &player) { const auto &controller = Options::controllers.at(player->getController()); - const bool autofire = player->isPowerUp() || Options::game.autofire; + const bool autofire = player->isPowerUp() || Options::settings.autofire; if (input_->checkInput(InputAction::LEFT, INPUT_ALLOW_REPEAT, controller.type, controller.index)) { diff --git a/source/game.h b/source/game.h index 540a519..9eacbde 100644 --- a/source/game.h +++ b/source/game.h @@ -135,11 +135,11 @@ private: // --- Variables de estado --- HiScoreEntry hi_score_ = HiScoreEntry( - Options::game.hi_score_table[0].name, - Options::game.hi_score_table[0].score); // Máxima puntuación y nombre de quien la ostenta + Options::settings.hi_score_table[0].name, + Options::settings.hi_score_table[0].score); // Máxima puntuación y nombre de quien la ostenta Demo demo_; // Variable con todas las variables relacionadas con el modo demo - Options::DifficultyCode difficulty_ = Options::game.difficulty; // Dificultad del juego + Options::DifficultyCode difficulty_ = Options::settings.difficulty; // Dificultad del juego Helper helper_; // Variable para gestionar las ayudas Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa bool coffee_machine_enabled_ = false; // Indica si hay una máquina de café en el terreno de juego diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index 830b3ad..40d81d5 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -117,15 +117,15 @@ namespace GlobalInputs const std::string CODE = "LANG"; if (Notifier::get()->checkCode(CODE)) { - Options::game.language = Lang::getNextLangCode(Options::game.language); - Lang::loadFromFile(getLangFile(static_cast(Options::game.language))); + Options::settings.language = Lang::getNextLangCode(Options::settings.language); + Lang::loadFromFile(getLangFile(static_cast(Options::settings.language))); Section::name = Section::Name::RESET; Section::options = Section::Options::RELOAD; - Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 05") + getLangName(Options::game.language)}); + Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 05") + getLangName(Options::settings.language)}); } else { - const auto NEXT = Lang::getNextLangCode(Options::game.language); + const auto NEXT = Lang::getNextLangCode(Options::settings.language); Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 04") + getLangName(NEXT), std::string()}, -1, CODE); } } @@ -133,8 +133,8 @@ namespace GlobalInputs // Cambia el modo de disparo void toggleFireMode() { - Options::game.autofire = !Options::game.autofire; - Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 08") + " " + boolToOnOff(Options::game.autofire)}); + Options::settings.autofire = !Options::settings.autofire; + Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 08") + " " + boolToOnOff(Options::settings.autofire)}); } // Salta una sección del juego diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 0e66161..2064e6a 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -51,7 +51,7 @@ HiScoreTable::HiScoreTable() HiScoreTable::~HiScoreTable() { SDL_DestroyTexture(backbuffer_); - Options::game.clearLastHiScoreEntries(); + Options::settings.clearLastHiScoreEntries(); } // Actualiza las variables @@ -232,15 +232,15 @@ void HiScoreTable::createSprites() for (int i = 0; i < MAX_NAMES; ++i) { const auto table_position = format(i + 1) + ". "; - const auto score = format(Options::game.hi_score_table.at(i).score); - const auto num_dots = ENTRY_LENGHT - Options::game.hi_score_table.at(i).name.size() - score.size(); - const auto one_cc = Options::game.hi_score_table.at(i).one_credit_complete ? " }" : ""; + const auto score = format(Options::settings.hi_score_table.at(i).score); + const auto num_dots = ENTRY_LENGHT - Options::settings.hi_score_table.at(i).name.size() - score.size(); + const auto one_cc = Options::settings.hi_score_table.at(i).one_credit_complete ? " }" : ""; std::string dots; for (int j = 0; j < (int)num_dots; ++j) { dots = dots + "."; } - const auto line = table_position + Options::game.hi_score_table.at(i).name + dots + score + one_cc; + const auto line = table_position + Options::settings.hi_score_table.at(i).name + dots + score + one_cc; entry_names_.emplace_back(std::make_shared(entry_text->writeDXToTexture(TEXT_SHADOW, line, 1, ORANGE_COLOR, 1, SHADOW_TEXT_COLOR))); const int default_pos_x = (backbuffer_width - entry_width) / 2; @@ -402,7 +402,7 @@ void HiScoreTable::iniEntryColors() void HiScoreTable::glowEntryNames() { const Color entry_color = getEntryColor(counter_ / 5); - for (const auto &entry_index : Options::game.last_hi_score_entry) + for (const auto &entry_index : Options::settings.last_hi_score_entry) { if (entry_index != -1) { diff --git a/source/lang.cpp b/source/lang.cpp index 55b1bf4..cada758 100644 --- a/source/lang.cpp +++ b/source/lang.cpp @@ -131,7 +131,7 @@ namespace Lang // Establece el idioma void setLanguage(Code lang) { - Options::game.language = lang; + Options::settings.language = lang; loadFromFile(Asset::get()->get(getLanguage(lang).file_name)); updateLanguageNames(); } diff --git a/source/options.cpp b/source/options.cpp index 01a13e9..58d81ee 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -12,7 +12,7 @@ namespace Options { // --- Variables globales --- WindowOptions window; // Opciones de la ventana - GameOptions game; // Opciones del juego + SettingsOptions settings; // Opciones del juego VideoOptions video; // Opciones de vídeo AudioOptions audio; // Opciones de audio std::vector controllers; // Opciones de mando para cada jugador @@ -28,7 +28,7 @@ namespace Options bool setOptions(const std::string &var, const std::string &value); // Inicializa las opciones del programa - void initOptions() + void init() { window.caption = "Coffee Crisis Arcade Edition"; window.size = 2; @@ -49,11 +49,11 @@ namespace Options audio.sound.volume = 50; // Opciones de juego - game.difficulty = DifficultyCode::NORMAL; - game.language = Lang::Code::VALENCIAN; - game.autofire = true; - game.shutdown_enabled = false; - game.clearLastHiScoreEntries(); + settings.difficulty = DifficultyCode::NORMAL; + settings.language = Lang::Code::VALENCIAN; + settings.autofire = true; + settings.shutdown_enabled = false; + settings.clearLastHiScoreEntries(); // Opciones de control controllers.clear(); @@ -63,16 +63,16 @@ namespace Options setKeyboardToPlayer(1); // Opciones pendientes - pending_changes.new_language = game.language; - pending_changes.new_difficulty = game.difficulty; + pending_changes.new_language = settings.language; + pending_changes.new_difficulty = settings.difficulty; pending_changes.has_pending_changes = false; } // Carga el fichero de configuración - bool loadOptionsFile(std::string file_path) + bool loadFromFile(std::string file_path) { // Inicializa las opciones del programa - initOptions(); + init(); // Indicador de éxito en la carga bool success = true; @@ -107,22 +107,22 @@ namespace Options else { // Crea el fichero con los valores por defecto - saveOptionsFile(file_path); + saveToFile(file_path); } // Normaliza los valores - if (game.language != Lang::Code::ENGLISH && - game.language != Lang::Code::VALENCIAN && - game.language != Lang::Code::SPANISH) + if (settings.language != Lang::Code::ENGLISH && + settings.language != Lang::Code::VALENCIAN && + settings.language != Lang::Code::SPANISH) { - game.language = Lang::Code::ENGLISH; + settings.language = Lang::Code::ENGLISH; } return success; } // Guarda el fichero de configuración - bool saveOptionsFile(std::string file_path) + bool saveToFile(std::string file_path) { std::ofstream file(file_path); @@ -166,10 +166,10 @@ namespace Options file << "## game.difficulty [" << static_cast(DifficultyCode::EASY) << ": easy, " << static_cast(DifficultyCode::NORMAL) << ": normal, " << static_cast(DifficultyCode::HARD) << ": hard]\n"; file << "\n"; - file << "game.language=" << static_cast(game.language) << "\n"; - file << "game.difficulty=" << static_cast(game.difficulty) << "\n"; - file << "game.autofire=" << boolToString(game.autofire) << "\n"; - file << "game.shutdown_enabled=" << boolToString(game.shutdown_enabled) << "\n"; + file << "game.language=" << static_cast(settings.language) << "\n"; + file << "game.difficulty=" << static_cast(settings.difficulty) << "\n"; + file << "game.autofire=" << boolToString(settings.autofire) << "\n"; + file << "game.shutdown_enabled=" << boolToString(settings.shutdown_enabled) << "\n"; // Opciones de mandos file << "\n\n## CONTROLLERS\n"; @@ -258,21 +258,21 @@ namespace Options // Opciones de juego else if (var == "game.language") { - game.language = static_cast(std::stoi(value)); - pending_changes.new_language = game.language; + settings.language = static_cast(std::stoi(value)); + pending_changes.new_language = settings.language; } else if (var == "game.difficulty") { - game.difficulty = static_cast(std::stoi(value)); - pending_changes.new_difficulty = game.difficulty; + settings.difficulty = static_cast(std::stoi(value)); + pending_changes.new_difficulty = settings.difficulty; } else if (var == "game.autofire") { - game.autofire = stringToBool(value); + settings.autofire = stringToBool(value); } else if (var == "game.shutdown_enabled") { - game.shutdown_enabled = stringToBool(value); + settings.shutdown_enabled = stringToBool(value); } // Opciones de mandos @@ -370,13 +370,13 @@ namespace Options } // Intercambia el teclado de jugador - void swapOptionsKeyboard() + void swapKeyboard() { std::swap(controllers.at(0).type, controllers.at(1).type); } // Intercambia los jugadores asignados a los dos primeros mandos - void swapOptionsControllers() + void swapControllers() { std::swap(controllers.at(0).player_id, controllers.at(1).player_id); std::swap(controllers.at(0).type, controllers.at(1).type); @@ -400,16 +400,16 @@ namespace Options { if (pending_changes.has_pending_changes) { - game.language = pending_changes.new_language; - game.difficulty = pending_changes.new_difficulty; + settings.language = pending_changes.new_language; + settings.difficulty = pending_changes.new_difficulty; pending_changes.has_pending_changes = false; } } void checkPendingChanges() { - if (game.language != pending_changes.new_language || - game.difficulty != pending_changes.new_difficulty) + if (settings.language != pending_changes.new_language || + settings.difficulty != pending_changes.new_difficulty) { pending_changes.has_pending_changes = true; } diff --git a/source/options.h b/source/options.h index f2a43ff..96e7f4a 100644 --- a/source/options.h +++ b/source/options.h @@ -74,8 +74,8 @@ namespace Options int volume; // Volumen general del audio }; - // --- Opciones del juego --- - struct GameOptions + // --- Opciones de configuracion --- + struct SettingsOptions { DifficultyCode difficulty; // Dificultad del juego Lang::Code language; // Idioma usado en el juego @@ -120,20 +120,20 @@ namespace Options // --- Variables globales --- extern WindowOptions window; // Opciones de la ventana - extern GameOptions game; // Opciones del juego + extern SettingsOptions settings; // Opciones del juego extern VideoOptions video; // Opciones de vídeo extern AudioOptions audio; // Opciones de audio extern std::vector controllers; // Opciones de mando para cada jugador extern PendingChanges pending_changes; // Opciones que se aplican al cerrar // --- Funciones de configuración --- - void initOptions(); // Inicializa las opciones del programa - bool loadOptionsFile(std::string file_path); // Carga el fichero de configuración - bool saveOptionsFile(std::string file_path); // Guarda el fichero de configuración - void setKeyboardToPlayer(int player_id); // Asigna el teclado al jugador - void swapOptionsKeyboard(); // Intercambia el teclado de jugador - void swapOptionsControllers(); // Intercambia los jugadores asignados a los dos primeros mandos - int getPlayerWhoUsesKeyboard(); // Averigua quién está usando el teclado - void applyPendingChanges(); // Aplica los cambios pendientes copiando los valores a sus variables + void init(); // Inicializa las opciones del programa + bool loadFromFile(std::string file_path); // Carga el fichero de configuración + bool saveToFile(std::string file_path); // Guarda el fichero de configuración + void setKeyboardToPlayer(int player_id); // Asigna el teclado al jugador + void swapKeyboard(); // Intercambia el teclado de jugador + void swapControllers(); // Intercambia los jugadores asignados a los dos primeros mandos + int getPlayerWhoUsesKeyboard(); // Averigua quién está usando el teclado + void applyPendingChanges(); // Aplica los cambios pendientes copiando los valores a sus variables void checkPendingChanges(); } // namespace Options \ No newline at end of file diff --git a/source/player.h b/source/player.h index 12a034c..a754d8b 100644 --- a/source/player.h +++ b/source/player.h @@ -108,7 +108,7 @@ public: bool canFire() const { return cool_down_ <= 0; } bool hasExtraHit() const { return extra_hit_; } bool isCooling() const { return firing_state_ == PlayerState::COOLING_LEFT || firing_state_ == PlayerState::COOLING_UP || firing_state_ == PlayerState::COOLING_RIGHT; } - bool IsEligibleForHighScore() const { return score_ > Options::game.hi_score_table.back().score; } + bool IsEligibleForHighScore() const { return score_ > Options::settings.hi_score_table.back().score; } bool isInvulnerable() const { return invulnerable_; } bool isPowerUp() const { return power_up_; } Circle &getCollider() { return collider_; } diff --git a/source/service_menu.cpp b/source/service_menu.cpp index 5141293..7ba1918 100644 --- a/source/service_menu.cpp +++ b/source/service_menu.cpp @@ -365,7 +365,7 @@ void ServiceMenu::initializeOptions() options_.emplace_back(Lang::getText("[SERVICE_MENU] SFX_VOLUME"), SettingsGroup::AUDIO, OptionBehavior::ADJUST, &Options::audio.sound.volume, ValueType::INT, 0, 100, 5); // Settings - options_.emplace_back(Lang::getText("[SERVICE_MENU] AUTOFIRE"), SettingsGroup::SETTINGS, OptionBehavior::ADJUST, &Options::game.autofire, ValueType::BOOL); + options_.emplace_back(Lang::getText("[SERVICE_MENU] AUTOFIRE"), SettingsGroup::SETTINGS, OptionBehavior::ADJUST, &Options::settings.autofire, ValueType::BOOL); options_.emplace_back( Lang::getText("[SERVICE_MENU] LANGUAGE"), SettingsGroup::SETTINGS, @@ -384,12 +384,12 @@ void ServiceMenu::initializeOptions() Lang::getText("[SERVICE_MENU] EASY"), Lang::getText("[SERVICE_MENU] NORMAL"), Lang::getText("[SERVICE_MENU] HARD")}); - options_.emplace_back(Lang::getText("[SERVICE_MENU] ENABLE_SHUTDOWN"), SettingsGroup::SETTINGS, OptionBehavior::ADJUST, &Options::game.shutdown_enabled, ValueType::BOOL); + options_.emplace_back(Lang::getText("[SERVICE_MENU] ENABLE_SHUTDOWN"), SettingsGroup::SETTINGS, OptionBehavior::ADJUST, &Options::settings.shutdown_enabled, ValueType::BOOL); // System options_.emplace_back(Lang::getText("[SERVICE_MENU] RESET"), SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE); options_.emplace_back(Lang::getText("[SERVICE_MENU] QUIT"), SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE); - if (Options::game.shutdown_enabled) + if (Options::settings.shutdown_enabled) options_.emplace_back(Lang::getText("[SERVICE_MENU] SHUTDOWN"), SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE); // Menu principal @@ -526,7 +526,7 @@ void ServiceMenu::AdjustListValues() auto option = getOptionEntryByCaption(Lang::getText("[SERVICE_MENU] LANGUAGE")); for (size_t i = 0; i < option->value_list.size(); ++i) { - if (Lang::getCodeFromName(option->value_list[i]) == Options::game.language) + if (Lang::getCodeFromName(option->value_list[i]) == Options::settings.language) { option->list_index = i; } diff --git a/source/title.cpp b/source/title.cpp index e75c578..924e9cd 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -269,14 +269,14 @@ void Title::swapControllers() return; } - Options::swapOptionsControllers(); + Options::swapControllers(); showControllers(); } // Intercambia el teclado de jugador void Title::swapKeyboard() { - Options::swapOptionsKeyboard(); + Options::swapKeyboard(); std::string text = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(Options::getPlayerWhoUsesKeyboard()) + ": " + Lang::getText("[DEFINE_BUTTONS] KEYBOARD"); Notifier::get()->show({text}); }