From 7483bf63c806c4aa7fd4914d8c698f625a4cb9d3 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 28 Mar 2026 20:36:56 +0100 Subject: [PATCH] establir la posicio i habitacio inicial de debug desde la consola --- source/core/system/debug.hpp | 1 + source/game/game_control.hpp | 4 ++++ source/game/scenes/game.cpp | 22 ++++++++++++++++++++++ source/game/ui/console.cpp | 21 +++++++++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/source/core/system/debug.hpp b/source/core/system/debug.hpp index 611bc91..fb1b2e4 100644 --- a/source/core/system/debug.hpp +++ b/source/core/system/debug.hpp @@ -38,6 +38,7 @@ class Debug { 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 private: static Debug* debug; // [SINGLETON] Objeto privado diff --git a/source/game/game_control.hpp b/source/game/game_control.hpp index 6046bf1..776c78b 100644 --- a/source/game/game_control.hpp +++ b/source/game/game_control.hpp @@ -10,5 +10,9 @@ namespace GameControl { inline std::function refresh_player_color; // Registrada por Game::Game() — hace toggle del modo debug (equivale a tecla 0) inline std::function toggle_debug_mode; + // Registrada por Game::Game() — guarda la habitación actual como habitación de inicio en debug.yaml + inline std::function set_initial_room; + // Registrada por Game::Game() — guarda la posición/flip actuales del jugador como posición de inicio en debug.yaml + inline std::function set_initial_pos; } #endif diff --git a/source/game/scenes/game.cpp b/source/game/scenes/game.cpp index ac1dbfb..35dacf1 100644 --- a/source/game/scenes/game.cpp +++ b/source/game/scenes/game.cpp @@ -75,6 +75,26 @@ Game::Game(Mode mode) scoreboard_data_->music = !Debug::get()->isEnabled(); scoreboard_data_->music ? Audio::get()->resumeMusic() : Audio::get()->pauseMusic(); }; + GameControl::set_initial_room = [this]() -> std::string { + auto ss = Debug::get()->getSpawnSettings(); + ss.room = current_room_; + Debug::get()->setSpawnSettings(ss); + Debug::get()->saveToFile(); + const std::string ROOM_NUM = ss.room.substr(0, ss.room.find('.')); + return "Room:" + ROOM_NUM; + }; + GameControl::set_initial_pos = [this]() -> std::string { + auto rect = player_->getRect(); + int tile_x = static_cast((rect.x + (rect.w / 2.0F)) / Tile::SIZE); + int tile_y = static_cast(rect.y / Tile::SIZE); + auto ss = Debug::get()->getSpawnSettings(); + ss.spawn_x = tile_x * Tile::SIZE; + ss.spawn_y = tile_y * Tile::SIZE; + ss.flip = player_->getSpawnParams().flip; + Debug::get()->setSpawnSettings(ss); + Debug::get()->saveToFile(); + return "Pos:" + std::to_string(tile_x) + "," + std::to_string(tile_y); + }; #endif SceneManager::current = (mode_ == Mode::GAME) ? SceneManager::Scene::GAME : SceneManager::Scene::DEMO; @@ -88,6 +108,8 @@ Game::~Game() { GameControl::change_room = nullptr; GameControl::refresh_player_color = nullptr; GameControl::toggle_debug_mode = nullptr; + GameControl::set_initial_room = nullptr; + GameControl::set_initial_pos = nullptr; #endif } diff --git a/source/game/ui/console.cpp b/source/game/ui/console.cpp index 6ad22f2..f837b4e 100644 --- a/source/game/ui/console.cpp +++ b/source/game/ui/console.cpp @@ -92,6 +92,7 @@ static void printHelp() { SDL_Log(" INVENCIBILITY [ON|OFF] Invincibility cheat (GAME only)"); SDL_Log(" OPEN THE JAIL Open the jail (GAME only)"); SDL_Log(" CLOSE THE JAIL Close the jail (GAME only)"); + SDL_Log(" SET INITIAL [ROOM|POS] Set initial room/position from current state (GAME only)"); #endif SDL_Log(" AUDIO [ON|OFF|VOL <0-100>] Audio master"); SDL_Log(" MUSIC [ON|OFF|VOL <0-100>] Music volume"); @@ -449,6 +450,26 @@ static const std::vector COMMANDS = { Options::cheats.jail_is_open = Options::Cheat::State::DISABLED; return "Jail closed"; }}, + + // SET INITIAL [ROOM|POS] — guarda habitación/posición actual como inicio en debug.yaml; solo escena GAME + {.keyword = "SET", .execute = [](const std::vector& args) -> std::string { + if (SceneManager::current != SceneManager::Scene::GAME) { return "Only available in GAME scene"; } + if (args.empty() || args[0] != "INITIAL") { return "Usage: SET INITIAL [ROOM|POS]"; } + + const bool DO_ROOM = args.size() == 1 || (args.size() >= 2 && args[1] == "ROOM"); + const bool DO_POS = args.size() == 1 || (args.size() >= 2 && args[1] == "POS"); + + if (!DO_ROOM && !DO_POS) { return "Usage: SET INITIAL [ROOM|POS]"; } + if (!GameControl::set_initial_room || !GameControl::set_initial_pos) { return "Game not initialized"; } + + std::string result; + if (DO_ROOM) { result = GameControl::set_initial_room(); } + if (DO_POS) { + if (!result.empty()) { result += ", "; } + result += GameControl::set_initial_pos(); + } + return result; + }}, #endif // SCENE [LOGO|LOADING|TITLE|CREDITS|GAME|ENDING|ENDING2|RESTART] — Cambiar o reiniciar escena