ECSTASY
All in the name
Loading...
Searching...
No Matches
GamepadSequenceListener.cpp
Go to the documentation of this file.
1
11
14
16{
18 const std::vector<Gamepad::Button> &sequence, Callback callback, size_t gamepadId) noexcept
19 : _sequence(sequence), _callback(callback), _gamepadId(gamepadId)
20 {
21 reset();
22 }
23
25 {
26 if (event.id != _gamepadId)
27 return false;
28
29 if (event.pressed) {
30 if (_heldButton == Gamepad::Button::Unknown && event.button == _sequence.at(_validatedButtons.size()))
31 _heldButton = event.button;
32 else if (_heldButton != Gamepad::Button::Unknown || !_validatedButtons.empty()) {
33 reset();
35 return update(event);
36 }
37 } else {
38 if (_heldButton != Gamepad::Button::Unknown && _heldButton == event.button) {
39 _validatedButtons.push_back(_heldButton);
40 _heldButton = Gamepad::Button::Unknown;
41 return isComplete();
42 }
43 }
44 return false;
45 }
46
48 {
50 }
51
53 {
54 if (force || isComplete()) {
55 _callback(registry, e, *this);
56 reset();
57 }
58 }
59
61 {
62 _sequence = newSequence;
63 reset();
64 }
65
66} // namespace ecstasy::integration::event
Encapsulate an index to an entity.
Definition Entity.hpp:35
Base of an ECS architecture.
Definition Registry.hpp:82
void operator()(Registry &registry, Entity e, bool force=false)
Call the callback and reset() if the sequence is complete or if force.
bool update(const GamepadButtonEvent &event) noexcept
Update the sequence with the given GamepadButtonEvent.
void setSequence(const std::vector< Gamepad::Button > &newSequence) noexcept
Change the expected sequence.
bool isComplete() const noexcept
Check whether the sequence is complete or not.
GamepadSequenceListener(const std::vector< Gamepad::Button > &sequence, Callback callback, size_t gamepadId=0) noexcept
Construct a new Gamepad Sequence Listener object.
constexpr void reset() noexcept
Reset the sequence completion.
Event integration.
Definition Event.hpp:25
T size(T... args)
Event describing a gamepad button pressed or released.