ECSTASY
All in the name
Loading...
Searching...
No Matches
GamepadCombinationListener.cpp
Go to the documentation of this file.
1
11
14
16{
18 const std::vector<Gamepad::Button> &combination, Callback callback, size_t gamepadId) noexcept
19 : _combination(combination), _callback(callback), _gamepadId(gamepadId)
20 {
21 reset();
22 }
23
25 {
26 if (event.id != _gamepadId)
27 return false;
28
29 auto it = _buttonStates.find(event.button);
30
31 if (it != _buttonStates.end() && it->second != event.pressed) {
32 if (event.pressed)
33 _validatedButtons++;
34 else
35 _validatedButtons--;
36 it->second = event.pressed;
37 return isComplete();
38 }
39 return false;
40 }
41
43 {
45 }
46
48 {
51 for (Gamepad::Button button : _combination)
52 _buttonStates[button] = false;
53 }
54
56 {
57 if (force || isComplete()) {
58 _callback(registry, e, *this);
59 reset();
60 }
61 }
62
64 {
65 _combination = newCombination;
66 reset();
67 }
68} // namespace ecstasy::integration::event
Encapsulate an index to an entity.
Definition Entity.hpp:35
Base of an ECS architecture.
Definition Registry.hpp:82
GamepadCombinationListener(const std::vector< Gamepad::Button > &combination, Callback callback, size_t gamepadId=0) noexcept
Construct a new Button Combination Listener object.
void operator()(Registry &registry, Entity e, bool force=false)
Call the callback and reset() if the combination is complete or if force.
void setCombination(const std::vector< Gamepad::Button > &newCombination) noexcept
Change the expected combination.
void reset() noexcept
Reset the combination completion.
bool update(const GamepadButtonEvent &event) noexcept
Update the combination with the given GamepadButtonEvent.
bool isComplete() const noexcept
Check whether the combination is complete or not.
T clear(T... args)
Event integration.
Definition Event.hpp:25
T size(T... args)
Event describing a gamepad button pressed or released.