Browse Source

Refactored runtime code to use IFlowchart exclusively

master
Christopher 8 years ago
parent
commit
04b56ab0c7
  1. 6
      Assets/Fungus/Flowchart/Scripts/Block.cs
  2. 10
      Assets/Fungus/Flowchart/Scripts/Command.cs
  3. 2
      Assets/Fungus/Flowchart/Scripts/EventHandler.cs
  4. 5
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs
  5. 2
      Assets/Fungus/Flowchart/Scripts/IBlock.cs
  6. 2
      Assets/Fungus/Flowchart/Scripts/ICommand.cs
  7. 6
      Assets/Fungus/Flowchart/Scripts/IFlowchart.cs
  8. 4
      Assets/Fungus/Scripts/Commands/Call.cs
  9. 2
      Assets/Fungus/Scripts/Commands/Conversation.cs
  10. 2
      Assets/Fungus/Scripts/Commands/DebugLog.cs
  11. 2
      Assets/Fungus/Scripts/Commands/DeleteSaveKey.cs
  12. 2
      Assets/Fungus/Scripts/Commands/ExecuteLua.cs
  13. 2
      Assets/Fungus/Scripts/Commands/LoadVariable.cs
  14. 2
      Assets/Fungus/Scripts/Commands/Menu.cs
  15. 2
      Assets/Fungus/Scripts/Commands/SaveVariable.cs
  16. 2
      Assets/Fungus/Scripts/Commands/Say.cs
  17. 4
      Assets/Fungus/Scripts/Commands/SendMessage.cs
  18. 2
      Assets/Fungus/Scripts/Commands/SetText.cs
  19. 2
      Assets/Fungus/Scripts/Commands/StopBlock.cs
  20. 4
      Assets/Fungus/Scripts/Commands/StopFlowchart.cs
  21. 2
      Assets/Fungus/Scripts/Commands/Write.cs
  22. 4
      Assets/Fungus/Scripts/Components/Localization.cs
  23. 2
      Assets/Fungus/Scripts/Components/MenuDialog.cs
  24. 2
      Assets/Fungus/Scripts/Components/SayDialog.cs
  25. 24
      Assets/Fungus/Scripts/Editor/BlockEditor.cs
  26. 2
      Assets/Fungus/Scripts/Editor/BlockInspector.cs
  27. 2
      Assets/Fungus/Scripts/Editor/CallEditor.cs
  28. 2
      Assets/Fungus/Scripts/Editor/CommandEditor.cs
  29. 2
      Assets/Fungus/Scripts/Editor/CommandListAdaptor.cs
  30. 6
      Assets/Fungus/Scripts/Editor/FlowchartEditor.cs
  31. 2
      Assets/Fungus/Scripts/Editor/FlowchartMenuItems.cs
  32. 12
      Assets/Fungus/Scripts/Editor/FlowchartWindow.cs
  33. 2
      Assets/Fungus/Scripts/Editor/IfEditor.cs
  34. 2
      Assets/Fungus/Scripts/Editor/LabelEditor.cs
  35. 2
      Assets/Fungus/Scripts/Editor/MenuEditor.cs
  36. 2
      Assets/Fungus/Scripts/Editor/MenuTimerEditor.cs
  37. 2
      Assets/Fungus/Scripts/Editor/SetVariableEditor.cs
  38. 2
      Assets/Fungus/Scripts/Editor/VariableEditor.cs
  39. 2
      Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs
  40. 2
      Assets/Fungus/Scripts/Editor/ViewEditor.cs
  41. 2
      Assets/Fungus/Scripts/Interfaces/ISayDialog.cs

6
Assets/Fungus/Flowchart/Scripts/Block.cs

@ -124,9 +124,9 @@ namespace Fungus
public virtual int JumpToCommandIndex { set { jumpToCommandIndex = value; } }
public virtual Flowchart GetFlowchart()
public virtual IFlowchart GetFlowchart()
{
return GetComponent<Flowchart>();
return GetComponent<IFlowchart>();
}
public virtual bool IsExecuting()
@ -158,7 +158,7 @@ namespace Fungus
executionCount++;
Flowchart flowchart = GetFlowchart();
IFlowchart flowchart = GetFlowchart();
executionState = ExecutionState.Executing;
#if UNITY_EDITOR

10
Assets/Fungus/Flowchart/Scripts/Command.cs

@ -92,13 +92,13 @@ namespace Fungus
/// <summary>
/// Returns the Flowchart that this command belongs to.
/// </summary>
public virtual Flowchart GetFlowchart()
public virtual IFlowchart GetFlowchart()
{
Flowchart flowchart = GetComponent<Flowchart>();
IFlowchart flowchart = GetComponent<IFlowchart>();
if (flowchart == null &&
transform.parent != null)
{
flowchart = transform.parent.GetComponent<Flowchart>();
flowchart = transform.parent.GetComponent<IFlowchart>();
}
return flowchart;
}
@ -267,7 +267,7 @@ namespace Fungus
public virtual string GetFlowchartLocalizationId()
{
// If no localization id has been set then use the Flowchart name
Flowchart flowchart = GetFlowchart();
IFlowchart flowchart = GetFlowchart();
if (flowchart == null)
{
return "";
@ -276,7 +276,7 @@ namespace Fungus
string localizationId = GetFlowchart().LocalizationId;
if (localizationId.Length == 0)
{
localizationId = flowchart.name;
localizationId = flowchart.GetName();
}
return localizationId;

2
Assets/Fungus/Flowchart/Scripts/EventHandler.cs

@ -57,7 +57,7 @@ namespace Fungus
return false;
}
Flowchart flowchart = parentBlock.GetFlowchart();
var flowchart = parentBlock.GetFlowchart();
// Auto-follow the executing block if none is currently selected
if (flowchart.SelectedBlock == null)

5
Assets/Fungus/Flowchart/Scripts/Flowchart.cs

@ -337,6 +337,11 @@ namespace Fungus
return gameObject.activeInHierarchy;
}
public string GetName()
{
return gameObject.name;
}
public int NextItemId()
{
int maxId = -1;

2
Assets/Fungus/Flowchart/Scripts/IBlock.cs

@ -67,7 +67,7 @@ namespace Fungus
/// <summary>
/// Returns the parent Flowchart for this Block.
/// </summary>
Flowchart GetFlowchart();
IFlowchart GetFlowchart();
/// <summary>
/// Returns true if the Block is executing a command.

2
Assets/Fungus/Flowchart/Scripts/ICommand.cs

@ -50,7 +50,7 @@ namespace Fungus
/// <summary>
/// Returns the Flowchart that this command belongs to.
/// </summary>
Flowchart GetFlowchart();
IFlowchart GetFlowchart();
/// <summary>
/// Execute the command.

6
Assets/Fungus/Flowchart/Scripts/IFlowchart.cs

@ -115,9 +115,13 @@ namespace Fungus
/// <summary>
/// Returns true if the Flowchart gameobject is active.
/// </summary>
/// <returns><c>true</c> if this instance is active; otherwise, <c>false</c>.</returns>
bool IsActive();
/// <summary>
/// Returns the Flowchart gameobject name.
/// </summary>
string GetName();
/// <summary>
/// Create a new block node which you can then add commands to.
/// </summary>

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

@ -40,7 +40,7 @@ namespace Fungus
public override void OnEnter()
{
Flowchart flowchart = GetFlowchart();
var flowchart = GetFlowchart();
if (targetBlock != null)
{
@ -63,7 +63,7 @@ namespace Fungus
}
if (targetFlowchart == null ||
targetFlowchart == GetFlowchart())
targetFlowchart.Equals(GetFlowchart()))
{
// If the executing block is currently selected then follow the execution
// onto the next block in the inspector.

2
Assets/Fungus/Scripts/Commands/Conversation.cs

@ -32,7 +32,7 @@ namespace Fungus
protected virtual IEnumerator DoConversation()
{
Flowchart flowchart = GetFlowchart();
var flowchart = GetFlowchart();
string subbedText = flowchart.SubstituteVariables(conversationText.Value);
yield return StartCoroutine(conversationManager.DoConversation(subbedText));

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

@ -29,7 +29,7 @@ namespace Fungus
public override void OnEnter ()
{
Flowchart flowchart = GetFlowchart();
var flowchart = GetFlowchart();
string message = flowchart.SubstituteVariables(logMessage.Value);
switch (logType)

2
Assets/Fungus/Scripts/Commands/DeleteSaveKey.cs

@ -25,7 +25,7 @@ namespace Fungus
return;
}
Flowchart flowchart = GetFlowchart();
var flowchart = GetFlowchart();
// Prepend the current save profile (if any)
string prefsKey = SetSaveProfile.saveProfile + "_" + flowchart.SubstituteVariables(key);

2
Assets/Fungus/Scripts/Commands/ExecuteLua.cs

@ -61,7 +61,7 @@ namespace Fungus
// Cache a descriptive name to use in Lua error messages
friendlyName = gameObject.name + "." + ParentBlock.BlockName + "." + "ExecuteLua #" + CommandIndex.ToString();
Flowchart flowchart = GetFlowchart();
var flowchart = GetFlowchart();
// See if a Lua Environment has been assigned to this Flowchart
if (luaEnvironment == null)

2
Assets/Fungus/Scripts/Commands/LoadVariable.cs

@ -33,7 +33,7 @@ namespace Fungus
return;
}
Flowchart flowchart = GetFlowchart();
var flowchart = GetFlowchart();
// Prepend the current save profile (if any)
string prefsKey = SetSaveProfile.saveProfile + "_" + flowchart.SubstituteVariables(key);

2
Assets/Fungus/Scripts/Commands/Menu.cs

@ -52,7 +52,7 @@ namespace Fungus
{
menuDialog.SetActive(true);
Flowchart flowchart = GetFlowchart();
var flowchart = GetFlowchart();
string displayText = flowchart.SubstituteVariables(text);
menuDialog.AddOption(displayText, interactable, targetBlock);

2
Assets/Fungus/Scripts/Commands/SaveVariable.cs

@ -37,7 +37,7 @@ namespace Fungus
return;
}
Flowchart flowchart = GetFlowchart();
var flowchart = GetFlowchart();
// Prepend the current save profile (if any)
string prefsKey = SetSaveProfile.saveProfile + "_" + flowchart.SubstituteVariables(key);

2
Assets/Fungus/Scripts/Commands/Say.cs

@ -85,7 +85,7 @@ namespace Fungus
return;
}
Flowchart flowchart = GetFlowchart();
var flowchart = GetFlowchart();
sayDialog.SetActive(true);

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

@ -36,12 +36,10 @@ namespace Fungus
return;
}
Flowchart flowchart = GetFlowchart();
MessageReceived[] receivers = null;
if (messageTarget == MessageTarget.SameFlowchart)
{
receivers = flowchart.GetComponents<MessageReceived>();
receivers = GetComponents<MessageReceived>();
}
else
{

2
Assets/Fungus/Scripts/Commands/SetText.cs

@ -28,7 +28,7 @@ namespace Fungus
public override void OnEnter()
{
Flowchart flowchart = GetFlowchart();
var flowchart = GetFlowchart();
string newText = flowchart.SubstituteVariables(text.Value);
if (targetTextObject == null)

2
Assets/Fungus/Scripts/Commands/StopBlock.cs

@ -28,7 +28,7 @@ namespace Fungus
if (flowchart == null)
{
flowchart = GetFlowchart();
flowchart = (Flowchart)GetFlowchart();
}
IBlock block = flowchart.FindBlock(blockName.Value);

4
Assets/Fungus/Scripts/Commands/StopFlowchart.cs

@ -23,14 +23,14 @@ namespace Fungus
public override void OnEnter()
{
Flowchart flowchart = GetFlowchart();
IFlowchart flowchart = GetFlowchart();
if (stopParentFlowchart)
{
flowchart.StopAllBlocks();
}
foreach (Flowchart f in targetFlowcharts)
foreach (IFlowchart f in targetFlowcharts)
{
if (f == flowchart)
{

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

@ -82,7 +82,7 @@ namespace Fungus
break;
}
Flowchart flowchart = GetFlowchart();
var flowchart = GetFlowchart();
string newText = flowchart.SubstituteVariables(text.Value);
if (!waitUntilFinished)

4
Assets/Fungus/Scripts/Components/Localization.cs

@ -135,8 +135,8 @@ namespace Fungus
// Add localizable commands in same order as command list to make it
// easier to localise / edit standard text.
Flowchart[] flowcharts = GameObject.FindObjectsOfType<Flowchart>();
foreach (Flowchart flowchart in flowcharts)
var flowcharts = GameObject.FindObjectsOfType<Flowchart>();
foreach (var flowchart in flowcharts)
{
IBlock[] blocks = flowchart.GetComponents<IBlock>();
foreach (IBlock block in blocks)

2
Assets/Fungus/Scripts/Components/MenuDialog.cs

@ -184,7 +184,7 @@ namespace Fungus
{
#if UNITY_EDITOR
// Select the new target block in the Flowchart window
Flowchart flowchart = block.GetFlowchart();
var flowchart = block.GetFlowchart();
flowchart.SelectedBlock = block;
#endif

2
Assets/Fungus/Scripts/Components/SayDialog.cs

@ -245,7 +245,7 @@ namespace Fungus
gameObject.SetActive(state);
}
public virtual void SetCharacter(Character character, Flowchart flowchart = null)
public virtual void SetCharacter(Character character, IFlowchart flowchart = null)
{
if (character == null)
{

24
Assets/Fungus/Scripts/Editor/BlockEditor.cs

@ -633,7 +633,7 @@ namespace Fungus
{
IBlock block = target as IBlock;
Flowchart flowchart = block.GetFlowchart();
var flowchart = (Flowchart)block.GetFlowchart();
// Use index of last selected command in list, or end of list if nothing selected.
int index = -1;
@ -728,7 +728,7 @@ namespace Fungus
return;
}
Flowchart flowchart = block.GetFlowchart();
var flowchart = (Flowchart)block.GetFlowchart();
flowchart.ClearSelectedCommands();
@ -757,7 +757,7 @@ namespace Fungus
public virtual void ShowContextMenu()
{
IBlock block = target as IBlock;
Flowchart flowchart = block.GetFlowchart();
var flowchart = (Flowchart)block.GetFlowchart();
if (flowchart == null)
{
@ -845,7 +845,7 @@ namespace Fungus
protected void SelectAll()
{
IBlock block = target as IBlock;
Flowchart flowchart = block.GetFlowchart();
var flowchart = (Flowchart)block.GetFlowchart();
if (flowchart == null ||
flowchart.SelectedBlock == null)
@ -866,7 +866,7 @@ namespace Fungus
protected void SelectNone()
{
IBlock block = target as IBlock;
Flowchart flowchart = block.GetFlowchart();
var flowchart = (Flowchart)block.GetFlowchart();
if (flowchart == null ||
flowchart.SelectedBlock == null)
@ -889,7 +889,7 @@ namespace Fungus
protected void Copy()
{
IBlock block = target as IBlock;
Flowchart flowchart = block.GetFlowchart();
var flowchart = (Flowchart)block.GetFlowchart();
if (flowchart == null ||
flowchart.SelectedBlock == null)
@ -919,7 +919,7 @@ namespace Fungus
protected void Paste()
{
IBlock block = target as IBlock;
Flowchart flowchart = block.GetFlowchart();
var flowchart = (Flowchart)block.GetFlowchart();
if (flowchart == null ||
flowchart.SelectedBlock == null)
@ -978,7 +978,7 @@ namespace Fungus
protected void Delete()
{
IBlock block = target as IBlock;
Flowchart flowchart = block.GetFlowchart();
var flowchart = (Flowchart)block.GetFlowchart();
if (flowchart == null ||
flowchart.SelectedBlock == null)
@ -1023,7 +1023,7 @@ namespace Fungus
protected void PlayCommand()
{
IBlock targetBlock = target as IBlock;
Flowchart flowchart = targetBlock.GetFlowchart();
var flowchart = (Flowchart)targetBlock.GetFlowchart();
Command command = flowchart.SelectedCommands[0];
if (targetBlock.IsExecuting())
{
@ -1043,7 +1043,7 @@ namespace Fungus
protected void StopAllPlayCommand()
{
IBlock targetBlock = target as IBlock;
Flowchart flowchart = targetBlock.GetFlowchart();
var flowchart = (Flowchart)targetBlock.GetFlowchart();
Command command = flowchart.SelectedCommands[0];
// Stop all active blocks then run the selected block.
@ -1060,7 +1060,7 @@ namespace Fungus
protected void SelectPrevious()
{
IBlock block = target as IBlock;
Flowchart flowchart = block.GetFlowchart();
var flowchart = (Flowchart)block.GetFlowchart();
int firstSelectedIndex = flowchart.SelectedBlock.CommandList.Count;
bool firstSelectedCommandFound = false;
@ -1100,7 +1100,7 @@ namespace Fungus
protected void SelectNext()
{
IBlock block = target as IBlock;
Flowchart flowchart = block.GetFlowchart();
var flowchart = (Flowchart)block.GetFlowchart();
int lastSelectedIndex = -1;
if (flowchart.SelectedCommands.Count > 0)

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

@ -77,7 +77,7 @@ namespace Fungus
IBlock block = blockInspector.block;
Flowchart flowchart = block.GetFlowchart();
var flowchart = (Flowchart)block.GetFlowchart();
if (activeBlockEditor == null ||
!block.Equals(activeBlockEditor.target))

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

@ -34,7 +34,7 @@ namespace Fungus
Flowchart flowchart = null;
if (targetFlowchartProp.objectReferenceValue == null)
{
flowchart = t.GetFlowchart();
flowchart = (Flowchart)t.GetFlowchart();
}
else
{

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

@ -37,7 +37,7 @@ namespace Fungus
return;
}
Flowchart flowchart = t.GetFlowchart();
var flowchart = (Flowchart)t.GetFlowchart();
if (flowchart == null)
{
return;

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

@ -167,7 +167,7 @@ namespace Fungus
return;
}
Flowchart flowchart = command.GetFlowchart();
var flowchart = (Flowchart)command.GetFlowchart();
if (flowchart == null)
{
return;

6
Assets/Fungus/Scripts/Editor/FlowchartEditor.cs

@ -57,7 +57,7 @@ namespace Fungus
{
serializedObject.Update();
Flowchart flowchart = target as Flowchart;
var flowchart = target as Flowchart;
flowchart.UpdateHideFlags();
@ -100,7 +100,7 @@ namespace Fungus
{
serializedObject.Update();
Flowchart t = target as Flowchart;
var t = target as Flowchart;
if (t.Variables.Count == 0)
{
@ -240,7 +240,7 @@ namespace Fungus
return;
}
Flowchart flowchart = addVariableInfo.flowchart;
var flowchart = addVariableInfo.flowchart;
System.Type variableType = addVariableInfo.variableType;
Undo.RecordObject(flowchart, "Add Variable");

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

@ -15,7 +15,7 @@ namespace Fungus
go.transform.position = Vector3.zero;
// This is the latest version of Flowchart, so no need to update.
Flowchart flowchart = go.GetComponent<Flowchart>();
var flowchart = go.GetComponent<Flowchart>();
if (flowchart != null)
{
flowchart.Version = Flowchart.CURRENT_VERSION;

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

@ -61,7 +61,7 @@ namespace Fungus
protected virtual void OnInspectorUpdate()
{
// Ensure the Block Inspector is always showing the currently selected block
Flowchart flowchart = GetFlowchart();
var flowchart = GetFlowchart();
if (flowchart == null)
{
return;
@ -97,7 +97,7 @@ namespace Fungus
if (Selection.activeGameObject != null)
{
Flowchart fs = Selection.activeGameObject.GetComponent<Flowchart>();
var fs = Selection.activeGameObject.GetComponent<Flowchart>();
if (fs != null)
{
fungusState.SelectedFlowchart = fs;
@ -109,7 +109,7 @@ namespace Fungus
protected virtual void OnGUI()
{
Flowchart flowchart = GetFlowchart();
var flowchart = GetFlowchart();
if (flowchart == null)
{
GUILayout.Label("No Flowchart scene object selected");
@ -573,7 +573,7 @@ namespace Fungus
protected virtual void DrawWindow(int windowId)
{
IBlock block = windowBlockMap[windowId];
Flowchart flowchart = block.GetFlowchart();
var flowchart = (Flowchart)block.GetFlowchart();
if (flowchart == null)
{
@ -713,7 +713,7 @@ namespace Fungus
{
if (blockB == null ||
block == blockB ||
blockB.GetFlowchart() != flowchart)
!blockB.GetFlowchart().Equals(flowchart))
{
continue;
}
@ -788,7 +788,7 @@ namespace Fungus
protected static void DuplicateBlock(object obj)
{
Flowchart flowchart = GetFlowchart();
var flowchart = GetFlowchart();
Block block = obj as Block;
Vector2 newPosition = new Vector2(block._NodeRect.position.x +

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

@ -36,7 +36,7 @@ namespace Fungus
If t = target as If;
Flowchart flowchart = t.GetFlowchart();
var flowchart = (Flowchart)t.GetFlowchart();
if (flowchart == null)
{
return;

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

@ -62,7 +62,7 @@ namespace Fungus
{
Label t = target as Label;
Flowchart flowchart = t.GetFlowchart();
var flowchart = (Flowchart)t.GetFlowchart();
if (flowchart == null)
{
return;

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

@ -31,7 +31,7 @@ namespace Fungus
public override void DrawCommandGUI()
{
Flowchart flowchart = FlowchartWindow.GetFlowchart();
var flowchart = FlowchartWindow.GetFlowchart();
if (flowchart == null)
{
return;

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

@ -23,7 +23,7 @@ namespace Fungus
public override void DrawCommandGUI()
{
Flowchart flowchart = FlowchartWindow.GetFlowchart();
var flowchart = FlowchartWindow.GetFlowchart();
if (flowchart == null)
{
return;

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

@ -37,7 +37,7 @@ namespace Fungus
SetVariable t = target as SetVariable;
Flowchart flowchart = t.GetFlowchart();
var flowchart = (Flowchart)t.GetFlowchart();
if (flowchart == null)
{
return;

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

@ -203,7 +203,7 @@ namespace Fungus
return;
}
Flowchart flowchart = command.GetFlowchart() as Flowchart;
var flowchart = command.GetFlowchart() as Flowchart;
if (flowchart == null)
{
return;

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

@ -123,7 +123,7 @@ namespace Fungus
return;
}
Flowchart flowchart = FlowchartWindow.GetFlowchart();
var flowchart = FlowchartWindow.GetFlowchart();
if (flowchart == null)
{
return;

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

@ -168,7 +168,7 @@ namespace Fungus
bool highlight = Selection.activeGameObject == view.gameObject;
Flowchart flowchart = FlowchartWindow.GetFlowchart();
var flowchart = FlowchartWindow.GetFlowchart();
if (flowchart != null)
{
foreach (Command command in flowchart.SelectedCommands)

2
Assets/Fungus/Scripts/Interfaces/ISayDialog.cs

@ -18,7 +18,7 @@ namespace Fungus
/// </summary>
/// <param name="character">The active speaking character.</param>
/// <param name="flowchart">An optional Flowchart to use for variable substitution in the character name string.</param>
void SetCharacter(Character character, Flowchart flowchart = null);
void SetCharacter(Character character, IFlowchart flowchart = null);
/// <summary>
/// Sets the character image to display on the Say Dialog.

Loading…
Cancel
Save