Skip to content

Commit

Permalink
fix: 修复replace字段解析错误,调整文档
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Jun 17, 2024
1 parent f05eeb4 commit 3c97238
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
9 changes: 3 additions & 6 deletions docs/en_us/3.1-PipelineProtocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,6 @@ This task property requires additional fields:
- `replace`: *array<string, 2>* | *list<array<string, 2>>*
Some text recognition results may not be accurate, so replacements are performed. Optional.

> Currently *array<string, 2>* is not available.

- `order_by`: *string*
How the results are sorted. Optional, default is `Horizontal`
Possible values: `Horizontal` | `Vertical` | `Area` | `Length` | `Random`
Expand Down Expand Up @@ -521,11 +519,10 @@ Additional properties for this task:
Presses a key.

- `key`: *int* | *list<int, >*
The key(s) to press, supporting only ASCII keys.
The key(s) to press, supporting only virtual key code of corresponding controller.

> Currently, this property requires not ascii but virtual key code of corresponding controller, and may be related to its InputType.
> [Adb Controller](https://developer.android.com/reference/android/view/KeyEvent)
> [Win Controller](https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes)
- [Adb Controller](https://developer.android.com/reference/android/view/KeyEvent)
- [Win32 Controller](https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes)

### `InputText`

Expand Down
9 changes: 3 additions & 6 deletions docs/zh_cn/3.1-任务流水线协议.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,6 @@ graph LR;
- `replace`: *array<string, 2>* | *list<array<string, 2>>*
部分文字识别结果不准确,进行替换。可选。
> 目前*array<string, 2>*不可用。
- `order_by`: *string*
结果排序方式。可选,默认 `Horizontal`
可选的值:`Horizontal` | `Vertical` | `Area` | `Length` | `Random`
Expand Down Expand Up @@ -528,11 +526,10 @@ graph LR;
按键。
- `key`: *int* | *list<int, >*
要按的键,仅支持 ascii
要按的键,仅支持对应控制器的虚拟按键码
> 目前,该键需要的不是ascii,而是对应控制器的虚拟按键码,且可能和控制器的InputType有关。
> [Adb控制器](https://developer.android.com/reference/android/view/KeyEvent)
> [Win控制器](https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes)
- [Adb 控制器](https://developer.android.com/reference/android/view/KeyEvent)
- [Win32 控制器](https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes)
### `InputText`
Expand Down
36 changes: 16 additions & 20 deletions source/MaaFramework/Resource/PipelineResMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,28 +780,24 @@ bool PipelineResMgr::parse_ocrer_param(
std::ranges::transform(u8_text, std::back_inserter(output.expected), to_u16);

if (auto replace_opt = input.find("replace")) {
if (!replace_opt->is_array()) {
LogError << "replace is not array" << VAR(input);
return false;
auto append_repalce = [&](const json::value& in) {
auto pair = in.as<std::array<std::string, 2>>();
output.replace.emplace_back(to_u16(pair[0]), to_u16(pair[1]));
};

json::value& replace = *replace_opt;

if (replace.is<std::array<std::string, 2>>()) {
append_repalce(replace);
}
auto& replace_array = replace_opt->as_array();
for (const auto& pair : replace_array) {
if (!pair.is_array()) {
LogError << "replace pair is not array" << VAR(input);
return false;
}
auto& pair_array = pair.as_array();
if (pair_array.size() != 2) {
LogError << "replace pair size != 2" << VAR(input);
return false;
else if (replace.is<std::vector<std::array<std::string, 2>>>()) {
for (const json::value& pair : replace.as_array()) {
append_repalce(pair);
}
auto& first = pair_array[0];
auto& second = pair_array[1];
if (!first.is_string() || !second.is_string()) {
LogError << "replace pair is not string" << VAR(input);
return false;
}
output.replace.emplace_back(to_u16(first.as_string()), to_u16(second.as_string()));
}
else {
LogError << "failed to parse replace" << VAR(replace);
return false;
}
}
else {
Expand Down

0 comments on commit 3c97238

Please sign in to comment.