mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 21:23:41 +00:00
added alternative to bindAction template function
This commit is contained in:
parent
de74ca1307
commit
ef37e335d2
@ -16,21 +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);
|
||||||
|
void bindAction(const std::string& actionName, std::vector<Key> keys, std::function<void()> callback);
|
||||||
|
|
||||||
template<typename... Keys>
|
// template<typename... Keys>
|
||||||
void bindAction(const std::string& actionName, std::function<void()> callback, Keys... 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'");
|
// 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())
|
// 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(keys), ...);
|
// (m_actions[actionName].keys.push_back(keys), ...);
|
||||||
(m_keyToActionsMap[keys].push_back(m_actions[actionName]), ...);
|
// (m_keyToActionsMap[keys].push_back(m_actions[actionName]), ...);
|
||||||
}
|
// }
|
||||||
|
|
||||||
void unbindAction(const std::string& actionName, Key key);
|
void unbindAction(const std::string& actionName, Key key);
|
||||||
|
|
||||||
|
|||||||
@ -11,17 +11,33 @@ void InputSystemComponent::update()
|
|||||||
handleActions();
|
handleActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
// void InputSystemComponent::bindAction(const std::string& actionName, Key key, std::function<void()> callback)
|
// alternative to template function
|
||||||
// {
|
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]);
|
||||||
|
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
// alternative to template function
|
||||||
|
void InputSystemComponent::bindAction(const std::string& actionName, std::vector<Key> keys, std::function<void()> 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)
|
void InputSystemComponent::unbindAction(const std::string& actionName, Key key)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user