using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
namespace Ichni.Story
{
public class DialogSentence
{
public string content;
public string audioEventName;
public string characterName;
public DialogSentence()
{
}
public DialogSentence(string content, string audioEventName, string characterName)
{
this.content = content;
this.audioEventName = audioEventName;
this.characterName = characterName;
}
///
/// 匹配{@FUNCTION},解析函数并返回解析后的语句内容。
///
public string GetInterpretedContent()
{
List parts = new List();
Regex regex = new Regex(@"\{\@.*?\}");
int lastIndex = 0;
foreach (Match match in regex.Matches(content))
{
if (match.Index > lastIndex)
{
parts.Add(content.Substring(lastIndex, match.Index - lastIndex));
}
parts.Add(match.Value);
lastIndex = match.Index + match.Length;
}
if (lastIndex < content.Length)
{
parts.Add(content.Substring(lastIndex));
}
for (int i = 0; i < parts.Count; i++)
{
if (parts[i].StartsWith("{@") && parts[i].EndsWith("}"))
{
string expression = parts[i].Substring(2, parts[i].Length - 3);
object result = StoryInterpreters.FunctionInterpreter.Eval(expression);
parts[i] = result.ToString();
}
}
return string.Join("", parts);
}
}
public class ChoiceGroup
{
public string choiceName;
public List choices;
public ChoiceGroup(string choiceName)
{
this.choiceName = choiceName;
this.choices = new List();
}
}
public class Choice
{
public string choiceText;
public string nextDialogName;
public Choice(string choiceText, string nextDialogName)
{
this.choiceText = choiceText;
this.nextDialogName = nextDialogName;
}
}
public class Condition
{
public string conditionSentence;
public string nextDialogName;
public bool GetConditionResult()
{
bool result = StoryInterpreters.ConditionInterpreter.Eval(conditionSentence);
return result;
}
}
public class DialogCharacter
{
public string name;
public string title;
public Dictionary emotions;
}
}