Skip to content

Commit

Permalink
feat(serialization): add serialization in gamepad.[hpp/cpp]
Browse files Browse the repository at this point in the history
  • Loading branch information
Dacops committed Feb 2, 2024
1 parent 17a16a1 commit 6a52d16
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/include/cubos/core/io/gamepad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <string>

#include <cubos/core/reflection/reflect.hpp>

namespace cubos::core::io
{
/// @brief Gamepad buttons.
Expand Down Expand Up @@ -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);
1 change: 1 addition & 0 deletions core/src/cubos/core/io/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cubos/core/reflection/type.hpp>

using namespace cubos::core;

using cubos::core::io::Cursor;
using cubos::core::reflection::EnumTrait;
using cubos::core::reflection::Type;
Expand Down
49 changes: 48 additions & 1 deletion core/src/cubos/core/io/gamepad.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#include <cubos/core/data/old/deserializer.hpp>
#include <cubos/core/data/old/serializer.hpp>
#include <cubos/core/io/gamepad.hpp>
#include <cubos/core/reflection/traits/enum.hpp>
#include <cubos/core/reflection/type.hpp>

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)
{
Expand Down Expand Up @@ -123,3 +129,44 @@ void data::old::deserialize<GamepadAxis>(Deserializer& des, GamepadAxis& obj)
des.read(axis);
obj = io::stringToGamepadAxis(axis);
}

CUBOS_REFLECT_EXTERNAL_IMPL(GamepadButton)

Check warning on line 133 in core/src/cubos/core/io/gamepad.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/io/gamepad.cpp#L133

Added line #L133 was not covered by tests
{
return Type::create("GamepadButton")
.with(EnumTrait{}
.withVariant<GamepadButton::Invalid>("Invalid")

Check warning on line 137 in core/src/cubos/core/io/gamepad.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/io/gamepad.cpp#L135-L137

Added lines #L135 - L137 were not covered by tests

.withVariant<GamepadButton::A>("A")
.withVariant<GamepadButton::B>("B")
.withVariant<GamepadButton::X>("X")
.withVariant<GamepadButton::Y>("Y")
.withVariant<GamepadButton::LBumper>("LBumper")
.withVariant<GamepadButton::RBumper>("RBumper")
.withVariant<GamepadButton::Back>("Back")
.withVariant<GamepadButton::Start>("Start")
.withVariant<GamepadButton::Guide>("Guide")
.withVariant<GamepadButton::LThumb>("LThumb")
.withVariant<GamepadButton::RThumb>("RThumb")
.withVariant<GamepadButton::Up>("Up")
.withVariant<GamepadButton::Right>("Right")
.withVariant<GamepadButton::Down>("Down")
.withVariant<GamepadButton::Left>("Left")

Check warning on line 153 in core/src/cubos/core/io/gamepad.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/io/gamepad.cpp#L139-L153

Added lines #L139 - L153 were not covered by tests

.withVariant<GamepadButton::Count>("Count"));

Check warning on line 155 in core/src/cubos/core/io/gamepad.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/io/gamepad.cpp#L155

Added line #L155 was not covered by tests
}

CUBOS_REFLECT_EXTERNAL_IMPL(GamepadAxis)

Check warning on line 158 in core/src/cubos/core/io/gamepad.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/io/gamepad.cpp#L158

Added line #L158 was not covered by tests
{
return Type::create("GamepadAxis")
.with(EnumTrait{}
.withVariant<GamepadAxis::Invalid>("Invalid")

Check warning on line 162 in core/src/cubos/core/io/gamepad.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/io/gamepad.cpp#L160-L162

Added lines #L160 - L162 were not covered by tests

.withVariant<GamepadAxis::LX>("LX")
.withVariant<GamepadAxis::LY>("LY")
.withVariant<GamepadAxis::RX>("RX")
.withVariant<GamepadAxis::RY>("RY")
.withVariant<GamepadAxis::LTrigger>("LTrigger")
.withVariant<GamepadAxis::RTrigger>("RTrigger")

Check warning on line 169 in core/src/cubos/core/io/gamepad.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/io/gamepad.cpp#L164-L169

Added lines #L164 - L169 were not covered by tests

.withVariant<GamepadAxis::Count>("Count"));

Check warning on line 171 in core/src/cubos/core/io/gamepad.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/io/gamepad.cpp#L171

Added line #L171 was not covered by tests
}

0 comments on commit 6a52d16

Please sign in to comment.