- ambits en la consola
- verifica que la habitacio de debug.yaml existisca
This commit is contained in:
@@ -444,3 +444,7 @@ auto Console::getVisibleHeight() -> int {
|
||||
if (status_ == Status::HIDDEN) { return 0; }
|
||||
return static_cast<int>(y_ + height_);
|
||||
}
|
||||
|
||||
// Scope de comandos
|
||||
void Console::setScope(const std::string& scope) { registry_.setScope(scope); }
|
||||
auto Console::getScope() const -> std::string { return registry_.getScope(); }
|
||||
|
||||
@@ -35,6 +35,10 @@ class Console {
|
||||
// Prompt configurable (por defecto "> ")
|
||||
void setPrompt(const std::string& prompt) { prompt_ = prompt; }
|
||||
|
||||
// Scope de comandos (filtra help y tab completion)
|
||||
void setScope(const std::string& scope);
|
||||
[[nodiscard]] auto getScope() const -> std::string;
|
||||
|
||||
// Callback llamado al abrir (true) o cerrar (false) la consola
|
||||
std::function<void(bool)> on_toggle;
|
||||
|
||||
|
||||
@@ -1091,6 +1091,17 @@ void CommandRegistry::load(const std::string& yaml_path) {
|
||||
const std::string category = cat_node["name"].get_value<std::string>();
|
||||
const bool cat_debug_only = cat_node.contains("debug_only") && cat_node["debug_only"].get_value<bool>();
|
||||
|
||||
// Scopes por defecto de la categoría
|
||||
std::vector<std::string> cat_scopes;
|
||||
if (cat_node.contains("scope")) {
|
||||
const auto& scope_node = cat_node["scope"];
|
||||
if (scope_node.is_sequence()) {
|
||||
for (const auto& s : scope_node) { cat_scopes.push_back(s.get_value<std::string>()); }
|
||||
} else {
|
||||
cat_scopes.push_back(scope_node.get_value<std::string>());
|
||||
}
|
||||
}
|
||||
|
||||
if (!cat_node.contains("commands")) { continue; }
|
||||
|
||||
for (const auto& cmd_node : cat_node["commands"]) {
|
||||
@@ -1106,6 +1117,20 @@ void CommandRegistry::load(const std::string& yaml_path) {
|
||||
def.help_hidden = cmd_node.contains("help_hidden") && cmd_node["help_hidden"].get_value<bool>();
|
||||
def.dynamic_completions = cmd_node.contains("dynamic_completions") && cmd_node["dynamic_completions"].get_value<bool>();
|
||||
|
||||
// Scopes: del comando, o hereda de la categoría, o "global" por defecto
|
||||
if (cmd_node.contains("scope")) {
|
||||
const auto& scope_node = cmd_node["scope"];
|
||||
if (scope_node.is_sequence()) {
|
||||
for (const auto& s : scope_node) { def.scopes.push_back(s.get_value<std::string>()); }
|
||||
} else {
|
||||
def.scopes.push_back(scope_node.get_value<std::string>());
|
||||
}
|
||||
} else if (!cat_scopes.empty()) {
|
||||
def.scopes = cat_scopes;
|
||||
} else {
|
||||
def.scopes.push_back("global");
|
||||
}
|
||||
|
||||
// Completions estáticas
|
||||
if (cmd_node.contains("completions")) {
|
||||
auto completions_node = cmd_node["completions"];
|
||||
@@ -1208,13 +1233,40 @@ 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;
|
||||
std::string debug_cmds;
|
||||
|
||||
for (const auto& cmd : commands_) {
|
||||
if (cmd.help_hidden) { continue; }
|
||||
|
||||
// Convertir keyword a minúsculas para la lista
|
||||
std::string kw_lower = cmd.keyword;
|
||||
std::ranges::transform(kw_lower, kw_lower.begin(), ::tolower);
|
||||
|
||||
@@ -1247,10 +1299,22 @@ auto CommandRegistry::getCompletions(const std::string& path) const -> std::vect
|
||||
return {};
|
||||
}
|
||||
|
||||
// Comprueba si un comando es visible en el scope activo
|
||||
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; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
auto CommandRegistry::getVisibleKeywords() const -> std::vector<std::string> {
|
||||
std::vector<std::string> result;
|
||||
for (const auto& cmd : commands_) {
|
||||
if (!cmd.hidden) {
|
||||
if (isCommandVisible(cmd)) {
|
||||
result.push_back(cmd.keyword);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ struct CommandDef {
|
||||
bool debug_only{false};
|
||||
bool help_hidden{false};
|
||||
bool dynamic_completions{false};
|
||||
std::vector<std::string> scopes; // Ámbitos: "global", "game", "editor", "debug"
|
||||
std::unordered_map<std::string, std::vector<std::string>> completions;
|
||||
};
|
||||
|
||||
@@ -40,9 +41,11 @@ class CommandRegistry {
|
||||
[[nodiscard]] auto generateTerminalHelp() const -> std::string;
|
||||
[[nodiscard]] auto generateConsoleHelp() const -> std::string;
|
||||
|
||||
// Scope activo (filtra comandos visibles en help y tab completion)
|
||||
void setScope(const std::string& scope) { active_scope_ = scope; }
|
||||
[[nodiscard]] auto getScope() const -> const std::string& { return active_scope_; }
|
||||
|
||||
// TAB completion
|
||||
// Devuelve las opciones de completado para un path dado (ej: "SHADER", "SHADER PRESET")
|
||||
// Combina completions estáticas del YAML con dinámicas registradas en C++
|
||||
[[nodiscard]] auto getCompletions(const std::string& path) const -> std::vector<std::string>;
|
||||
[[nodiscard]] auto getVisibleKeywords() const -> std::vector<std::string>;
|
||||
|
||||
@@ -51,6 +54,8 @@ class CommandRegistry {
|
||||
std::unordered_map<std::string, CommandHandler> handlers_;
|
||||
std::unordered_map<std::string, std::vector<std::string>> completions_map_;
|
||||
std::unordered_map<std::string, DynamicCompletionProvider> dynamic_providers_;
|
||||
std::string active_scope_; // Scope activo ("" = sin filtro, muestra todo)
|
||||
|
||||
void registerHandlers();
|
||||
[[nodiscard]] auto isCommandVisible(const CommandDef& cmd) const -> bool;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user