mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 15:53:42 +00:00
Implemented template function for binding actions
This commit is contained in:
parent
cefa1c2e29
commit
de74ca1307
@ -16,7 +16,22 @@ public:
|
|||||||
void init() override;
|
void init() override;
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
void bindAction(const std::string& actionName, Key key, std::function<void()> callback);
|
// void bindAction(const std::string& actionName, Key key, std::function<void()> callback);
|
||||||
|
|
||||||
|
template<typename... Keys>
|
||||||
|
void bindAction(const std::string& actionName, std::function<void()> callback, Keys... keys)
|
||||||
|
{
|
||||||
|
static_assert((std::is_same<Keys, Key>::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]), ...);
|
||||||
|
}
|
||||||
|
|
||||||
void unbindAction(const std::string& actionName, Key key);
|
void unbindAction(const std::string& actionName, Key key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -11,17 +11,17 @@ void InputSystemComponent::update()
|
|||||||
handleActions();
|
handleActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputSystemComponent::bindAction(const std::string& actionName, Key key, std::function<void()> callback)
|
// void InputSystemComponent::bindAction(const std::string& actionName, Key key, std::function<void()> callback)
|
||||||
{
|
// {
|
||||||
if (m_actions.find(actionName) == m_actions.end())
|
// if (m_actions.find(actionName) == m_actions.end())
|
||||||
{
|
// {
|
||||||
m_actions[actionName] = InputAction(actionName, callback);
|
// m_actions[actionName] = InputAction(actionName, callback);
|
||||||
}
|
// }
|
||||||
|
|
||||||
m_actions[actionName].keys.push_back(key);
|
// m_actions[actionName].keys.push_back(key);
|
||||||
m_keyToActionsMap[key].push_back(m_actions[actionName]);
|
// m_keyToActionsMap[key].push_back(m_actions[actionName]);
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
void InputSystemComponent::unbindAction(const std::string& actionName, Key key)
|
void InputSystemComponent::unbindAction(const std::string& actionName, Key key)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user