using Milimoe.FunGame.Core.Library.Common.Addon;
using Milimoe.FunGame.Core.Service;
namespace Milimoe.FunGame.Core.Api.Utility
{
public class WebAPIPluginLoader
{
///
/// 已读取的插件列表
/// key 是
///
public Dictionary Plugins { get; } = [];
///
/// 已加载的插件DLL名称对应的路径
///
public static Dictionary PluginFilePaths => new(AddonManager.PluginFilePaths);
private WebAPIPluginLoader()
{
}
///
/// 构建一个插件读取器并读取插件
///
/// 用于构建
/// 其他需要传入给插件初始化的对象
///
public static WebAPIPluginLoader LoadPlugins(Dictionary delegates, params object[] otherobjs)
{
WebAPIPluginLoader loader = new();
AddonManager.LoadWebAPIPlugins(loader.Plugins, delegates, otherobjs);
foreach (WebAPIPlugin plugin in loader.Plugins.Values.ToList())
{
// 如果插件加载后需要执行代码,请重写AfterLoad方法
plugin.AfterLoad(loader, otherobjs);
}
return loader;
}
public WebAPIPlugin this[string name]
{
get
{
return Plugins[name];
}
set
{
Plugins.TryAdd(name, value);
}
}
}
}