Пример #1
0
        // for the shortcut options
        // (-> line of text <<if expression>> indent statements dedent)+
        public override int VisitShortcut_statement(YarnSpinnerParser.Shortcut_statementContext context)
        {
            string endOfGroupLabel = compiler.RegisterLabel("group_end");

            var labels = new List <string>();

            int optionCount = 0;

            foreach (var shortcut in context.shortcut())
            {
                string optionDestinationLabel = compiler.RegisterLabel("option_" + (optionCount + 1));
                labels.Add(optionDestinationLabel);

                string endOfClauseLabel = null;
                if (shortcut.shortcut_conditional() != null)
                {
                    endOfClauseLabel = compiler.RegisterLabel("conditional_" + optionCount);

                    Visit(shortcut.shortcut_conditional().expression());

                    compiler.Emit(ByteCode.JumpIfFalse, endOfClauseLabel);
                }

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

                string shortcutLine  = ShortcutText(shortcut.shortcut_text());
                string labelStringID = compiler.program.RegisterString(shortcutLine, compiler.currentNode.name, lineID, shortcut.Start.Line, true);

                compiler.Emit(ByteCode.AddOption, labelStringID, optionDestinationLabel);

                if (shortcut.shortcut_conditional() != null)
                {
                    compiler.Emit(ByteCode.Label, endOfClauseLabel);
                    compiler.Emit(ByteCode.Pop);
                }
                optionCount++;
            }

            compiler.Emit(ByteCode.ShowOptions);

            // TODO: investigate a cleaner way because this is odd...
            if (compiler.flags.DisableShuffleOptionsAfterNextSet == true)
            {
                compiler.Emit(ByteCode.PushBool, false);
                compiler.Emit(ByteCode.StoreVariable, VirtualMachine.SpecialVariables.ShuffleOptions);
                compiler.Emit(ByteCode.Pop);
                compiler.flags.DisableShuffleOptionsAfterNextSet = false;
            }

            compiler.Emit(ByteCode.Jump);

            optionCount = 0;
            foreach (var shortcut in context.shortcut())
            {
                compiler.Emit(ByteCode.Label, labels[optionCount]);

                // running through all the children statements of the shortcut
                foreach (var child in shortcut.statement())
                {
                    Visit(child);
                }

                compiler.Emit(ByteCode.JumpTo, endOfGroupLabel);

                optionCount++;
            }

            compiler.Emit(ByteCode.Label, endOfGroupLabel);
            compiler.Emit(ByteCode.Pop);

            return(0);
        }
 /// <summary>
 /// Visit a parse tree produced by <see cref="YarnSpinnerParser.shortcut_statement"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitShortcut_statement([NotNull] YarnSpinnerParser.Shortcut_statementContext context)
 {
     return(VisitChildren(context));
 }
Пример #3
0
        // for the shortcut options
        // (-> line of text <<if expression>> indent statements dedent)+
        public override int VisitShortcut_statement(YarnSpinnerParser.Shortcut_statementContext context)
        {
            string endOfGroupLabel = compiler.RegisterLabel("group_end");

            var labels = new List <string>();

            int optionCount = 0;

            foreach (var shortcut in context.shortcut())
            {
                string optionDestinationLabel = compiler.RegisterLabel("option_" + (optionCount + 1));
                labels.Add(optionDestinationLabel);

                string endOfClauseLabel = null;
                if (shortcut.shortcut_conditional() != null)
                {
                    endOfClauseLabel = compiler.RegisterLabel("conditional_" + optionCount);

                    Visit(shortcut.shortcut_conditional().expression());

                    compiler.Emit(OpCode.JumpIfFalse, new Operand(endOfClauseLabel));
                }

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

                string shortcutLine  = ShortcutText(shortcut.shortcut_text());
                string labelStringID = compiler.RegisterString(shortcutLine, compiler.currentNode.Name, lineID, shortcut.Start.Line);

                compiler.Emit(OpCode.AddOption, new Operand(labelStringID), new Operand(optionDestinationLabel));

                if (shortcut.shortcut_conditional() != null)
                {
                    compiler.currentNode.Labels.Add(endOfClauseLabel, compiler.currentNode.Instructions.Count);
                    compiler.Emit(OpCode.Pop);
                }
                optionCount++;
            }

            compiler.Emit(OpCode.ShowOptions);

            compiler.Emit(OpCode.Jump);

            optionCount = 0;
            foreach (var shortcut in context.shortcut())
            {
                compiler.currentNode.Labels.Add(labels[optionCount], compiler.currentNode.Instructions.Count);

                // running through all the children statements of the shortcut
                foreach (var child in shortcut.statement())
                {
                    Visit(child);
                }

                compiler.Emit(OpCode.JumpTo, new Operand(endOfGroupLabel));

                optionCount++;
            }

            compiler.currentNode.Labels.Add(endOfGroupLabel, compiler.currentNode.Instructions.Count);
            compiler.Emit(OpCode.Pop);

            return(0);
        }
Пример #4
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="YarnSpinnerParser.shortcut_statement"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitShortcut_statement([NotNull] YarnSpinnerParser.Shortcut_statementContext context)
 {
 }