posat un poc d'ordre en els comandos de la consola

This commit is contained in:
2026-04-03 07:50:11 +02:00
parent 6faa80eef4
commit 052607873b
4 changed files with 57 additions and 40 deletions

View File

@@ -1033,6 +1033,16 @@ void CommandRegistry::registerHandlers() {
dynamic_providers_["EDIT MAPBG"] = color_provider;
dynamic_providers_["EDIT MAPCONN"] = color_provider;
// SET: propiedades dinámicas según selección en el editor
dynamic_providers_["SET"] = []() -> std::vector<std::string> {
if (MapEditor::get() != nullptr && MapEditor::get()->isActive()) {
return MapEditor::get()->getSetCompletions();
}
return {};
};
// SET COLOR/BGCOLOR/etc. ya tienen sus providers arriba
// HELP: lista de comandos visibles en el scope activo
dynamic_providers_["HELP"] = [this]() -> std::vector<std::string> {
return getVisibleKeywords();
@@ -1261,56 +1271,48 @@ auto CommandRegistry::generateTerminalHelp() const -> std::string {
}
auto CommandRegistry::generateConsoleHelp() const -> std::string {
if (!active_scope_.empty()) {
// Con scope activo: listar solo los comandos de ese scope + global
std::string cmds;
std::string shortcuts;
for (const auto& cmd : commands_) {
if (cmd.help_hidden) { continue; }
if (!isCommandVisible(cmd)) { continue; }
std::string kw_lower = cmd.keyword;
std::ranges::transform(kw_lower, kw_lower.begin(), ::tolower);
if (!cmds.empty()) { cmds += ", "; }
cmds += kw_lower;
}
std::string result = active_scope_ + " commands:\n" + cmds + "\n";
// Atajos de teclado del editor
if (active_scope_ == "editor") {
result += "\nkeys: 9=editor 8=grid e=eraser m=map";
}
result += "\n-- more info on the terminal";
return result;
}
// Sin scope: formato original (release + debug)
std::string release_cmds;
// Agrupar comandos visibles por scope
std::string global_cmds;
std::string debug_cmds;
std::string editor_cmds;
for (const auto& cmd : commands_) {
if (cmd.help_hidden) { continue; }
if (!isCommandVisible(cmd)) { continue; }
std::string kw_lower = cmd.keyword;
std::ranges::transform(kw_lower, kw_lower.begin(), ::tolower);
if (cmd.debug_only) {
// Clasificar por el PRIMER scope del comando
const std::string& primary = cmd.scopes.empty() ? "global" : cmd.scopes[0];
if (primary == "editor") {
if (!editor_cmds.empty()) { editor_cmds += ", "; }
editor_cmds += kw_lower;
} else if (primary == "debug") {
if (!debug_cmds.empty()) { debug_cmds += ", "; }
debug_cmds += kw_lower;
} else {
if (!release_cmds.empty()) { release_cmds += ", "; }
release_cmds += kw_lower;
if (!global_cmds.empty()) { global_cmds += ", "; }
global_cmds += kw_lower;
}
}
std::string result = "Commands:\n" + release_cmds + "\n";
if (!debug_cmds.empty()) {
result += "\nDebug commands:\n" + debug_cmds + "\n";
// Construir resultado
std::string result;
if (active_scope_ == "editor" && !editor_cmds.empty()) {
result += "Editor:\n" + editor_cmds + "\n";
result += "keys: 9=editor 8=grid e=eraser m=map\n";
}
if (!debug_cmds.empty()) {
if (!result.empty()) { result += "\n"; }
result += "Debug:\n" + debug_cmds + "\n";
}
if (!result.empty()) { result += "\n"; }
result += "Commands:\n" + global_cmds + "\n";
result += "-- more info on the terminal";
return result;
}
@@ -1336,14 +1338,17 @@ auto CommandRegistry::getCompletions(const std::string& path) const -> std::vect
return {};
}
// Comprueba si un comando es visible en el scope activo
// Comprueba si un comando es utilizable en el scope activo (acumulativo)
// Release: global + game
// Debug: global + game + debug
// Editor: global + game + debug + editor
auto CommandRegistry::isCommandVisible(const CommandDef& cmd) const -> bool {
if (cmd.hidden) { return false; }
if (active_scope_.empty()) { return true; } // Sin filtro, todo visible
// Un comando es visible si pertenece al scope activo o al scope "global"
for (const auto& s : cmd.scopes) {
if (s == active_scope_ || s == "global") { return true; }
if (s == "global" || s == "game") { return true; }
if (s == "debug" && (active_scope_ == "debug" || active_scope_ == "editor")) { return true; }
if (s == "editor" && active_scope_ == "editor") { return true; }
}
return false;
}