mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
feat: AbstractTask新增附加已有插件、插件查找 (#9816)
* feat: 新增插件查找 * feat: AbstractTask增加附加已有插件 * perf: attach -> append
This commit is contained in:
@@ -47,6 +47,25 @@ namespace asst
|
||||
m_plugins.emplace_back(plugin);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
template <typename PluginType>
|
||||
requires std::derived_from<PluginType, AbstractTaskPlugin> // Plugin must inherit AbstractTaskPlugin
|
||||
void append_plugin(const std::shared_ptr<PluginType>& plugin)
|
||||
{
|
||||
m_plugins.emplace_back(plugin);
|
||||
}
|
||||
|
||||
template <typename PluginType>
|
||||
requires std::derived_from<PluginType, AbstractTaskPlugin>
|
||||
std::shared_ptr<PluginType> find_plugin()
|
||||
{
|
||||
for (const auto& plugin : m_plugins) {
|
||||
if (auto ptr = std::dynamic_pointer_cast<PluginType>(plugin)) {
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
void clear_plugin() noexcept;
|
||||
|
||||
bool get_enable() const noexcept { return m_enable; }
|
||||
|
||||
Reference in New Issue
Block a user