From deb5223c03d66932ac7b23b1f606c43614b69252 Mon Sep 17 00:00:00 2001 From: jie65535 Date: Sun, 12 Apr 2026 12:02:10 +0800 Subject: [PATCH] Improve activity update method to use JSON data directly --- Source/GrasscutterTools/Pages/PageTools.cs | 31 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/Source/GrasscutterTools/Pages/PageTools.cs b/Source/GrasscutterTools/Pages/PageTools.cs index 07cd70a..fcd834e 100644 --- a/Source/GrasscutterTools/Pages/PageTools.cs +++ b/Source/GrasscutterTools/Pages/PageTools.cs @@ -171,20 +171,41 @@ namespace GrasscutterTools.Pages { TextMapData.LoadTextMapByLanguage(languageCode); - var activityMap = new Dictionary(activityItems.Count); + // 从 JSON 构建 activityId -> 翻译文本的映射 + var activityMap = new Dictionary(); foreach (var item in activityItems) activityMap[item.ActivityId] = TextMapData.GetText(item.NameTextMapHash); var buffer = new StringBuilder(); - foreach (var item in GameData.Activity) + var processedIds = new HashSet(); + + // 保持原有的分组结构(从 GameData.Activity 读取),保留人工整理的内容 + foreach (var group in GameData.Activity) { - buffer.Append("// ").AppendLine(item.Key); - foreach (var id in item.Value.Ids) + buffer.Append("// ").AppendLine(group.Key); + foreach (var id in group.Value.Ids) { + processedIds.Add(id); buffer.Append(id).Append(':'); - buffer.AppendLine(activityMap.TryGetValue(id, out var title) ? title : item.Value[id]); + // 对于中文,保留人工整理的内容;对于其他语言,使用 JSON 中的官方翻译 + if (languageCode == "zh-cn") + buffer.AppendLine(group.Value[id]); // 使用旧的人工整理的内容 + else + buffer.AppendLine(activityMap.TryGetValue(id, out var title) ? title : group.Value[id]); } } + + // 添加 JSON 中存在但旧文件中不存在的新活动 + var newActivities = activityItems.Where(item => !processedIds.Contains(item.ActivityId)).OrderBy(item => item.ActivityId); + if (newActivities.Any()) + { + buffer.AppendLine("// New"); + foreach (var item in newActivities) + { + buffer.Append(item.ActivityId).Append(':').AppendLine(activityMap[item.ActivityId]); + } + } + var activityFilePath = Path.Combine(TxtProjectResRoot.Text, languageCode, "Activity.txt"); File.WriteAllText(activityFilePath, buffer.ToString(), Encoding.UTF8); }