mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 02:23:01 +08:00
chore.更新集成文档,修改setparam部分接口实现
This commit is contained in:
@@ -122,7 +122,8 @@ A Game Assistant for Arknights
|
||||
|
||||
- [C 接口](https://github.com/MistEO/MeoAssistantArknights/blob/dev/include/AsstCaller.h)
|
||||
- [Python 接口](https://github.com/MistEO/MeoAssistantArknights/wiki/Python-%E6%8E%A5%E5%8F%A3)
|
||||
- [Golang 接口](https://github.com/MistEO/MeoAssistantArknights/wiki/Golang-%E6%8E%A5%E5%8F%A3)
|
||||
- [Golang 接口](https://github.com/MistEO/MeoAssistantArknights/wiki/Golang-%E6%8E%A5%E5%8F%A3) 已停止维护 orz
|
||||
- [集成文档](docs/集成文档.md) 龟速更新中_(:з」∠)_
|
||||
- [回调消息协议](docs/回调消息协议.md)
|
||||
|
||||
## 声明
|
||||
|
||||
34
docs/集成文档.md
Normal file
34
docs/集成文档.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# 集成文档
|
||||
|
||||
## 接口介绍
|
||||
|
||||
### AsstSetParam
|
||||
|
||||
#### 接口原型
|
||||
|
||||
```c++
|
||||
bool ASSTAPI AsstSetParam(AsstHandle handle, const char* param_id, const char* param_value);
|
||||
```
|
||||
|
||||
#### 接口说明
|
||||
|
||||
设置实例级参数
|
||||
|
||||
#### 返回值
|
||||
|
||||
- bool
|
||||
返回是否设置成功
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- AsstHandle handle
|
||||
实例句柄
|
||||
- const char* param_id
|
||||
参数 id
|
||||
- const char* param_value
|
||||
参数值,json string
|
||||
|
||||
| 参数作用 | 参数 id | 参数值 | 参数示例 |
|
||||
| ------- | ------- | ----- | -------- |
|
||||
| 设置企鹅数据 id | penguin_id | { "id" : string } | { "id" : "1234567" } |
|
||||
| 设置 OCR 任务要识别的文字 | ocr_text | { TaskName: [ string, ...]} | { "Roguelike1ChooseOper" : [ "帕拉斯", "银灰" ] } |
|
||||
@@ -424,7 +424,7 @@ bool asst::Assistant::set_param(const std::string& param_id, const std::string&
|
||||
{
|
||||
Log.info(__FUNCTION__, param_id, param_value);
|
||||
|
||||
using SetParamFuncType = std::function<bool(const std::string&)>;
|
||||
using SetParamFuncType = std::function<bool(const json::value&)>;
|
||||
|
||||
static const std::unordered_map<std::string, SetParamFuncType> ParamsMapping = {
|
||||
{AsstParamIdPenguinId, std::bind(&Assistant::set_penguid_id, this, std::placeholders::_1)},
|
||||
@@ -433,7 +433,13 @@ bool asst::Assistant::set_param(const std::string& param_id, const std::string&
|
||||
|
||||
if (const auto iter = ParamsMapping.find(param_id);
|
||||
iter != ParamsMapping.cend()) {
|
||||
return iter->second(param_value);
|
||||
const auto json_opt = json::parse(param_value);
|
||||
if (!json_opt) {
|
||||
return false;
|
||||
}
|
||||
const auto& root = json_opt.value();
|
||||
|
||||
return iter->second(root);
|
||||
}
|
||||
else {
|
||||
Log.error("Invaild Param Id", param_id);
|
||||
@@ -595,26 +601,25 @@ void Assistant::clear_cache()
|
||||
//Task.clear_cache();
|
||||
}
|
||||
|
||||
bool asst::Assistant::set_penguid_id(const std::string& param_value)
|
||||
bool asst::Assistant::set_penguid_id(const json::value& root)
|
||||
{
|
||||
if (!(root.is_object() && root.contains("id") && root.at("id").is_string())) {
|
||||
return false;
|
||||
}
|
||||
auto& opt = Resrc.cfg().get_options();
|
||||
if (param_value.empty()) {
|
||||
std::string id = root.at("id").as_string();
|
||||
if (id.empty()) {
|
||||
opt.penguin_report.extra_param.clear();
|
||||
}
|
||||
else {
|
||||
opt.penguin_report.extra_param = "-H \"authorization: PenguinID " + param_value + "\"";
|
||||
opt.penguin_report.extra_param = "-H \"authorization: PenguinID " + id + "\"";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool asst::Assistant::set_ocr_text(const std::string& param_value)
|
||||
bool asst::Assistant::set_ocr_text(const json::value& root)
|
||||
{
|
||||
const auto json_opt = json::parse(param_value);
|
||||
if (!json_opt) {
|
||||
return false;
|
||||
}
|
||||
const auto& root = json_opt.value();
|
||||
|
||||
bool ret = true;
|
||||
for (auto&& [key, text] : root.as_object()) {
|
||||
if (!text.is_array()) {
|
||||
return false;
|
||||
@@ -626,8 +631,8 @@ bool asst::Assistant::set_ocr_text(const std::string& param_value)
|
||||
}
|
||||
text_vec.emplace_back(text.as_string());
|
||||
}
|
||||
m_task_data->set_ocr_text(key, std::move(text_vec));
|
||||
ret &= m_task_data->set_ocr_text(key, std::move(text_vec));
|
||||
}
|
||||
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -97,8 +97,8 @@ namespace asst
|
||||
void clear_cache();
|
||||
|
||||
/* set params */
|
||||
bool set_penguid_id(const std::string& param_value);
|
||||
bool set_ocr_text(const std::string& param_value);
|
||||
bool set_penguid_id(const json::value& root);
|
||||
bool set_ocr_text(const json::value& root);
|
||||
|
||||
bool m_inited = false;
|
||||
std::string m_uuid;
|
||||
|
||||
Reference in New Issue
Block a user