ECSTASY
All in the name
Loading...
Searching...
No Matches
GamepadSequenceListener.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_INTEGRATIONS_EVENT_LISTENERS_GAMEPADSEQUENCELISTENER_HPP_
13#define ECSTASY_INTEGRATIONS_EVENT_LISTENERS_GAMEPADSEQUENCELISTENER_HPP_
14
15#include <functional>
16#include <vector>
19
20namespace ecstasy
21{
22 class Registry;
23}
24
26{
27 struct GamepadButtonEvent;
28
39 public:
42
57 const std::vector<Gamepad::Button> &sequence, Callback callback, size_t gamepadId = 0) noexcept;
58
65 ~GamepadSequenceListener() noexcept = default;
66
77 bool update(const GamepadButtonEvent &event) noexcept;
78
87 [[nodiscard]] bool isComplete() const noexcept;
88
95 constexpr void reset() noexcept
96 {
99 }
100
111 void operator()(Registry &registry, Entity e, bool force = false);
112
123 void setSequence(const std::vector<Gamepad::Button> &newSequence) noexcept;
124
133 [[nodiscard]] constexpr const std::vector<Gamepad::Button> &getSequence() const noexcept
134 {
135 return _sequence;
136 }
137
148 [[nodiscard]] constexpr std::vector<Gamepad::Button> &getSequence() noexcept
149 {
150 return _sequence;
151 }
152
161 [[nodiscard]] constexpr const Callback &getCallback() const noexcept
162 {
163 return _callback;
164 }
165
177 [[nodiscard]] constexpr Gamepad::Button getHeldButton() const noexcept
178 {
179 return _heldButton;
180 }
181
192 [[nodiscard]] constexpr const std::vector<Gamepad::Button> &getValidatedButtons() const noexcept
193 {
194 return _validatedButtons;
195 }
196
205 [[nodiscard]] constexpr size_t getGamepadId() const noexcept
206 {
207 return _gamepadId;
208 }
209
220 constexpr void setGamepadId(size_t gamepadId) noexcept
221 {
222 _gamepadId = gamepadId;
223 reset();
224 }
225
226 private:
227 // Expected sequence of buttons to watch for.
229 // Validated buttons.
231 // Button held (if any, otherwise @ref Gamepad::Button::Unknown).
233 // Callback called when the sequence is validated.
235 // Gamepad id to watch for.
237 };
238} // namespace ecstasy::integration::event
239
240#endif /* !ECSTASY_INTEGRATIONS_EVENT_LISTENERS_GAMEPADSEQUENCELISTENER_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
void operator()(Registry &registry, Entity e, bool force=false)
Call the callback and reset() if the sequence is complete or if force.
constexpr Gamepad::Button getHeldButton() const noexcept
Get the button held.
constexpr void setGamepadId(size_t gamepadId) noexcept
Change the Gamepad Id.
bool update(const GamepadButtonEvent &event) noexcept
Update the sequence with the given GamepadButtonEvent.
constexpr const Callback & getCallback() const noexcept
Get the sequence completion callback.
constexpr const std::vector< Gamepad::Button > & getSequence() const noexcept
Get the expected sequence.
constexpr size_t getGamepadId() const noexcept
Get the Gamepad Id.
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.
constexpr std::vector< Gamepad::Button > & getSequence() noexcept
Get the expected sequence.
constexpr void reset() noexcept
Reset the sequence completion.
constexpr const std::vector< Gamepad::Button > & getValidatedButtons() const noexcept
Get the Validated Buttons.
T clear(T... args)
Event integration.
Definition Event.hpp:25
Namespace containing all symbols specific to ecstasy.
Definition ecstasy.hpp:30
Event describing a gamepad button pressed or released.