Skip to content

Commit

Permalink
Error handling for dialogue starting
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Sep 9, 2024
1 parent 3b2b516 commit 3265a9f
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions Winch/Patches/API/DialogueRunnerPatcher.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System;
using HarmonyLib;
using UnityEngine;
using HarmonyLib;
using Winch.Core;
using Winch.Core.API;
using Winch.Util;

namespace Winch.Patches.API;

[HarmonyPriority(Priority.First)]
[HarmonyPatch(typeof(DredgeDialogueRunner), nameof(DredgeDialogueRunner.Awake))]
[HarmonyPatch(typeof(DredgeDialogueRunner))]
internal static class DialogueRunnerPatcher
{
public static void Postfix(DredgeDialogueRunner __instance)
[HarmonyPostfix]
[HarmonyPriority(Priority.First)]
[HarmonyPatch(nameof(DredgeDialogueRunner.Awake))]
public static void Awake_Postfix(DredgeDialogueRunner __instance)
{
__instance.AddCommandHandler<string>("LogDebug", __instance.LogDebug);
__instance.AddCommandHandler<string>("LogInfo", __instance.LogInfo);
Expand Down Expand Up @@ -39,4 +38,21 @@ private static void LogError(this DredgeDialogueRunner dialogueRunner, string me
{
WinchCore.Log.Debug(message, dialogueRunner.CurrentNodeName);
}

[HarmonyPrefix]
[HarmonyPriority(Priority.First)]
[HarmonyPatch(nameof(DredgeDialogueRunner.StartDialogue))]
public static bool StartDialogue_Prefix(DredgeDialogueRunner __instance, string nodeName)
{
if (!__instance.Dialogue.IsActive && !__instance.NodeExists(nodeName))
{
WinchCore.Log.Error("No node named " + nodeName + " has been loaded.", "DredgeDialogueRunner.StartDialogue");
GameEvents.Instance.TriggerDialogueStarted();
__instance.onDialogueComplete.Invoke();
return false;
}
else
return true;
}

}

0 comments on commit 3265a9f

Please sign in to comment.