From 86a2c009e3bb623a13d72fa4680279ead5641d9e Mon Sep 17 00:00:00 2001 From: Vincenzo Date: Fri, 20 Dec 2024 23:24:19 +0500 Subject: [PATCH 1/2] added alias mapping, new alias command, modified triggerCommand to check alias map --- library/src/interactor_impl.cxx | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/library/src/interactor_impl.cxx b/library/src/interactor_impl.cxx index 036574f6d5..94abb5cfa4 100644 --- a/library/src/interactor_impl.cxx +++ b/library/src/interactor_impl.cxx @@ -43,6 +43,11 @@ using mod_t = interaction_bind_t::ModifierKeys; class interactor_impl::internals { + //------------------------------------------------------------------- +private: + // Map to store aliases + std::map aliasMap; + //------------------------------------------------------------------- public: struct BindingCommands { @@ -753,6 +758,18 @@ std::vector interactor_impl::getCommandActions() const return actions; } +//---------------------------------------------------------------------------- +void interactor_impl::alias(const std::string& action, const std::string& value) +{ + if (action.empty() || value.empty()) + { + F3DLog::Error(F3DLog::Severity::ERROR, "Alias action or value cannot be empty."); + return; + } + aliasMap[action] = value; + F3DLog::Info(F3DLog::Severity::DEBUG, "Alias added: " + action + " -> " + value); +} + //---------------------------------------------------------------------------- bool interactor_impl::triggerCommand(std::string_view command) { @@ -773,7 +790,16 @@ bool interactor_impl::triggerCommand(std::string_view command) return true; } - const std::string& action = tokens[0]; + std::string action = tokens[0]; + + // Check if action is an alias + auto aliasIt = aliasMap.find(action); + if (aliasIt != aliasMap.end()) + { + action = aliasIt->second; + F3DLog::Info(F3DLog::Severity::DEBUG, "Alias resolved: " + action); + } + try { // Find the right command to call From 0ba115ab686a7115308b9d577b79498091921207 Mon Sep 17 00:00:00 2001 From: Vincenzo Date: Sat, 21 Dec 2024 01:31:00 +0500 Subject: [PATCH 2/2] fixed declare error --- library/private/interactor_impl.h | 2 ++ library/src/interactor_impl.cxx | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/library/private/interactor_impl.h b/library/private/interactor_impl.h index ec901eba1b..304986e805 100644 --- a/library/private/interactor_impl.h +++ b/library/private/interactor_impl.h @@ -40,6 +40,8 @@ class interactor_impl : public interactor std::function&)> callback) override; interactor& removeCommand(const std::string& action) override; std::vector getCommandActions() const override; + std::unordered_map aliasMap; + void alias(const std::string& action, const std::string& value); bool triggerCommand(std::string_view command) override; interactor& initBindings() override; diff --git a/library/src/interactor_impl.cxx b/library/src/interactor_impl.cxx index 94abb5cfa4..6e112173f9 100644 --- a/library/src/interactor_impl.cxx +++ b/library/src/interactor_impl.cxx @@ -763,11 +763,11 @@ void interactor_impl::alias(const std::string& action, const std::string& value) { if (action.empty() || value.empty()) { - F3DLog::Error(F3DLog::Severity::ERROR, "Alias action or value cannot be empty."); + log::error("Alias action or value cannot be empty."); return; } aliasMap[action] = value; - F3DLog::Info(F3DLog::Severity::DEBUG, "Alias added: " + action + " -> " + value); + log::error("Alias added: " + action + " -> " + value); } //---------------------------------------------------------------------------- @@ -797,7 +797,7 @@ bool interactor_impl::triggerCommand(std::string_view command) if (aliasIt != aliasMap.end()) { action = aliasIt->second; - F3DLog::Info(F3DLog::Severity::DEBUG, "Alias resolved: " + action); + log::error("Alias resolved: " + action); } try