From 1bb2142d190e5a9ec7de4ca50b10dfe78994c2a7 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 29 Mar 2026 12:58:32 +0200 Subject: [PATCH] fix: corregida logica per obrir i entrar a la jail. ja no mira el nom de la habitacio sino el numero --- source/core/system/debug.cpp | 32 ++++++++++++++++++++------------ source/core/system/debug.hpp | 24 ++++++++++++------------ source/game/defaults.hpp | 5 +++++ source/game/game_control.hpp | 2 +- source/game/gameplay/room.cpp | 3 ++- source/game/gameplay/room.hpp | 1 + source/game/scene_manager.hpp | 4 ++-- source/game/scenes/game.cpp | 8 +++++--- source/game/ui/console.cpp | 35 +++++++++++++++++++++++++---------- 9 files changed, 73 insertions(+), 41 deletions(-) diff --git a/source/core/system/debug.cpp b/source/core/system/debug.cpp index 8f9a91e..8d475b3 100644 --- a/source/core/system/debug.cpp +++ b/source/core/system/debug.cpp @@ -94,12 +94,12 @@ void Debug::setDebugFile(const std::string& path) { // Convierte string a SceneManager::Scene (para debug.yaml) static auto sceneFromString(const std::string& s) -> SceneManager::Scene { - if (s == "LOGO") { return SceneManager::Scene::LOGO; } + if (s == "LOGO") { return SceneManager::Scene::LOGO; } if (s == "LOADING") { return SceneManager::Scene::LOADING_SCREEN; } - if (s == "TITLE") { return SceneManager::Scene::TITLE; } + if (s == "TITLE") { return SceneManager::Scene::TITLE; } if (s == "CREDITS") { return SceneManager::Scene::CREDITS; } - if (s == "DEMO") { return SceneManager::Scene::DEMO; } - if (s == "ENDING") { return SceneManager::Scene::ENDING; } + if (s == "DEMO") { return SceneManager::Scene::DEMO; } + if (s == "ENDING") { return SceneManager::Scene::ENDING; } if (s == "ENDING2") { return SceneManager::Scene::ENDING2; } return SceneManager::Scene::GAME; // Fallback seguro } @@ -107,14 +107,22 @@ static auto sceneFromString(const std::string& s) -> SceneManager::Scene { // Convierte SceneManager::Scene a string (para debug.yaml) static auto sceneToString(SceneManager::Scene scene) -> std::string { switch (scene) { - case SceneManager::Scene::LOGO: return "LOGO"; - case SceneManager::Scene::LOADING_SCREEN: return "LOADING"; - case SceneManager::Scene::TITLE: return "TITLE"; - case SceneManager::Scene::CREDITS: return "CREDITS"; - case SceneManager::Scene::DEMO: return "DEMO"; - case SceneManager::Scene::ENDING: return "ENDING"; - case SceneManager::Scene::ENDING2: return "ENDING2"; - default: return "GAME"; + case SceneManager::Scene::LOGO: + return "LOGO"; + case SceneManager::Scene::LOADING_SCREEN: + return "LOADING"; + case SceneManager::Scene::TITLE: + return "TITLE"; + case SceneManager::Scene::CREDITS: + return "CREDITS"; + case SceneManager::Scene::DEMO: + return "DEMO"; + case SceneManager::Scene::ENDING: + return "ENDING"; + case SceneManager::Scene::ENDING2: + return "ENDING2"; + default: + return "GAME"; } } diff --git a/source/core/system/debug.hpp b/source/core/system/debug.hpp index e04e944..45a73e6 100644 --- a/source/core/system/debug.hpp +++ b/source/core/system/debug.hpp @@ -43,10 +43,10 @@ class Debug { void setDebugFile(const std::string& path); // Establece la ruta del archivo debug.yaml void loadFromFile(); // Carga la configuración de debug desde debug.yaml void saveToFile() const; // Guarda la configuración de debug en debug.yaml - [[nodiscard]] auto getSpawnSettings() const -> const SpawnSettings& { return spawn_settings_; } // Obtiene los valores de spawn - void setSpawnSettings(const SpawnSettings& s) { spawn_settings_ = s; } // Establece los valores de spawn - [[nodiscard]] auto getInitialScene() const -> SceneManager::Scene { return initial_scene_; } // Obtiene la escena inicial de debug - void setInitialScene(SceneManager::Scene s) { initial_scene_ = s; } // Establece la escena inicial de debug + [[nodiscard]] auto getSpawnSettings() const -> const SpawnSettings& { return spawn_settings_; } // Obtiene los valores de spawn + void setSpawnSettings(const SpawnSettings& s) { spawn_settings_ = s; } // Establece los valores de spawn + [[nodiscard]] auto getInitialScene() const -> SceneManager::Scene { return initial_scene_; } // Obtiene la escena inicial de debug + void setInitialScene(SceneManager::Scene s) { initial_scene_ = s; } // Establece la escena inicial de debug private: static Debug* debug; // [SINGLETON] Objeto privado @@ -55,14 +55,14 @@ class Debug { ~Debug() = default; // Destructor // Variables - std::map watches_; // Watch window: valores persistentes (key→value) - std::vector slot_; // One-shot: textos que se limpian cada frame - std::vector log_; // Log persistente - int x_ = 0; // Posicion donde escribir el texto de debug - int y_ = 0; // Posición donde escribir el texto de debug - bool enabled_ = false; // Indica si esta activo el modo debug - std::string debug_file_path_; // Ruta del archivo debug.yaml - SpawnSettings spawn_settings_; // Configuración de spawn para debug + std::map watches_; // Watch window: valores persistentes (key→value) + std::vector slot_; // One-shot: textos que se limpian cada frame + std::vector log_; // Log persistente + int x_ = 0; // Posicion donde escribir el texto de debug + int y_ = 0; // Posición donde escribir el texto de debug + bool enabled_ = false; // Indica si esta activo el modo debug + std::string debug_file_path_; // Ruta del archivo debug.yaml + SpawnSettings spawn_settings_; // Configuración de spawn para debug SceneManager::Scene initial_scene_ = SceneManager::Scene::GAME; // Escena inicial en debug }; diff --git a/source/game/defaults.hpp b/source/game/defaults.hpp index fd8c2fa..744b5e0 100644 --- a/source/game/defaults.hpp +++ b/source/game/defaults.hpp @@ -88,8 +88,13 @@ namespace Defaults::Localization { constexpr const char* LANGUAGE = "ca"; // Idioma por defecto (en = inglés, ca = catalán) } // namespace Defaults::Localization +namespace Defaults::Game::Items { + constexpr const float PERCENT_TO_OPEN_THE_JAIL = 0.9F; // Porcentaje de items necesarios para abrir la jail +} // namespace Defaults::Game::Items + namespace Defaults::Game::Room { constexpr const char* INITIAL = "03.yaml"; // Habitación de inicio + constexpr const char* END_ROOM = "01"; // Habitación final (jail) } // namespace Defaults::Game::Room namespace Defaults::Game::Player { diff --git a/source/game/game_control.hpp b/source/game/game_control.hpp index 1c3dc1d..30b167b 100644 --- a/source/game/game_control.hpp +++ b/source/game/game_control.hpp @@ -5,7 +5,7 @@ namespace GameControl { // Disponible en todos los builds — refresca el color del jugador según cheats inline std::function refresh_player_color; -} +} // namespace GameControl #ifdef _DEBUG namespace GameControl { diff --git a/source/game/gameplay/room.cpp b/source/game/gameplay/room.cpp index c9c7683..57ca566 100644 --- a/source/game/gameplay/room.cpp +++ b/source/game/gameplay/room.cpp @@ -5,6 +5,7 @@ #include "core/rendering/screen.hpp" // Para Screen #include "core/rendering/surface.hpp" // Para Surface #include "core/resources/resource_cache.hpp" // Para Resource +#include "game/defaults.hpp" // Para Defaults::Game #include "game/gameplay/collision_map.hpp" // Para CollisionMap #include "game/gameplay/enemy_manager.hpp" // Para EnemyManager #include "game/gameplay/item_manager.hpp" // Para ItemManager @@ -82,7 +83,7 @@ void Room::initializeRoom(const Data& room) { // Abre la jail para poder entrar void Room::openTheJail() { // NOLINT(readability-convert-member-functions-to-static) - if (data_->jail_is_open && name_ == "THE JAIL") { + if (data_->jail_is_open && number_ == Defaults::Game::Room::END_ROOM) { // Elimina el último enemigo (Bry debe ser el último enemigo definido en el fichero) if (!enemy_manager_->isEmpty()) { enemy_manager_->removeLastEnemy(); diff --git a/source/game/gameplay/room.hpp b/source/game/gameplay/room.hpp index c8bb04f..c05a49f 100644 --- a/source/game/gameplay/room.hpp +++ b/source/game/gameplay/room.hpp @@ -61,6 +61,7 @@ class Room { ~Room(); // NOLINT(modernize-use-equals-default, performance-trivially-destructible) -- defined in .cpp for unique_ptr with forward declarations // --- Funciones --- + [[nodiscard]] auto getNumber() const -> const std::string& { return number_; } // Devuelve el numero de la habitación [[nodiscard]] auto getName() const -> const std::string& { return name_; } // Devuelve el nombre de la habitación [[nodiscard]] auto getBGColor() const -> Uint8 { return stringToColor(bg_color_); } // Devuelve el color de la habitación [[nodiscard]] auto getBorderColor() const -> Uint8 { return stringToColor(border_color_); } // Devuelve el color del borde diff --git a/source/game/scene_manager.hpp b/source/game/scene_manager.hpp index b21b467..89a2f35 100644 --- a/source/game/scene_manager.hpp +++ b/source/game/scene_manager.hpp @@ -33,8 +33,8 @@ namespace SceneManager { TITLE_WITHOUT_LOADING_SCREEN // Al título sin pantalla de carga }; -// --- Variables de estado globales --- - inline Scene current = Scene::LOGO; // Escena actual (en _DEBUG sobrescrito por Director tras cargar debug.yaml) + // --- Variables de estado globales --- + inline Scene current = Scene::LOGO; // Escena actual (en _DEBUG sobrescrito por Director tras cargar debug.yaml) inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual inline Scene scene_before_restart = Scene::LOGO; // escena a relanzar tras RESTART_CURRENT diff --git a/source/game/scenes/game.cpp b/source/game/scenes/game.cpp index 5d63eb9..1e0c615 100644 --- a/source/game/scenes/game.cpp +++ b/source/game/scenes/game.cpp @@ -720,9 +720,11 @@ void Game::setScoreBoardColor() { // NOLINT(readability-convert-member-function // Comprueba si ha finalizado el juego auto Game::checkEndGame() -> bool { - const bool IS_ON_THE_ROOM = room_->getName() == "THE JAIL"; // Estar en la habitación que toca - const bool HAVE_THE_ITEMS = scoreboard_data_->items >= int(total_items_ * 0.9F) || Options::cheats.jail_is_open == Options::Cheat::State::ENABLED; // Con mas del 90% de los items recogidos - const bool IS_ON_THE_DOOR = player_->getRect().x <= 128; // Y en la ubicación que toca (En la puerta) + const bool IS_ON_THE_ROOM = room_->getNumber() == Defaults::Game::Room::END_ROOM; // Estar en la habitación que toca + const bool HAVE_THE_ITEMS = + scoreboard_data_->items >= int(total_items_ * Defaults::Game::Items::PERCENT_TO_OPEN_THE_JAIL) || + Options::cheats.jail_is_open == Options::Cheat::State::ENABLED; // Con mas del 90% de los items recogidos + const bool IS_ON_THE_DOOR = player_->getRect().x <= 128; // Y en la ubicación que toca (En la puerta) scoreboard_data_->jail_is_open = HAVE_THE_ITEMS; diff --git a/source/game/ui/console.cpp b/source/game/ui/console.cpp index 326a0e3..dff1a6e 100644 --- a/source/game/ui/console.cpp +++ b/source/game/ui/console.cpp @@ -15,12 +15,11 @@ #include "core/rendering/surface.hpp" // Para Surface #include "core/rendering/text.hpp" // Para Text #include "core/resources/resource_cache.hpp" // Para Resource +#include "game/game_control.hpp" // Para GameControl (refresh_player_color) #include "game/options.hpp" // Para Options #include "game/scene_manager.hpp" // Para SceneManager #include "game/ui/notifier.hpp" // Para Notifier -#include "game/game_control.hpp" // Para GameControl (refresh_player_color) - #ifdef _DEBUG #include "core/system/debug.hpp" // Para Debug #endif @@ -500,14 +499,30 @@ static const std::vector COMMANDS = { SceneManager::Scene target = SceneManager::current; std::string name = "current"; if (args.size() >= 3) { - if (args[2] == "GAME") { target = SceneManager::Scene::GAME; name = "GAME"; } - else if (args[2] == "LOGO") { target = SceneManager::Scene::LOGO; name = "LOGO"; } - else if (args[2] == "LOADING") { target = SceneManager::Scene::LOADING_SCREEN; name = "LOADING"; } - else if (args[2] == "TITLE") { target = SceneManager::Scene::TITLE; name = "TITLE"; } - else if (args[2] == "CREDITS") { target = SceneManager::Scene::CREDITS; name = "CREDITS"; } - else if (args[2] == "ENDING") { target = SceneManager::Scene::ENDING; name = "ENDING"; } - else if (args[2] == "ENDING2") { target = SceneManager::Scene::ENDING2; name = "ENDING2"; } - else { return "Unknown scene: " + args[2]; } + if (args[2] == "GAME") { + target = SceneManager::Scene::GAME; + name = "GAME"; + } else if (args[2] == "LOGO") { + target = SceneManager::Scene::LOGO; + name = "LOGO"; + } else if (args[2] == "LOADING") { + target = SceneManager::Scene::LOADING_SCREEN; + name = "LOADING"; + } else if (args[2] == "TITLE") { + target = SceneManager::Scene::TITLE; + name = "TITLE"; + } else if (args[2] == "CREDITS") { + target = SceneManager::Scene::CREDITS; + name = "CREDITS"; + } else if (args[2] == "ENDING") { + target = SceneManager::Scene::ENDING; + name = "ENDING"; + } else if (args[2] == "ENDING2") { + target = SceneManager::Scene::ENDING2; + name = "ENDING2"; + } else { + return "Unknown scene: " + args[2]; + } } Debug::get()->setInitialScene(target); Debug::get()->saveToFile();