ECSTASY
All in the name
Loading...
Searching...
No Matches
ActionBinding.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_INTEGRATIONS_USER_ACTION_ACTIONBINDING_HPP_
13#define ECSTASY_INTEGRATIONS_USER_ACTION_ACTIONBINDING_HPP_
14
15#include <iostream>
16#include <toml++/toml.h>
17#include <unordered_map>
18
19#include "Action.hpp"
24
26{
28 namespace
29 {
31 }
32
41 template <typename E>
44
53 public:
54 // LCOV_EXCL_START
55
57
58 // LCOV_EXCL_STOP
59#ifdef _DOXYGEN_
61 enum class Type {
63 Key,
66
67 Count
68 };
69#endif
70
77 constexpr ActionBinding() noexcept : type(Type::Count), actionId(0)
78 {
79 }
80
92 template <typename E, typename = is_valid_action_id<E>>
93 constexpr ActionBinding(E id, event::Mouse::Button input) noexcept
94 : type(Type::MouseButton), actionId(static_cast<Action::Id>(id)), mouseButton(input)
95 {
96 }
97
111 template <typename E, typename = is_valid_action_id<E>>
112 constexpr ActionBinding(E id, event::Keyboard::Key input)
113 : type(Type::Key), actionId(static_cast<Action::Id>(id)), key(input)
114 {
116 }
117
131 template <typename E, typename = is_valid_action_id<E>>
133 : type(Type::GamepadButton), actionId(static_cast<Action::Id>(id)), gamepadButton(input)
134 {
136 }
137
151 template <typename E, typename = is_valid_action_id<E>>
152 constexpr ActionBinding(E id, event::Gamepad::Axis input)
153 : type(Type::GamepadAxis), actionId(static_cast<Action::Id>(id)), gamepadAxis(input)
154 {
156 }
157
168 [[nodiscard]] constexpr bool operator==(const ActionBinding &other) const noexcept
169 {
170 if (type != other.type || actionId != other.actionId)
171 return false;
172
173 switch (type) {
174 case Type::MouseButton: return mouseButton == other.mouseButton;
175 case Type::Key: return key == other.key;
176 case Type::GamepadButton: return gamepadButton == other.gamepadButton;
177 case Type::GamepadAxis: return gamepadAxis == other.gamepadAxis;
178 default: return true;
179 }
180 }
181
191
199
208 union {
213 };
214 };
215} // namespace ecstasy::integration::user_action
216
217#endif /* !ECSTASY_INTEGRATIONS_USER_ACTION_ACTIONBINDING_HPP_ */
Create a serializable enumeration type.
#define SERIALIZABLE_ENUM(NAME, STARTING_AT,...)
Create a serializable enumeration type.
static constexpr void assertAxisValid(Axis axis, bool allowUnknown=false)
Check whether an axis is valid.
Definition Gamepad.hpp:287
Axis
Gamepad axis, associated value must be in range [-1, 1].
Definition Gamepad.hpp:66
static constexpr void assertButtonValid(Button button, bool allowUnknown=false)
Check whether a button is valid.
Definition Gamepad.hpp:269
static constexpr void assertKeyValid(Key key, bool allowUnknown=false)
Check whether a key is valid.
Definition Keyboard.hpp:236
Action binding class, represent a binding between an input and a given action.
event::Mouse::Button mouseButton
Type::MouseButton associated data.
event::Gamepad::Axis gamepadAxis
Type::GamepadAxis associated data.
constexpr ActionBinding(E id, event::Mouse::Button input) noexcept
Construct a mouse button action binding.
event::Gamepad::Button gamepadButton
Type::GamepadButton associated data.
constexpr ActionBinding() noexcept
Construct an empty action binding.
@ GamepadButton
The action is bound to a gamepad button state.
@ MouseButton
The action is bound to a mouse button state.
@ Key
The action is bound to a keyboard key state.
@ GamepadAxis
The action is bound to a gamepad axis state.
@ Count
Keep last - the total number of bindings.
event::Keyboard::Key key
Type::Key associated data.
constexpr ActionBinding(E id, event::Gamepad::Axis input)
Construct a gamepad axis action binding.
constexpr ActionBinding(E id, event::Gamepad::Button input)
Construct a gamepad button action binding.
constexpr bool operator==(const ActionBinding &other) const noexcept
Equality operator overload.
constexpr ActionBinding(E id, event::Keyboard::Key input)
Construct a key action binding.
Event integration.
Definition Event.hpp:25
User action integration.
Definition Action.hpp:18
typename std::conditional< std::is_enum_v< E >, std::true_type, std::is_same< E, Action::Id > >::type is_valid_action_id
Boolean type trait to check if a type is a valid action id type (enum or size_t).
Describe an action changed event.
Definition Action.hpp:25
size_t Id
Action identifier type.
Definition Action.hpp:27