Elin Decompiled Documentation EA 23.315 Nightly
Loading...
Searching...
No Matches
SourceData.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Linq;
5using System.Reflection;
6using NPOI.SS.UserModel;
7using NPOI.SS.Util;
8using NPOI.XSSF.UserModel;
9using UnityEngine;
10
11public class SourceData<T, T2> : SourceData where T : SourceData.BaseRow
12{
13 public class FieldInfo
14 {
15 public string id;
16
17 public string name;
18
19 public bool isStatic;
20
21 public int width;
22
23 public int column;
24
25 public bool IsIndex => id == "id";
26
27 public string GetValue(T r)
28 {
29 if (r.HasField<string>(id))
30 {
31 return r.GetField<string>(id);
32 }
33 if (r.HasField<int>(id))
34 {
35 return r.GetField<int>(id).ToString();
36 }
37 if (r.HasField<string[]>(id))
38 {
39 string text = "";
40 string[] field = r.GetField<string[]>(id);
41 if (field != null)
42 {
43 string[] array = field;
44 foreach (string text2 in array)
45 {
46 text = text + text2 + ",";
47 }
48 }
49 return text.TrimEnd(',');
50 }
51 return "";
52 }
53 }
54
55 public class FieldMap
56 {
58
59 public int column;
60 }
61
62 public List<T> rows = new List<T>();
63
64 public Dictionary<T2, T> map = new Dictionary<T2, T>();
65
66 public Dictionary<string, T> alias = new Dictionary<string, T>();
67
68 [NonSerialized]
69 public bool initialized;
70
71 [NonSerialized]
72 private List<T> _backupRows = new List<T>();
73
74 [NonSerialized]
75 public List<string> editorListString = new List<string>();
76
77 public static ISheet currentSheet;
78
79 public virtual bool AllowHotInitialization => false;
80
81 public virtual string[] ImportFields => new string[1] { "" };
82
83 public override void Init()
84 {
85 Debug.Log("Initializing:" + base.name);
86 if (initialized)
87 {
88 Debug.Log("#init Skipping sourceData.Init:" + base.name);
89 return;
90 }
91 initialized = true;
92 editorListString.Clear();
94 int num = 0;
95 foreach (T row in rows)
96 {
97 SetRow(row);
98 if (row.UseAlias)
99 {
100 alias[row.GetAlias] = row;
101 }
102 row._index = num;
103 num++;
104 }
105 OnInit();
106 }
107
108 public virtual void OnInit()
109 {
110 }
111
112 public virtual void SetRow(T row)
113 {
114 }
115
116 public override void Reset()
117 {
118 initialized = false;
119 if (!Application.isPlaying)
120 {
121 BaseCore.resetRuntime = true;
122 }
123 if (map != null)
124 {
125 map.Clear();
126 }
127 if (alias != null)
128 {
129 alias.Clear();
130 }
131 if (Application.isPlaying && AllowHotInitialization)
132 {
133 Init();
134 }
135 }
136
137 public override bool ImportData(ISheet sheet, string bookname, bool overwrite = false)
138 {
139 if (!overwrite)
140 {
141 rows = new List<T>();
142 }
143 isNew = true;
144 nameSheet = sheet.SheetName;
145 nameBook = bookname;
146 SourceData.rowHeader = sheet.GetRow(0);
147 SourceData.rowDefault = sheet.GetRow(2);
148 IRow row = sheet.GetRow(3);
149 if (SourceData.rowHeader == null || row == null)
150 {
151 ERROR.lastImported = 0;
152 return true;
153 }
154 IReadOnlyDictionary<string, int> rowMapping = GetRowMapping();
155 Dictionary<string, int> header = null;
156 if (rowMapping != null)
157 {
158 header = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
159 foreach (ICell cell in SourceData.rowHeader.Cells)
160 {
161 string text = cell.ToString().Trim();
162 if (!(text == "0") && !text.IsEmpty())
163 {
164 header[text] = cell.ColumnIndex;
165 }
166 }
167 if (!rowMapping.All((KeyValuePair<string, int> kv) => header.TryGetValue(kv.Key, 0) == kv.Value))
168 {
169 string[] array = rowMapping.Keys.Except(header.Keys).ToArray();
170 if (array.Length != 0)
171 {
172 Debug.LogWarning("#source ill-format file with missing columns, init with empty values\n" + ExcelParser.GetRowHeaderDiff(rowMapping, header));
173 string[] array2 = array;
174 foreach (string text2 in array2)
175 {
176 SourceData.rowHeader.CreateCell(276, CellType.String).SetCellValue(text2);
177 header[text2] = 276;
178 }
179 }
180 else
181 {
182 Debug.Log("#source ill-format file with reordered columns");
183 }
184 }
185 else
186 {
187 header = null;
188 }
189 }
190 int num = 0;
191 for (int j = 3; j <= sheet.LastRowNum; j++)
192 {
193 SourceData.row = sheet.GetRow(j);
194 try
195 {
196 if (string.IsNullOrEmpty(SourceData.row?.GetCell(0)?.ToString()))
197 {
198 break;
199 }
200 T val = ((header != null) ? CreateRowByMapping(header) : CreateRow());
201 val.OnImportData(this);
202 rows.Add(val);
203 num++;
204 continue;
205 }
206 catch (Exception arg)
207 {
208 Debug.LogError($"#source failed to create row#{j + 1}\n{arg}");
209 continue;
210 }
211 }
212 Debug.Log(sheet.SheetName + "/" + sheet.LastRowNum + "/" + num);
213 ERROR.lastImported = num;
215 initialized = false;
216 return true;
217 }
218
219 public virtual void OnAfterImportData()
220 {
221 }
222
223 public virtual T CreateRow()
224 {
225 return null;
226 }
227
228 public virtual T CreateRowByMapping(IReadOnlyDictionary<string, int> mapping)
229 {
230 return null;
231 }
232
233 public override BaseRow[] ExportRows()
234 {
235 return rows.OfType<BaseRow>().ToArray();
236 }
237
238 public override int ImportRows(IEnumerable<BaseRow> sourceRows)
239 {
240 int num = 0;
241 foreach (BaseRow sourceRow in sourceRows)
242 {
243 if (sourceRow is T val)
244 {
245 val.OnImportData(this);
246 rows.Add(val);
247 num++;
248 }
249 }
251 initialized = false;
252 return num;
253 }
254
255 public virtual void RemoveDuplicateRows()
256 {
257 HashSet<T2> hashSet = new HashSet<T2>();
258 List<T> list = new List<T>(rows.Count);
259 string arg = GetType().Name;
260 System.Reflection.FieldInfo field = typeof(T).GetField("id");
261 bool flag = typeof(LangRow).IsAssignableFrom(typeof(T));
262 if (field == null)
263 {
264 return;
265 }
266 if (field.FieldType != typeof(T2))
267 {
268 Debug.LogError($"#source-override: {arg} id field mismatch {field.FieldType} != {typeof(T2)}");
269 }
270 for (int num = rows.Count - 1; num >= 0; num--)
271 {
272 T val = rows[num];
273 T2 val2 = (T2)field.GetValue(val);
274 if (hashSet.Add(val2))
275 {
276 list.Add(val);
277 }
278 else if (!flag)
279 {
280 Debug.Log($"#source-override: {arg} {val2}");
281 }
282 }
283 if (rows.Count != list.Count)
284 {
285 Debug.Log($"#source-override: {arg} total/{rows.Count} -> unique/{list.Count}");
286 list.Reverse();
287 rows = list;
288 }
289 }
290
291 public override void BackupSource()
292 {
294 }
295
296 public override void RollbackSource()
297 {
299 }
300
301 public List<string> GetListString()
302 {
303 return BuildEditorList().editorListString;
304 }
305
307 {
308 if (editorListString.Count == 0)
309 {
310 foreach (T row in rows)
311 {
312 editorListString.Add(row.GetEditorListName());
313 }
314 }
315 return this;
316 }
317
318 public List<FieldInfo> GetFields()
319 {
320 List<FieldInfo> list = new List<FieldInfo>();
321 int x = 0;
322 AddField("id", 4096);
323 AddField("version", 4096);
324 AddField("filter", 4096);
325 AddField("name", 4096);
326 AddField("text", 4096);
327 AddField("detail", 4096);
328 AddField("description", 4096);
329 string[] importFields = ImportFields;
330 foreach (string text in importFields)
331 {
332 if (!text.IsEmpty())
333 {
334 AddField(text, 4096);
335 }
336 }
337 return list;
338 void AddField(string id, int width)
339 {
340 bool flag = id == "id" || id == "filter";
341 bool flag2 = id == "version";
342 if (!(typeof(T).GetField(id) == null) || flag2)
343 {
344 list.Add(new FieldInfo
345 {
346 id = id,
347 name = id,
348 isStatic = flag,
349 width = width,
350 column = x
351 });
352 x++;
353 if (!(flag || flag2))
354 {
355 list.Add(new FieldInfo
356 {
357 id = id,
358 name = id + "_EN",
359 isStatic = true,
360 width = width,
361 column = x
362 });
363 x++;
364 list.Add(new FieldInfo
365 {
366 id = id + "_JP",
367 name = id + "_JP",
368 isStatic = true,
369 width = width,
370 column = x
371 });
372 x++;
373 }
374 }
375 }
376 }
377
378 public virtual T GetRow(string id)
379 {
380 return null;
381 }
382
383 public override void ExportTexts(string path, bool update = false)
384 {
385 Debug.Log("Exporting:" + nameSheet + " path:" + path);
386 string text = nameSheet + ".xlsx";
387 XSSFWorkbook xSSFWorkbook = new XSSFWorkbook();
388 List<FieldInfo> fields = GetFields();
389 currentSheet = xSSFWorkbook.CreateSheet(nameSheet);
390 int num = 0;
391 int y = 0;
392 foreach (FieldInfo item in fields)
393 {
394 GetCell(num, y).SetCellValue(item.name);
395 currentSheet.SetColumnWidth(num, item.width);
396 ICellStyle cellStyle = xSSFWorkbook.CreateCellStyle();
397 cellStyle.FillForegroundColor = 44;
398 cellStyle.FillPattern = FillPattern.SolidForeground;
399 if (!item.isStatic && item.id != "version")
400 {
401 GetCell(num, y).CellStyle = cellStyle;
402 }
403 num++;
404 }
405 string cellValue = BaseCore.Instance.version.GetText() ?? "";
406 y = 2;
407 foreach (T row4 in rows)
408 {
409 foreach (FieldInfo item2 in fields)
410 {
411 if (item2.isStatic)
412 {
413 GetCell(item2.column, y).SetCellValue(item2.GetValue(row4));
414 }
415 else if (item2.id == "version")
416 {
417 GetCell(item2.column, y).SetCellValue(cellValue);
418 }
419 }
420 y++;
421 }
422 currentSheet.CreateFreezePane(0, 2);
423 currentSheet.SetAutoFilter(new CellRangeAddress(1, 1, 0, fields.Count - 1));
424 if (update)
425 {
426 Dictionary<string, int> dictionary = new Dictionary<string, int>();
427 if (!File.Exists(path + "_temp/" + text))
428 {
429 return;
430 }
431 XSSFWorkbook xSSFWorkbook2;
432 using (FileStream @is = File.Open(path + "_temp/" + text, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
433 {
434 xSSFWorkbook2 = new XSSFWorkbook((Stream)@is);
435 }
436 ISheet sheetAt = xSSFWorkbook2.GetSheetAt(0);
437 IRow row = sheetAt.GetRow(0);
438 int num2 = 0;
439 foreach (FieldInfo item3 in fields)
440 {
441 if (item3.isStatic)
442 {
443 continue;
444 }
445 int num3 = -1;
446 for (int i = 0; i < row.LastCellNum; i++)
447 {
448 string stringCellValue = row.GetCell(i).StringCellValue;
449 if (stringCellValue.IsEmpty())
450 {
451 break;
452 }
453 if (stringCellValue == item3.id)
454 {
455 num3 = i;
456 break;
457 }
458 }
459 if (num3 == -1)
460 {
461 continue;
462 }
463 dictionary.Add(item3.id, 0);
464 for (y = 2; y <= sheetAt.LastRowNum; y++)
465 {
466 IRow row2 = sheetAt.GetRow(y);
467 if (row2 == null)
468 {
469 if (y > 5)
470 {
471 break;
472 }
473 continue;
474 }
475 ICell cell = row2.GetCell(0);
476 if (cell == null)
477 {
478 continue;
479 }
480 string text2 = ((cell.CellType == CellType.Numeric) ? cell.NumericCellValue.ToString() : cell.StringCellValue);
481 if (text2.IsEmpty())
482 {
483 continue;
484 }
485 for (int j = 0; j <= currentSheet.LastRowNum; j++)
486 {
487 IRow row3 = currentSheet.GetRow(j);
488 if (row3 == null)
489 {
490 if (j > 5)
491 {
492 break;
493 }
494 continue;
495 }
496 ICell cell2 = row3.GetCell(0);
497 if (cell2 == null || cell2.StringCellValue != text2)
498 {
499 continue;
500 }
501 string text3 = row2.GetCell(num3)?.StringCellValue ?? "";
502 if (text3.IsEmpty())
503 {
504 continue;
505 }
506 (row3.GetCell(item3.column) ?? row3.CreateCell(item3.column)).SetCellValue(text3);
507 if (item3.id != "version")
508 {
509 ICell cell3 = row3.GetCell(item3.column + 2);
510 ICell cell4 = row2.GetCell(num3 + 2);
511 if (cell3 == null)
512 {
513 continue;
514 }
515 if (cell4 == null || cell3.StringCellValue != cell4.StringCellValue)
516 {
517 row3.GetCell(1).SetCellValue(cellValue);
518 }
519 num2++;
520 }
521 dictionary[item3.id]++;
522 }
523 }
524 }
525 Log.system = Log.system + ((num2 == 0) ? "(No Changes) " : "(Updated) ") + path + "/" + text + Environment.NewLine;
526 if (num2 != 0)
527 {
528 foreach (KeyValuePair<string, int> item4 in dictionary)
529 {
530 Log.system = Log.system + item4.Key + ":" + item4.Value + " ";
531 }
532 Log.system += Environment.NewLine;
533 }
534 Log.system += Environment.NewLine;
535 }
536 if (!Directory.Exists(path))
537 {
538 Directory.CreateDirectory(path);
539 }
540 using FileStream stream = new FileStream(path + "/" + text, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
541 xSSFWorkbook.Write(stream);
542 }
543
544 public override void ValidateLang()
545 {
546 string langImportMod = CorePath.CorePackage.LangImportMod;
547 string text = nameSheet + ".xlsx";
548 Log.system = Log.system + langImportMod + text + Environment.NewLine;
549 Log.system += Environment.NewLine;
550 }
551
552 public override void ImportTexts(string _nameSheet = null)
553 {
554 string langImportMod = CorePath.CorePackage.LangImportMod;
555 string text = _nameSheet.IsEmpty(nameSheet) + ".xlsx";
556 if (!File.Exists(langImportMod + text))
557 {
558 return;
559 }
560 XSSFWorkbook xSSFWorkbook;
561 using (FileStream @is = File.Open(langImportMod + text, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
562 {
563 xSSFWorkbook = new XSSFWorkbook((Stream)@is);
564 }
565 ISheet sheetAt = xSSFWorkbook.GetSheetAt(0);
566 List<FieldInfo> fields = GetFields();
567 IRow row = sheetAt.GetRow(0);
568 List<FieldMap> list = new List<FieldMap>();
569 foreach (FieldInfo item in fields)
570 {
571 if (item.isStatic)
572 {
573 continue;
574 }
575 for (int i = 0; i < row.LastCellNum; i++)
576 {
577 string stringCellValue = row.GetCell(i).StringCellValue;
578 if (stringCellValue.IsEmpty())
579 {
580 break;
581 }
582 if (stringCellValue == item.id)
583 {
584 list.Add(new FieldMap
585 {
586 field = item,
587 column = i
588 });
589 break;
590 }
591 }
592 }
593 for (int j = 2; j <= sheetAt.LastRowNum; j++)
594 {
595 IRow row2 = sheetAt.GetRow(j);
596 T val = GetRow(row2.GetCell(0).StringCellValue);
597 if (val == null)
598 {
599 Debug.Log(sheetAt.SheetName + ": id to import no longer exist: " + row2.GetCell(0).StringCellValue);
600 break;
601 }
602 foreach (FieldMap item2 in list)
603 {
604 FieldInfo field = item2.field;
605 System.Reflection.FieldInfo field2 = val.GetType().GetField(field.id + "_L");
606 if (field2 == null)
607 {
608 continue;
609 }
610 if (typeof(string[]).IsAssignableFrom(field2.FieldType))
611 {
612 ICell cell = row2.GetCell(item2.column);
613 string[] array = ((cell == null) ? new string[0] : cell.StringCellValue.Split(','));
614 string[] field3 = val.GetField<string[]>(field.id);
615 if (field3 != null)
616 {
617 field2.SetValue(val, (array.Length >= field3.Length) ? array : field3);
618 }
619 }
620 else
621 {
622 ICell cell2 = row2.GetCell(item2.column);
623 if (cell2 != null)
624 {
625 field2.SetValue(val, cell2.StringCellValue.IsEmpty(val.GetField<string>(field.id)));
626 }
627 }
628 }
629 }
630 }
631
632 public static ICell GetCell(int x, int y)
633 {
634 IRow row = currentSheet.GetRow(y) ?? currentSheet.CreateRow(y);
635 return row.GetCell(x) ?? row.CreateCell(x);
636 }
637}
638public class SourceData : ScriptableObject
639{
640 public enum AutoID
641 {
642 None,
643 Auto
644 }
645
646 [Serializable]
647 public class BaseRow
648 {
649 private static readonly Dictionary<Type, Dictionary<string, FieldInfo>> _fieldCache = new Dictionary<Type, Dictionary<string, FieldInfo>>();
650
651 public int _index;
652
653 public virtual bool UseAlias => false;
654
655 public virtual string GetAlias => "";
656
657 public Dictionary<string, FieldInfo> GetRowFields()
658 {
659 Type type = GetType();
660 if (_fieldCache.TryGetValue(type, out var value))
661 {
662 return value;
663 }
664 value = new Dictionary<string, FieldInfo>();
665 FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);
666 foreach (FieldInfo fieldInfo in fields)
667 {
668 value[fieldInfo.Name] = fieldInfo;
669 }
670 return _fieldCache[type] = value;
671 }
672
673 public virtual string GetName()
674 {
675 return GetText();
676 }
677
678 public string GetDetail()
679 {
680 return GetText("detail");
681 }
682
683 public virtual string GetEditorListName()
684 {
685 return this.GetField<int>("id") + "-" + this.GetField<string>("alias") + "(" + this.GetField<string>("name_JP") + ")";
686 }
687
688 public string GetText(string id = "name", bool returnNull = false)
689 {
690 Dictionary<string, FieldInfo> rowFields = GetRowFields();
691 if (rowFields.TryGetValue(id + LangSuffix, out var value))
692 {
693 string text = value.GetValue(this) as string;
694 if (!text.IsEmpty())
695 {
696 return text;
697 }
698 }
699 if (!Lang.isBuiltin && rowFields.TryGetValue(id, out var value2))
700 {
701 string text2 = value2.GetValue(this) as string;
702 if (!text2.IsEmpty())
703 {
704 return text2;
705 }
706 }
707 if (!returnNull)
708 {
709 return "";
710 }
711 return null;
712 }
713
714 public string[] GetTextArray(string id)
715 {
716 Dictionary<string, FieldInfo> rowFields = GetRowFields();
717 if (rowFields.TryGetValue(id + LangSuffix, out var value) && value.GetValue(this) is string[] { Length: >0 } array)
718 {
719 return array;
720 }
721 if (!Lang.isBuiltin && rowFields.TryGetValue(id, out var value2) && value2.GetValue(this) is string[] { Length: >0 } array2)
722 {
723 return array2;
724 }
725 return Array.Empty<string>();
726 }
727
728 public virtual void SetID(ref int count)
729 {
730 this.SetField("id", count);
731 count++;
732 }
733
734 public virtual void OnImportData(SourceData data)
735 {
736 }
737
738 public virtual IDictionary<string, string> ExportTexts(string idField = "id")
739 {
740 Dictionary<string, FieldInfo> rowFields = GetRowFields();
741 object obj = rowFields.GetValueOrDefault(idField)?.GetValue(this);
742 SortedDictionary<string, string> sortedDictionary = new SortedDictionary<string, string>();
743 if (obj == null)
744 {
745 return sortedDictionary;
746 }
747 string name = GetType().DeclaringType.Name;
748 foreach (var (text2, jp2) in rowFields)
749 {
750 if (!text2.EndsWith("_JP"))
751 {
752 continue;
753 }
754 string text3 = text2[..^3];
755 if (rowFields.TryGetValue(text3, out var value) && rowFields.TryGetValue(text3 + "_L", out var value2))
756 {
757 string text4 = GetFieldText(jp2, value, value2);
758 if (!text4.IsEmpty())
759 {
760 sortedDictionary[$"{name}.{obj}.{text3}"] = text4;
761 }
762 }
763 }
764 return sortedDictionary;
765 string GetFieldText(FieldInfo jp, FieldInfo en, FieldInfo l)
766 {
767 object value3 = jp.GetValue(this);
768 object value4 = en.GetValue(this);
769 object value5 = l.GetValue(this);
770 string langCode = Lang.langCode;
771 object obj2 = ((langCode == "JP") ? value3 : ((!(langCode == "EN")) ? (value5 ?? value4) : value4));
772 object obj3 = obj2;
773 if (obj3 is string str)
774 {
775 return str.IsEmpty(value4 as string);
776 }
777 if (obj3 is string[] array)
778 {
779 return string.Join(',', (array.Length != 0) ? array : (value4 as string[]));
780 }
781 return null;
782 }
783 }
784
785 public virtual void ImportTexts(IReadOnlyDictionary<string, string> texts, string idField = "id")
786 {
787 Dictionary<string, FieldInfo> rowFields = GetRowFields();
788 object obj = rowFields.GetValueOrDefault(idField)?.GetValue(this);
789 if (obj == null)
790 {
791 return;
792 }
793 string name = GetType().DeclaringType.Name;
794 string langCode = Lang.langCode;
795 foreach (var (text2, fieldInfo2) in rowFields)
796 {
797 if (!text2.EndsWith("_L"))
798 {
799 continue;
800 }
801 string text3 = text2[..^2];
802 if (!texts.TryGetValue($"{name}.{obj}.{text3}", out var value2) || value2.IsEmpty() || !rowFields.TryGetValue(text3, out var value3) || !rowFields.TryGetValue(text3 + "_JP", out var value4))
803 {
804 continue;
805 }
806 fieldInfo2.SetValue(this, null);
807 SetFieldText(fieldInfo2, value2);
808 if (!(langCode == "EN"))
809 {
810 if (langCode == "JP")
811 {
812 SetFieldText(value4, value2);
813 }
814 }
815 else
816 {
817 SetFieldText(value3, value2);
818 }
819 }
820 void SetFieldText(FieldInfo l, string value)
821 {
822 if (l.FieldType == typeof(string))
823 {
824 l.SetValue(this, value);
825 }
826 else if (l.FieldType == typeof(string[]))
827 {
828 l.SetValue(this, value.IsEmpty() ? Array.Empty<string>() : value.Split(','));
829 }
830 }
831 }
832 }
833
834 public static string LangSuffix;
835
836 public static string dataPath;
837
839
840 public bool isNew = true;
841
842 public string nameSheet;
843
844 public string nameBook;
845
846 public virtual string sheetName => "";
847
848 public virtual string sourcePath => "";
849
850 public static IRow row
851 {
852 get
853 {
854 return ExcelParser.row;
855 }
856 set
857 {
858 ExcelParser.row = value;
859 }
860 }
861
862 public static IRow rowDefault
863 {
864 get
865 {
866 return ExcelParser.rowDefault;
867 }
868 set
869 {
870 ExcelParser.rowDefault = value;
871 }
872 }
873
874 public static IRow rowHeader
875 {
876 get
877 {
878 return ExcelParser.rowHeader;
879 }
880 set
881 {
882 ExcelParser.rowHeader = value;
883 }
884 }
885
886 public void BuildFlags(string rawText, Dictionary<string, bool> map)
887 {
888 if (!string.IsNullOrEmpty(rawText))
889 {
890 string[] array = rawText.Split(',');
891 foreach (string key in array)
892 {
893 map.Add(key, value: true);
894 }
895 }
896 }
897
898 public virtual void Reset()
899 {
900 }
901
902 public virtual void InsertData(IRow row)
903 {
904 }
905
906 public virtual void Init()
907 {
908 }
909
910 public virtual string[] GetList(string id)
911 {
912 return null;
913 }
914
915 public virtual bool ImportData(ISheet sheet, string bookname, bool overwrite = false)
916 {
917 return false;
918 }
919
920 public virtual int ImportRows(IEnumerable<BaseRow> sourceRows)
921 {
922 return 0;
923 }
924
925 public virtual BaseRow[] ExportRows()
926 {
927 return Array.Empty<BaseRow>();
928 }
929
930 public virtual void BackupSource()
931 {
932 }
933
934 public virtual void RollbackSource()
935 {
936 }
937
938 public virtual void BackupPref()
939 {
940 }
941
942 public virtual void RestorePref()
943 {
944 }
945
946 public virtual void ValidatePref()
947 {
948 }
949
950 public virtual void ExportTexts(string path, bool update = false)
951 {
952 }
953
954 public virtual void ImportTexts(string _nameSheet = null)
955 {
956 }
957
958 public virtual void ValidateLang()
959 {
960 }
961
962 public virtual IReadOnlyDictionary<string, int> GetRowMapping()
963 {
964 return null;
965 }
966
967 public virtual IReadOnlyDictionary<string, string> GetTypeMapping()
968 {
969 return null;
970 }
971
972 public static bool IsNull(ICell cell)
973 {
974 if (cell != null && cell.CellType != CellType.Blank)
975 {
976 return cell.CellType == CellType.Unknown;
977 }
978 return true;
979 }
980
981 public static int GetInt(int id)
982 {
983 return ExcelParser.GetInt(id);
984 }
985
986 public static bool GetBool(int id)
987 {
988 return ExcelParser.GetBool(id);
989 }
990
991 public static double GetDouble(int id)
992 {
993 return ExcelParser.GetDouble(id);
994 }
995
996 public static float GetFloat(int id)
997 {
998 return ExcelParser.GetFloat(id);
999 }
1000
1001 public static float[] GetFloatArray(int id)
1002 {
1003 return ExcelParser.GetFloatArray(id);
1004 }
1005
1006 public static int[] GetIntArray(int id)
1007 {
1008 return ExcelParser.GetIntArray(id);
1009 }
1010
1011 public static string[] GetStringArray(int id)
1012 {
1013 return ExcelParser.GetStringArray(id);
1014 }
1015
1016 public static string GetString(int id)
1017 {
1018 return ExcelParser.GetString(id);
1019 }
1020
1021 public static string GetStr(int id, bool useDefault = false)
1022 {
1023 return ExcelParser.GetStr(id, useDefault);
1024 }
1025}
Version version
Definition: BaseCore.cs:17
static BaseCore Instance
Definition: BaseCore.cs:11
static string LangImportMod
Definition: CorePath.cs:81
static bool GetBool(int id)
Definition: ExcelParser.cs:51
static string GetRowHeaderDiff(IReadOnlyDictionary< string, int > mapping, IReadOnlyDictionary< string, int > header)
Definition: ExcelParser.cs:228
static IRow rowDefault
Definition: ExcelParser.cs:14
static int GetInt(int id)
Definition: ExcelParser.cs:27
static IRow row
Definition: ExcelParser.cs:12
static string GetString(int id)
Definition: ExcelParser.cs:153
static int[] GetIntArray(int id)
Definition: ExcelParser.cs:118
static float GetFloat(int id)
Definition: ExcelParser.cs:84
static double GetDouble(int id)
Definition: ExcelParser.cs:70
static string GetStr(int id, bool useDefault=false)
Definition: ExcelParser.cs:164
static float[] GetFloatArray(int id)
Definition: ExcelParser.cs:98
static IRow rowHeader
Definition: ExcelParser.cs:16
static string[] GetStringArray(int id)
Definition: ExcelParser.cs:143
Definition: Lang.cs:7
static string langCode
Definition: Lang.cs:29
static bool isBuiltin
Definition: Lang.cs:43
virtual string GetEditorListName()
Definition: SourceData.cs:683
string GetDetail()
Definition: SourceData.cs:678
string[] GetTextArray(string id)
Definition: SourceData.cs:714
virtual string GetAlias
Definition: SourceData.cs:655
virtual void SetID(ref int count)
Definition: SourceData.cs:728
virtual string GetName()
Definition: SourceData.cs:673
string GetText(string id="name", bool returnNull=false)
Definition: SourceData.cs:688
virtual bool UseAlias
Definition: SourceData.cs:653
virtual IDictionary< string, string > ExportTexts(string idField="id")
Definition: SourceData.cs:738
static readonly Dictionary< Type, Dictionary< string, FieldInfo > > _fieldCache
Definition: SourceData.cs:649
virtual void OnImportData(SourceData data)
Definition: SourceData.cs:734
virtual void ImportTexts(IReadOnlyDictionary< string, string > texts, string idField="id")
Definition: SourceData.cs:785
Dictionary< string, FieldInfo > GetRowFields()
Definition: SourceData.cs:657
string GetValue(T r)
Definition: SourceData.cs:27
static float GetFloat(int id)
Definition: SourceData.cs:996
virtual string[] ImportFields
Definition: SourceData.cs:81
static string[] GetStringArray(int id)
Definition: SourceData.cs:1011
virtual void SetRow(T row)
Definition: SourceData.cs:112
static IRow rowHeader
Definition: SourceData.cs:875
override bool ImportData(ISheet sheet, string bookname, bool overwrite=false)
Definition: SourceData.cs:137
static string GetString(int id)
Definition: SourceData.cs:1016
static IRow row
Definition: SourceData.cs:851
static bool GetBool(int id)
Definition: SourceData.cs:986
override void RollbackSource()
Definition: SourceData.cs:296
virtual BaseRow[] ExportRows()
Definition: SourceData.cs:925
override void ExportTexts(string path, bool update=false)
Definition: SourceData.cs:383
static bool IsNull(ICell cell)
Definition: SourceData.cs:972
virtual string[] GetList(string id)
Definition: SourceData.cs:910
virtual T CreateRow()
Definition: SourceData.cs:223
virtual void Reset()
Definition: SourceData.cs:898
static double GetDouble(int id)
Definition: SourceData.cs:991
static IRow rowDefault
Definition: SourceData.cs:863
virtual void BackupSource()
Definition: SourceData.cs:930
virtual IReadOnlyDictionary< string, int > GetRowMapping()
Definition: SourceData.cs:962
virtual string sheetName
Definition: SourceData.cs:846
static int GetInt(int id)
Definition: SourceData.cs:981
virtual void InsertData(IRow row)
Definition: SourceData.cs:902
virtual string sourcePath
Definition: SourceData.cs:848
virtual void OnInit()
Definition: SourceData.cs:108
AutoID autoID
Definition: SourceData.cs:838
override void BackupSource()
Definition: SourceData.cs:291
string nameBook
Definition: SourceData.cs:844
void BuildFlags(string rawText, Dictionary< string, bool > map)
Definition: SourceData.cs:886
static string GetStr(int id, bool useDefault=false)
Definition: SourceData.cs:1021
static ICell GetCell(int x, int y)
Definition: SourceData.cs:632
virtual void OnAfterImportData()
Definition: SourceData.cs:219
virtual bool ImportData(ISheet sheet, string bookname, bool overwrite=false)
Definition: SourceData.cs:915
override void ValidateLang()
Definition: SourceData.cs:544
static float[] GetFloatArray(int id)
Definition: SourceData.cs:1001
static ISheet currentSheet
Definition: SourceData.cs:77
virtual void ValidateLang()
Definition: SourceData.cs:958
List< T > _backupRows
Definition: SourceData.cs:72
string nameSheet
Definition: SourceData.cs:842
virtual T CreateRowByMapping(IReadOnlyDictionary< string, int > mapping)
Definition: SourceData.cs:228
virtual void RemoveDuplicateRows()
Definition: SourceData.cs:255
override BaseRow[] ExportRows()
Definition: SourceData.cs:233
static int[] GetIntArray(int id)
Definition: SourceData.cs:1006
Dictionary< string, T > alias
Definition: SourceData.cs:66
virtual void ExportTexts(string path, bool update=false)
Definition: SourceData.cs:950
virtual void ValidatePref()
Definition: SourceData.cs:946
override int ImportRows(IEnumerable< BaseRow > sourceRows)
Definition: SourceData.cs:238
virtual void RollbackSource()
Definition: SourceData.cs:934
override void ImportTexts(string _nameSheet=null)
Definition: SourceData.cs:552
virtual void RestorePref()
Definition: SourceData.cs:942
virtual T GetRow(string id)
Definition: SourceData.cs:378
override void Reset()
Definition: SourceData.cs:116
List< string > editorListString
Definition: SourceData.cs:75
static string LangSuffix
Definition: SourceData.cs:834
bool initialized
Definition: SourceData.cs:69
List< FieldInfo > GetFields()
Definition: SourceData.cs:318
List< string > GetListString()
Definition: SourceData.cs:301
SourceData< T, T2 > BuildEditorList()
Definition: SourceData.cs:306
bool isNew
Definition: SourceData.cs:840
virtual IReadOnlyDictionary< string, string > GetTypeMapping()
Definition: SourceData.cs:967
virtual void BackupPref()
Definition: SourceData.cs:938
List< T > rows
Definition: SourceData.cs:62
virtual int ImportRows(IEnumerable< BaseRow > sourceRows)
Definition: SourceData.cs:920
static string dataPath
Definition: SourceData.cs:836
override void Init()
Definition: SourceData.cs:83
virtual void ImportTexts(string _nameSheet=null)
Definition: SourceData.cs:954
Dictionary< T2, T > map
Definition: SourceData.cs:64
virtual void Init()
Definition: SourceData.cs:906
virtual bool AllowHotInitialization
Definition: SourceData.cs:79
string GetText()
Definition: Version.cs:16