private DialogueNode VisitLoopDialogueNode(DialogueNode pPrevious) { #if DEBUG_WRITE Console.WriteLine("VisitLoopDialogueNode()"); #endif match(Token.TokenType.LOOP); LoopDialogueNode n = _dialogueRunner.Create <LoopDialogueNode>(_conversationName, _language, (_nodeCounter++).ToString() + " (loop)"); AddLinkFromPreviousNode(pPrevious, n); //ImmediateNode finalNode = _dialogueRunner.Create<ImmediateNode>(_conversationName, _language, (_nodeCounter++).ToString() + "(final node)"); //n.nextNode = finalNode.name; AllowLineBreak(); _loopStack.Push(n); match(Token.TokenType.BLOCK_BEGIN); ImmediateNode branchStartNode = _dialogueRunner.Create <ImmediateNode>(_conversationName, _language, (_nodeCounter++).ToString() + " (loop branch node)"); n.branchNode = branchStartNode.name; SilentDialogueNode unifiedEndNode = _dialogueRunner.Create <SilentDialogueNode>(_conversationName, _language, (_nodeCounter++).ToString() + " (unified end node for loop)"); Nodes(branchStartNode, unifiedEndNode); match(Token.TokenType.BLOCK_END); _loopStack.Pop(); return(n); }
private void PrintImmediateNode(ImmediateNode pImmediateNode) { Indentation(); _output.Append(pImmediateNode.name + "\n"); DialogueNode nextNode = _dialogueRunner.GetDialogueNode(_conversation, pImmediateNode.nextNode); SwitchOnNode(nextNode); }
private DialogueNode VisitEmptyNodeWithName(DialogueNode pPreviousNode) { match(Token.TokenType.BRACKET_LEFT); string nodeCustomName = match(Token.TokenType.NAME).getTokenString(); ImmediateNode n = _dialogueRunner.Create <ImmediateNode>(_conversationName, _language, (_nodeCounter++).ToString()); n.name = nodeCustomName; match(Token.TokenType.BRACKET_RIGHT); AddLinkFromPreviousNode(pPreviousNode, n); return(n); }
private DialogueNode VisitIfDialogueNode(DialogueNode pPrevious) { #if DEBUG_WRITE Console.WriteLine("IfDialogueNode()"); #endif match(Token.TokenType.IF); string expressionName = ""; string[] args = VisitFunctionCall(out expressionName); AllowLineBreak(); match(Token.TokenType.BLOCK_BEGIN); UnifiedEndNodeForScope unifiedEndNode = _dialogueRunner.Create <UnifiedEndNodeForScope>(_conversationName, _language, (_nodeCounter++) + " (unified end of if)"); ExpressionDialogueNode ifTrue = _dialogueRunner.Create <ExpressionDialogueNode>(_conversationName, _language, (_nodeCounter++) + " (if true)"); Nodes(ifTrue, unifiedEndNode); ifTrue.expression = expressionName; ifTrue.args = args; #if DEBUG_WRITE Console.WriteLine("Added IfTrue node with expression '" + ifTrue.expression + "'"); #endif match(Token.TokenType.BLOCK_END); AllowLineBreak(); ImmediateNode ifFalse = null; List <ExpressionDialogueNode> elifNodes = new List <ExpressionDialogueNode>(); while (lookAheadType(1) == Token.TokenType.ELIF) { match(Token.TokenType.ELIF); string elifExpressionName = ""; string[] elifArgs = VisitFunctionCall(out elifExpressionName); AllowLineBreak(); match(Token.TokenType.BLOCK_BEGIN); ExpressionDialogueNode elifNode = _dialogueRunner.Create <ExpressionDialogueNode>(_conversationName, _language, (_nodeCounter++) + " (elif)"); Nodes(elifNode, unifiedEndNode); elifNode.expression = elifExpressionName; elifNode.args = elifArgs; elifNodes.Add(elifNode); #if DEBUG_WRITE Console.WriteLine("Added Elif node with expression '" + elifNode.expression + "'"); #endif match(Token.TokenType.BLOCK_END); AllowLineBreak(); } if (lookAheadType(1) == Token.TokenType.ELSE) { match(Token.TokenType.ELSE); AllowLineBreak(); match(Token.TokenType.BLOCK_BEGIN); ifFalse = _dialogueRunner.Create <ImmediateNode>(_conversationName, _language, (_nodeCounter++) + " (if false)"); Nodes(ifFalse, unifiedEndNode); match(Token.TokenType.BLOCK_END); } IfDialogueNode ifNode = _dialogueRunner.Create <IfDialogueNode>(_conversationName, _language, (_nodeCounter++) + " (if)"); #if DEBUG_WRITE Console.WriteLine("Added IfDialogueNode() with name '" + ifNode.name + "'"); //foreach(DialogueNode elif in elifNodes) { // Console.WriteLine("Added ElifDialogueNode() with name '" + elif.name + "'"); //} #endif AddLinkFromPreviousNode(pPrevious, ifNode); ifNode.nextNode = unifiedEndNode.name; ifNode.ifTrueNode = ifTrue; ifNode.elifNodes = elifNodes.ToArray(); if (ifFalse != null) { ifNode.ifFalseNode = ifFalse; } else { ifNode.ifFalseNode = null; } if (!_dialogueRunner.HasExpression(expressionName)) { //throw new GrimmException("There is no '" + expressionName + "' expression registered in the dialogue runner"); } return(unifiedEndNode); }
private WaitDialogueNode VisitWaitDialogueNode(DialogueNode pPrevious) { #if DEBUG_WRITE Console.WriteLine("WaitDialogueNode()"); #endif match(Token.TokenType.WAIT); WaitDialogueNode n = _dialogueRunner.Create <WaitDialogueNode>(_conversationName, _language, (_nodeCounter++) + " (start commando)"); List <ExpressionDialogueNode> expressionNodes = new List <ExpressionDialogueNode>(); bool hasEventListener = false; while (true) { if (lookAheadType(1) == Token.TokenType.NAME) { string expressionName = ""; string[] args = VisitFunctionCall(out expressionName); ExpressionDialogueNode expressionNode = _dialogueRunner.Create <ExpressionDialogueNode>(_conversationName, _language, (_nodeCounter++) + " (expression)"); expressionNode.expression = expressionName; expressionNode.args = args; expressionNodes.Add(expressionNode); } else if (lookAheadType(1) == Token.TokenType.AND) { ConsumeCurrentToken(); } else if (lookAheadType(1) == Token.TokenType.LISTEN) { if (hasEventListener) { throw new GrimmException(_conversationName + " already has a event listener attached to the wait statement on line " + lookAhead(1).LineNr); } ConsumeCurrentToken(); n.eventName = match(Token.TokenType.NAME).getTokenString(); hasEventListener = true; #if DEBUG_WRITE Console.WriteLine("This WaitDialogueNode has an event called " + n.eventName); #endif } else { break; } } n.expressions = expressionNodes.ToArray(); string handleName = ""; if (lookAheadType(1) == Token.TokenType.BRACKET_LEFT) { match(Token.TokenType.BRACKET_LEFT); Token handleToken = match(Token.TokenType.NAME); handleName = handleToken.getTokenString(); match(Token.TokenType.BRACKET_RIGHT); } n.handle = handleName; if (_loopStack.Count > 0) { // Add this listening dialogue node to the scope of the loop so that it is automatically removed when the loop ends n.scopeNode = _loopStack.Peek().name; } #if DEBUG_WRITE Console.WriteLine("Added WaitDialogueNode() with name '" + n.name + "'"); #endif //if(!_dialogueRunner.HasExpression(expressionName)) { //throw new GrimmException("There is no '" + expressionName + "' expression registered in the dialogue runner"); //} SilentDialogueNode silentEndNode = _dialogueRunner.Create <SilentDialogueNode>(_conversationName, _language, (_nodeCounter++).ToString() + "(silent stop node)"); AllowLineBreak(); if (lookAheadType(1) == Token.TokenType.BLOCK_BEGIN) { _loopStack.Push(n); ImmediateNode eventBranchStartNode = _dialogueRunner.Create <ImmediateNode>(_conversationName, _language, (_nodeCounter++).ToString() + "(waitBranchStartNode)"); n.branchNode = eventBranchStartNode.name; n.hasBranch = true; match(Token.TokenType.BLOCK_BEGIN); Nodes(eventBranchStartNode, silentEndNode); match(Token.TokenType.BLOCK_END); _loopStack.Pop(); } else { #if DEBUG_WRITE Console.WriteLine("this wait dialogue node had no body"); #endif } AddLinkFromPreviousNode(pPrevious, n); return(n); }
DialogueNode VisitListeningDialogueNode(DialogueNode pPrevious) { #if DEBUG_WRITE Console.WriteLine("VisitListeningDialogueNode()"); #endif match(Token.TokenType.LISTEN); string eventName = GetAStringFromNextToken(false, false); string handleName = ""; if (lookAheadType(1) == Token.TokenType.BRACKET_LEFT) { match(Token.TokenType.BRACKET_LEFT); Token handleToken = match(Token.TokenType.NAME); handleName = handleToken.getTokenString(); match(Token.TokenType.BRACKET_RIGHT); } else if ( (lookAheadType(1) != Token.TokenType.EOF) && (lookAheadType(1) != Token.TokenType.NEW_LINE) && (lookAheadType(1) != Token.TokenType.BLOCK_BEGIN)) { throw new GrimmException("Can't follow LISTEN statement with token of type " + lookAheadType(1) + " at line " + lookAhead(1).LineNr + " and position " + lookAhead(1).LinePosition + " in " + _conversationName); } ListeningDialogueNode n = _dialogueRunner.Create <ListeningDialogueNode>(_conversationName, _language, (_nodeCounter++).ToString() + "(event listener)"); n.eventName = eventName; n.handle = handleName; if (_loopStack.Count > 0) { // Add this listening dialogue node to the scope of the loop so that it is automatically removed as a listener when the loop ends n.scopeNode = _loopStack.Peek().name; } SilentDialogueNode silentNode = _dialogueRunner.Create <SilentDialogueNode>(_conversationName, _language, (_nodeCounter++).ToString() + "(silent stop node)"); AllowLineBreak(); if (lookAheadType(1) == Token.TokenType.BLOCK_BEGIN) { _loopStack.Push(n); ImmediateNode eventBranchStartNode = _dialogueRunner.Create <ImmediateNode>(_conversationName, _language, (_nodeCounter++).ToString() + "(eventBranchStartNode)"); n.branchNode = eventBranchStartNode.name; n.hasBranch = true; match(Token.TokenType.BLOCK_BEGIN); Nodes(eventBranchStartNode, silentNode); match(Token.TokenType.BLOCK_END); _loopStack.Pop(); } else { #if DEBUG_WRITE Console.WriteLine("this listening dialogue node had no body"); #endif } AddLinkFromPreviousNode(pPrevious, n); return(n); }