From 754bb013be45b97eb8ea32810be78f505472971d Mon Sep 17 00:00:00 2001 From: Flowaria Date: Sat, 27 Dec 2025 00:07:51 +0900 Subject: [PATCH] - Added Revision Matching - Better Export pathing --- Dialogues/DialogueLoader.cs | 23 +++++++++++++------ ...CalamityDialogue.DevourerOfGods.Death.json | 1 + .../CalamityDialogue.DevourerOfGods.Head.json | 1 + ...alamityDialogue.DevourerOfGods.Phases.json | 1 + ...lamityDialogue.DevourerOfGods.Running.json | 1 + UI/DialogueDisplay/DialogueDisplayUI.cs | 5 ++++ 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Dialogues/DialogueLoader.cs b/Dialogues/DialogueLoader.cs index d4e9878056..ea4d128607 100644 --- a/Dialogues/DialogueLoader.cs +++ b/Dialogues/DialogueLoader.cs @@ -78,20 +78,21 @@ internal class DialogueLoader : ModSystem cursor.EmitLdloc(modLdloc); cursor.EmitLdloc(pathLdloc); - cursor.EmitDelegate((Mod mod, string path) => + cursor.EmitDelegate((Mod mod, string basePath) => { if (mod != CalamityMod.Instance) return; - var exportPath = Path.Combine(path, "Dialogues", "en-US"); - if (!Directory.Exists(exportPath)) Directory.CreateDirectory(exportPath); - foreach (var entry in GetDialogueTextDatas(CalamityMod.Instance, GameCulture.DefaultCulture, skipDeserializeData: true)) { try { + var destFilePath = Path.Combine(basePath, entry.FilePath); + var destDir = Path.GetDirectoryName(destFilePath); + if (!Directory.Exists(destDir)) Directory.CreateDirectory(destDir); + using var stream = CalamityMod.Instance.File.GetStream(entry.FilePath); - using var fileStream = File.OpenWrite(Path.Combine(exportPath, Path.GetFileName(entry.FilePath))); + using var fileStream = File.OpenWrite(destFilePath); using var writer = new StreamWriter(fileStream, Encoding.UTF8); using var reader = new StreamReader(stream, Encoding.UTF8); writer.Write(reader.ReadToEnd()); @@ -130,8 +131,17 @@ internal class DialogueLoader : ModSystem { foreach (var entry in GetDialogueTextDatas(mod, activeCulture)) { - if (!_DialogueLookup.ContainsKey(entry.DialogueKey)) + if (!_DialogueLookup.TryGetValue(entry.DialogueKey, out var oldEntry)) + { + CalamityMod.Log.Warn($"Dialogue Localization was detected but original Dialogue file does not exists. This will not be applied! : '{entry.FilePath}'"); continue; + } + + if (entry.Data.Revision != oldEntry.Data.Revision) + { + CalamityMod.Log.Warn($"Dialogue Localization was detected but revision mismatches. This will not be applied! : '{entry.FilePath}'"); + continue; + } _DialogueLookup[entry.DialogueKey] = entry; } @@ -184,7 +194,6 @@ internal class DialogueLoader : ModSystem if (data != null || skipDeserializeData) { - CalamityMod.Log.Info($"Found Dialogue Item: '{mod.Name}', '{file.Name}', '{prefix}', '{culture.Name}'"); yield return new DialogueTextDataEntry(file.Name, dialogueKey, data); } } diff --git a/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Death.json b/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Death.json index 808d9f0d2a..3e92c78a0f 100644 --- a/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Death.json +++ b/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Death.json @@ -1,4 +1,5 @@ { + "Revision": 1, "DefaultColor": "6383FF", "DefaultSpeaker": "DevourerOfGods", "AlignType": 1, diff --git a/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Head.json b/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Head.json index 23af53b64e..93da2b43ff 100644 --- a/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Head.json +++ b/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Head.json @@ -1,4 +1,5 @@ { + "Revision": 1, "DefaultColor": "6383FF", "DefaultSpeaker": "DevourerOfGods", "AlignType": 1, diff --git a/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Phases.json b/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Phases.json index ea29aca85b..3ae52d8b17 100644 --- a/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Phases.json +++ b/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Phases.json @@ -1,4 +1,5 @@ { + "Revision": 1, "DefaultColor": "6383FF", "DefaultSpeaker": "DevourerOfGods", "AlignType": 1, diff --git a/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Running.json b/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Running.json index 697082968b..de35cd7052 100644 --- a/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Running.json +++ b/Dialogues/en-US/CalamityDialogue.DevourerOfGods.Running.json @@ -1,4 +1,5 @@ { + "Revision": 1, "DefaultColor": "6383FF", "DefaultSpeaker": "DevourerOfGods", "AlignType": 1, diff --git a/UI/DialogueDisplay/DialogueDisplayUI.cs b/UI/DialogueDisplay/DialogueDisplayUI.cs index 0cbef28634..5739c68a8c 100644 --- a/UI/DialogueDisplay/DialogueDisplayUI.cs +++ b/UI/DialogueDisplay/DialogueDisplayUI.cs @@ -1198,6 +1198,11 @@ namespace CalamityMod.UI.DialogueDisplay public int PunctuationDelayCap { get; init; } public Dictionary PunctuationDelays { get; init; } + /// + /// Only used for DialogueLoader + /// + public int Revision { get; init; } + [JsonConstructor] public DialogueTextData(DialoguePage[] Pages, int Page = 0, string DefaultColor = null, string DefaultSpeaker = null, int DefaultScale = 1, Alignment AlignType = 0, int TextDelay = 3, PunctuationData BasePunctuationDelay = null, int PunctuationDelayCap = 60, Dictionary PunctuationDelays = null) {