Browse Source

Added WriterState signal

master
Christopher 8 years ago
parent
commit
73c93669b5
  1. 25
      Assets/Fungus/Scripts/Components/Writer.cs
  2. 9
      Assets/Fungus/Scripts/Signals/WriterSignals.cs
  3. 7
      Assets/Tests/Signals/SignalsTests.unity
  4. 38
      Assets/Tests/Signals/WriterSignalsTester.cs

25
Assets/Fungus/Scripts/Components/Writer.cs

@ -12,6 +12,23 @@ using Fungus.Utils;
namespace Fungus
{
/// <summary>
/// Current state of the writing process.
/// </summary>
public enum WriterState
{
/// <summary> Invalid state. </summary>
Invalid,
/// <summary> Writer has started writing. </summary>
Start,
/// <summary> Writing has been paused. </summary>
Pause,
/// <summary> Writing has resumed after a pause. </summary>
Resume,
/// <summary> Writing has ended. </summary>
End
}
/// <summary>
/// Writes text using a typewriter effect to a UI text object.
/// </summary>
@ -677,6 +694,8 @@ namespace Fungus
protected virtual void NotifyStart(AudioClip audioClip)
{
WriterSignals.DoWriterState(this, WriterState.Start);
foreach (IWriterListener writerListener in writerListeners)
{
writerListener.OnStart(audioClip);
@ -685,6 +704,8 @@ namespace Fungus
protected virtual void NotifyPause()
{
WriterSignals.DoWriterState(this, WriterState.Pause);
foreach (IWriterListener writerListener in writerListeners)
{
writerListener.OnPause();
@ -693,6 +714,8 @@ namespace Fungus
protected virtual void NotifyResume()
{
WriterSignals.DoWriterState(this, WriterState.Resume);
foreach (IWriterListener writerListener in writerListeners)
{
writerListener.OnResume();
@ -701,6 +724,8 @@ namespace Fungus
protected virtual void NotifyEnd(bool stopAudio)
{
WriterSignals.DoWriterState(this, WriterState.End);
foreach (IWriterListener writerListener in writerListeners)
{
writerListener.OnEnd(stopAudio);

9
Assets/Fungus/Scripts/Signals/WriterSignals.cs

@ -16,7 +16,14 @@ namespace Fungus
/// </summary>
public delegate void TextTagTokenHandler(Writer writer, TextTagToken token, int index, int maxIndex);
public static event TextTagTokenHandler OnTextTagToken;
public static void DoTextTagToken(Writer writer, TextTagToken token, int index, int maxIndex){ if(OnTextTagToken != null) OnTextTagToken(writer, token, index, maxIndex); }
public static void DoTextTagToken(Writer writer, TextTagToken token, int index, int maxIndex) { if(OnTextTagToken != null) OnTextTagToken(writer, token, index, maxIndex); }
/// <summary>
/// WriterState signal. Sent when the writer changes state.
/// </summary>
public delegate void WriterStateHandler(Writer writer, WriterState writerState);
public static event WriterStateHandler OnWriterState;
public static void DoWriterState(Writer writer, WriterState writerState) { if (OnWriterState != null) OnWriterState(writer, writerState); }
#endregion
}

7
Assets/Tests/Signals/SignalsTests.unity

@ -306,7 +306,7 @@ MonoBehaviour:
textObject: {fileID: 41796120}
text:
stringRef: {fileID: 0}
stringVal: '{b}hello{/b}'
stringVal: '{b}{w=0.5}hello{/b}'
description:
clearText: 1
waitUntilFinished: 1
@ -378,8 +378,9 @@ MonoBehaviour:
y: -340
width: 1114
height: 859
selectedBlock: {fileID: 0}
selectedCommands: []
selectedBlock: {fileID: 411939903}
selectedCommands:
- {fileID: 411939901}
variables: []
description: Check that Writer signals are sending correctly
stepPause: 0

38
Assets/Tests/Signals/WriterSignalsTester.cs

@ -9,9 +9,12 @@ namespace Fungus
[AddComponentMenu("")]
public class WriterSignalsTester : MonoBehaviour
{
int correctTagCount = 0;
void OnEnable()
{
WriterSignals.OnTextTagToken += OnTextTagToken;
WriterSignals.OnWriterState += OnWriterState;
}
void OnDisable()
@ -21,15 +24,44 @@ namespace Fungus
void OnTextTagToken(Writer writer, TextTagToken token, int index, int maxIndex)
{
if (index == 0 && token.type != TokenType.BoldStart)
if (index == 0 && token.type == TokenType.BoldStart)
{
correctTagCount++;
}
else if (index == 1 && token.type == TokenType.Wait)
{
correctTagCount++;
}
else if (index == 2 && token.type == TokenType.Words)
{
correctTagCount++;
}
else if (index == 3 && token.type == TokenType.BoldEnd)
{
correctTagCount++;
}
}
void OnWriterState(Writer writer, WriterState writerState)
{
if (writerState == WriterState.Start && correctTagCount != 0)
{
IntegrationTest.Fail();
}
if (writerState == WriterState.Pause && correctTagCount != 2)
{
IntegrationTest.Fail();
}
else if (index == 1 && token.type != TokenType.Words)
if (writerState == WriterState.Resume && correctTagCount != 2)
{
IntegrationTest.Fail();
}
else if (index == 2 && token.type == TokenType.BoldEnd)
else if (writerState == WriterState.End && correctTagCount != 4)
{
IntegrationTest.Fail();
}
if (writerState == WriterState.End)
{
IntegrationTest.Pass();
}

Loading…
Cancel
Save