From 44e2a2b53277438f710fbfc6cbbc92613d83ba86 Mon Sep 17 00:00:00 2001 From: Paul Joannon Date: Wed, 30 Oct 2024 23:41:45 +0100 Subject: [PATCH] Add error signals [CHANGELOG] Add new signals emitted when errors occur: `AuthorError`, `WarningError`, `ErrorError` --- addons/GodotInk/Src/InkStory.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/addons/GodotInk/Src/InkStory.cs b/addons/GodotInk/Src/InkStory.cs index cf3b95e..8d804ed 100644 --- a/addons/GodotInk/Src/InkStory.cs +++ b/addons/GodotInk/Src/InkStory.cs @@ -22,6 +22,15 @@ public partial class InkStory : Resource [Signal] public delegate void MadeChoiceEventHandler(InkChoice choice); + [Signal] + public delegate void AuthorErrorEventHandler(string message); + + [Signal] + public delegate void WarningErrorEventHandler(string message); + + [Signal] + public delegate void ErrorErrorEventHandler(string message); + protected virtual string RawStory { get => rawStory; @@ -57,12 +66,14 @@ private void InitializeRuntimeStory() { runtimeStory.onDidContinue -= OnContinued; runtimeStory.onMakeChoice -= OnMadeChoice; + runtimeStory.onError -= OnError; } runtimeStory = new Ink.Runtime.Story(rawStory); runtimeStory.onDidContinue += OnContinued; runtimeStory.onMakeChoice += OnMadeChoice; + runtimeStory.onError += OnError; } public string CurrentText => runtimeStory.currentText; @@ -694,6 +705,24 @@ private void OnMadeChoice(Ink.Runtime.Choice choice) _ = EmitSignal(SignalName.MadeChoice, new InkChoice(choice)); } + private void OnError(string message, Ink.ErrorType type) + { + switch (type) + { + case Ink.ErrorType.Author: + _ = EmitSignal(SignalName.AuthorError, message); + break; + case Ink.ErrorType.Warning: + _ = EmitSignal(SignalName.WarningError, message); + break; + case Ink.ErrorType.Error: + _ = EmitSignal(SignalName.ErrorError, message); + break; + default: + return; + } + } + public override PropertyList _GetPropertyList() { PropertyList properties = base._GetPropertyList() ?? new PropertyList();