ECSTASY
All in the name
Loading...
Searching...
No Matches
KeyCombinationListener.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_INTEGRATIONS_EVENT_LISTENERS_KEYCOMBINATIONLISTENER_HPP_
13#define ECSTASY_INTEGRATIONS_EVENT_LISTENERS_KEYCOMBINATIONLISTENER_HPP_
14
15#include <functional>
16#include <vector>
19
20namespace ecstasy
21{
22 class Registry;
23}
24
26{
27 struct KeyEvent;
28
37 public:
40
53 KeyCombinationListener(const std::vector<Keyboard::Key> &combination, Callback callback) noexcept;
54
61 ~KeyCombinationListener() noexcept = default;
62
73 bool update(const KeyEvent &event) noexcept;
74
83 [[nodiscard]] bool isComplete() const noexcept;
84
91 void reset() noexcept;
92
103 void operator()(Registry &registry, Entity e, bool force = false);
104
115 void setCombination(const std::vector<Keyboard::Key> &newCombination) noexcept;
116
125 [[nodiscard]] constexpr const std::vector<Keyboard::Key> &getCombination() const noexcept
126 {
127 return _combination;
128 }
129
140 [[nodiscard]] constexpr std::vector<Keyboard::Key> &getCombination() noexcept
141 {
142 return _combination;
143 }
144
153 [[nodiscard]] constexpr const Callback &getCallback() const noexcept
154 {
155 return _callback;
156 }
157
166 [[nodiscard]] constexpr size_t getValidatedKeys() const noexcept
167 {
168 return _validatedKeys;
169 }
170
181 [[nodiscard]] constexpr const std::unordered_map<Keyboard::Key, bool> &getKeyStates() const noexcept
182 {
183 return _keyStates;
184 }
185
186 private:
187 // Expected combination of keys to watch for.
189 // Validated keys.
191 // Count of validated keys.
193 // Callback called when the combination is validated.
195 };
196} // namespace ecstasy::integration::event
197
198#endif /* !ECSTASY_INTEGRATIONS_EVENT_LISTENERS_KEYCOMBINATIONLISTENER_HPP_ */
Encapsulate an index to an entity.
Encapsulate an index to an entity.
Definition Entity.hpp:35
Base of an ECS architecture.
Definition Registry.hpp:82
std::unordered_map< Keyboard::Key, bool > _keyStates
constexpr size_t getValidatedKeys() const noexcept
Get the count of validated keys.
~KeyCombinationListener() noexcept=default
Default destructor.
void reset() noexcept
Reset the combination completion.
bool update(const KeyEvent &event) noexcept
Update the combination with the given KeyEvent.
constexpr std::vector< Keyboard::Key > & getCombination() noexcept
Get the expected combination.
constexpr const std::vector< Keyboard::Key > & getCombination() const noexcept
Get the expected combination.
constexpr const std::unordered_map< Keyboard::Key, bool > & getKeyStates() const noexcept
Get the Key States.
bool isComplete() const noexcept
Check whether the combination is complete or not.
void setCombination(const std::vector< Keyboard::Key > &newCombination) noexcept
Change the expected combination.
constexpr const Callback & getCallback() const noexcept
Get the combination completion callback.
Event integration.
Definition Event.hpp:25
Namespace containing all symbols specific to ecstasy.
Definition ecstasy.hpp:30
Event describing a key pressed or released.
Definition KeyEvent.hpp:25