Elin Decompiled Documentation EA 23.286 Nightly Patch 1
Loading...
Searching...
No Matches
BaseModManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Linq;
5using UnityEngine;
6
7public class BaseModManager
8{
9 [Serializable]
10 public class BaseResource
11 {
12 public string resourcePath;
13
14 public List<string> files;
15
16 public void Parse<T>(ModItemList<T> list) where T : UnityEngine.Object
17 {
18 foreach (string file in files)
19 {
20 list.Add(null, resourcePath + "/" + file);
21 }
22 }
23 }
24
25 public static BaseModManager Instance;
26
27 public static string rootMod;
28
29 public static string rootDefaultPacakge;
30
31 public static bool isInitialized;
32
33 public static List<string> listChainLoad = new List<string>();
34
35 private static readonly Dictionary<string, HashSet<Action<object>>> _eventHandlers = new Dictionary<string, HashSet<Action<object>>>();
36
37 public DirectoryInfo dirWorkshop;
38
39 public int priorityIndex;
40
41 [NonSerialized]
42 public List<BaseModPackage> packages = new List<BaseModPackage>();
43
44 public virtual void Init(string path, string defaultPackage = "_Elona")
45 {
46 Debug.Log("Initializing ModManager:" + defaultPackage + "/" + path);
47 Instance = this;
48 rootMod = (rootDefaultPacakge = path);
49 if (!defaultPackage.IsEmpty())
50 {
51 rootDefaultPacakge = rootMod + defaultPackage + "/";
52 }
53 }
54
55 public void InitLang()
56 {
57 Debug.Log("Initializing Langs: " + Lang.langCode);
58 foreach (LangSetting value in MOD.langs.Values)
59 {
60 if (value.id != Lang.langCode)
61 {
62 continue;
63 }
64 new DirectoryInfo(value.dir);
65 FileInfo[] files = new DirectoryInfo(value.dir + "Data").GetFiles();
66 foreach (FileInfo fileInfo in files)
67 {
68 if (fileInfo.Name == "Alias.xlsx")
69 {
70 Lang.alias = new ExcelData(fileInfo.FullName);
71 }
72 if (fileInfo.Name == "Name.xlsx")
73 {
74 Lang.names = new ExcelData(fileInfo.FullName);
75 }
76 if (fileInfo.Name == "chara_talk.xlsx")
77 {
78 MOD.listTalk.items.Add(new ExcelData(fileInfo.FullName));
79 }
80 if (fileInfo.Name == "chara_tone.xlsx")
81 {
82 MOD.tones.items.Add(new ExcelData(fileInfo.FullName));
83 }
84 }
85 }
86 }
87
88 public virtual void ParseExtra(DirectoryInfo dir, BaseModPackage package)
89 {
90 }
91
92 public static void SubscribeEvent(string eventId, Action<object> handler)
93 {
94 if (!_eventHandlers.TryGetValue(eventId, out var value))
95 {
96 value = new HashSet<Action<object>>();
97 _eventHandlers[eventId] = value;
98 }
99 value.Add(handler);
100 }
101
102 public static void UnsubscribeEvent(string eventId, Action<object> handler)
103 {
104 if (_eventHandlers.TryGetValue(eventId, out var value))
105 {
106 value.Remove(handler);
107 if (value.Count == 0)
108 {
109 _eventHandlers.Remove(eventId);
110 }
111 }
112 }
113
114 public static void PublishEvent(string eventId, object data = null)
115 {
116 if (!_eventHandlers.TryGetValue(eventId, out var value))
117 {
118 return;
119 }
120 foreach (Action<object> item in value.ToList())
121 {
122 try
123 {
124 item(data);
125 }
126 catch (Exception arg)
127 {
128 Debug.LogError($"#event '{eventId}' throws error in one of the handlers\n{arg}");
129 }
130 }
131 }
132
133 public static bool HasEventSubscriber(string eventId)
134 {
135 int? num = _eventHandlers.GetValueOrDefault(eventId)?.Count;
136 if (num.HasValue)
137 {
138 return num.GetValueOrDefault() > 0;
139 }
140 return false;
141 }
142}
$
Definition: ModManager.cs:85
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 bool isInitialized
static string rootDefaultPacakge
virtual void ParseExtra(DirectoryInfo dir, BaseModPackage package)
static BaseModManager Instance
static string rootMod
static void PublishEvent(string eventId, object data=null)
static List< string > listChainLoad
static void SubscribeEvent(string eventId, Action< object > handler)
static bool HasEventSubscriber(string eventId)
DirectoryInfo dirWorkshop
List< ExcelData > items
Definition: ExcelDataList.cs:6
string dir
Definition: LangSetting.cs:28
string id
Definition: LangSetting.cs:22
Definition: Lang.cs:7
static string langCode
Definition: Lang.cs:29
Definition: MOD.cs:7
static TalkDataList listTalk
Definition: MOD.cs:10
static ToneDataList tones
Definition: MOD.cs:12
static Dictionary< string, LangSetting > langs
Definition: MOD.cs:8