motion_from_button.cpp 965 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "input_common/motion_from_button.h"
  5. #include "input_common/motion_input.h"
  6. namespace InputCommon {
  7. class MotionKey final : public Input::MotionDevice {
  8. public:
  9. using Button = std::unique_ptr<Input::ButtonDevice>;
  10. explicit MotionKey(Button key_) : key(std::move(key_)) {}
  11. Input::MotionStatus GetStatus() const override {
  12. if (key->GetStatus()) {
  13. return motion.GetRandomMotion(2, 6);
  14. }
  15. return motion.GetRandomMotion(0, 0);
  16. }
  17. private:
  18. Button key;
  19. InputCommon::MotionInput motion{0.0f, 0.0f, 0.0f};
  20. };
  21. std::unique_ptr<Input::MotionDevice> MotionFromButton::Create(const Common::ParamPackage& params) {
  22. auto key = Input::CreateDevice<Input::ButtonDevice>(params.Serialize());
  23. return std::make_unique<MotionKey>(std::move(key));
  24. }
  25. } // namespace InputCommon