Elin Decompiled Documentation EA 23.285 Nightly
Loading...
Searching...
No Matches
SourceImporter Class Reference
Inheritance diagram for SourceImporter:
EClass

Public Member Functions

 SourceImporter (IReadOnlyDictionary< string, SourceData > sourceMapping)
 
SourceData FindSourceByName (string name)
 
IEnumerable< SourceDataImportFilesCached (IEnumerable< string > imports, bool resetData=true)
 

Static Public Member Functions

static void HotInit (IEnumerable< SourceData > sourceData)
 
- Static Public Member Functions inherited from EClass
static int rndSeed (int a, int seed)
 
static int rnd (long a)
 
static int rnd (int a)
 
static int curve (long _a, int start, int step, int rate=75)
 
static int sqrt (int a)
 
static int rndHalf (int a)
 
static float rndf (float a)
 
static int rndSqrt (int a)
 
static void Wait (float a, Card c)
 
static void Wait (float a, Point p)
 
static int Bigger (int a, int b)
 
static int Smaller (int a, int b)
 

Public Attributes

Dictionary< string, EMod > fileProviders = new Dictionary<string, EMod>(PathComparer.Default)
 

Private Member Functions

SourceData.BaseRow[] LoadBySheetName (ISheet sheet, string file)
 
string ISheet[] ISheet element PrefetchWorkbook (string file)
 

Private Attributes

readonly IReadOnlyDictionary< string, SourceData_sourceMapping
 
 SourceData
 
string file
 
string ISheet[] sheets
 

Additional Inherited Members

- Static Public Attributes inherited from EClass
static Core core
 
- Properties inherited from EClass
static Game game [get]
 
static bool AdvMode [get]
 
static Player player [get]
 
static Chara pc [get]
 
static UI ui [get]
 
static Map _map [get]
 
static Zone _zone [get]
 
static FactionBranch Branch [get]
 
static FactionBranch BranchOrHomeBranch [get]
 
static Faction Home [get]
 
static Faction Wilds [get]
 
static Scene scene [get]
 
static BaseGameScreen screen [get]
 
static GameSetting setting [get]
 
static GameData gamedata [get]
 
static ColorProfile Colors [get]
 
static World world [get]
 
static SourceManager sources [get]
 
static SourceManager editorSources [get]
 
static SoundManager Sound [get]
 
static CoreDebug debug [get]
 

Detailed Description

Definition at line 10 of file SourceImporter.cs.

Constructor & Destructor Documentation

◆ SourceImporter()

SourceImporter.SourceImporter ( IReadOnlyDictionary< string, SourceData sourceMapping)
inline

Definition at line 16 of file SourceImporter.cs.

17 {
18 _sourceMapping = sourceMapping;
19 }
readonly IReadOnlyDictionary< string, SourceData > _sourceMapping

References _sourceMapping.

Member Function Documentation

◆ FindSourceByName()

SourceData SourceImporter.FindSourceByName ( string  name)
inline

Definition at line 21 of file SourceImporter.cs.

22 {
23 string[] array = new string[3]
24 {
25 "Source" + name,
26 "Lang" + name,
27 name
28 };
29 foreach (string key in array)
30 {
31 if (_sourceMapping.TryGetValue(key, out var value))
32 {
33 return value;
34 }
35 }
36 return null;
37 }

References _sourceMapping.

Referenced by ImportFilesCached(), and LoadBySheetName().

◆ HotInit()

static void SourceImporter.HotInit ( IEnumerable< SourceData sourceData)
inlinestatic

Definition at line 186 of file SourceImporter.cs.

187 {
188 Debug.Log("#source resetting data...");
189 foreach (SourceData sourceDatum in sourceData)
190 {
191 try
192 {
193 sourceDatum.Reset();
194 sourceDatum.Init();
195 }
196 catch (Exception arg)
197 {
198 Debug.LogError($"#source failed to reset dirty data {sourceDatum.GetType().Name}\n{arg}");
199 }
200 }
201 Debug.Log("#source initialized data");
202 }
$
Definition: ModManager.cs:85
override void Reset()
Definition: SourceData.cs:115
override void Init()
Definition: SourceData.cs:82

References $, Debug, SourceData< T, T2 >.Init(), and SourceData< T, T2 >.Reset().

Referenced by ModManager.ImportAllModSourceSheets(), and ImportFilesCached().

◆ ImportFilesCached()

IEnumerable< SourceData > SourceImporter.ImportFilesCached ( IEnumerable< string >  imports,
bool  resetData = true 
)
inline

Definition at line 85 of file SourceImporter.cs.

86 {
87 SourceCache[] array = imports.Select(SourceCache.GetOrCreate).Distinct().ToArray();
88 Dictionary<SourceCache, (string, ISheet[], ISheet)> dictionary = (from c in array
89 where c.IsDirtyOrEmpty
90 select PrefetchWorkbook(c.SheetFile.FullName)).ToArray().ToDictionary(((string file, ISheet[] sheets, ISheet element) p) => SourceCache.GetOrCreate(p.file));
92 HashSet<SourceData> hashSet = new HashSet<SourceData> { elements };
93 SourceCache[] array2 = array;
94 foreach (SourceCache sourceCache in array2)
95 {
96 string arg = sourceCache.SheetFile.ShortPath();
97 if (fileProviders.TryGetValue(sourceCache.SheetFile.FullName, out var value))
98 {
99 sourceCache.SetMod(value);
100 }
101 SourceData.BaseRow[] rows;
102 if (sourceCache.IsDirtyOrEmpty)
103 {
104 if (dictionary.TryGetValue(sourceCache, out var value2) && value2.Item3 != null)
105 {
106 SourceData.BaseRow[] item = LoadBySheetName(value2.Item3, value2.Item1).Item2;
107 sourceCache.EmplaceCache("Element", item);
108 value?.sourceRows.UnionWith(item);
109 Debug.Log(string.Format("#source workbook {0}:{1}:{2}", arg, "Element", item.Length));
110 }
111 }
112 else if (sourceCache.TryGetCache("Element", out rows))
113 {
114 int num = elements.ImportRows(rows);
115 value?.sourceRows.UnionWith(rows);
116 Debug.Log(string.Format("#source workbook-cache {0}:{1}:{2}", arg, "Element", num));
117 }
118 }
119 array2 = array;
120 foreach (SourceCache sourceCache2 in array2)
121 {
122 string text = sourceCache2.SheetFile.ShortPath();
123 if (sourceCache2.IsDirtyOrEmpty)
124 {
125 if (!dictionary.TryGetValue(sourceCache2, out var value3) || value3.Item2.Length == 0)
126 {
127 continue;
128 }
129 Debug.Log("#source workbook " + text);
130 ISheet[] item2 = value3.Item2;
131 foreach (ISheet sheet in item2)
132 {
133 if (sheet.SheetName == "Element")
134 {
135 continue;
136 }
137 var (sourceData, array3) = LoadBySheetName(sheet, value3.Item1);
138 if ((object)sourceData != null)
139 {
140 int? num2 = array3?.Length;
141 if (num2.HasValue && num2.GetValueOrDefault() > 0)
142 {
143 sourceCache2.EmplaceCache(sheet.SheetName, array3);
144 sourceCache2.Mod?.sourceRows.UnionWith(array3);
145 hashSet.Add(sourceData);
146 }
147 }
148 }
149 continue;
150 }
151 foreach (KeyValuePair<string, SourceData.BaseRow[]> item3 in sourceCache2.Source)
152 {
153 item3.Deconstruct(out var key, out var value4);
154 string text2 = key;
155 SourceData.BaseRow[] array4 = value4;
156 SourceData sourceData2 = FindSourceByName(text2);
157 if (!(sourceData2 is SourceThingV))
158 {
159 if (sourceData2 is SourceElement || (object)sourceData2 == null)
160 {
161 continue;
162 }
163 }
164 else
165 {
166 sourceData2 = EClass.sources.things;
167 }
168 if (array4 == null)
169 {
170 Debug.Log("#source cached rows are empty " + text + ":" + text2);
171 continue;
172 }
173 int num3 = sourceData2.ImportRows(array4);
174 sourceCache2.Mod?.sourceRows.UnionWith(array4);
175 Debug.Log($"#source workbook-cache {text}:{text2}:{num3}");
176 hashSet.Add(sourceData2);
177 }
178 }
179 if (resetData)
180 {
181 HotInit(hashSet);
182 }
183 return hashSet;
184 }
Definition: EClass.cs:6
static SourceManager sources
Definition: EClass.cs:43
override int ImportRows(IEnumerable< BaseRow > sourceRows)
Definition: SourceData.cs:176
string ISheet[] sheets
string ISheet[] ISheet element PrefetchWorkbook(string file)
static void HotInit(IEnumerable< SourceData > sourceData)
Dictionary< string, EMod > fileProviders
SourceData FindSourceByName(string name)
SourceData.BaseRow[] LoadBySheetName(ISheet sheet, string file)
SourceThing things
SourceElement elements

References $, Debug, SourceManager.elements, file, fileProviders, FindSourceByName(), HotInit(), SourceData< T, T2 >.ImportRows(), item, LoadBySheetName(), PrefetchWorkbook(), sheets, EClass.sources, and SourceManager.things.

Referenced by ModManager.ImportAllModSourceSheets().

◆ LoadBySheetName()

SourceData.BaseRow[] SourceImporter.LoadBySheetName ( ISheet  sheet,
string  file 
)
inlineprivate

Definition at line 39 of file SourceImporter.cs.

40 {
41 string sheetName = sheet.SheetName;
42 try
43 {
44 SourceData sourceData = FindSourceByName(sheetName);
45 if ((object)sourceData == null)
46 {
47 Debug.Log("#source skipping sheet " + sheetName);
48 return (null, null);
49 }
50 IList list;
51 if (!(sourceData is SourceThingV))
52 {
53 list = sourceData.GetField<IList>("rows");
54 }
55 else
56 {
57 IList rows = EClass.sources.things.rows;
58 list = rows;
59 }
60 IList list2 = list;
61 int count = list2.Count;
62 Debug.Log("#source loading sheet " + sheetName);
63 ExcelParser.path = file;
64 string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
65 if (!sourceData.ImportData(sheet, fileNameWithoutExtension, overwrite: true))
66 {
67 throw new SourceParseException("#source failed to import data " + sourceData.GetType().Name + ":" + fileNameWithoutExtension + "/" + sheetName);
68 }
69 SourceData.BaseRow[] item = Array.Empty<SourceData.BaseRow>();
70 int num = ERROR.msg.Split('/')[^1].ToInt();
71 if (num > 0)
72 {
73 item = list2.OfType<SourceData.BaseRow>().Skip(count).Take(num)
74 .ToArray();
75 }
76 return (sourceData, item);
77 }
78 catch (Exception arg)
79 {
80 Debug.LogError($"#source failed to load sheet {sheetName}\n{arg}");
81 }
82 return (null, null);
83 }
Definition: ERROR.cs:2
static string msg
Definition: ERROR.cs:3
override bool ImportData(ISheet sheet, string bookname, bool overwrite=false)
Definition: SourceData.cs:136

References $, Debug, file, FindSourceByName(), SourceData< T, T2 >.ImportData(), item, ERROR.msg, EClass.sources, and SourceManager.things.

Referenced by ImportFilesCached().

◆ PrefetchWorkbook()

string ISheet[] ISheet element SourceImporter.PrefetchWorkbook ( string  file)
inlineprivate

Definition at line 204 of file SourceImporter.cs.

205 {
206 using FileStream @is = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
207 XSSFWorkbook xSSFWorkbook = new XSSFWorkbook((Stream)@is);
208 List<ISheet> list = new List<ISheet>();
209 ISheet item = null;
210 for (int i = 0; i < xSSFWorkbook.NumberOfSheets; i++)
211 {
212 ISheet sheetAt = xSSFWorkbook.GetSheetAt(i);
213 SourceData sourceData = FindSourceByName(sheetAt.SheetName);
214 if (!(sourceData is SourceElement))
215 {
216 if ((object)sourceData != null)
217 {
218 list.Add(sheetAt);
219 }
220 }
221 else
222 {
223 item = sheetAt;
224 }
225 }
226 Debug.Log("#source workbook-prefetch " + file.ShortPath());
227 return (file: file, sheets: list.ToArray(), element: item);
228 }

Referenced by ImportFilesCached().

Member Data Documentation

◆ _sourceMapping

readonly IReadOnlyDictionary<string, SourceData> SourceImporter._sourceMapping
private

Definition at line 12 of file SourceImporter.cs.

Referenced by FindSourceByName(), and SourceImporter().

◆ file

string SourceImporter.file
private

Definition at line 204 of file SourceImporter.cs.

Referenced by ImportFilesCached(), and LoadBySheetName().

◆ fileProviders

Dictionary<string, EMod> SourceImporter.fileProviders = new Dictionary<string, EMod>(PathComparer.Default)

Definition at line 14 of file SourceImporter.cs.

Referenced by ModManager.ImportAllModSourceSheets(), and ImportFilesCached().

◆ sheets

string ISheet [] SourceImporter.sheets
private

Definition at line 204 of file SourceImporter.cs.

Referenced by ImportFilesCached().

◆ SourceData

SourceImporter.SourceData
private

Definition at line 39 of file SourceImporter.cs.


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