mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
feat.支持增量更新国际服资源
This commit is contained in:
@@ -45,7 +45,9 @@ TaskId ASSTAPI AsstAppendTask(AsstHandle handle, const char* type, const char* p
|
||||
"mecidine": int, // 最大使用理智药数量,可选,默认 0
|
||||
"stone": int, // 最大吃石头数量,可选,默认 0
|
||||
"times": int, // 指定次数,可选,默认无穷大
|
||||
"penguin_id": string // 企鹅数据汇报 id, 可选,默认为空
|
||||
"penguin_id": string, // 企鹅数据汇报 id, 可选,默认为空
|
||||
"server": string // 服务器,可选,默认 "CN", 会影响掉落识别及上传
|
||||
// 选项:"CN" | "US" | "JP" | "KR"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -9,6 +9,10 @@ bool asst::AbstractConfiger::load(const std::string& filename)
|
||||
{
|
||||
LogTraceFunction;
|
||||
|
||||
if (!std::filesystem::exists(filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string content = utils::load_file_without_bom(filename);
|
||||
|
||||
auto&& ret = json::parser::parse(content);
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <meojson/json.hpp>
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#include "AsstDef.h"
|
||||
#include "AsstUtils.hpp"
|
||||
#include "Controller.h"
|
||||
#include "Logger.hpp"
|
||||
|
||||
@@ -46,11 +46,17 @@ bool asst::FightTask::set_params(const json::value& params)
|
||||
const int stone = params.get("stone", 0);
|
||||
const int times = params.get("times", INT_MAX);
|
||||
std::string penguin_id = params.get("penguin_id", "");
|
||||
std::string server = params.get("server", "CN");
|
||||
|
||||
if (!m_runned) {
|
||||
m_start_up_task_ptr->set_enable(true);
|
||||
|
||||
m_stage_task_ptr->set_enable(true);
|
||||
if (stage.empty()) {
|
||||
m_start_up_task_ptr->set_enable(false);
|
||||
m_stage_task_ptr->set_enable(false);
|
||||
}
|
||||
else {
|
||||
m_start_up_task_ptr->set_enable(true);
|
||||
m_stage_task_ptr->set_enable(true);
|
||||
}
|
||||
m_stage_task_ptr->set_tasks({ stage });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "OcrPack.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include <PaddleOCR/paddle_ocr.h>
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
@@ -28,6 +30,10 @@ bool asst::OcrPack::load(const std::string& dir)
|
||||
{
|
||||
LogTraceFunction;
|
||||
|
||||
if (!std::filesystem::exists(dir)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
constexpr static const char* DetName = "/det";
|
||||
//constexpr static const char* ClsName = "/cls";
|
||||
constexpr static const char* RecName = "/rec";
|
||||
|
||||
@@ -16,6 +16,10 @@ bool asst::PenguinPack::load(const std::string& dir)
|
||||
{
|
||||
LogTraceFunction;
|
||||
|
||||
if (!std::filesystem::exists(dir)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = load_json(dir + "/json/stages.json", dir + "/json/hash_index.json");
|
||||
|
||||
for (const auto& file : std::filesystem::directory_iterator(dir + "/items")) {
|
||||
|
||||
@@ -23,27 +23,57 @@ bool asst::Resource::load(const std::string& dir)
|
||||
constexpr static const char* PenguinResourceFilename = "penguin-stats-recognize";
|
||||
constexpr static const char* TilesCalcResourceFilename = "Arknights-Tile-Pos";
|
||||
|
||||
bool overload = false;
|
||||
|
||||
/* 加载各个Json配置文件 */
|
||||
if (!m_general_cfg_unique_ins.load(dir + GeneralCfgFilename)) {
|
||||
m_last_error = std::string(GeneralCfgFilename) + ": " + m_general_cfg_unique_ins.get_last_error();
|
||||
return false;
|
||||
if (!m_loaded) {
|
||||
m_last_error = std::string(GeneralCfgFilename) + ": " + m_general_cfg_unique_ins.get_last_error();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
overload = true;
|
||||
}
|
||||
|
||||
if (!TaskData::get_instance().load(dir + TaskDataFilename)) {
|
||||
m_last_error = std::string(TaskDataFilename) + ": " + TaskData::get_instance().get_last_error();
|
||||
return false;
|
||||
if (!m_loaded) {
|
||||
m_last_error = std::string(TaskDataFilename) + ": " + TaskData::get_instance().get_last_error();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
overload = true;
|
||||
}
|
||||
|
||||
if (!m_recruit_cfg_unique_ins.load(dir + RecruitCfgFilename)) {
|
||||
m_last_error = std::string(RecruitCfgFilename) + ": " + m_recruit_cfg_unique_ins.get_last_error();
|
||||
return false;
|
||||
if (!m_loaded) {
|
||||
m_last_error = std::string(RecruitCfgFilename) + ": " + m_recruit_cfg_unique_ins.get_last_error();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
overload = true;
|
||||
}
|
||||
|
||||
if (!m_item_cfg_unique_ins.load(dir + ItemCfgFilename)) {
|
||||
m_last_error = std::string(ItemCfgFilename) + ": " + m_item_cfg_unique_ins.get_last_error();
|
||||
return false;
|
||||
if (!m_loaded) {
|
||||
m_last_error = std::string(ItemCfgFilename) + ": " + m_item_cfg_unique_ins.get_last_error();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
overload = true;
|
||||
}
|
||||
|
||||
if (!m_infrast_cfg_unique_ins.load(dir + InfrastCfgFilename)) {
|
||||
m_last_error = std::string(InfrastCfgFilename) + ": " + m_infrast_cfg_unique_ins.get_last_error();
|
||||
return false;
|
||||
if (!m_loaded) {
|
||||
m_last_error = std::string(InfrastCfgFilename) + ": " + m_infrast_cfg_unique_ins.get_last_error();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
overload = true;
|
||||
}
|
||||
|
||||
const auto& opt = m_general_cfg_unique_ins.get_options();
|
||||
@@ -55,28 +85,55 @@ bool asst::Resource::load(const std::string& dir)
|
||||
m_templ_resource_unique_ins.append_load_required(m_infrast_cfg_unique_ins.get_templ_required());
|
||||
|
||||
if (!m_templ_resource_unique_ins.load(dir + TemplsFilename)) {
|
||||
m_last_error = std::string(TemplsFilename) + ": " + m_templ_resource_unique_ins.get_last_error();
|
||||
return false;
|
||||
if (!m_loaded) {
|
||||
m_last_error = std::string(TemplsFilename) + ": " + m_templ_resource_unique_ins.get_last_error();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
overload = true;
|
||||
}
|
||||
|
||||
/* 加载OCR库所需要的资源 */
|
||||
//m_ocr_pack_unique_ins.set_param(opt.ocr_gpu_index, opt.ocr_thread_number);
|
||||
if (!m_ocr_pack_unique_ins.load(dir + OcrResourceFilename)) {
|
||||
m_last_error = std::string(OcrResourceFilename) + ": " + m_ocr_pack_unique_ins.get_last_error();
|
||||
return false;
|
||||
if (!m_loaded) {
|
||||
m_last_error = std::string(OcrResourceFilename) + ": " + m_ocr_pack_unique_ins.get_last_error();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
overload = true;
|
||||
}
|
||||
|
||||
/* 加载企鹅数据识别库所需要的资源 */
|
||||
m_penguin_pack_unique_ins.set_language(opt.penguin_report.server);
|
||||
if (!m_penguin_pack_unique_ins.load(dir + PenguinResourceFilename)) {
|
||||
m_last_error = std::string(PenguinResourceFilename) + ": " + m_penguin_pack_unique_ins.get_last_error();
|
||||
return false;
|
||||
if (!m_loaded) {
|
||||
m_last_error = std::string(PenguinResourceFilename) + ": " + m_penguin_pack_unique_ins.get_last_error();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
overload = true;
|
||||
}
|
||||
|
||||
/* 加载地图格子识别库所需要的资源 */
|
||||
|
||||
if (!m_tile_pack_unique_ins.load(dir + TilesCalcResourceFilename)) {
|
||||
m_last_error = std::string(TilesCalcResourceFilename) + ": " + m_tile_pack_unique_ins.get_last_error();
|
||||
return false;
|
||||
if (!m_loaded) {
|
||||
m_last_error = std::string(TilesCalcResourceFilename) + ": " + m_tile_pack_unique_ins.get_last_error();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
overload = true;
|
||||
}
|
||||
|
||||
if (m_loaded) {
|
||||
return overload;
|
||||
}
|
||||
|
||||
m_loaded = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -110,6 +110,8 @@ namespace asst
|
||||
OcrPack m_ocr_pack_unique_ins;
|
||||
PenguinPack m_penguin_pack_unique_ins;
|
||||
TilePack m_tile_pack_unique_ins;
|
||||
|
||||
bool m_loaded = false;
|
||||
};
|
||||
|
||||
//static auto& resource = Resource::get_instance();
|
||||
|
||||
@@ -48,6 +48,11 @@ bool asst::StageDropsTaskPlugin::set_penguin_id(std::string id)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool asst::StageDropsTaskPlugin::set_server(std::string server)
|
||||
{
|
||||
m_server = std::move(server);
|
||||
}
|
||||
|
||||
bool asst::StageDropsTaskPlugin::_run()
|
||||
{
|
||||
LogTraceFunction;
|
||||
@@ -82,6 +87,7 @@ bool asst::StageDropsTaskPlugin::recognize_drops()
|
||||
if (need_exit()) {
|
||||
return false;
|
||||
}
|
||||
Resrc.penguin().set_language(m_server);
|
||||
const cv::Mat image = m_ctrler->get_image();
|
||||
std::string res = Resrc.penguin().recognize(image);
|
||||
Log.trace("Results of penguin recognition:\n", res);
|
||||
@@ -165,7 +171,7 @@ void asst::StageDropsTaskPlugin::upload_to_penguin()
|
||||
return;
|
||||
}
|
||||
json::value body;
|
||||
body["server"] = opt.penguin_report.server;
|
||||
body["server"] = m_server;
|
||||
body["stageId"] = stage_id;
|
||||
// To fix: https://github.com/MistEO/MeoAssistantArknights/issues/40
|
||||
body["drops"] = json::array();
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace asst
|
||||
virtual void set_task_ptr(AbstractTask* ptr) override;
|
||||
|
||||
bool set_penguin_id(std::string id);
|
||||
bool set_server(std::string server);
|
||||
private:
|
||||
virtual bool _run() override;
|
||||
|
||||
@@ -35,5 +36,6 @@ namespace asst
|
||||
std::vector<std::future<void>> m_upload_pending;
|
||||
ProcessTask* m_cast_ptr = nullptr;
|
||||
std::string m_penguin_id;
|
||||
std::string m_server = "CN";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -25,12 +25,15 @@ bool asst::TemplResource::load(const std::string& dir)
|
||||
cv::Mat templ = cv::imread(filepath);
|
||||
emplace_templ(filename, std::move(templ));
|
||||
}
|
||||
else if (m_loaded) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
m_last_error = filepath + " not exists";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_loaded = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,5 +55,5 @@ const cv::Mat asst::TemplResource::get_templ(const std::string& key) const noexc
|
||||
|
||||
void asst::TemplResource::emplace_templ(std::string key, cv::Mat templ)
|
||||
{
|
||||
m_templs.emplace(std::move(key), std::move(templ));
|
||||
m_templs[std::move(key)] = std::move(templ);
|
||||
}
|
||||
|
||||
@@ -26,5 +26,7 @@ namespace asst
|
||||
private:
|
||||
std::unordered_set<std::string> m_templs_filename;
|
||||
std::unordered_map<std::string, cv::Mat> m_templs;
|
||||
|
||||
bool m_loaded = false;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ bool asst::TilePack::load(const std::string & dir)
|
||||
{
|
||||
LogTraceFunction;
|
||||
|
||||
if (!std::filesystem::exists(dir)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
constexpr static const char* filename = "/levels.json";
|
||||
|
||||
try {
|
||||
|
||||
@@ -15,13 +15,16 @@ int main(int argc, char** argv)
|
||||
// 若使用 VS,请先设置 TestCaller 属性-调试-工作目录为 $(TargetDir)
|
||||
AsstLoadResource(get_cur_dir().c_str());
|
||||
|
||||
// 增量更新国际服的资源
|
||||
//AsstLoadResource((get_cur_dir() + R"(/resource/international/US)").c_str());
|
||||
|
||||
auto ptr = AsstCreate();
|
||||
if (ptr == nullptr) {
|
||||
std::cerr << "create failed" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool connected = AsstConnect(ptr, "adb", "127.0.0.1:5555", "");
|
||||
bool connected = AsstConnect(ptr, "adb", "127.0.0.1:7555", "");
|
||||
if (!connected) {
|
||||
std::cerr << "connect failed" << std::endl;
|
||||
AsstDestroy(ptr);
|
||||
@@ -32,58 +35,58 @@ int main(int argc, char** argv)
|
||||
|
||||
/* 详细参数可参考 docs / 集成文档.md */
|
||||
|
||||
AsstAppendTask(ptr, "StartUp", R"({})");
|
||||
//AsstAppendTask(ptr, "StartUp", R"({})");
|
||||
|
||||
AsstAppendTask(ptr, "Fight", R"(
|
||||
{
|
||||
"stage": "CE-5"
|
||||
"stage": ""
|
||||
}
|
||||
)");
|
||||
|
||||
AsstAppendTask(ptr, "Recruit", R"(
|
||||
{
|
||||
"select":[4],
|
||||
"confirm":[3,4],
|
||||
"times":4
|
||||
}
|
||||
)");
|
||||
|
||||
AsstAppendTask(ptr, "Infrast", R"(
|
||||
{
|
||||
"facility": ["Mfg", "Trade", "Power", "Control", "Reception", "Office", "Dorm"],
|
||||
"drones": "Money"
|
||||
}
|
||||
)");
|
||||
|
||||
AsstAppendTask(ptr, "Visit", R"({})");
|
||||
|
||||
AsstAppendTask(ptr, "Mall", R"(
|
||||
{
|
||||
"shopping": true,
|
||||
"is_black_list": false,
|
||||
"shopping_list": [
|
||||
"家具",
|
||||
"碳"
|
||||
]
|
||||
}
|
||||
)");
|
||||
AsstAppendTask(ptr, "Award", R"({})");
|
||||
|
||||
AsstAppendTask(ptr, "Roguelike", R"(
|
||||
{
|
||||
"opers": [
|
||||
{
|
||||
"name": "帕拉斯"
|
||||
},
|
||||
{
|
||||
"name": "梓兰"
|
||||
},
|
||||
{
|
||||
"name": "安赛尔"
|
||||
}
|
||||
]
|
||||
}
|
||||
)");
|
||||
// AsstAppendTask(ptr, "Recruit", R"(
|
||||
//{
|
||||
// "select":[4],
|
||||
// "confirm":[3,4],
|
||||
// "times":4
|
||||
//}
|
||||
// )");
|
||||
//
|
||||
// AsstAppendTask(ptr, "Infrast", R"(
|
||||
//{
|
||||
// "facility": ["Mfg", "Trade", "Power", "Control", "Reception", "Office", "Dorm"],
|
||||
// "drones": "Money"
|
||||
//}
|
||||
//)");
|
||||
//
|
||||
// AsstAppendTask(ptr, "Visit", R"({})");
|
||||
//
|
||||
// AsstAppendTask(ptr, "Mall", R"(
|
||||
//{
|
||||
// "shopping": true,
|
||||
// "is_black_list": false,
|
||||
// "shopping_list": [
|
||||
// "家具",
|
||||
// "碳"
|
||||
// ]
|
||||
//}
|
||||
//)");
|
||||
// AsstAppendTask(ptr, "Award", R"({})");
|
||||
//
|
||||
// AsstAppendTask(ptr, "Roguelike", R"(
|
||||
//{
|
||||
// "opers": [
|
||||
// {
|
||||
// "name": "帕拉斯"
|
||||
// },
|
||||
// {
|
||||
// "name": "梓兰"
|
||||
// },
|
||||
// {
|
||||
// "name": "安赛尔"
|
||||
// }
|
||||
// ]
|
||||
//}
|
||||
//)");
|
||||
|
||||
AsstStart(ptr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user