ECSTASY
All in the name
Loading...
Searching...
No Matches
GamepadCombinationListener.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_INTEGRATIONS_EVENT_LISTENERS_GAMEPADCOMBINATIONLISTENER_HPP_
13#define ECSTASY_INTEGRATIONS_EVENT_LISTENERS_GAMEPADCOMBINATIONLISTENER_HPP_
14
15#include <functional>
16#include <vector>
19
20namespace ecstasy
21{
22 class Registry;
23}
24
26{
27 struct GamepadButtonEvent;
28
37 public:
40
55 const std::vector<Gamepad::Button> &combination, Callback callback, size_t gamepadId = 0) noexcept;
56
63 ~GamepadCombinationListener() noexcept = default;
64
75 bool update(const GamepadButtonEvent &event) noexcept;
76
85 [[nodiscard]] bool isComplete() const noexcept;
86
93 void reset() noexcept;
94
105 void operator()(Registry &registry, Entity e, bool force = false);
106
117 void setCombination(const std::vector<Gamepad::Button> &newCombination) noexcept;
118
127 [[nodiscard]] constexpr const std::vector<Gamepad::Button> &getCombination() const noexcept
128 {
129 return _combination;
130 }
131
142 [[nodiscard]] constexpr std::vector<Gamepad::Button> &getCombination() noexcept
143 {
144 return _combination;
145 }
146
155 [[nodiscard]] constexpr const Callback &getCallback() const noexcept
156 {
157 return _callback;
158 }
159
168 [[nodiscard]] constexpr size_t getValidatedButtons() const noexcept
169 {
170 return _validatedButtons;
171 }
172
183 [[nodiscard]] constexpr const std::unordered_map<Gamepad::Button, bool> &getButtonStates() const noexcept
184 {
185 return _buttonStates;
186 }
187
196 [[nodiscard]] constexpr size_t getGamepadId() const noexcept
197 {
198 return _gamepadId;
199 }
200
211 void setGamepadId(size_t gamepadId) noexcept
212 {
213 _gamepadId = gamepadId;
214 reset();
215 }
216
217 private:
218 // Combination of buttons to watch for.
220 // Buttons of the combination that are pressed.
222 // Count of validated buttons.
224 // Callback called when the combination is validated.
226 // Gamepad id to watch for.
228 };
229} // namespace ecstasy::integration::event
230
231#endif /* !ECSTASY_INTEGRATIONS_EVENT_LISTENERS_GAMEPADCOMBINATIONLISTENER_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
constexpr size_t getGamepadId() const noexcept
Get the Gamepad Id.
void setGamepadId(size_t gamepadId) noexcept
Change the Gamepad Id.
constexpr const Callback & getCallback() const noexcept
Get the combination completion callback.
constexpr const std::unordered_map< Gamepad::Button, bool > & getButtonStates() const noexcept
Get the Button States.
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.
constexpr size_t getValidatedButtons() const noexcept
Get the count of validated buttons.
constexpr const std::vector< Gamepad::Button > & getCombination() const noexcept
Get the expected combination.
constexpr std::vector< Gamepad::Button > & getCombination() noexcept
Get the expected combination.
bool isComplete() const noexcept
Check whether the combination is complete or not.
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.