diff --git a/include/InputSystemComponent.h b/include/InputSystemComponent.h index 9050f4e..f0be5d4 100644 --- a/include/InputSystemComponent.h +++ b/include/InputSystemComponent.h @@ -16,21 +16,22 @@ public: void init() override; void update() override; - // void bindAction(const std::string& actionName, Key key, std::function callback); + void bindAction(const std::string& actionName, Key key, std::function callback); + void bindAction(const std::string& actionName, std::vector keys, std::function callback); - template - void bindAction(const std::string& actionName, std::function callback, Keys... keys) - { - static_assert((std::is_same::value && ...), "A passed argument for 'Keys' is not of type 'Key'"); + // template + // void bindAction(const std::string& actionName, std::function callback, Keys... keys) + // { + // static_assert((std::is_same::value && ...), "A passed argument for 'Keys' is not of type 'Key'"); - if (m_actions.find(actionName) == m_actions.end()) - { - m_actions[actionName] = InputAction(actionName, callback); - } - - (m_actions[actionName].keys.push_back(keys), ...); - (m_keyToActionsMap[keys].push_back(m_actions[actionName]), ...); - } + // if (m_actions.find(actionName) == m_actions.end()) + // { + // m_actions[actionName] = InputAction(actionName, callback); + // } + + // (m_actions[actionName].keys.push_back(keys), ...); + // (m_keyToActionsMap[keys].push_back(m_actions[actionName]), ...); + // } void unbindAction(const std::string& actionName, Key key); diff --git a/src/InputSystemComponent.cpp b/src/InputSystemComponent.cpp index 9bd66af..0bab05f 100644 --- a/src/InputSystemComponent.cpp +++ b/src/InputSystemComponent.cpp @@ -11,17 +11,33 @@ void InputSystemComponent::update() handleActions(); } -// void InputSystemComponent::bindAction(const std::string& actionName, Key key, std::function callback) -// { -// if (m_actions.find(actionName) == m_actions.end()) -// { -// m_actions[actionName] = InputAction(actionName, callback); -// } +// alternative to template function +void InputSystemComponent::bindAction(const std::string& actionName, Key key, std::function callback) +{ + if (m_actions.find(actionName) == m_actions.end()) + { + m_actions[actionName] = InputAction(actionName, callback); + } -// m_actions[actionName].keys.push_back(key); -// m_keyToActionsMap[key].push_back(m_actions[actionName]); + m_actions[actionName].keys.push_back(key); + m_keyToActionsMap[key].push_back(m_actions[actionName]); -// } +} + +// alternative to template function +void InputSystemComponent::bindAction(const std::string& actionName, std::vector keys, std::function callback) +{ + if (m_actions.find(actionName) == m_actions.end()) + { + m_actions[actionName] = InputAction(actionName, callback); + } + + for (Key key : keys) + { + m_actions[actionName].keys.push_back(key); + m_keyToActionsMap[key].push_back(m_actions[actionName]); + } +} void InputSystemComponent::unbindAction(const std::string& actionName, Key key) {