Elin Decompiled Documentation EA 23.317 Nightly
Loading...
Searching...
No Matches
BaseModManager Class Reference

Classes

class  BaseResource
 

Public Member Functions

virtual void Init (string path, string defaultPackage="_Elona")
 
void InitLang ()
 
virtual void ParseExtra (DirectoryInfo dir, BaseModPackage package)
 

Static Public Member Functions

static void SubscribeEvent (string eventId, Action< object > handler)
 
static void SubscribeEvent (string eventId, Action handler)
 
static void SubscribeEvent< T > (string eventId, Action< T > handler)
 
static void UnsubscribeEvent (string eventId, Action< object > handler)
 
static void UnsubscribeEvent (string eventId, Action handler)
 
static void UnsubscribeEvent< T > (string eventId, Action< T > handler)
 
static void PublishEvent (string eventId, object data=null)
 
static void PublishEvent< T > (string eventId, T data=default(T))
 
static bool HasEventSubscriber (string eventId)
 

Public Attributes

DirectoryInfo dirWorkshop
 
int priorityIndex
 
List< BaseModPackagepackages = new List<BaseModPackage>()
 

Static Public Attributes

static BaseModManager Instance
 
static string rootMod
 
static string rootDefaultPacakge
 
static bool isInitialized
 
static List< string > listChainLoad = new List<string>()
 

Static Private Attributes

static readonly Dictionary< string, HashSet< Action< object > > > _eventHandlers = new Dictionary<string, HashSet<Action<object>>>()
 
static readonly Dictionary<(string, Delegate), Action< object > > _typedEventHandlers = new Dictionary<(string, Delegate), Action<object>>()
 

Detailed Description

Definition at line 7 of file BaseModManager.cs.

Member Function Documentation

◆ HasEventSubscriber()

static bool BaseModManager.HasEventSubscriber ( string  eventId)
inlinestatic

Definition at line 214 of file BaseModManager.cs.

215 {
216 int? num = _eventHandlers.GetValueOrDefault(eventId)?.Count;
217 if (num.HasValue)
218 {
219 return num.GetValueOrDefault() > 0;
220 }
221 return false;
222 }
static readonly Dictionary< string, HashSet< Action< object > > > _eventHandlers

References _eventHandlers.

◆ Init()

virtual void BaseModManager.Init ( string  path,
string  defaultPackage = "_Elona" 
)
inlinevirtual

Definition at line 46 of file BaseModManager.cs.

47 {
48 Debug.Log("Initializing ModManager:" + defaultPackage + "/" + path);
49 Instance = this;
50 rootMod = (rootDefaultPacakge = path);
51 _eventHandlers.Clear();
52 _typedEventHandlers.Clear();
53 if (!defaultPackage.IsEmpty())
54 {
55 rootDefaultPacakge = rootMod + defaultPackage + "/";
56 }
57 }
static readonly Dictionary<(string, Delegate), Action< object > > _typedEventHandlers
static string rootDefaultPacakge
static BaseModManager Instance
static string rootMod

References _eventHandlers, _typedEventHandlers, Debug, Instance, rootDefaultPacakge, and rootMod.

◆ InitLang()

void BaseModManager.InitLang ( )
inline

Definition at line 59 of file BaseModManager.cs.

60 {
61 Debug.Log("Initializing Langs: " + Lang.langCode);
64 MOD.tones.Clear();
65 LangSetting langSetting = MOD.langs.TryGetValue(Lang.langCode);
66 if (langSetting == null)
67 {
68 Debug.LogError("Lang: " + Lang.langCode + " is not set");
69 langSetting = MOD.langs.FirstItem();
70 }
71 FileInfo[] files = new DirectoryInfo(langSetting.dir + "Data").GetFiles();
72 foreach (FileInfo fileInfo in files)
73 {
74 switch (fileInfo.Name)
75 {
76 case "Alias.xlsx":
77 Lang.alias = new ExcelData(fileInfo.FullName);
78 break;
79 case "Name.xlsx":
80 Lang.names = new ExcelData(fileInfo.FullName);
81 break;
82 case "chara_talk.xlsx":
83 MOD.listTalk.Add(new ExcelData(fileInfo.FullName));
84 break;
85 case "god_talk.xlsx":
86 MOD.listGodTalk.Add(new ExcelData(fileInfo.FullName));
87 break;
88 case "chara_tone.xlsx":
89 MOD.tones.Add(new ExcelData(fileInfo.FullName));
90 break;
91 }
92 }
93 }
void Add(ExcelData data)
string dir
Definition: LangSetting.cs:28
Definition: Lang.cs:7
static string langCode
Definition: Lang.cs:29
Definition: MOD.cs:7
static TalkDataList listTalk
Definition: MOD.cs:10
static GodTalkDataList listGodTalk
Definition: MOD.cs:12
static ToneDataList tones
Definition: MOD.cs:14
static Dictionary< string, LangSetting > langs
Definition: MOD.cs:8

References ExcelDataList.Add(), ExcelDataList.Clear(), Debug, LangSetting.dir, Lang.langCode, MOD.langs, MOD.listGodTalk, MOD.listTalk, and MOD.tones.

◆ ParseExtra()

virtual void BaseModManager.ParseExtra ( DirectoryInfo  dir,
BaseModPackage  package 
)
inlinevirtual

Definition at line 95 of file BaseModManager.cs.

96 {
97 }

Referenced by BaseModPackage.Parse().

◆ PublishEvent()

static void BaseModManager.PublishEvent ( string  eventId,
object  data = null 
)
inlinestatic

Definition at line 190 of file BaseModManager.cs.

191 {
192 if (!_eventHandlers.TryGetValue(eventId, out var value))
193 {
194 return;
195 }
196 foreach (Action<object> item in value.ToList())
197 {
198 try
199 {
200 item(data);
201 }
202 catch (Exception arg)
203 {
204 Debug.LogError($"#event '{eventId}' throws error in one of the handlers\n{arg}");
205 }
206 }
207 }

References $, _eventHandlers, Debug, and item.

Referenced by Card._OnDeserialized(), Feat.Apply(), Card.Create(), SourceManager.Init(), Scene.Init(), Game.Load(), Act.Perform(), PublishEvent< T >(), Game.Save(), Core.SetLang(), ReligionManager.SetOwner(), and Game.StartNewGame().

◆ PublishEvent< T >()

static void BaseModManager.PublishEvent< T > ( string  eventId,
data = default(T) 
)
inlinestatic

Definition at line 209 of file BaseModManager.cs.

210 {
211 PublishEvent(eventId, (object)data);
212 }
static void PublishEvent(string eventId, object data=null)

References PublishEvent().

◆ SubscribeEvent() [1/2]

static void BaseModManager.SubscribeEvent ( string  eventId,
Action  handler 
)
inlinestatic

Definition at line 112 of file BaseModManager.cs.

113 {
114 if (handler != null)
115 {
116 Action<object> action = delegate
117 {
118 handler();
119 };
120 (string, Delegate) key = (eventId, handler);
121 _typedEventHandlers[key] = action;
122 SubscribeEvent(eventId, action);
123 }
124 }
static void SubscribeEvent(string eventId, Action< object > handler)

References _typedEventHandlers, and SubscribeEvent().

◆ SubscribeEvent() [2/2]

static void BaseModManager.SubscribeEvent ( string  eventId,
Action< object >  handler 
)
inlinestatic

◆ SubscribeEvent< T >()

static void BaseModManager.SubscribeEvent< T > ( string  eventId,
Action< T >  handler 
)
inlinestatic

Definition at line 126 of file BaseModManager.cs.

127 {
128 if (handler == null)
129 {
130 return;
131 }
132 Action<object> action = delegate(object data)
133 {
134 if (!(data is T obj))
135 {
136 if (data != null)
137 {
138 throw new InvalidCastException($"{handler.Method.DeclaringType?.Assembly.GetName()} " + "expects " + typeof(T).Name + ", got " + data.GetType().Name);
139 }
140 handler(default(T));
141 }
142 else
143 {
144 handler(obj);
145 }
146 };
147 (string, Delegate) key = (eventId, handler);
148 _typedEventHandlers[key] = action;
149 SubscribeEvent(eventId, action);
150 }

References $, _typedEventHandlers, and SubscribeEvent().

◆ UnsubscribeEvent() [1/2]

static void BaseModManager.UnsubscribeEvent ( string  eventId,
Action  handler 
)
inlinestatic

Definition at line 164 of file BaseModManager.cs.

165 {
166 if (handler != null)
167 {
168 (string, Delegate) key = (eventId, handler);
169 if (_typedEventHandlers.TryGetValue(key, out var value))
170 {
171 UnsubscribeEvent(eventId, value);
172 _typedEventHandlers.Remove(key);
173 }
174 }
175 }
static void UnsubscribeEvent(string eventId, Action< object > handler)

References _typedEventHandlers, and UnsubscribeEvent().

◆ UnsubscribeEvent() [2/2]

static void BaseModManager.UnsubscribeEvent ( string  eventId,
Action< object >  handler 
)
inlinestatic

Definition at line 152 of file BaseModManager.cs.

153 {
154 if (_eventHandlers.TryGetValue(eventId, out var value))
155 {
156 value.Remove(handler);
157 if (value.Count == 0)
158 {
159 _eventHandlers.Remove(eventId);
160 }
161 }
162 }

References _eventHandlers.

Referenced by UnsubscribeEvent(), and UnsubscribeEvent< T >().

◆ UnsubscribeEvent< T >()

static void BaseModManager.UnsubscribeEvent< T > ( string  eventId,
Action< T >  handler 
)
inlinestatic

Definition at line 177 of file BaseModManager.cs.

178 {
179 if (handler != null)
180 {
181 (string, Delegate) key = (eventId, handler);
182 if (_typedEventHandlers.TryGetValue(key, out var value))
183 {
184 UnsubscribeEvent(eventId, value);
185 _typedEventHandlers.Remove(key);
186 }
187 }
188 }

References _typedEventHandlers, and UnsubscribeEvent().

Member Data Documentation

◆ _eventHandlers

readonly Dictionary<string, HashSet<Action<object> > > BaseModManager._eventHandlers = new Dictionary<string, HashSet<Action<object>>>()
staticprivate

◆ _typedEventHandlers

readonly Dictionary<(string, Delegate), Action<object> > BaseModManager._typedEventHandlers = new Dictionary<(string, Delegate), Action<object>>()
staticprivate

◆ dirWorkshop

DirectoryInfo BaseModManager.dirWorkshop

Definition at line 39 of file BaseModManager.cs.

◆ Instance

BaseModManager BaseModManager.Instance
static

◆ isInitialized

bool BaseModManager.isInitialized
static

Definition at line 31 of file BaseModManager.cs.

◆ listChainLoad

List<string> BaseModManager.listChainLoad = new List<string>()
static

Definition at line 33 of file BaseModManager.cs.

Referenced by ModManager.ActivatePackages().

◆ packages

List<BaseModPackage> BaseModManager.packages = new List<BaseModPackage>()

Definition at line 44 of file BaseModManager.cs.

Referenced by LayerPickPCC.GetPartProvider(), and LayerPickPCC.PartSorter().

◆ priorityIndex

int BaseModManager.priorityIndex

Definition at line 41 of file BaseModManager.cs.

◆ rootDefaultPacakge

string BaseModManager.rootDefaultPacakge
static

Definition at line 29 of file BaseModManager.cs.

Referenced by ModManager.Init(), and Init().

◆ rootMod

string BaseModManager.rootMod
static

The documentation for this class was generated from the following file: