Browse Source

Documented all enum values. Moved all enums to namespace scope.

master
Christopher 8 years ago
parent
commit
47b946b306
  1. 20
      Assets/Fungus/Scripts/Commands/Call.cs
  2. 46
      Assets/Fungus/Scripts/Commands/ControlAudio.cs
  3. 10
      Assets/Fungus/Scripts/Commands/ControlStage.cs
  4. 20
      Assets/Fungus/Scripts/Commands/DebugLog.cs
  5. 17
      Assets/Fungus/Scripts/Commands/FadeUI.cs
  6. 20
      Assets/Fungus/Scripts/Commands/Fullscreen.cs
  7. 26
      Assets/Fungus/Scripts/Commands/InvokeEvent.cs
  8. 8
      Assets/Fungus/Scripts/Commands/InvokeMethod.cs
  9. 21
      Assets/Fungus/Scripts/Commands/SendMessage.cs
  10. 29
      Assets/Fungus/Scripts/Commands/SetVariable.cs
  11. 23
      Assets/Fungus/Scripts/Commands/Write.cs
  12. 8
      Assets/Fungus/Scripts/Commands/iTweenCommand.cs
  13. 23
      Assets/Fungus/Scripts/Components/DialogInput.cs
  14. 62
      Assets/Fungus/Scripts/Components/Writer.cs
  15. 17
      Assets/Fungus/Scripts/Components/WriterAudio.cs
  16. 4
      Assets/Fungus/Scripts/Editor/ControlAudioEditor.cs
  17. 12
      Assets/Fungus/Scripts/Editor/InvokeEventEditor.cs
  18. 28
      Assets/Fungus/Scripts/Editor/SetVariableEditor.cs
  19. 10
      Assets/Fungus/Scripts/Editor/WriteEditor.cs
  20. 2
      Assets/Fungus/Scripts/Editor/WriterAudioEditor.cs
  21. 20
      Assets/Fungus/Scripts/EventHandlers/KeyPressed.cs
  22. 4
      Assets/Fungus/Scripts/Interfaces/IBlock.cs
  23. 15
      Assets/Fungus/Scripts/Interfaces/IPortraitController.cs
  24. 23
      Assets/Fungus/Scripts/Interfaces/IVariable.cs
  25. 70
      Assets/Fungus/Scripts/Utils/TextTagParser.cs
  26. 105
      Assets/Fungus/Scripts/Utils/TextTagToken.cs
  27. 84
      Assets/Tests/UI/Editor/TextTagParserTests.cs

20
Assets/Fungus/Scripts/Commands/Call.cs

@ -8,6 +8,19 @@ using System;
namespace Fungus.Commands namespace Fungus.Commands
{ {
/// <summary>
/// Supported modes for calling a block.
/// </summary>
public enum CallMode
{
/// <summary> Stop executing the current block after calling. </summary>
Stop,
/// <summary> Continue executing the current block after calling </summary>
Continue,
/// <summary> Wait until the called block finishes executing, then continue executing current block. </summary>
WaitUntilFinished
}
/// <summary> /// <summary>
/// Execute another block in the same Flowchart as the command, or in a different Flowchart. /// Execute another block in the same Flowchart as the command, or in a different Flowchart.
/// </summary> /// </summary>
@ -17,13 +30,6 @@ namespace Fungus.Commands
[AddComponentMenu("")] [AddComponentMenu("")]
public class Call : Command public class Call : Command
{ {
public enum CallMode
{
Stop, // Stop executing the current block after calling
Continue, // Continue executing the current block after calling
WaitUntilFinished // Wait until the called block finishes executing, then continue executing current block
}
[Tooltip("Flowchart which contains the block to execute. If none is specified then the current Flowchart is used.")] [Tooltip("Flowchart which contains the block to execute. If none is specified then the current Flowchart is used.")]
[SerializeField] protected Flowchart targetFlowchart; [SerializeField] protected Flowchart targetFlowchart;

46
Assets/Fungus/Scripts/Commands/ControlAudio.cs

@ -8,6 +8,23 @@ using Fungus.Variables;
namespace Fungus.Commands namespace Fungus.Commands
{ {
/// <summary>
/// The type of audio control to perform.
/// </summary>
public enum ControlAudioType
{
/// <summary> Play the audiosource once. </summary>
PlayOnce,
/// <summary> Play the audiosource in a loop. </summary>
PlayLoop,
/// <summary> Pause a looping audiosource. </summary>
PauseLoop,
/// <summary> Stop a looping audiosource. </summary>
StopLoop,
/// <summary> Change the volume level of an audiosource. </summary>
ChangeVolume
}
/// <summary> /// <summary>
/// Plays, loops, or stops an audiosource. Any AudioSources with the same tag as the target Audio Source will automatically be stoped. /// Plays, loops, or stops an audiosource. Any AudioSources with the same tag as the target Audio Source will automatically be stoped.
/// </summary> /// </summary>
@ -17,18 +34,9 @@ namespace Fungus.Commands
[ExecuteInEditMode] [ExecuteInEditMode]
public class ControlAudio : Command public class ControlAudio : Command
{ {
public enum ControlType
{
PlayOnce,
PlayLoop,
PauseLoop,
StopLoop,
ChangeVolume
}
[Tooltip("What to do to audio")] [Tooltip("What to do to audio")]
[SerializeField] protected ControlType control; [SerializeField] protected ControlAudioType control;
public virtual ControlType Control { get { return control; } } public virtual ControlAudioType Control { get { return control; } }
[Tooltip("Audio clip to play")] [Tooltip("Audio clip to play")]
[SerializeField] protected AudioSourceData _audioSource; [SerializeField] protected AudioSourceData _audioSource;
@ -55,28 +63,28 @@ namespace Fungus.Commands
return; return;
} }
if (control != ControlType.ChangeVolume) if (control != ControlAudioType.ChangeVolume)
{ {
_audioSource.Value.volume = endVolume; _audioSource.Value.volume = endVolume;
} }
switch(control) switch(control)
{ {
case ControlType.PlayOnce: case ControlAudioType.PlayOnce:
StopAudioWithSameTag(); StopAudioWithSameTag();
PlayOnce(); PlayOnce();
break; break;
case ControlType.PlayLoop: case ControlAudioType.PlayLoop:
StopAudioWithSameTag(); StopAudioWithSameTag();
PlayLoop(); PlayLoop();
break; break;
case ControlType.PauseLoop: case ControlAudioType.PauseLoop:
PauseLoop(); PauseLoop();
break; break;
case ControlType.StopLoop: case ControlAudioType.StopLoop:
StopLoop(_audioSource.Value); StopLoop(_audioSource.Value);
break; break;
case ControlType.ChangeVolume: case ControlAudioType.ChangeVolume:
ChangeVolume(); ChangeVolume();
break; break;
} }
@ -256,11 +264,11 @@ namespace Fungus.Commands
if (fadeDuration > 0) if (fadeDuration > 0)
{ {
fadeType = " Fade out"; fadeType = " Fade out";
if (control != ControlType.StopLoop) if (control != ControlAudioType.StopLoop)
{ {
fadeType = " Fade in volume to " + endVolume; fadeType = " Fade in volume to " + endVolume;
} }
if (control == ControlType.ChangeVolume) if (control == ControlAudioType.ChangeVolume)
{ {
fadeType = " to " + endVolume; fadeType = " to " + endVolume;
} }

10
Assets/Fungus/Scripts/Commands/ControlStage.cs

@ -6,14 +6,24 @@ using Fungus.Utils;
namespace Fungus.Commands namespace Fungus.Commands
{ {
/// <summary>
/// Supported display operations for Stage.
/// </summary>
public enum StageDisplayType public enum StageDisplayType
{ {
/// <summary> No operation </summary>
None, None,
/// <summary> Show the stage and all portraits. </summary>
Show, Show,
/// <summary> Hide the stage and all portraits. </summary>
Hide, Hide,
/// <summary> Swap the stage and all portraits with another stage. </summary>
Swap, Swap,
/// <summary> Move stage to the front. </summary>
MoveToFront, MoveToFront,
/// <summary> Undim all portraits on the stage. </summary>
UndimAllPortraits, UndimAllPortraits,
/// <summary> Dim all non-speaking portraits on the stage. </summary>
DimNonSpeakingPortraits DimNonSpeakingPortraits
} }

20
Assets/Fungus/Scripts/Commands/DebugLog.cs

@ -6,6 +6,19 @@ using Fungus.Variables;
namespace Fungus.Commands namespace Fungus.Commands
{ {
/// <summary>
/// Type of log message. Maps directly to Unity's log types.
/// </summary>
public enum DebugLogType
{
/// <summary> Informative log message. </summary>
Info,
/// <summary> Warning log message. </summary>
Warning,
/// <summary> Error log message. </summary>
Error
}
/// <summary> /// <summary>
/// Writes a log message to the debug console. /// Writes a log message to the debug console.
/// </summary> /// </summary>
@ -15,13 +28,6 @@ namespace Fungus.Commands
[AddComponentMenu("")] [AddComponentMenu("")]
public class DebugLog : Command public class DebugLog : Command
{ {
public enum DebugLogType
{
Info,
Warning,
Error
}
[Tooltip("Display type of debug log info")] [Tooltip("Display type of debug log info")]
[SerializeField] protected DebugLogType logType; [SerializeField] protected DebugLogType logType;

17
Assets/Fungus/Scripts/Commands/FadeUI.cs

@ -8,6 +8,17 @@ using Fungus.Variables;
namespace Fungus.Commands namespace Fungus.Commands
{ {
/// <summary>
/// Select which type of fade will be applied.
/// </summary>
public enum FadeMode
{
/// <summary> Fade the alpha color component only. </summary>
Alpha,
/// <summary> Fade all color components (RGBA). </summary>
Color
}
/// <summary> /// <summary>
/// Fades a UI object. /// Fades a UI object.
/// </summary> /// </summary>
@ -16,12 +27,6 @@ namespace Fungus.Commands
"Fades a UI object")] "Fades a UI object")]
public class FadeUI : TweenUI public class FadeUI : TweenUI
{ {
public enum FadeMode
{
Alpha,
Color
}
[SerializeField] protected FadeMode fadeMode = FadeMode.Alpha; [SerializeField] protected FadeMode fadeMode = FadeMode.Alpha;
[SerializeField] protected ColorData targetColor = new ColorData(Color.white); [SerializeField] protected ColorData targetColor = new ColorData(Color.white);

20
Assets/Fungus/Scripts/Commands/Fullscreen.cs

@ -5,6 +5,19 @@ using UnityEngine;
namespace Fungus.Commands namespace Fungus.Commands
{ {
/// <summary>
/// Fullscreen mode options.
/// </summary>
public enum FullscreenMode
{
/// <summary> Toggle the current mode between fullscreen and windowed. </summary>
Toggle,
/// <summary> Switch to fullscreen mode. </summary>
Fullscreen,
/// <summary> Switch to windowed mode. </summary>
Windowed
}
/// <summary> /// <summary>
/// Sets the application to fullscreen, windowed or toggles the current state. /// Sets the application to fullscreen, windowed or toggles the current state.
/// </summary> /// </summary>
@ -14,13 +27,6 @@ namespace Fungus.Commands
[AddComponentMenu("")] [AddComponentMenu("")]
public class Fullscreen : Command public class Fullscreen : Command
{ {
public enum FullscreenMode
{
Toggle,
Fullscreen,
Windowed
}
[SerializeField] protected FullscreenMode fullscreenMode; [SerializeField] protected FullscreenMode fullscreenMode;
public override void OnEnter() public override void OnEnter()

26
Assets/Fungus/Scripts/Commands/InvokeEvent.cs

@ -8,6 +8,23 @@ using Fungus.Variables;
namespace Fungus.Commands namespace Fungus.Commands
{ {
/// <summary>
/// Supported types of method invocation.
/// </summary>
public enum InvokeType
{
/// <summary> Call a method with an optional constant value parameter. </summary>
Static, //
/// <summary> Call a method with an optional boolean constant / variable parameter. </summary>
DynamicBoolean,
/// <summary> Call a method with an optional integer constant / variable parameter. </summary>
DynamicInteger,
/// <summary> Call a method with an optional float constant / variable parameter. </summary>
DynamicFloat,
/// <summary> Call a method with an optional string constant / variable parameter. </summary>
DynamicString
}
/// <summary> /// <summary>
/// Calls a list of component methods via the Unity Event System (as used in the Unity UI) /// Calls a list of component methods via the Unity Event System (as used in the Unity UI)
/// This command is more efficient than the Invoke Method command but can only pass a single parameter and doesn't support return values. /// This command is more efficient than the Invoke Method command but can only pass a single parameter and doesn't support return values.
@ -25,15 +42,6 @@ namespace Fungus.Commands
[Serializable] public class FloatEvent : UnityEvent<float> {} [Serializable] public class FloatEvent : UnityEvent<float> {}
[Serializable] public class StringEvent : UnityEvent<string> {} [Serializable] public class StringEvent : UnityEvent<string> {}
public enum InvokeType
{
Static, // Call a method with an optional constant value parameter
DynamicBoolean, // Call a method with an optional boolean constant / variable parameter
DynamicInteger, // Call a method with an optional integer constant / variable parameter
DynamicFloat, // Call a method with an optional float constant / variable parameter
DynamicString // Call a method with an optional string constant / variable parameter
}
[Tooltip("Delay (in seconds) before the methods will be called")] [Tooltip("Delay (in seconds) before the methods will be called")]
[SerializeField] protected float delay; [SerializeField] protected float delay;

8
Assets/Fungus/Scripts/Commands/InvokeMethod.cs

@ -66,7 +66,7 @@ namespace Fungus.Commands
[HideInInspector] [HideInInspector]
[Tooltip("The coroutine call behavior for methods that return IEnumerator")] [Tooltip("The coroutine call behavior for methods that return IEnumerator")]
[SerializeField] protected Call.CallMode callMode; [SerializeField] protected CallMode callMode;
protected Type componentType; protected Type componentType;
protected Component objComponent; protected Component objComponent;
@ -121,11 +121,11 @@ namespace Fungus.Commands
{ {
StartCoroutine(ExecuteCoroutine()); StartCoroutine(ExecuteCoroutine());
if (callMode == Call.CallMode.Continue) if (callMode == CallMode.Continue)
{ {
Continue(); Continue();
} }
else if(callMode == Call.CallMode.Stop) else if(callMode == CallMode.Stop)
{ {
StopParentBlock(); StopParentBlock();
} }
@ -141,7 +141,7 @@ namespace Fungus.Commands
{ {
yield return StartCoroutine((IEnumerator)objMethod.Invoke(objComponent, GetParameterValues())); yield return StartCoroutine((IEnumerator)objMethod.Invoke(objComponent, GetParameterValues()));
if (callMode == Call.CallMode.WaitUntilFinished) if (callMode == CallMode.WaitUntilFinished)
{ {
Continue(); Continue();
} }

21
Assets/Fungus/Scripts/Commands/SendMessage.cs

@ -8,6 +8,21 @@ using Fungus.EventHandlers;
namespace Fungus.Commands namespace Fungus.Commands
{ {
/// <summary>
/// Supported target types for messages.
/// </summary>
public enum MessageTarget
{
/// <summary>
/// Send message to the Flowchart containing the SendMessage command.
/// </summary>
SameFlowchart,
/// <summary>
/// Broadcast message to all Flowcharts.
/// </summary>
AllFlowcharts
}
/// <summary> /// <summary>
/// Sends a message to either the owner Flowchart or all Flowcharts in the scene. Blocks can listen for this message using a Message Received event handler. /// Sends a message to either the owner Flowchart or all Flowcharts in the scene. Blocks can listen for this message using a Message Received event handler.
/// </summary> /// </summary>
@ -18,12 +33,6 @@ namespace Fungus.Commands
[ExecuteInEditMode] [ExecuteInEditMode]
public class SendMessage : Command public class SendMessage : Command
{ {
public enum MessageTarget
{
SameFlowchart,
AllFlowcharts
}
[Tooltip("Target flowchart(s) to send the message to")] [Tooltip("Target flowchart(s) to send the message to")]
[SerializeField] protected MessageTarget messageTarget; [SerializeField] protected MessageTarget messageTarget;

29
Assets/Fungus/Scripts/Commands/SetVariable.cs

@ -6,6 +6,25 @@ using Fungus.Variables;
namespace Fungus.Commands namespace Fungus.Commands
{ {
/// <summary>
/// Mathematical operations that can be performed on variables.
/// </summary>
public enum SetOperator
{
/// <summary> = operator. </summary>
Assign, //
/// <summary> =! operator. </summary>
Negate,
/// <summary> += operator. </summary>
Add,
/// <summary> -= operator. </summary>
Subtract,
/// <summary> *= operator. </summary>
Multiply,
/// <summary> /= operator. </summary>
Divide
}
/// <summary> /// <summary>
/// Sets a Boolean, Integer, Float or String variable to a new value using a simple arithmetic operation. The value can be a constant or reference another variable of the same type. /// Sets a Boolean, Integer, Float or String variable to a new value using a simple arithmetic operation. The value can be a constant or reference another variable of the same type.
/// </summary> /// </summary>
@ -15,16 +34,6 @@ namespace Fungus.Commands
[AddComponentMenu("")] [AddComponentMenu("")]
public class SetVariable : Command public class SetVariable : Command
{ {
public enum SetOperator
{
Assign, // =
Negate, // =!
Add, // +=
Subtract, // -=
Multiply, // *=
Divide // /=
}
[Tooltip("The variable whos value will be set")] [Tooltip("The variable whos value will be set")]
[VariableProperty(typeof(BooleanVariable), [VariableProperty(typeof(BooleanVariable),
typeof(IntegerVariable), typeof(IntegerVariable),

23
Assets/Fungus/Scripts/Commands/Write.cs

@ -6,6 +6,21 @@ using Fungus.Variables;
namespace Fungus.Commands namespace Fungus.Commands
{ {
/// <summary>
/// Text coloring mode for Write command.
/// </summary>
public enum TextColor
{
/// <summary> Don't change the text color. </summary>
Default,
/// <summary> Set the text alpha to 1. </summary>
SetVisible,
/// <summary> Set the text alpha to a value. </summary>
SetAlpha,
/// <summary> Set the text color to a value. </summary>
SetColor
}
/// <summary> /// <summary>
/// Writes content to a UI Text or Text Mesh object. /// Writes content to a UI Text or Text Mesh object.
/// </summary> /// </summary>
@ -30,14 +45,6 @@ namespace Fungus.Commands
[Tooltip("Wait until this command finishes before executing the next command")] [Tooltip("Wait until this command finishes before executing the next command")]
[SerializeField] protected bool waitUntilFinished = true; [SerializeField] protected bool waitUntilFinished = true;
public enum TextColor
{
Default,
SetVisible,
SetAlpha,
SetColor
}
[SerializeField] protected TextColor textColor = TextColor.Default; [SerializeField] protected TextColor textColor = TextColor.Default;
[SerializeField] protected FloatData setAlpha = new FloatData(1f); [SerializeField] protected FloatData setAlpha = new FloatData(1f);

8
Assets/Fungus/Scripts/Commands/iTweenCommand.cs

@ -7,12 +7,18 @@ using Fungus.Variables;
namespace Fungus.Commands namespace Fungus.Commands
{ {
/// <summary>
/// Axis to apply the tween on.
/// </summary>
public enum iTweenAxis public enum iTweenAxis
{ {
/// <summary> Don't specify an axis. </summary>
None, None,
/// <summary> Apply the tween on the X axis only. </summary>
X, X,
/// <summary> Apply the tween on the Y axis only. </summary>
Y, Y,
/// <summary> Apply the tween on the Z axis only. </summary>
Z Z
} }

23
Assets/Fungus/Scripts/Components/DialogInput.cs

@ -6,19 +6,26 @@ using UnityEngine.EventSystems;
namespace Fungus namespace Fungus
{ {
/// <summary>
/// Supported modes for clicking through a Say Dialog.
/// </summary>
public enum ClickMode
{
/// <summary> Clicking disabled. </summary>
Disabled,
/// <summary> Click anywhere on screen to advance. </summary>
ClickAnywhere,
/// <summary> Click anywhere on Say Dialog to advance. </summary>
ClickOnDialog,
/// <summary> Click on continue button to advance. </summary>
ClickOnButton
}
/// <summary> /// <summary>
/// Input handler for say dialogs. /// Input handler for say dialogs.
/// </summary> /// </summary>
public class DialogInput : MonoBehaviour, IDialogInput public class DialogInput : MonoBehaviour, IDialogInput
{ {
public enum ClickMode
{
Disabled, // Clicking disabled
ClickAnywhere, // Click anywhere on screen to advance
ClickOnDialog, // Click anywhere on Say Dialog to advance
ClickOnButton // Click on continue button to advance
}
[Tooltip("Click to advance story")] [Tooltip("Click to advance story")]
[SerializeField] protected ClickMode clickMode; [SerializeField] protected ClickMode clickMode;

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

@ -297,34 +297,34 @@ namespace Fungus
exitFlag = false; exitFlag = false;
isWriting = true; isWriting = true;
TextTagToken.TokenType previousTokenType = TextTagToken.TokenType.Invalid; TokenType previousTokenType = TokenType.Invalid;
foreach (TextTagToken token in tokens) foreach (TextTagToken token in tokens)
{ {
switch (token.type) switch (token.type)
{ {
case TextTagToken.TokenType.Words: case TokenType.Words:
yield return StartCoroutine(DoWords(token.paramList, previousTokenType)); yield return StartCoroutine(DoWords(token.paramList, previousTokenType));
break; break;
case TextTagToken.TokenType.BoldStart: case TokenType.BoldStart:
boldActive = true; boldActive = true;
break; break;
case TextTagToken.TokenType.BoldEnd: case TokenType.BoldEnd:
boldActive = false; boldActive = false;
break; break;
case TextTagToken.TokenType.ItalicStart: case TokenType.ItalicStart:
italicActive = true; italicActive = true;
break; break;
case TextTagToken.TokenType.ItalicEnd: case TokenType.ItalicEnd:
italicActive = false; italicActive = false;
break; break;
case TextTagToken.TokenType.ColorStart: case TokenType.ColorStart:
if (CheckParamCount(token.paramList, 1)) if (CheckParamCount(token.paramList, 1))
{ {
colorActive = true; colorActive = true;
@ -332,66 +332,66 @@ namespace Fungus
} }
break; break;
case TextTagToken.TokenType.ColorEnd: case TokenType.ColorEnd:
colorActive = false; colorActive = false;
break; break;
case TextTagToken.TokenType.SizeStart: case TokenType.SizeStart:
if (TryGetSingleParam(token.paramList, 0, 16f, out sizeValue)) if (TryGetSingleParam(token.paramList, 0, 16f, out sizeValue))
{ {
sizeActive = true; sizeActive = true;
} }
break; break;
case TextTagToken.TokenType.SizeEnd: case TokenType.SizeEnd:
sizeActive = false; sizeActive = false;
break; break;
case TextTagToken.TokenType.Wait: case TokenType.Wait:
yield return StartCoroutine(DoWait(token.paramList)); yield return StartCoroutine(DoWait(token.paramList));
break; break;
case TextTagToken.TokenType.WaitForInputNoClear: case TokenType.WaitForInputNoClear:
yield return StartCoroutine(DoWaitForInput(false)); yield return StartCoroutine(DoWaitForInput(false));
break; break;
case TextTagToken.TokenType.WaitForInputAndClear: case TokenType.WaitForInputAndClear:
yield return StartCoroutine(DoWaitForInput(true)); yield return StartCoroutine(DoWaitForInput(true));
break; break;
case TextTagToken.TokenType.WaitOnPunctuationStart: case TokenType.WaitOnPunctuationStart:
TryGetSingleParam(token.paramList, 0, punctuationPause, out currentPunctuationPause); TryGetSingleParam(token.paramList, 0, punctuationPause, out currentPunctuationPause);
break; break;
case TextTagToken.TokenType.WaitOnPunctuationEnd: case TokenType.WaitOnPunctuationEnd:
currentPunctuationPause = punctuationPause; currentPunctuationPause = punctuationPause;
break; break;
case TextTagToken.TokenType.Clear: case TokenType.Clear:
text = ""; text = "";
break; break;
case TextTagToken.TokenType.SpeedStart: case TokenType.SpeedStart:
TryGetSingleParam(token.paramList, 0, writingSpeed, out currentWritingSpeed); TryGetSingleParam(token.paramList, 0, writingSpeed, out currentWritingSpeed);
break; break;
case TextTagToken.TokenType.SpeedEnd: case TokenType.SpeedEnd:
currentWritingSpeed = writingSpeed; currentWritingSpeed = writingSpeed;
break; break;
case TextTagToken.TokenType.Exit: case TokenType.Exit:
exitFlag = true; exitFlag = true;
break; break;
case TextTagToken.TokenType.Message: case TokenType.Message:
if (CheckParamCount(token.paramList, 1)) if (CheckParamCount(token.paramList, 1))
{ {
Flowchart.BroadcastFungusMessage(token.paramList[0]); Flowchart.BroadcastFungusMessage(token.paramList[0]);
} }
break; break;
case TextTagToken.TokenType.VerticalPunch: case TokenType.VerticalPunch:
{ {
float vintensity; float vintensity;
float time; float time;
@ -401,7 +401,7 @@ namespace Fungus
} }
break; break;
case TextTagToken.TokenType.HorizontalPunch: case TokenType.HorizontalPunch:
{ {
float hintensity; float hintensity;
float time; float time;
@ -411,7 +411,7 @@ namespace Fungus
} }
break; break;
case TextTagToken.TokenType.Punch: case TokenType.Punch:
{ {
float intensity; float intensity;
float time; float time;
@ -421,13 +421,13 @@ namespace Fungus
} }
break; break;
case TextTagToken.TokenType.Flash: case TokenType.Flash:
float flashDuration; float flashDuration;
TryGetSingleParam(token.paramList, 0, 0.2f, out flashDuration); TryGetSingleParam(token.paramList, 0, 0.2f, out flashDuration);
Flash(flashDuration); Flash(flashDuration);
break; break;
case TextTagToken.TokenType.Audio: case TokenType.Audio:
{ {
AudioSource audioSource = null; AudioSource audioSource = null;
if (CheckParamCount(token.paramList, 1)) if (CheckParamCount(token.paramList, 1))
@ -441,7 +441,7 @@ namespace Fungus
} }
break; break;
case TextTagToken.TokenType.AudioLoop: case TokenType.AudioLoop:
{ {
AudioSource audioSource = null; AudioSource audioSource = null;
if (CheckParamCount(token.paramList, 1)) if (CheckParamCount(token.paramList, 1))
@ -456,7 +456,7 @@ namespace Fungus
} }
break; break;
case TextTagToken.TokenType.AudioPause: case TokenType.AudioPause:
{ {
AudioSource audioSource = null; AudioSource audioSource = null;
if (CheckParamCount(token.paramList, 1)) if (CheckParamCount(token.paramList, 1))
@ -470,7 +470,7 @@ namespace Fungus
} }
break; break;
case TextTagToken.TokenType.AudioStop: case TokenType.AudioStop:
{ {
AudioSource audioSource = null; AudioSource audioSource = null;
if (CheckParamCount(token.paramList, 1)) if (CheckParamCount(token.paramList, 1))
@ -506,7 +506,7 @@ namespace Fungus
} }
} }
protected virtual IEnumerator DoWords(List<string> paramList, TextTagToken.TokenType previousTokenType) protected virtual IEnumerator DoWords(List<string> paramList, TokenType previousTokenType)
{ {
if (!CheckParamCount(paramList, 1)) if (!CheckParamCount(paramList, 1))
{ {
@ -516,8 +516,8 @@ namespace Fungus
string param = paramList[0]; string param = paramList[0];
// Trim whitespace after a {wc} or {c} tag // Trim whitespace after a {wc} or {c} tag
if (previousTokenType == TextTagToken.TokenType.WaitForInputAndClear || if (previousTokenType == TokenType.WaitForInputAndClear ||
previousTokenType == TextTagToken.TokenType.Clear) previousTokenType == TokenType.Clear)
{ {
param = param.TrimStart(' ', '\t', '\r', '\n'); param = param.TrimStart(' ', '\t', '\r', '\n');
} }

17
Assets/Fungus/Scripts/Components/WriterAudio.cs

@ -6,17 +6,22 @@ using System.Collections.Generic;
namespace Fungus namespace Fungus
{ {
/// <summary>
/// Type of audio effect to play.
/// </summary>
public enum AudioMode
{
/// <summary> Use short beep sound effects. </summary>
Beeps,
/// <summary> Use long looping sound effect. </summary>
SoundEffect,
}
/// <summary> /// <summary>
/// Manages audio effects for Dialogs. /// Manages audio effects for Dialogs.
/// </summary> /// </summary>
public class WriterAudio : MonoBehaviour, IWriterListener public class WriterAudio : MonoBehaviour, IWriterListener
{ {
public enum AudioMode
{
Beeps, // Use short beep sound effects
SoundEffect, // Use long looping sound effect
}
[Tooltip("Volume level of writing sound effects")] [Tooltip("Volume level of writing sound effects")]
[Range(0,1)] [Range(0,1)]
[SerializeField] protected float volume = 1f; [SerializeField] protected float volume = 1f;

4
Assets/Fungus/Scripts/Editor/ControlAudioEditor.cs

@ -40,11 +40,11 @@ namespace Fungus.EditorUtils
EditorGUILayout.PropertyField(controlProp); EditorGUILayout.PropertyField(controlProp);
EditorGUILayout.PropertyField(audioSourceProp); EditorGUILayout.PropertyField(audioSourceProp);
string fadeLabel = "Fade Out Duration"; string fadeLabel = "Fade Out Duration";
if (t.Control != ControlAudio.ControlType.StopLoop && t.Control != ControlAudio.ControlType.PauseLoop) if (t.Control != ControlAudioType.StopLoop && t.Control != ControlAudioType.PauseLoop)
{ {
fadeLabel = "Fade In Duration"; fadeLabel = "Fade In Duration";
string volumeLabel = "End Volume"; string volumeLabel = "End Volume";
if (t.Control == ControlAudio.ControlType.ChangeVolume) if (t.Control == ControlAudioType.ChangeVolume)
{ {
fadeLabel = "Fade Duration"; fadeLabel = "Fade Duration";
volumeLabel = "New Volume"; volumeLabel = "New Volume";

12
Assets/Fungus/Scripts/Editor/InvokeEventEditor.cs

@ -46,24 +46,24 @@ namespace Fungus.EditorUtils
EditorGUILayout.PropertyField(delayProp); EditorGUILayout.PropertyField(delayProp);
EditorGUILayout.PropertyField(invokeTypeProp); EditorGUILayout.PropertyField(invokeTypeProp);
switch ((InvokeEvent.InvokeType)invokeTypeProp.enumValueIndex) switch ((InvokeType)invokeTypeProp.enumValueIndex)
{ {
case InvokeEvent.InvokeType.Static: case InvokeType.Static:
EditorGUILayout.PropertyField(staticEventProp); EditorGUILayout.PropertyField(staticEventProp);
break; break;
case InvokeEvent.InvokeType.DynamicBoolean: case InvokeType.DynamicBoolean:
EditorGUILayout.PropertyField(booleanEventProp); EditorGUILayout.PropertyField(booleanEventProp);
EditorGUILayout.PropertyField(booleanParameterProp); EditorGUILayout.PropertyField(booleanParameterProp);
break; break;
case InvokeEvent.InvokeType.DynamicInteger: case InvokeType.DynamicInteger:
EditorGUILayout.PropertyField(integerEventProp); EditorGUILayout.PropertyField(integerEventProp);
EditorGUILayout.PropertyField(integerParameterProp); EditorGUILayout.PropertyField(integerParameterProp);
break; break;
case InvokeEvent.InvokeType.DynamicFloat: case InvokeType.DynamicFloat:
EditorGUILayout.PropertyField(floatEventProp); EditorGUILayout.PropertyField(floatEventProp);
EditorGUILayout.PropertyField(floatParameterProp); EditorGUILayout.PropertyField(floatParameterProp);
break; break;
case InvokeEvent.InvokeType.DynamicString: case InvokeType.DynamicString:
EditorGUILayout.PropertyField(stringEventProp); EditorGUILayout.PropertyField(stringEventProp);
EditorGUILayout.PropertyField(stringParameterProp); EditorGUILayout.PropertyField(stringParameterProp);
break; break;

28
Assets/Fungus/Scripts/Editor/SetVariableEditor.cs

@ -75,29 +75,29 @@ namespace Fungus.EditorUtils
switch (t._SetOperator) switch (t._SetOperator)
{ {
default: default:
case SetVariable.SetOperator.Assign: case SetOperator.Assign:
selectedIndex = 0; selectedIndex = 0;
break; break;
case SetVariable.SetOperator.Negate: case SetOperator.Negate:
selectedIndex = 1; selectedIndex = 1;
break; break;
case SetVariable.SetOperator.Add: case SetOperator.Add:
selectedIndex = 1; selectedIndex = 1;
break; break;
case SetVariable.SetOperator.Subtract: case SetOperator.Subtract:
selectedIndex = 2; selectedIndex = 2;
break; break;
case SetVariable.SetOperator.Multiply: case SetOperator.Multiply:
selectedIndex = 3; selectedIndex = 3;
break; break;
case SetVariable.SetOperator.Divide: case SetOperator.Divide:
selectedIndex = 4; selectedIndex = 4;
break; break;
} }
selectedIndex = EditorGUILayout.Popup(new GUIContent("Operation", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray()); selectedIndex = EditorGUILayout.Popup(new GUIContent("Operation", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray());
SetVariable.SetOperator setOperator = SetVariable.SetOperator.Assign; SetOperator setOperator = SetOperator.Assign;
if (variableType == typeof(BooleanVariable) || if (variableType == typeof(BooleanVariable) ||
variableType == typeof(StringVariable)) variableType == typeof(StringVariable))
{ {
@ -105,10 +105,10 @@ namespace Fungus.EditorUtils
{ {
default: default:
case 0: case 0:
setOperator = SetVariable.SetOperator.Assign; setOperator = SetOperator.Assign;
break; break;
case 1: case 1:
setOperator = SetVariable.SetOperator.Negate; setOperator = SetOperator.Negate;
break; break;
} }
} }
@ -119,19 +119,19 @@ namespace Fungus.EditorUtils
{ {
default: default:
case 0: case 0:
setOperator = SetVariable.SetOperator.Assign; setOperator = SetOperator.Assign;
break; break;
case 1: case 1:
setOperator = SetVariable.SetOperator.Add; setOperator = SetOperator.Add;
break; break;
case 2: case 2:
setOperator = SetVariable.SetOperator.Subtract; setOperator = SetOperator.Subtract;
break; break;
case 3: case 3:
setOperator = SetVariable.SetOperator.Multiply; setOperator = SetOperator.Multiply;
break; break;
case 4: case 4:
setOperator = SetVariable.SetOperator.Divide; setOperator = SetOperator.Divide;
break; break;
} }
} }

10
Assets/Fungus/Scripts/Editor/WriteEditor.cs

@ -71,16 +71,16 @@ namespace Fungus.EditorUtils
EditorGUILayout.PropertyField(clearTextProp); EditorGUILayout.PropertyField(clearTextProp);
EditorGUILayout.PropertyField(textColorProp); EditorGUILayout.PropertyField(textColorProp);
switch ((Write.TextColor)textColorProp.enumValueIndex) switch ((TextColor)textColorProp.enumValueIndex)
{ {
case Write.TextColor.Default: case TextColor.Default:
break; break;
case Write.TextColor.SetVisible: case TextColor.SetVisible:
break; break;
case Write.TextColor.SetAlpha: case TextColor.SetAlpha:
EditorGUILayout.PropertyField(setAlphaProp); EditorGUILayout.PropertyField(setAlphaProp);
break; break;
case Write.TextColor.SetColor: case TextColor.SetColor:
EditorGUILayout.PropertyField(setColorProp); EditorGUILayout.PropertyField(setColorProp);
break; break;
} }

2
Assets/Fungus/Scripts/Editor/WriterAudioEditor.cs

@ -39,7 +39,7 @@ namespace Fungus.EditorUtils
EditorGUILayout.PropertyField(inputSoundProp); EditorGUILayout.PropertyField(inputSoundProp);
EditorGUILayout.PropertyField(audioModeProp); EditorGUILayout.PropertyField(audioModeProp);
if ((WriterAudio.AudioMode)audioModeProp.enumValueIndex == WriterAudio.AudioMode.Beeps) if ((AudioMode)audioModeProp.enumValueIndex == AudioMode.Beeps)
{ {
ReorderableListGUI.Title(new GUIContent("Beep Sounds", "A list of beep sounds to play at random")); ReorderableListGUI.Title(new GUIContent("Beep Sounds", "A list of beep sounds to play at random"));
ReorderableListGUI.ListField(beepSoundsProp); ReorderableListGUI.ListField(beepSoundsProp);

20
Assets/Fungus/Scripts/EventHandlers/KeyPressed.cs

@ -5,6 +5,19 @@
namespace Fungus.EventHandlers namespace Fungus.EventHandlers
{ {
/// <summary>
/// Key press modes supported by Key Pressed event handler.
/// </summary>
public enum KeyPressType
{
/// <summary> Execute once when the key is pressed down. </summary>
KeyDown,
/// <summary> Execute once when the key is released </summary>
KeyUp,
/// <summary> Execute once per frame when key is held down. </summary>
KeyRepeat
}
/// <summary> /// <summary>
/// The block will execute when a key press event occurs. /// The block will execute when a key press event occurs.
/// </summary> /// </summary>
@ -14,13 +27,6 @@ namespace Fungus.EventHandlers
[AddComponentMenu("")] [AddComponentMenu("")]
public class KeyPressed : EventHandler public class KeyPressed : EventHandler
{ {
public enum KeyPressType
{
KeyDown, // Execute once when the key is pressed down
KeyUp, // Execute once when the key is released
KeyRepeat // Execute once per frame when key is held down
}
[Tooltip("The type of keypress to activate on")] [Tooltip("The type of keypress to activate on")]
[SerializeField] protected KeyPressType keyPressType; [SerializeField] protected KeyPressType keyPressType;

4
Assets/Fungus/Scripts/Interfaces/IBlock.cs

@ -11,7 +11,9 @@ namespace Fungus
/// </summary> /// </summary>
public enum ExecutionState public enum ExecutionState
{ {
Idle, /// <summary> No command executing </summary>
Idle,
/// <summary> Executing a command </summary>
Executing, Executing,
} }

15
Assets/Fungus/Scripts/Interfaces/IPortraitController.cs

@ -7,14 +7,19 @@ using Fungus.Utils;
namespace Fungus namespace Fungus
{ {
/// <summary> /// <summary>
/// Types of display operations supported by portraits /// Types of display operations supported by portraits.
/// </summary> /// </summary>
public enum DisplayType public enum DisplayType
{ {
/// <summary> Do nothing. </summary>
None, None,
/// <summary> Show the portrait. </summary>
Show, Show,
/// <summary> Hide the portrait. </summary>
Hide, Hide,
/// <summary> Replace the existing portrait. </summary>
Replace, Replace,
/// <summary> Move portrait to the front. </summary>
MoveToFront MoveToFront
} }
@ -23,8 +28,11 @@ namespace Fungus
/// </summary> /// </summary>
public enum FacingDirection public enum FacingDirection
{ {
None, /// <summary> Unknown direction </summary>
None,
/// <summary> Facing left. </summary>
Left, Left,
/// <summary> Facing right. </summary>
Right Right
} }
@ -33,8 +41,11 @@ namespace Fungus
/// </summary> /// </summary>
public enum PositionOffset public enum PositionOffset
{ {
/// <summary> Unknown offset direction. </summary>
None, None,
/// <summary> Offset applies to the left. </summary>
OffsetLeft, OffsetLeft,
/// <summary> Offset applies to the right. </summary>
OffsetRight OffsetRight
} }

23
Assets/Fungus/Scripts/Interfaces/IVariable.cs

@ -3,14 +3,23 @@
namespace Fungus namespace Fungus
{ {
/// <summary>
/// Standard comparison operators.
/// </summary>
public enum CompareOperator public enum CompareOperator
{ {
Equals, // == /// <summary> == mathematical operator.</summary>
NotEquals, // != Equals,
LessThan, // < /// <summary> != mathematical operator.</summary>
GreaterThan, // > NotEquals,
LessThanOrEquals, // <= /// <summary> < mathematical operator.</summary>
GreaterThanOrEquals // >= LessThan,
/// <summary> > mathematical operator.</summary>
GreaterThan,
/// <summary> <= mathematical operator.</summary>
LessThanOrEquals,
/// <summary> >= mathematical operator.</summary>
GreaterThanOrEquals
} }
/// <summary> /// <summary>
@ -18,7 +27,9 @@ namespace Fungus
/// </summary> /// </summary>
public enum VariableScope public enum VariableScope
{ {
/// <summary> Can only be accessed by commands in the same Flowchart. </summary>
Private, Private,
/// <summary> Can be accessed from any command in any Flowchart. </summary>
Public Public
} }

70
Assets/Fungus/Scripts/Utils/TextTagParser.cs

@ -45,7 +45,7 @@ namespace Fungus.Utils
protected virtual void AddWordsToken(List<TextTagToken> tokenList, string words) protected virtual void AddWordsToken(List<TextTagToken> tokenList, string words)
{ {
TextTagToken token = new TextTagToken(); TextTagToken token = new TextTagToken();
token.type = TextTagToken.TokenType.Words; token.type = TokenType.Words;
token.paramList = new List<string>(); token.paramList = new List<string>();
token.paramList.Add(words); token.paramList.Add(words);
tokenList.Add(token); tokenList.Add(token);
@ -62,131 +62,131 @@ namespace Fungus.Utils
string tag = tagText.Substring(1, tagText.Length - 2); string tag = tagText.Substring(1, tagText.Length - 2);
var type = TextTagToken.TokenType.Invalid; var type = TokenType.Invalid;
List<string> parameters = ExtractParameters(tag); List<string> parameters = ExtractParameters(tag);
if (tag == "b") if (tag == "b")
{ {
type = TextTagToken.TokenType.BoldStart; type = TokenType.BoldStart;
} }
else if (tag == "/b") else if (tag == "/b")
{ {
type = TextTagToken.TokenType.BoldEnd; type = TokenType.BoldEnd;
} }
else if (tag == "i") else if (tag == "i")
{ {
type = TextTagToken.TokenType.ItalicStart; type = TokenType.ItalicStart;
} }
else if (tag == "/i") else if (tag == "/i")
{ {
type = TextTagToken.TokenType.ItalicEnd; type = TokenType.ItalicEnd;
} }
else if (tag.StartsWith("color=")) else if (tag.StartsWith("color="))
{ {
type = TextTagToken.TokenType.ColorStart; type = TokenType.ColorStart;
} }
else if (tag == "/color") else if (tag == "/color")
{ {
type = TextTagToken.TokenType.ColorEnd; type = TokenType.ColorEnd;
} }
else if (tag.StartsWith("size=")) else if (tag.StartsWith("size="))
{ {
type = TextTagToken.TokenType.SizeStart; type = TokenType.SizeStart;
} }
else if (tag == "/size") else if (tag == "/size")
{ {
type = TextTagToken.TokenType.SizeEnd; type = TokenType.SizeEnd;
} }
else if (tag == "wi") else if (tag == "wi")
{ {
type = TextTagToken.TokenType.WaitForInputNoClear; type = TokenType.WaitForInputNoClear;
} }
if (tag == "wc") if (tag == "wc")
{ {
type = TextTagToken.TokenType.WaitForInputAndClear; type = TokenType.WaitForInputAndClear;
} }
else if (tag.StartsWith("wp=")) else if (tag.StartsWith("wp="))
{ {
type = TextTagToken.TokenType.WaitOnPunctuationStart; type = TokenType.WaitOnPunctuationStart;
} }
else if (tag == "wp") else if (tag == "wp")
{ {
type = TextTagToken.TokenType.WaitOnPunctuationStart; type = TokenType.WaitOnPunctuationStart;
} }
else if (tag == "/wp") else if (tag == "/wp")
{ {
type = TextTagToken.TokenType.WaitOnPunctuationEnd; type = TokenType.WaitOnPunctuationEnd;
} }
else if (tag.StartsWith("w=")) else if (tag.StartsWith("w="))
{ {
type = TextTagToken.TokenType.Wait; type = TokenType.Wait;
} }
else if (tag == "w") else if (tag == "w")
{ {
type = TextTagToken.TokenType.Wait; type = TokenType.Wait;
} }
else if (tag == "c") else if (tag == "c")
{ {
type = TextTagToken.TokenType.Clear; type = TokenType.Clear;
} }
else if (tag.StartsWith("s=")) else if (tag.StartsWith("s="))
{ {
type = TextTagToken.TokenType.SpeedStart; type = TokenType.SpeedStart;
} }
else if (tag == "s") else if (tag == "s")
{ {
type = TextTagToken.TokenType.SpeedStart; type = TokenType.SpeedStart;
} }
else if (tag == "/s") else if (tag == "/s")
{ {
type = TextTagToken.TokenType.SpeedEnd; type = TokenType.SpeedEnd;
} }
else if (tag == "x") else if (tag == "x")
{ {
type = TextTagToken.TokenType.Exit; type = TokenType.Exit;
} }
else if (tag.StartsWith("m=")) else if (tag.StartsWith("m="))
{ {
type = TextTagToken.TokenType.Message; type = TokenType.Message;
} }
else if (tag.StartsWith("vpunch") || else if (tag.StartsWith("vpunch") ||
tag.StartsWith("vpunch=")) tag.StartsWith("vpunch="))
{ {
type = TextTagToken.TokenType.VerticalPunch; type = TokenType.VerticalPunch;
} }
else if (tag.StartsWith("hpunch") || else if (tag.StartsWith("hpunch") ||
tag.StartsWith("hpunch=")) tag.StartsWith("hpunch="))
{ {
type = TextTagToken.TokenType.HorizontalPunch; type = TokenType.HorizontalPunch;
} }
else if (tag.StartsWith("punch") || else if (tag.StartsWith("punch") ||
tag.StartsWith("punch=")) tag.StartsWith("punch="))
{ {
type = TextTagToken.TokenType.Punch; type = TokenType.Punch;
} }
else if (tag.StartsWith("flash") || else if (tag.StartsWith("flash") ||
tag.StartsWith("flash=")) tag.StartsWith("flash="))
{ {
type = TextTagToken.TokenType.Flash; type = TokenType.Flash;
} }
else if (tag.StartsWith("audio=")) else if (tag.StartsWith("audio="))
{ {
type = TextTagToken.TokenType.Audio; type = TokenType.Audio;
} }
else if (tag.StartsWith("audioloop=")) else if (tag.StartsWith("audioloop="))
{ {
type = TextTagToken.TokenType.AudioLoop; type = TokenType.AudioLoop;
} }
else if (tag.StartsWith("audiopause=")) else if (tag.StartsWith("audiopause="))
{ {
type = TextTagToken.TokenType.AudioPause; type = TokenType.AudioPause;
} }
else if (tag.StartsWith("audiostop=")) else if (tag.StartsWith("audiostop="))
{ {
type = TextTagToken.TokenType.AudioStop; type = TokenType.AudioStop;
} }
if (type != TextTagToken.TokenType.Invalid) if (type != TokenType.Invalid)
{ {
TextTagToken token = new TextTagToken(); TextTagToken token = new TextTagToken();
token.type = type; token.type = type;
@ -261,13 +261,13 @@ namespace Fungus.Utils
foreach (TextTagToken token in tokens) foreach (TextTagToken token in tokens)
{ {
if (trimLeading && if (trimLeading &&
token.type == TextTagToken.TokenType.Words) token.type == TokenType.Words)
{ {
token.paramList[0] = token.paramList[0].TrimStart(' ', '\t', '\r', '\n'); token.paramList[0] = token.paramList[0].TrimStart(' ', '\t', '\r', '\n');
} }
if (token.type == TextTagToken.TokenType.Clear || if (token.type == TokenType.Clear ||
token.type == TextTagToken.TokenType.WaitForInputAndClear) token.type == TokenType.WaitForInputAndClear)
{ {
trimLeading = true; trimLeading = true;
} }

105
Assets/Fungus/Scripts/Utils/TextTagToken.cs

@ -5,41 +5,82 @@ using System.Collections.Generic;
namespace Fungus.Utils namespace Fungus.Utils
{ {
public class TextTagToken /// <summary>
/// Supported token types for use in Say / Write text.
/// </summary>
public enum TokenType
{ {
public enum TokenType /// <summary> Invalid token type. </summary>
{ Invalid,
Invalid, /// <summary> A string of words. </summary>
Words, // A string of words Words,
BoldStart, // b /// <summary> b </summary>
BoldEnd, // /b BoldStart, //
ItalicStart, // i /// <summary> /b </summary>
ItalicEnd, // /i BoldEnd,
ColorStart, // color=red /// <summary> i </summary>
ColorEnd, // /color ItalicStart,
SizeStart, // size=20 /// <summary> /i </summary>
SizeEnd, // /size ItalicEnd,
Wait, // w, w=0.5 /// <summary> color=red </summary>
WaitForInputNoClear, // wi ColorStart,
WaitForInputAndClear, // wc /// <summary> /color </summary>
WaitOnPunctuationStart, // wp, wp=0.5 ColorEnd,
WaitOnPunctuationEnd, // /wp /// <summary> size=20 </summary>
Clear, // c SizeStart,
SpeedStart, // s, s=60 /// <summary> /size </summary>
SpeedEnd, // /s SizeEnd,
Exit, // x /// <summary> w, w=0.5 </summary>
Message, // m=MessageName Wait,
VerticalPunch, // {vpunch=0.5} /// <summary> wi </summary>
HorizontalPunch, // {hpunch=0.5} WaitForInputNoClear,
Punch, // {punch=0.5} /// <summary> wc </summary>
Flash, // {flash=0.5} WaitForInputAndClear,
Audio, // {audio=Sound} /// <summary> wp, wp=0.5 </summary>
AudioLoop, // {audioloop=Sound} WaitOnPunctuationStart,
AudioPause, // {audiopause=Sound} /// <summary> /wp </summary>
AudioStop // {audiostop=Sound} WaitOnPunctuationEnd,
} /// <summary> c </summary>
Clear,
/// <summary> s, s=60 </summary>
SpeedStart,
/// <summary> /s </summary>
SpeedEnd,
/// <summary> x </summary>
Exit,
/// <summary> m=MessageName </summary>
Message,
/// <summary> vpunch=0.5 </summary>
VerticalPunch,
/// <summary> hpunch=0.5 </summary>
HorizontalPunch,
/// <summary> punch=0.5 </summary>
Punch,
/// <summary> flash=0.5 </summary>
Flash,
/// <summary> audio=Sound </summary>
Audio,
/// <summary> audioloop=Sound </summary>
AudioLoop,
/// <summary> audiopause=Sound </summary>
AudioPause,
/// <summary> audiostop=Sound </summary>
AudioStop
}
/// <summary>
/// Represents a token of story text. The text is broken into a list of tokens.
/// </summary>
public class TextTagToken
{
/// <summary>
/// The type of the token.
/// </summary>
public TokenType type = TokenType.Invalid; public TokenType type = TokenType.Invalid;
/// <summary>
/// List of comma separated parameters.
/// </summary>
public List<string> paramList; public List<string> paramList;
} }
} }

84
Assets/Tests/UI/Editor/TextTagParserTests.cs

@ -40,139 +40,139 @@ public class TextTagParserTests
"{audiostop=Sound}"); "{audiostop=Sound}");
int i = 0; int i = 0;
Assert.That(tokens[i].type == TextTagToken.TokenType.Words); Assert.That(tokens[i].type == TokenType.Words);
Assert.That(tokens[i].paramList[0] == "Words "); Assert.That(tokens[i].paramList[0] == "Words ");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.BoldStart); Assert.That(tokens[i].type == TokenType.BoldStart);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Words); Assert.That(tokens[i].type == TokenType.Words);
Assert.That(tokens[i].paramList[0] == "bold test"); Assert.That(tokens[i].paramList[0] == "bold test");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.BoldEnd); Assert.That(tokens[i].type == TokenType.BoldEnd);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.ItalicStart); Assert.That(tokens[i].type == TokenType.ItalicStart);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Words); Assert.That(tokens[i].type == TokenType.Words);
Assert.That(tokens[i].paramList[0] == "italic test"); Assert.That(tokens[i].paramList[0] == "italic test");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.ItalicEnd); Assert.That(tokens[i].type == TokenType.ItalicEnd);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.ColorStart); Assert.That(tokens[i].type == TokenType.ColorStart);
Assert.That(tokens[i].paramList[0] == "red"); Assert.That(tokens[i].paramList[0] == "red");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Words); Assert.That(tokens[i].type == TokenType.Words);
Assert.That(tokens[i].paramList[0] == "color test"); Assert.That(tokens[i].paramList[0] == "color test");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.ColorEnd); Assert.That(tokens[i].type == TokenType.ColorEnd);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.SizeStart); Assert.That(tokens[i].type == TokenType.SizeStart);
Assert.That(tokens[i].paramList[0] == "30"); Assert.That(tokens[i].paramList[0] == "30");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Words); Assert.That(tokens[i].type == TokenType.Words);
Assert.That(tokens[i].paramList[0] == "size test"); Assert.That(tokens[i].paramList[0] == "size test");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.SizeEnd); Assert.That(tokens[i].type == TokenType.SizeEnd);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Wait); Assert.That(tokens[i].type == TokenType.Wait);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Wait); Assert.That(tokens[i].type == TokenType.Wait);
Assert.That(tokens[i].paramList[0] == "0.5"); Assert.That(tokens[i].paramList[0] == "0.5");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.WaitForInputNoClear); Assert.That(tokens[i].type == TokenType.WaitForInputNoClear);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.WaitForInputAndClear); Assert.That(tokens[i].type == TokenType.WaitForInputAndClear);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.WaitOnPunctuationStart); Assert.That(tokens[i].type == TokenType.WaitOnPunctuationStart);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.WaitOnPunctuationStart); Assert.That(tokens[i].type == TokenType.WaitOnPunctuationStart);
Assert.That(tokens[i].paramList[0] == "0.5"); Assert.That(tokens[i].paramList[0] == "0.5");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.WaitOnPunctuationEnd); Assert.That(tokens[i].type == TokenType.WaitOnPunctuationEnd);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Clear); Assert.That(tokens[i].type == TokenType.Clear);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.SpeedStart); Assert.That(tokens[i].type == TokenType.SpeedStart);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.SpeedStart); Assert.That(tokens[i].type == TokenType.SpeedStart);
Assert.That(tokens[i].paramList[0] == "60"); Assert.That(tokens[i].paramList[0] == "60");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.SpeedEnd); Assert.That(tokens[i].type == TokenType.SpeedEnd);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Exit); Assert.That(tokens[i].type == TokenType.Exit);
Assert.That(tokens[i].paramList.Count == 0); Assert.That(tokens[i].paramList.Count == 0);
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Message); Assert.That(tokens[i].type == TokenType.Message);
Assert.That(tokens[i].paramList[0] == "Message"); Assert.That(tokens[i].paramList[0] == "Message");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.VerticalPunch); Assert.That(tokens[i].type == TokenType.VerticalPunch);
Assert.That(tokens[i].paramList[0] == "0.5"); Assert.That(tokens[i].paramList[0] == "0.5");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.HorizontalPunch); Assert.That(tokens[i].type == TokenType.HorizontalPunch);
Assert.That(tokens[i].paramList[0] == "0.5"); Assert.That(tokens[i].paramList[0] == "0.5");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Punch); Assert.That(tokens[i].type == TokenType.Punch);
Assert.That(tokens[i].paramList[0] == "0.5"); Assert.That(tokens[i].paramList[0] == "0.5");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Flash); Assert.That(tokens[i].type == TokenType.Flash);
Assert.That(tokens[i].paramList[0] == "0.5"); Assert.That(tokens[i].paramList[0] == "0.5");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Audio); Assert.That(tokens[i].type == TokenType.Audio);
Assert.That(tokens[i].paramList[0] == "Sound"); Assert.That(tokens[i].paramList[0] == "Sound");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.AudioLoop); Assert.That(tokens[i].type == TokenType.AudioLoop);
Assert.That(tokens[i].paramList[0] == "Sound"); Assert.That(tokens[i].paramList[0] == "Sound");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.AudioPause); Assert.That(tokens[i].type == TokenType.AudioPause);
Assert.That(tokens[i].paramList[0] == "Sound"); Assert.That(tokens[i].paramList[0] == "Sound");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.AudioStop); Assert.That(tokens[i].type == TokenType.AudioStop);
Assert.That(tokens[i].paramList[0] == "Sound"); Assert.That(tokens[i].paramList[0] == "Sound");
Assert.That(tokens.Count == 34); Assert.That(tokens.Count == 34);
@ -187,35 +187,35 @@ public class TextTagParserTests
List<TextTagToken> tokens = textTagParser.Tokenize("Play sound{audio=BeepSound}{w=1} Play loop{audioloop=BeepSound}{w=3} Stop{audiostop=BeepSound}"); List<TextTagToken> tokens = textTagParser.Tokenize("Play sound{audio=BeepSound}{w=1} Play loop{audioloop=BeepSound}{w=3} Stop{audiostop=BeepSound}");
int i = 0; int i = 0;
Assert.That(tokens[i].type == TextTagToken.TokenType.Words); Assert.That(tokens[i].type == TokenType.Words);
Assert.That(tokens[i].paramList[0] == "Play sound"); Assert.That(tokens[i].paramList[0] == "Play sound");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Audio); Assert.That(tokens[i].type == TokenType.Audio);
Assert.That(tokens[i].paramList[0] == "BeepSound"); Assert.That(tokens[i].paramList[0] == "BeepSound");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Wait); Assert.That(tokens[i].type == TokenType.Wait);
Assert.That(tokens[i].paramList[0] == "1"); Assert.That(tokens[i].paramList[0] == "1");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Words); Assert.That(tokens[i].type == TokenType.Words);
Assert.That(tokens[i].paramList[0] == " Play loop"); Assert.That(tokens[i].paramList[0] == " Play loop");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.AudioLoop); Assert.That(tokens[i].type == TokenType.AudioLoop);
Assert.That(tokens[i].paramList[0] == "BeepSound"); Assert.That(tokens[i].paramList[0] == "BeepSound");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Wait); Assert.That(tokens[i].type == TokenType.Wait);
Assert.That(tokens[i].paramList[0] == "3"); Assert.That(tokens[i].paramList[0] == "3");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.Words); Assert.That(tokens[i].type == TokenType.Words);
Assert.That(tokens[i].paramList[0] == " Stop"); Assert.That(tokens[i].paramList[0] == " Stop");
i++; i++;
Assert.That(tokens[i].type == TextTagToken.TokenType.AudioStop); Assert.That(tokens[i].type == TokenType.AudioStop);
Assert.That(tokens[i].paramList[0] == "BeepSound"); Assert.That(tokens[i].paramList[0] == "BeepSound");
Assert.That(tokens.Count == 8); Assert.That(tokens.Count == 8);

Loading…
Cancel
Save