Code: Select all
public struct Choice
{
public string result;
public string nextBranch;
}
public struct Branch
{
public Dictionary choices;
}
public class ChoiceTree
{
public Dictionary branches;
// some other properties
// some methods
}
Code: Select all
branches:
- Key: "main1"
Value:
choices:
- Key: "few minutes"
Value:
result: "S"
nextBranch: "refuse"
- Key: "hold on"
Value:
result: "D"
nextBranch: "refuse"
- Key: "of course"
Value:
result: "LS"
nextBranch: "accept"
- Key: "fine"
Value:
result: "HD"
nextBranch: "accept"
- Key: "refuse"
Value:
- Key: "reluctant"
Value:
choices:
result: "HH"
nextBranch: "accept"
- Key: "happily"
Value:
choices:
result: "L"
nextBranch: "accept"
Code: Select all
public class YamlChoiceTreeeParser
{
public YamlChoiceTreeeParser(string filePath)
{
if (!File.Exists(filePath))
{
throw new Exception("YAML file not found");
}
using (StreamReader sr = new StreamReader(filePath))
{
var deserializer = new DeserializerBuilder()
.Build();
var choiceTree = deserializer.Deserialize(sr);
}
}
}
Mobile version