using EasyTalk.Controller;
using EasyTalk.Nodes.Core;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace EasyTalk.Nodes.Logic
{
///
/// A node used to dynamically build a string during dialgoue playback.
///
[Serializable]
public class BuildStringNode : ListNode, DialogueFlowNode, FunctionalNode
{
///
/// Creates a new BuildStringNode.
///
public BuildStringNode()
{
this.name = "BUILD STRING";
this.nodeType = NodeType.BUILD_STRING;
}
///
public bool DetermineAndStoreValue(NodeHandler nodeHandler, Dictionary nodeValues, GameObject convoOwner = null)
{
string value = "";
for(int i = 0; i < items.Count; i++)
{
if (Inputs[i+1].AttachedIDs.Count > 0)
{
object inputValue = nodeValues[Inputs[i + 1].AttachedIDs[0]];
if (inputValue != null)
{
value += inputValue.ToString();
}
}
else
{
string itemText = ((StringItem)items[i]).text;
//itemText = nodeHandler.TranslateText(itemText);
itemText = nodeHandler.ReplaceVariablesInString(itemText);
if (itemText != null)
{
value += itemText;
}
}
}
NodeConnection stringOutput = FindOutputOfType(InputOutputType.STRING);
nodeValues.TryAdd(stringOutput.ID, value);
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;
}
}
///
/// A string value item used in the 'build string' type node.
///
[Serializable]
public class StringItem : ListItem
{
///
/// The text of the string.
///
[SerializeField]
public string text;
///
/// Creates a new StringItem.
///
public StringItem() { }
///
/// Creates a new StringItem with the specified value.
///
/// The string value.
public StringItem(string text)
{
this.text = text;
}
}
}