diff --git a/src/core/analog_controller.cpp b/src/core/analog_controller.cpp index 7663f32b0..665d70afb 100644 --- a/src/core/analog_controller.cpp +++ b/src/core/analog_controller.cpp @@ -413,3 +413,26 @@ std::optional AnalogController::StaticGetButtonCodeByName(std::string_view #undef BUTTON } + +Controller::AxisList AnalogController::StaticGetAxisNames() +{ +#define A(n) \ + { \ +#n, static_cast < s32>(Axis::n) \ + } + + return {A(LeftX), A(LeftY), A(RightX), A(RightY)}; + +#undef A +} + +Controller::ButtonList AnalogController::StaticGetButtonNames() +{ +#define B(n) \ + { \ +#n, static_cast < s32>(Button::n) \ + } + return {B(Up), B(Down), B(Left), B(Right), B(Select), B(Start), B(Triangle), B(Cross), B(Circle), + B(Square), B(L1), B(L2), B(R1), B(R2), B(L3), B(R3)}; +#undef B +} diff --git a/src/core/analog_controller.h b/src/core/analog_controller.h index 1ea78f955..1449a8779 100644 --- a/src/core/analog_controller.h +++ b/src/core/analog_controller.h @@ -46,6 +46,8 @@ public: static std::unique_ptr Create(); static std::optional StaticGetAxisCodeByName(std::string_view axis_name); static std::optional StaticGetButtonCodeByName(std::string_view button_name); + static AxisList StaticGetAxisNames(); + static ButtonList StaticGetButtonNames(); ControllerType GetType() const override; std::optional GetAxisCodeByName(std::string_view axis_name) const override; diff --git a/src/core/controller.cpp b/src/core/controller.cpp index ff23bce0a..9ce77e9d9 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -62,6 +62,38 @@ std::optional Controller::GetButtonCodeByName(std::string_view button_name) return std::nullopt; } +Controller::AxisList Controller::GetAxisNames(ControllerType type) +{ + switch (type) + { + case ControllerType::DigitalController: + return DigitalController::StaticGetAxisNames(); + + case ControllerType::AnalogController: + return AnalogController::StaticGetAxisNames(); + + case ControllerType::None: + default: + return {}; + } +} + +Controller::ButtonList Controller::GetButtonNames(ControllerType type) +{ + switch (type) + { + case ControllerType::DigitalController: + return DigitalController::StaticGetButtonNames(); + + case ControllerType::AnalogController: + return AnalogController::StaticGetButtonNames(); + + case ControllerType::None: + default: + return {}; + } +} + std::optional Controller::GetAxisCodeByName(ControllerType type, std::string_view axis_name) { switch (type) diff --git a/src/core/controller.h b/src/core/controller.h index df73c1e6b..573e0a5fa 100644 --- a/src/core/controller.h +++ b/src/core/controller.h @@ -2,13 +2,18 @@ #include "types.h" #include #include +#include #include +#include class StateWrapper; class Controller { public: + using ButtonList = std::vector>; + using AxisList = std::vector>; + Controller(); virtual ~Controller(); @@ -50,4 +55,10 @@ public: /// Gets the integer code for a button in the specified controller type. static std::optional GetButtonCodeByName(ControllerType type, std::string_view button_name); + + /// Returns a list of axises for the specified controller type. + static AxisList GetAxisNames(ControllerType type); + + /// Returns a list of buttons for the specified controller type. + static ButtonList GetButtonNames(ControllerType type); }; diff --git a/src/core/digital_controller.cpp b/src/core/digital_controller.cpp index b4252810f..fb1bb86ff 100644 --- a/src/core/digital_controller.cpp +++ b/src/core/digital_controller.cpp @@ -132,3 +132,19 @@ std::optional DigitalController::StaticGetButtonCodeByName(std::string_view #undef BUTTON } + +Controller::AxisList DigitalController::StaticGetAxisNames() +{ + return {}; +} + +Controller::ButtonList DigitalController::StaticGetButtonNames() +{ +#define B(n) \ + { \ +#n, static_cast < s32>(Button::n) \ + } + return {B(Up), B(Down), B(Left), B(Right), B(Select), B(Start), B(Triangle), + B(Cross), B(Circle), B(Square), B(L1), B(L2), B(R1), B(R2)}; +#undef B +} diff --git a/src/core/digital_controller.h b/src/core/digital_controller.h index 759905c62..58dbb465c 100644 --- a/src/core/digital_controller.h +++ b/src/core/digital_controller.h @@ -34,6 +34,8 @@ public: static std::unique_ptr Create(); static std::optional StaticGetAxisCodeByName(std::string_view button_name); static std::optional StaticGetButtonCodeByName(std::string_view button_name); + static AxisList StaticGetAxisNames(); + static ButtonList StaticGetButtonNames(); ControllerType GetType() const override; std::optional GetAxisCodeByName(std::string_view axis_name) const override;