underlying codes implement

This commit is contained in:
lhhxxxxx
2022-06-04 23:15:03 +08:00
parent d0049ddd1f
commit 6e9c1914c2
6 changed files with 49 additions and 1 deletions

View File

@@ -18,6 +18,10 @@
"cmdFormat_Doc": "命令格式,想打印详细信息可以尝试添加 -v -i"
}
},
"intent": {
"Official": "com.hypergryph.arknights/com.u8.sdk.U8UnityContext",
"Bilibili": "com.hypergryph.arknights.bilibili/com.u8.sdk.U8UnityContext"
},
"connection": {
"General": {
"devices": "[Adb] devices",

View File

@@ -158,6 +158,12 @@ namespace asst
double score = 0.0;
Rect rect;
};
enum class ServerType
{
Official,
Bilibili
};
}
namespace std

View File

@@ -522,6 +522,21 @@ cv::Mat asst::Controller::get_resized_image() const
return resized_mat;
}
int asst::Controller::start_game(const ServerType& server_type, bool block)
{
if (auto intent_name = Resrc.cfg().get_intent_name(server_type))
{
std::string cur_cmd = utils::string_replace_all(m_adb.start, "[Intent]", intent_name.value());
int id = push_cmd(cur_cmd);
if (block)
{
wait(id);
}
return id;
}
return -1;
}
int asst::Controller::click(const Point& p, bool block)
{
int x = static_cast<int>(p.x * m_control_scale);
@@ -828,6 +843,7 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a
m_adb.screencap_raw_with_gzip = cmd_replace(adb_cfg.screencap_raw_with_gzip);
m_adb.screencap_encode = cmd_replace(adb_cfg.screencap_encode);
m_adb.release = cmd_replace(adb_cfg.release);
m_adb.start = cmd_replace(adb_cfg.start);
return true;
}

View File

@@ -37,7 +37,9 @@ namespace asst
cv::Mat get_image(bool raw = false);
std::vector<uchar> get_image_encode() const;
// 点击和滑动都是异步执行返回该任务的id
// 开启/置顶游戏、点击和滑动都是异步执行返回该任务的id
int start_game(const ServerType& server_type = asst::ServerType::Official, bool block = true);
int click(const Point& p, bool block = true);
int click(const Rect& rect, bool block = true);
int click_without_scale(const Point& p, bool block = true);
@@ -108,6 +110,8 @@ namespace asst
std::string screencap_encode;
std::string release;
std::string start;
/* propertities */
enum class ScreencapEndOfLine
{

View File

@@ -28,6 +28,11 @@ bool asst::GeneralConfiger::parse(const json::value& json)
m_options.aip_ocr.client_id = aip_ocr.get("clientId", std::string());
m_options.aip_ocr.client_secret = aip_ocr.get("clientSerect", std::string());
}
const json::value& intent_json = json.at("intent");
m_intent_name[asst::ServerType::Official] = intent_json.at("Official").as_string();
m_intent_name[asst::ServerType::Bilibili] = intent_json.at("Bilibili").as_string();
}
for (const auto& [name, cfg_json] : json.at("connection").as_object()) {
@@ -45,6 +50,7 @@ bool asst::GeneralConfiger::parse(const json::value& json)
adb.screencap_raw_with_gzip = cfg_json.at("screencapRawWithGzip").as_string();
adb.screencap_encode = cfg_json.at("screencapEncode").as_string();
adb.release = cfg_json.at("release").as_string();
adb.start = cfg_json.at("start").as_string();
//adb.pullscreen = cfg_json.at("pullscreen").as_string();
m_adb_cfg[name] = std::move(adb);

View File

@@ -53,6 +53,7 @@ namespace asst
std::string screencap_raw_with_gzip;
std::string screencap_encode;
std::string release;
std::string start;
};
class GeneralConfiger : public AbstractConfiger
@@ -83,6 +84,16 @@ namespace asst
}
}
[[nodiscard]] std::optional<std::string> get_intent_name(const asst::ServerType& server_type) const
{
if (auto iter = m_intent_name.find(server_type);
iter != m_intent_name.cend())
{
return iter->second;
}
return std::nullopt;
}
void set_options(Options opt) noexcept
{
m_options = std::move(opt);
@@ -94,5 +105,6 @@ namespace asst
std::string m_version;
Options m_options;
std::unordered_map<std::string, AdbCfg> m_adb_cfg;
std::unordered_map<asst::ServerType, std::string> m_intent_name;
};
}