diff options
| author | 2020-10-08 10:18:39 -0700 | |
|---|---|---|
| committer | 2020-10-08 10:18:39 -0700 | |
| commit | 06e65de93cfa923b6fb1f12fa20193515249234d (patch) | |
| tree | 9771ca19a2686af1185f62ed7488d977d37a1703 /src/input_common/motion_from_button.cpp | |
| parent | Merge pull request #4765 from ReinUsesLisp/fix-sort-devices (diff) | |
| parent | Add random motion input to keyboard (diff) | |
| download | yuzu-06e65de93cfa923b6fb1f12fa20193515249234d.tar.gz yuzu-06e65de93cfa923b6fb1f12fa20193515249234d.tar.xz yuzu-06e65de93cfa923b6fb1f12fa20193515249234d.zip | |
Merge pull request #4677 from german77/ShakeFromButton
InputCommon: Add random motion input for buttons
Diffstat (limited to 'src/input_common/motion_from_button.cpp')
| -rw-r--r-- | src/input_common/motion_from_button.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/input_common/motion_from_button.cpp b/src/input_common/motion_from_button.cpp new file mode 100644 index 000000000..9d459f963 --- /dev/null +++ b/src/input_common/motion_from_button.cpp | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "input_common/motion_from_button.h" | ||
| 6 | #include "input_common/motion_input.h" | ||
| 7 | |||
| 8 | namespace InputCommon { | ||
| 9 | |||
| 10 | class MotionKey final : public Input::MotionDevice { | ||
| 11 | public: | ||
| 12 | using Button = std::unique_ptr<Input::ButtonDevice>; | ||
| 13 | |||
| 14 | MotionKey(Button key_) : key(std::move(key_)) {} | ||
| 15 | |||
| 16 | Input::MotionStatus GetStatus() const override { | ||
| 17 | |||
| 18 | if (key->GetStatus()) { | ||
| 19 | return motion.GetRandomMotion(2, 6); | ||
| 20 | } | ||
| 21 | return motion.GetRandomMotion(0, 0); | ||
| 22 | } | ||
| 23 | |||
| 24 | private: | ||
| 25 | Button key; | ||
| 26 | InputCommon::MotionInput motion{0.0f, 0.0f, 0.0f}; | ||
| 27 | }; | ||
| 28 | |||
| 29 | std::unique_ptr<Input::MotionDevice> MotionFromButton::Create(const Common::ParamPackage& params) { | ||
| 30 | auto key = Input::CreateDevice<Input::ButtonDevice>(params.Serialize()); | ||
| 31 | return std::make_unique<MotionKey>(std::move(key)); | ||
| 32 | } | ||
| 33 | |||
| 34 | } // namespace InputCommon | ||