From eef07944467669a8b047719a5b53ef08119f68a8 Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Tue, 3 Dec 2024 01:09:14 -0600 Subject: [PATCH 1/3] Patch Ship Log Manager to merge ship log entries with the same ID --- .../Builder/ShipLog/RumorModeBuilder.cs | 30 +++++++++++++++++++ .../ShipLogPatches/ShipLogManagerPatches.cs | 13 ++++++++ 2 files changed, 43 insertions(+) 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; + } } } From 9588c027c5845b2512f2af2f0de8f789c0274055 Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Tue, 3 Dec 2024 01:14:34 -0600 Subject: [PATCH 2/3] Remove spurious import --- NewHorizons/Builder/ShipLog/RumorModeBuilder.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs b/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs index 195b34eb..7f4d28f2 100644 --- a/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs @@ -10,7 +10,6 @@ using System.Collections.Generic; using System.IO; using System.Xml.Linq; using UnityEngine; -using UnityEngine.InputSystem.HID; namespace NewHorizons.Builder.ShipLog { From c2fa1c82372c85176851455c8e0b89bb2e14e2f6 Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Tue, 3 Dec 2024 10:03:24 -0600 Subject: [PATCH 3/3] Add section to ship log docs page on merging ship log entries --- docs/src/content/docs/guides/ship-log.md | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/src/content/docs/guides/ship-log.md b/docs/src/content/docs/guides/ship-log.md index efcc2d42..55399d2b 100644 --- a/docs/src/content/docs/guides/ship-log.md +++ b/docs/src/content/docs/guides/ship-log.md @@ -542,3 +542,28 @@ Adding an entry location is similar to adding a Reveal Volume: ``` ![entryLocationExample](@/assets/docs-images/ship_log/entry_position.webp) + +## Extending Base Game Entries + +You can add new facts and sub-entries to existing ship log entries by adding a dummy entry to your ship log XML file with the same ID as an existing entry. Any facts and sub-entries will be applied to the existing entry. For example, to extend the "Village" entry on Timber Hearth (which has the internal ID "TH_VILLAGE"): + +```xml title="ExampleShipLog.xml" + + TIMBER_HEARTH + + TH_VILLAGE + + EXAMPLES_VILLAGE + A lot of unfamiliar characters are hanging around the village now. + + + EXAMPLES_DREAM + Wetrock Dream + + EXAMPLES_DREAM_EXPLORED + I dreamed about Wetrock using a green campfire. + + + + +```