2using System.Collections.Generic;
4using System.Reflection;
5using NPOI.SS.UserModel;
7using NPOI.XSSF.UserModel;
28 if (r.HasField<
string>(
id))
30 return r.GetField<
string>(
id);
32 if (r.HasField<
int>(
id))
34 return r.GetField<
int>(
id).ToString();
36 if (r.HasField<
string[]>(
id))
39 string[] field = r.GetField<
string[]>(
id);
42 string[] array = field;
43 foreach (
string text2
in array)
45 text = text + text2 +
",";
48 return text.TrimEnd(
',');
61 public List<T>
rows =
new List<T>();
63 public Dictionary<T2, T>
map =
new Dictionary<T2, T>();
65 public Dictionary<string, T>
alias =
new Dictionary<string, T>();
82 public override void Init()
86 Debug.Log(
"#init Skipping sourceData.Init:" + base.name);
116 if (!Application.isPlaying)
118 BaseCore.resetRuntime =
true;
134 public override bool ImportData(ISheet sheet,
string bookname,
bool overwrite =
false)
138 rows =
new List<T>();
143 SourceData.rowDefault = sheet.GetRow(2);
145 for (
int i = 3; i <= sheet.LastRowNum; i++)
147 SourceData.row = sheet.GetRow(i);
153 val.OnImportData(
this);
157 string text = sheet.SheetName +
"/" + sheet.LastRowNum +
"/" + num;
203 List<FieldInfo> list =
new List<FieldInfo>();
205 AddField(
"id", 4096);
206 AddField(
"version", 4096);
207 AddField(
"filter", 4096);
208 AddField(
"name", 4096);
209 AddField(
"text", 4096);
210 AddField(
"detail", 4096);
211 AddField(
"description", 4096);
213 foreach (
string text
in importFields)
217 AddField(text, 4096);
221 void AddField(
string id,
int width)
223 bool flag =
id ==
"id" ||
id ==
"filter";
224 bool flag2 =
id ==
"version";
225 if (!(typeof(T).GetField(
id) ==
null) || flag2)
236 if (!(flag || flag2))
266 public override void ExportTexts(
string path,
bool update =
false)
270 XSSFWorkbook xSSFWorkbook =
new XSSFWorkbook();
279 ICellStyle cellStyle = xSSFWorkbook.CreateCellStyle();
280 cellStyle.FillForegroundColor = 44;
281 cellStyle.FillPattern = FillPattern.SolidForeground;
282 if (!
item.isStatic &&
item.id !=
"version")
284 GetCell(num, y).CellStyle = cellStyle;
290 foreach (T row4
in rows)
298 else if (item2.
id ==
"version")
306 currentSheet.SetAutoFilter(
new CellRangeAddress(1, 1, 0, fields.Count - 1));
309 Dictionary<string, int> dictionary =
new Dictionary<string, int>();
310 if (!File.Exists(path +
"_temp/" + text))
314 XSSFWorkbook xSSFWorkbook2;
315 using (FileStream @is = File.Open(path +
"_temp/" + text, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
317 xSSFWorkbook2 =
new XSSFWorkbook((Stream)@is);
319 ISheet sheetAt = xSSFWorkbook2.GetSheetAt(0);
320 IRow
row = sheetAt.GetRow(0);
329 for (
int i = 0; i <
row.LastCellNum; i++)
331 string stringCellValue =
row.GetCell(i).StringCellValue;
332 if (stringCellValue.IsEmpty())
336 if (stringCellValue == item3.
id)
346 dictionary.Add(item3.
id, 0);
347 for (y = 2; y <= sheetAt.LastRowNum; y++)
349 IRow row2 = sheetAt.GetRow(y);
358 ICell cell = row2.GetCell(0);
363 string text2 = ((cell.CellType == CellType.Numeric) ? cell.NumericCellValue.ToString() : cell.StringCellValue);
379 ICell cell2 = row3.GetCell(0);
380 if (cell2 ==
null || cell2.StringCellValue != text2)
384 string text3 = row2.GetCell(num3)?.StringCellValue ??
"";
389 (row3.GetCell(item3.
column) ?? row3.CreateCell(item3.
column)).SetCellValue(text3);
390 if (item3.
id !=
"version")
392 ICell cell3 = row3.GetCell(item3.
column + 2);
393 ICell cell4 = row2.GetCell(num3 + 2);
398 if (cell4 ==
null || cell3.StringCellValue != cell4.StringCellValue)
400 row3.GetCell(1).SetCellValue(cellValue);
404 dictionary[item3.
id]++;
408 Log.system = Log.system + ((num2 == 0) ?
"(No Changes) " :
"(Updated) ") + path +
"/" + text + Environment.NewLine;
411 foreach (KeyValuePair<string, int> item4
in dictionary)
413 Log.system = Log.system + item4.Key +
":" + item4.Value +
" ";
415 Log.system += Environment.NewLine;
417 Log.system += Environment.NewLine;
419 if (!Directory.Exists(path))
421 Directory.CreateDirectory(path);
423 using FileStream stream =
new FileStream(path +
"/" + text, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
424 xSSFWorkbook.Write(stream);
431 Log.system = Log.system + langImportMod + text + Environment.NewLine;
432 Log.system += Environment.NewLine;
438 string text = _nameSheet.IsEmpty(
nameSheet) +
".xlsx";
439 if (!File.Exists(langImportMod + text))
443 XSSFWorkbook xSSFWorkbook;
444 using (FileStream @is = File.Open(langImportMod + text, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
446 xSSFWorkbook =
new XSSFWorkbook((Stream)@is);
448 ISheet sheetAt = xSSFWorkbook.GetSheetAt(0);
450 IRow
row = sheetAt.GetRow(0);
451 List<FieldMap> list =
new List<FieldMap>();
458 for (
int i = 0; i <
row.LastCellNum; i++)
460 string stringCellValue =
row.GetCell(i).StringCellValue;
461 if (stringCellValue.IsEmpty())
465 if (stringCellValue ==
item.id)
476 for (
int j = 2; j <= sheetAt.LastRowNum; j++)
478 IRow row2 = sheetAt.GetRow(j);
479 T val =
GetRow(row2.GetCell(0).StringCellValue);
482 Debug.Log(sheetAt.SheetName +
": id to import no longer exist: " + row2.GetCell(0).StringCellValue);
488 System.Reflection.FieldInfo field2 = val.GetType().GetField(field.
id +
"_L");
493 if (typeof(
string[]).IsAssignableFrom(field2.FieldType))
495 ICell cell = row2.GetCell(item2.
column);
496 string[] array = ((cell ==
null) ?
new string[0] : cell.StringCellValue.Split(
','));
497 string[] field3 = val.GetField<
string[]>(field.
id);
500 field2.SetValue(val, (array.Length >= field3.Length) ? array : field3);
505 ICell cell2 = row2.GetCell(item2.
column);
508 field2.SetValue(val, cell2.StringCellValue.IsEmpty(val.GetField<
string>(field.
id)));
518 return row.GetCell(x) ??
row.CreateCell(x);
550 return this.GetField<int>(
"id") +
"-" + this.GetField<string>(
"alias") +
"(" + this.GetField<string>(
"name_JP") +
")";
553 public string GetText(
string id =
"name",
bool returnNull =
false)
558 FieldInfo field2 = GetType().GetField(
id);
559 if (field2 !=
null && !(field2.
GetValue(
this) as
string).IsEmpty())
561 return field2.
GetValue(
this) as string;
566 return (field.
GetValue(
this) as
string).IsEmpty(returnNull ?
null :
"");
576 if (field !=
null && field.
GetValue(
this) is
string[] array && array.Length != 0)
580 return GetType().GetField(
id).
GetValue(
this) as
string[];
582 return GetType().GetField(
id +
Lang.
suffix).GetValue(
this) as
string[];
585 public virtual void SetID(ref
int count)
587 this.SetField(
"id", count);
620 ExcelParser.row = value;
632 ExcelParser.rowDefault = value;
638 if (!
string.IsNullOrEmpty(rawText))
640 string[] array = rawText.Split(
',');
641 foreach (
string key
in array)
643 map.Add(key, value:
true);
665 public virtual bool ImportData(ISheet sheet,
string bookname,
bool overwrite =
false)
704 if (cell !=
null && cell.CellType != CellType.Blank)
706 return cell.CellType == CellType.Unknown;
751 public static string GetStr(
int id,
bool useDefault =
false)
static string LangImportMod
static bool GetBool(int id)
static int GetInt(int id)
static string GetString(int id)
static int[] GetIntArray(int id)
static float GetFloat(int id)
static double GetDouble(int id)
static string GetStr(int id, bool useDefault=false)
static float[] GetFloatArray(int id)
static string[] GetStringArray(int id)
virtual string GetEditorListName()
string[] GetTextArray(string id)
virtual void SetID(ref int count)
string GetText(string id="name", bool returnNull=false)
virtual void OnImportData(SourceData data)
static float GetFloat(int id)
virtual string[] ImportFields
static string[] GetStringArray(int id)
virtual void SetRow(T row)
override bool ImportData(ISheet sheet, string bookname, bool overwrite=false)
static string GetString(int id)
static bool GetBool(int id)
override void RollbackSource()
override void ExportTexts(string path, bool update=false)
static bool IsNull(ICell cell)
virtual string[] GetList(string id)
static double GetDouble(int id)
virtual void BackupSource()
static int GetInt(int id)
virtual void InsertData(IRow row)
virtual string sourcePath
override void BackupSource()
void BuildFlags(string rawText, Dictionary< string, bool > map)
static string GetStr(int id, bool useDefault=false)
static ICell GetCell(int x, int y)
virtual void OnAfterImportData()
virtual bool ImportData(ISheet sheet, string bookname, bool overwrite=false)
override void ValidateLang()
static float[] GetFloatArray(int id)
static ISheet currentSheet
virtual void ValidateLang()
static int[] GetIntArray(int id)
Dictionary< string, T > alias
virtual void ExportTexts(string path, bool update=false)
virtual void ValidatePref()
virtual void RollbackSource()
override void ImportTexts(string _nameSheet=null)
virtual void RestorePref()
virtual T GetRow(string id)
List< string > editorListString
List< FieldInfo > GetFields()
List< string > GetListString()
SourceData< T, T2 > BuildEditorList()
virtual void BackupPref()
virtual void ImportTexts(string _nameSheet=null)
virtual bool AllowHotInitialization