reestructurat els comandos de consola

This commit is contained in:
2026-04-01 22:46:02 +02:00
parent 950eeffb07
commit c94adf39af
2 changed files with 102 additions and 103 deletions

View File

@@ -457,24 +457,86 @@ static auto cmd_sound(const std::vector<std::string>& args) -> std::string {
}
#ifdef _DEBUG
// DEBUG [ON|OFF]
// DEBUG [MODE [ON|OFF]|START [HERE|ROOM|POS|SCENE <name>]]
static auto cmd_debug(const std::vector<std::string>& 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 [<name>] — 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 <name>]"; }
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 <name>]]";
}
// ROOM <num>|NEXT|PREV
@@ -503,6 +565,20 @@ static auto cmd_room(const std::vector<std::string>& args) -> std::string {
return std::string("Room not found: ") + buf;
}
// ITEMS <0-200>
static auto cmd_items(const std::vector<std::string>& 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<std::string>& args) -> std::string {
if (Options::kiosk.enabled) { return "Not allowed in kiosk mode"; }
@@ -660,81 +736,6 @@ static auto cmd_player(const std::vector<std::string>& args) -> std::string {
return "usage: player skin <name> | player color <0-15>|default";
}
// SET INITIAL / SET ITEMS
static auto cmd_set(const std::vector<std::string>& args) -> std::string {
#ifdef _DEBUG
// SET INITIAL SCENE [<nombre>]
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>&) -> 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