mirror of https://git.suyu.dev/suyu/suyu
Add random motion input to keyboard
parent
03b574ae22
commit
2978232390
@ -0,0 +1,34 @@
|
||||
// Copyright 2020 yuzu Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "input_common/motion_from_button.h"
|
||||
#include "input_common/motion_input.h"
|
||||
|
||||
namespace InputCommon {
|
||||
|
||||
class MotionKey final : public Input::MotionDevice {
|
||||
public:
|
||||
using Button = std::unique_ptr<Input::ButtonDevice>;
|
||||
|
||||
MotionKey(Button key_) : key(std::move(key_)) {}
|
||||
|
||||
Input::MotionStatus GetStatus() const override {
|
||||
|
||||
if (key->GetStatus()) {
|
||||
return motion.GetRandomMotion(2, 6);
|
||||
}
|
||||
return motion.GetRandomMotion(0, 0);
|
||||
}
|
||||
|
||||
private:
|
||||
Button key;
|
||||
InputCommon::MotionInput motion{0.0f, 0.0f, 0.0f};
|
||||
};
|
||||
|
||||
std::unique_ptr<Input::MotionDevice> MotionFromButton::Create(const Common::ParamPackage& params) {
|
||||
auto key = Input::CreateDevice<Input::ButtonDevice>(params.Serialize());
|
||||
return std::make_unique<MotionKey>(std::move(key));
|
||||
}
|
||||
|
||||
} // namespace InputCommon
|
@ -0,0 +1,25 @@
|
||||
// Copyright 2020 yuzu Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/frontend/input.h"
|
||||
|
||||
namespace InputCommon {
|
||||
|
||||
/**
|
||||
* An motion device factory that takes a keyboard button and uses it as a random
|
||||
* motion device.
|
||||
*/
|
||||
class MotionFromButton final : public Input::Factory<Input::MotionDevice> {
|
||||
public:
|
||||
/**
|
||||
* Creates an motion device from button devices
|
||||
* @param params contains parameters for creating the device:
|
||||
* - "key": a serialized ParamPackage for creating a button device
|
||||
*/
|
||||
std::unique_ptr<Input::MotionDevice> Create(const Common::ParamPackage& params) override;
|
||||
};
|
||||
|
||||
} // namespace InputCommon
|
Loading…
Reference in New Issue