posat un poc d'ordre en els comandos de la consola
This commit is contained in:
@@ -259,7 +259,6 @@ categories:
|
||||
usage: "SET <property> <value>"
|
||||
dynamic_completions: true
|
||||
completions:
|
||||
SET: [ANIMATION, COLOR, VX, VY, FLIP, MIRROR, BGCOLOR, BORDER, ITEMCOLOR1, ITEMCOLOR2, CONVEYOR, TILESET, UP, DOWN, LEFT, RIGHT, TILE, COUNTER]
|
||||
SET FLIP: [ON, OFF]
|
||||
SET MIRROR: [ON, OFF]
|
||||
SET CONVEYOR: [LEFT, NONE, RIGHT]
|
||||
|
||||
@@ -931,6 +931,18 @@ auto MapEditor::hasSelectedEnemy() const -> bool {
|
||||
return selected_enemy_ >= 0 && selected_enemy_ < static_cast<int>(room_data_.enemies.size());
|
||||
}
|
||||
|
||||
// Devuelve las propiedades válidas de SET según la selección actual
|
||||
auto MapEditor::getSetCompletions() const -> std::vector<std::string> {
|
||||
if (hasSelectedEnemy()) {
|
||||
return {"ANIMATION", "COLOR", "VX", "VY", "FLIP", "MIRROR"};
|
||||
}
|
||||
if (hasSelectedItem()) {
|
||||
return {"TILE", "COUNTER"};
|
||||
}
|
||||
// Room
|
||||
return {"BGCOLOR", "BORDER", "ITEMCOLOR1", "ITEMCOLOR2", "CONVEYOR", "TILESET", "UP", "DOWN", "LEFT", "RIGHT"};
|
||||
}
|
||||
|
||||
// Modifica una propiedad del enemigo seleccionado
|
||||
auto MapEditor::setEnemyProperty(const std::string& property, const std::string& value) -> std::string {
|
||||
if (!active_) { return "Editor not active"; }
|
||||
|
||||
@@ -40,6 +40,7 @@ class MapEditor {
|
||||
auto deleteEnemy() -> std::string;
|
||||
auto duplicateEnemy() -> std::string;
|
||||
[[nodiscard]] auto hasSelectedEnemy() const -> bool;
|
||||
[[nodiscard]] auto getSetCompletions() const -> std::vector<std::string>;
|
||||
|
||||
// Comandos para propiedades de la habitación
|
||||
auto setRoomProperty(const std::string& property, const std::string& value) -> std::string;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user