diff --git a/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs b/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs index d224fffa..195b34eb 100644 --- a/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.IO; using System.Xml.Linq; using UnityEngine; +using UnityEngine.InputSystem.HID; namespace NewHorizons.Builder.ShipLog { @@ -154,6 +155,35 @@ namespace NewHorizons.Builder.ShipLog } } + public static void MergeEntries(ShipLogManager manager, ShipLogEntry entry, ShipLogEntry existing) + { + foreach (var fact in entry.GetRumorFacts()) + { + existing._rumorFacts.Add(fact); + fact.OnFactRevealed += existing.OnFactRevealed; + + manager._factRevealCount = Mathf.Max(manager._factRevealCount, fact.GetRevealOrder()); + manager._factList.Add(fact); + manager._factDict.Add(fact.GetID(), fact); + } + foreach (var fact in entry.GetExploreFacts()) + { + existing._exploreFacts.Add(fact); + existing._completionFacts.Add(fact); + fact.OnFactRevealed += existing.OnFactRevealed; + + manager._factRevealCount = Mathf.Max(manager._factRevealCount, fact.GetRevealOrder()); + manager._factList.Add(fact); + manager._factDict.Add(fact.GetID(), fact); + } + foreach (var child in entry.GetChildren()) + { + existing._childEntries.Add(child); + + manager.AddEntry(child); + } + } + private static void AddTranslation(XElement entry) { XElement nameElement = entry.Element("Name"); diff --git a/NewHorizons/Patches/ShipLogPatches/ShipLogManagerPatches.cs b/NewHorizons/Patches/ShipLogPatches/ShipLogManagerPatches.cs index b76d61bb..5fe2684b 100644 --- a/NewHorizons/Patches/ShipLogPatches/ShipLogManagerPatches.cs +++ b/NewHorizons/Patches/ShipLogPatches/ShipLogManagerPatches.cs @@ -129,5 +129,18 @@ namespace NewHorizons.Patches.ShipLogPatches return false; } } + + [HarmonyPrefix] + [HarmonyPatch(nameof(ShipLogManager.AddEntry))] + public static bool ShipLogManager_AddEntry(ShipLogManager __instance, ShipLogEntry entry) + { + if (__instance._entryDict.TryGetValue(entry.GetID(), out var existing)) + { + NHLogger.LogVerbose($"Merging duplicate shiplog entry: {entry.GetID()}"); + RumorModeBuilder.MergeEntries(__instance, entry, existing); + return false; + } + return true; + } } }