Пример #1
0
    public Godot.Object MakeGDInkPath(Ink.Runtime.Path path)
    {
        var inkPath = (Godot.Object)InkPath.New();

        inkPath.Call("_init_with_components_string", path.componentsString);
        return(inkPath);
    }
Пример #2
0
        public void TestPaths()
        {
            // Different instances should ensure different instances of individual components
            var path1 = new Path("hello.1.world");
            var path2 = new Path("hello.1.world");

            var path3 = new Path(".hello.1.world");
            var path4 = new Path(".hello.1.world");

            Assert.AreEqual(path1, path2);

            Assert.AreEqual(path3, path4);

            Assert.AreNotEqual(path1, path3);
        }
Пример #3
0
        public void Begin()
        {
            EvaluateStory();

            var rand = new Random();

            while (story.currentChoices.Count > 0)
            {
                var choices = story.currentChoices;

                var          choiceIdx        = 0;
                bool         choiceIsValid    = false;
                Runtime.Path userDivertedPath = null;

                // autoPlay: Pick random choice
                if (autoPlay)
                {
                    choiceIdx = rand.Next() % choices.Count;
                }

                // Normal: Ask user for choice number
                else
                {
                    Console.ForegroundColor = ConsoleColor.Blue;

                    int i = 1;
                    foreach (Choice choice in choices)
                    {
                        Console.WriteLine("{0}: {1}", i, choice.text);
                        i++;
                    }


                    do
                    {
                        string userInput = Console.ReadLine();

                        var    inputParser    = new InkParser(userInput);
                        object evaluatedInput = inputParser.CommandLineUserInput();

                        // Choice
                        if (evaluatedInput is int?)
                        {
                            choiceIdx = ((int)evaluatedInput) - 1;

                            if (choiceIdx < 0 || choiceIdx >= choices.Count)
                            {
                                Console.WriteLine("Choice out of range");
                            }
                            else
                            {
                                choiceIsValid = true;
                            }
                        }

                        // Help
                        else if (evaluatedInput is string && (string)evaluatedInput == "help")
                        {
                            Console.WriteLine("Type a choice number, a divert (e.g. '==> myKnot'), an expression, or a variable assignment (e.g. 'x = 5')");
                        }

                        // User entered some ink
                        else if (evaluatedInput is Parsed.Object)
                        {
                            // Variable assignment: create in Parsed.Story as well as the Runtime.Story
                            // so that we don't get an error message during reference resolution
                            if (evaluatedInput is Parsed.VariableAssignment)
                            {
                                var varAssign = (Parsed.VariableAssignment)evaluatedInput;
                                if (varAssign.isNewTemporaryDeclaration)
                                {
                                    parsedStory.TryAddNewVariableDeclaration(varAssign);
                                }
                            }

                            var parsedObj = (Parsed.Object)evaluatedInput;
                            parsedObj.parent = parsedStory;
                            parsedObj.GenerateRuntimeObject();
                            parsedObj.ResolveReferences(parsedStory);
                            var runtimeObj = parsedObj.runtimeObject;

                            if (!parsedStory.hadError)
                            {
                                // Divert
                                if (evaluatedInput is Parsed.Divert)
                                {
                                    userDivertedPath = ((Parsed.Divert)evaluatedInput).runtimeDivert.targetPath;
                                }

                                // Expression or variable assignment
                                else if (evaluatedInput is Parsed.Expression || evaluatedInput is Parsed.VariableAssignment)
                                {
                                    var result = story.EvaluateExpression((Container)runtimeObj);
                                    if (result != null)
                                    {
                                        Console.WriteLine(result);
                                    }
                                }
                            }
                            else
                            {
                                parsedStory.ResetError();
                            }
                        }

                        else
                        {
                            Console.WriteLine("Unexpected input. Type 'help' or a choice number.");
                        }
                    } while(!choiceIsValid && userDivertedPath == null);
                }

                Console.ResetColor();

                if (choiceIsValid)
                {
                    story.ChooseChoiceIndex(choiceIdx);
                }
                else if (userDivertedPath != null)
                {
                    story.ChoosePath(userDivertedPath);
                    userDivertedPath = null;
                }

                EvaluateStory();
            }
        }
Пример #4
0
        public void Begin()
        {
            EvaluateStory();

            var rand = new Random();

            while (story.currentChoices.Count > 0 || this.keepOpenAfterStoryFinish)
            {
                var choices = story.currentChoices;

                var          choiceIdx        = 0;
                bool         choiceIsValid    = false;
                Runtime.Path userDivertedPath = null;

                // autoPlay: Pick random choice
                if (autoPlay)
                {
                    choiceIdx = rand.Next() % choices.Count;
                }

                // Normal: Ask user for choice number
                else
                {
                    Console.ForegroundColor = ConsoleColor.Blue;

                    // Add extra newline to ensure that the choice is
                    // on a separate line.
                    Console.WriteLine();

                    int i = 1;
                    foreach (Choice choice in choices)
                    {
                        Console.WriteLine("{0}: {1}", i, choice.text);
                        i++;
                    }


                    do
                    {
                        // Prompt
                        Console.Write("?> ");
                        string userInput = Console.ReadLine();

                        // If we have null user input, it means that we're
                        // "at the end of the stream", or in other words, the input
                        // stream has closed, so there's nothing more we can do.
                        // We return immediately, since otherwise we get into a busy
                        // loop waiting for user input.
                        if (userInput == null)
                        {
                            Console.WriteLine("<User input stream closed.>");
                            return;
                        }

                        var inputParser = new InkParser(userInput);
                        var input       = inputParser.CommandLineUserInput();

                        // Choice
                        if (input.choiceInput != null)
                        {
                            choiceIdx = ((int)input.choiceInput) - 1;

                            if (choiceIdx < 0 || choiceIdx >= choices.Count)
                            {
                                Console.WriteLine("Choice out of range");
                            }
                            else
                            {
                                choiceIsValid = true;
                            }
                        }

                        // Help
                        else if (input.isHelp)
                        {
                            Console.WriteLine("Type a choice number, a divert (e.g. '-> myKnot'), an expression, or a variable assignment (e.g. 'x = 5')");
                        }

                        // Quit
                        else if (input.isExit)
                        {
                            return;
                        }

                        // Request for debug source line number
                        else if (input.debugSource != null)
                        {
                            var offset = (int)input.debugSource;
                            var dm     = DebugMetadataForContentAtOffset(offset);
                            if (dm != null)
                            {
                                Console.WriteLine("DebugSource: " + dm.ToString());
                            }
                            else
                            {
                                Console.WriteLine("DebugSource: Unknown source");
                            }
                        }

                        // User entered some ink
                        else if (input.userImmediateModeStatement != null)
                        {
                            var parsedObj = input.userImmediateModeStatement as Parsed.Object;

                            // Variable assignment: create in Parsed.Story as well as the Runtime.Story
                            // so that we don't get an error message during reference resolution
                            if (parsedObj is Parsed.VariableAssignment)
                            {
                                var varAssign = (Parsed.VariableAssignment)parsedObj;
                                if (varAssign.isNewTemporaryDeclaration)
                                {
                                    parsedStory.TryAddNewVariableDeclaration(varAssign);
                                }
                            }

                            parsedObj.parent = parsedStory;
                            var runtimeObj = parsedObj.runtimeObject;

                            parsedObj.ResolveReferences(parsedStory);

                            if (!parsedStory.hadError)
                            {
                                // Divert
                                if (parsedObj is Parsed.Divert)
                                {
                                    var parsedDivert = parsedObj as Parsed.Divert;
                                    userDivertedPath = parsedDivert.runtimeDivert.targetPath;
                                }

                                // Expression or variable assignment
                                else if (parsedObj is Parsed.Expression || parsedObj is Parsed.VariableAssignment)
                                {
                                    var result = story.EvaluateExpression((Container)runtimeObj);
                                    if (result != null)
                                    {
                                        Console.WriteLine(result.ToString());
                                    }
                                }
                            }
                            else
                            {
                                parsedStory.ResetError();
                            }
                        }

                        else
                        {
                            Console.WriteLine("Unexpected input. Type 'help' or a choice number.");
                        }
                    } while(!choiceIsValid && userDivertedPath == null);
                }

                Console.ResetColor();

                if (choiceIsValid)
                {
                    story.ChooseChoiceIndex(choiceIdx);
                }
                else if (userDivertedPath != null)
                {
                    story.ChoosePath(userDivertedPath);
                    userDivertedPath = null;
                }

                EvaluateStory();
            }
        }