Controller: Add methods to query buttons/axises for a controller type
This commit is contained in:
parent
0528a2a1f9
commit
4b1541087a
|
@ -413,3 +413,26 @@ std::optional<s32> 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
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@ public:
|
|||
static std::unique_ptr<AnalogController> Create();
|
||||
static std::optional<s32> StaticGetAxisCodeByName(std::string_view axis_name);
|
||||
static std::optional<s32> StaticGetButtonCodeByName(std::string_view button_name);
|
||||
static AxisList StaticGetAxisNames();
|
||||
static ButtonList StaticGetButtonNames();
|
||||
|
||||
ControllerType GetType() const override;
|
||||
std::optional<s32> GetAxisCodeByName(std::string_view axis_name) const override;
|
||||
|
|
|
@ -62,6 +62,38 @@ std::optional<s32> 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<s32> Controller::GetAxisCodeByName(ControllerType type, std::string_view axis_name)
|
||||
{
|
||||
switch (type)
|
||||
|
|
|
@ -2,13 +2,18 @@
|
|||
#include "types.h"
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
class StateWrapper;
|
||||
|
||||
class Controller
|
||||
{
|
||||
public:
|
||||
using ButtonList = std::vector<std::pair<std::string, s32>>;
|
||||
using AxisList = std::vector<std::pair<std::string, s32>>;
|
||||
|
||||
Controller();
|
||||
virtual ~Controller();
|
||||
|
||||
|
@ -50,4 +55,10 @@ public:
|
|||
|
||||
/// Gets the integer code for a button in the specified controller type.
|
||||
static std::optional<s32> 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);
|
||||
};
|
||||
|
|
|
@ -132,3 +132,19 @@ std::optional<s32> 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
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ public:
|
|||
static std::unique_ptr<DigitalController> Create();
|
||||
static std::optional<s32> StaticGetAxisCodeByName(std::string_view button_name);
|
||||
static std::optional<s32> StaticGetButtonCodeByName(std::string_view button_name);
|
||||
static AxisList StaticGetAxisNames();
|
||||
static ButtonList StaticGetButtonNames();
|
||||
|
||||
ControllerType GetType() const override;
|
||||
std::optional<s32> GetAxisCodeByName(std::string_view axis_name) const override;
|
||||
|
|
Loading…
Reference in New Issue