From c94adf39af8557fc8012162934d23e618e291c22 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 1 Apr 2026 22:46:02 +0200 Subject: [PATCH] reestructurat els comandos de consola --- data/console/commands.yaml | 24 ++-- source/game/ui/console_commands.cpp | 181 ++++++++++++++-------------- 2 files changed, 102 insertions(+), 103 deletions(-) diff --git a/data/console/commands.yaml b/data/console/commands.yaml index ac78da5..4314c10 100644 --- a/data/console/commands.yaml +++ b/data/console/commands.yaml @@ -117,16 +117,6 @@ categories: PLAYER SKIN: [DEFAULT, ABAD, BATMAN, CHIP, CONGO, JEANNINE, MUMMY, UPV_STUDENT] PLAYER COLOR: [DEFAULT] - - keyword: SET - handler: cmd_set - description: "Set debug options" - usage: "SET INITIAL [ROOM|POS|SCENE] | SET ITEMS <0-200>" - debug_only: true - completions: - SET: [INITIAL, ITEMS] - SET INITIAL: [ROOM, POS, SCENE] - SET INITIAL SCENE: [LOGO, LOADING, TITLE, CREDITS, GAME, ENDING, ENDING2] - - keyword: RESTART handler: cmd_restart description: Restart from the beginning @@ -193,10 +183,18 @@ categories: commands: - keyword: DEBUG handler: cmd_debug - description: "Toggle debug overlay (F12)" - usage: "DEBUG [ON|OFF]" + description: "Debug mode and start options (F12)" + usage: "DEBUG [MODE [ON|OFF]|START [HERE|ROOM|POS|SCENE ]]" completions: - DEBUG: [ON, OFF] + DEBUG: [MODE, START] + DEBUG MODE: [ON, OFF] + DEBUG START: [HERE, ROOM, POS, SCENE] + DEBUG START SCENE: [LOGO, LOADING, TITLE, CREDITS, GAME, ENDING, ENDING2] + + - keyword: ITEMS + handler: cmd_items + description: "Set item count (GAME only)" + usage: "ITEMS <0-200>" - keyword: ROOM handler: cmd_room diff --git a/source/game/ui/console_commands.cpp b/source/game/ui/console_commands.cpp index bdbf3c4..4117b3c 100644 --- a/source/game/ui/console_commands.cpp +++ b/source/game/ui/console_commands.cpp @@ -457,24 +457,86 @@ static auto cmd_sound(const std::vector& args) -> std::string { } #ifdef _DEBUG -// DEBUG [ON|OFF] +// DEBUG [MODE [ON|OFF]|START [HERE|ROOM|POS|SCENE ]] static auto cmd_debug(const std::vector& args) -> std::string { - if (SceneManager::current != SceneManager::Scene::GAME) { return "Only available in GAME scene"; } - if (!GameControl::toggle_debug_mode) { return "Game not initialized"; } - const bool ENABLED = Debug::get()->isEnabled(); - if (!args.empty() && args[0] == "ON") { - if (ENABLED) { return "Debug mode already ON"; } - GameControl::toggle_debug_mode(); - return "Debug mode ON"; + // --- START subcommands (START SCENE works from any scene) --- + if (!args.empty() && args[0] == "START") { + // START SCENE [] — works from any scene + if (args.size() >= 2 && args[1] == "SCENE") { + SceneManager::Scene target = SceneManager::current; + std::string name = "current"; + if (args.size() >= 3) { + if (args[2] == "GAME") { + target = SceneManager::Scene::GAME; + name = "game"; + } else if (args[2] == "LOGO") { + target = SceneManager::Scene::LOGO; + name = "logo"; + } else if (args[2] == "LOADING") { + target = SceneManager::Scene::LOADING_SCREEN; + name = "loading"; + } else if (args[2] == "TITLE") { + target = SceneManager::Scene::TITLE; + name = "title"; + } else if (args[2] == "CREDITS") { + target = SceneManager::Scene::CREDITS; + name = "credits"; + } else if (args[2] == "ENDING") { + target = SceneManager::Scene::ENDING; + name = "ending"; + } else if (args[2] == "ENDING2") { + target = SceneManager::Scene::ENDING2; + name = "ending2"; + } else { + std::string scene_lower = args[2]; + std::ranges::transform(scene_lower, scene_lower.begin(), ::tolower); + return "Unknown scene: " + scene_lower; + } + } + Debug::get()->setInitialScene(target); + Debug::get()->saveToFile(); + return "Initial scene set to: " + name; + } + + // START HERE|ROOM|POS — requires GAME scene + if (SceneManager::current != SceneManager::Scene::GAME) { return "Only available in GAME scene"; } + if (!GameControl::set_initial_room || !GameControl::set_initial_pos) { return "Game not initialized"; } + + const bool DO_ROOM = args.size() == 1 || args[1] == "HERE" || args[1] == "ROOM"; + const bool DO_POS = args.size() == 1 || args[1] == "HERE" || args[1] == "POS"; + + if (!DO_ROOM && !DO_POS) { return "usage: debug start [here|room|pos|scene ]"; } + + 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; } - if (!args.empty() && args[0] == "OFF") { - if (!ENABLED) { return "Debug mode already OFF"; } + + // --- MODE [ON|OFF] toggle (requires GAME scene) --- + if (!args.empty() && args[0] == "MODE") { + if (SceneManager::current != SceneManager::Scene::GAME) { return "Only available in GAME scene"; } + if (!GameControl::toggle_debug_mode) { return "Game not initialized"; } + const bool ENABLED = Debug::get()->isEnabled(); + if (args.size() >= 2 && args[1] == "ON") { + if (ENABLED) { return "Debug mode already ON"; } + GameControl::toggle_debug_mode(); + return "Debug mode ON"; + } + if (args.size() >= 2 && args[1] == "OFF") { + if (!ENABLED) { return "Debug mode already OFF"; } + GameControl::toggle_debug_mode(); + return "Debug mode OFF"; + } + if (args.size() >= 2) { return "usage: debug mode [on|off]"; } GameControl::toggle_debug_mode(); - return "Debug mode OFF"; + return std::string("Debug mode ") + (Debug::get()->isEnabled() ? "ON" : "OFF"); } - if (!args.empty()) { return "usage: debug [on|off]"; } - GameControl::toggle_debug_mode(); - return std::string("Debug mode ") + (Debug::get()->isEnabled() ? "ON" : "OFF"); + + return "usage: debug [mode [on|off]|start [here|room|pos|scene ]]"; } // ROOM |NEXT|PREV @@ -503,6 +565,20 @@ static auto cmd_room(const std::vector& args) -> std::string { return std::string("Room not found: ") + buf; } +// ITEMS <0-200> +static auto cmd_items(const std::vector& args) -> std::string { + if (SceneManager::current != SceneManager::Scene::GAME) { return "Only available in GAME scene"; } + if (args.empty()) { return "usage: items <0-200>"; } + int count = 0; + try { + count = std::stoi(args[0]); + } catch (...) { return "usage: items <0-200>"; } + if (count < 0 || count > 200) { return "Items must be between 0 and 200"; } + if (!GameControl::set_items) { return "Game not initialized"; } + GameControl::set_items(count); + return "Items: " + std::to_string(count); +} + // SCENE [LOGO|LOADING|TITLE|CREDITS|GAME|ENDING|ENDING2|RESTART] static auto cmd_scene(const std::vector& args) -> std::string { if (Options::kiosk.enabled) { return "Not allowed in kiosk mode"; } @@ -660,81 +736,6 @@ static auto cmd_player(const std::vector& args) -> std::string { return "usage: player skin | player color <0-15>|default"; } -// SET INITIAL / SET ITEMS -static auto cmd_set(const std::vector& args) -> std::string { -#ifdef _DEBUG - // SET INITIAL SCENE [] - if (args.size() >= 2 && args[0] == "INITIAL" && args[1] == "SCENE") { - SceneManager::Scene target = SceneManager::current; - std::string name = "current"; - if (args.size() >= 3) { - if (args[2] == "GAME") { - target = SceneManager::Scene::GAME; - name = "game"; - } else if (args[2] == "LOGO") { - target = SceneManager::Scene::LOGO; - name = "logo"; - } else if (args[2] == "LOADING") { - target = SceneManager::Scene::LOADING_SCREEN; - name = "loading"; - } else if (args[2] == "TITLE") { - target = SceneManager::Scene::TITLE; - name = "title"; - } else if (args[2] == "CREDITS") { - target = SceneManager::Scene::CREDITS; - name = "credits"; - } else if (args[2] == "ENDING") { - target = SceneManager::Scene::ENDING; - name = "ending"; - } else if (args[2] == "ENDING2") { - target = SceneManager::Scene::ENDING2; - name = "ending2"; - } else { - std::string scene_lower = args[2]; - std::ranges::transform(scene_lower, scene_lower.begin(), ::tolower); - return "Unknown scene: " + scene_lower; - } - } - Debug::get()->setInitialScene(target); - Debug::get()->saveToFile(); - return "Initial scene set to: " + name; - } - - if (SceneManager::current != SceneManager::Scene::GAME) { return "Only available in GAME scene"; } - - // SET ITEMS <0-200> - if (!args.empty() && args[0] == "ITEMS") { - if (args.size() < 2) { return "usage: set items <0-200>"; } - int count = 0; - try { - count = std::stoi(args[1]); - } catch (...) { return "usage: set items <0-200>"; } - if (count < 0 || count > 200) { return "Items must be between 0 and 200"; } - if (!GameControl::set_items) { return "Game not initialized"; } - GameControl::set_items(count); - return "Items: " + std::to_string(count); - } - - if (args.empty() || args[0] != "INITIAL") { return "usage: set initial [room|pos|scene] | set items <0-200>"; } - - 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|scene]"; } - 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; -#else - return "Debug only command"; -#endif -} - // RESTART static auto cmd_restart(const std::vector&) -> std::string { SceneManager::current = SceneManager::Scene::LOGO; @@ -798,7 +799,6 @@ void CommandRegistry::registerHandlers() { handlers_["cmd_hide"] = cmd_hide; handlers_["cmd_cheat"] = cmd_cheat; handlers_["cmd_player"] = cmd_player; - handlers_["cmd_set"] = cmd_set; handlers_["cmd_restart"] = cmd_restart; handlers_["cmd_kiosk"] = cmd_kiosk; handlers_["cmd_exit"] = cmd_exit; @@ -806,6 +806,7 @@ void CommandRegistry::registerHandlers() { handlers_["cmd_size"] = cmd_size; #ifdef _DEBUG handlers_["cmd_debug"] = cmd_debug; + handlers_["cmd_items"] = cmd_items; handlers_["cmd_room"] = cmd_room; handlers_["cmd_scene"] = cmd_scene; #endif