Browse Source

Reverted IBlock interface

master
Christopher 9 years ago
parent
commit
01feb27c61
  1. 2
      Assets/Fungus/Scripts/Commands/StopBlock.cs
  2. 73
      Assets/Fungus/Scripts/Components/Block.cs
  3. 32
      Assets/Fungus/Scripts/Components/Flowchart.cs
  4. 2
      Assets/Fungus/Scripts/Components/Localization.cs
  5. 2
      Assets/Fungus/Scripts/Editor/FlowchartWindow.cs
  6. 119
      Assets/Fungus/Scripts/Interfaces/IBlock.cs
  7. 12
      Assets/Fungus/Scripts/Interfaces/IBlock.cs.meta
  8. 8
      Assets/Fungus/Scripts/Interfaces/IFlowchart.cs

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

@ -32,7 +32,7 @@ namespace Fungus.Commands
flowchart = (Flowchart)GetFlowchart();
}
IBlock block = flowchart.FindBlock(blockName.Value);
var block = flowchart.FindBlock(blockName.Value);
if (block == null ||
!block.IsExecuting())
{

73
Assets/Fungus/Scripts/Components/Block.cs

@ -11,13 +11,24 @@ using Fungus.Utils;
namespace Fungus
{
/// <summary>
/// Execution state of a Block.
/// </summary>
public enum ExecutionState
{
/// <summary> No command executing </summary>
Idle,
/// <summary> Executing a command </summary>
Executing,
}
/// <summary>
/// A container for a sequence of Fungus comands.
/// </summary>
[ExecuteInEditMode]
[RequireComponent(typeof(Flowchart))]
[AddComponentMenu("")]
public class Block : Node, IBlock
public class Block : Node
{
[SerializeField] protected int itemId = -1; // Invalid flowchart item id
@ -101,46 +112,91 @@ namespace Fungus
}
#endif
#region IBlock implementation
#region Public methods
/// <summary>
/// The execution state of the Block.
/// </summary>
public virtual ExecutionState State { get { return executionState; } }
/// <summary>
/// Unique identifier for the Block.
/// </summary>
public virtual int ItemId { get { return itemId; } set { itemId = value; } }
/// <summary>
/// The name of the block node as displayed in the Flowchart window.
/// </summary>
public virtual string BlockName { get { return blockName; } set { blockName = value; } }
/// <summary>
/// Description text to display under the block node
/// </summary>
public virtual string Description { get { return description; } }
/// <summary>
/// An optional Event Handler which can execute the block when an event occurs.
/// Note: Using the concrete class instead of the interface here because of weird editor behaviour.
/// </summary>
public virtual EventHandler _EventHandler { get { return eventHandler; } set { eventHandler = value; } }
/// <summary>
/// The currently executing command.
/// </summary>
public virtual Command ActiveCommand { get { return activeCommand; } }
/// <summary>
/// Timer for fading Block execution icon.
/// </summary>
public virtual float ExecutingIconTimer { get; set; }
/// <summary>
/// The list of commands in the sequence.
/// </summary>
public virtual List<Command> CommandList { get { return commandList; } }
/// <summary>
/// Controls the next command to execute in the block execution coroutine.
/// </summary>
public virtual int JumpToCommandIndex { set { jumpToCommandIndex = value; } }
/// <summary>
/// Returns the parent Flowchart for this Block.
/// </summary>
public virtual IFlowchart GetFlowchart()
{
return GetComponent<IFlowchart>();
}
/// <summary>
/// Returns true if the Block is executing a command.
/// </summary>
public virtual bool IsExecuting()
{
return (executionState == ExecutionState.Executing);
}
/// <summary>
/// Returns the number of times this Block has executed.
/// </summary>
public virtual int GetExecutionCount()
{
return executionCount;
}
/// <summary>
/// Start a coroutine which executes all commands in the Block. Only one running instance of each Block is permitted.
/// </summary>
public virtual void StartExecution()
{
StartCoroutine(Execute());
}
/// <summary>
/// A coroutine method that executes all commands in the Block. Only one running instance of each Block is permitted.
/// </summary>
/// <param name="commandIndex">Index of command to start execution at</param>
/// <param name="onComplete">Delegate function to call when execution completes</param>
public virtual IEnumerator Execute(int commandIndex = 0, Action onComplete = null)
{
if (executionState != ExecutionState.Idle)
@ -249,6 +305,9 @@ namespace Fungus
}
}
/// <summary>
/// Stop executing commands in this Block.
/// </summary>
public virtual void Stop()
{
// Tell the executing command to stop immediately
@ -262,6 +321,9 @@ namespace Fungus
jumpToCommandIndex = int.MaxValue;
}
/// <summary>
/// Returns a list of all Blocks connected to this one.
/// </summary>
public virtual List<Block> GetConnectedBlocks()
{
var connectedBlocks = new List<Block>();
@ -275,6 +337,10 @@ namespace Fungus
return connectedBlocks;
}
/// <summary>
/// Returns the type of the previously executing command.
/// </summary>
/// <returns>The previous active command type.</returns>
public virtual System.Type GetPreviousActiveCommandType()
{
if (previousActiveCommandIndex >= 0 &&
@ -286,6 +352,9 @@ namespace Fungus
return null;
}
/// <summary>
/// Recalculate the indent levels for all commands in the list.
/// </summary>
public virtual void UpdateIndentLevels()
{
int indentLevel = 0;

32
Assets/Fungus/Scripts/Components/Flowchart.cs

@ -200,7 +200,7 @@ namespace Fungus
// Make sure item ids are unique and monotonically increasing.
// This should always be the case, but some legacy Flowcharts may have issues.
List<int> usedIds = new List<int>();
var blocks = GetComponents<IBlock>();
var blocks = GetComponents<Block>();
foreach (var block in blocks)
{
if (block.ItemId == -1 ||
@ -241,7 +241,7 @@ namespace Fungus
}
}
var blocks = GetComponents<IBlock>();
var blocks = GetComponents<Block>();
foreach (var command in GetComponents<Command>())
{
@ -339,7 +339,7 @@ namespace Fungus
public int NextItemId()
{
int maxId = -1;
var blocks = GetComponents<IBlock>();
var blocks = GetComponents<Block>();
foreach (var block in blocks)
{
maxId = Math.Max(maxId, block.ItemId);
@ -363,9 +363,9 @@ namespace Fungus
return b;
}
public virtual IBlock FindBlock(string blockName)
public virtual Block FindBlock(string blockName)
{
var blocks = GetComponents<IBlock>();
var blocks = GetComponents<Block>();
foreach (var block in blocks)
{
if (block.BlockName == blockName)
@ -393,7 +393,7 @@ namespace Fungus
}
}
public virtual bool ExecuteBlock(IBlock block, int commandIndex = 0, Action onComplete = null)
public virtual bool ExecuteBlock(Block block, int commandIndex = 0, Action onComplete = null)
{
if (block == null)
{
@ -421,8 +421,8 @@ namespace Fungus
public virtual void StopAllBlocks()
{
var blocks = GetComponents<IBlock>();
foreach (IBlock block in blocks)
var blocks = GetComponents<Block>();
foreach (Block block in blocks)
{
if (block.IsExecuting())
{
@ -486,7 +486,7 @@ namespace Fungus
}
}
public virtual string GetUniqueBlockKey(string originalKey, IBlock ignoreBlock = null)
public virtual string GetUniqueBlockKey(string originalKey, Block ignoreBlock = null)
{
int suffix = 0;
string baseKey = originalKey.Trim();
@ -497,7 +497,7 @@ namespace Fungus
baseKey = FungusConstants.DefaultBlockName;
}
var blocks = GetComponents<IBlock>();
var blocks = GetComponents<Block>();
string key = baseKey;
while (true)
@ -537,7 +537,7 @@ namespace Fungus
baseKey = "New Label";
}
IBlock block = ignoreLabel.ParentBlock;
var block = ignoreLabel.ParentBlock;
string key = baseKey;
while (true)
@ -811,8 +811,8 @@ namespace Fungus
public virtual bool HasExecutingBlocks()
{
var blocks = GetComponents<IBlock>();
foreach (IBlock block in blocks)
var blocks = GetComponents<Block>();
foreach (var block in blocks)
{
if (block.IsExecuting())
{
@ -822,10 +822,10 @@ namespace Fungus
return false;
}
public virtual List<IBlock> GetExecutingBlocks()
public virtual List<Block> GetExecutingBlocks()
{
var executingBlocks = new List<IBlock>();
var blocks = GetComponents<IBlock>();
var executingBlocks = new List<Block>();
var blocks = GetComponents<Block>();
foreach (var block in blocks)
{
if (block.IsExecuting())

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

@ -139,7 +139,7 @@ namespace Fungus
var flowcharts = GameObject.FindObjectsOfType<Flowchart>();
foreach (var flowchart in flowcharts)
{
var blocks = flowchart.GetComponents<IBlock>();
var blocks = flowchart.GetComponents<Block>();
foreach (var block in blocks)
{
foreach (var command in block.CommandList)

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

@ -551,7 +551,7 @@ namespace Fungus.EditorUtils
return newBlock;
}
protected virtual void DeleteBlock(Flowchart flowchart, IBlock block)
protected virtual void DeleteBlock(Flowchart flowchart, Block block)
{
foreach (var command in block.CommandList)
{

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

@ -1,119 +0,0 @@
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using System.Collections;
using System.Collections.Generic;
namespace Fungus
{
/// <summary>
/// Execution state of a Block.
/// </summary>
public enum ExecutionState
{
/// <summary> No command executing </summary>
Idle,
/// <summary> Executing a command </summary>
Executing,
}
/// <summary>
/// A container for a sequence of Fungus comands.
/// </summary>
public interface IBlock
{
/// <summary>
/// The execution state of the Block.
/// </summary>
ExecutionState State { get; }
/// <summary>
/// Unique identifier for the Block.
/// </summary>
int ItemId { get; set; }
/// <summary>
/// The name of the block node as displayed in the Flowchart window.
/// </summary>
string BlockName { get; set; }
/// <summary>
/// Description text to display under the block node
/// </summary>
string Description { get; }
/// <summary>
/// An optional Event Handler which can execute the block when an event occurs.
/// Note: Using the concrete class instead of the interface here because of weird editor behaviour.
/// </summary>
EventHandler _EventHandler { get; set; }
/// <summary>
/// The currently executing command.
/// </summary>
Command ActiveCommand { get; }
/// <summary>
/// Timer for fading Block execution icon.
/// </summary>
float ExecutingIconTimer { get; set; }
/// <summary>
/// The list of commands in the sequence.
/// </summary>
List<Command> CommandList { get; }
/// <summary>
/// Controls the next command to execute in the block execution coroutine.
/// </summary>
int JumpToCommandIndex { set; }
/// <summary>
/// Returns the parent Flowchart for this Block.
/// </summary>
IFlowchart GetFlowchart();
/// <summary>
/// Returns true if the Block is executing a command.
/// </summary>
bool IsExecuting();
/// <summary>
/// Returns the number of times this Block has executed.
/// </summary>
int GetExecutionCount();
/// <summary>
/// Start a coroutine which executes all commands in the Block. Only one running instance of each Block is permitted.
/// </summary>
void StartExecution();
/// <summary>
/// A coroutine method that executes all commands in the Block. Only one running instance of each Block is permitted.
/// </summary>
/// <param name="commandIndex">Index of command to start execution at</param>
/// <param name="onComplete">Delegate function to call when execution completes</param>
IEnumerator Execute(int commandIndex = 0, System.Action onComplete = null);
/// <summary>
/// Stop executing commands in this Block.
/// </summary>
void Stop();
/// <summary>
/// Returns a list of all Blocks connected to this one.
/// </summary>
List<Block> GetConnectedBlocks();
/// <summary>
/// Returns the type of the previously executing command.
/// </summary>
/// <returns>The previous active command type.</returns>
System.Type GetPreviousActiveCommandType();
/// <summary>
/// Recalculate the indent levels for all commands in the list.
/// </summary>
void UpdateIndentLevels();
}
}

12
Assets/Fungus/Scripts/Interfaces/IBlock.cs.meta

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 3a23dd66c807e4fab86a64184c3faa9a
timeCreated: 1473856388
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/Fungus/Scripts/Interfaces/IFlowchart.cs

@ -133,7 +133,7 @@ namespace Fungus
/// <summary>
/// Returns the named Block in the flowchart, or null if not found.
/// </summary>
IBlock FindBlock(string blockName);
Block FindBlock(string blockName);
/// <summary>
/// Execute a child block in the Flowchart.
@ -146,7 +146,7 @@ namespace Fungus
/// This version provides extra options to control how the block is executed.
/// Returns true if the Block started execution.
/// </summary>
bool ExecuteBlock(IBlock block, int commandIndex = 0, System.Action onComplete = null);
bool ExecuteBlock(Block block, int commandIndex = 0, System.Action onComplete = null);
/// <summary>
/// Stop all executing Blocks in this Flowchart.
@ -167,7 +167,7 @@ namespace Fungus
/// <summary>
/// Returns a new Block key that is guaranteed not to clash with any existing Block in the Flowchart.
/// </summary>
string GetUniqueBlockKey(string originalKey, IBlock ignoreBlock = null);
string GetUniqueBlockKey(string originalKey, Block ignoreBlock = null);
/// <summary>
/// Returns a new Label key that is guaranteed not to clash with any existing Label in the Block.
@ -283,7 +283,7 @@ namespace Fungus
/// <summary>
/// Returns a list of all executing blocks in this Flowchart.
/// </summary>
List<IBlock> GetExecutingBlocks();
List<Block> GetExecutingBlocks();
/// <summary>
/// Substitute variables in the input text with the format {$VarName}

Loading…
Cancel
Save