mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
feat: 优化单步任务的json解析逻辑
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "../SingleStep/SingleStepBattleProcessTask.h"
|
||||
#include "Config/Miscellaneous/CopilotConfig.h"
|
||||
#include "Utils/Logger.hpp"
|
||||
|
||||
asst::SingleStepTask::SingleStepTask(const AsstCallback& callback, Assistant* inst)
|
||||
: InterfaceTask(callback, inst, TaskType)
|
||||
@@ -9,14 +10,28 @@ asst::SingleStepTask::SingleStepTask(const AsstCallback& callback, Assistant* in
|
||||
|
||||
bool asst::SingleStepTask::set_params(const json::value& params)
|
||||
{
|
||||
std::string type = params.at("type").as_string();
|
||||
std::string subtype = params.at("subtype").as_string();
|
||||
const json::value& details = params.at("details");
|
||||
std::string type = params.get("type", "");
|
||||
std::string subtype = params.get("subtype", "");
|
||||
auto details_opt = params.find("details");
|
||||
|
||||
if (type == "copilot" && subtype == "action") {
|
||||
if (type == "copilot" && subtype == "action" && details_opt) {
|
||||
auto task = std::make_shared<SingleStepBattleProcessTask>(m_callback, m_inst, TaskType);
|
||||
// for debug
|
||||
task->set_stage_name("OF-1");
|
||||
|
||||
// 请参考自动战斗协议
|
||||
task->set_actions(CopilotConfig::parse_actions(details));
|
||||
try {
|
||||
task->set_actions(CopilotConfig::parse_actions(*details_opt));
|
||||
}
|
||||
catch (const json::exception& e) {
|
||||
Log.error(__FUNCTION__, e.what());
|
||||
return false;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
Log.error(__FUNCTION__, e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
m_subtasks.emplace_back(std::move(task));
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user