From 6a52d16b360f14a68821189e4e5a4ff52f58e02b Mon Sep 17 00:00:00 2001 From: David Pires <79417054+Dacops@users.noreply.github.com> Date: Fri, 2 Feb 2024 00:26:38 +0000 Subject: [PATCH] feat(serialization): add serialization in gamepad.[hpp/cpp] --- core/include/cubos/core/io/gamepad.hpp | 5 +++ core/src/cubos/core/io/cursor.cpp | 1 + core/src/cubos/core/io/gamepad.cpp | 49 +++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/core/include/cubos/core/io/gamepad.hpp b/core/include/cubos/core/io/gamepad.hpp index 9914b97677..1738ceff1c 100644 --- a/core/include/cubos/core/io/gamepad.hpp +++ b/core/include/cubos/core/io/gamepad.hpp @@ -6,6 +6,8 @@ #include +#include + namespace cubos::core::io { /// @brief Gamepad buttons. @@ -100,3 +102,6 @@ namespace cubos::core::io /// @ingroup core-io GamepadAxis stringToGamepadAxis(const std::string& str); } // namespace cubos::core::io + +CUBOS_REFLECT_EXTERNAL_DECL(cubos::core::io::GamepadButton); +CUBOS_REFLECT_EXTERNAL_DECL(cubos::core::io::GamepadAxis); diff --git a/core/src/cubos/core/io/cursor.cpp b/core/src/cubos/core/io/cursor.cpp index 165bb6a88b..ab6b198dc0 100644 --- a/core/src/cubos/core/io/cursor.cpp +++ b/core/src/cubos/core/io/cursor.cpp @@ -3,6 +3,7 @@ #include using namespace cubos::core; + using cubos::core::io::Cursor; using cubos::core::reflection::EnumTrait; using cubos::core::reflection::Type; diff --git a/core/src/cubos/core/io/gamepad.cpp b/core/src/cubos/core/io/gamepad.cpp index 56d8043959..282dfe2835 100644 --- a/core/src/cubos/core/io/gamepad.cpp +++ b/core/src/cubos/core/io/gamepad.cpp @@ -1,12 +1,18 @@ #include #include #include +#include +#include + +using namespace cubos::core; using cubos::core::data::old::Deserializer; using cubos::core::data::old::Serializer; + using cubos::core::io::GamepadAxis; using cubos::core::io::GamepadButton; -using namespace cubos::core; +using cubos::core::reflection::EnumTrait; +using cubos::core::reflection::Type; std::string io::gamepadButtonToString(GamepadButton button) { @@ -123,3 +129,44 @@ void data::old::deserialize(Deserializer& des, GamepadAxis& obj) des.read(axis); obj = io::stringToGamepadAxis(axis); } + +CUBOS_REFLECT_EXTERNAL_IMPL(GamepadButton) +{ + return Type::create("GamepadButton") + .with(EnumTrait{} + .withVariant("Invalid") + + .withVariant("A") + .withVariant("B") + .withVariant("X") + .withVariant("Y") + .withVariant("LBumper") + .withVariant("RBumper") + .withVariant("Back") + .withVariant("Start") + .withVariant("Guide") + .withVariant("LThumb") + .withVariant("RThumb") + .withVariant("Up") + .withVariant("Right") + .withVariant("Down") + .withVariant("Left") + + .withVariant("Count")); +} + +CUBOS_REFLECT_EXTERNAL_IMPL(GamepadAxis) +{ + return Type::create("GamepadAxis") + .with(EnumTrait{} + .withVariant("Invalid") + + .withVariant("LX") + .withVariant("LY") + .withVariant("RX") + .withVariant("RY") + .withVariant("LTrigger") + .withVariant("RTrigger") + + .withVariant("Count")); +}