0
I created a dialogue creation language for a game, but at the stage where I analyze recursion, it is always generated incorrectly.
The syntax looks like this:
Chance(Num);Relation(Num);Reputation(Num):Dialog>Option0[RelationInc,ReputationInc],...
And to add the recursion, the character '>' is used before any other, as >Chance;Relation;Reputation:Dialog>Option[bla,bla]...
and so on.
In my code, I can capture the number of '>' before each snippet, format the string and process it to have a dialog item, but when checking the recursion, it is erroneous.
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 someone tell me some way to make it functional?
How does the expression work for you? It could indicate a step-by-step of how it is executed and also indicate where the problem is in the step-by-step created?
– CypherPotato
Add a sample txt and the processLine() and compileItem methods()
– Leandro Angelo
Fortunately, after several hours, I discovered the solution through the old thinking and deduction, but I will provide the method I used to achieve, since I can not close the topic.
– DiaDeTedio