Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DialogueRunner parameter added to DialoguePresenterBase / DialogueViewBase #309

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Editor/Importers/YarnProjectImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ internal IEnumerable<string> GetErrorsForScript(TextAsset sourceScript)
return Enumerable.Empty<string>();
}

internal IEnumerable<StringTableEntry>? GenerateStringsTable()
public IEnumerable<StringTableEntry>? GenerateStringsTable()
{
var job = GetCompilationJob();
job.CompilationType = CompilationJob.Type.StringsOnly;
Expand Down
4 changes: 2 additions & 2 deletions Runtime/DialogueRunner/DialogueRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ async YarnTask RunLineAndInvokeCompletion(DialoguePresenterBase view, LocalizedL
try
{
// Run the line and wait for it to finish
await view.RunLineAsync(localisedLine, token);
await view.RunLineAsync(this, localisedLine, token);
}
catch (System.Exception e)
{
Expand Down Expand Up @@ -737,7 +737,7 @@ async YarnTask WaitForOptionsView(DialoguePresenterBase? view)
{
return;
}
var result = await view.RunOptionsAsync(localisedOptions, optionCancellationSource.Token);
var result = await view.RunOptionsAsync(this, localisedOptions, optionCancellationSource.Token);
if (result != null)
{
// We no longer need the other views, so tell them to stop
Expand Down
5 changes: 3 additions & 2 deletions Runtime/Localisation/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void AddLocalizedStrings(IEnumerable<StringTableEntry> stringTableEntries

return null;
}
#endif
#else
public YarnTask<T?> GetLocalizedObjectAsync<T>(string key) where T : UnityEngine.Object
{
if (!entries.TryGetValue(key, out var entry))
Expand All @@ -210,6 +210,7 @@ public void AddLocalizedStrings(IEnumerable<StringTableEntry> stringTableEntries

return null;
}
#endif

#if UNITY_EDITOR
internal T? GetLocalizedObjectSync<T>(string key) where T : UnityEngine.Object
Expand Down Expand Up @@ -277,7 +278,7 @@ public void AddLocalizedObjectToAsset<T>(string key, T value) where T : UnityEng
entry.localizedAsset = value;
}
#endif
#endregion
#endregion

public virtual void Clear()
{
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Views/DialoguePresenterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public abstract class DialoguePresenterBase : MonoBehaviour
/// showing the line to the user.</returns>
/// <seealso cref="RunOptionsAsync(DialogueOption[],
/// CancellationToken)"/>
public abstract YarnTask RunLineAsync(LocalizedLine line, LineCancellationToken token);
public abstract YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine line, LineCancellationToken token);


/// <summary>
Expand Down Expand Up @@ -119,7 +119,7 @@ public abstract class DialoguePresenterBase : MonoBehaviour
/// <returns>A task that indicates which option was selected, or that this dialogue view did not select an option.</returns>
/// <seealso cref="RunLineAsync(LocalizedLine, LineCancellationToken)"/>
/// <seealso cref="YarnAsync.NoOptionSelected"/>
public abstract YarnTask<DialogueOption?> RunOptionsAsync(DialogueOption[] dialogueOptions, CancellationToken cancellationToken);
public abstract YarnTask<DialogueOption?> RunOptionsAsync(DialogueRunner runner, DialogueOption[] dialogueOptions, CancellationToken cancellationToken);

/// <summary>Called by the <see cref="DialogueRunner"/> to signal that
/// dialogue has started.</summary>
Expand Down
20 changes: 10 additions & 10 deletions Runtime/Views/Legacy/DialogueViewBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public virtual void DialogueStarted()
/// <seealso cref="InterruptLine(LocalizedLine, Action)"/>
/// <seealso cref="DismissLine(Action)"/>
/// <seealso cref="RunOptions(DialogueOption[], Action{int})"/>
public virtual void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
public virtual void RunLine(DialogueRunner runner, LocalizedLine dialogueLine, Action onDialogueLineFinished)
{
// The default implementation does nothing, and immediately calls
// onDialogueLineFinished.
Expand Down Expand Up @@ -174,7 +174,7 @@ public virtual void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFin
/// called after the line has finished being presented.</param>
/// <seealso cref="RunLine(LocalizedLine, Action)"/>
/// <seealso cref="DismissLine(Action)"/>
public virtual void InterruptLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
public virtual void InterruptLine(DialogueRunner runner, LocalizedLine dialogueLine, Action onDialogueLineFinished)
{
// the default implementation does nothing
onDialogueLineFinished?.Invoke();
Expand Down Expand Up @@ -217,7 +217,7 @@ public virtual void InterruptLine(LocalizedLine dialogueLine, Action onDialogueL
/// </remarks>
/// <param name="onDismissalComplete">The method that should be called
/// when the view has finished dismissing the line.</param>
public virtual void DismissLine(Action onDismissalComplete)
public virtual void DismissLine(DialogueRunner runner, Action onDismissalComplete)
{
// The default implementation does nothing, and immediately calls
// onDialogueLineFinished.
Expand Down Expand Up @@ -272,7 +272,7 @@ public virtual void DismissLine(Action onDismissalComplete)
/// displayed to the user.</param>
/// <param name="onOptionSelected">A method that should be called when
/// the user has made a selection.</param>
public virtual void RunOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
public virtual void RunOptions(DialogueRunner runner, DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
{
// The default implementation does nothing.
}
Expand Down Expand Up @@ -367,7 +367,7 @@ public override YarnTask OnDialogueCompleteAsync()
// This method implements the v3 async pattern for dialogue views on top
// of the v2 API.
/// <inheritdoc/>
public override async YarnTask RunLineAsync(LocalizedLine line, LineCancellationToken token)
public override async YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine line, LineCancellationToken token)
{
// phaseComplete is a flag that represents whether the current
// 'phase' of a v2-style dialogue view (Run, Interrupt, Dismiss) is
Expand All @@ -376,7 +376,7 @@ public override async YarnTask RunLineAsync(LocalizedLine line, LineCancellation
void PhaseComplete() => phaseComplete = true;

// Run the line, and make phaseComplete become true when it's done.
this.RunLine(line, PhaseComplete);
this.RunLine(runner, line, PhaseComplete);

// Wait for one of the following things to happen:
// 1. RunLine completes successfully and calls PhaseComplete.
Expand All @@ -394,7 +394,7 @@ public override async YarnTask RunLineAsync(LocalizedLine line, LineCancellation
if (token.IsNextLineRequested)
{
phaseComplete = false;
this.InterruptLine(line, PhaseComplete);
this.InterruptLine(runner, line, PhaseComplete);
while (phaseComplete == false
&& Application.exitCancellationToken.IsCancellationRequested == false)
{
Expand All @@ -405,7 +405,7 @@ public override async YarnTask RunLineAsync(LocalizedLine line, LineCancellation
// Finally, signal that the line should be dismissed, and wait for
// the dismissal to complete.
phaseComplete = false;
this.DismissLine(PhaseComplete);
this.DismissLine(runner, PhaseComplete);

while (phaseComplete == false
&& Application.exitCancellationToken.IsCancellationRequested == false)
Expand All @@ -417,13 +417,13 @@ public override async YarnTask RunLineAsync(LocalizedLine line, LineCancellation
// This method implements the v3 async pattern for dialogue views on top
// of the v2 API.
/// <inheritdoc/>
public override async YarnTask<DialogueOption?> RunOptionsAsync(DialogueOption[] dialogueOptions, CancellationToken cancellationToken)
public override async YarnTask<DialogueOption?> RunOptionsAsync(DialogueRunner runner, DialogueOption[] dialogueOptions, CancellationToken cancellationToken)
{
int selectedOptionID = -1;

// Run the options, and wait for either a selection to be made, or
// for this view to be cancelled.
this.RunOptions(dialogueOptions, (selectedID) =>
this.RunOptions(runner, dialogueOptions, (selectedID) =>
{
selectedOptionID = selectedID;
});
Expand Down
6 changes: 3 additions & 3 deletions Runtime/Views/Legacy/LineView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private void Reset()
}

/// <inheritdoc/>
public override void DismissLine(Action onDismissalComplete)
public override void DismissLine(DialogueRunner runner, Action onDismissalComplete)
{
currentLine = null;

Expand Down Expand Up @@ -278,7 +278,7 @@ private IEnumerator DismissLineInternal(Action onDismissalComplete)
}

/// <inheritdoc/>
public override void InterruptLine(LocalizedLine dialogueLine, Action onInterruptLineFinished)
public override void InterruptLine(DialogueRunner runner, LocalizedLine dialogueLine, Action onInterruptLineFinished)
{
if (this == null)
{
Expand Down Expand Up @@ -333,7 +333,7 @@ public override void InterruptLine(LocalizedLine dialogueLine, Action onInterrup
}

/// <inheritdoc/>
public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
public override void RunLine(DialogueRunner runner, LocalizedLine dialogueLine, Action onDialogueLineFinished)
{
// Stop any coroutines currently running on this line view (for
// example, any other RunLine that might be running)
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Views/Legacy/OptionsListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public void Reset()
canvasGroup = GetComponentInParent<CanvasGroup>();
}

public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
public override void RunLine(DialogueRunner runner, LocalizedLine dialogueLine, Action onDialogueLineFinished)
{
// Don't do anything with this line except note it and immediately
// indicate that we're finished with it. RunOptions will use it to
// display the text of the previous line.
lastSeenLine = dialogueLine;
onDialogueLineFinished();
}
public override void RunOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
public override void RunOptions(DialogueRunner runner, DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
{
// If we don't already have enough option views, create more
while (dialogueOptions.Length > optionViews.Count)
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Views/LineAdvancer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public override YarnTask OnDialogueCompleteAsync()
/// </summary>
/// <inheritdoc cref="LinePresenter.RunLineAsync" path="/param"/>
/// <returns>A completed task.</returns>
public override YarnTask RunLineAsync(LocalizedLine line, LineCancellationToken token)
public override YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine line, LineCancellationToken token)
{
// A new line has come in, so reset the number of times we've seen a
// request to skip.
Expand All @@ -321,7 +321,7 @@ public override YarnTask RunLineAsync(LocalizedLine line, LineCancellationToken
/// <inheritdoc cref="LinePresenter.RunOptionsAsync" path="/param"/>
/// <returns>A completed task indicating that no option was selected by
/// this view.</returns>
public override YarnTask<DialogueOption?> RunOptionsAsync(DialogueOption[] dialogueOptions, CancellationToken cancellationToken)
public override YarnTask<DialogueOption?> RunOptionsAsync(DialogueRunner runner, DialogueOption[] dialogueOptions, CancellationToken cancellationToken)
{
// This line view doesn't take any actions when options are
// presented.
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Views/LinePresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private void Start()
/// <summary>Presents a line using the configured text view.</summary>
/// <inheritdoc cref="DialoguePresenterBase.RunLineAsync(LocalizedLine, LineCancellationToken)" path="/param"/>
/// <inheritdoc cref="DialoguePresenterBase.RunLineAsync(LocalizedLine, LineCancellationToken)" path="/returns"/>
public override async YarnTask RunLineAsync(LocalizedLine line, LineCancellationToken token)
public override async YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine line, LineCancellationToken token)
{
if (lineText == null)
{
Expand Down Expand Up @@ -405,7 +405,7 @@ public override async YarnTask RunLineAsync(LocalizedLine line, LineCancellation
/// <remarks>
/// This dialogue view does not handle any options.
/// </remarks>
public override YarnTask<DialogueOption?> RunOptionsAsync(DialogueOption[] dialogueOptions, CancellationToken cancellationToken)
public override YarnTask<DialogueOption?> RunOptionsAsync(DialogueRunner runner, DialogueOption[] dialogueOptions, CancellationToken cancellationToken)
{
return YarnTask<DialogueOption?>.FromResult(null);
}
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Views/OptionsPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public override YarnTask OnDialogueStartedAsync()
/// <inheritdoc cref="DialoguePresenterBase.RunLineAsync"
/// path="/param"/>
/// <returns>A completed task.</returns>
public override YarnTask RunLineAsync(LocalizedLine line, LineCancellationToken token)
public override YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine line, LineCancellationToken token)
{
if (showsLastLine)
{
Expand All @@ -162,7 +162,7 @@ public override YarnTask RunLineAsync(LocalizedLine line, LineCancellationToken
/// path="/param"/>
/// <inheritdoc cref="DialoguePresenterBase.RunOptionsAsync"
/// path="/returns"/>
public override async YarnTask<DialogueOption?> RunOptionsAsync(DialogueOption[] dialogueOptions, CancellationToken cancellationToken)
public override async YarnTask<DialogueOption?> RunOptionsAsync(DialogueRunner runner, DialogueOption[] dialogueOptions, CancellationToken cancellationToken)
{
// If we don't already have enough option views, create more
while (dialogueOptions.Length > optionViews.Count)
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Views/VoiceOverPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void Reset()
/// LineCancellationToken)" path="/param"/>
/// <seealso cref="DialoguePresenterBase.RunLineAsync(LocalizedLine,
/// LineCancellationToken)"/>
public override async YarnTask RunLineAsync(LocalizedLine dialogueLine, LineCancellationToken lineCancellationToken)
public override async YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine dialogueLine, LineCancellationToken lineCancellationToken)
{
// Get the localized voice over audio clip
AudioClip? voiceOverClip = null;
Expand Down Expand Up @@ -240,7 +240,7 @@ public override YarnTask OnDialogueCompleteAsync()
}

/// <inheritdoc/>
public override YarnTask<DialogueOption?> RunOptionsAsync(DialogueOption[] dialogueOptions, CancellationToken cancellationToken)
public override YarnTask<DialogueOption?> RunOptionsAsync(DialogueRunner runner, DialogueOption[] dialogueOptions, CancellationToken cancellationToken)
{
return DialogueRunner.NoOptionSelected;
}
Expand Down