Beispiel #1
0
        // A <<jump>> command, which immediately jumps to another node, given
        // its name.
        public override int VisitJumpToNodeName([NotNull] YarnSpinnerParser.JumpToNodeNameContext context)
        {
            if (trackingEnabled != null)
            {
                GenerateTrackingCode(trackingEnabled);
            }
            compiler.Emit(OpCode.PushString, context.destination, new Operand(context.destination.Text));
            compiler.Emit(OpCode.RunNode, context.Start);

            return(0);
        }
Beispiel #2
0
        // really ought to make this emit like a list of opcodes actually
        public static void GenerateTrackingCode(Compiler compiler, string variableName)
        {
            // pushing the var and the increment onto the stack
            compiler.Emit(OpCode.PushVariable, new Operand(variableName));
            compiler.Emit(OpCode.PushFloat, new Operand(1));

            // Indicate that we are pushing this many items for comparison
            compiler.Emit(OpCode.PushFloat, new Operand(2));

            // calling the function
            compiler.Emit(OpCode.CallFunc, new Operand("Number.Add"));

            // now store the variable and clean up the stack
            compiler.Emit(OpCode.StoreVariable, new Operand(variableName));
            compiler.Emit(OpCode.Pop);
        }
Beispiel #3
0
        // a regular ol' line of text
        public override int VisitLine_statement(YarnSpinnerParser.Line_statementContext context)
        {
            // TODO: add support for line conditions:
            //
            // Mae: here's a line <<if true>>
            //
            // is identical to
            //
            // <<if true>>
            // Mae: here's a line
            // <<endif>>

            // Convert the formatted string into a string with
            // placeholders, and evaluate the inline expressions and push
            // the results onto the stack.
            GenerateFormattedText(context.line_formatted_text().children, out var composedString, out var expressionCount);

            // Get the lineID for this string from the hashtags if it has one; otherwise, a new one will be created
            string lineID = compiler.GetLineID(context.hashtag());

            var hashtagText = GetHashtagTexts(context.hashtag());

            int lineNumber = context.Start.Line;

            string stringID = compiler.RegisterString(
                composedString.ToString(),
                compiler.CurrentNode.Name,
                lineID,
                lineNumber,
                hashtagText);

            compiler.Emit(OpCode.RunLine, new Operand(stringID), new Operand(expressionCount));

            return(0);
        }
Beispiel #4
0
        // a regular ol' line of text
        public override int VisitLine_statement(YarnSpinnerParser.Line_statementContext context)
        {
            // grabbing the line of text and stripping off any "'s if they had them
            string lineText = context.text().GetText().Trim('"');

            // getting the lineID from the hashtags if it has one
            string lineID = compiler.GetLineID(context.hashtag_block());

            // technically this only gets the line the statement started on
            int lineNumber = context.Start.Line;

            string stringID = compiler.RegisterString(lineText, compiler.currentNode.Name, lineID, lineNumber);

            compiler.Emit(OpCode.RunLine, new Operand(stringID));

            return(0);
        }
        // a regular ol' line of text
        public override int VisitLine_statement(YarnSpinnerParser.Line_statementContext context)
        {
            // TODO: add support for line conditions:
            //
            // Mae: here's a line <<if true>>
            //
            // is identical to
            //
            // <<if true>> Mae: here's a line <<endif>>

            // Evaluate the inline expressions and push the results onto
            // the stack.
            var expressionCount = GenerateCodeForExpressionsInFormattedText(context.line_formatted_text().children);

            // Get the lineID for this string from the hashtags
            string lineID = Compiler.GetLineID(context.hashtag());

            if (lineID == null)
            {
                throw new ParseException("No line ID specified");
            }

            compiler.Emit(OpCode.RunLine, new Operand(lineID), new Operand(expressionCount));

            return(0);
        }