establir la posicio i habitacio inicial de debug desde la consola

This commit is contained in:
2026-03-28 20:36:56 +01:00
parent 268763f162
commit 7483bf63c8
4 changed files with 48 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ class Debug {
void loadFromFile(); // Carga la configuración de debug desde 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 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 [[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: private:
static Debug* debug; // [SINGLETON] Objeto privado static Debug* debug; // [SINGLETON] Objeto privado

View File

@@ -10,5 +10,9 @@ namespace GameControl {
inline std::function<void()> refresh_player_color; inline std::function<void()> refresh_player_color;
// Registrada por Game::Game() — hace toggle del modo debug (equivale a tecla 0) // Registrada por Game::Game() — hace toggle del modo debug (equivale a tecla 0)
inline std::function<void()> toggle_debug_mode; inline std::function<void()> toggle_debug_mode;
// Registrada por Game::Game() — guarda la habitación actual como habitación de inicio en debug.yaml
inline std::function<std::string()> 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<std::string()> set_initial_pos;
} }
#endif #endif

View File

@@ -75,6 +75,26 @@ Game::Game(Mode mode)
scoreboard_data_->music = !Debug::get()->isEnabled(); scoreboard_data_->music = !Debug::get()->isEnabled();
scoreboard_data_->music ? Audio::get()->resumeMusic() : Audio::get()->pauseMusic(); 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<int>((rect.x + (rect.w / 2.0F)) / Tile::SIZE);
int tile_y = static_cast<int>(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 #endif
SceneManager::current = (mode_ == Mode::GAME) ? SceneManager::Scene::GAME : SceneManager::Scene::DEMO; SceneManager::current = (mode_ == Mode::GAME) ? SceneManager::Scene::GAME : SceneManager::Scene::DEMO;
@@ -88,6 +108,8 @@ Game::~Game() {
GameControl::change_room = nullptr; GameControl::change_room = nullptr;
GameControl::refresh_player_color = nullptr; GameControl::refresh_player_color = nullptr;
GameControl::toggle_debug_mode = nullptr; GameControl::toggle_debug_mode = nullptr;
GameControl::set_initial_room = nullptr;
GameControl::set_initial_pos = nullptr;
#endif #endif
} }

View File

@@ -92,6 +92,7 @@ static void printHelp() {
SDL_Log(" INVENCIBILITY [ON|OFF] Invincibility cheat (GAME only)"); SDL_Log(" INVENCIBILITY [ON|OFF] Invincibility cheat (GAME only)");
SDL_Log(" OPEN THE JAIL Open the jail (GAME only)"); SDL_Log(" OPEN THE JAIL Open the jail (GAME only)");
SDL_Log(" CLOSE THE JAIL Close 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 #endif
SDL_Log(" AUDIO [ON|OFF|VOL <0-100>] Audio master"); SDL_Log(" AUDIO [ON|OFF|VOL <0-100>] Audio master");
SDL_Log(" MUSIC [ON|OFF|VOL <0-100>] Music volume"); SDL_Log(" MUSIC [ON|OFF|VOL <0-100>] Music volume");
@@ -449,6 +450,26 @@ static const std::vector<ConsoleCommand> COMMANDS = {
Options::cheats.jail_is_open = Options::Cheat::State::DISABLED; Options::cheats.jail_is_open = Options::Cheat::State::DISABLED;
return "Jail closed"; 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<std::string>& 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 #endif
// SCENE [LOGO|LOADING|TITLE|CREDITS|GAME|ENDING|ENDING2|RESTART] — Cambiar o reiniciar escena // SCENE [LOGO|LOADING|TITLE|CREDITS|GAME|ENDING|ENDING2|RESTART] — Cambiar o reiniciar escena