common/input: Add helpers functions for creating input and output devices

Avoids the redundancy of needing to explictly specify the common
namespace and the type.
This commit is contained in:
Lioncash 2022-11-28 09:19:01 -05:00
parent 7f42432f42
commit 2ec7d0b5fd
7 changed files with 102 additions and 90 deletions

View file

@ -318,16 +318,11 @@ private:
std::unique_ptr<Common::Input::InputDevice> StickFromButton::Create(
const Common::ParamPackage& params) {
const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
auto up = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>(
params.Get("up", null_engine));
auto down = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>(
params.Get("down", null_engine));
auto left = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>(
params.Get("left", null_engine));
auto right = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>(
params.Get("right", null_engine));
auto modifier = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>(
params.Get("modifier", null_engine));
auto up = Common::Input::CreateInputDeviceFromString(params.Get("up", null_engine));
auto down = Common::Input::CreateInputDeviceFromString(params.Get("down", null_engine));
auto left = Common::Input::CreateInputDeviceFromString(params.Get("left", null_engine));
auto right = Common::Input::CreateInputDeviceFromString(params.Get("right", null_engine));
auto modifier = Common::Input::CreateInputDeviceFromString(params.Get("modifier", null_engine));
auto modifier_scale = params.Get("modifier_scale", 0.5f);
auto modifier_angle = params.Get("modifier_angle", 5.5f);
return std::make_unique<Stick>(std::move(up), std::move(down), std::move(left),

View file

@ -69,8 +69,7 @@ private:
std::unique_ptr<Common::Input::InputDevice> TouchFromButton::Create(
const Common::ParamPackage& params) {
const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
auto button = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>(
params.Get("button", null_engine));
auto button = Common::Input::CreateInputDeviceFromString(params.Get("button", null_engine));
const float x = params.Get("x", 0.0f) / 1280.0f;
const float y = params.Get("y", 0.0f) / 720.0f;
return std::make_unique<TouchFromButtonDevice>(std::move(button), x, y);