mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-17 01:59:33 +08:00
feat: 重新加入 tasks.json 的默认值检查 (#9583)
This commit is contained in:
@@ -232,14 +232,16 @@ bool asst::TaskData::generate_raw_task_info(std::string_view name, std::string_v
|
||||
task->type = type;
|
||||
task->base = base;
|
||||
task->prefix = prefix;
|
||||
utils::get_value_or(name, json, "next", task->next, [&]() { return append_prefix(base_task->next, prefix); });
|
||||
utils::get_value_or(name, json, "sub", task->sub, [&]() { return append_prefix(base_task->sub, prefix); });
|
||||
utils::get_value_or(name, json, "exceededNext", task->exceeded_next,
|
||||
[&]() { return append_prefix(base_task->exceeded_next, prefix); });
|
||||
utils::get_value_or(name, json, "onErrorNext", task->on_error_next,
|
||||
[&]() { return append_prefix(base_task->on_error_next, prefix); });
|
||||
utils::get_value_or(name, json, "reduceOtherTimes", task->reduce_other_times,
|
||||
[&]() { return append_prefix(base_task->reduce_other_times, prefix); });
|
||||
utils::get_and_check_value_or(name, json, "next", task->next,
|
||||
[&]() { return append_prefix(base_task->next, prefix); });
|
||||
utils::get_and_check_value_or(name, json, "sub", task->sub,
|
||||
[&]() { return append_prefix(base_task->sub, prefix); });
|
||||
utils::get_and_check_value_or(name, json, "exceededNext", task->exceeded_next,
|
||||
[&]() { return append_prefix(base_task->exceeded_next, prefix); });
|
||||
utils::get_and_check_value_or(name, json, "onErrorNext", task->on_error_next,
|
||||
[&]() { return append_prefix(base_task->on_error_next, prefix); });
|
||||
utils::get_and_check_value_or(name, json, "reduceOtherTimes", task->reduce_other_times,
|
||||
[&]() { return append_prefix(base_task->reduce_other_times, prefix); });
|
||||
m_task_status[task_name_view(name)] = NotToBeGenerate;
|
||||
|
||||
// 保存虚任务未展开的任务
|
||||
@@ -360,7 +362,7 @@ asst::TaskPtr asst::TaskData::generate_task_info(std::string_view name)
|
||||
|
||||
// 获取 algorithm 并按照 algorithm 生成 TaskInfo
|
||||
AlgorithmType algorithm;
|
||||
utils::get_value_or(name, json, "algorithm", algorithm, base->algorithm);
|
||||
utils::get_and_check_value_or(name, json, "algorithm", algorithm, base->algorithm);
|
||||
TaskPtr task = nullptr;
|
||||
switch (algorithm) {
|
||||
case AlgorithmType::MatchTemplate:
|
||||
@@ -384,7 +386,7 @@ asst::TaskPtr asst::TaskData::generate_task_info(std::string_view name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#define ASST_TASKDATA_GET_VALUE_OR(key, value) utils::get_value_or(name, json, key, task->value, base->value)
|
||||
#define ASST_TASKDATA_GET_VALUE_OR(key, value) utils::get_and_check_value_or(name, json, key, task->value, base->value)
|
||||
#define ASST_TASKDATA_GET_VALUE_OR_LAZY(key, value, m) \
|
||||
utils::get_value_or(name, json, key, task->value, raw->value); \
|
||||
if (auto opt = compile_tasklist(task->value, name, m); !opt) [[unlikely]] { \
|
||||
@@ -435,7 +437,7 @@ asst::TaskPtr asst::TaskData::generate_match_task_info(std::string_view name, co
|
||||
default_ptr = default_match_task_info_ptr;
|
||||
}
|
||||
auto match_task_info_ptr = std::make_shared<MatchTaskInfo>();
|
||||
if (!utils::get_value_or(name, task_json, "template", match_task_info_ptr->templ_names, [&]() {
|
||||
if (!utils::get_and_check_value_or(name, task_json, "template", match_task_info_ptr->templ_names, [&]() {
|
||||
return derived_type == TaskDerivedType::Implicit // 隐式 Template Task 时继承,其它时默认值使用任务名
|
||||
? default_ptr->templ_names
|
||||
: std::vector { std::string(name) + ".png" };
|
||||
@@ -477,7 +479,7 @@ asst::TaskPtr asst::TaskData::generate_match_task_info(std::string_view name, co
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
utils::get_value_or(name, task_json, "maskRange", match_task_info_ptr->mask_range, default_ptr->mask_range);
|
||||
utils::get_and_check_value_or(name, task_json, "maskRange", match_task_info_ptr->mask_range, default_ptr->mask_range);
|
||||
return match_task_info_ptr;
|
||||
}
|
||||
|
||||
@@ -497,11 +499,11 @@ asst::TaskPtr asst::TaskData::generate_ocr_task_info(std::string_view name, cons
|
||||
Log.warn("Ocr task", name, "has implicit empty text.");
|
||||
}
|
||||
#endif
|
||||
utils::get_value_or(name, task_json, "fullMatch", ocr_task_info_ptr->full_match, default_ptr->full_match);
|
||||
utils::get_value_or(name, task_json, "isAscii", ocr_task_info_ptr->is_ascii, default_ptr->is_ascii);
|
||||
utils::get_value_or(name, task_json, "withoutDet", ocr_task_info_ptr->without_det, default_ptr->without_det);
|
||||
utils::get_value_or(name, task_json, "replaceFull", ocr_task_info_ptr->replace_full, default_ptr->replace_full);
|
||||
utils::get_value_or(name, task_json, "ocrReplace", ocr_task_info_ptr->replace_map, default_ptr->replace_map);
|
||||
utils::get_and_check_value_or(name, task_json, "fullMatch", ocr_task_info_ptr->full_match, default_ptr->full_match);
|
||||
utils::get_and_check_value_or(name, task_json, "isAscii", ocr_task_info_ptr->is_ascii, default_ptr->is_ascii);
|
||||
utils::get_and_check_value_or(name, task_json, "withoutDet", ocr_task_info_ptr->without_det, default_ptr->without_det);
|
||||
utils::get_and_check_value_or(name, task_json, "replaceFull", ocr_task_info_ptr->replace_full, default_ptr->replace_full);
|
||||
utils::get_and_check_value_or(name, task_json, "ocrReplace", ocr_task_info_ptr->replace_map, default_ptr->replace_map);
|
||||
return ocr_task_info_ptr;
|
||||
}
|
||||
|
||||
@@ -520,9 +522,9 @@ asst::TaskPtr asst::TaskData::generate_hash_task_info(std::string_view name, con
|
||||
Log.warn("Hash task", name, "has implicit empty hashes.");
|
||||
}
|
||||
#endif
|
||||
utils::get_value_or(name, task_json, "threshold", hash_task_info_ptr->dist_threshold, default_ptr->dist_threshold);
|
||||
utils::get_value_or(name, task_json, "maskRange", hash_task_info_ptr->mask_range, default_ptr->mask_range);
|
||||
utils::get_value_or(name, task_json, "bound", hash_task_info_ptr->bound, default_ptr->bound);
|
||||
utils::get_and_check_value_or(name, task_json, "threshold", hash_task_info_ptr->dist_threshold, default_ptr->dist_threshold);
|
||||
utils::get_and_check_value_or(name, task_json, "maskRange", hash_task_info_ptr->mask_range, default_ptr->mask_range);
|
||||
utils::get_and_check_value_or(name, task_json, "bound", hash_task_info_ptr->bound, default_ptr->bound);
|
||||
return hash_task_info_ptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user