Merge branch 'dev' of github.com:MistEO/MeoAssistantArknights into dev

This commit is contained in:
MistEO
2022-03-08 21:05:12 +08:00
10 changed files with 1014 additions and 514 deletions

1
.gitignore vendored
View File

@@ -432,4 +432,3 @@ screen.png
adb_screen.png
tools/**/*.png
resource/infrast
.vscode

10
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,10 @@
{
"json.schemas": [
{
"fileMatch": [
"resource/tasks.json"
],
"url": "./docs/maa_tasks_schema.json"
}
]
}

View File

@@ -128,6 +128,30 @@ namespace json
value& operator[](const std::string& key);
value& operator[](std::string&& key);
value operator|(const object& rhs)&;
value operator|(object&& rhs)&;
value operator|(const object& rhs)&&;
value operator|(object&& rhs)&&;
value& operator|=(const object& rhs);
value& operator|=(object&& rhs);
//value operator&(const object& rhs)&;
//value operator&(object&& rhs)&;
//value operator&(const object& rhs)&&;
//value operator&(object&& rhs)&&;
//value& operator&=(const object& rhs);
//value& operator&=(object&& rhs);
value operator+(const array& rhs)&;
value operator+(array&& rhs)&;
value operator+(const array& rhs)&&;
value operator+(array&& rhs)&&;
value& operator+=(const array& rhs);
value& operator+=(array&& rhs);
explicit operator bool() const { return as_boolean(); }
explicit operator int() const { return as_integer(); }
explicit operator long() const { return as_long(); }
@@ -141,14 +165,19 @@ namespace json
private:
static var_t deep_copy(const var_t& src);
template <typename... KeysThenDefaultValue, size_t... KeysIndexes>
decltype(auto) get(std::tuple<KeysThenDefaultValue...> keys_then_default_value, std::index_sequence<KeysIndexes...>) const;
decltype(auto) get(
std::tuple<KeysThenDefaultValue...> keys_then_default_value,
std::index_sequence<KeysIndexes...>) const;
template <typename T, typename FirstKey, typename... RestKeys>
decltype(auto) get_aux(T&& default_value, FirstKey&& first, RestKeys &&... rest) const;
template <typename T, typename UniqueKey>
decltype(auto) get_aux(T&& default_value, UniqueKey&& first) const;
const std::string& as_basic_type_str() const;
std::string& as_basic_type_str();
value_type _type = value_type::Null;
var_t _raw_data;
@@ -164,6 +193,7 @@ namespace json
{
public:
using raw_array = std::vector<value>;
using value_type = raw_array::value_type;
using iterator = raw_array::iterator;
using const_iterator = raw_array::const_iterator;
using reverse_iterator = raw_array::reverse_iterator;
@@ -225,6 +255,14 @@ namespace json
const value& operator[](size_t pos) const;
value& operator[](size_t pos);
array operator+(const array& rhs)&;
array operator+(array&& rhs)&;
array operator+(const array& rhs)&&;
array operator+(array&& rhs)&&;
array& operator+=(const array& rhs);
array& operator+=(array&& rhs);
array& operator=(const array&) = default;
array& operator=(array&&) noexcept = default;
@@ -243,13 +281,14 @@ namespace json
{
public:
using raw_object = std::unordered_map<std::string, value>;
using value_type = raw_object::value_type;
using iterator = raw_object::iterator;
using const_iterator = raw_object::const_iterator;
public:
object() = default;
object(const object& rhs) = default;
object(object&& rhs) = default;
object(object&& rhs) noexcept = default;
object(const raw_object& raw_obj);
object(raw_object&& raw_obj);
object(std::initializer_list<raw_object::value_type> init_list);
@@ -283,6 +322,7 @@ namespace json
const value& get(const std::string& key) const;
template <typename... Args> decltype(auto) emplace(Args &&...args);
template <typename... Args> decltype(auto) insert(Args &&...args);
void clear() noexcept;
bool earse(const std::string& key);
@@ -297,6 +337,22 @@ namespace json
value& operator[](const std::string& key);
value& operator[](std::string&& key);
object operator|(const object& rhs)&;
object operator|(object&& rhs)&;
object operator|(const object& rhs)&&;
object operator|(object&& rhs)&&;
object& operator|=(const object& rhs);
object& operator|=(object&& rhs);
//object operator&(const object& rhs)&;
//object operator&(object&& rhs)&;
//object operator&(const object& rhs)&&;
//object operator&(object&& rhs)&&;
//object& operator&=(const object& rhs);
//object& operator&=(object&& rhs);
object& operator=(const object&) = default;
object& operator=(object&&) = default;
@@ -454,20 +510,12 @@ namespace json
MEOJSON_INLINE const value& value::at(size_t pos) const
{
if (is_array()) {
return std::get<array_ptr>(_raw_data)->at(pos);
}
throw exception("Wrong Type or data empty");
return as_array().at(pos);
}
MEOJSON_INLINE const value& value::at(const std::string& key) const
{
if (is_object()) {
return std::get<object_ptr>(_raw_data)->at(key);
}
throw exception("Wrong Type or data empty");
return as_object().at(key);
}
template <typename... KeysThenDefaultValue>
@@ -533,7 +581,7 @@ namespace json
MEOJSON_INLINE bool value::as_boolean() const
{
if (is_boolean()) {
if (std::string b_str = std::get<std::string>(_raw_data);
if (const std::string& b_str = as_basic_type_str();
b_str == "true") {
return true;
}
@@ -552,7 +600,7 @@ namespace json
MEOJSON_INLINE int value::as_integer() const
{
if (is_number()) {
return std::stoi(std::get<std::string>(_raw_data));
return std::stoi(as_basic_type_str());
}
else {
throw exception("Wrong Type");
@@ -574,7 +622,7 @@ namespace json
MEOJSON_INLINE long value::as_long() const
{
if (is_number()) {
return std::stol(std::get<std::string>(_raw_data));
return std::stol(as_basic_type_str());
}
else {
throw exception("Wrong Type");
@@ -584,7 +632,7 @@ namespace json
MEOJSON_INLINE unsigned long value::as_unsigned_long() const
{
if (is_number()) {
return std::stoul(std::get<std::string>(_raw_data));
return std::stoul(as_basic_type_str());
}
else {
throw exception("Wrong Type");
@@ -594,7 +642,7 @@ namespace json
MEOJSON_INLINE long long value::as_long_long() const
{
if (is_number()) {
return std::stoll(std::get<std::string>(_raw_data));
return std::stoll(as_basic_type_str());
}
else {
throw exception("Wrong Type");
@@ -604,7 +652,7 @@ namespace json
MEOJSON_INLINE unsigned long long value::as_unsigned_long_long() const
{
if (is_number()) {
return std::stoull(std::get<std::string>(_raw_data));
return std::stoull(as_basic_type_str());
}
else {
throw exception("Wrong Type");
@@ -614,7 +662,7 @@ namespace json
MEOJSON_INLINE float value::as_float() const
{
if (is_number()) {
return std::stof(std::get<std::string>(_raw_data));
return std::stof(as_basic_type_str());
}
else {
throw exception("Wrong Type");
@@ -624,7 +672,7 @@ namespace json
MEOJSON_INLINE double value::as_double() const
{
if (is_number()) {
return std::stod(std::get<std::string>(_raw_data));
return std::stod(as_basic_type_str());
}
else {
throw exception("Wrong Type");
@@ -634,7 +682,7 @@ namespace json
MEOJSON_INLINE long double value::as_long_double() const
{
if (is_number()) {
return std::stold(std::get<std::string>(_raw_data));
return std::stold(as_basic_type_str());
}
else {
throw exception("Wrong Type");
@@ -644,7 +692,7 @@ namespace json
MEOJSON_INLINE const std::string value::as_string() const
{
if (is_string()) {
return escape_string(std::get<std::string>(_raw_data));
return escape_string(as_basic_type_str());
}
else {
throw exception("Wrong Type");
@@ -671,11 +719,11 @@ namespace json
MEOJSON_INLINE array& value::as_array()
{
if (is_array()) {
return *std::get<array_ptr>(_raw_data);
}
else if (empty()) {
if (empty()) {
*this = array();
}
if (is_array()) {
return *std::get<array_ptr>(_raw_data);
}
@@ -684,17 +732,26 @@ namespace json
MEOJSON_INLINE object& value::as_object()
{
if (is_object()) {
return *std::get<object_ptr>(_raw_data);
}
else if (empty()) {
if (empty()) {
*this = object();
}
if (is_object()) {
return *std::get<object_ptr>(_raw_data);
}
throw exception("Wrong Type or data empty");
}
MEOJSON_INLINE const std::string& value::as_basic_type_str() const
{
return std::get<std::string>(_raw_data);
}
MEOJSON_INLINE std::string& value::as_basic_type_str()
{
return std::get<std::string>(_raw_data);
}
template<typename... Args>
MEOJSON_INLINE decltype(auto) value::array_emplace(Args &&...args)
{
@@ -719,13 +776,13 @@ namespace json
return "null";
case value_type::Boolean:
case value_type::Number:
return std::get<std::string>(_raw_data);
return as_basic_type_str();
case value_type::String:
return '"' + std::get<std::string>(_raw_data) + '"';
return '"' + as_basic_type_str() + '"';
case value_type::Array:
return std::get<array_ptr>(_raw_data)->to_string();
return as_array().to_string();
case value_type::Object:
return std::get<object_ptr>(_raw_data)->to_string();
return as_object().to_string();
default:
throw exception("Unknown Value Type");
}
@@ -739,13 +796,13 @@ namespace json
return "null";
case value_type::Boolean:
case value_type::Number:
return std::get<std::string>(_raw_data);
return as_basic_type_str();
case value_type::String:
return '"' + std::get<std::string>(_raw_data) + '"';
return '"' + as_basic_type_str() + '"';
case value_type::Array:
return std::get<array_ptr>(_raw_data)->format(shift_str, basic_shift_count);
return as_array().format(shift_str, basic_shift_count);
case value_type::Object:
return std::get<object_ptr>(_raw_data)->format(shift_str, basic_shift_count);
return as_object().format(shift_str, basic_shift_count);
default:
throw exception("Unknown Value Type");
}
@@ -763,50 +820,130 @@ namespace json
MEOJSON_INLINE const value& value::operator[](size_t pos) const
{
if (is_array()) {
return std::get<array_ptr>(_raw_data)->operator[](pos);
}
// Array not support to create by operator[]
throw exception("Wrong Type");
return as_array()[pos];
}
MEOJSON_INLINE value& value::operator[](size_t pos)
{
if (is_array()) {
return std::get<array_ptr>(_raw_data)->operator[](pos);
}
// Array not support to create by operator[]
throw exception("Wrong Type");
return as_array()[pos];
}
MEOJSON_INLINE value& value::operator[](const std::string& key)
{
if (is_object()) {
return std::get<object_ptr>(_raw_data)->operator[](key);
}
// Create a new value by operator[]
else if (empty()) {
if (empty()) {
*this = object();
return std::get<object_ptr>(_raw_data)->operator[](key);
}
throw exception("Wrong Type");
return as_object()[key];
}
MEOJSON_INLINE value& value::operator[](std::string&& key)
{
if (is_object()) {
return std::get<object_ptr>(_raw_data)->operator[](key);
}
// Create a new value by operator[]
else if (empty()) {
if (empty()) {
*this = object();
return std::get<object_ptr>(_raw_data)->operator[](key);
}
throw exception("Wrong Type");
return as_object()[std::move(key)];
}
MEOJSON_INLINE value value::operator|(const object& rhs)&
{
return as_object() | rhs;
}
MEOJSON_INLINE value value::operator|(object&& rhs)&
{
return as_object() | std::move(rhs);
}
MEOJSON_INLINE value value::operator|(const object& rhs)&&
{
return std::move(as_object()) | rhs;
}
MEOJSON_INLINE value value::operator|(object&& rhs)&&
{
return std::move(as_object()) | std::move(rhs);
}
MEOJSON_INLINE value& value::operator|=(const object& rhs)
{
as_object() |= rhs;
return *this;
}
MEOJSON_INLINE value& value::operator|=(object&& rhs)
{
as_object() |= std::move(rhs);
return *this;
}
//MEOJSON_INLINE value value::operator&(const object& rhs)&
//{
// return as_object() & rhs;
//}
//MEOJSON_INLINE value value::operator&(object&& rhs)&
//{
// return as_object() & std::move(rhs);
//}
//MEOJSON_INLINE value value::operator&(const object& rhs)&&
//{
// return std::move(as_object()) & rhs;
//}
//MEOJSON_INLINE value value::operator&(object&& rhs)&&
//{
// return std::move(as_object()) & std::move(rhs);
//}
//MEOJSON_INLINE value& value::operator&=(const object& rhs)
//{
// as_object() &= rhs;
// return *this;
//}
//MEOJSON_INLINE value& value::operator&=(object&& rhs)
//{
// as_object() &= std::move(rhs);
// return *this;
//}
MEOJSON_INLINE value value::operator+(const array& rhs)&
{
return as_array() + rhs;
}
MEOJSON_INLINE value value::operator+(array&& rhs)&
{
return as_array() + std::move(rhs);
}
MEOJSON_INLINE value value::operator+(const array& rhs)&&
{
return std::move(as_array()) + rhs;
}
MEOJSON_INLINE value value::operator+(array&& rhs)&&
{
return std::move(as_array()) + std::move(rhs);
}
MEOJSON_INLINE value& value::operator+=(const array& rhs)
{
as_array() += rhs;
return *this;
}
MEOJSON_INLINE value& value::operator+=(array&& rhs)
{
as_array() += std::move(rhs);
return *this;
}
template <typename... Args>
@@ -1195,6 +1332,50 @@ namespace json
return _array_data[pos];
}
MEOJSON_INLINE array array::operator+(const array& rhs)&
{
array temp = *this;
temp._array_data.insert(_array_data.end(), rhs.begin(), rhs.end());
return temp;
}
MEOJSON_INLINE array array::operator+(array&& rhs)&
{
array temp = *this;
temp._array_data.insert(_array_data.end(),
std::make_move_iterator(rhs.begin()),
std::make_move_iterator(rhs.end()));
return temp;
}
MEOJSON_INLINE array array::operator+(const array& rhs)&&
{
_array_data.insert(_array_data.end(), rhs.begin(), rhs.end());
return std::move(*this);
}
MEOJSON_INLINE array array::operator+(array&& rhs)&&
{
_array_data.insert(_array_data.end(),
std::make_move_iterator(rhs.begin()),
std::make_move_iterator(rhs.end()));
return std::move(*this);
}
MEOJSON_INLINE array& array::operator+=(const array& rhs)
{
_array_data.insert(_array_data.end(), rhs.begin(), rhs.end());
return *this;
}
MEOJSON_INLINE array& array::operator+=(array&& rhs)
{
_array_data.insert(_array_data.end(),
std::make_move_iterator(rhs.begin()),
std::make_move_iterator(rhs.end()));
return *this;
}
// const raw_array &array::raw_data() const
// {
// return _array_data;
@@ -1211,6 +1392,11 @@ namespace json
return _object_data.emplace(std::forward<Args>(args)...);
}
template <typename... Args> decltype(auto) object::insert(Args &&...args)
{
return _object_data.insert(std::forward<Args>(args)...);
}
MEOJSON_INLINE std::ostream& operator<<(std::ostream& out, const array& arr)
{
// TODO: format output
@@ -1528,6 +1714,108 @@ namespace json
return _object_data[std::move(key)];
}
MEOJSON_INLINE object object::operator|(const object& rhs)&
{
object temp = *this;
temp._object_data.insert(rhs.begin(), rhs.end());
return temp;
}
MEOJSON_INLINE object object::operator|(object&& rhs)&
{
object temp = *this;
//temp._object_data.merge(std::move(rhs._object_data));
temp._object_data.insert(
std::make_move_iterator(rhs.begin()),
std::make_move_iterator(rhs.end()));
return temp;
}
MEOJSON_INLINE object object::operator|(const object& rhs)&&
{
_object_data.insert(rhs.begin(), rhs.end());
return std::move(*this);
}
MEOJSON_INLINE object object::operator|(object&& rhs)&&
{
//_object_data.merge(std::move(rhs._object_data));
_object_data.insert(
std::make_move_iterator(rhs.begin()),
std::make_move_iterator(rhs.end()));
return std::move(*this);
}
MEOJSON_INLINE object& object::operator|=(const object& rhs)
{
_object_data.insert(rhs.begin(), rhs.end());
return *this;
}
MEOJSON_INLINE object& object::operator|=(object&& rhs)
{
_object_data.insert(
std::make_move_iterator(rhs.begin()),
std::make_move_iterator(rhs.end()));
return *this;
}
//MEOJSON_INLINE object object::operator&(const object& rhs)&
//{
// object temp;
// for (const auto& [key, value] : *this) {
// if (rhs.contains(key)) {
// temp.emplace(key, value);
// }
// }
// return temp;
//}
//MEOJSON_INLINE object object::operator&(object&& rhs)&
//{
// object temp;
// for (const auto& [key, value] : *this) {
// if (rhs.contains(key)) {
// temp.emplace(key, value);
// }
// }
// return temp;
//}
//MEOJSON_INLINE object object::operator&(const object& rhs)&&
//{
// object temp;
// for (auto&& [key, value] : *this) {
// if (rhs.contains(key)) {
// temp.emplace(key, std::move(value));
// }
// }
// return temp;
//}
//MEOJSON_INLINE object object::operator&(object&& rhs)&&
//{
// object temp;
// for (auto&& [key, value] : *this) {
// if (rhs.contains(key)) {
// temp.emplace(key, std::move(value));
// }
// }
// return temp;
//}
//MEOJSON_INLINE object& object::operator&=(const object& rhs)
//{
// *this = std::move(*this) & rhs;
// return *this;
//}
//MEOJSON_INLINE object& object::operator&=(object&& rhs)
//{
// *this = std::move(*this) & std::move(rhs);
// return *this;
//}
// const raw_object &object::raw_data() const
// {
// return _object_data;

212
docs/maa_tasks_schema.json Normal file
View File

@@ -0,0 +1,212 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "maa task config",
"patternProperties": {
"^(?!\\$)": {
"type": "object",
"oneOf": [
{
"$ref": "#/definitions/JustReturnTask"
},
{
"$ref": "#/definitions/MatchTemplateTask"
},
{
"$ref": "#/definitions/OcrDetectTask"
},
{
"$ref": "#/definitions/HashTask"
}
]
}
},
"definitions": {
"Rectangle": {
"type": "array",
"maxItems": 4,
"minItems": 4,
"items": {
"type": "number"
}
},
"TaskNameList": {
"type": "array",
"items": {
"type": "string",
"description": "要执行的任务"
}
},
"BaseTask": {
"properties": {
"algorithm": {
"type": "string",
"description": "算法类型"
},
"action": {
"type": "string",
"pattern": "ClickSelf|ClickRand|DoNothing|Stop|ClickRect|SwipeToTheLeft|SwipeToTheRight",
"default": "DoNothing",
"description": "可选项,表示识别到后的动作\n不填写时默认为 DoNothing"
},
"next": {
"$ref": "#/definitions/TaskNameList",
"description": "可选项,表示执行完当前任务后,下一个要执行的任务\n会从前往后依次去识别去执行第一个匹配上的\n不填写默认执行完当前任务直接停止"
},
"maxTimes": {
"type": "number",
"description": "可选项,表示该任务最大执行次数\n不填写时默认无穷大\n达到最大次数后若存在 exceededNext 字段,则执行 exceededNext否则直接任务停止"
},
"exceededNext": {
"$ref": "#/definitions/TaskNameList",
"description": "可选项,表示达到了最大执行次数后要执行的任务\n不填写时达到了最大执行次数则停止填写后就执行这里的而不是 next 里的"
},
"preDelay": {
"type": "number",
"description": "可选项,表示识别到后延迟多久才执行 action单位毫秒不填写时默认 0"
},
"rearDelay": {
"type": "number",
"description": "可选项,表示 action 执行完后延迟多久才去识别 next, 单位毫秒;不填写时默认 0"
},
"roi": {
"$ref": "#/definitions/Rectangle",
"description": "可选项,表示识别的范围,格式为 [ x, y, width, height ]\n以 1280 * 720 为基准自动缩放;不填写时默认 [ 0, 0, 1280, 720 ]\n尽量填写减小识别范围可以减少性能消耗加快识别速度"
},
"cache": {
"type": "boolean",
"default": true,
"description": "可选项,表示该任务是否使用缓存,默认为 true;\n第一次识别到后以后永远只在第一次识别到的位置进行识别开启可大幅节省性能\n但仅适用于待识别目标位置完全不会变的任务若待识别目标位置会变请设为 false"
},
"rectMove": {
"$ref": "#/definitions/Rectangle",
"description": "可选项,识别后的目标移动,不建议使用该选项。以 1280 * 720 为基准自动缩放\n例如识别到了 A 图标,但实际要点击的是 A 图标旁边的某个位置,则进行移动后再点击。可以的话尽量直接识别要点击的位置,不建议使用该选项"
},
"reduceOtherTimes": {
"type": "array",
"items": {
"type": "string",
"description": "要执行的任务"
},
"description": "可选项,执行后减少其他任务的执行计数。\n可选项执行后减少其他任务的执行计数。"
},
"specificRect": {
"$ref": "#/definitions/Rectangle",
"description": "仅当 action 为 ClickRect 时有效且必选,表示指定的点击位置(范围内随机一点)。以 1280 * 720 为基准自动缩放"
}
}
},
"JustReturnTask": {
"allOf": [
{
"$ref": "#/definitions/BaseTask"
}
],
"properties": {
"algorithm": {
"type": "string",
"pattern": "JustReturn"
}
},
"description": "不进行识别,直接执行 action",
"required": [
"algorithm"
]
},
"MatchTemplateTask": {
"allOf": [
{
"$ref": "#/definitions/BaseTask"
}
],
"properties": {
"algorithm": {
"type": "string",
"pattern": "MatchTemplate"
},
"template": {
"type": "string",
"default": "",
"description": "可选项,要匹配的图片文件名\n不填时写默认 \"任务名.png\""
},
"templThreshold": {
"type": "number",
"default": 0.8,
"description": "可选项,图片模板匹配得分的阈值,超过阈值才认为识别到了。\n默认 0.8, 可根据日志查看实际得分是多少"
},
"maskRange": {
"type": "array",
"maxItems": 2,
"minimum": 2,
"items": {
"type": "number"
},
"default": [
1,
255
],
"description": "可选项,灰度掩码范围。例如将图片不需要识别的部分涂成黑色(灰度值为 0然后设置 [ 1, 255 ], 匹配的时候即刻忽略涂黑的部分"
}
},
"description": "匹配图片"
},
"OcrDetectTask": {
"allOf": [
{
"$ref": "#/definitions/BaseTask"
}
],
"properties": {
"algorithm": {
"type": "string",
"pattern": "OcrDetect"
},
"text": {
"type": "array",
"items": {
"type": "string"
},
"description": "必选项,要识别的文字内容,只要任一匹配上了即认为识别到了"
},
"fullMatch": {
"type": "boolean",
"default": false,
"description": "可选项,文字识别是否需要全字匹配(不能多字),默认为 false\nfalse 时只要是子串即可:例如 text: [ \"开始\" ],实际识别到了 \"开始行动\",也算识别成功;\ntrue 时则必须识别到了 \"开始\",多一个字都不行"
},
"ocrReplace": {
"type": "array",
"items": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": {
"type": "string"
}
},
"description": "可选项,针对常见识别错的文字进行替换(支持正则)"
}
},
"description": "文字识别",
"required": [
"algorithm",
"text"
]
},
"HashTask": {
"allOf": [
{
"$ref": "#/definitions/BaseTask"
}
],
"properties": {
"algorithm": {
"type": "string",
"pattern": "Hash"
}
},
"description": "哈希计算",
"required": [
"algorithm"
]
}
}
}

View File

@@ -132,3 +132,15 @@
}
}
```
## Schema 检验
本项目为 `tasks.json` 配置了 json schema 检验schema 文件为`docs/maa_tasks_schema.json`
### Visual Studio
`MeoAssistant.vcxporj` 中已对其进行配置,开箱即用。提示效果较为晦涩,且有部分信息缺失。
### Visual Studio Code
`.vscode/settings.json` 中已对其进行配置,用 vscode 打开该**项目文件夹**即可使用。提示效果较好。

View File

@@ -63,8 +63,7 @@ Todo
"details": {
"adb": string, // AsstConnect 接口 adb_path 参数
"address": string, // AsstConnect 接口 address 参数
"config": string, // AsstConnect 接口 config 参数
"uuid": string // 设备唯一码(连接失败时为空)
"config": string // AsstConnect 接口 config 参数
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -354,6 +354,16 @@ void asst::Controller::random_delay() const
Log.trace("random_delay |", rand_delay, "ms");
std::this_thread::sleep_for(std::chrono::milliseconds(rand_delay));
}
}
void asst::Controller::clear_info() noexcept
{
m_adb = decltype(m_adb)();
m_uuid.clear();
m_width = 0;
m_height = 0;
m_control_scale = 1.0;
m_scale_size = decltype(m_scale_size)();
}
int asst::Controller::push_cmd(const std::string & cmd)
@@ -613,13 +623,25 @@ bool asst::Controller::connect(const std::string & adb_path, const std::string &
{
LogTraceFunction;
clear_info();
auto get_info_json = [&]() -> json::value {
return json::object{
{ "uuid", m_uuid},
{ "details", json::object {
{ "adb", adb_path },
{ "address", address },
{ "config", config }
}}
};
};
auto adb_ret = Resrc.cfg().get_adb_cfg(config);
if (!adb_ret) {
json::value info = json::object{
{ "what", "ConnectFailed" },
{ "why", "ConfigNotFound" },
{ "details", json::object{} }
};
json::value info = get_info_json() |
json::object{
{ "what", "ConnectFailed" },
{ "why", "ConfigNotFound" }};
m_callback(AsstMsg::ConnectionInfo, info, m_callback_arg);
return false;
}
@@ -645,16 +667,10 @@ bool asst::Controller::connect(const std::string & adb_path, const std::string &
auto connect_ret = call_command(cmd_replace(adb_cfg.connect));
// 端口即使错误命令仍然会返回0TODO 对connect_result进行判断
if (!connect_ret) {
json::value info = json::object{
{ "what", "ConnectFailed" },
{ "why", "Connection command failed to exec" },
{ "uuid", ""},
{ "details", json::object {
{ "adb", adb_path },
{ "address", address },
{ "config", config },
{ "uuid", "" }
}}
json::value info = get_info_json() |
json::object{
{ "what", "ConnectFailed" },
{ "why", "Connection command failed to exec" }
};
m_callback(AsstMsg::ConnectionInfo, info, m_callback_arg);
return false;
@@ -665,16 +681,11 @@ bool asst::Controller::connect(const std::string & adb_path, const std::string &
{
auto uuid_ret = call_command(cmd_replace(adb_cfg.uuid));
if (!uuid_ret) {
json::value info = json::object{
{ "what", "ConnectFailed" },
{ "why", "Uuid command failed to exec" },
{ "uuid", "" },
{ "details", json::object {
{ "adb", adb_path },
{ "address", address },
{ "config", config }
}}
};
json::value info = get_info_json() |
json::object{
{ "what", "ConnectFailed" },
{ "why", "Uuid command failed to exec" }
};
m_callback(AsstMsg::ConnectionInfo, info, m_callback_arg);
return false;
}
@@ -686,17 +697,12 @@ bool asst::Controller::connect(const std::string & adb_path, const std::string &
uuid_str.erase(std::remove(uuid_str.begin(), uuid_str.end(), ' '), uuid_str.end());
m_uuid = std::move(uuid_str);
json::value info = json::object{
{ "what", "UuidGetted" },
{ "why", "" },
{ "uuid", m_uuid },
{ "details", json::object {
{ "uuid", m_uuid },
{ "adb", adb_path },
{ "address", address },
{ "config", config }
}}
};
json::value info = get_info_json() |
json::object{
{ "what", "UuidGetted" },
{ "why", "" }
};
info["details"]["uuid"] = m_uuid;
m_callback(AsstMsg::ConnectionInfo, info, m_callback_arg);
}
@@ -726,16 +732,11 @@ bool asst::Controller::connect(const std::string & adb_path, const std::string &
{
auto display_ret = call_command(cmd_replace(adb_cfg.display));
if (!display_ret) {
json::value info = json::object{
{ "what", "ConnectFailed" },
{ "why", "Display command failed to exec" },
{ "uuid", m_uuid },
{ "details", json::object {
{ "adb", adb_path },
{ "address", address },
{ "config", config }
}}
};
json::value info = get_info_json() |
json::object{
{ "what", "ConnectFailed" },
{ "why", "Display command failed to exec" }
};
m_callback(AsstMsg::ConnectionInfo, info, m_callback_arg);
return false;
}
@@ -756,18 +757,17 @@ bool asst::Controller::connect(const std::string & adb_path, const std::string &
m_width = (std::max)(size_value1, size_value2);
m_height = (std::min)(size_value1, size_value2);
json::value info = json::object{
json::value info = get_info_json() |
json::object{
{ "what", "ResolutionGetted" },
{ "why", "" },
{ "uuid", m_uuid },
{ "details", json::object {
{ "adb", adb_path },
{ "address", address },
{ "config", config },
{ "why", "" }
};
info["details"] |= json::object {
{ "width", m_width },
{ "height", m_height }
}}
};
};
m_callback(AsstMsg::ConnectionInfo, info, m_callback_arg);
}
@@ -791,16 +791,11 @@ bool asst::Controller::connect(const std::string & adb_path, const std::string &
}
{
json::value info = json::object{
{ "what", "Connected" },
{ "why", "" },
{ "uuid", m_uuid },
{ "details", json::object {
{ "adb", adb_path },
{ "address", address },
{ "config", config }
}}
};
json::value info = get_info_json() |
json::object{
{ "what", "Connected" },
{ "why", "" }
};
m_callback(AsstMsg::ConnectionInfo, info, m_callback_arg);
}

View File

@@ -70,6 +70,7 @@ namespace asst
Point rand_point_in_rect(const Rect& rect);
void random_delay() const;
void clear_info() noexcept;
// 转换data中所有的crlf为lf有些模拟器自带的adbexec-out输出的\n会被替换成\r\n导致解码错误所以这里转一下回来点名批评mumu
static void convert_lf(std::vector<unsigned char>& data);

View File

@@ -271,7 +271,7 @@ xcopy /e /y /i /c $(SolutionDir)3rdparty\resource $(TargetDir)resource</Command>
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties _1_1_4_1_1_4resource_4config_1json__JsonSchema="" />
<UserProperties _1_1_4_1_1_4resource_4config_1json__JsonSchema="" _1_1_4_1_1_4resource_4tasks_1json__JsonSchema="../docs/maa_tasks_schema.json" />
</VisualStudio>
</ProjectExtensions>
</Project>