新的AddonController构造方法 (#70)

This commit is contained in:
yeziuku 2023-12-09 17:02:51 +08:00 committed by GitHub
parent 1fd5187785
commit 7cb1ce7f24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 45 deletions

View File

@ -1,4 +1,5 @@
using Milimoe.FunGame.Core.Entity;
using System.Collections;
using Milimoe.FunGame.Core.Entity;
using Milimoe.FunGame.Core.Library.Common.Addon;
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Service;
@ -52,7 +53,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
/// <param name="delegates">用于构建 <see cref="Controller.AddonController"/></param>
/// <param name="otherobjs">其他需要传入给插件初始化的对象</param>
/// <returns></returns>
public static GameModeLoader LoadGameModes(FunGameInfo.FunGame runtime, Delegate[] delegates, params object[] otherobjs)
public static GameModeLoader LoadGameModes(FunGameInfo.FunGame runtime, Hashtable delegates, params object[] otherobjs)
{
GameModeLoader loader = new();
if (runtime == FunGameInfo.FunGame.FunGame_Desktop)

View File

@ -1,4 +1,5 @@
using Milimoe.FunGame.Core.Library.Common.Addon;
using System.Collections;
using Milimoe.FunGame.Core.Library.Common.Addon;
using Milimoe.FunGame.Core.Library.Common.Event;
using Milimoe.FunGame.Core.Service;
@ -23,7 +24,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
/// <param name="delegates">用于构建 <see cref="Controller.AddonController"/></param>
/// <param name="otherobjs">其他需要传入给插件初始化的对象</param>
/// <returns></returns>
public static PluginLoader LoadPlugins(Delegate[] delegates, params object[] otherobjs)
public static PluginLoader LoadPlugins(Hashtable delegates, params object[] otherobjs)
{
PluginLoader loader = new();
AddonManager.LoadPlugins(loader.Plugins, delegates, otherobjs);

View File

@ -1,4 +1,5 @@
using Milimoe.FunGame.Core.Api.Transmittal;
using System.Collections;
using Milimoe.FunGame.Core.Api.Transmittal;
using Milimoe.FunGame.Core.Interface;
using Milimoe.FunGame.Core.Library.Constant;
@ -11,7 +12,12 @@ namespace Milimoe.FunGame.Core.Controller
/// <summary>
/// 输出系统消息
/// </summary>
private Action<string> MaskMethod_WriteLine { get; set; } = new(msg => Console.Write("\r" + msg + "\n\r> "));
private Action<string> MaskMethod_WriteLine { get; set; }
/// <summary>
/// 输出错误消息
/// </summary>
private Action<Exception> MaskMethod_Error { get; set; }
/// <summary>
/// 基于本地已连接的Socket创建新的数据请求
@ -23,11 +29,6 @@ namespace Milimoe.FunGame.Core.Controller
/// </summary>
private Func<DataRequestType, DataRequest> MaskMethod_NewLongRunningDataRequest { get; set; }
/// <summary>
/// 输出错误消息
/// </summary>
private Action<Exception> MaskMethod_Error { get; set; } = new(e => Console.Write("\r" + e + "\n\r> "));
/// <summary>
/// 输出系统消息
/// </summary>
@ -35,6 +36,13 @@ namespace Milimoe.FunGame.Core.Controller
/// <returns></returns>
public void WriteLine(string msg) => MaskMethod_WriteLine(msg);
/// <summary>
/// 输出错误消息
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
public void Error(Exception e) => MaskMethod_Error(e);
/// <summary>
/// 基于本地已连接的Socket创建新的数据请求
/// <para>请勿在 <see cref="Library.Common.Addon.GameModeServer"/> 中调用此方法</para>
@ -51,29 +59,28 @@ namespace Milimoe.FunGame.Core.Controller
/// <returns></returns>
public DataRequest NewLongRunningDataRequest(DataRequestType type) => MaskMethod_NewLongRunningDataRequest(type);
/// <summary>
/// 输出错误消息
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
public void Error(Exception e) => MaskMethod_Error(e);
/// <summary>
/// 新建一个AddonController
/// </summary>
/// <param name="Addon"></param>
/// <param name="delegates"></param>
public AddonController(IAddon Addon, Delegate[] delegates)
public AddonController(IAddon Addon, Hashtable delegates)
{
this.Addon = Addon;
if (delegates.Length > 0) MaskMethod_WriteLine = (Action<string>)delegates[0];
if (delegates.Length > 1) MaskMethod_NewDataRequest = (Func<DataRequestType, DataRequest>)delegates[1];
if (delegates.Length > 2) MaskMethod_NewLongRunningDataRequest = (Func<DataRequestType, DataRequest>)delegates[2];
if (delegates.Length > 3) MaskMethod_Error = (Action<Exception>)delegates[3];
if (delegates.ContainsKey("WriteLine")) MaskMethod_WriteLine = delegates["WriteLine"] != null ? (Action<string>)delegates["WriteLine"]! : new(DefaultPrint);
if (delegates.ContainsKey("Error")) MaskMethod_Error = delegates["Error"] != null ? (Action<Exception>)delegates["Error"]! : new(DefaultPrint);
if (delegates.ContainsKey("NewDataRequest")) MaskMethod_NewDataRequest = delegates["NewDataRequest"] != null ? (Func<DataRequestType, DataRequest>)delegates["NewDataRequest"]! : new(DefaultNewDataRequest);
if (delegates.ContainsKey("NewLongRunningDataRequest")) MaskMethod_NewLongRunningDataRequest = delegates["NewLongRunningDataRequest"] != null ? (Func<DataRequestType, DataRequest>)delegates["NewLongRunningDataRequest"]! : new(DefaultNewDataRequest);
MaskMethod_WriteLine ??= new(DefaultPrint);
MaskMethod_Error ??= new(DefaultPrint);
MaskMethod_NewDataRequest ??= new(DefaultNewDataRequest);
MaskMethod_NewLongRunningDataRequest ??= new(DefaultNewDataRequest);
}
private void DefaultPrint(string msg) => Console.Write("\r" + msg + "\n\r> ");
private void DefaultPrint(Exception e) => DefaultPrint(e.ToString());
private DataRequest DefaultNewDataRequest(DataRequestType type)
{
if (Addon is IGameModeServer) throw new NotSupportedException("请勿在GameModeServer类中调用此方法");

View File

@ -361,7 +361,7 @@
物品表
</summary>
</member>
<member name="M:Milimoe.FunGame.Core.Api.Utility.GameModeLoader.LoadGameModes(Milimoe.FunGame.Core.Library.Constant.FunGameInfo.FunGame,System.Delegate[],System.Object[])">
<member name="M:Milimoe.FunGame.Core.Api.Utility.GameModeLoader.LoadGameModes(Milimoe.FunGame.Core.Library.Constant.FunGameInfo.FunGame,System.Collections.Hashtable,System.Object[])">
<summary>
传入 <see cref="T:Milimoe.FunGame.Core.Library.Constant.FunGameInfo.FunGame"/> 类型来创建指定端的模组读取器
<para>runtime = <see cref="F:Milimoe.FunGame.Core.Library.Constant.FunGameInfo.FunGame.FunGame_Desktop"/> 时,仅读取 <seealso cref="P:Milimoe.FunGame.Core.Api.Utility.GameModeLoader.Modes"/></para>
@ -768,7 +768,7 @@
<para>key 是 <see cref="P:Milimoe.FunGame.Core.Library.Common.Addon.Plugin.Name"/></para>
</summary>
</member>
<member name="M:Milimoe.FunGame.Core.Api.Utility.PluginLoader.LoadPlugins(System.Delegate[],System.Object[])">
<member name="M:Milimoe.FunGame.Core.Api.Utility.PluginLoader.LoadPlugins(System.Collections.Hashtable,System.Object[])">
<summary>
构建一个插件读取器并读取插件
</summary>
@ -965,6 +965,11 @@
输出系统消息
</summary>
</member>
<member name="P:Milimoe.FunGame.Core.Controller.AddonController.MaskMethod_Error">
<summary>
输出错误消息
</summary>
</member>
<member name="P:Milimoe.FunGame.Core.Controller.AddonController.MaskMethod_NewDataRequest">
<summary>
基于本地已连接的Socket创建新的数据请求
@ -975,11 +980,6 @@
基于本地已连接的Socket创建长时间运行的数据请求
</summary>
</member>
<member name="P:Milimoe.FunGame.Core.Controller.AddonController.MaskMethod_Error">
<summary>
输出错误消息
</summary>
</member>
<member name="M:Milimoe.FunGame.Core.Controller.AddonController.WriteLine(System.String)">
<summary>
输出系统消息
@ -987,6 +987,13 @@
<param name="msg"></param>
<returns></returns>
</member>
<member name="M:Milimoe.FunGame.Core.Controller.AddonController.Error(System.Exception)">
<summary>
输出错误消息
</summary>
<param name="e"></param>
<returns></returns>
</member>
<member name="M:Milimoe.FunGame.Core.Controller.AddonController.NewDataRequest(Milimoe.FunGame.Core.Library.Constant.DataRequestType)">
<summary>
基于本地已连接的Socket创建新的数据请求
@ -1003,14 +1010,7 @@
<param name="type"></param>
<returns></returns>
</member>
<member name="M:Milimoe.FunGame.Core.Controller.AddonController.Error(System.Exception)">
<summary>
输出错误消息
</summary>
<param name="e"></param>
<returns></returns>
</member>
<member name="M:Milimoe.FunGame.Core.Controller.AddonController.#ctor(Milimoe.FunGame.Core.Interface.IAddon,System.Delegate[])">
<member name="M:Milimoe.FunGame.Core.Controller.AddonController.#ctor(Milimoe.FunGame.Core.Interface.IAddon,System.Collections.Hashtable)">
<summary>
新建一个AddonController
</summary>
@ -2320,7 +2320,7 @@
所处的房间
</summary>
</member>
<member name="M:Milimoe.FunGame.Core.Service.AddonManager.LoadPlugins(System.Collections.Generic.Dictionary{System.String,Milimoe.FunGame.Core.Library.Common.Addon.Plugin},System.Delegate[],System.Object[])">
<member name="M:Milimoe.FunGame.Core.Service.AddonManager.LoadPlugins(System.Collections.Generic.Dictionary{System.String,Milimoe.FunGame.Core.Library.Common.Addon.Plugin},System.Collections.Hashtable,System.Object[])">
<summary>
从plugins目录加载所有插件
</summary>
@ -2329,7 +2329,7 @@
<param name="otherobjs"></param>
<returns></returns>
</member>
<member name="M:Milimoe.FunGame.Core.Service.AddonManager.LoadGameModes(System.Collections.Generic.Dictionary{System.String,Milimoe.FunGame.Core.Library.Common.Addon.GameMode},System.Collections.Generic.List{Milimoe.FunGame.Core.Entity.Character},System.Collections.Generic.List{Milimoe.FunGame.Core.Entity.Skill},System.Collections.Generic.List{Milimoe.FunGame.Core.Entity.Item},System.Delegate[],System.Object[])">
<member name="M:Milimoe.FunGame.Core.Service.AddonManager.LoadGameModes(System.Collections.Generic.Dictionary{System.String,Milimoe.FunGame.Core.Library.Common.Addon.GameMode},System.Collections.Generic.List{Milimoe.FunGame.Core.Entity.Character},System.Collections.Generic.List{Milimoe.FunGame.Core.Entity.Skill},System.Collections.Generic.List{Milimoe.FunGame.Core.Entity.Item},System.Collections.Hashtable,System.Object[])">
<summary>
从gamemodes目录加载所有模组
</summary>
@ -2341,7 +2341,7 @@
<param name="otherobjs"></param>
<returns></returns>
</member>
<member name="M:Milimoe.FunGame.Core.Service.AddonManager.LoadGameModesForServer(System.Collections.Generic.Dictionary{System.String,Milimoe.FunGame.Core.Library.Common.Addon.GameModeServer},System.Collections.Generic.List{Milimoe.FunGame.Core.Entity.Character},System.Collections.Generic.List{Milimoe.FunGame.Core.Entity.Skill},System.Collections.Generic.List{Milimoe.FunGame.Core.Entity.Item},System.Delegate[],System.Object[])">
<member name="M:Milimoe.FunGame.Core.Service.AddonManager.LoadGameModesForServer(System.Collections.Generic.Dictionary{System.String,Milimoe.FunGame.Core.Library.Common.Addon.GameModeServer},System.Collections.Generic.List{Milimoe.FunGame.Core.Entity.Character},System.Collections.Generic.List{Milimoe.FunGame.Core.Entity.Skill},System.Collections.Generic.List{Milimoe.FunGame.Core.Entity.Item},System.Collections.Hashtable,System.Object[])">
<summary>
从gamemodes目录加载所有适用于服务器的模组
</summary>

View File

@ -1,4 +1,5 @@
using System.Reflection;
using System.Collections;
using System.Reflection;
using Milimoe.FunGame.Core.Entity;
using Milimoe.FunGame.Core.Library.Common.Addon;
using Milimoe.FunGame.Core.Library.Constant;
@ -14,7 +15,7 @@ namespace Milimoe.FunGame.Core.Service
/// <param name="delegates"></param>
/// <param name="otherobjs"></param>
/// <returns></returns>
internal static Dictionary<string, Plugin> LoadPlugins(Dictionary<string, Plugin> plugins, Delegate[] delegates, params object[] otherobjs)
internal static Dictionary<string, Plugin> LoadPlugins(Dictionary<string, Plugin> plugins, Hashtable delegates, params object[] otherobjs)
{
if (!Directory.Exists(ReflectionSet.PluginFolderPath)) return plugins;
@ -50,7 +51,7 @@ namespace Milimoe.FunGame.Core.Service
/// <param name="delegates"></param>
/// <param name="otherobjs"></param>
/// <returns></returns>
internal static Dictionary<string, GameMode> LoadGameModes(Dictionary<string, GameMode> gamemodes, List<Character> characters, List<Skill> skills, List<Item> items, Delegate[] delegates, params object[] otherobjs)
internal static Dictionary<string, GameMode> LoadGameModes(Dictionary<string, GameMode> gamemodes, List<Character> characters, List<Skill> skills, List<Item> items, Hashtable delegates, params object[] otherobjs)
{
if (!Directory.Exists(ReflectionSet.GameModeFolderPath)) return gamemodes;
@ -111,7 +112,7 @@ namespace Milimoe.FunGame.Core.Service
/// <param name="delegates"></param>
/// <param name="otherobjs"></param>
/// <returns></returns>
internal static Dictionary<string, GameModeServer> LoadGameModesForServer(Dictionary<string, GameModeServer> gamemodes, List<Character> characters, List<Skill> skills, List<Item> items, Delegate[] delegates, params object[] otherobjs)
internal static Dictionary<string, GameModeServer> LoadGameModesForServer(Dictionary<string, GameModeServer> gamemodes, List<Character> characters, List<Skill> skills, List<Item> items, Hashtable delegates, params object[] otherobjs)
{
if (!Directory.Exists(ReflectionSet.GameModeFolderPath)) return gamemodes;