Skip to content

Commit b8f664a

Browse files
committed
2.1.8 update
1 parent f247c15 commit b8f664a

File tree

6 files changed

+202
-36
lines changed

6 files changed

+202
-36
lines changed

DungeonArtifactTrans/Hooks.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Reflection;
66
using System.Text;
7+
using Achievement;
78
using BepInEx;
89
using Compiler;
910
using HarmonyLib;
@@ -186,6 +187,50 @@ public static void Postfix()
186187
}
187188
}
188189
}
190+
191+
[HarmonyPatch(typeof(LocalAchievementStats), MethodType.Constructor)]
192+
public static class AchievementsFix
193+
{
194+
public static void Postfix(LocalAchievementStats __instance)
195+
{
196+
var titles = AccessTools.Field(typeof(LocalAchievementStats), "titles");
197+
var accumulates = AccessTools.Property(typeof(LocalAchievementStats), "accumulates");
198+
if (titles.GetValue(__instance) is List<AchievementTitle> titleList)
199+
{
200+
Logger.Log($"Process title, {titleList.Count}");
201+
foreach (var title in titleList)
202+
{
203+
if (TranslationDB.AchievementTitleInfo.TryGetValue($"Ach_{title.code}_Title", out var transValue))
204+
{
205+
Logger.Log($"{title.title} to {transValue}");
206+
if (!transValue.Trim().IsNullOrWhiteSpace())
207+
title.title = transValue;
208+
}
209+
210+
if (TranslationDB.AchievementTitleInfo.TryGetValue($"Ach_{title.code}_Desc", out var transValue2))
211+
{
212+
Logger.Log($"{title.discription} to {transValue2}");
213+
if (!transValue2.Trim().IsNullOrWhiteSpace())
214+
title.discription = transValue2;
215+
}
216+
}
217+
}
218+
/* Description 不需要翻译
219+
if (accumulates.GetValue(__instance) is List<AchiementntAccumulate> accList)
220+
{
221+
foreach (var title in accList)
222+
{
223+
if (TranslationDB.EntityInfo.TryGetValue($"Ach_{title.key}_Title", out var transValue))
224+
{
225+
Logger.Log($"{title.title} to {transValue}");
226+
if (!transValue.Trim().IsNullOrWhiteSpace())
227+
title. = transValue;
228+
}
229+
}
230+
}
231+
*/
232+
}
233+
}
189234

190235
[HarmonyPatch(typeof(Controler), nameof(PlayableCharacter.LoadResource))]
191236
public static class EntityFix
@@ -199,6 +244,7 @@ public static void Postfix(ref Controler.EntityXml __result)
199244
}
200245
}
201246
}
247+
202248

203249
[HarmonyPatch(typeof(CreditComponent), "Update")]
204250
public static class CreditFix

DungeonArtifactTrans/TranslationDB.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public static class TranslationDB
1616
public static Dictionary<string, string> ScenarioInfo = null;
1717
public static Dictionary<string, TranslationItem> LangDescription = null;
1818
public static Dictionary<string, string> EntityInfo = null;
19+
public static Dictionary<string, string> AchievementAccumlateInfo = null;
20+
public static Dictionary<string, string> AchievementTitleInfo = null;
1921

2022
public static void Init()
2123
{
@@ -160,6 +162,46 @@ public static void Init()
160162

161163
VocabularyInfo2 = dst;
162164
}
165+
166+
{
167+
// 读取 JSON 文件内容
168+
string jsonContent = File.ReadAllText(
169+
Path.Join(modPath, "AchievementAccumlate_translated.json"));
170+
171+
// 反序列化 JSON 字符串为 TranslationItem 结构体的列表
172+
var items = JsonConvert.DeserializeObject<List<TranslationItem>>(jsonContent);
173+
var dst = new Dictionary<string, string>();
174+
foreach (var item in items)
175+
{
176+
if (!dst.TryAdd(item.Key, item.Translation))
177+
{
178+
Logger.Log($"Find Duplicated Item {item.Original}, content {item.Translation}");
179+
continue;
180+
}
181+
}
182+
183+
AchievementAccumlateInfo = dst;
184+
}
185+
186+
{
187+
// 读取 JSON 文件内容
188+
string jsonContent = File.ReadAllText(
189+
Path.Join(modPath, "AchievementTitle_translated.json"));
190+
191+
// 反序列化 JSON 字符串为 TranslationItem 结构体的列表
192+
var items = JsonConvert.DeserializeObject<List<TranslationItem>>(jsonContent);
193+
var dst = new Dictionary<string, string>();
194+
foreach (var item in items)
195+
{
196+
if (!dst.TryAdd(item.Key, item.Translation))
197+
{
198+
Logger.Log($"Find Duplicated Item {item.Original}, content {item.Translation}");
199+
continue;
200+
}
201+
}
202+
203+
AchievementTitleInfo = dst;
204+
}
163205
}
164206

165207

0 commit comments

Comments
 (0)