2using System.Collections.Generic;
18 foreach (
string file
in files)
35 private static readonly Dictionary<string, HashSet<Action<object>>>
_eventHandlers =
new Dictionary<string, HashSet<Action<object>>>();
37 private static readonly Dictionary<(string, Delegate), Action<object>>
_typedEventHandlers =
new Dictionary<(
string, Delegate), Action<object>>();
44 public List<BaseModPackage>
packages =
new List<BaseModPackage>();
46 public virtual void Init(
string path,
string defaultPackage =
"_Elona")
48 Debug.Log(
"Initializing ModManager:" + defaultPackage +
"/" + path);
53 if (!defaultPackage.IsEmpty())
66 if (langSetting ==
null)
71 FileInfo[] files =
new DirectoryInfo(langSetting.
dir +
"Data").GetFiles();
72 foreach (FileInfo fileInfo
in files)
74 switch (fileInfo.Name)
77 Lang.alias =
new ExcelData(fileInfo.FullName);
80 Lang.names =
new ExcelData(fileInfo.FullName);
82 case "chara_talk.xlsx":
88 case "chara_tone.xlsx":
105 value =
new HashSet<Action<object>>();
116 Action<object> action = delegate
120 (string, Delegate) key = (eventId, handler);
132 Action<object> action = delegate(
object data)
134 if (!(data is T obj))
138 throw new InvalidCastException(
$"{handler.Method.DeclaringType?.Assembly.GetName()} " +
"expects " + typeof(T).Name +
", got " + data.GetType().Name);
147 (string, Delegate) key = (eventId, handler);
156 value.Remove(handler);
157 if (value.Count == 0)
168 (string, Delegate) key = (eventId, handler);
181 (string, Delegate) key = (eventId, handler);
196 foreach (Action<object>
item in value.ToList())
202 catch (Exception arg)
204 Debug.LogError(
$"#event '{eventId}' throws error in one of the handlers\n{arg}");
219 return num.GetValueOrDefault() > 0;
void Parse< T >(ModItemList< T > list)
List< BaseModPackage > packages
static readonly Dictionary< string, HashSet< Action< object > > > _eventHandlers
virtual void Init(string path, string defaultPackage="_Elona")
static void UnsubscribeEvent(string eventId, Action< object > handler)
static readonly Dictionary<(string, Delegate), Action< object > > _typedEventHandlers
static void UnsubscribeEvent< T >(string eventId, Action< T > handler)
static bool isInitialized
static string rootDefaultPacakge
virtual void ParseExtra(DirectoryInfo dir, BaseModPackage package)
static BaseModManager Instance
static void PublishEvent(string eventId, object data=null)
static void SubscribeEvent(string eventId, Action handler)
static List< string > listChainLoad
static void UnsubscribeEvent(string eventId, Action handler)
static void SubscribeEvent(string eventId, Action< object > handler)
static bool HasEventSubscriber(string eventId)
DirectoryInfo dirWorkshop
static void SubscribeEvent< T >(string eventId, Action< T > handler)
static void PublishEvent< T >(string eventId, T data=default(T))
static TalkDataList listTalk
static GodTalkDataList listGodTalk
static ToneDataList tones
static Dictionary< string, LangSetting > langs