mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-18 02:10:21 +08:00
feat: 增加任务截图插件
This commit is contained in:
@@ -8586,6 +8586,18 @@
|
||||
20
|
||||
]
|
||||
},
|
||||
"ScreenshotTaskPlugin-Config": {
|
||||
"Doc": "本任务是插件 ScreenshotTaskPlugin 的配置",
|
||||
"Doc_2": "需要在任务 Task 开始时截图时,将 Task 加入到此任务的 next 列表。",
|
||||
"algorithm": "JustReturn",
|
||||
"next": []
|
||||
},
|
||||
"ScreenshotTaskPlugin-Config-Debug": {
|
||||
"Doc": "本任务是插件 ScreenshotTaskPlugin 的配置",
|
||||
"Doc_2": "存在 DEBUG 或 DEBUG.txt 时的额外截图",
|
||||
"algorithm": "JustReturn",
|
||||
"next": []
|
||||
},
|
||||
"Roguelike@Abandon": {
|
||||
"Doc": "base_task",
|
||||
"template": "empty.png",
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
<ClInclude Include="Task\Interface\CustomTask.h" />
|
||||
<ClInclude Include="Task\Interface\VideoRecognitionTask.h" />
|
||||
<ClInclude Include="Task\Interface\OperBoxTask.h" />
|
||||
<ClInclude Include="Task\Miscellaneous\ScreenshotTaskPlugin.h" />
|
||||
<ClInclude Include="Task\Miscellaneous\CopilotListNotificationPlugin.h" />
|
||||
<ClInclude Include="Task\Miscellaneous\OperBoxRecognitionTask.h" />
|
||||
<ClInclude Include="Task\Miscellaneous\AccountSwitchTask.h" />
|
||||
@@ -240,6 +241,7 @@
|
||||
<ClCompile Include="Task\Infrast\InfrastProcessingTask.cpp" />
|
||||
<ClCompile Include="Task\Interface\VideoRecognitionTask.cpp" />
|
||||
<ClCompile Include="Task\Interface\OperBoxTask.cpp" />
|
||||
<ClCompile Include="Task\Miscellaneous\ScreenshotTaskPlugin.cpp" />
|
||||
<ClCompile Include="Task\Miscellaneous\CopilotListNotificationPlugin.cpp" />
|
||||
<ClCompile Include="Task\Miscellaneous\OperBoxRecognitionTask.cpp" />
|
||||
<ClCompile Include="Task\Miscellaneous\AccountSwitchTask.cpp" />
|
||||
|
||||
@@ -648,6 +648,9 @@
|
||||
<ClInclude Include="Task\Roguelike\RoguelikeStrategyChangeTaskPlugin.h">
|
||||
<Filter>Source\Task\Roguelike</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Task\Miscellaneous\ScreenshotTaskPlugin.h">
|
||||
<Filter>Source\Task\Miscellaneous</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Vision\VisionHelper.cpp">
|
||||
@@ -1079,5 +1082,8 @@
|
||||
<ClCompile Include="Task\Roguelike\RoguelikeStrategyChangeTaskPlugin.cpp">
|
||||
<Filter>Source\Task\Roguelike</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Task\Miscellaneous\ScreenshotTaskPlugin.cpp">
|
||||
<Filter>Source\Task\Miscellaneous</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
50
src/MaaCore/Task/Miscellaneous/ScreenshotTaskPlugin.cpp
Normal file
50
src/MaaCore/Task/Miscellaneous/ScreenshotTaskPlugin.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "ScreenshotTaskPlugin.h"
|
||||
|
||||
#include "Config/TaskData.h"
|
||||
#include "Utils/Logger.hpp"
|
||||
|
||||
asst::ScreenshotTaskPlugin::ScreenshotTaskPlugin(const AsstCallback& callback, Assistant* inst,
|
||||
std::string_view task_chain)
|
||||
: AbstractTaskPlugin(callback, inst, task_chain)
|
||||
{
|
||||
m_screenshot_tasks.clear();
|
||||
if (auto ptr = Task.get(config_name)) {
|
||||
ranges::copy(ptr->next, std::back_inserter(m_screenshot_tasks));
|
||||
}
|
||||
else {
|
||||
Log.info(__FUNCTION__, "| no config found");
|
||||
}
|
||||
|
||||
#ifndef ASST_DEBUG
|
||||
bool need_save_debug_img = std::ifstream("DEBUG").good() || std::ifstream("DEBUG.txt").good();
|
||||
if (!need_save_debug_img) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (auto ptr = Task.get(debug_config_name)) {
|
||||
ranges::copy(ptr->next, std::back_inserter(m_screenshot_tasks));
|
||||
}
|
||||
else {
|
||||
Log.info(__FUNCTION__, "| no debug config found");
|
||||
}
|
||||
}
|
||||
|
||||
bool asst::ScreenshotTaskPlugin::verify(AsstMsg msg, const json::value& details) const
|
||||
{
|
||||
if (msg != AsstMsg::SubTaskStart || details.get("subtask", std::string()) != "ProcessTask") {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string& task = details.get("details", "task", "");
|
||||
if (ranges::any_of(m_screenshot_tasks, [&task](std::string_view item) { return task.ends_with(item); })) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool asst::ScreenshotTaskPlugin::_run()
|
||||
{
|
||||
save_img(utils::path("debug") / utils::path(std::string(m_task_chain)));
|
||||
return true;
|
||||
}
|
||||
24
src/MaaCore/Task/Miscellaneous/ScreenshotTaskPlugin.h
Normal file
24
src/MaaCore/Task/Miscellaneous/ScreenshotTaskPlugin.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "Task/AbstractTaskPlugin.h"
|
||||
|
||||
namespace asst
|
||||
{
|
||||
class ScreenshotTaskPlugin : public AbstractTaskPlugin
|
||||
{
|
||||
public:
|
||||
ScreenshotTaskPlugin(const AsstCallback& callback, Assistant* inst, std::string_view task_chain);
|
||||
virtual ~ScreenshotTaskPlugin() override = default;
|
||||
|
||||
public:
|
||||
virtual bool verify(AsstMsg msg, const json::value& details) const override;
|
||||
|
||||
protected:
|
||||
virtual bool _run() override;
|
||||
|
||||
private:
|
||||
static const constexpr std::string_view config_name = "ScreenshotTaskPlugin-Config";
|
||||
static const constexpr std::string_view debug_config_name = "ScreenshotTaskPlugin-Config-Debug";
|
||||
|
||||
std::vector<std::string> m_screenshot_tasks;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user