// 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 UnityEngine;
using System.Collections.Generic;
namespace Fungus
{
///
/// Visual scripting controller for the Flowchart programming language.
/// Flowchart objects may be edited visually using the Flowchart editor window.
///
public interface IFlowchart
{
///
/// Scroll position of Flowchart editor window.
///
Vector2 ScrollPos { get; set; }
///
/// Scroll position of Flowchart variables window.
///
Vector2 VariablesScrollPos { get; set; }
///
/// Show the variables pane.
///
bool VariablesExpanded { get; set; }
///
/// Height of command block view in inspector.
///
float BlockViewHeight { get; set; }
///
/// Zoom level of Flowchart editor window.
///
float Zoom { get; set; }
///
/// Scrollable area for Flowchart editor window.
///
Rect ScrollViewRect { get; set; }
///
/// Currently selected block in the Flowchart editor.
///
Block SelectedBlock { get; set; }
///
/// Currently selected command in the Flowchart editor.
///
List SelectedCommands { get; }
///
/// The list of variables that can be accessed by the Flowchart.
///
List Variables { get; }
///
/// Description text displayed in the Flowchart editor window
///
string Description { get; }
///
/// Slow down execution in the editor to make it easier to visualise program flow.
///
float StepPause { get; }
///
/// Use command color when displaying the command list in the inspector.
///
bool ColorCommands { get; }
///
/// Saves the selected block and commands when saving the scene. Helps avoid version control conflicts if you've only changed the active selection.
///
bool SaveSelection { get; }
///
/// Unique identifier for identifying this flowchart in localized string keys.
///
string LocalizationId { get; }
///
/// Display line numbers in the command list in the Block inspector.
///
bool ShowLineNumbers { get; }
///
/// Lua Environment to be used by default for all Execute Lua commands in this Flowchart.
///
ILuaEnvironment LuaEnv { get; }
///
/// The ExecuteLua command adds a global Lua variable with this name bound to the flowchart prior to executing.
///
string LuaBindingName { get; }
///
/// Position in the center of all blocks in the flowchart.
///
Vector2 CenterPosition { set; get; }
///
/// Variable to track flowchart's version so components can update to new versions.
///
int Version { set; }
///
/// Returns the next id to assign to a new flowchart item.
/// Item ids increase monotically so they are guaranteed to
/// be unique within a Flowchart.
///
int NextItemId();
///
/// Returns true if the Flowchart gameobject is active.
///
bool IsActive();
///
/// Returns the Flowchart gameobject name.
///
string GetName();
///
/// Create a new block node which you can then add commands to.
///
Block CreateBlock(Vector2 position);
///
/// Returns the named Block in the flowchart, or null if not found.
///
IBlock FindBlock(string blockName);
///
/// Execute a child block in the Flowchart.
/// You can use this method in a UI event. e.g. to handle a button click.
void ExecuteBlock(string blockName);
///
/// Execute a child block in the flowchart.
/// The block must be in an idle state to be executed.
/// This version provides extra options to control how the block is executed.
/// Returns true if the Block started execution.
///
bool ExecuteBlock(IBlock block, int commandIndex = 0, System.Action onComplete = null);
///
/// Stop all executing Blocks in this Flowchart.
///
void StopAllBlocks();
///
/// Sends a message to this Flowchart only.
/// Any block with a matching MessageReceived event handler will start executing.
///
void SendFungusMessage(string messageName);
///
/// Returns a new variable key that is guaranteed not to clash with any existing variable in the list.
///
string GetUniqueVariableKey(string originalKey, Variable ignoreVariable = null);
///
/// Returns a new Block key that is guaranteed not to clash with any existing Block in the Flowchart.
///
string GetUniqueBlockKey(string originalKey, IBlock ignoreBlock = null);
///
/// Returns a new Label key that is guaranteed not to clash with any existing Label in the Block.
///
string GetUniqueLabelKey(string originalKey, Label ignoreLabel);
///
/// Returns the variable with the specified key, or null if the key is not found.
/// You will need to cast the returned variable to the correct sub-type.
/// You can then access the variable's value using the Value property. e.g.
/// BooleanVariable boolVar = flowchart.GetVariable("MyBool") as BooleanVariable;
/// boolVar.Value = false;
///
Variable GetVariable(string key);
///
/// Returns the variable with the specified key, or null if the key is not found.
/// You can then access the variable's value using the Value property. e.g.
/// BooleanVariable boolVar = flowchart.GetVariable("MyBool");
/// boolVar.Value = false;
///
T GetVariable(string key) where T : Variable;
///
/// Register a new variable with the Flowchart at runtime.
/// The variable should be added as a component on the Flowchart game object.
///
void SetVariable(string key, T newvariable) where T : Variable;
///
/// Gets a list of all variables with public scope in this Flowchart.
///
List GetPublicVariables();
///
/// Gets the value of a boolean variable.
/// Returns false if the variable key does not exist.
///
bool GetBooleanVariable(string key);
///
/// Sets the value of a boolean variable.
/// The variable must already be added to the list of variables for this Flowchart.
///
void SetBooleanVariable(string key, bool value);
///
/// Gets the value of an integer variable.
/// Returns 0 if the variable key does not exist.
///
int GetIntegerVariable(string key);
///
/// Sets the value of an integer variable.
/// The variable must already be added to the list of variables for this Flowchart.
///
void SetIntegerVariable(string key, int value);
///
/// Gets the value of a float variable.
/// Returns 0 if the variable key does not exist.
///
float GetFloatVariable(string key);
///
/// Sets the value of a float variable.
/// The variable must already be added to the list of variables for this Flowchart.
///
void SetFloatVariable(string key, float value);
///
/// Gets the value of a string variable.
/// Returns the empty string if the variable key does not exist.
///
string GetStringVariable(string key);
///
/// Sets the value of a string variable.
/// The variable must already be added to the list of variables for this Flowchart.
///
void SetStringVariable(string key, string value);
///
/// Set the block objects to be hidden or visible depending on the hideComponents property.
///
void UpdateHideFlags();
///
/// Clears the list of selected commands.
///
void ClearSelectedCommands();
///
/// Adds a command to the list of selected commands.
///
void AddSelectedCommand(Command command);
///
/// Reset the commands and variables in the Flowchart.
///
void Reset(bool resetCommands, bool resetVariables);
///
/// Override this in a Flowchart subclass to filter which commands are shown in the Add Command list.
///
bool IsCommandSupported(CommandInfoAttribute commandInfo);
///
/// Returns true if there are any executing blocks in this Flowchart.
///
bool HasExecutingBlocks();
///
/// Returns a list of all executing blocks in this Flowchart.
///
List GetExecutingBlocks();
///
/// Substitute variables in the input text with the format {$VarName}
/// This will first match with private variables in this Flowchart, and then
/// with public variables in all Flowcharts in the scene (and any component
/// in the scene that implements StringSubstituter.ISubstitutionHandler).
///
string SubstituteVariables(string input);
}
}