using EasyTalk.Controller;
using EasyTalk.Nodes.Core;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace EasyTalk.Nodes.Variable
{
///
/// A node which allows a variable value to be retrieved and passed into another node's value input.
///
[Serializable]
public class GetVariableNode : Node, DialogueFlowNode, FunctionalNode
{
///
/// The name of the variable to retrieve a value for.
///
[SerializeField]
private string variableName;
///
/// Creates a new GetVariableNode.
///
public GetVariableNode()
{
this.name = "GET VARIABLE";
this.nodeType = NodeType.GET_VARIABLE_VALUE;
}
///
/// Gets or sets the name of the variable this node retrieves the value of.
///
public string VariableName
{
get { return this.variableName; }
set { this.variableName = value; }
}
///
public bool DetermineAndStoreValue(NodeHandler nodeHandler, Dictionary nodeValues, GameObject convoOwner = null)
{
NodeVariable variable = nodeHandler.GetVariable(variableName);
if(variable != null)
{
NodeConnection valueConn = null;
if (variable.variableType == typeof(int))
{
valueConn = FindOutputOfType(InputOutputType.INT);
}
else if (variable.variableType == typeof(string))
{
valueConn = FindOutputOfType(InputOutputType.STRING);
}
else if (variable.variableType == typeof(float))
{
valueConn = FindOutputOfType(InputOutputType.FLOAT);
}
else if (variable.variableType == typeof(bool))
{
valueConn = FindOutputOfType(InputOutputType.BOOL);
}
if (valueConn != null)
{
nodeValues.TryAdd(valueConn.ID, variable.currentValue);
}
}
return true;
}
///
public List GetDependencyOutputIDs()
{
return FindDependencyOutputIDs();
}
///
public NodeConnection GetFlowInput()
{
return FindFlowInputs()[0];
}
///
public NodeConnection GetFlowOutput()
{
return FindFlowOutputs()[0];
}
///
public bool HasDependencies()
{
return FindDependencyOutputIDs().Count > 0;
}
}
}