using Milimoe.FunGame.Core.Interface.Addons; using Milimoe.FunGame.Core.Library.Common.Addon; namespace Milimoe.FunGame.Core.Controller { /// /// 这是通用的控制器,仅提供基本功能 /// /// Addon的类型,如 或者 / / public class BaseAddonController where T : IAddon { /// /// 控制器的本体 /// public T Addon { get; } /// /// 输出系统消息 /// protected Action MaskMethod_WriteLine { get; set; } /// /// 输出错误消息 /// protected Action MaskMethod_Error { get; set; } /// /// 输出系统消息 /// /// /// public void WriteLine(string msg) => MaskMethod_WriteLine(msg); /// /// 输出错误消息 /// /// /// public void Error(Exception e) => MaskMethod_Error(e); /// /// 新建一个BaseAddonController /// /// /// public BaseAddonController(IAddon addon, Dictionary delegates) { Addon = (T)addon; if (delegates.TryGetValue("WriteLine", out object? value)) MaskMethod_WriteLine = value != null ? (Action)value : new(DefaultPrint); if (delegates.TryGetValue("Error", out value)) MaskMethod_Error = value != null ? (Action)value : new(DefaultPrint); MaskMethod_WriteLine ??= new(DefaultPrint); MaskMethod_Error ??= new(DefaultPrint); } /// /// 默认的输出错误消息方法 /// /// /// private void DefaultPrint(string msg) => Console.Write("\r" + msg + "\n\r> "); /// /// 输出错误消息 /// /// /// private void DefaultPrint(Exception e) => DefaultPrint(e.ToString()); } }