From f3c953fafff7126f4e7d5ce081fb4c1755865c4c Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 1 Jul 2023 19:08:22 -0400 Subject: [PATCH] Make hearthian recording actually work --- NewHorizons/Builder/Props/DialogueBuilder.cs | 27 +++++++++++++++++-- .../Modules/Props/Dialogue/DialogueInfo.cs | 2 ++ .../HearthianRecorderEffectsPatches.cs | 24 +++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 NewHorizons/Patches/DialoguePatches/HearthianRecorderEffectsPatches.cs diff --git a/NewHorizons/Builder/Props/DialogueBuilder.cs b/NewHorizons/Builder/Props/DialogueBuilder.cs index ac2f8c17..8016f80d 100644 --- a/NewHorizons/Builder/Props/DialogueBuilder.cs +++ b/NewHorizons/Builder/Props/DialogueBuilder.cs @@ -199,8 +199,31 @@ namespace NewHorizons.Builder.Props } else if (hearthianRecorder != null) { - // #520 - hearthianRecorder._characterDialogueTree = dialogue; + Delay.FireOnNextUpdate(() => + { + // #520 + if (hearthianRecorder._characterDialogueTree != null) + { + hearthianRecorder._characterDialogueTree.OnStartConversation -= hearthianRecorder.OnPlayRecorder; + hearthianRecorder._characterDialogueTree.OnEndConversation -= hearthianRecorder.OnStopRecorder; + } + + // Recorder props have their own dialogue on them already + // Make sure to delete it when we're trying to connect new dialogue to it + var existingDialogue = hearthianRecorder.GetComponent(); + if (existingDialogue != dialogue && existingDialogue != null) + { + // Can't delete the existing dialogue because its a required component but we can make it unable to select at least + GameObject.Destroy(hearthianRecorder.GetComponent()); + GameObject.Destroy(hearthianRecorder.GetComponent()); + GameObject.Destroy(existingDialogue._interactVolume); + existingDialogue.enabled = false; + } + + hearthianRecorder._characterDialogueTree = dialogue; + hearthianRecorder._characterDialogueTree.OnStartConversation += hearthianRecorder.OnPlayRecorder; + hearthianRecorder._characterDialogueTree.OnEndConversation += hearthianRecorder.OnStopRecorder; + }); } else { diff --git a/NewHorizons/External/Modules/Props/Dialogue/DialogueInfo.cs b/NewHorizons/External/Modules/Props/Dialogue/DialogueInfo.cs index 9fb77d6e..06207150 100644 --- a/NewHorizons/External/Modules/Props/Dialogue/DialogueInfo.cs +++ b/NewHorizons/External/Modules/Props/Dialogue/DialogueInfo.cs @@ -25,6 +25,8 @@ namespace NewHorizons.External.Modules.Props.Dialogue /// CharacterAnimController, TravelerController, TravelerEyeController (eye of the universe), FacePlayerWhenTalking, /// HearthianRecorderEffects or SolanumAnimController. /// + /// If it's a Recorder this will also delete the existing dialogue already attached to that prop. + /// /// If none of those components are present it will add a FacePlayerWhenTalking component. /// public string pathToAnimController; diff --git a/NewHorizons/Patches/DialoguePatches/HearthianRecorderEffectsPatches.cs b/NewHorizons/Patches/DialoguePatches/HearthianRecorderEffectsPatches.cs new file mode 100644 index 00000000..b4b28a55 --- /dev/null +++ b/NewHorizons/Patches/DialoguePatches/HearthianRecorderEffectsPatches.cs @@ -0,0 +1,24 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.DialoguePatches +{ + [HarmonyPatch(typeof(HearthianRecorderEffects))] + public static class HearthianRecorderEffectsPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(HearthianRecorderEffects.Awake))] + public static bool HearthianRecorderEffects_Awake(HearthianRecorderEffects __instance) + { + // If we're adding custom dialogue to a recorder the CharacterDialogueTree isn't going to be on the object + if (__instance.GetComponent() == null) + { + __instance.enabled = false; + return false; + } + else + { + return true; + } + } + } +}