Example #1
0
        // executes a node, and returns either the name of the next node to run
        // or null (indicating the dialogue is over)
        internal IEnumerable <Dialogue.RunnerResult> RunNode(Yarn.Parser.Node node)
        {
            // Clear the list of options when we start a new node
            currentOptions = new List <Parser.OptionStatement> ();

            // Run all of the statements in this node
            foreach (var command in RunStatements(node.statements))
            {
                yield return(command);
            }

            // If we have no options, we're all done
            if (currentOptions.Count == 0)
            {
                yield return(new Dialogue.NodeCompleteResult(null));

                yield break;
            }
            else
            {
                // We have options!

                // If we have precisely one option and it's got no label, jump to it
                if (currentOptions.Count == 1 &&
                    currentOptions[0].label == null)
                {
                    yield return(new Dialogue.NodeCompleteResult(currentOptions [0].destination));

                    yield break;
                }

                // Otherwise, ask which option to pick...
                var optionStrings = new List <string> ();
                foreach (var option in currentOptions)
                {
                    var label = option.label ?? option.destination;
                    optionStrings.Add(label);
                }

                Parser.OptionStatement selectedOption = null;

                yield return(new Dialogue.OptionSetResult(optionStrings, delegate(int selectedOptionIndex) {
                    selectedOption = currentOptions[selectedOptionIndex];
                }));

                if (selectedOption == null)
                {
                    dialogue.LogErrorMessage("Option chooser was never called!");
                    yield break;
                }

                // And jump to its destination!
                yield return(new Dialogue.NodeCompleteResult(selectedOption.destination));
            }
            yield break;
        }
Example #2
0
        void GenerateCode(Node node, Parser.OptionStatement statement)
        {
            if (statement.label == null)
            {
                // this is a jump to another node
                Emit(node, ByteCode.RunNode, statement.destination);
            }
            else
            {
                var stringID = program.RegisterString(statement.label);

                Emit(node, ByteCode.AddOption, stringID, statement.destination);
            }
        }
Example #3
0
        void GenerateCode(Node node, Parser.OptionStatement statement)
        {
            var destination = statement.destination;

            if (statement.label == null)
            {
                // this is a jump to another node
                Emit(node, ByteCode.RunNode, destination);
            }
            else
            {
                var lineID = GetLineIDFromNodeTags(statement.parent);

                var stringID = program.RegisterString(statement.label, node.name, lineID, statement.lineNumber, true);

                Emit(node, ByteCode.AddOption, stringID, destination);
            }
        }