From 0c8aa5fe50781a7f7f54a0cfcaa55825a05f8ccb Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 1 Apr 2026 20:17:31 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20entrar=20i=20eixir=20al=20mode=20debug?= =?UTF-8?q?=20mant=C3=A9=20l'estat=20previ=20del=20jugador?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/game/scenes/game.cpp | 23 ++++++++++++++++++++--- source/game/scenes/game.hpp | 2 ++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/source/game/scenes/game.cpp b/source/game/scenes/game.cpp index a2ab6e1..4227402 100644 --- a/source/game/scenes/game.cpp +++ b/source/game/scenes/game.cpp @@ -80,9 +80,17 @@ Game::Game(Mode mode) Options::stats.items = count; }; GameControl::toggle_debug_mode = [this]() -> void { + const bool ENTERING_DEBUG = !Debug::get()->isEnabled(); + if (ENTERING_DEBUG) { + invincible_before_debug_ = (Options::cheats.invincible == Options::Cheat::State::ENABLED); + } Debug::get()->toggleEnabled(); room_->redrawMap(); - Options::cheats.invincible = static_cast(Debug::get()->isEnabled()); + if (Debug::get()->isEnabled()) { + Options::cheats.invincible = Options::Cheat::State::ENABLED; + } else { + Options::cheats.invincible = invincible_before_debug_ ? Options::Cheat::State::ENABLED : Options::Cheat::State::DISABLED; + } player_->setColor(); scoreboard_data_->music = !Debug::get()->isEnabled(); scoreboard_data_->music ? Audio::get()->resumeMusic() : Audio::get()->pauseMusic(); @@ -512,15 +520,24 @@ void Game::handleDebugEvents(const SDL_Event& event) { // NOLINT(readability-co Notifier::get()->show({Locale::get()->get("achievements.header"), Locale::get()->get("achievements.c11")}, Notifier::Style::CHEEVO, -1, false, "F7"); // NOLINT(readability-static-accessed-through-instance) break; - case SDLK_0: + case SDLK_0: { + const bool ENTERING_DEBUG = !Debug::get()->isEnabled(); + if (ENTERING_DEBUG) { + invincible_before_debug_ = (Options::cheats.invincible == Options::Cheat::State::ENABLED); + } Debug::get()->toggleEnabled(); Notifier::get()->show({Debug::get()->isEnabled() ? Locale::get()->get("game.debug_enabled") : Locale::get()->get("game.debug_disabled")}); // NOLINT(readability-static-accessed-through-instance) room_->redrawMap(); - Options::cheats.invincible = static_cast(Debug::get()->isEnabled()); + if (Debug::get()->isEnabled()) { + Options::cheats.invincible = Options::Cheat::State::ENABLED; + } else { + Options::cheats.invincible = invincible_before_debug_ ? Options::Cheat::State::ENABLED : Options::Cheat::State::DISABLED; + } player_->setColor(); scoreboard_data_->music = !Debug::get()->isEnabled(); scoreboard_data_->music ? Audio::get()->resumeMusic() : Audio::get()->pauseMusic(); break; + } default: break; diff --git a/source/game/scenes/game.hpp b/source/game/scenes/game.hpp index 32b6de5..ce42bbc 100644 --- a/source/game/scenes/game.hpp +++ b/source/game/scenes/game.hpp @@ -130,5 +130,7 @@ class Game { // Variables de debug para arrastre con ratón bool debug_dragging_player_{false}; // Indica si estamos arrastrando al jugador con el ratón float debug_drag_speed_{0.0F}; // Velocidad actual del arrastre (ease-in) + // Estado previo de invencibilidad antes de entrar en modo debug + bool invincible_before_debug_{false}; #endif }; \ No newline at end of file