establir la posicio i habitacio inicial de debug desde la consola
This commit is contained in:
@@ -10,5 +10,9 @@ namespace GameControl {
|
||||
inline std::function<void()> refresh_player_color;
|
||||
// Registrada por Game::Game() — hace toggle del modo debug (equivale a tecla 0)
|
||||
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
|
||||
|
||||
@@ -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<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
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ConsoleCommand> 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<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
|
||||
|
||||
// SCENE [LOGO|LOADING|TITLE|CREDITS|GAME|ENDING|ENDING2|RESTART] — Cambiar o reiniciar escena
|
||||
|
||||
Reference in New Issue
Block a user