diff --git a/data/console/commands.yaml b/data/console/commands.yaml index 6179a50..75113f5 100644 --- a/data/console/commands.yaml +++ b/data/console/commands.yaml @@ -201,9 +201,9 @@ categories: - keyword: ROOM handler: cmd_room description: "Change to room number (GAME only)" - usage: "ROOM <1-60>|NEXT|PREV" + usage: "ROOM <1-60>|NEXT|PREV|LEFT|RIGHT|UP|DOWN" completions: - ROOM: [NEXT, PREV] + ROOM: [NEXT, PREV, LEFT, RIGHT, UP, DOWN] - keyword: SCENE handler: cmd_scene diff --git a/source/game/game_control.hpp b/source/game/game_control.hpp index d42acf3..5a193d7 100644 --- a/source/game/game_control.hpp +++ b/source/game/game_control.hpp @@ -27,6 +27,7 @@ namespace GameControl { inline std::function enter_editor; inline std::function exit_editor; inline std::function revert_editor; - inline std::function reload_current_room; // Recarga la habitación actual desde disco + inline std::function reload_current_room; // Recarga la habitación actual desde disco + inline std::function get_adjacent_room; // Obtiene la room adyacente (UP/DOWN/LEFT/RIGHT) } // namespace GameControl #endif diff --git a/source/game/scenes/game.cpp b/source/game/scenes/game.cpp index daadc11..44b1720 100644 --- a/source/game/scenes/game.cpp +++ b/source/game/scenes/game.cpp @@ -133,6 +133,13 @@ Game::Game(Mode mode) GameControl::revert_editor = []() -> std::string { return MapEditor::get()->revert(); }; + GameControl::get_adjacent_room = [this](const std::string& direction) -> std::string { + if (direction == "UP") { return room_->getRoom(Room::Border::TOP); } + if (direction == "DOWN") { return room_->getRoom(Room::Border::BOTTOM); } + if (direction == "LEFT") { return room_->getRoom(Room::Border::LEFT); } + if (direction == "RIGHT") { return room_->getRoom(Room::Border::RIGHT); } + return "0"; + }; #endif SceneManager::current = (mode_ == Mode::GAME) ? SceneManager::Scene::GAME : SceneManager::Scene::DEMO; @@ -158,6 +165,7 @@ Game::~Game() { GameControl::exit_editor = nullptr; GameControl::revert_editor = nullptr; GameControl::reload_current_room = nullptr; + GameControl::get_adjacent_room = nullptr; #endif } diff --git a/source/game/ui/console_commands.cpp b/source/game/ui/console_commands.cpp index 26874ca..18d0dd5 100644 --- a/source/game/ui/console_commands.cpp +++ b/source/game/ui/console_commands.cpp @@ -22,7 +22,8 @@ #include "utils/utils.hpp" // Para toUpper, prettyName #ifdef _DEBUG -#include "core/system/debug.hpp" // Para Debug +#include "core/system/debug.hpp" // Para Debug +#include "game/editor/map_editor.hpp" // Para MapEditor #endif // ── Helpers ────────────────────────────────────────────────────────────────── @@ -560,9 +561,48 @@ static auto cmd_debug(const std::vector& args) -> std::string { } // ROOM |NEXT|PREV +// Helper: cambia de room teniendo en cuenta el editor (exit → change → re-enter) +static auto changeRoomWithEditor(const std::string& room_file) -> std::string { + if (!GameControl::change_room) { return "Game not initialized"; } + + const bool EDITOR_WAS_ACTIVE = MapEditor::get() && MapEditor::get()->isActive(); + + // Si el editor está activo, salir primero (guarda y recarga la room actual) + if (EDITOR_WAS_ACTIVE && GameControl::exit_editor) { + GameControl::exit_editor(); + } + + // Cambiar de habitación + if (!GameControl::change_room(room_file)) { + // Si falla, re-entrar al editor en la room original + if (EDITOR_WAS_ACTIVE && GameControl::enter_editor) { + GameControl::enter_editor(); + } + return std::string("Room not found: ") + room_file; + } + + // Si el editor estaba activo, re-entrar en la nueva room + if (EDITOR_WAS_ACTIVE && GameControl::enter_editor) { + GameControl::enter_editor(); + } + + return std::string("Room: ") + room_file; +} + static auto cmd_room(const std::vector& args) -> std::string { if (SceneManager::current != SceneManager::Scene::GAME) { return "Only available in GAME scene"; } - if (args.empty()) { return "usage: room <1-60>|next|prev"; } + if (args.empty()) { return "usage: room <1-60>|next|prev|left|right|up|down"; } + + // Direcciones: LEFT, RIGHT, UP, DOWN + if (args[0] == "LEFT" || args[0] == "RIGHT" || args[0] == "UP" || args[0] == "DOWN") { + if (!GameControl::get_adjacent_room) { return "Game not initialized"; } + const std::string ADJACENT = GameControl::get_adjacent_room(args[0]); + if (ADJACENT == "0" || ADJACENT.empty()) { + return "No room " + toLower(args[0]); + } + return changeRoomWithEditor(ADJACENT); + } + int num = 0; if (args[0] == "NEXT" || args[0] == "PREV") { if (!GameControl::get_current_room) { return "Game not initialized"; } @@ -574,15 +614,12 @@ static auto cmd_room(const std::vector& args) -> std::string { } else { try { num = std::stoi(args[0]); - } catch (...) { return "usage: room <1-60>|next|prev"; } + } catch (...) { return "usage: room <1-60>|next|prev|left|right|up|down"; } } if (num < 1 || num > 60) { return "Room must be between 1 and 60"; } char buf[16]; std::snprintf(buf, sizeof(buf), "%02d.yaml", num); - if (GameControl::change_room && GameControl::change_room(buf)) { - return std::string("Room: ") + buf; - } - return std::string("Room not found: ") + buf; + return changeRoomWithEditor(buf); } // ITEMS <0-200> @@ -632,7 +669,19 @@ static auto cmd_scene(const std::vector& args) -> std::string { // EDIT [ON|OFF|REVERT] static auto cmd_edit(const std::vector& args) -> std::string { - if (args.empty() || args[0] == "ON") { + if (args.empty()) { + // Toggle: si está activo → off, si no → on + if (MapEditor::get() && MapEditor::get()->isActive()) { + if (GameControl::exit_editor) { GameControl::exit_editor(); } + return "Editor OFF"; + } + if (GameControl::enter_editor) { + GameControl::enter_editor(); + return "Editor ON"; + } + return "Not in game"; + } + if (args[0] == "ON") { if (GameControl::enter_editor) { GameControl::enter_editor(); return "Editor ON";