Пример #1
0
        public void InstantiateDialoguesFromDatabase()
        {
            {
                RelayTwo relay = new RelayTwo();
                relay.CreateTable(DialogueNode.TABLE_NAME);
                DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH);

                TimedDialogueNode d1 = runner.Create <TimedDialogueNode>("c", Language.SWEDISH, "d1") as TimedDialogueNode;
                d1.speaker = "A";

                TimedDialogueNode d2 = runner.Create <TimedDialogueNode>("c", Language.SWEDISH, "d2");
                d2.speaker = "B";

                relay.SaveAll("conversation.xml");
            }

            {
                RelayTwo relay = new RelayTwo();
                relay.LoadAll("conversation.xml");
                DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH);

                TimedDialogueNode d1 = runner.GetDialogueNode("c", "d1") as TimedDialogueNode;
                TimedDialogueNode d2 = runner.GetDialogueNode("c", "d2") as TimedDialogueNode;

                Assert.AreEqual("A", d1.speaker);
                Assert.AreEqual("B", d2.speaker);
            }
        }
Пример #2
0
        public void InstantiateDialoguesFromDatabase()
        {
            {
                RelayTwo relay = new RelayTwo();
                relay.CreateTable(DialogueNode.TABLE_NAME);
                DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH);

                TimedDialogueNode d1 = runner.Create<TimedDialogueNode>("c", Language.SWEDISH, "d1") as TimedDialogueNode;
                d1.speaker = "A";

                TimedDialogueNode d2 = runner.Create<TimedDialogueNode>("c", Language.SWEDISH, "d2");
                d2.speaker = "B";

                relay.SaveAll("conversation.xml");
            }

            {
                RelayTwo relay = new RelayTwo();
                relay.LoadAll("conversation.xml");
                DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH);

                TimedDialogueNode d1 = runner.GetDialogueNode("c", "d1") as TimedDialogueNode;
                TimedDialogueNode d2 = runner.GetDialogueNode("c", "d2") as TimedDialogueNode;

                Assert.AreEqual("A", d1.speaker);
                Assert.AreEqual("B", d2.speaker);
            }
        }
Пример #3
0
        static void RunDialogue()
        {
            string conversationName = "meeting"; // "PixieMeeting1";

            RelayTwo relay;
            DialogueRunner dialogueRunner;

            relay = new RelayTwo();
            relay.CreateTable(DialogueNode.TABLE_NAME);

            dialogueRunner = new DialogueRunner(relay, Language.DEFAULT);
            dialogueRunner.AddExpression("CoinFlip", CoinFlip);
            dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSpeech);
            dialogueRunner.logger.AddListener(Log);

            DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner);
            scriptLoader.LoadDialogueNodesFromFile(conversationName + ".dia");

            DialogueScriptPrinter printer = new DialogueScriptPrinter(dialogueRunner);
            printer.PrintConversation(conversationName);

            Console.WriteLine(" - " + conversationName + " - ");
            dialogueRunner.StartConversation(conversationName);

            while(dialogueRunner.ConversationIsRunning(conversationName))
            {
                //printer.PrintConversation(conversationName);

                dialogueRunner.Update(1.0f);
                DialogueNode activeDialogueNode = dialogueRunner.GetActiveBranchingDialogueNode(conversationName);
                if(activeDialogueNode is BranchingDialogueNode)
                {
                    BranchingDialogueNode branchingNode = activeDialogueNode as BranchingDialogueNode;

                    //printer.PrintConversation(conversationName);

                    int i = 1;
                    Console.WriteLine("Choose an alternative:");
                    foreach(string optionNodeName in branchingNode.nextNodes)
                    {
                        TimedDialogueNode optionNode = dialogueRunner.GetDialogueNode(conversationName, optionNodeName) as TimedDialogueNode;
                        Console.WriteLine(i++ + ". " + optionNode.line);
                    }

                    int choice = -1;
                    while(choice < 0 || choice > branchingNode.nextNodes.Length - 1) {
                        try {
                            choice = 0; //Convert.ToInt32(Console.ReadLine()) - 1;
                        }
                        catch {
                            choice = -1;
                        }
                    }

                    branchingNode.Choose(choice);
                }
            }
        }
        public void ImmediateNodeWithCustomName()
        {
            RelayTwo relay = new RelayTwo();
            relay.CreateTable(DialogueNode.TABLE_NAME);

            DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.SWEDISH);

            DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner);
            scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation9.dia");

            DialogueNode n = dialogueRunner.GetDialogueNode("conversation9", "Örjan");
            Assert.IsNotNull(n);
        }
Пример #5
0
        static void RunDialogue()
        {
            string conversationName = "meeting";             // "PixieMeeting1";

            RelayTwo       relay;
            DialogueRunner dialogueRunner;

            relay = new RelayTwo();
            relay.CreateTable(DialogueNode.TABLE_NAME);

            dialogueRunner = new DialogueRunner(relay, Language.DEFAULT);
            dialogueRunner.AddExpression("CoinFlip", CoinFlip);
            dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSpeech);
            dialogueRunner.logger.AddListener(Log);

            DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner);

            scriptLoader.LoadDialogueNodesFromFile(conversationName + ".dia");

            DialogueScriptPrinter printer = new DialogueScriptPrinter(dialogueRunner);

            printer.PrintConversation(conversationName);

            Console.WriteLine(" - " + conversationName + " - ");
            dialogueRunner.StartConversation(conversationName);

            while (dialogueRunner.ConversationIsRunning(conversationName))
            {
                //printer.PrintConversation(conversationName);

                dialogueRunner.Update(1.0f);
                DialogueNode activeDialogueNode = dialogueRunner.GetActiveBranchingDialogueNode(conversationName);
                if (activeDialogueNode is BranchingDialogueNode)
                {
                    BranchingDialogueNode branchingNode = activeDialogueNode as BranchingDialogueNode;

                    //printer.PrintConversation(conversationName);

                    int i = 1;
                    Console.WriteLine("Choose an alternative:");
                    foreach (string optionNodeName in branchingNode.nextNodes)
                    {
                        TimedDialogueNode optionNode = dialogueRunner.GetDialogueNode(conversationName, optionNodeName) as TimedDialogueNode;
                        Console.WriteLine(i++ + ". " + optionNode.line);
                    }

                    int choice = -1;
                    while (choice < 0 || choice > branchingNode.nextNodes.Length - 1)
                    {
                        try {
                            choice = 0;                             //Convert.ToInt32(Console.ReadLine()) - 1;
                        }
                        catch {
                            choice = -1;
                        }
                    }

                    branchingNode.Choose(choice);
                }
            }
        }