Skip to content

Commit

Permalink
Add error signals
Browse files Browse the repository at this point in the history
[CHANGELOG]
Add new signals emitted when errors occur: `AuthorError`, `WarningError`, `ErrorError`
  • Loading branch information
paulloz committed Oct 30, 2024
1 parent 43cbffc commit 44e2a2b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions addons/GodotInk/Src/InkStory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 44e2a2b

Please sign in to comment.