I created a dialog language for a game, but in the step where I analyze the recursion, it is always generated incorrectly.
The syntax looks like this:
Chance(Num);Relation(Num);Reputation(Num):Dialog>Option0[RelationInc,ReputationInc],...
And to add recursion, the character '>' before any other, such as >Chance;Relation;Reputation:Dialog>Option[bla,bla]...
, and so on.
In my code, I can pick up the number of '>' before each section, format the string and process it to have a dialog item, but when checking the recursion, it gets wrong.
Current Code:
public Dialog Compile(string source,string id)
{
Dialog handler = new Dialog(id);
List<DialogItem> controls = new List<DialogItem>();
source = source.Replace("\r","");
string[] lines = source.Split('\n');
int curDepth = -1;
foreach(var ln in lines)
{
string line = ln;
int depth;
bool global = processLine(ref line,out depth);
var dialog = compileItem(line);
dialog.Depth = depth;
dialog.IsGlobal = global;
//Begin
if(global)
{
handler.Items.Add(dialog);
}
bool isParent = global || depth > curDepth;
bool isDown = depth < curDepth;
bool changed = false;
if(isParent && !isDown)
{
controls.Add(dialog);
changed = true;
}
if(isDown)
{
if(curDepth > -1 && curDepth < controls.Count)
{
controls.RemoveAt(curDepth);
}
curDepth = depth;
}
if(curDepth > -1 && curDepth != depth)
{
controls[curDepth].Childs.Add(dialog);
}
if(changed)curDepth = depth;
//End
}
return handler;
}
Could anyone tell me some way to make it functional?