EasyTalk API
Loading...
Searching...
No Matches
EasyTalk.Controller.NodeHandler Class Reference

This class is used to process a collection of linked nodes, such as a dialogue and handles all of the logic for moving from one node to the next, evaluating variable values, and sending messages (via callbacks) about what is happening in a dialogue as it is processed. More...

Public Member Functions

 NodeHandler (GameObject owner)
 Creates a new NodeHandler.
 
void Initialize (Dialogue dialogue)
 Initializes the NodeHandler by setting the dialogue, clearing various mappings, determining the default 'entry' node, and creating variables.
 
void ForceExit ()
 Forces an exit to be triggered immediately on the Dialogue.
 
IEnumerator JumpToNodeAfterDelay (float delay, Node node)
 Jumps to the specified node after a certain amount of time.
 
void ChooseOption (int optionIdx)
 Chooses the option, and thus continues down the corresponding path, of the option specified.
 
void ProcessNode (Node node)
 Processes the node specified according to its type.
 
void HandleWaitNode ()
 Waits for the configured duration of the wait node currently being processed before continuing.
 
void HandlePauseNode ()
 Triggers the OnPause() callback on the Dialogue Listener and waits for a continue.
 
void HandleStoryNode ()
 Triggers the OnStory() callback on the Dialogue Listener and waits for a continue.
 
void ProcessCurrentNode ()
 Processes the current node, determining any dependent values used by the node and setting values as necessary on outputs. Once the node is processed, the next node will be determined and processed.
 
void HandleJump ()
 Handles the 'jump out' node by finding the associated 'jump in' node and moving to the next node after the 'jump in'.
 
void HandleConversation ()
 Handles the current 'conversation' node, sending a signal via the onDisplayConversationLine callback to display the first line in the 'conversation' node. If the 'conversation' node only has 1 line, the atConversationNodeEnding callback will also be triggered.
 
void HandlePathSelectorNode ()
 Evaluates the current 'path select' node to determine which path to continue down and the moves along that path.
 
void HandleOptionNode ()
 Builds a List of DialogueOptions to present to the player based on the current 'option' node. This method handles 'option modifier' nodes and also deals with variable injection, translation, and tag extraction. Once the List of DialogueOptions is created, this method calls the onDisplayOptions callback so that the options can be used by anything registered with the delegate.
 
string Translate (string text)
 Performs a lookup in the active Translation Library for the text provided and returns a translation, if there is one. The text is attempted to be translated into whatever langauge is set on EasyTalkGameState.Instance.Language.
 
string Translate (string text, out string preTranslationText)
 Performs a lookup in the active Translation Library for the text provided and returns a translation, if there is one. The text is attempted to be translated into whatever langauge is set on EasyTalkGameState.Instance.Language. This method also sets the provided preTranslationText string to the string being translated, immediately prior to translation. The preTranslationText may differ from the originally provided text if the EasyTalkDialogueSettings.Instance.TranslationEvaluationMode is set to TRANSLATE_AFTER_VARIABLE_EVALUATION, since in that mode, all variable tags are replaced with their values prior to translation.
 
void HandleExit ()
 Handles the current 'exit' node by exiting the dialogue and triggering the onDialogueExited callback.
 
string ReplaceVariablesInString (string text)
 This method does variable value injection, replacing all variable references in the specified string with their associated values.
 
object GetVariableValue (string variableName)
 Returns the value of the variable specified, if available; otherwise returns null.
 
void SetVariableValue (string variableName, object variableValue)
 Sets the value of the specified variable.
 
NodeVariable GetVariable (string variableName)
 Returns the NodeVariable associated with the specified variable name.
 
EntryNode FindEntryNode ()
 Finds and returns the first 'entry' node in the Dialogue.
 
void EnterDialogue (string entryPointName=null)
 Enters and begins processing the Dialogue. If no entry point is specified, the Dialogue will enter at the first 'entry' node found in the Dialogue.
 
void Continue ()
 Continues along to the next line of dialogue, or the next node if the last line is currently being displayed.
 
void ResetVariablesOnEntry ()
 Resets the values of each variable which is set to "reset on entry".
 
void SaveVariableValues (string prefix="", bool saveToPlayerPrefs=false)
 Saves the values of all variables in the Dialogue to either a file, or to the PlayerPrefs.
 
void LoadVariableValues (string prefix="", bool loadFromPlayerPrefs=false)
 Loads the states of the Dialogue's variables from a save if available.
 
void LoadVariableValues (NodeVariableValueCollection valueCollection)
 Loads the variable values from the specified NodeVariableValueCollection into the Dialogue.
 
NodeVariableValueCollection GetVariableValues ()
 Returns a new NodeVariableValueCollection containing the current values of each variable in the Dialogue.
 
string TranslateText (string text)
 Translates the specified string to a localized string using the TranslationLibrary of the Dialogue.
 
void SetListener (DialogueListener listener)
 Sets the Dialogue Listener which the node handler should send events to during Dialogue processing.
 

Protected Attributes

Dictionary< int, NodeinputIdToNodeMap = new Dictionary<int, Node>()
 A mapping of node input IDs to the nodes which those inputs belong to.
 
Dictionary< int, NodeoutputIdToNodeMap = new Dictionary<int, Node>()
 A mapping of node output IDs to the nodes which those inputs belong to.
 
Dictionary< string, NodejumpMap = new Dictionary<string, Node>()
 A mapping of jump keys/IDs to the 'jump in' nodes they belong to.
 
Dictionary< string, NodeVariablevariables = new Dictionary<string, NodeVariable>()
 A mapping of variable names to their definitions and values.
 
Dictionary< string, NodeentryMap = new Dictionary<string, Node>()
 A mapping of entry IDs to the 'entry' nodes they belong to.
 
Node entryNode
 The default 'entry' node which is used if an entry ID is not provided, or the 'entry' node with the ID specified can't be found.
 
Node currentNode
 The current node being processed/displayed.
 
int convoIdx = 0
 The line index of the conversation when a 'conversation' node is being processed.
 
GameObject owner = null
 The GameObject this NodeHandler is being used by.
 

Private Member Functions

void Propagate (Dictionary< int, object > nodeOutputValues, Node node)
 Evaluates the specified node to determine its output value based on its configuration and any incoming values that it depends upon, then pushes the evaluated final value to any nodes connected along the output value path.
 
void DetermineNodeValue (Dictionary< int, object > nodeOutputValues, Node node)
 Recursively determines the output value of the specified node.
 
ConversationLine GetConversationLine ()
 Builds a ConversationLine object containing information about the current line of dialogue to be displayed. This method handles variable injection, tag extraction, and translation on the text in the 'conversation' node's current line of dialogue.
 
Node GetNextNode ()
 Returns the next node along the Dialogue flow path.
 
void CreateBoolVariable (Node node)
 Creates a new bool type NodeVariable from the provided bool variable node.
 
void CreateIntVariable (Node node)
 Creates a new int type NodeVariable from the provided int variable node.
 
void CreateFloatVariable (Node node)
 Creates a new float type NodeVariable from the provided float variable node.
 
void CreateStringVariable (Node node)
 Creates a new string type NodeVariable from the provided string variable node.
 

Private Attributes

Dialogue dialogue
 The dialogue to process.
 
DialogueListener listener
 The Dialogue Listener to use for callbacks as events happen during dialogue processing.
 

Detailed Description

This class is used to process a collection of linked nodes, such as a dialogue and handles all of the logic for moving from one node to the next, evaluating variable values, and sending messages (via callbacks) about what is happening in a dialogue as it is processed.

Constructor & Destructor Documentation

◆ NodeHandler()

EasyTalk.Controller.NodeHandler.NodeHandler ( GameObject owner)

Creates a new NodeHandler.

Parameters
ownerThe GameObject which the NodeHandler is associated with.

Member Function Documentation

◆ ChooseOption()

void EasyTalk.Controller.NodeHandler.ChooseOption ( int optionIdx)

Chooses the option, and thus continues down the corresponding path, of the option specified.

Parameters
optionIdxThe option index to choose. This should be the index of the option as it was originally in the 'option' node, which may differ from the index of the option as it occurs in the List of options displayed to the player. It is recommended to use DialogueOption.OptionIndex for reliability.

◆ Continue()

void EasyTalk.Controller.NodeHandler.Continue ( )

Continues along to the next line of dialogue, or the next node if the last line is currently being displayed.

◆ CreateBoolVariable()

void EasyTalk.Controller.NodeHandler.CreateBoolVariable ( Node node)
private

Creates a new bool type NodeVariable from the provided bool variable node.

Parameters
nodeThe node to use.

◆ CreateFloatVariable()

void EasyTalk.Controller.NodeHandler.CreateFloatVariable ( Node node)
private

Creates a new float type NodeVariable from the provided float variable node.

Parameters
nodeThe node to use.

◆ CreateIntVariable()

void EasyTalk.Controller.NodeHandler.CreateIntVariable ( Node node)
private

Creates a new int type NodeVariable from the provided int variable node.

Parameters
nodeThe node to use.

◆ CreateStringVariable()

void EasyTalk.Controller.NodeHandler.CreateStringVariable ( Node node)
private

Creates a new string type NodeVariable from the provided string variable node.

Parameters
nodeThe node to use.

◆ DetermineNodeValue()

void EasyTalk.Controller.NodeHandler.DetermineNodeValue ( Dictionary< int, object > nodeOutputValues,
Node node )
private

Recursively determines the output value of the specified node.

Parameters
nodeOutputValuesA map of node IDs and connection IDs to the output values that those IDs correspond to.
nodeThe node to evaluate.

◆ EnterDialogue()

void EasyTalk.Controller.NodeHandler.EnterDialogue ( string entryPointName = null)

Enters and begins processing the Dialogue. If no entry point is specified, the Dialogue will enter at the first 'entry' node found in the Dialogue.

Parameters
entryPointNameThe optional name of the entry point where the Dialogue should start being processed.

◆ FindEntryNode()

EntryNode EasyTalk.Controller.NodeHandler.FindEntryNode ( )

Finds and returns the first 'entry' node in the Dialogue.

Returns
The first 'entry' node found int the Dialogue.

◆ ForceExit()

void EasyTalk.Controller.NodeHandler.ForceExit ( )

Forces an exit to be triggered immediately on the Dialogue.

◆ GetConversationLine()

ConversationLine EasyTalk.Controller.NodeHandler.GetConversationLine ( )
private

Builds a ConversationLine object containing information about the current line of dialogue to be displayed. This method handles variable injection, tag extraction, and translation on the text in the 'conversation' node's current line of dialogue.

Returns
A ConversationLine containing information about the current line of dialogue to be displayed.

◆ GetNextNode()

Node EasyTalk.Controller.NodeHandler.GetNextNode ( )
private

Returns the next node along the Dialogue flow path.

Returns
The next node to be moved to after the current node.

◆ GetVariable()

NodeVariable EasyTalk.Controller.NodeHandler.GetVariable ( string variableName)

Returns the NodeVariable associated with the specified variable name.

Parameters
variableNameThe name of the variable to retrieve.
Returns
The NodeVariable for the specified variable name.

◆ GetVariableValue()

object EasyTalk.Controller.NodeHandler.GetVariableValue ( string variableName)

Returns the value of the variable specified, if available; otherwise returns null.

Parameters
variableNameThe name of the variable to retrieve the value of.
Returns
The value of the specified variable.

◆ GetVariableValues()

NodeVariableValueCollection EasyTalk.Controller.NodeHandler.GetVariableValues ( )

Returns a new NodeVariableValueCollection containing the current values of each variable in the Dialogue.

Returns
A collection of current variable values for the Dialogue.

◆ HandleConversation()

void EasyTalk.Controller.NodeHandler.HandleConversation ( )

Handles the current 'conversation' node, sending a signal via the onDisplayConversationLine callback to display the first line in the 'conversation' node. If the 'conversation' node only has 1 line, the atConversationNodeEnding callback will also be triggered.

◆ HandleExit()

void EasyTalk.Controller.NodeHandler.HandleExit ( )

Handles the current 'exit' node by exiting the dialogue and triggering the onDialogueExited callback.

◆ HandleJump()

void EasyTalk.Controller.NodeHandler.HandleJump ( )

Handles the 'jump out' node by finding the associated 'jump in' node and moving to the next node after the 'jump in'.

◆ HandleOptionNode()

void EasyTalk.Controller.NodeHandler.HandleOptionNode ( )

Builds a List of DialogueOptions to present to the player based on the current 'option' node. This method handles 'option modifier' nodes and also deals with variable injection, translation, and tag extraction. Once the List of DialogueOptions is created, this method calls the onDisplayOptions callback so that the options can be used by anything registered with the delegate.

◆ HandlePathSelectorNode()

void EasyTalk.Controller.NodeHandler.HandlePathSelectorNode ( )

Evaluates the current 'path select' node to determine which path to continue down and the moves along that path.

◆ HandlePauseNode()

void EasyTalk.Controller.NodeHandler.HandlePauseNode ( )

Triggers the OnPause() callback on the Dialogue Listener and waits for a continue.

◆ HandleStoryNode()

void EasyTalk.Controller.NodeHandler.HandleStoryNode ( )

Triggers the OnStory() callback on the Dialogue Listener and waits for a continue.

◆ HandleWaitNode()

void EasyTalk.Controller.NodeHandler.HandleWaitNode ( )

Waits for the configured duration of the wait node currently being processed before continuing.

◆ Initialize()

void EasyTalk.Controller.NodeHandler.Initialize ( Dialogue dialogue)

Initializes the NodeHandler by setting the dialogue, clearing various mappings, determining the default 'entry' node, and creating variables.

Parameters
dialogueThe Dialogue to use.

◆ JumpToNodeAfterDelay()

IEnumerator EasyTalk.Controller.NodeHandler.JumpToNodeAfterDelay ( float delay,
Node node )

Jumps to the specified node after a certain amount of time.

Parameters
delayThe delay, in seconds.
nodeThe node to jump to.
Returns

◆ LoadVariableValues() [1/2]

void EasyTalk.Controller.NodeHandler.LoadVariableValues ( NodeVariableValueCollection valueCollection)

Loads the variable values from the specified NodeVariableValueCollection into the Dialogue.

Parameters
valueCollectionThe collection of node variable values to load.

◆ LoadVariableValues() [2/2]

void EasyTalk.Controller.NodeHandler.LoadVariableValues ( string prefix = "",
bool loadFromPlayerPrefs = false )

Loads the states of the Dialogue's variables from a save if available.

Parameters
prefixThe prefix to use when loading. This prefix is appended to the beginning of the dialogue name.
loadFromPlayerPrefsIf true, variable states will be loaded from PlayerPrefs rather than a JSON file.

◆ ProcessCurrentNode()

void EasyTalk.Controller.NodeHandler.ProcessCurrentNode ( )

Processes the current node, determining any dependent values used by the node and setting values as necessary on outputs. Once the node is processed, the next node will be determined and processed.

◆ ProcessNode()

void EasyTalk.Controller.NodeHandler.ProcessNode ( Node node)

Processes the node specified according to its type.

Parameters
nodeThe node to process.

◆ Propagate()

void EasyTalk.Controller.NodeHandler.Propagate ( Dictionary< int, object > nodeOutputValues,
Node node )
private

Evaluates the specified node to determine its output value based on its configuration and any incoming values that it depends upon, then pushes the evaluated final value to any nodes connected along the output value path.

Parameters
nodeOutputValuesA map of node IDs and connection IDs to the output values that those IDs correspond to.
nodeThe node to evaluate.

◆ ReplaceVariablesInString()

string EasyTalk.Controller.NodeHandler.ReplaceVariablesInString ( string text)

This method does variable value injection, replacing all variable references in the specified string with their associated values.

Parameters
textThe string to inject variable values into.
Returns
The modified string with variable references replaced by their respective values.

◆ ResetVariablesOnEntry()

void EasyTalk.Controller.NodeHandler.ResetVariablesOnEntry ( )

Resets the values of each variable which is set to "reset on entry".

◆ SaveVariableValues()

void EasyTalk.Controller.NodeHandler.SaveVariableValues ( string prefix = "",
bool saveToPlayerPrefs = false )

Saves the values of all variables in the Dialogue to either a file, or to the PlayerPrefs.

Parameters
prefixThe prefix to use when saving. This prefix is appended to the beginning of the dialogue name.
saveToPlayerPrefsWhether the variable states should be saved to PlayerPrefs. If set to false, the variable states will be saved to a JSON file instead.

◆ SetListener()

void EasyTalk.Controller.NodeHandler.SetListener ( DialogueListener listener)

Sets the Dialogue Listener which the node handler should send events to during Dialogue processing.

Parameters
listenerThe Dialogue Listener to use.

◆ SetVariableValue()

void EasyTalk.Controller.NodeHandler.SetVariableValue ( string variableName,
object variableValue )

Sets the value of the specified variable.

Parameters
variableNameThe name of the variable to set.
variableValueThe value to set on the variable.

◆ Translate() [1/2]

string EasyTalk.Controller.NodeHandler.Translate ( string text)

Performs a lookup in the active Translation Library for the text provided and returns a translation, if there is one. The text is attempted to be translated into whatever langauge is set on EasyTalkGameState.Instance.Language.

Parameters
textThe text to translate.
Returns
A translation of the provided text, if there is a match in the current Translation Library.

◆ Translate() [2/2]

string EasyTalk.Controller.NodeHandler.Translate ( string text,
out string preTranslationText )

Performs a lookup in the active Translation Library for the text provided and returns a translation, if there is one. The text is attempted to be translated into whatever langauge is set on EasyTalkGameState.Instance.Language. This method also sets the provided preTranslationText string to the string being translated, immediately prior to translation. The preTranslationText may differ from the originally provided text if the EasyTalkDialogueSettings.Instance.TranslationEvaluationMode is set to TRANSLATE_AFTER_VARIABLE_EVALUATION, since in that mode, all variable tags are replaced with their values prior to translation.

Parameters
textThe text to translate.
preTranslationTextA string to store the text value which was translated in. This value is the text which is ultimately translated and may differ from the provided text string.
Returns
A translation of the provided text, if there is a match in the current Translation Library.

◆ TranslateText()

string EasyTalk.Controller.NodeHandler.TranslateText ( string text)

Translates the specified string to a localized string using the TranslationLibrary of the Dialogue.

Parameters
textThe line of text to translate.
Returns
The translated text, if a translation is found that matches the text provided.

Member Data Documentation

◆ convoIdx

int EasyTalk.Controller.NodeHandler.convoIdx = 0
protected

The line index of the conversation when a 'conversation' node is being processed.

◆ currentNode

Node EasyTalk.Controller.NodeHandler.currentNode
protected

The current node being processed/displayed.

◆ dialogue

Dialogue EasyTalk.Controller.NodeHandler.dialogue
private

The dialogue to process.

◆ entryMap

Dictionary<string, Node> EasyTalk.Controller.NodeHandler.entryMap = new Dictionary<string, Node>()
protected

A mapping of entry IDs to the 'entry' nodes they belong to.

◆ entryNode

Node EasyTalk.Controller.NodeHandler.entryNode
protected

The default 'entry' node which is used if an entry ID is not provided, or the 'entry' node with the ID specified can't be found.

◆ inputIdToNodeMap

Dictionary<int, Node> EasyTalk.Controller.NodeHandler.inputIdToNodeMap = new Dictionary<int, Node>()
protected

A mapping of node input IDs to the nodes which those inputs belong to.

◆ jumpMap

Dictionary<string, Node> EasyTalk.Controller.NodeHandler.jumpMap = new Dictionary<string, Node>()
protected

A mapping of jump keys/IDs to the 'jump in' nodes they belong to.

◆ listener

DialogueListener EasyTalk.Controller.NodeHandler.listener
private

The Dialogue Listener to use for callbacks as events happen during dialogue processing.

◆ outputIdToNodeMap

Dictionary<int, Node> EasyTalk.Controller.NodeHandler.outputIdToNodeMap = new Dictionary<int, Node>()
protected

A mapping of node output IDs to the nodes which those inputs belong to.

◆ owner

GameObject EasyTalk.Controller.NodeHandler.owner = null
protected

The GameObject this NodeHandler is being used by.

◆ variables

Dictionary<string, NodeVariable> EasyTalk.Controller.NodeHandler.variables = new Dictionary<string, NodeVariable>()
protected

A mapping of variable names to their definitions and values.