Browse Source

Added token index

master
Christopher 8 years ago
parent
commit
e1ed5eabcd
  1. 7
      Assets/Fungus/Scripts/Components/Writer.cs
  2. 4
      Assets/Fungus/Scripts/Signals/WriterSignals.cs
  3. 14
      Assets/Tests/Signals/WriterSignalsTester.cs

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

@ -232,9 +232,12 @@ namespace Fungus
TokenType previousTokenType = TokenType.Invalid;
foreach (TextTagToken token in tokens)
for (int i = 0; i < tokens.Count; ++i)
{
WriterSignals.DoTextTagToken(this, token);
var token = tokens[i];
// Notify listeners about new token
WriterSignals.DoTextTagToken(this, token, i, tokens.Count);
switch (token.type)
{

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

@ -14,9 +14,9 @@ namespace Fungus
/// <summary>
/// TextTagToken signal. Sent for each unique token when writing text.
/// </summary>
public delegate void TextTagTokenHandler(Writer writer, TextTagToken token);
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){ if(OnTextTagToken != null) OnTextTagToken(writer, token); }
public static void DoTextTagToken(Writer writer, TextTagToken token, int index, int maxIndex){ if(OnTextTagToken != null) OnTextTagToken(writer, token, index, maxIndex); }
#endregion
}

14
Assets/Tests/Signals/WriterSignalsTester.cs

@ -9,8 +9,6 @@ namespace Fungus
[AddComponentMenu("")]
public class WriterSignalsTester : MonoBehaviour
{
int step = 0;
void OnEnable()
{
WriterSignals.OnTextTagToken += OnTextTagToken;
@ -21,17 +19,17 @@ namespace Fungus
WriterSignals.OnTextTagToken -= OnTextTagToken;
}
void OnTextTagToken(Writer writer, TextTagToken token)
void OnTextTagToken(Writer writer, TextTagToken token, int index, int maxIndex)
{
if (step == 0 && token.type == TokenType.BoldStart)
if (index == 0 && token.type != TokenType.BoldStart)
{
step = 1;
IntegrationTest.Fail();
}
else if (step == 1 && token.type == TokenType.Words)
else if (index == 1 && token.type != TokenType.Words)
{
step = 2;
IntegrationTest.Fail();
}
else if (step == 2 && token.type == TokenType.BoldEnd)
else if (index == 2 && token.type == TokenType.BoldEnd)
{
IntegrationTest.Pass();
}

Loading…
Cancel
Save