fix: 全局减小adb滑动距离

糊屎!
This commit is contained in:
MistEO
2023-05-21 01:19:12 +08:00
parent f9216a25b9
commit 3fa6fd6340
7 changed files with 30 additions and 11 deletions

View File

@@ -1,7 +1,11 @@
#include "ControlScaleProxy.h"
asst::ControlScaleProxy::ControlScaleProxy(std::shared_ptr<ControllerAPI> controller, ProxyCallback proxy_callback)
: m_controller(controller), m_callback(proxy_callback), m_rand_engine(std::random_device {}())
#include "Config/GeneralConfig.h"
asst::ControlScaleProxy::ControlScaleProxy(std::shared_ptr<ControllerAPI> controller, ControllerType controller_type,
ProxyCallback proxy_callback)
: m_controller(controller), m_controller_type(controller_type), m_callback(proxy_callback),
m_rand_engine(std::random_device {}())
{
auto screen_res = m_controller->get_screen_res();
@@ -74,8 +78,17 @@ bool asst::ControlScaleProxy::swipe(const Point& p1, const Point& p2, int durati
bool asst::ControlScaleProxy::swipe(const Rect& r1, const Rect& r2, int duration, bool extra_swipe, double slope_in,
double slope_out, bool with_pause)
{
return swipe(rand_point_in_rect(r1), rand_point_in_rect(r2), duration, extra_swipe, slope_in, slope_out,
with_pause);
auto rand_p1 = rand_point_in_rect(r1);
auto rand_p2 = rand_point_in_rect(r2);
if (m_controller_type == ControllerType::Adb) {
// 同样的参数 ADB 总是划过头,糊点屎进来
const auto& opt = Config.get_options();
auto x_dist = rand_p1.x - rand_p2.x;
rand_p2.x = rand_p1.x - static_cast<int>(x_dist * opt.adb_swipe_x_distance_multiplier);
}
return swipe(rand_p1, rand_p2, duration, extra_swipe, slope_in, slope_out, with_pause);
}
bool asst::ControlScaleProxy::inject_input_event(InputEvent event)

View File

@@ -15,7 +15,8 @@ namespace asst
using ProxyCallback = std::function<void(const json::object&)>;
public:
ControlScaleProxy(std::shared_ptr<ControllerAPI> controller, ProxyCallback proxy_callback);
ControlScaleProxy(std::shared_ptr<ControllerAPI> controller, ControllerType controller_type,
ProxyCallback proxy_callback);
~ControlScaleProxy() = default;
ControlScaleProxy(const ControlScaleProxy&) = delete;
@@ -45,5 +46,6 @@ namespace asst
std::pair<int, int> m_scale_size = { WindowWidthDefault, WindowHeightDefault };
double m_control_scale = 1.0;
ControllerType m_controller_type = ControllerType::Minitouch;
};
}

View File

@@ -186,7 +186,7 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a
};
try {
m_scale_proxy = std::make_shared<ControlScaleProxy>(m_controller, proxy_callback);
m_scale_proxy = std::make_shared<ControlScaleProxy>(m_controller, m_controller_type, proxy_callback);
}
catch (const std::exception& e) {
Log.error("Cannot create controller proxy: {}", e.what());