From 694bc0a888fcb58fa0da5f003a924bfaed0d32f7 Mon Sep 17 00:00:00 2001 From: Phillip Stephens <antidote.crk@gmail.com> Date: Thu, 26 Apr 2018 14:10:32 -0700 Subject: [PATCH] Add ability to unregister command on the fly --- hecl/include/hecl/Console.hpp | 1 + hecl/lib/Console.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/hecl/include/hecl/Console.hpp b/hecl/include/hecl/Console.hpp index 6e6cd6f64..f863b12bd 100644 --- a/hecl/include/hecl/Console.hpp +++ b/hecl/include/hecl/Console.hpp @@ -80,6 +80,7 @@ private: public: Console(CVarManager*); void registerCommand(std::string_view name, std::string_view helpText, std::string_view usage, const std::function<void(Console*, const std::vector<std::string>&)>&& func); + void unregisterCommand(std::string_view name); void executeString(const std::string& strToExec); diff --git a/hecl/lib/Console.cpp b/hecl/lib/Console.cpp index a6d03c330..c7ef715c2 100644 --- a/hecl/lib/Console.cpp +++ b/hecl/lib/Console.cpp @@ -32,6 +32,14 @@ void Console::registerCommand(std::string_view name, std::string_view helpText, m_commands[lowName] = SConsoleCommand{name.data(), helpText.data(), usage.data(), std::move(func)}; } +void Console::unregisterCommand(std::string_view name) +{ + std::string lowName = name.data(); + athena::utility::tolower(lowName); + if (m_commands.find(lowName) != m_commands.end()) + m_commands.erase(m_commands.find(lowName)); +} + void Console::executeString(const std::string& str) { if (str.empty())