mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 18:47:55 +08:00
fix: 修复 reduce_other_times 不能正常工作的问题
perf: 优化回调处理 Co-authored-by: MistEO <mistereo@hotmail.com>
This commit is contained in:
@@ -165,6 +165,14 @@ bool asst::AbstractTask::need_exit() const
|
||||
|
||||
void asst::AbstractTask::callback(AsstMsg msg, const json::value& detail)
|
||||
{
|
||||
json::value proced_detail = detail;
|
||||
// TODO 屎山: task 字段需要忽略 @ 和前面的字符,否则回调大改
|
||||
if (std::string task = detail.get("details", "task", std::string()); !task.empty()) {
|
||||
if (size_t pos = task.rfind('@'); pos != std::string::npos) {
|
||||
proced_detail["details"]["task"] = task.substr(pos + 1);
|
||||
}
|
||||
}
|
||||
|
||||
for (const TaskPluginPtr& plugin : m_plugins) {
|
||||
plugin->set_exit_flag(m_exit_flag);
|
||||
plugin->set_ctrler(m_ctrler);
|
||||
@@ -172,7 +180,7 @@ void asst::AbstractTask::callback(AsstMsg msg, const json::value& detail)
|
||||
plugin->set_status(m_status);
|
||||
plugin->set_task_ptr(this);
|
||||
|
||||
if (!plugin->verify(msg, detail)) {
|
||||
if (!plugin->verify(msg, proced_detail)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -183,7 +191,7 @@ void asst::AbstractTask::callback(AsstMsg msg, const json::value& detail)
|
||||
}
|
||||
}
|
||||
if (m_callback) {
|
||||
m_callback(msg, detail, m_callback_arg);
|
||||
m_callback(msg, proced_detail, m_callback_arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ namespace asst
|
||||
virtual AbstractTask& set_task_id(int task_id) noexcept;
|
||||
|
||||
template <typename PluginType>
|
||||
std::shared_ptr<PluginType> register_plugin()
|
||||
requires std::derived_from<PluginType, AbstractTaskPlugin> // Plugin must inherit AbstractTaskPlugin
|
||||
std::shared_ptr<PluginType> register_plugin()
|
||||
{
|
||||
auto plugin = std::make_shared<PluginType>(m_callback, m_callback_arg, m_task_chain);
|
||||
m_plugins.emplace(plugin);
|
||||
|
||||
@@ -61,6 +61,8 @@ namespace asst
|
||||
}
|
||||
};
|
||||
|
||||
task_info_ptr->name = task_prefix + "@" + base_ptr->name;
|
||||
generate_tasks(task_info_ptr->sub, base_ptr->sub);
|
||||
generate_tasks(task_info_ptr->next, base_ptr->next);
|
||||
generate_tasks(task_info_ptr->exceeded_next, base_ptr->exceeded_next);
|
||||
generate_tasks(task_info_ptr->on_error_next, base_ptr->on_error_next);
|
||||
|
||||
Reference in New Issue
Block a user