chore.初步完成cmake,修改一些头文件路径

This commit is contained in:
MistEO
2021-12-11 22:10:09 +08:00
parent af1a4cc5c9
commit d48d7c94d9
18 changed files with 446 additions and 421 deletions

1
.gitignore vendored
View File

@@ -2,6 +2,7 @@
*.d
# Compiled Object files
build
*.slo
*.lo
*.o

24
CMakeLists.txt Normal file
View File

@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 2.8)
project(MeoAsst)
include_directories(include 3rdparty/include)
aux_source_directory(src/MeoAssistance SRC)
add_definitions(-DMEO_DLL_EXPORTS)
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/MP>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/MP>")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_CXX_STANDARD 17)
add_library(MeoAsst_LIB SHARED ${SRC})
find_library(Opencv_LIB NAMES opencv_world453 PATHS 3rdparty/lib)
find_library(OcrLite_LIB NAMES OcrLiteOnnx PATHS 3rdparty/lib)
find_library(Penguin_LIB NAMES penguin-stats-recognize PATHS 3rdparty/lib)
find_library(MeoJson_LIB NAMES libmeojson PATHS 3rdparty/lib)
target_link_libraries(MeoAsst_LIB ${Opencv_LIB} ${OcrLite_LIB} ${Penguin_LIB} ${MeoJson_LIB})

View File

@@ -1,6 +1,6 @@
#include "AbstractConfiger.h"
#include <json.h>
#include <meojson/json.h>
#include "AsstUtils.hpp"

View File

@@ -3,7 +3,7 @@
#include <filesystem>
#include <time.h>
#include <json.h>
#include <meojson/json.h>
#include <opencv2/opencv.hpp>
#include "AsstUtils.hpp"

View File

@@ -1,252 +1,252 @@
#include "AsstCaller.h"
#include <string.h>
#include <json_value.h>
#include "Assistance.h"
#include "AsstDef.h"
#include "AsstUtils.hpp"
#include "AsstCaller.h"
#include <string.h>
#include <meojson/json_value.h>
#include "Assistance.h"
#include "AsstDef.h"
#include "AsstUtils.hpp"
#include "Version.h"
#if 0
#if _MSC_VER
// Win32平台下Dll的入口
BOOL APIENTRY DllMain(HINSTANCE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
UNREFERENCED_PARAMETER(hModule);
UNREFERENCED_PARAMETER(lpReserved);
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#elif VA_GNUC
#endif
#endif
AsstCallback _callback = nullptr;
void CallbackTrans(asst::AsstMsg msg, const json::value& json, void* custom_arg)
{
_callback(static_cast<int>(msg), asst::utils::utf8_to_gbk(json.to_string()).c_str(), custom_arg);
}
void* AsstCreate(const char* dirname)
{
try {
return new asst::Assistance(dirname);
}
catch (...) {
return nullptr;
}
}
void* AsstCreateEx(const char* dirname, AsstCallback callback, void* custom_arg)
{
try {
// 创建多实例回调会有问题,有空再慢慢整
_callback = callback;
return new asst::Assistance(dirname, CallbackTrans, custom_arg);
}
catch (...) {
return nullptr;
}
}
void AsstDestroy(void* p_asst)
{
if (p_asst == nullptr) {
return;
}
delete p_asst;
p_asst = nullptr;
}
bool AsstCatchDefault(void* p_asst)
{
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->catch_default();
}
bool AsstCatchEmulator(void* p_asst)
{
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->catch_emulator();
}
bool AsstCatchCustom(void* p_asst, const char* address)
{
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->catch_custom(address);
}
bool AsstCatchFake(void* p_asst)
{
#ifdef LOG_TRACE
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->catch_fake();
#else
return false;
#endif // LOG_TRACE
}
bool AsstAppendFight(void* p_asst, int max_mecidine, int max_stone, int max_times)
{
if (p_asst == nullptr) {
return false;
#if 0
#if _MSC_VER
// Win32平台下Dll的入口
BOOL APIENTRY DllMain(HINSTANCE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
UNREFERENCED_PARAMETER(hModule);
UNREFERENCED_PARAMETER(lpReserved);
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
asst::Assistance* ptr = (asst::Assistance*)p_asst;
return ptr->append_fight(max_mecidine, max_stone, max_times);
return TRUE;
}
#elif VA_GNUC
#endif
#endif
AsstCallback _callback = nullptr;
void CallbackTrans(asst::AsstMsg msg, const json::value& json, void* custom_arg)
{
_callback(static_cast<int>(msg), asst::utils::utf8_to_gbk(json.to_string()).c_str(), custom_arg);
}
void* AsstCreate(const char* dirname)
{
try {
return new asst::Assistance(dirname);
}
catch (...) {
return nullptr;
}
}
void* AsstCreateEx(const char* dirname, AsstCallback callback, void* custom_arg)
{
try {
// 创建多实例回调会有问题,有空再慢慢整
_callback = callback;
return new asst::Assistance(dirname, CallbackTrans, custom_arg);
}
catch (...) {
return nullptr;
}
}
void AsstDestroy(void* p_asst)
{
if (p_asst == nullptr) {
return;
}
delete p_asst;
p_asst = nullptr;
}
bool AsstCatchDefault(void* p_asst)
{
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->catch_default();
}
bool AsstCatchEmulator(void* p_asst)
{
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->catch_emulator();
}
bool AsstCatchCustom(void* p_asst, const char* address)
{
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->catch_custom(address);
}
bool AsstCatchFake(void* p_asst)
{
#ifdef LOG_TRACE
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->catch_fake();
#else
return false;
#endif // LOG_TRACE
}
bool AsstAppendFight(void* p_asst, int max_mecidine, int max_stone, int max_times)
{
if (p_asst == nullptr) {
return false;
}
asst::Assistance* ptr = (asst::Assistance*)p_asst;
return ptr->append_fight(max_mecidine, max_stone, max_times);
}
bool AsstAppendAward(void* p_asst)
{
if (p_asst == nullptr) {
return false;
}
{
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->append_award();
}
bool AsstAppendVisit(void* p_asst)
{
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->append_visit();
}
bool AsstAppendVisit(void* p_asst)
{
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->append_visit();
}
bool AsstAppendMall(void* p_asst, bool with_shopping)
{
if (p_asst == nullptr) {
return false;
}
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->append_mall(with_shopping);
}
//bool AsstAppendProcessTask(void* p_asst, const char* task)
//{
// if (p_asst == nullptr) {
// return false;
// }
//
// return ((asst::Assistance*)p_asst)->append_process_task(task);
}
//bool AsstAppendProcessTask(void* p_asst, const char* task)
//{
// if (p_asst == nullptr) {
// return false;
// }
//
// return ((asst::Assistance*)p_asst)->append_process_task(task);
//}
bool AsstStartRecruitCalc(void* p_asst, const int select_level[], int required_len, bool set_time)
{
if (p_asst == nullptr) {
return false;
}
std::vector<int> level_vector;
level_vector.assign(select_level, select_level + required_len);
return ((asst::Assistance*)p_asst)->start_recruit_calc(level_vector, set_time);
}
bool AsstAppendInfrast(void* p_asst, int work_mode, const char** order, int order_size, const char* uses_of_drones, double dorm_threshold)
{
if (p_asst == nullptr) {
return false;
}
std::vector<std::string> order_vector;
order_vector.assign(order, order + order_size);
bool AsstStartRecruitCalc(void* p_asst, const int select_level[], int required_len, bool set_time)
{
if (p_asst == nullptr) {
return false;
}
std::vector<int> level_vector;
level_vector.assign(select_level, select_level + required_len);
return ((asst::Assistance*)p_asst)->start_recruit_calc(level_vector, set_time);
}
bool AsstAppendInfrast(void* p_asst, int work_mode, const char** order, int order_size, const char* uses_of_drones, double dorm_threshold)
{
if (p_asst == nullptr) {
return false;
}
std::vector<std::string> order_vector;
order_vector.assign(order, order + order_size);
return ((asst::Assistance*)p_asst)->
append_infrast(
static_cast<asst::infrast::WorkMode>(work_mode),
order_vector,
uses_of_drones,
dorm_threshold);
dorm_threshold);
}
bool AsstAppendRecruit(void* p_asst, int max_times, const int select_level[], int select_len, const int confirm_level[], int confirm_len, bool need_refresh)
{
if (p_asst == nullptr) {
return false;
}
std::vector<int> required_vector;
{
if (p_asst == nullptr) {
return false;
}
std::vector<int> required_vector;
required_vector.assign(select_level, select_level + select_len);
std::vector<int> confirm_vector;
std::vector<int> confirm_vector;
confirm_vector.assign(confirm_level, confirm_level + confirm_len);
return ((asst::Assistance*)p_asst)->append_recruit(max_times, required_vector, confirm_vector, need_refresh);
}
}
bool AsstStart(void* p_asst)
{
if (p_asst == nullptr) {
return false;
}
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->start();
}
bool AsstStop(void* p_asst)
{
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->stop();
bool AsstStop(void* p_asst)
{
if (p_asst == nullptr) {
return false;
}
return ((asst::Assistance*)p_asst)->stop();
}
bool MEOAPI AsstSetPenguinId(void* p_asst, const char* id)
bool AsstSetPenguinId(void* p_asst, const char* id)
{
if (p_asst == nullptr) {
return false;
}
if (p_asst == nullptr) {
return false;
}
auto ptr = (asst::Assistance*)p_asst;
ptr->set_penguin_id(id);
return true;
}
//bool AsstSetParam(void* p_asst, const char* type, const char* param, const char* value)
//{
// if (p_asst == nullptr) {
// return false;
// }
//
// return ((asst::Assistance*)p_asst)->set_param(type, param, value);
//}
const char* AsstGetVersion()
{
return asst::Version;
}
bool AsstAppendDebug(void* p_asst)
{
if (p_asst == nullptr) {
return false;
}
#if LOG_TRACE
return ((asst::Assistance*)p_asst)->append_debug();
#else
return false;
#endif // LOG_TRACE
}
//bool AsstSetParam(void* p_asst, const char* type, const char* param, const char* value)
//{
// if (p_asst == nullptr) {
// return false;
// }
//
// return ((asst::Assistance*)p_asst)->set_param(type, param, value);
//}
const char* AsstGetVersion()
{
return asst::Version;
}
bool AsstAppendDebug(void* p_asst)
{
if (p_asst == nullptr) {
return false;
}
#if LOG_TRACE
return ((asst::Assistance*)p_asst)->append_debug();
#else
return false;
#endif // LOG_TRACE
}

View File

@@ -5,7 +5,7 @@
#include <ostream>
#include <unordered_map>
#include <json.h>
#include <meojson/json.h>
namespace asst
{

View File

@@ -1,6 +1,6 @@
#include "GeneralConfiger.h"
#include <json.h>
#include <meojson/json.h>
bool asst::GeneralConfiger::parse(const json::value& json)
{
@@ -52,4 +52,4 @@ bool asst::GeneralConfiger::parse(const json::value& json)
}
return true;
}
}

View File

@@ -1,6 +1,6 @@
#include "InfrastConfiger.h"
#include <json.h>
#include <meojson/json.h>
bool asst::InfrastConfiger::parse(const json::value& json)
{
@@ -209,4 +209,4 @@ bool asst::InfrastConfiger::parse(const json::value& json)
m_facilities_info.emplace(facility_name, std::move(fac_info));
}
return true;
}
}

View File

@@ -1,6 +1,6 @@
#include "ItemConfiger.h"
#include <json.h>
#include <meojson/json.h>
bool asst::ItemConfiger::parse(const json::value& json)
{
@@ -9,4 +9,4 @@ bool asst::ItemConfiger::parse(const json::value& json)
m_item_name.emplace(id, std::move(name));
}
return true;
}
}

View File

@@ -150,12 +150,12 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(SolutionDir)include;$(SolutionDir)3rdparty\include;$(SolutionDir)3rdparty\include\meojson;$(SolutionDir)\3rdparty\include\opencv;$(SolutionDir)\3rdparty\include\opencv2;$(SolutionDir)3drPart\include\OcrLiteNcnn;;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)include;$(SolutionDir)3rdparty\include;$(IncludePath)</IncludePath>
<LibraryPath>$(TargetDir);$(SolutionDir)\3rdparty\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(SolutionDir)include;$(SolutionDir)3rdparty\include;$(SolutionDir)3rdparty\include\meojson;$(SolutionDir)3rdparty\include\opencv;$(SolutionDir)3rdparty\include\opencv2;$(SolutionDir)3drPart\include\OcrLiteNcnn;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)include;$(SolutionDir)3rdparty\include;$(IncludePath)</IncludePath>
<LibraryPath>$(TargetDir);$(SolutionDir)\3rdparty\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">

View File

@@ -2,7 +2,7 @@
#include <filesystem>
#include <json.h>
#include <meojson/json.h>
#include <opencv2/opencv.hpp>
namespace penguin
{
@@ -92,4 +92,4 @@ bool asst::PenguinPack::load_templ(const std::string& item_id, const std::string
penguin::load_templ(item_id.c_str(), buf.data(), buf.size());
return true;
}
}

View File

@@ -2,7 +2,7 @@
#include <Windows.h>
#include <json.h>
#include <meojson/json.h>
#include "AsstUtils.hpp"
#include "Logger.hpp"
@@ -96,4 +96,4 @@ bool asst::PenguinUploader::request_penguin(const std::string& body)
::CloseHandle(pipe_read);
::CloseHandle(pipe_child_write);
return true;
}
}

View File

@@ -3,7 +3,7 @@
#include <chrono>
#include <random>
#include <json.h>
#include <meojson/json.h>
#include "AsstUtils.hpp"
#include "Controller.h"
@@ -208,4 +208,4 @@ void asst::ProcessTask::exec_swipe_task(ProcessTaskAction action)
default: // 走不到这里TODO 报个错
break;
}
}
}

View File

@@ -2,7 +2,7 @@
#include <algorithm>
#include <json.h>
#include <meojson/json.h>
bool asst::RecruitConfiger::parse(const json::value& json)
{
@@ -31,7 +31,7 @@ bool asst::RecruitConfiger::parse(const json::value& json)
// 按干员等级排个序
std::sort(m_all_opers.begin(), m_all_opers.end(), [](const auto& lhs, const auto& rhs) -> bool {
return lhs.level > rhs.level;
});
});
return true;
}
}

View File

@@ -4,7 +4,7 @@
#include <fstream>
#include <sstream>
#include <json.h>
#include <meojson/json.h>
#include "AsstDef.h"
@@ -78,4 +78,4 @@ bool asst::Resource::load(const std::string& dir)
}
return true;
}
}

View File

@@ -1,32 +1,32 @@
#include "TaskData.h"
#include <algorithm>
#include <json.h>
#include "AsstDef.h"
#include "GeneralConfiger.h"
#include "TemplResource.h"
const std::shared_ptr<asst::TaskInfo> asst::TaskData::get(const std::string& name) const noexcept
{
if (auto iter = m_all_tasks_info.find(name);
iter != m_all_tasks_info.cend()) {
return iter->second;
}
else {
return nullptr;
}
}
const std::unordered_set<std::string>& asst::TaskData::get_templ_required() const noexcept
{
return m_templ_required;
}
std::shared_ptr<asst::TaskInfo> asst::TaskData::get(std::string name)
{
return m_all_tasks_info[std::move(name)];
#include "TaskData.h"
#include <algorithm>
#include <meojson/json.h>
#include "AsstDef.h"
#include "GeneralConfiger.h"
#include "TemplResource.h"
const std::shared_ptr<asst::TaskInfo> asst::TaskData::get(const std::string& name) const noexcept
{
if (auto iter = m_all_tasks_info.find(name);
iter != m_all_tasks_info.cend()) {
return iter->second;
}
else {
return nullptr;
}
}
const std::unordered_set<std::string>& asst::TaskData::get_templ_required() const noexcept
{
return m_templ_required;
}
std::shared_ptr<asst::TaskInfo> asst::TaskData::get(std::string name)
{
return m_all_tasks_info[std::move(name)];
}
void asst::TaskData::clear_cache() noexcept
@@ -34,125 +34,125 @@ void asst::TaskData::clear_cache() noexcept
for (auto&& [name, ptr] : m_all_tasks_info) {
ptr->region_of_appeared = Rect();
}
}
bool asst::TaskData::parse(const json::value& json)
{
for (const auto& [name, task_json] : json.as_object()) {
std::string algorithm_str = task_json.get("algorithm", "matchtemplate");
std::transform(algorithm_str.begin(), algorithm_str.end(), algorithm_str.begin(), ::tolower);
AlgorithmType algorithm = AlgorithmType::Invaild;
if (algorithm_str == "matchtemplate") {
algorithm = AlgorithmType::MatchTemplate;
}
else if (algorithm_str == "justreturn") {
algorithm = AlgorithmType::JustReturn;
}
else if (algorithm_str == "ocrdetect") {
algorithm = AlgorithmType::OcrDetect;
}
// CompareHist是MatchTemplate的衍生算法不应作为单独的配置参数出现
// else if (algorithm_str == "comparehist") {}
else {
m_last_error = "algorithm error " + algorithm_str;
return false;
}
std::shared_ptr<TaskInfo> task_info_ptr = nullptr;
switch (algorithm) {
case AlgorithmType::JustReturn:
task_info_ptr = std::make_shared<TaskInfo>();
break;
case AlgorithmType::MatchTemplate: {
auto match_task_info_ptr = std::make_shared<MatchTaskInfo>();
match_task_info_ptr->templ_name = task_json.get("template", name + ".png");
m_templ_required.emplace(match_task_info_ptr->templ_name);
match_task_info_ptr->templ_threshold = task_json.get(
"templThreshold", TemplThresholdDefault);
match_task_info_ptr->special_threshold = task_json.get(
"specialThreshold", 0);
if (task_json.exist("maskRange")) {
match_task_info_ptr->mask_range = std::make_pair(
task_json.at("maskRange")[0].as_integer(),
task_json.at("maskRange")[1].as_integer());
}
task_info_ptr = match_task_info_ptr;
} break;
case AlgorithmType::OcrDetect: {
auto ocr_task_info_ptr = std::make_shared<OcrTaskInfo>();
for (const json::value& text : task_json.at("text").as_array()) {
ocr_task_info_ptr->text.emplace_back(text.as_string());
}
ocr_task_info_ptr->need_full_match = task_json.get("need_match", false);
if (task_json.exist("ocrReplace")) {
for (const json::value& rep : task_json.at("ocrReplace").as_array()) {
ocr_task_info_ptr->replace_map.emplace(rep.as_array()[0].as_string(), rep.as_array()[1].as_string());
}
}
task_info_ptr = ocr_task_info_ptr;
} break;
}
task_info_ptr->cache = task_json.get("cache", true);
task_info_ptr->algorithm = algorithm;
task_info_ptr->name = name;
std::string action = task_json.get("action", std::string());
std::transform(action.begin(), action.end(), action.begin(), ::tolower);
if (action == "clickself") {
task_info_ptr->action = ProcessTaskAction::ClickSelf;
}
else if (action == "clickrand") {
task_info_ptr->action = ProcessTaskAction::ClickRand;
}
else if (action == "donothing" || action.empty()) {
task_info_ptr->action = ProcessTaskAction::DoNothing;
}
else if (action == "stop") {
task_info_ptr->action = ProcessTaskAction::Stop;
}
else if (action == "clickrect") {
task_info_ptr->action = ProcessTaskAction::ClickRect;
const json::value& rect_json = task_json.at("specificRect");
task_info_ptr->specific_rect = Rect(
rect_json[0].as_integer(),
rect_json[1].as_integer(),
rect_json[2].as_integer(),
rect_json[3].as_integer());
}
else if (action == "stagedrops") {
task_info_ptr->action = ProcessTaskAction::StageDrops;
}
else if (action == "swipetotheleft") {
task_info_ptr->action = ProcessTaskAction::SwipeToTheLeft;
}
else if (action == "swipetotheright") {
task_info_ptr->action = ProcessTaskAction::SwipeToTheRight;
}
else {
m_last_error = "Task: " + name + " error: " + action;
return false;
}
task_info_ptr->max_times = task_json.get("maxTimes", INT_MAX);
if (task_json.exist("exceededNext")) {
const json::array& excceed_next_arr = task_json.at("exceededNext").as_array();
for (const json::value& excceed_next : excceed_next_arr) {
task_info_ptr->exceeded_next.emplace_back(excceed_next.as_string());
}
}
else {
task_info_ptr->exceeded_next.emplace_back("Stop");
}
task_info_ptr->pre_delay = task_json.get("preDelay", 0);
task_info_ptr->rear_delay = task_json.get("rearDelay", 0);
if (task_json.exist("reduceOtherTimes")) {
const json::array& reduce_arr = task_json.at("reduceOtherTimes").as_array();
for (const json::value& reduce : reduce_arr) {
task_info_ptr->reduce_other_times.emplace_back(reduce.as_string());
}
}
if (task_json.exist("roi")) {
}
bool asst::TaskData::parse(const json::value& json)
{
for (const auto& [name, task_json] : json.as_object()) {
std::string algorithm_str = task_json.get("algorithm", "matchtemplate");
std::transform(algorithm_str.begin(), algorithm_str.end(), algorithm_str.begin(), ::tolower);
AlgorithmType algorithm = AlgorithmType::Invaild;
if (algorithm_str == "matchtemplate") {
algorithm = AlgorithmType::MatchTemplate;
}
else if (algorithm_str == "justreturn") {
algorithm = AlgorithmType::JustReturn;
}
else if (algorithm_str == "ocrdetect") {
algorithm = AlgorithmType::OcrDetect;
}
// CompareHist是MatchTemplate的衍生算法不应作为单独的配置参数出现
// else if (algorithm_str == "comparehist") {}
else {
m_last_error = "algorithm error " + algorithm_str;
return false;
}
std::shared_ptr<TaskInfo> task_info_ptr = nullptr;
switch (algorithm) {
case AlgorithmType::JustReturn:
task_info_ptr = std::make_shared<TaskInfo>();
break;
case AlgorithmType::MatchTemplate: {
auto match_task_info_ptr = std::make_shared<MatchTaskInfo>();
match_task_info_ptr->templ_name = task_json.get("template", name + ".png");
m_templ_required.emplace(match_task_info_ptr->templ_name);
match_task_info_ptr->templ_threshold = task_json.get(
"templThreshold", TemplThresholdDefault);
match_task_info_ptr->special_threshold = task_json.get(
"specialThreshold", 0);
if (task_json.exist("maskRange")) {
match_task_info_ptr->mask_range = std::make_pair(
task_json.at("maskRange")[0].as_integer(),
task_json.at("maskRange")[1].as_integer());
}
task_info_ptr = match_task_info_ptr;
} break;
case AlgorithmType::OcrDetect: {
auto ocr_task_info_ptr = std::make_shared<OcrTaskInfo>();
for (const json::value& text : task_json.at("text").as_array()) {
ocr_task_info_ptr->text.emplace_back(text.as_string());
}
ocr_task_info_ptr->need_full_match = task_json.get("need_match", false);
if (task_json.exist("ocrReplace")) {
for (const json::value& rep : task_json.at("ocrReplace").as_array()) {
ocr_task_info_ptr->replace_map.emplace(rep.as_array()[0].as_string(), rep.as_array()[1].as_string());
}
}
task_info_ptr = ocr_task_info_ptr;
} break;
}
task_info_ptr->cache = task_json.get("cache", true);
task_info_ptr->algorithm = algorithm;
task_info_ptr->name = name;
std::string action = task_json.get("action", std::string());
std::transform(action.begin(), action.end(), action.begin(), ::tolower);
if (action == "clickself") {
task_info_ptr->action = ProcessTaskAction::ClickSelf;
}
else if (action == "clickrand") {
task_info_ptr->action = ProcessTaskAction::ClickRand;
}
else if (action == "donothing" || action.empty()) {
task_info_ptr->action = ProcessTaskAction::DoNothing;
}
else if (action == "stop") {
task_info_ptr->action = ProcessTaskAction::Stop;
}
else if (action == "clickrect") {
task_info_ptr->action = ProcessTaskAction::ClickRect;
const json::value& rect_json = task_json.at("specificRect");
task_info_ptr->specific_rect = Rect(
rect_json[0].as_integer(),
rect_json[1].as_integer(),
rect_json[2].as_integer(),
rect_json[3].as_integer());
}
else if (action == "stagedrops") {
task_info_ptr->action = ProcessTaskAction::StageDrops;
}
else if (action == "swipetotheleft") {
task_info_ptr->action = ProcessTaskAction::SwipeToTheLeft;
}
else if (action == "swipetotheright") {
task_info_ptr->action = ProcessTaskAction::SwipeToTheRight;
}
else {
m_last_error = "Task: " + name + " error: " + action;
return false;
}
task_info_ptr->max_times = task_json.get("maxTimes", INT_MAX);
if (task_json.exist("exceededNext")) {
const json::array& excceed_next_arr = task_json.at("exceededNext").as_array();
for (const json::value& excceed_next : excceed_next_arr) {
task_info_ptr->exceeded_next.emplace_back(excceed_next.as_string());
}
}
else {
task_info_ptr->exceeded_next.emplace_back("Stop");
}
task_info_ptr->pre_delay = task_json.get("preDelay", 0);
task_info_ptr->rear_delay = task_json.get("rearDelay", 0);
if (task_json.exist("reduceOtherTimes")) {
const json::array& reduce_arr = task_json.at("reduceOtherTimes").as_array();
for (const json::value& reduce : reduce_arr) {
task_info_ptr->reduce_other_times.emplace_back(reduce.as_string());
}
}
if (task_json.exist("roi")) {
const json::array& area_arr = task_json.at("roi").as_array();
int x = area_arr[0].as_integer();
int y = area_arr[1].as_integer();
@@ -163,41 +163,41 @@ bool asst::TaskData::parse(const json::value& json)
m_last_error = name + " roi is out of bounds";
return false;
}
#endif
task_info_ptr->roi = Rect(x, y, width, height);
}
else {
task_info_ptr->roi = Rect();
}
if (task_json.exist("next")) {
for (const json::value& next : task_json.at("next").as_array()) {
task_info_ptr->next.emplace_back(next.as_string());
}
}
if (task_json.exist("rectMove")) {
const json::array& move_arr = task_json.at("rectMove").as_array();
task_info_ptr->rect_move = Rect(
move_arr[0].as_integer(),
move_arr[1].as_integer(),
move_arr[2].as_integer(),
move_arr[3].as_integer());
}
else {
task_info_ptr->rect_move = Rect();
}
m_all_tasks_info.emplace(name, task_info_ptr);
#endif
task_info_ptr->roi = Rect(x, y, width, height);
}
else {
task_info_ptr->roi = Rect();
}
if (task_json.exist("next")) {
for (const json::value& next : task_json.at("next").as_array()) {
task_info_ptr->next.emplace_back(next.as_string());
}
}
if (task_json.exist("rectMove")) {
const json::array& move_arr = task_json.at("rectMove").as_array();
task_info_ptr->rect_move = Rect(
move_arr[0].as_integer(),
move_arr[1].as_integer(),
move_arr[2].as_integer(),
move_arr[3].as_integer());
}
else {
task_info_ptr->rect_move = Rect();
}
m_all_tasks_info.emplace(name, task_info_ptr);
}
#ifdef LOG_TRACE
for (const auto& [name, task] : m_all_tasks_info) {
for (const auto& next : task->next) {
for (const auto& next : task->next) {
if (m_all_tasks_info.find(next) == m_all_tasks_info.cend()) {
m_last_error = name + "'s next " + next + " is null";
return false;
}
}
m_last_error = name + "'s next " + next + " is null";
return false;
}
}
}
#endif
return true;
}
#endif
return true;
}

View File

@@ -2,7 +2,7 @@
#include <fstream>
#include <json.h>
#include <meojson/json.h>
constexpr static const char* EmulatorPathKey = "emulatorPath";
@@ -45,4 +45,4 @@ bool asst::UserConfiger::save()
ofs.close();
return true;
}
}

View File

@@ -2,7 +2,7 @@
#include "AbstractConfiger.h"
#include <json_value.h>
#include <meojson/json_value.h>
#include <unordered_map>
namespace asst