Pad: Add button name -> code lookup functions

This commit is contained in:
Connor McLaughlin
2019-12-09 00:46:04 +10:00
parent 8930383c96
commit c1710482df
4 changed files with 58 additions and 1 deletions

View File

@ -72,3 +72,33 @@ std::shared_ptr<DigitalController> DigitalController::Create()
{
return std::make_shared<DigitalController>();
}
std::optional<s32> DigitalController::GetButtonCodeByName(std::string_view button_name)
{
#define BUTTON(name) \
if (button_name == #name) \
{ \
return static_cast<s32>(ZeroExtend32(static_cast<u8>(Button::name))); \
}
BUTTON(Select);
BUTTON(L3);
BUTTON(R3);
BUTTON(Start);
BUTTON(Up);
BUTTON(Right);
BUTTON(Down);
BUTTON(Left);
BUTTON(L2);
BUTTON(R2);
BUTTON(L1);
BUTTON(R1);
BUTTON(Triangle);
BUTTON(Circle);
BUTTON(Cross);
BUTTON(Square);
return std::nullopt;
#undef BUTTON
}