ECSTASY
All in the name
Loading...
Searching...
No Matches
KeyCombinationListener.cpp
Go to the documentation of this file.
1
11
14
16{
18 const std::vector<Keyboard::Key> &combination, Callback callback) noexcept
19 : _combination(combination), _callback(callback)
20 {
21 reset();
22 }
23
25 {
26 auto it = _keyStates.find(event.key);
27
28 if (it != _keyStates.end() && it->second != event.pressed) {
29 if (event.pressed)
30 _validatedKeys++;
31 else
32 _validatedKeys--;
33 it->second = event.pressed;
34 return isComplete();
35 }
36 return false;
37 }
38
40 {
42 }
43
45 {
48 for (Keyboard::Key key : _combination)
49 _keyStates[key] = false;
50 }
51
52 void KeyCombinationListener::operator()(Registry &registry, Entity e, bool force)
53 {
54 if (force || isComplete()) {
55 _callback(registry, e, *this);
56 reset();
57 }
58 }
59
61 {
62 _combination = newCombination;
63 reset();
64 }
65} // namespace ecstasy::integration::event
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
void operator()(Registry &registry, Entity e, bool force=false)
Call the callback and reset() if the combination is complete or if force.
void reset() noexcept
Reset the combination completion.
bool update(const KeyEvent &event) noexcept
Update the combination with the given KeyEvent.
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.
KeyCombinationListener(const std::vector< Keyboard::Key > &combination, Callback callback) noexcept
Construct a new Key Combination Listener object.
T clear(T... args)
Event integration.
Definition Event.hpp:25
T size(T... args)
Event describing a key pressed or released.
Definition KeyEvent.hpp:25