mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-13 01:33:43 +00:00
Compare commits
No commits in common. "18c722d07d5e5395b9f8ef02665e062c41c59b07" and "cefa1c2e2904c980816de59dad6bb4513f62c87c" have entirely different histories.
18c722d07d
...
cefa1c2e29
@ -8,8 +8,7 @@
|
|||||||
#include "InputComponent.h"
|
#include "InputComponent.h"
|
||||||
#include "InputAction.h"
|
#include "InputAction.h"
|
||||||
|
|
||||||
class InputSystemComponent : public InputComponent
|
class InputSystemComponent : public InputComponent {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
InputSystemComponent() = default;
|
InputSystemComponent() = default;
|
||||||
~InputSystemComponent() = default;
|
~InputSystemComponent() = default;
|
||||||
@ -18,39 +17,7 @@ public:
|
|||||||
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>
|
|
||||||
// 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);
|
||||||
void unbindAction(const std::string& actionName, std::vector<Key> key);
|
|
||||||
|
|
||||||
// template<typename... Keys>
|
|
||||||
// void unbindAction(const std::string& actionName, Keys... keys)
|
|
||||||
// {
|
|
||||||
// static_assert((std::is_same<Keys, Key>::value && ...), "A passed argument for 'Keys' is not of type 'Key'");
|
|
||||||
|
|
||||||
// auto actionIt = m_actions.find(actionName);
|
|
||||||
// if (actionIt != m_actions.end())
|
|
||||||
// {
|
|
||||||
// auto& action = actionIt->second;
|
|
||||||
// (action.keys.erase(std::remove(action.keys.begin(), action.keys.end(), keys), action.keys.end()), ...);
|
|
||||||
// (m_keyToActionsMap[keys].erase(std::remove_if(m_keyToActionsMap[keys].begin(), m_keyToActionsMap[keys].end(),
|
|
||||||
// [&](const InputAction& a) { return a.actionName == actionName; }), m_keyToActionsMap[keys].end()), ...);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
InputComponent* m_inputComponent;
|
InputComponent* m_inputComponent;
|
||||||
|
|||||||
@ -11,7 +11,6 @@ void InputSystemComponent::update()
|
|||||||
handleActions();
|
handleActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
// alternative to bindAction template
|
|
||||||
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())
|
||||||
@ -24,22 +23,6 @@ void InputSystemComponent::bindAction(const std::string& actionName, Key key, st
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// alternative to bindAction template
|
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// alternative to unbindAction template
|
|
||||||
void InputSystemComponent::unbindAction(const std::string& actionName, Key key)
|
void InputSystemComponent::unbindAction(const std::string& actionName, Key key)
|
||||||
{
|
{
|
||||||
auto actionIt = m_actions.find(actionName);
|
auto actionIt = m_actions.find(actionName);
|
||||||
@ -52,22 +35,6 @@ void InputSystemComponent::unbindAction(const std::string& actionName, Key key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// alternative to unbindAction template
|
|
||||||
void InputSystemComponent::unbindAction(const std::string& actionName, const std::vector<Key>& keysToRemove)
|
|
||||||
{
|
|
||||||
for (Key key : keysToRemove)
|
|
||||||
{
|
|
||||||
auto actionIt = m_actions.find(actionName);
|
|
||||||
if (actionIt != m_actions.end())
|
|
||||||
{
|
|
||||||
auto& action = actionIt->second;
|
|
||||||
action.keys.erase(std::remove(action.keys.begin(), action.keys.end(), key), action.keys.end());
|
|
||||||
m_keyToActionsMap[key].erase(std::remove_if(m_keyToActionsMap[key].begin(), m_keyToActionsMap[key].end(),
|
|
||||||
[&](const InputAction& a) { return a.actionName == actionName; }), m_keyToActionsMap[key].end());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void InputSystemComponent::handleActions()
|
void InputSystemComponent::handleActions()
|
||||||
{
|
{
|
||||||
for (auto& keyActionsPair : m_keyToActionsMap)
|
for (auto& keyActionsPair : m_keyToActionsMap)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user