Elin Decompiled Documentation EA 23.331 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 216 of file BaseModManager.cs.

217 {
218 int? num = _eventHandlers.GetValueOrDefault(eventId)?.Count;
219 if (num.HasValue)
220 {
221 return num.GetValueOrDefault() > 0;
222 }
223 return false;
224 }
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);
66 MOD.tones.Clear();
67 LangSetting langSetting = MOD.langs.TryGetValue(Lang.langCode);
68 if (langSetting == null)
69 {
70 Debug.LogError("Lang: " + Lang.langCode + " is not set");
71 langSetting = MOD.langs.FirstItem();
72 }
73 FileInfo[] files = new DirectoryInfo(langSetting.dir + "Data").GetFiles();
74 foreach (FileInfo fileInfo in files)
75 {
76 switch (fileInfo.Name)
77 {
78 case "Alias.xlsx":
79 MOD.listAlias.Add(new ExcelData(fileInfo.FullName));
80 break;
81 case "Name.xlsx":
82 MOD.listName.Add(new ExcelData(fileInfo.FullName));
83 break;
84 case "chara_talk.xlsx":
85 MOD.listTalk.Add(new ExcelData(fileInfo.FullName));
86 break;
87 case "god_talk.xlsx":
88 MOD.listGodTalk.Add(new ExcelData(fileInfo.FullName));
89 break;
90 case "chara_tone.xlsx":
91 MOD.tones.Add(new ExcelData(fileInfo.FullName));
92 break;
93 }
94 }
95 }
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:14
static GodTalkDataList listGodTalk
Definition: MOD.cs:16
static ToneDataList tones
Definition: MOD.cs:18
static ExcelDataList listAlias
Definition: MOD.cs:10
static Dictionary< string, LangSetting > langs
Definition: MOD.cs:8
static ExcelDataList listName
Definition: MOD.cs:12

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

◆ ParseExtra()

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

Definition at line 97 of file BaseModManager.cs.

98 {
99 }

Referenced by BaseModPackage.Parse().

◆ PublishEvent()

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

Definition at line 192 of file BaseModManager.cs.

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

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 211 of file BaseModManager.cs.

212 {
213 PublishEvent(eventId, (object)data);
214 }
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 114 of file BaseModManager.cs.

115 {
116 if (handler != null)
117 {
118 Action<object> action = delegate
119 {
120 handler();
121 };
122 (string, Delegate) key = (eventId, handler);
123 _typedEventHandlers[key] = action;
124 SubscribeEvent(eventId, action);
125 }
126 }
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 128 of file BaseModManager.cs.

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

References $, _typedEventHandlers, and SubscribeEvent().

◆ UnsubscribeEvent() [1/2]

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

Definition at line 166 of file BaseModManager.cs.

167 {
168 if (handler != null)
169 {
170 (string, Delegate) key = (eventId, handler);
171 if (_typedEventHandlers.TryGetValue(key, out var value))
172 {
173 UnsubscribeEvent(eventId, value);
174 _typedEventHandlers.Remove(key);
175 }
176 }
177 }
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 154 of file BaseModManager.cs.

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

References _eventHandlers.

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

◆ UnsubscribeEvent< T >()

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

Definition at line 179 of file BaseModManager.cs.

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

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: