Elin Decompiled Documentation EA 23.315 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[] fetched PrefetchWorkbook (string file, string[] prefetchNames)
 

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 198 of file SourceImporter.cs.

199 {
200 Debug.Log("#source resetting data...");
201 foreach (SourceData sourceDatum in sourceData)
202 {
203 try
204 {
205 sourceDatum.Reset();
206 sourceDatum.Init();
207 }
208 catch (Exception arg)
209 {
210 Debug.LogError($"#source failed to reset dirty data {sourceDatum.GetType().Name}\n{arg}");
211 }
212 }
213 Debug.Log("#source initialized data");
214 }
override void Reset()
Definition: SourceData.cs:116
override void Init()
Definition: SourceData.cs:83

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

Referenced by ImportFilesCached().

◆ ImportFilesCached()

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

Definition at line 84 of file SourceImporter.cs.

85 {
86 string[] prefetchSheetNames = new string[2] { "Element", "Material" };
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, prefetchSheetNames)).ToArray().ToDictionary(((string file, ISheet[] sheets, ISheet[] fetched) 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 if (sourceCache.IsDirtyOrEmpty)
102 {
103 if (!dictionary.TryGetValue(sourceCache, out var value2) || value2.Item3.Length == 0)
104 {
105 continue;
106 }
107 ISheet[] item = value2.Item3;
108 foreach (ISheet sheet in item)
109 {
110 SourceData.BaseRow[] item2 = LoadBySheetName(sheet, value2.Item1).Item2;
111 if (!item2.IsEmpty())
112 {
113 sourceCache.EmplaceCache(sheet.SheetName, item2);
114 value?.sourceRows.UnionWith(item2);
115 Debug.Log($"#source workbook {arg}:{sheet.SheetName}:{item2.Length}");
116 }
117 }
118 continue;
119 }
120 string[] array3 = prefetchSheetNames;
121 foreach (string text in array3)
122 {
123 if (sourceCache.TryGetCache(text, out var rows))
124 {
125 int num = elements.ImportRows(rows);
126 value?.sourceRows.UnionWith(rows);
127 Debug.Log($"#source workbook-cache {arg}:{text}:{num}");
128 }
129 }
130 }
131 array2 = array;
132 foreach (SourceCache sourceCache2 in array2)
133 {
134 string text2 = sourceCache2.SheetFile.ShortPath();
135 if (sourceCache2.IsDirtyOrEmpty)
136 {
137 if (!dictionary.TryGetValue(sourceCache2, out var value3) || value3.Item2.Length == 0)
138 {
139 continue;
140 }
141 Debug.Log("#source workbook " + text2);
142 ISheet[] item = value3.Item2;
143 foreach (ISheet sheet2 in item)
144 {
145 if (prefetchSheetNames.Contains(sheet2.SheetName))
146 {
147 continue;
148 }
149 var (sourceData, array4) = LoadBySheetName(sheet2, value3.Item1);
150 if ((object)sourceData != null)
151 {
152 int? num2 = array4?.Length;
153 if (num2.HasValue && num2.GetValueOrDefault() > 0)
154 {
155 sourceCache2.EmplaceCache(sheet2.SheetName, array4);
156 sourceCache2.Mod?.sourceRows.UnionWith(array4);
157 hashSet.Add(sourceData);
158 }
159 }
160 }
161 continue;
162 }
163 foreach (KeyValuePair<string, SourceData.BaseRow[]> item3 in sourceCache2.Source)
164 {
165 item3.Deconstruct(out var key, out var value4);
166 string text3 = key;
167 SourceData.BaseRow[] array5 = value4;
168 SourceData sourceData2 = FindSourceByName(text3);
169 if (!(sourceData2 is SourceThingV))
170 {
171 if (sourceData2 is SourceElement || (object)sourceData2 == null)
172 {
173 continue;
174 }
175 }
176 else
177 {
178 sourceData2 = EClass.sources.things;
179 }
180 if (array5 == null)
181 {
182 Debug.Log("#source cached rows are empty " + text2 + ":" + text3);
183 continue;
184 }
185 int num3 = sourceData2.ImportRows(array5);
186 sourceCache2.Mod?.sourceRows.UnionWith(array5);
187 Debug.Log($"#source workbook-cache {text2}:{text3}:{num3}");
188 hashSet.Add(sourceData2);
189 }
190 }
191 if (resetData)
192 {
193 HotInit(hashSet);
194 }
195 return hashSet;
196 }
Definition: EClass.cs:6
static SourceManager sources
Definition: EClass.cs:43
override int ImportRows(IEnumerable< BaseRow > sourceRows)
Definition: SourceData.cs:238
string ISheet[] sheets
static void HotInit(IEnumerable< SourceData > sourceData)
Dictionary< string, EMod > fileProviders
SourceData FindSourceByName(string name)
string ISheet[] ISheet[] fetched PrefetchWorkbook(string file, string[] prefetchNames)
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.

◆ 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 ERROR.lastImported = 0;
65 string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
66 if (!sourceData.ImportData(sheet, fileNameWithoutExtension, overwrite: true))
67 {
68 throw new SourceParseException("#source failed to import data " + sourceData.GetType().Name + ":" + fileNameWithoutExtension + "/" + sheetName);
69 }
70 if (ERROR.lastImported > 0)
71 {
72 SourceData.BaseRow[] item = list2.OfType<SourceData.BaseRow>().Skip(count).Take(ERROR.lastImported)
73 .ToArray();
74 return (sourceData, item);
75 }
76 }
77 catch (Exception arg)
78 {
79 Debug.LogError($"#source failed to load sheet {sheetName}\n{arg}");
80 }
81 return (null, Array.Empty<SourceData.BaseRow>());
82 }
Definition: ERROR.cs:2
static int lastImported
Definition: ERROR.cs:5
override bool ImportData(ISheet sheet, string bookname, bool overwrite=false)
Definition: SourceData.cs:137

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

Referenced by ImportFilesCached().

◆ PrefetchWorkbook()

string ISheet[] ISheet[] fetched SourceImporter.PrefetchWorkbook ( string  file,
string[]  prefetchNames 
)
inlineprivate

Definition at line 216 of file SourceImporter.cs.

217 {
218 using FileStream @is = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
219 XSSFWorkbook xSSFWorkbook = new XSSFWorkbook((Stream)@is);
220 List<ISheet> list = new List<ISheet>();
221 List<ISheet> list2 = new List<ISheet>();
222 for (int i = 0; i < xSSFWorkbook.NumberOfSheets; i++)
223 {
224 ISheet sheetAt = xSSFWorkbook.GetSheetAt(i);
225 if (FindSourceByName(sheetAt.SheetName) != null && prefetchNames.Contains(sheetAt.SheetName))
226 {
227 list2.Add(sheetAt);
228 }
229 else
230 {
231 list.Add(sheetAt);
232 }
233 }
234 Debug.Log("#source workbook-prefetch " + file.ShortPath());
235 return (file: file, sheets: list.ToArray(), fetched: list2.ToArray());
236 }

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 216 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 ImportFilesCached().

◆ sheets

string ISheet [] SourceImporter.sheets
private

Definition at line 216 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: