clang-tidy
This commit is contained in:
@@ -55,7 +55,7 @@ static auto boolToggle(
|
||||
// ── Command handlers ─────────────────────────────────────────────────────────
|
||||
|
||||
// SS [ON|OFF|SIZE|UPSCALE [NEAREST|LINEAR]|DOWNSCALE [BILINEAR|LANCZOS2|LANCZOS3]]
|
||||
static auto cmd_ss(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdSs(const std::vector<std::string>& args) -> std::string { // NOLINT(readability-function-cognitive-complexity)
|
||||
if (!Screen::get()->isHardwareAccelerated()) { return "No GPU acceleration"; }
|
||||
static const std::array<std::string_view, 3> DOWNSCALE_NAMES = {"Bilinear", "Lanczos2", "Lanczos3"};
|
||||
if (!args.empty() && args[0] == "SIZE") {
|
||||
@@ -118,34 +118,34 @@ static auto applyPreset(const std::vector<std::string>& args) -> std::string {
|
||||
const bool IS_CRTPI = Options::video.shader.current_shader == Rendering::ShaderType::CRTPI;
|
||||
const auto& presets_postfx = Options::postfx_presets;
|
||||
const auto& presets_crtpi = Options::crtpi_presets;
|
||||
const std::string shader_label = IS_CRTPI ? "CrtPi" : "PostFX";
|
||||
const std::string SHADER_LABEL = IS_CRTPI ? "CrtPi" : "PostFX";
|
||||
|
||||
auto& current_idx = IS_CRTPI ? Options::video.shader.current_crtpi_preset
|
||||
: Options::video.shader.current_postfx_preset;
|
||||
const int count = static_cast<int>(IS_CRTPI ? presets_crtpi.size() : presets_postfx.size());
|
||||
const int COUNT = static_cast<int>(IS_CRTPI ? presets_crtpi.size() : presets_postfx.size());
|
||||
|
||||
if (count == 0) { return "No " + shader_label + " presets available"; }
|
||||
if (COUNT == 0) { return "No " + SHADER_LABEL + " presets available"; }
|
||||
|
||||
const auto presetName = [&]() -> std::string {
|
||||
const auto& name = IS_CRTPI ? presets_crtpi[static_cast<size_t>(current_idx)].name
|
||||
: presets_postfx[static_cast<size_t>(current_idx)].name;
|
||||
const auto PRESET_NAME = [&]() -> std::string {
|
||||
const auto& name = IS_CRTPI ? presets_crtpi[static_cast<size_t>(current_idx)].name // NOLINT(clang-analyzer-core.CallAndMessage)
|
||||
: presets_postfx[static_cast<size_t>(current_idx)].name; // NOLINT(clang-analyzer-core.CallAndMessage)
|
||||
return prettyName(name);
|
||||
};
|
||||
|
||||
if (args.empty()) {
|
||||
return shader_label + " preset: " + presetName();
|
||||
return SHADER_LABEL + " preset: " + PRESET_NAME();
|
||||
}
|
||||
|
||||
if (args[0] == "NEXT") {
|
||||
current_idx = (current_idx + 1) % count;
|
||||
current_idx = (current_idx + 1) % COUNT;
|
||||
} else if (args[0] == "PREV") {
|
||||
current_idx = (current_idx - 1 + count) % count;
|
||||
current_idx = (current_idx - 1 + COUNT) % COUNT;
|
||||
} else {
|
||||
// Buscar por nombre (case-insensitive, con guiones)
|
||||
std::string search = args[0];
|
||||
std::ranges::transform(search, search.begin(), ::toupper);
|
||||
bool found = false;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
const auto& name = IS_CRTPI ? presets_crtpi[static_cast<size_t>(i)].name
|
||||
: presets_postfx[static_cast<size_t>(i)].name;
|
||||
if (toUpper(name) == search) {
|
||||
@@ -166,11 +166,11 @@ static auto applyPreset(const std::vector<std::string>& args) -> std::string {
|
||||
} else {
|
||||
Screen::get()->reloadPostFX();
|
||||
}
|
||||
return shader_label + " preset: " + presetName();
|
||||
return SHADER_LABEL + " preset: " + PRESET_NAME();
|
||||
}
|
||||
|
||||
// SHADER [ON|OFF|NEXT|POSTFX|CRTPI|PRESET [NEXT|PREV|<name>]]
|
||||
static auto cmd_shader(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdShader(const std::vector<std::string>& args) -> std::string {
|
||||
if (!Screen::get()->isHardwareAccelerated()) { return "No GPU acceleration"; }
|
||||
if (args.empty()) {
|
||||
Screen::get()->toggleShaders();
|
||||
@@ -200,19 +200,19 @@ static auto cmd_shader(const std::vector<std::string>& args) -> std::string {
|
||||
(Options::video.shader.current_shader == Rendering::ShaderType::CRTPI ? "CrtPi" : "PostFX");
|
||||
}
|
||||
if (args[0] == "PRESET") {
|
||||
const std::vector<std::string> rest(args.begin() + 1, args.end());
|
||||
return applyPreset(rest);
|
||||
const std::vector<std::string> REST(args.begin() + 1, args.end());
|
||||
return applyPreset(REST);
|
||||
}
|
||||
return "usage: shader [on|off|next|postfx|crtpi|preset [next|prev|<name>]]";
|
||||
}
|
||||
|
||||
// BORDER [ON|OFF]
|
||||
static auto cmd_border(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdBorder(const std::vector<std::string>& args) -> std::string {
|
||||
return boolToggle("Border", Options::video.border.enabled, [] { Screen::get()->toggleBorder(); }, args);
|
||||
}
|
||||
|
||||
// FULLSCREEN [ON|OFF [PLEASE]]
|
||||
static auto cmd_fullscreen(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdFullscreen(const std::vector<std::string>& args) -> std::string {
|
||||
const bool EXPLICIT_ON = !args.empty() && args[0] == "ON";
|
||||
const bool EXPLICIT_OFF = !args.empty() && args[0] == "OFF";
|
||||
const bool WITH_PLEASE = !args.empty() && args.back() == "PLEASE";
|
||||
@@ -240,8 +240,8 @@ static auto cmd_fullscreen(const std::vector<std::string>& args) -> std::string
|
||||
}
|
||||
|
||||
// ZOOM UP/DOWN/<num>
|
||||
static auto cmd_zoom(const std::vector<std::string>& args) -> std::string {
|
||||
if (args.empty()) { return "usage: zoom [up|down|<1-" + std::to_string(Screen::get()->getMaxZoom()) + ">]"; }
|
||||
static auto cmdZoom(const std::vector<std::string>& args) -> std::string {
|
||||
if (args.empty()) { return "usage: zoom [up|down|<1-" + std::to_string(Screen::getMaxZoom()) + ">]"; }
|
||||
if (args[0] == "UP") {
|
||||
if (!Screen::get()->incWindowZoom()) { return "Max zoom reached"; }
|
||||
return "Zoom " + std::to_string(Options::window.zoom);
|
||||
@@ -252,7 +252,7 @@ static auto cmd_zoom(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
try {
|
||||
const int N = std::stoi(args[0]);
|
||||
const int MAX = Screen::get()->getMaxZoom();
|
||||
const int MAX = Screen::getMaxZoom();
|
||||
if (N < 1 || N > MAX) {
|
||||
return "Zoom must be between 1 and " + std::to_string(MAX);
|
||||
}
|
||||
@@ -260,11 +260,11 @@ static auto cmd_zoom(const std::vector<std::string>& args) -> std::string {
|
||||
Screen::get()->setWindowZoom(N);
|
||||
return "Zoom " + std::to_string(Options::window.zoom);
|
||||
} catch (...) {}
|
||||
return "usage: zoom [up|down|<1-" + std::to_string(Screen::get()->getMaxZoom()) + ">]";
|
||||
return "usage: zoom [up|down|<1-" + std::to_string(Screen::getMaxZoom()) + ">]";
|
||||
}
|
||||
|
||||
// INTSCALE [ON|OFF]
|
||||
static auto cmd_intscale(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdIntscale(const std::vector<std::string>& args) -> std::string {
|
||||
const bool ON = args.empty() ? !Options::video.integer_scale
|
||||
: (args[0] == "ON");
|
||||
if (!args.empty() && args[0] != "ON" && args[0] != "OFF") {
|
||||
@@ -279,12 +279,12 @@ static auto cmd_intscale(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// VSYNC [ON|OFF]
|
||||
static auto cmd_vsync(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdVsync(const std::vector<std::string>& args) -> std::string {
|
||||
return boolToggle("VSync", Options::video.vertical_sync, [] { Screen::get()->toggleVSync(); }, args);
|
||||
}
|
||||
|
||||
// DRIVER [LIST|AUTO|NONE|<name>]
|
||||
static auto cmd_driver(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdDriver(const std::vector<std::string>& args) -> std::string {
|
||||
if (args.empty()) {
|
||||
const auto& driver = Screen::get()->getGPUDriver();
|
||||
return "GPU: " + (driver.empty() ? std::string("sdl") : driver);
|
||||
@@ -336,22 +336,22 @@ static auto cmd_driver(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// PALETTE NEXT/PREV/SORT/DEFAULT/<name>
|
||||
static auto cmd_palette(const std::vector<std::string>& args) -> std::string {
|
||||
const auto palName = []() -> std::string {
|
||||
static auto cmdPalette(const std::vector<std::string>& args) -> std::string {
|
||||
const auto PAL_NAME = []() -> std::string {
|
||||
return Screen::get()->getPalettePrettyName();
|
||||
};
|
||||
if (args.empty()) { return "usage: palette [next|prev|sort [original|luminance|spectrum]|default|<name>]"; }
|
||||
if (args[0] == "NEXT") {
|
||||
Screen::get()->nextPalette();
|
||||
return "Palette: " + palName();
|
||||
return "Palette: " + PAL_NAME();
|
||||
}
|
||||
if (args[0] == "PREV") {
|
||||
Screen::get()->previousPalette();
|
||||
return "Palette: " + palName();
|
||||
return "Palette: " + PAL_NAME();
|
||||
}
|
||||
if (args[0] == "DEFAULT") {
|
||||
Screen::get()->setPaletteByName(Defaults::Video::PALETTE_NAME);
|
||||
return "Palette: " + palName();
|
||||
return "Palette: " + PAL_NAME();
|
||||
}
|
||||
if (args[0] == "SORT") {
|
||||
if (args.size() == 1) {
|
||||
@@ -374,11 +374,11 @@ static auto cmd_palette(const std::vector<std::string>& args) -> std::string {
|
||||
std::ranges::transform(arg_lower, arg_lower.begin(), ::tolower);
|
||||
return "Unknown palette: " + arg_lower;
|
||||
}
|
||||
return "Palette: " + palName();
|
||||
return "Palette: " + PAL_NAME();
|
||||
}
|
||||
|
||||
// AUDIO [ON|OFF|VOL <0-100>]
|
||||
static auto cmd_audio(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdAudio(const std::vector<std::string>& args) -> std::string {
|
||||
if (args.empty()) {
|
||||
const int VOL = static_cast<int>(Options::audio.volume * 100.0F);
|
||||
return std::string("Audio ") + (Options::audio.enabled ? "ON" : "OFF") +
|
||||
@@ -409,7 +409,7 @@ static auto cmd_audio(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// MUSIC [ON|OFF|VOL <0-100>]
|
||||
static auto cmd_music(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdMusic(const std::vector<std::string>& args) -> std::string {
|
||||
if (args.empty()) {
|
||||
const int VOL = static_cast<int>(Options::audio.music.volume * 100.0F);
|
||||
return std::string("Music ") + (Options::audio.music.enabled ? "ON" : "OFF") +
|
||||
@@ -444,7 +444,7 @@ static auto cmd_music(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// SOUND [ON|OFF|VOL <0-100>]
|
||||
static auto cmd_sound(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdSound(const std::vector<std::string>& args) -> std::string {
|
||||
if (args.empty()) {
|
||||
const int VOL = static_cast<int>(Options::audio.sound.volume * 100.0F);
|
||||
return std::string("Sound ") + (Options::audio.sound.enabled ? "ON" : "OFF") +
|
||||
@@ -480,7 +480,7 @@ static auto cmd_sound(const std::vector<std::string>& args) -> std::string {
|
||||
|
||||
#ifdef _DEBUG
|
||||
// DEBUG [MODE [ON|OFF]|START [HERE|ROOM|POS|SCENE <name>]]
|
||||
static auto cmd_debug(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdDebug(const std::vector<std::string>& args) -> std::string { // NOLINT(readability-function-cognitive-complexity)
|
||||
// --- START subcommands (START SCENE works from any scene) ---
|
||||
if (!args.empty() && args[0] == "START") {
|
||||
// START SCENE [<name>] — works from any scene
|
||||
@@ -566,7 +566,7 @@ static auto cmd_debug(const std::vector<std::string>& args) -> std::string {
|
||||
static auto changeRoomWithEditor(const std::string& room_file) -> std::string {
|
||||
if (!GameControl::change_room) { return "Game not initialized"; }
|
||||
|
||||
const bool EDITOR_WAS_ACTIVE = MapEditor::get() && MapEditor::get()->isActive();
|
||||
const bool EDITOR_WAS_ACTIVE = (MapEditor::get() != nullptr) && MapEditor::get()->isActive();
|
||||
|
||||
// Si el editor está activo, salir primero (guarda y recarga la room actual)
|
||||
if (EDITOR_WAS_ACTIVE && GameControl::exit_editor) {
|
||||
@@ -591,19 +591,19 @@ static auto changeRoomWithEditor(const std::string& room_file) -> std::string {
|
||||
return std::string("Room: ") + room_file;
|
||||
}
|
||||
|
||||
static auto cmd_room(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdRoom(const std::vector<std::string>& args) -> std::string { // NOLINT(readability-function-cognitive-complexity)
|
||||
if (SceneManager::current != SceneManager::Scene::GAME) { return "Only available in GAME scene"; }
|
||||
if (args.empty()) { return "usage: room <1-60>|next|prev|left|right|up|down"; }
|
||||
|
||||
// DELETE: borrar la habitación actual
|
||||
if (args[0] == "DELETE") {
|
||||
if (!MapEditor::get() || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
if ((MapEditor::get() == nullptr) || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
return MapEditor::get()->deleteRoom();
|
||||
}
|
||||
|
||||
// NEW [LEFT|RIGHT|UP|DOWN]: crear habitación nueva (opcionalmente conectada)
|
||||
if (args[0] == "NEW") {
|
||||
if (!MapEditor::get() || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
if ((MapEditor::get() == nullptr) || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
std::string direction = (args.size() >= 2) ? args[1] : "";
|
||||
return MapEditor::get()->createNewRoom(direction);
|
||||
}
|
||||
@@ -621,9 +621,9 @@ static auto cmd_room(const std::vector<std::string>& args) -> std::string {
|
||||
int num = 0;
|
||||
if (args[0] == "NEXT" || args[0] == "PREV") {
|
||||
if (!GameControl::get_current_room) { return "Game not initialized"; }
|
||||
const std::string current = GameControl::get_current_room();
|
||||
const std::string CURRENT = GameControl::get_current_room();
|
||||
try {
|
||||
num = std::stoi(current.substr(0, current.find('.')));
|
||||
num = std::stoi(CURRENT.substr(0, CURRENT.find('.')));
|
||||
} catch (...) { return "Cannot determine current room"; }
|
||||
num += (args[0] == "NEXT") ? 1 : -1;
|
||||
} else {
|
||||
@@ -638,7 +638,7 @@ static auto cmd_room(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// ITEMS <0-200>
|
||||
static auto cmd_items(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdItems(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;
|
||||
@@ -652,7 +652,7 @@ static auto cmd_items(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// SCENE [LOGO|LOADING|TITLE|CREDITS|GAME|ENDING|ENDING2|RESTART]
|
||||
static auto cmd_scene(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdScene(const std::vector<std::string>& args) -> std::string {
|
||||
if (Options::kiosk.enabled) { return "Not allowed in kiosk mode"; }
|
||||
if (args.empty()) { return "usage: scene [logo|loading|title|credits|game|ending|ending2|restart]"; }
|
||||
|
||||
@@ -683,10 +683,10 @@ static auto cmd_scene(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// EDIT [ON|OFF|REVERT]
|
||||
static auto cmd_edit(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdEdit(const std::vector<std::string>& args) -> std::string { // NOLINT(readability-function-cognitive-complexity)
|
||||
if (args.empty()) {
|
||||
// Toggle: si está activo → off, si no → on
|
||||
if (MapEditor::get() && MapEditor::get()->isActive()) {
|
||||
if ((MapEditor::get() != nullptr) && MapEditor::get()->isActive()) {
|
||||
if (GameControl::exit_editor) { GameControl::exit_editor(); }
|
||||
return "Editor OFF";
|
||||
}
|
||||
@@ -718,26 +718,26 @@ static auto cmd_edit(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
// EDIT SHOW/HIDE INFO/GRID
|
||||
if ((args[0] == "SHOW" || args[0] == "HIDE") && args.size() >= 2) {
|
||||
if (!MapEditor::get() || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
if ((MapEditor::get() == nullptr) || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
bool show = (args[0] == "SHOW");
|
||||
if (args[1] == "INFO") { return MapEditor::get()->showInfo(show); }
|
||||
if (args[1] == "GRID") { return MapEditor::get()->showGrid(show); }
|
||||
}
|
||||
// EDIT MAPBG/MAPCONN <color>
|
||||
if (args[0] == "MAPBG" && args.size() >= 2) {
|
||||
if (!MapEditor::get() || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
if ((MapEditor::get() == nullptr) || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
return MapEditor::get()->setMiniMapBg(args[1]);
|
||||
}
|
||||
if (args[0] == "MAPCONN" && args.size() >= 2) {
|
||||
if (!MapEditor::get() || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
if ((MapEditor::get() == nullptr) || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
return MapEditor::get()->setMiniMapConn(args[1]);
|
||||
}
|
||||
return "usage: edit [on|off|revert|show|hide|mapbg|mapconn] [...]";
|
||||
}
|
||||
|
||||
// SET <property> <value> — modifica propiedad del enemigo seleccionado o de la habitación
|
||||
static auto cmd_set(const std::vector<std::string>& args) -> std::string {
|
||||
if (!MapEditor::get() || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
static auto cmdSet(const std::vector<std::string>& args) -> std::string {
|
||||
if ((MapEditor::get() == nullptr) || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
if (args.empty()) { return "usage: set <property> <value>"; }
|
||||
|
||||
// SET TILE no necesita argumento (abre el tile picker visual)
|
||||
@@ -762,8 +762,8 @@ static auto cmd_set(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// ENEMY [ADD|DELETE|DUPLICATE]
|
||||
static auto cmd_enemy(const std::vector<std::string>& args) -> std::string {
|
||||
if (!MapEditor::get() || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
static auto cmdEnemy(const std::vector<std::string>& args) -> std::string {
|
||||
if ((MapEditor::get() == nullptr) || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
if (args.empty()) { return "usage: enemy <add|delete|duplicate>"; }
|
||||
if (args[0] == "ADD") { return MapEditor::get()->addEnemy(); }
|
||||
if (args[0] == "DELETE") {
|
||||
@@ -778,8 +778,8 @@ static auto cmd_enemy(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// ITEM [ADD|DELETE|DUPLICATE]
|
||||
static auto cmd_item(const std::vector<std::string>& args) -> std::string {
|
||||
if (!MapEditor::get() || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
static auto cmdItem(const std::vector<std::string>& args) -> std::string {
|
||||
if ((MapEditor::get() == nullptr) || !MapEditor::get()->isActive()) { return "Editor not active"; }
|
||||
if (args.empty()) { return "usage: item <add|delete|duplicate>"; }
|
||||
if (args[0] == "ADD") { return MapEditor::get()->addItem(); }
|
||||
if (args[0] == "DELETE") {
|
||||
@@ -795,7 +795,7 @@ static auto cmd_item(const std::vector<std::string>& args) -> std::string {
|
||||
#endif
|
||||
|
||||
// SHOW [INFO|NOTIFICATION|CHEEVO]
|
||||
static auto cmd_show(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdShow(const std::vector<std::string>& args) -> std::string {
|
||||
#ifdef _DEBUG
|
||||
if (!args.empty() && args[0] == "NOTIFICATION") {
|
||||
Notifier::get()->show({"NOTIFICATION"});
|
||||
@@ -815,7 +815,7 @@ static auto cmd_show(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// HIDE [INFO]
|
||||
static auto cmd_hide(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdHide(const std::vector<std::string>& args) -> std::string {
|
||||
if (args.empty() || args[0] != "INFO") { return "usage: hide [info]"; }
|
||||
if (!RenderInfo::get()->isActive()) { return "Info overlay already OFF"; }
|
||||
RenderInfo::get()->toggle();
|
||||
@@ -823,7 +823,7 @@ static auto cmd_hide(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// CHEAT [subcomando]
|
||||
static auto cmd_cheat(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdCheat(const std::vector<std::string>& args) -> std::string { // NOLINT(readability-function-cognitive-complexity)
|
||||
if (SceneManager::current != SceneManager::Scene::GAME) { return "Only available in GAME scene"; }
|
||||
if (args.empty()) { return "usage: cheat [infinite lives|invincibility|open the jail|close the jail]"; }
|
||||
|
||||
@@ -885,7 +885,7 @@ static auto cmd_cheat(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// PLAYER SKIN / PLAYER COLOR
|
||||
static auto cmd_player(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdPlayer(const std::vector<std::string>& args) -> std::string {
|
||||
if (SceneManager::current != SceneManager::Scene::GAME) { return "Only available in GAME scene"; }
|
||||
|
||||
// PLAYER SKIN <name>
|
||||
@@ -920,14 +920,14 @@ static auto cmd_player(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// RESTART
|
||||
static auto cmd_restart(const std::vector<std::string>&) -> std::string {
|
||||
static auto cmdRestart(const std::vector<std::string>& /*unused*/) -> std::string {
|
||||
SceneManager::current = SceneManager::Scene::LOGO;
|
||||
Audio::get()->stopMusic();
|
||||
return "Restarting...";
|
||||
}
|
||||
|
||||
// KIOSK [ON|OFF PLEASE|PLEASE]
|
||||
static auto cmd_kiosk(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdKiosk(const std::vector<std::string>& args) -> std::string {
|
||||
const bool DISABLE = (!args.empty() && args[0] == "PLEASE") ||
|
||||
(args.size() >= 2 && args[0] == "OFF" && args[1] == "PLEASE");
|
||||
if (DISABLE) {
|
||||
@@ -947,7 +947,7 @@ static auto cmd_kiosk(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// EXIT / QUIT
|
||||
static auto cmd_exit(const std::vector<std::string>& args) -> std::string {
|
||||
static auto cmdExit(const std::vector<std::string>& args) -> std::string {
|
||||
if (Options::kiosk.enabled && (args.empty() || args[0] != "PLEASE")) {
|
||||
return "Not allowed in kiosk mode";
|
||||
}
|
||||
@@ -956,7 +956,7 @@ static auto cmd_exit(const std::vector<std::string>& args) -> std::string {
|
||||
}
|
||||
|
||||
// SIZE
|
||||
static auto cmd_size(const std::vector<std::string>&) -> std::string {
|
||||
static auto cmdSize(const std::vector<std::string>& /*unused*/) -> std::string {
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
SDL_GetWindowSize(SDL_GetRenderWindow(Screen::get()->getRenderer()), &w, &h);
|
||||
@@ -965,37 +965,37 @@ static auto cmd_size(const std::vector<std::string>&) -> std::string {
|
||||
|
||||
// ── CommandRegistry ──────────────────────────────────────────────────────────
|
||||
|
||||
void CommandRegistry::registerHandlers() {
|
||||
handlers_["cmd_ss"] = cmd_ss;
|
||||
handlers_["cmd_shader"] = cmd_shader;
|
||||
handlers_["cmd_border"] = cmd_border;
|
||||
handlers_["cmd_fullscreen"] = cmd_fullscreen;
|
||||
handlers_["cmd_zoom"] = cmd_zoom;
|
||||
handlers_["cmd_intscale"] = cmd_intscale;
|
||||
handlers_["cmd_vsync"] = cmd_vsync;
|
||||
handlers_["cmd_driver"] = cmd_driver;
|
||||
handlers_["cmd_palette"] = cmd_palette;
|
||||
handlers_["cmd_audio"] = cmd_audio;
|
||||
handlers_["cmd_music"] = cmd_music;
|
||||
handlers_["cmd_sound"] = cmd_sound;
|
||||
handlers_["cmd_show"] = cmd_show;
|
||||
handlers_["cmd_hide"] = cmd_hide;
|
||||
handlers_["cmd_cheat"] = cmd_cheat;
|
||||
handlers_["cmd_player"] = cmd_player;
|
||||
handlers_["cmd_restart"] = cmd_restart;
|
||||
handlers_["cmd_kiosk"] = cmd_kiosk;
|
||||
handlers_["cmd_exit"] = cmd_exit;
|
||||
handlers_["cmd_quit"] = cmd_exit; // QUIT usa el mismo handler que EXIT
|
||||
handlers_["cmd_size"] = cmd_size;
|
||||
void CommandRegistry::registerHandlers() { // NOLINT(readability-function-cognitive-complexity)
|
||||
handlers_["cmd_ss"] = cmdSs;
|
||||
handlers_["cmd_shader"] = cmdShader;
|
||||
handlers_["cmd_border"] = cmdBorder;
|
||||
handlers_["cmd_fullscreen"] = cmdFullscreen;
|
||||
handlers_["cmd_zoom"] = cmdZoom;
|
||||
handlers_["cmd_intscale"] = cmdIntscale;
|
||||
handlers_["cmd_vsync"] = cmdVsync;
|
||||
handlers_["cmd_driver"] = cmdDriver;
|
||||
handlers_["cmd_palette"] = cmdPalette;
|
||||
handlers_["cmd_audio"] = cmdAudio;
|
||||
handlers_["cmd_music"] = cmdMusic;
|
||||
handlers_["cmd_sound"] = cmdSound;
|
||||
handlers_["cmd_show"] = cmdShow;
|
||||
handlers_["cmd_hide"] = cmdHide;
|
||||
handlers_["cmd_cheat"] = cmdCheat;
|
||||
handlers_["cmd_player"] = cmdPlayer;
|
||||
handlers_["cmd_restart"] = cmdRestart;
|
||||
handlers_["cmd_kiosk"] = cmdKiosk;
|
||||
handlers_["cmd_exit"] = cmdExit;
|
||||
handlers_["cmd_quit"] = cmdExit; // QUIT usa el mismo handler que EXIT
|
||||
handlers_["cmd_size"] = cmdSize;
|
||||
#ifdef _DEBUG
|
||||
handlers_["cmd_debug"] = cmd_debug;
|
||||
handlers_["cmd_items"] = cmd_items;
|
||||
handlers_["cmd_room"] = cmd_room;
|
||||
handlers_["cmd_scene"] = cmd_scene;
|
||||
handlers_["cmd_edit"] = cmd_edit;
|
||||
handlers_["cmd_set"] = cmd_set;
|
||||
handlers_["cmd_enemy"] = cmd_enemy;
|
||||
handlers_["cmd_item"] = cmd_item;
|
||||
handlers_["cmd_debug"] = cmdDebug;
|
||||
handlers_["cmd_items"] = cmdItems;
|
||||
handlers_["cmd_room"] = cmdRoom;
|
||||
handlers_["cmd_scene"] = cmdScene;
|
||||
handlers_["cmd_edit"] = cmdEdit;
|
||||
handlers_["cmd_set"] = cmdSet;
|
||||
handlers_["cmd_enemy"] = cmdEnemy;
|
||||
handlers_["cmd_item"] = cmdItem;
|
||||
#endif
|
||||
// HELP se registra en load() como lambda que captura this
|
||||
|
||||
@@ -1081,7 +1081,7 @@ void CommandRegistry::registerHandlers() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void CommandRegistry::load(const std::string& yaml_path) {
|
||||
void CommandRegistry::load(const std::string& yaml_path) { // NOLINT(readability-function-cognitive-complexity)
|
||||
registerHandlers();
|
||||
|
||||
// Cargar y parsear el YAML
|
||||
@@ -1103,8 +1103,8 @@ void CommandRegistry::load(const std::string& yaml_path) {
|
||||
if (!yaml.contains("categories")) { return; }
|
||||
|
||||
for (const auto& cat_node : yaml["categories"]) {
|
||||
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>();
|
||||
const auto 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;
|
||||
@@ -1123,12 +1123,12 @@ void CommandRegistry::load(const std::string& yaml_path) {
|
||||
CommandDef def;
|
||||
def.keyword = cmd_node["keyword"].get_value<std::string>();
|
||||
def.handler_id = cmd_node["handler"].get_value<std::string>();
|
||||
def.category = category;
|
||||
def.category = CATEGORY;
|
||||
def.description = cmd_node.contains("description") ? cmd_node["description"].get_value<std::string>() : "";
|
||||
def.usage = cmd_node.contains("usage") ? cmd_node["usage"].get_value<std::string>() : def.keyword;
|
||||
def.instant = cmd_node.contains("instant") && cmd_node["instant"].get_value<bool>();
|
||||
def.hidden = cmd_node.contains("hidden") && cmd_node["hidden"].get_value<bool>();
|
||||
def.debug_only = cat_debug_only || (cmd_node.contains("debug_only") && cmd_node["debug_only"].get_value<bool>());
|
||||
def.debug_only = CAT_DEBUG_ONLY || (cmd_node.contains("debug_only") && cmd_node["debug_only"].get_value<bool>());
|
||||
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>();
|
||||
|
||||
@@ -1143,14 +1143,14 @@ void CommandRegistry::load(const std::string& yaml_path) {
|
||||
} else if (!cat_scopes.empty()) {
|
||||
def.scopes = cat_scopes;
|
||||
} else {
|
||||
def.scopes.push_back("global");
|
||||
def.scopes.emplace_back("global");
|
||||
}
|
||||
|
||||
// Completions estáticas
|
||||
if (cmd_node.contains("completions")) {
|
||||
auto completions_node = cmd_node["completions"];
|
||||
for (auto it = completions_node.begin(); it != completions_node.end(); ++it) {
|
||||
std::string path = it.key().get_value<std::string>();
|
||||
auto path = it.key().get_value<std::string>();
|
||||
std::vector<std::string> opts;
|
||||
for (const auto& opt : *it) {
|
||||
opts.push_back(opt.get_value<std::string>());
|
||||
@@ -1171,7 +1171,7 @@ void CommandRegistry::load(const std::string& yaml_path) {
|
||||
def.completions.clear();
|
||||
auto extras_completions = extras["completions"];
|
||||
for (auto it = extras_completions.begin(); it != extras_completions.end(); ++it) {
|
||||
std::string path = it.key().get_value<std::string>();
|
||||
auto path = it.key().get_value<std::string>();
|
||||
std::vector<std::string> opts;
|
||||
for (const auto& opt : *it) {
|
||||
opts.push_back(opt.get_value<std::string>());
|
||||
@@ -1237,9 +1237,9 @@ auto CommandRegistry::findCommand(const std::string& keyword) const -> const Com
|
||||
auto CommandRegistry::execute(const std::string& keyword, const std::vector<std::string>& args) const -> std::string {
|
||||
const auto* def = findCommand(keyword);
|
||||
if (def == nullptr) { return ""; }
|
||||
const auto it = handlers_.find(def->handler_id);
|
||||
if (it == handlers_.end()) { return "Handler not found: " + def->handler_id; }
|
||||
return it->second(args);
|
||||
const auto IT = handlers_.find(def->handler_id);
|
||||
if (IT == handlers_.end()) { return "Handler not found: " + def->handler_id; }
|
||||
return IT->second(args);
|
||||
}
|
||||
|
||||
auto CommandRegistry::generateTerminalHelp() const -> std::string {
|
||||
@@ -1270,7 +1270,7 @@ auto CommandRegistry::generateTerminalHelp() const -> std::string {
|
||||
return out.str();
|
||||
}
|
||||
|
||||
auto CommandRegistry::generateConsoleHelp() const -> std::string {
|
||||
auto CommandRegistry::generateConsoleHelp() const -> std::string { // NOLINT(readability-function-cognitive-complexity)
|
||||
// Agrupar comandos visibles por scope
|
||||
std::string global_cmds;
|
||||
std::string debug_cmds;
|
||||
@@ -1328,13 +1328,13 @@ auto CommandRegistry::getCompletions(const std::string& path) const -> std::vect
|
||||
}
|
||||
|
||||
// Primero: buscar proveedor dinámico (tiene prioridad si existe)
|
||||
const auto dyn_it = dynamic_providers_.find(path);
|
||||
if (dyn_it != dynamic_providers_.end()) {
|
||||
return dyn_it->second();
|
||||
const auto DYN_IT = dynamic_providers_.find(path);
|
||||
if (DYN_IT != dynamic_providers_.end()) {
|
||||
return DYN_IT->second();
|
||||
}
|
||||
// Fallback: completions estáticas del YAML
|
||||
const auto it = completions_map_.find(path);
|
||||
if (it != completions_map_.end()) { return it->second; }
|
||||
const auto IT = completions_map_.find(path);
|
||||
if (IT != completions_map_.end()) { return IT->second; }
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -1345,12 +1345,11 @@ auto CommandRegistry::getCompletions(const std::string& path) const -> std::vect
|
||||
auto CommandRegistry::isCommandVisible(const CommandDef& cmd) const -> bool {
|
||||
if (cmd.hidden) { return false; }
|
||||
|
||||
for (const auto& s : cmd.scopes) {
|
||||
return std::ranges::any_of(cmd.scopes, [this](const auto& s) {
|
||||
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;
|
||||
return s == "editor" && active_scope_ == "editor";
|
||||
});
|
||||
}
|
||||
|
||||
auto CommandRegistry::getVisibleKeywords() const -> std::vector<std::string> {
|
||||
|
||||
Reference in New Issue
Block a user