2using System.Collections.Generic;
5using NPOI.SS.UserModel;
6using NPOI.XSSF.UserModel;
21 IO.DeleteDirectory(dir);
22 IO.CopyAll(dirInfo.FullName, dir);
28 List<FileInfo> list =
new List<FileInfo>();
29 FileInfo[] files = dir.GetFiles(
"*.xlsx", SearchOption.TopDirectoryOnly);
30 foreach (FileInfo fileInfo
in files)
34 talkTexts.Add(excelData);
39 Debug.Log(
$"TalkText: {talkTexts.Count}");
44 public IReadOnlyList<FileInfo>
ParseMap(DirectoryInfo dir,
bool addToList =
true)
46 List<FileInfo> list =
new List<FileInfo>();
47 FileInfo[] files = dir.GetFiles(
"*.z", SearchOption.TopDirectoryOnly);
48 foreach (FileInfo fileInfo
in files)
50 string key = Path.ChangeExtension(fileInfo.Name,
null);
60 Debug.Log(
$"Map: {maps.Count}");
65 public IReadOnlyList<FileInfo>
ParseMapPiece(DirectoryInfo dir,
bool addToList =
true)
67 List<FileInfo> list =
new List<FileInfo>();
68 FileInfo[] files = dir.GetFiles(
"*.mp", SearchOption.TopDirectoryOnly);
69 foreach (FileInfo fileInfo
in files)
71 string key = Path.ChangeExtension(fileInfo.Name,
null);
76 partialMaps[key] = fileInfo;
81 Debug.Log(
$"PartialMap: {partialMaps.Count}");
88 List<FileInfo> list =
new List<FileInfo>();
89 FileInfo[] files = dir.GetFiles(
"*.png", SearchOption.TopDirectoryOnly);
90 foreach (FileInfo fileInfo
in files)
92 string key = Path.ChangeExtension(fileInfo.Name,
null);
93 textureReplaces[key] = fileInfo;
98 Debug.Log(
$"Texture Replace: {textureReplaces.Count}");
105 List<FileInfo> list =
new List<FileInfo>();
106 FileInfo[] files = dir.GetFiles(
"*.png", SearchOption.AllDirectories);
107 foreach (FileInfo fileInfo
in files)
109 string key = Path.ChangeExtension(Path.GetRelativePath(dir.FullName, fileInfo.FullName).NormalizePath(),
null);
110 string text = Path.ChangeExtension(fileInfo.FullName,
null);
112 string value = (textures[key] = text);
113 dictModItems[key] = value;
118 Debug.Log(
$"Texture: {textures.Count}");
125 List<FileInfo> list =
new List<FileInfo>();
126 FileInfo[] files = dir.GetFiles(
"*.png", SearchOption.TopDirectoryOnly);
127 foreach (FileInfo fileInfo
in files)
129 string name = fileInfo.Name;
130 if (name.StartsWith(
"BG_", StringComparison.Ordinal))
134 else if (name.StartsWith(
"BGF_", StringComparison.Ordinal))
138 else if (name.EndsWith(
"-full.png", StringComparison.Ordinal))
142 else if (name.EndsWith(
"-overlay.png", StringComparison.Ordinal))
151 portraits[name] = fileInfo;
156 Debug.Log(
$"Portrait: {portraits.Count}");
165 Mapping =
new FileMapping(dir.Parent);
168 Lang.excelDialog =
null;
169 Debug.Log(
"LangMod: " +
string.Join(
", ", Mapping.OrderedLangMods));
170 if (Mapping.SourceSheets.Count > 0)
172 Debug.Log(
$"Source Sheets: {Mapping.SourceSheets.Count}, {Mapping.SourceLangMod}");
178 List<FileInfo> list =
new List<FileInfo>();
179 FileInfo[] files = dir.GetFiles(
"*.*", SearchOption.AllDirectories);
180 foreach (FileInfo fileInfo
in files)
182 if (ModUtil.GetAudioType(fileInfo.Extension) != AudioType.UNKNOWN)
184 string key = Path.ChangeExtension(Path.GetRelativePath(dir.FullName, fileInfo.FullName).NormalizePath(),
null);
185 Dictionary<string, FileInfo> dictionary =
MOD.
sounds;
186 FileInfo value = (sounds[key] = fileInfo);
187 dictionary[key] = value;
193 Debug.Log(
$"Sound: {sounds.Count}");
195 int num = sounds.Keys.Count((
string k) => k.StartsWith(
"BGM/"));
205 customContent.Clear();
263 ModUtil.FixDefaultThingRowPref(r6);
287 else if (row.id.StartsWith(
"cwl") || row.id.StartsWith(
"custom"))
289 customContent.Add(CustomReligionContent.CreateFromRow(row,
this));
294 ModUtil.FixDefaultCharaRowPref(r);
298 customContent.RemoveAll((ICustomContent p) => p ==
null);
303 SortedDictionary<string, string> sortedDictionary =
new SortedDictionary<string, string>();
308 foreach (KeyValuePair<string, string>
item in sourceRow.ExportTexts(sourceRow.UseAlias ?
"alias" :
"id"))
310 item.Deconstruct(out var key, out var value);
312 string value2 = value;
313 sortedDictionary[key2] = value2;
317 catch (Exception arg)
319 Debug.LogError(
$"#source failed to export localization for {title}/{id}\n{arg}");
321 return sortedDictionary;
328 sourceRow.ImportTexts(texts, sourceRow.UseAlias ?
"alias" :
"id");
334 Mapping.RebuildLangModMapping(lang);
335 for (FileInfo fileInfo = Mapping.RelocateFile(
"SourceLocalization.json"); fileInfo !=
null; fileInfo = Mapping.RelocateFile(
"SourceLocalization.json"))
338 Debug.Log(
"#source-localization deleted " + fileInfo.ShortPath());
345 if (!base.IsSourceLocalizable)
349 IReadOnlyDictionary<string, string> modEntries = SourceLocalization.GetModEntries(
id, lang);
351 SortedDictionary<string, string>
final =
new SortedDictionary<string, string>();
352 foreach (var (key, defaultValue) in sortedDictionary)
354 final[key] = modEntries.GetValueOrDefault(key, defaultValue);
356 string text3 = Path.Combine(dirInfo.FullName,
"LangMod/" + lang +
"/SourceLocalization.json");
357 if (force || modEntries.Count !=
final.Count || modEntries.Any((KeyValuePair<string, string> kv) => !
final.ContainsKey(kv.Key)))
359 JsonSerializerSettings setting =
new JsonSerializerSettings
361 PreserveReferencesHandling = PreserveReferencesHandling.None,
362 NullValueHandling = NullValueHandling.Ignore
364 IO.SaveFile(text3,
final, compress:
false, setting);
365 SourceLocalization.UpdateModEntries(
id, lang,
final);
374 DirectoryInfo[] directories = dir.GetDirectories();
375 foreach (DirectoryInfo directoryInfo
in directories)
377 if (!directoryInfo.Name.StartsWith(
"_") && !TryAddLang(directoryInfo, isNew:
false))
379 Debug.Log(
"Generating Language Mod Contents:" + directoryInfo.FullName);
381 Directory.CreateDirectory(directoryInfo.FullName +
"/Dialog");
383 sources.ExportSourceTexts(directoryInfo.FullName +
"/Game");
385 TryAddLang(directoryInfo, isNew:
true);
388 bool TryAddLang(DirectoryInfo dirLang,
bool isNew)
390 string name = dirLang.Name;
391 FileInfo[] files = dirLang.GetFiles();
392 foreach (FileInfo fileInfo
in files)
394 if (fileInfo.Name ==
"lang.ini")
399 dir = dirLang.FullName +
"/"
408 Log.system =
"Updated Language Files:" + Environment.NewLine + Environment.NewLine;
409 Debug.Log(
"Updating Language:" + langSetting.
name +
"/" + langSetting.
GetVersion() +
"/" + core.version.GetInt());
410 string text = dirLang.FullName +
"/Game";
411 Directory.Move(text, text +
"_temp");
412 sources.ExportSourceTexts(text);
413 sources.UpdateSourceTexts(text);
414 IO.DeleteDirectory(text +
"_temp");
415 text = dirLang.FullName +
"/Dialog";
416 Directory.Move(text, text +
"_temp");
419 IO.DeleteDirectory(text +
"_temp");
420 text = dirLang.FullName +
"/Data";
421 IO.CopyDir(text, text +
"_temp");
424 UpdateTalks(
new DirectoryInfo(text), text +
"_temp");
425 IO.DeleteDirectory(text +
"_temp");
427 IO.SaveText(dirLang.FullName +
"/update.txt",
Log.
system);
439 DirectoryInfo[] directories = dir.GetDirectories();
440 foreach (DirectoryInfo directoryInfo
in directories)
442 UpdateDialogs(directoryInfo, dirTemp +
"/" + directoryInfo.Name);
444 FileInfo[] files = dir.GetFiles();
445 foreach (FileInfo fileInfo
in files)
447 if (fileInfo.Name.EndsWith(
"xlsx"))
456 FileInfo[] files = dir.GetFiles();
457 foreach (FileInfo fileInfo
in files)
459 if (fileInfo.Name ==
"god_talk.xlsx" || fileInfo.Name ==
"chara_talk.xlsx")
468 string path = dirTemp +
"/" + f.Name;
469 if (!File.Exists(path))
473 XSSFWorkbook xSSFWorkbook;
474 using (FileStream @is = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
476 xSSFWorkbook =
new XSSFWorkbook((Stream)@is);
478 XSSFWorkbook xSSFWorkbook2;
479 using (FileStream is2 = File.Open(f.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
481 xSSFWorkbook2 =
new XSSFWorkbook((Stream)is2);
483 for (
int i = 0; i < xSSFWorkbook2.NumberOfSheets; i++)
485 ISheet sheetAt = xSSFWorkbook2.GetSheetAt(i);
486 ISheet sheet = xSSFWorkbook.GetSheet(sheetAt.SheetName);
489 Log.system = Log.system +
"Old sheet not found:" + sheetAt.SheetName + Environment.NewLine;
493 Log.system = Log.system + ((num == 0) ?
"(No Changes) " :
"(Updated) ") + f.FullName +
"(" + sheetAt.SheetName +
")" + Environment.NewLine;
496 Log.system = Log.system + num + Environment.NewLine;
498 Log.system += Environment.NewLine;
500 using FileStream stream =
new FileStream(f.FullName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
501 xSSFWorkbook2.Write(stream);
506 Dictionary<string, string[]> dictionary =
new Dictionary<string, string[]>();
510 IRow row = destSheet.GetRow(0);
511 IRow row2 = oldSheet.GetRow(0);
512 List<SheetIndex> list =
new List<SheetIndex>();
513 int cellnum = FindField(row,
"id");
514 int cellnum2 = FindField(row2,
"id");
515 for (
int i = 0; i < row.LastCellNum; i++)
517 ICell cell = row.GetCell(i);
522 string stringCellValue = cell.StringCellValue;
523 if (stringCellValue ==
"id" || (updateOnlytext && stringCellValue !=
"text"))
527 for (
int j = 0; j < row2.LastCellNum; j++)
529 cell = row2.GetCell(j);
534 if (cell.StringCellValue == stringCellValue)
541 Debug.Log(destSheet.SheetName +
"/" + stringCellValue +
"/" + i +
"/" + j);
546 for (
int k = 2; k <= oldSheet.LastRowNum; k++)
548 IRow row3 = oldSheet.GetRow(k);
559 ICell cell2 = row3.GetCell(cellnum2);
564 string text = ((cell2.CellType == CellType.Numeric) ? cell2.NumericCellValue.ToString() : cell2.StringCellValue);
569 string[] array =
new string[list.Count];
570 for (
int l = 0; l < list.Count; l++)
572 ICell cell3 = row3.GetCell(list[l].old);
575 string stringCellValue2 = cell3.StringCellValue;
576 if (!stringCellValue2.IsEmpty())
578 array[l] = stringCellValue2;
582 dictionary.Add(text, array);
585 for (
int m = 2; m <= destSheet.LastRowNum; m++)
587 IRow row4 = destSheet.GetRow(m);
598 ICell cell4 = row4.GetCell(cellnum);
603 string text2 = ((cell4.CellType == CellType.Numeric) ? cell4.NumericCellValue.ToString() : cell4.StringCellValue);
604 if (text2.IsEmpty() || !dictionary.ContainsKey(text2))
608 string[] array2 = dictionary[text2];
609 for (
int n = 0; n < list.Count; n++)
611 ICell cell5 = row4.GetCell(list[n].dest) ?? row4.CreateCell(list[n].dest, CellType.String);
614 cell5.SetCellValue(array2[n]);
615 cell5.SetCellType(CellType.String);
616 cell5.SetAsActiveCell();
622 static int FindField(IRow row5,
string id)
624 for (
int num4 = 0; num4 < row5.LastCellNum; num4++)
626 ICell cell6 = row5.GetCell(num4);
631 if (cell6.StringCellValue ==
id)
static string packageCore
static CustomBlockContent CreateFromRow(SourceBlock.Row r, ModPackage owner=null)
static CustomCellEffectContent CreateFromRow(SourceCellEffect.Row r, ModPackage owner=null)
static CustomCharaContent CreateFromRow(SourceChara.Row r, ModPackage owner=null)
static CustomDecoContent CreateFromRow(SourceDeco.Row r, ModPackage owner=null)
static CustomElementContent CreateFromRow(SourceElement.Row r, ModPackage owner=null)
static CustomFloorContent CreateFromRow(SourceFloor.Row r, ModPackage owner=null)
static CustomMaterialContent CreateFromRow(SourceMaterial.Row r, ModPackage owner=null)
static CustomObjContent CreateFromRow(SourceObj.Row r, ModPackage owner=null)
static CustomStatContent CreateFromRow(SourceStat.Row r, ModPackage owner=null)
static CustomThingContent CreateFromRow(SourceThing.Row r, ModPackage mod=null)
static CustomZoneContent CreateFromRow(SourceZone.Row r, ModPackage owner=null)
static bool IsBuiltin(string id)
static Dictionary< string, LangSetting > langs
static Dictionary< string, FileInfo > sounds
static List< FileInfo > listMaps
static List< FileInfo > listPartialMaps
void Add(FileInfo fi, string path=null, string prefix="")
void CopyContentTo(string dir)
IReadOnlyList< FileInfo > ParseTalkText(DirectoryInfo dir)
void UpdateDialogs(DirectoryInfo dir, string dirTemp)
override void ClearSourceLocalizations(string lang)
override string UpdateSourceLocalizationFile(string lang, bool force=false)
void ParseLangMod(DirectoryInfo dir)
void UpdateExcelBook(FileInfo f, string dirTemp, bool updateOnlyText)
IReadOnlyList< FileInfo > ParseTexture(DirectoryInfo dir)
void AddOrUpdateLang(DirectoryInfo dir)
override void GenerateCustomContentProfiles()
IReadOnlyList< FileInfo > ParseMapPiece(DirectoryInfo dir, bool addToList=true)
override void ImportSourceLocalizations(IReadOnlyDictionary< string, string > texts)
override SortedDictionary< string, string > ExportSourceLocalizations()
void UpdateTalks(DirectoryInfo dir, string dirTemp)
IReadOnlyList< FileInfo > ParseTextureReplace(DirectoryInfo dir)
IReadOnlyList< FileInfo > ParsePortrait(DirectoryInfo dir)
IReadOnlyList< FileInfo > ParseMap(DirectoryInfo dir, bool addToList=true)
int UpdateExcelSheet(ISheet destSheet, ISheet oldSheet, bool updateOnlytext)
IReadOnlyList< FileInfo > ParseSound(DirectoryInfo dir)
static ModItemList< Sprite > modPortraitBGFs
static ModItemList< Sprite > modPortraitBGs
static ModItemList< Sprite > modOverlays
static ModItemList< Sprite > modPortraits
static HashSet< string > allIds
static ModItemList< Sprite > modFull
static Dictionary< string, string > dictModItems
static List< ExcelData > modList