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())
68 if (langSetting ==
null)
73 FileInfo[] files =
new DirectoryInfo(langSetting.
dir +
"Data").GetFiles();
74 foreach (FileInfo fileInfo
in files)
76 switch (fileInfo.Name)
84 case "chara_talk.xlsx":
90 case "chara_tone.xlsx":
107 value =
new HashSet<Action<object>>();
118 Action<object> action = delegate
122 (string, Delegate) key = (eventId, handler);
134 Action<object> action = delegate(
object data)
136 if (!(data is T obj))
140 throw new InvalidCastException(
$"{handler.Method.DeclaringType?.Assembly.GetName()} " +
"expects " + typeof(T).Name +
", got " + data.GetType().Name);
149 (string, Delegate) key = (eventId, handler);
158 value.Remove(handler);
159 if (value.Count == 0)
170 (string, Delegate) key = (eventId, handler);
183 (string, Delegate) key = (eventId, handler);
198 foreach (Action<object>
item in value.ToList())
204 catch (Exception arg)
206 Debug.LogError(
$"#event '{eventId}' throws error in one of the handlers\n{arg}");
221 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 ExcelDataList listAlias
static Dictionary< string, LangSetting > langs
static ExcelDataList listName