yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

input_common: Fix joycon mappings

This commit is contained in:
german77 2023-01-14 00:36:03 -06:00 committed by Narr the Reg
parent 340f15d1fa
commit fafa92cfb8
2 changed files with 53 additions and 57 deletions

View File

@ -411,13 +411,25 @@ std::shared_ptr<Joycon::JoyconDriver> Joycons::GetHandle(PadIdentifier identifie
} }
PadIdentifier Joycons::GetIdentifier(std::size_t port, Joycon::ControllerType type) const { PadIdentifier Joycons::GetIdentifier(std::size_t port, Joycon::ControllerType type) const {
const std::array<u8, 16> guid{0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, static_cast<u8>(type)};
return { return {
.guid = Common::UUID{Common::InvalidUUID}, .guid = Common::UUID{guid},
.port = port, .port = port,
.pad = static_cast<std::size_t>(type), .pad = static_cast<std::size_t>(type),
}; };
} }
Common::ParamPackage Joycons::GetParamPackage(std::size_t port, Joycon::ControllerType type) const {
const auto identifier = GetIdentifier(port, type);
return {
{"engine", GetEngineName()},
{"guid", identifier.guid.RawString()},
{"port", std::to_string(identifier.port)},
{"pad", std::to_string(identifier.pad)},
};
}
std::vector<Common::ParamPackage> Joycons::GetInputDevices() const { std::vector<Common::ParamPackage> Joycons::GetInputDevices() const {
std::vector<Common::ParamPackage> devices{}; std::vector<Common::ParamPackage> devices{};
@ -428,14 +440,11 @@ std::vector<Common::ParamPackage> Joycons::GetInputDevices() const {
if (!device->IsConnected()) { if (!device->IsConnected()) {
return; return;
} }
auto param = GetParamPackage(device->GetDevicePort(), device->GetHandleDeviceType());
std::string name = fmt::format("{} {}", JoyconName(device->GetHandleDeviceType()), std::string name = fmt::format("{} {}", JoyconName(device->GetHandleDeviceType()),
device->GetDevicePort() + 1); device->GetDevicePort() + 1);
devices.emplace_back(Common::ParamPackage{ param.Set("display", std::move(name));
{"engine", GetEngineName()}, devices.emplace_back(param);
{"display", std::move(name)},
{"port", std::to_string(device->GetDevicePort())},
{"pad", std::to_string(static_cast<std::size_t>(device->GetHandleDeviceType()))},
});
}; };
for (const auto& controller : left_joycons) { for (const auto& controller : left_joycons) {
@ -453,14 +462,15 @@ std::vector<Common::ParamPackage> Joycons::GetInputDevices() const {
if (!left_joycons[i]->IsConnected() || !right_joycons[i]->IsConnected()) { if (!left_joycons[i]->IsConnected() || !right_joycons[i]->IsConnected()) {
continue; continue;
} }
constexpr auto type = Joycon::ControllerType::Dual; auto main_param = GetParamPackage(i, left_joycons[i]->GetHandleDeviceType());
const auto second_param = GetParamPackage(i, right_joycons[i]->GetHandleDeviceType());
const auto type = Joycon::ControllerType::Dual;
std::string name = fmt::format("{} {}", JoyconName(type), i + 1); std::string name = fmt::format("{} {}", JoyconName(type), i + 1);
devices.emplace_back(Common::ParamPackage{
{"engine", GetEngineName()}, main_param.Set("display", std::move(name));
{"display", std::move(name)}, main_param.Set("guid2", second_param.Get("guid", ""));
{"port", std::to_string(i)}, main_param.Set("pad", std::to_string(static_cast<size_t>(type)));
{"pad", std::to_string(static_cast<std::size_t>(type))}, devices.emplace_back(main_param);
});
} }
return devices; return devices;
@ -496,26 +506,21 @@ ButtonMapping Joycons::GetButtonMappingForDevice(const Common::ParamPackage& par
ButtonMapping mapping{}; ButtonMapping mapping{};
for (const auto& [switch_button, joycon_button, side] : switch_to_joycon_button) { for (const auto& [switch_button, joycon_button, side] : switch_to_joycon_button) {
int pad = params.Get("pad", 0); const std::size_t port = static_cast<std::size_t>(params.Get("port", 0));
if (pad == static_cast<int>(Joycon::ControllerType::Dual)) { auto pad = static_cast<Joycon::ControllerType>(params.Get("pad", 0));
pad = side ? static_cast<int>(Joycon::ControllerType::Right) if (pad == Joycon::ControllerType::Dual) {
: static_cast<int>(Joycon::ControllerType::Left); pad = side ? Joycon::ControllerType::Right : Joycon::ControllerType::Left;
} }
Common::ParamPackage button_params{}; Common::ParamPackage button_params = GetParamPackage(port, pad);
button_params.Set("engine", GetEngineName());
button_params.Set("port", params.Get("port", 0));
button_params.Set("pad", pad);
button_params.Set("button", static_cast<int>(joycon_button)); button_params.Set("button", static_cast<int>(joycon_button));
mapping.insert_or_assign(switch_button, std::move(button_params)); mapping.insert_or_assign(switch_button, std::move(button_params));
} }
// Map SL and SR buttons for left joycons // Map SL and SR buttons for left joycons
if (params.Get("pad", 0) == static_cast<int>(Joycon::ControllerType::Left)) { if (params.Get("pad", 0) == static_cast<int>(Joycon::ControllerType::Left)) {
Common::ParamPackage button_params{}; const std::size_t port = static_cast<std::size_t>(params.Get("port", 0));
button_params.Set("engine", GetEngineName()); Common::ParamPackage button_params = GetParamPackage(port, Joycon::ControllerType::Left);
button_params.Set("port", params.Get("port", 0));
button_params.Set("pad", static_cast<int>(Joycon::ControllerType::Left));
Common::ParamPackage sl_button_params = button_params; Common::ParamPackage sl_button_params = button_params;
Common::ParamPackage sr_button_params = button_params; Common::ParamPackage sr_button_params = button_params;
@ -527,10 +532,8 @@ ButtonMapping Joycons::GetButtonMappingForDevice(const Common::ParamPackage& par
// Map SL and SR buttons for right joycons // Map SL and SR buttons for right joycons
if (params.Get("pad", 0) == static_cast<int>(Joycon::ControllerType::Right)) { if (params.Get("pad", 0) == static_cast<int>(Joycon::ControllerType::Right)) {
Common::ParamPackage button_params{}; const std::size_t port = static_cast<std::size_t>(params.Get("port", 0));
button_params.Set("engine", GetEngineName()); Common::ParamPackage button_params = GetParamPackage(port, Joycon::ControllerType::Right);
button_params.Set("port", params.Get("port", 0));
button_params.Set("pad", static_cast<int>(Joycon::ControllerType::Right));
Common::ParamPackage sl_button_params = button_params; Common::ParamPackage sl_button_params = button_params;
Common::ParamPackage sr_button_params = button_params; Common::ParamPackage sr_button_params = button_params;
@ -548,25 +551,20 @@ AnalogMapping Joycons::GetAnalogMappingForDevice(const Common::ParamPackage& par
return {}; return {};
} }
int pad_left = params.Get("pad", 0); const std::size_t port = static_cast<std::size_t>(params.Get("port", 0));
int pad_right = pad_left; auto pad_left = static_cast<Joycon::ControllerType>(params.Get("pad", 0));
if (pad_left == static_cast<int>(Joycon::ControllerType::Dual)) { auto pad_right = pad_left;
pad_left = static_cast<int>(Joycon::ControllerType::Left); if (pad_left == Joycon::ControllerType::Dual) {
pad_right = static_cast<int>(Joycon::ControllerType::Right); pad_left = Joycon::ControllerType::Left;
pad_right = Joycon::ControllerType::Right;
} }
AnalogMapping mapping = {}; AnalogMapping mapping = {};
Common::ParamPackage left_analog_params; Common::ParamPackage left_analog_params = GetParamPackage(port, pad_left);
left_analog_params.Set("engine", GetEngineName());
left_analog_params.Set("port", params.Get("port", 0));
left_analog_params.Set("pad", pad_left);
left_analog_params.Set("axis_x", static_cast<int>(Joycon::PadAxes::LeftStickX)); left_analog_params.Set("axis_x", static_cast<int>(Joycon::PadAxes::LeftStickX));
left_analog_params.Set("axis_y", static_cast<int>(Joycon::PadAxes::LeftStickY)); left_analog_params.Set("axis_y", static_cast<int>(Joycon::PadAxes::LeftStickY));
mapping.insert_or_assign(Settings::NativeAnalog::LStick, std::move(left_analog_params)); mapping.insert_or_assign(Settings::NativeAnalog::LStick, std::move(left_analog_params));
Common::ParamPackage right_analog_params; Common::ParamPackage right_analog_params = GetParamPackage(port, pad_right);
right_analog_params.Set("engine", GetEngineName());
right_analog_params.Set("port", params.Get("port", 0));
right_analog_params.Set("pad", pad_right);
right_analog_params.Set("axis_x", static_cast<int>(Joycon::PadAxes::RightStickX)); right_analog_params.Set("axis_x", static_cast<int>(Joycon::PadAxes::RightStickX));
right_analog_params.Set("axis_y", static_cast<int>(Joycon::PadAxes::RightStickY)); right_analog_params.Set("axis_y", static_cast<int>(Joycon::PadAxes::RightStickY));
mapping.insert_or_assign(Settings::NativeAnalog::RStick, std::move(right_analog_params)); mapping.insert_or_assign(Settings::NativeAnalog::RStick, std::move(right_analog_params));
@ -578,24 +576,19 @@ MotionMapping Joycons::GetMotionMappingForDevice(const Common::ParamPackage& par
return {}; return {};
} }
int pad_left = params.Get("pad", 0); const std::size_t port = static_cast<std::size_t>(params.Get("port", 0));
int pad_right = pad_left; auto pad_left = static_cast<Joycon::ControllerType>(params.Get("pad", 0));
if (pad_left == static_cast<int>(Joycon::ControllerType::Dual)) { auto pad_right = pad_left;
pad_left = static_cast<int>(Joycon::ControllerType::Left); if (pad_left == Joycon::ControllerType::Dual) {
pad_right = static_cast<int>(Joycon::ControllerType::Right); pad_left = Joycon::ControllerType::Left;
pad_right = Joycon::ControllerType::Right;
} }
MotionMapping mapping = {}; MotionMapping mapping = {};
Common::ParamPackage left_motion_params; Common::ParamPackage left_motion_params = GetParamPackage(port, pad_left);
left_motion_params.Set("engine", GetEngineName());
left_motion_params.Set("port", params.Get("port", 0));
left_motion_params.Set("pad", pad_left);
left_motion_params.Set("motion", 0); left_motion_params.Set("motion", 0);
mapping.insert_or_assign(Settings::NativeMotion::MotionLeft, std::move(left_motion_params)); mapping.insert_or_assign(Settings::NativeMotion::MotionLeft, std::move(left_motion_params));
Common::ParamPackage right_Motion_params; Common::ParamPackage right_Motion_params = GetParamPackage(port, pad_right);
right_Motion_params.Set("engine", GetEngineName());
right_Motion_params.Set("port", params.Get("port", 0));
right_Motion_params.Set("pad", pad_right);
right_Motion_params.Set("motion", 1); right_Motion_params.Set("motion", 1);
mapping.insert_or_assign(Settings::NativeMotion::MotionRight, std::move(right_Motion_params)); mapping.insert_or_assign(Settings::NativeMotion::MotionRight, std::move(right_Motion_params));
return mapping; return mapping;

View File

@ -88,9 +88,12 @@ private:
/// Returns a JoyconHandle corresponding to a PadIdentifier /// Returns a JoyconHandle corresponding to a PadIdentifier
std::shared_ptr<Joycon::JoyconDriver> GetHandle(PadIdentifier identifier) const; std::shared_ptr<Joycon::JoyconDriver> GetHandle(PadIdentifier identifier) const;
/// Returns a PadIdentifier corresponding to the port number /// Returns a PadIdentifier corresponding to the port number and joycon type
PadIdentifier GetIdentifier(std::size_t port, Joycon::ControllerType type) const; PadIdentifier GetIdentifier(std::size_t port, Joycon::ControllerType type) const;
/// Returns a ParamPackage corresponding to the port number and joycon type
Common::ParamPackage GetParamPackage(std::size_t port, Joycon::ControllerType type) const;
std::string JoyconName(std::size_t port) const; std::string JoyconName(std::size_t port) const;
Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const; Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const;