2using System.Collections.Generic;
5using NPOI.SS.UserModel;
6using NPOI.XSSF.UserModel;
27 IO.DeleteDirectory(dir);
28 IO.CopyAll(dirInfo.FullName, dir);
34 List<FileInfo> list =
new List<FileInfo>();
35 FileInfo[] files = dir.GetFiles(
"*.xlsx", SearchOption.TopDirectoryOnly);
36 foreach (FileInfo fileInfo
in files)
40 talkTexts.Add(excelData);
45 Debug.Log(
$"TalkText: {talkTexts.Count}");
50 public IReadOnlyList<FileInfo>
ParseMap(DirectoryInfo dir,
bool addToList =
true)
52 List<FileInfo> list =
new List<FileInfo>();
53 FileInfo[] files = dir.GetFiles(
"*.z", SearchOption.TopDirectoryOnly);
54 foreach (FileInfo fileInfo
in files)
56 string key = Path.ChangeExtension(fileInfo.Name,
null);
66 Debug.Log(
$"Map: {maps.Count}");
71 public IReadOnlyList<FileInfo>
ParseMapPiece(DirectoryInfo dir,
bool addToList =
true)
73 List<FileInfo> list =
new List<FileInfo>();
74 FileInfo[] files = dir.GetFiles(
"*.mp", SearchOption.TopDirectoryOnly);
75 foreach (FileInfo fileInfo
in files)
77 string key = Path.ChangeExtension(fileInfo.Name,
null);
82 partialMaps[key] = fileInfo;
87 Debug.Log(
$"PartialMap: {partialMaps.Count}");
94 List<FileInfo> list =
new List<FileInfo>();
95 FileInfo[] files = dir.GetFiles(
"*.png", SearchOption.TopDirectoryOnly);
96 foreach (FileInfo fileInfo
in files)
98 string key = Path.ChangeExtension(fileInfo.Name,
null);
99 textureReplaces[key] = fileInfo;
104 Debug.Log(
$"Texture Replace: {textureReplaces.Count}");
111 List<FileInfo> list =
new List<FileInfo>();
112 FileInfo[] files = dir.GetFiles(
"*.png", SearchOption.AllDirectories);
113 foreach (FileInfo fileInfo
in files)
115 string key = Path.ChangeExtension(Path.GetRelativePath(dir.FullName, fileInfo.FullName).NormalizePath(),
null);
116 string text = Path.ChangeExtension(fileInfo.FullName,
null);
118 string value = (textures[key] = text);
119 dictModItems[key] = value;
124 Debug.Log(
$"Texture: {textures.Count}");
131 List<FileInfo> list =
new List<FileInfo>();
132 FileInfo[] files = dir.GetFiles(
"*.png", SearchOption.TopDirectoryOnly);
133 foreach (FileInfo fileInfo
in files)
135 string name = fileInfo.Name;
136 if (name.StartsWith(
"BG_", StringComparison.Ordinal))
140 else if (name.StartsWith(
"BGF_", StringComparison.Ordinal))
144 else if (name.EndsWith(
"-full.png", StringComparison.Ordinal))
148 else if (name.EndsWith(
"-overlay.png", StringComparison.Ordinal))
157 portraits[name] = fileInfo;
162 Debug.Log(
$"Portrait: {portraits.Count}");
171 Mapping =
new FileMapping(dir.Parent);
174 Lang.excelDialog =
null;
175 Debug.Log(
"LangMod: " +
string.Join(
", ", Mapping.OrderedLangMods));
176 if (Mapping.SourceSheets.Count > 0)
178 Debug.Log(
$"Source Sheets: {Mapping.SourceSheets.Count}, {Mapping.SourceLangMod}");
184 List<FileInfo> list =
new List<FileInfo>();
185 FileInfo[] files = dir.GetFiles(
"*.*", SearchOption.AllDirectories);
186 foreach (FileInfo fileInfo
in files)
188 if (ModUtil.GetAudioType(fileInfo.Extension) != AudioType.UNKNOWN)
190 string key = Path.ChangeExtension(Path.GetRelativePath(dir.FullName, fileInfo.FullName).NormalizePath(),
null);
191 Dictionary<string, FileInfo> dictionary =
MOD.
sounds;
192 FileInfo value = (sounds[key] = fileInfo);
193 dictionary[key] = value;
199 Debug.Log(
$"Sound: {sounds.Count}");
201 int num = sounds.Keys.Count((
string k) => k.StartsWith(
"BGM/"));
211 customContent.Clear();
269 ModUtil.FixDefaultThingRowPref(r6);
293 else if (row.id.StartsWith(
"cwl") || row.id.StartsWith(
"custom"))
295 customContent.Add(CustomReligionContent.CreateFromRow(row,
this));
300 ModUtil.FixDefaultCharaRowPref(r);
304 customContent.RemoveAll((ICustomContent p) => p ==
null);
309 SortedDictionary<string, string> sortedDictionary =
new SortedDictionary<string, string>();
314 foreach (KeyValuePair<string, string>
item in sourceRow.ExportTexts(sourceRow.UseAlias ?
"alias" :
"id"))
316 item.Deconstruct(out var key, out var value);
318 string value2 = value;
319 sortedDictionary[key2] = value2;
323 catch (Exception arg)
325 Debug.LogError(
$"#source failed to export localization for {title}/{id}\n{arg}");
327 return sortedDictionary;
334 sourceRow.ImportTexts(texts, sourceRow.UseAlias ?
"alias" :
"id");
340 Mapping.RebuildLangModMapping(lang);
341 for (FileInfo fileInfo = Mapping.RelocateFile(
"SourceLocalization.json"); fileInfo !=
null; fileInfo = Mapping.RelocateFile(
"SourceLocalization.json"))
344 Debug.Log(
"#source-localization deleted " + fileInfo.ShortPath());
351 if (!base.IsSourceLocalizable)
355 IReadOnlyDictionary<string, string> modEntries = SourceLocalization.GetModEntries(
id, lang);
357 SortedDictionary<string, string>
final =
new SortedDictionary<string, string>();
358 foreach (var (key, defaultValue) in sortedDictionary)
360 final[key] = modEntries.GetValueOrDefault(key, defaultValue);
362 string text3 = Path.Combine(dirInfo.FullName,
"LangMod/" + lang +
"/SourceLocalization.json");
363 if (force || modEntries.Count !=
final.Count || modEntries.Any((KeyValuePair<string, string> kv) => !
final.ContainsKey(kv.Key)))
365 JsonSerializerSettings setting =
new JsonSerializerSettings
367 PreserveReferencesHandling = PreserveReferencesHandling.None,
368 NullValueHandling = NullValueHandling.Ignore
370 IO.SaveFile(text3,
final, compress:
false, setting);
371 SourceLocalization.UpdateModEntries(
id, lang,
final);
380 DirectoryInfo[] directories = dir.GetDirectories();
381 foreach (DirectoryInfo directoryInfo
in directories)
383 if (!directoryInfo.Name.StartsWith(
"_") && !TryAddLang(directoryInfo, isNew:
false))
385 Debug.Log(
"Generating Language Mod Contents:" + directoryInfo.FullName);
387 Directory.CreateDirectory(directoryInfo.FullName +
"/Dialog");
389 sources.ExportSourceTexts(directoryInfo.FullName +
"/Game");
391 TryAddLang(directoryInfo, isNew:
true);
394 bool TryAddLang(DirectoryInfo dirLang,
bool isNew)
396 string name = dirLang.Name;
397 FileInfo[] files = dirLang.GetFiles();
398 foreach (FileInfo fileInfo
in files)
400 if (fileInfo.Name ==
"lang.ini")
405 dir = dirLang.FullName +
"/"
414 Log.system =
"Updated Language Files:" + Environment.NewLine + Environment.NewLine;
415 Debug.Log(
"Updating Language:" + langSetting.
name +
"/" + langSetting.
GetVersion() +
"/" + core.version.GetInt());
416 string text = dirLang.FullName +
"/Game";
417 Directory.Move(text, text +
"_temp");
418 sources.ExportSourceTexts(text);
419 sources.UpdateSourceTexts(text);
420 IO.DeleteDirectory(text +
"_temp");
421 text = dirLang.FullName +
"/Dialog";
422 Directory.Move(text, text +
"_temp");
425 IO.DeleteDirectory(text +
"_temp");
426 text = dirLang.FullName +
"/Data";
427 IO.CopyDir(text, text +
"_temp");
430 UpdateTalks(
new DirectoryInfo(text), text +
"_temp");
431 IO.DeleteDirectory(text +
"_temp");
433 IO.SaveText(dirLang.FullName +
"/update.txt",
Log.
system);
445 DirectoryInfo[] directories = dir.GetDirectories();
446 foreach (DirectoryInfo directoryInfo
in directories)
448 UpdateDialogs(directoryInfo, dirTemp +
"/" + directoryInfo.Name);
450 FileInfo[] files = dir.GetFiles();
451 foreach (FileInfo fileInfo
in files)
453 if (fileInfo.Name.EndsWith(
"xlsx"))
462 FileInfo[] files = dir.GetFiles();
463 foreach (FileInfo fileInfo
in files)
465 if (fileInfo.Name ==
"god_talk.xlsx" || fileInfo.Name ==
"chara_talk.xlsx")
474 string path = dirTemp +
"/" + f.Name;
475 if (!File.Exists(path))
479 XSSFWorkbook xSSFWorkbook;
480 using (FileStream @is = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
482 xSSFWorkbook =
new XSSFWorkbook((Stream)@is);
484 XSSFWorkbook xSSFWorkbook2;
485 using (FileStream is2 = File.Open(f.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
487 xSSFWorkbook2 =
new XSSFWorkbook((Stream)is2);
489 for (
int i = 0; i < xSSFWorkbook2.NumberOfSheets; i++)
491 ISheet sheetAt = xSSFWorkbook2.GetSheetAt(i);
492 ISheet sheet = xSSFWorkbook.GetSheet(sheetAt.SheetName);
495 Log.system = Log.system +
"Old sheet not found:" + sheetAt.SheetName + Environment.NewLine;
499 Log.system = Log.system + ((num == 0) ?
"(No Changes) " :
"(Updated) ") + f.FullName +
"(" + sheetAt.SheetName +
")" + Environment.NewLine;
502 Log.system = Log.system + num + Environment.NewLine;
504 Log.system += Environment.NewLine;
506 using FileStream stream =
new FileStream(f.FullName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
507 xSSFWorkbook2.Write(stream);
512 Dictionary<string, string[]> dictionary =
new Dictionary<string, string[]>();
516 IRow row = destSheet.GetRow(0);
517 IRow row2 = oldSheet.GetRow(0);
518 List<SheetIndex> list =
new List<SheetIndex>();
519 int cellnum = FindField(row,
"id");
520 int cellnum2 = FindField(row2,
"id");
521 for (
int i = 0; i < row.LastCellNum; i++)
523 ICell cell = row.GetCell(i);
528 string stringCellValue = cell.StringCellValue;
529 if (stringCellValue ==
"id" || (updateOnlytext && stringCellValue !=
"text"))
533 for (
int j = 0; j < row2.LastCellNum; j++)
535 cell = row2.GetCell(j);
540 if (cell.StringCellValue == stringCellValue)
547 Debug.Log(destSheet.SheetName +
"/" + stringCellValue +
"/" + i +
"/" + j);
552 for (
int k = 2; k <= oldSheet.LastRowNum; k++)
554 IRow row3 = oldSheet.GetRow(k);
565 ICell cell2 = row3.GetCell(cellnum2);
570 string text = ((cell2.CellType == CellType.Numeric) ? cell2.NumericCellValue.ToString() : cell2.StringCellValue);
575 string[] array =
new string[list.Count];
576 for (
int l = 0; l < list.Count; l++)
578 ICell cell3 = row3.GetCell(list[l].old);
581 string stringCellValue2 = cell3.StringCellValue;
582 if (!stringCellValue2.IsEmpty())
584 array[l] = stringCellValue2;
588 dictionary.Add(text, array);
591 for (
int m = 2; m <= destSheet.LastRowNum; m++)
593 IRow row4 = destSheet.GetRow(m);
604 ICell cell4 = row4.GetCell(cellnum);
609 string text2 = ((cell4.CellType == CellType.Numeric) ? cell4.NumericCellValue.ToString() : cell4.StringCellValue);
610 if (text2.IsEmpty() || !dictionary.ContainsKey(text2))
614 string[] array2 = dictionary[text2];
615 for (
int n = 0; n < list.Count; n++)
617 ICell cell5 = row4.GetCell(list[n].dest) ?? row4.CreateCell(list[n].dest, CellType.String);
620 cell5.SetCellValue(array2[n]);
621 cell5.SetCellType(CellType.String);
622 cell5.SetAsActiveCell();
628 static int FindField(IRow row5,
string id)
630 for (
int num4 = 0; num4 < row5.LastCellNum; num4++)
632 ICell cell6 = row5.GetCell(num4);
637 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)
Action< UINote > onBuildConfig
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