Ejemplo n.º 1
0
        private void PrintExpressionDialogueNode(ExpressionDialogueNode pExpressionNode)
        {
            Indentation();

            _output.Append("Expression " + pExpressionNode.expression + "\n");

            DialogueNode nextNode = _dialogueRunner.GetDialogueNode(_conversation, pExpressionNode.nextNode);

            SwitchOnNode(nextNode);
        }
Ejemplo n.º 2
0
        private void PrintExpressionDialogueNode(ExpressionDialogueNode pExpressionNode)
        {
            Indentation();

            _output.Append("Expression " + pExpressionNode.expression + "\n");

            DialogueNode nextNode = _dialogueRunner.GetDialogueNode(_conversation, pExpressionNode.nextNode);
            SwitchOnNode(nextNode);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }