ECSTASY
All in the name
Loading...
Searching...
No Matches
KeySequenceListener.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_INTEGRATIONS_EVENT_LISTENERS_KEYSEQUENCELISTENER_HPP_
13#define ECSTASY_INTEGRATIONS_EVENT_LISTENERS_KEYSEQUENCELISTENER_HPP_
14
15#include <functional>
16#include <vector>
19
20namespace ecstasy
21{
22 class Registry;
23}
24
26{
27 struct KeyEvent;
28
39 public:
42
55 KeySequenceListener(const std::vector<Keyboard::Key> &sequence, Callback callback) noexcept;
56
63 ~KeySequenceListener() noexcept = default;
64
75 bool update(const KeyEvent &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 setSequence(const std::vector<Keyboard::Key> &newSequence) noexcept;
118
127 [[nodiscard]] constexpr const std::vector<Keyboard::Key> &getSequence() const noexcept
128 {
129 return _sequence;
130 }
131
142 [[nodiscard]] constexpr std::vector<Keyboard::Key> &getSequence() noexcept
143 {
144 return _sequence;
145 }
146
155 [[nodiscard]] constexpr const Callback &getCallback() const noexcept
156 {
157 return _callback;
158 }
159
160 // clang-format off
172 // clang-format on
173 [[nodiscard]] constexpr Keyboard::Key getHeldKey() const noexcept
174 {
175 return _heldKey;
176 }
177
188 [[nodiscard]] constexpr const std::vector<Keyboard::Key> &getValidatedKeys() const noexcept
189 {
190 return _validatedKeys;
191 }
192
193 private:
194 // Sequence to watch for.
196 // Validated keys.
198 // Current key held (if any, @ref Keyboard::Key::Unknown otherwise).
200 // Callback called when the sequence is validated.
202 };
203} // namespace ecstasy::integration::event
204
205#endif /* !ECSTASY_INTEGRATIONS_EVENT_LISTENERS_KEYSEQUENCELISTENER_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 std::vector< Keyboard::Key > & getSequence() noexcept
Get the expected sequence.
constexpr Keyboard::Key getHeldKey() const noexcept
Get the key held.
constexpr const std::vector< Keyboard::Key > & getSequence() const noexcept
Get the expected sequence.
constexpr const Callback & getCallback() const noexcept
Get the sequence completion callback.
~KeySequenceListener() noexcept=default
Default destructor.
void setSequence(const std::vector< Keyboard::Key > &newSequence) noexcept
Change the expected sequence.
bool update(const KeyEvent &event) noexcept
Update the sequence with the given KeyEvent.
constexpr const std::vector< Keyboard::Key > & getValidatedKeys() const noexcept
Get the Validated Keys.
bool isComplete() const noexcept
Check whether the sequence is complete or not.
void reset() noexcept
Reset the sequence completion.
Event integration.
Definition Event.hpp:25
Namespace containing all symbols specific to ecstasy.
Definition ecstasy.hpp:30
Event describing a key pressed or released.
Definition KeyEvent.hpp:25