Patch Ship Log Manager to merge ship log entries with the same ID

This commit is contained in:
Joshua Thome 2024-12-03 01:09:14 -06:00
parent 66886f9b2f
commit eef0794446
2 changed files with 43 additions and 0 deletions

View File

@ -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");

View File

@ -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;
}
}
}