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

@@ -14,6 +14,8 @@
"adbExtraSwipeDuration_Doc": "额外的滑动持续时间adb有bug同样的参数偶尔会划得非常远。额外做一个短程滑动把之前的停下来。若小于0则关闭额外滑动功能",
"adbSwipeDurationMultiplier": 10.0,
"adbSwipeDurationMultiplier_Doc": "adb 滑动延迟倍数",
"adbSwipeXDistanceMultiplier": 0.8,
"adbSwipeXDistanceMultiplier_Doc": "adb 滑动 X 距离倍数",
"minitouchSwipeDefaultDuration": 200,
"minitouchSwipeExtraEndDelay": 150,
"minitouchExtraSwipeDist": 100,
@@ -146,4 +148,4 @@
"screencapEncode": "[Adb] -s [AdbSerial] exec-out \"screencap -p 2>/tmp/maa-assistant-arknights.log\""
}
]
}
}

View File

@@ -18,6 +18,7 @@ bool asst::GeneralConfig::parse(const json::value& json)
m_options.adb_extra_swipe_dist = options_json.get("adbExtraSwipeDist", 100);
m_options.adb_extra_swipe_duration = options_json.get("adbExtraSwipeDuration", -1);
m_options.adb_swipe_duration_multiplier = options_json.get("adbSwipeDurationMultiplier", 10.0);
m_options.adb_swipe_x_distance_multiplier = options_json.get("adbSwipeXDistanceMultiplier", 10.0);
m_options.minitouch_extra_swipe_dist = options_json.get("minitouchExtraSwipeDist", 100);
m_options.minitouch_extra_swipe_duration = options_json.get("minitouchExtraSwipeDuration", -1);
m_options.minitouch_swipe_default_duration = options_json.get("minitouchSwipeDefaultDuration", 200);

View File

@@ -36,7 +36,8 @@ namespace asst
// adb有bug同样的参数偶尔会划得非常远。
// 额外做一个短程滑动,把之前的停下来。
// 若小于0则关闭额外滑动功能。
double adb_swipe_duration_multiplier = 0; // adb 滑动持续时间倍数
double adb_swipe_duration_multiplier = 0; // adb 滑动持续时间倍数
double adb_swipe_x_distance_multiplier = 0; // adb 滑动距离倍数
int minitouch_extra_swipe_dist = 0;
int minitouch_extra_swipe_duration = -1;
int minitouch_swipe_default_duration = 0;

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());

View File

@@ -282,9 +282,9 @@ bool asst::BattleHelper::deploy_oper(const std::string& name, const Point& loc,
}
bool deploy_with_pause =
ControlFeat::support(m_inst_helper.ctrler()->support_features(), ControlFeat::SWIPE_WITH_PAUSE);
m_inst_helper.ctrler()->swipe(oper_rect, Rect(target_point.x, target_point.y, 1, 1), duration, false,
swipe_oper_task_ptr->special_params.at(1), swipe_oper_task_ptr->special_params.at(2),
deploy_with_pause);
m_inst_helper.ctrler()->swipe(Point(oper_rect.x, oper_rect.y), Point(target_point.x, target_point.y), duration,
false, swipe_oper_task_ptr->special_params.at(1),
swipe_oper_task_ptr->special_params.at(2), deploy_with_pause);
// 拖动干员朝向
if (direction != DeployDirection::None) {