public IEnumerable <float> LoadRelayFromDirectory(string pInputDirectory, bool pOnlyLoadTingsAndRooms) { #if PROFILE Stopwatch sw = new Stopwatch(); sw.Start(); #endif _relay = CreateEmptyRelay(); DialogueRunner dialogueRunner = new DialogueRunner(_relay, Language.DEFAULT); _dialogueScriptLoader = new DialogueScriptLoader(dialogueRunner); _sourceCodeDispenser = new SourceCodeDispenser(_relay); _timetableRunner = new TimetableRunner(_relay); string[] files = GetFilesRecursively(pInputDirectory); for (int i = 0; i < files.Length; i++) { FoundFile(files[i], pOnlyLoadTingsAndRooms); yield return((float)i / (float)files.Length); } #if PROFILE sw.Stop(); logger.Log("Loading relay from directory " + pInputDirectory + " took " + sw.Elapsed.TotalSeconds + " s."); #endif }
public void AssertCommando() { _lines = new List<string>(); s_pooWasCalledCorrectly = false; RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.AddExpression("Pass", Pass); dialogueRunner.AddExpression("Fail", Fail); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation16.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation16"); Assert.Throws<GrimmAssertException>(() => { dialogueRunner.StartConversation("conversation16"); for(int i = 0; i < 100; i++) { dialogueRunner.Update(1.0f); } }); Assert.AreEqual(4, _lines.Count); Assert.AreEqual("hej1", _lines[0]); Assert.AreEqual("", _lines[1]); Assert.AreEqual("hej2", _lines[2]); Assert.AreEqual("", _lines[3]); }
public void SimpleConversation() { DialogueScriptLoader loader = new DialogueScriptLoader(_dialogueRunner); loader.LoadDialogueNodesFromFile("../conversations/conversation5.dia"); DialogueScriptPrinter printer = new DialogueScriptPrinter(_dialogueRunner); printer.PrintConversation("conversation5"); }
public void ComplicatedConversation() { DialogueScriptLoader loader = new DialogueScriptLoader(_dialogueRunner); loader.LoadDialogueNodesFromFile("../conversations/conversation4.dia"); DialogueScriptPrinter printer = new DialogueScriptPrinter(_dialogueRunner); printer.PrintConversation("conversation4"); }
public RelayTwo CreateRelay(string pInputDirectory, bool pOnlyLoadTingsAndRooms) { _relay = CreateEmptyRelay(); DialogueRunner dialogueRunner = new DialogueRunner(_relay, Language.DEFAULT); _dialogueScriptLoader = new DialogueScriptLoader(dialogueRunner); _sourceCodeDispenser = new SourceCodeDispenser(_relay); _timetableRunner = new TimetableRunner(_relay); foreach (string s in GetFilesRecursively(pInputDirectory)) { FoundFile(s, pOnlyLoadTingsAndRooms); } return(_relay); }
public void Basics() { _speech = new List<Speech>(); _dialogueRunner.AddOnSomeoneSaidSomethingListener(LogSpeech); DialogueScriptLoader loader = new DialogueScriptLoader(_dialogueRunner); loader.LoadDialogueNodesFromFile("../conversations/conversation1.dia"); foreach(var node in _dialogueRunner.GetAllNodes()) { Console.WriteLine(node.name); } List<DialogueNode> nodes = new List<DialogueNode>(); nodes.Add(_dialogueRunner.GetDialogueNode("conversation1", "__Start__")); nodes.Add(_dialogueRunner.GetDialogueNode("conversation1", "0_line_1")); nodes.Add(_dialogueRunner.GetDialogueNode("conversation1", "1_line_2")); nodes.Add(_dialogueRunner.GetDialogueNode("conversation1", "2_line_3")); nodes.Add(_dialogueRunner.GetDialogueNode("conversation1", "__End__")); foreach(DialogueNode n in nodes) { Console.WriteLine("Has a node called '{0}' with next node '{1}' of type {2}", n.name, n.nextNode, n.GetType()); } _dialogueRunner.StartConversation("conversation1"); for(int i = 0; i < 1000; i++) { _dialogueRunner.Update(1.0f); } Assert.AreEqual(6, _speech.Count); Assert.AreEqual("Hoho", _speech[0].line); Assert.AreEqual("", _speech[1].line); Assert.AreEqual("Hjälp!",_speech[2].line); Assert.AreEqual("", _speech[3].line); Assert.AreEqual("Oh no", _speech[4].line); Assert.AreEqual("", _speech[5].line); Assert.AreEqual("Tomten", _speech[0].speaker); Assert.AreEqual("Tomten", _speech[1].speaker); Assert.AreEqual("Barn", _speech[2].speaker); Assert.AreEqual("Barn", _speech[3].speaker); Assert.AreEqual("Tomten", _speech[4].speaker); Assert.AreEqual("Tomten", _speech[5].speaker); }
public void Focus() { _lines = new List<string>(); bool madeActive = false; RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(LogDialogueRunner); dialogueRunner.AddFocusConversationListener((string pConversation) => { if(pConversation == "conversation23") { madeActive = true; } }); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation23.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation23"); dialogueRunner.StartConversation("conversation23"); for(int i = 0; i < 500; i++) { dialogueRunner.Update(1.0f); } Assert.IsTrue(madeActive); }
public void StopAnotherConversation() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(Console.WriteLine); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation32.dia"); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation31.dia"); dialogueRunner.StartConversation("conversation32"); for(int i = 0; i < 100; i++) { dialogueRunner.Update(0.1f); } dialogueRunner.StartConversation("conversation31"); for(int i = 0; i < 100; i++) { dialogueRunner.Update(0.1f); } Assert.IsFalse(dialogueRunner.ConversationIsRunning("conversation32")); Assert.IsFalse(dialogueRunner.ConversationIsRunning("conversation31")); }
public void EmptyLoop() { RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation24.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation24"); dialogueRunner.StartConversation("conversation24"); dialogueRunner.Update(1.0f); Assert.IsTrue(dialogueRunner.ConversationIsRunning("conversation24")); // never ends }
public void WaitAndLoop() { var log = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(Console.WriteLine); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation39.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation39"); dialogueRunner.AddFunction("Log", (args) => log.Add(args[0])); dialogueRunner.logger.AddListener(s => Console.WriteLine("LOG: " + s)); dialogueRunner.StartConversation("conversation39"); for(int i = 0; i < 10 * 7; i++) { dialogueRunner.Update(0.1f); } dialogueRunner.Update(0.1f); Assert.AreEqual(7, log.Count); Assert.AreEqual("boom", log[0]); Assert.AreEqual("boom", log[1]); Assert.AreEqual("boom", log[2]); Assert.AreEqual("boom", log[3]); Assert.AreEqual("boom", log[4]); Assert.AreEqual("boom", log[5]); Assert.AreEqual("boom", log[6]); }
public void StartingOtherDialoguesAndStoryNodes() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation1.dia"); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation11.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation11"); dialogueRunner.StartConversation("conversation11"); for(int i = 0; i < 1000; i++) { dialogueRunner.Update(1.0f); } Console.WriteLine("Output:"); foreach(string s in _lines) { Console.WriteLine(s); } Assert.AreEqual(6, _lines.Count); Assert.AreEqual("Hoho", _lines[0]); Assert.AreEqual("", _lines[1]); Assert.AreEqual("Hjälp!",_lines[2]); Assert.AreEqual("", _lines[3]); Assert.AreEqual("Oh no", _lines[4]); Assert.AreEqual("", _lines[5]); }
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); }
public void ListeningDialogueNodeWithNoBranch() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(LogDialogueRunner); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation21.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation21"); dialogueRunner.StartConversation("conversation21"); Assert.AreEqual(0, _lines.Count); for(int i = 0; i < 500; i++) { if(i == 250) { dialogueRunner.EventHappened("RainStarted"); } dialogueRunner.Update(1.0f); } Assert.AreEqual(2, _lines.Count); Assert.AreEqual("Where is my umbrella?", _lines[0]); Assert.AreEqual("", _lines[1]); }
public void BreakOutOfLoop() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(Console.WriteLine); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation26.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation26"); Console.WriteLine("Starting..."); dialogueRunner.StartConversation("conversation26"); for(int i = 0; i < 10; i++) { Console.WriteLine("Update " + i); dialogueRunner.Update(0.3f); } foreach(string s in _lines) { Console.WriteLine(s); } Assert.IsFalse(dialogueRunner.ConversationIsRunning("conversation26")); Assert.AreEqual(2, _lines.Count); Assert.AreEqual("yo", _lines[0]); Assert.AreEqual("", _lines[1]); }
public void CallAFunctionFromDialogueScript() { RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddFunction("foo", foo); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation13.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation13"); dialogueRunner.StartConversation("conversation13"); for(int i = 0; i < 10; i++) { dialogueRunner.Update(0.1f); } Assert.IsTrue(s_fooWasCalled); }
public void WaitMustComeBeforeListen() { RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.logger.AddListener(Console.WriteLine); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); Assert.Throws<GrimmException> ( () => { scriptLoader.LoadDialogueNodesFromFile ("../conversations/conversation38.dia"); } ); }
public void WaitSpecifiedTime() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(Console.WriteLine); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation36.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation36"); dialogueRunner.StartConversation("conversation36"); dialogueRunner.Update(1.0f); Assert.AreEqual(0, _lines.Count); dialogueRunner.Update(0.01f); dialogueRunner.Update(0.01f); dialogueRunner.Update(0.01f); dialogueRunner.Update(0.01f); dialogueRunner.Update(3.0f); dialogueRunner.Update(1.0f); dialogueRunner.Update(1.0f); dialogueRunner.Update(1.0f); // TODO: had to hack this a bit (with multiple updates) to make it work, hope it's OK... Assert.AreEqual(2, _lines.Count); Assert.AreEqual("Woo!", _lines[0]); }
public void WaitForMultipleConditions() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(Console.WriteLine); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation28.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation28"); }
public void WaitForEvents() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(Console.WriteLine); dialogueRunner.AddExpression("Whatever", ((string[] args) => (true))); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation35.dia"); //DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); //scriptPrinter.PrintConversation("conversation35"); dialogueRunner.StartConversation("conversation35"); for(int i = 0; i < 100; i++) { dialogueRunner.Update(0.5f); } Assert.AreEqual(2, _lines.Count); Assert.AreEqual("Yeah1", _lines[0]); dialogueRunner.EventHappened("Bam"); for(int i = 0; i < 100; i++) { dialogueRunner.Update(0.5f); } Assert.AreEqual(4, _lines.Count); Assert.AreEqual("Yeah2", _lines[2]); }
public void WaitForConditionWithArguments() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.AddExpression("StateIs", StateIs); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation18.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation18"); dialogueRunner.StartConversation("conversation18"); for(int i = 0; i < 100; i++) { dialogueRunner.Update(1.0f); } Assert.AreEqual(0, _lines.Count); for(int i = 0; i < 100; i++) { if(i == 50) { s_monsterState = "Angry"; } dialogueRunner.Update(1.0f); } Assert.AreEqual(2, _lines.Count); Assert.AreEqual("Ahhhhh!", _lines[0]); Assert.AreEqual("", _lines[1]); }
public void GotoNodes() { RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.SWEDISH); dialogueRunner.logger.AddListener(LogDialogueRunner); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); _lines = new List<string>(); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation6.dia"); DialogueScriptPrinter printer = new DialogueScriptPrinter(dialogueRunner); printer.PrintConversation("conversation6"); dialogueRunner.StartConversation("conversation6"); for(int i = 0; i < 1000; i++) { dialogueRunner.Update(1.0f); } Console.WriteLine("Output:"); foreach(string s in _lines) { Console.WriteLine(s); } Assert.AreEqual(6, _lines.Count); Assert.AreEqual("a", _lines[0]); Assert.AreEqual("", _lines[1]); Assert.AreEqual("b", _lines[2]); Assert.AreEqual("", _lines[3]); Assert.AreEqual("c", _lines[4]); Assert.AreEqual("", _lines[5]); }
public void CallAFunctionWithDotOperator() { s_pooWasCalledCorrectly = false; RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddFunction("poo", poo); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation15.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation15"); dialogueRunner.StartConversation("conversation15"); for(int i = 0; i < 10; i++) { dialogueRunner.Update(0.1f); } Assert.IsTrue(s_pooWasCalledCorrectly); }
public void IfNode() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.SWEDISH); dialogueRunner.logger.AddListener(LogDialogueRunner); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.AddExpression("TimeForSleep", TimeForSleep); dialogueRunner.AddExpression("TimeForDinner", TimeForDinner); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation7.dia"); DialogueScriptPrinter printer = new DialogueScriptPrinter(dialogueRunner); printer.PrintConversation("conversation7"); dialogueRunner.StartConversation("conversation7"); for(int i = 0; i < 1000; i++) { dialogueRunner.Update(1.0f); } Console.WriteLine("Output:"); foreach(string s in _lines) { Console.WriteLine(s); } Assert.AreEqual(4, _lines.Count); Assert.AreEqual("Let's eat", _lines[0]); Assert.AreEqual("", _lines[1]); Assert.AreEqual("I'm hungry", _lines[2]); Assert.AreEqual("", _lines[3]); }
public void ListeningForEventAndSaveInBetween() { _lines = new List<string>(); { RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(LogDialogueRunner); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation19.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation19"); dialogueRunner.StartConversation("conversation19"); for(int i = 0; i < 10; i++) { dialogueRunner.Update(0.1f); } Assert.AreEqual(1, _lines.Count); Assert.AreEqual("Blah blah blah", _lines[0]); relay.SaveAll("save.xml"); } { RelayTwo relay = new RelayTwo("save.xml"); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(LogDialogueRunner); dialogueRunner.EventHappened("TensionWentUp"); for(int i = 0; i < 500; i++) { dialogueRunner.Update(1.0f); } Assert.AreEqual(4, _lines.Count); Assert.AreEqual("Oh!", _lines[1]); Assert.AreEqual("", _lines[2]); Assert.AreEqual("", _lines[3]); Assert.IsFalse(dialogueRunner.ConversationIsRunning("conversation19")); dialogueRunner.EventHappened("SomethingElse"); // this is not supposed to do anything since the story is over for(int i = 0; i < 500; i++) { dialogueRunner.Update(1.0f); } Assert.AreEqual(4, _lines.Count); } }
public void InterruptCommando() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(Console.WriteLine); D.onDLog += (pMessage) => { Console.WriteLine("DLog: " + pMessage); }; DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation1.dia"); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation33.dia"); dialogueRunner.StartConversation("conversation33"); for(int i = 0; i < 300; i++) { dialogueRunner.Update(0.1f); } Assert.AreEqual(10, _lines.Count); Assert.AreEqual("before", _lines[0]); Assert.AreEqual("", _lines[1]); Assert.AreEqual("Hoho", _lines[2]); Assert.AreEqual("", _lines[3]); Assert.AreEqual("Hjälp!", _lines[4]); Assert.AreEqual("", _lines[5]); Assert.AreEqual("Oh no", _lines[6]); Assert.AreEqual("", _lines[7]); Assert.AreEqual("after", _lines[8]); Assert.AreEqual("", _lines[9]); }
public void RemoveOptionsAfterTheyHaveBeenSelected() { DialogueScriptLoader loader = new DialogueScriptLoader(_dialogueRunner); loader.LoadDialogueNodesFromFile("../conversations/conversation37.dia"); _dialogueRunner.StartConversation("conversation37"); for(int i = 0; i < 10; i++) { _dialogueRunner.Update(0.1f); } BranchingDialogueNode n = _dialogueRunner.GetActiveBranchingDialogueNode("conversation37"); Assert.IsNotNull(n); Assert.AreEqual (3, n.nextNodes.Length); Assert.AreEqual ("a", GetTextFromOption (n, 0)); Assert.AreEqual ("b", GetTextFromOption (n, 1)); Assert.AreEqual ("c", GetTextFromOption (n, 2)); n.Choose (1); for (int i = 0; i < 100; i++) { _dialogueRunner.Update (0.1f); } BranchingDialogueNode sameNodeButLaterAfterLooping = _dialogueRunner.GetActiveBranchingDialogueNode("conversation37"); Assert.AreEqual (2, sameNodeButLaterAfterLooping.nextNodes.Length); Assert.AreEqual ("a", GetTextFromOption (sameNodeButLaterAfterLooping, 0)); Assert.AreEqual ("c", GetTextFromOption (sameNodeButLaterAfterLooping, 1)); n.Choose (1); for(int i = 0; i < 100; i++) { _dialogueRunner.Update(0.1f); } BranchingDialogueNode nodeAgain = _dialogueRunner.GetActiveBranchingDialogueNode("conversation37"); Assert.AreEqual (1, nodeAgain.nextNodes.Length); Assert.AreEqual ("a", GetTextFromOption (nodeAgain, 0)); n.Choose (0); for(int i = 0; i < 10; i++) { _dialogueRunner.Update(0.1f); } BranchingDialogueNode finalTime = _dialogueRunner.GetActiveBranchingDialogueNode("conversation37"); // RIGHT NOW THE LAST CHOICE ISN'T REMOVED TO AVOID GETTING STUCK WITH ZERO OPTIONS //Assert.AreEqual (0, finalTime.nextNodes.Length); }
public void CancelNested() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(LogDialogueRunner); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation22b.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation22b"); dialogueRunner.StartConversation("conversation22b"); for(int i = 0; i < 500; i++) { dialogueRunner.Update(1.0f); } Assert.AreEqual(2, _lines.Count); Assert.AreEqual("Yup", _lines[0]); Assert.AreEqual("", _lines[1]); }
public void StopCommando() { _lines = new List<string>(); s_pooWasCalledCorrectly = false; RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation17.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation17"); dialogueRunner.StartConversation("conversation17"); for(int i = 0; i < 100; i++) { dialogueRunner.Update(1.0f); } Console.WriteLine("OUTPUT:"); foreach(string s in _lines) { Console.WriteLine(s); } Assert.AreEqual(2, _lines.Count); Assert.AreEqual("hej1", _lines[0]); Assert.AreEqual("", _lines[1]); }
public void LoadingADialogueWithOptions() { DialogueScriptLoader loader = new DialogueScriptLoader(_dialogueRunner); loader.LoadDialogueNodesFromFile("../conversations/conversation3.dia"); _dialogueRunner.StartConversation("conversation3"); for(int i = 0; i < 10; i++) { _dialogueRunner.Update(0.1f); } BranchingDialogueNode n = _dialogueRunner.GetActiveBranchingDialogueNode("conversation3"); Assert.IsNotNull(n); TimedDialogueNode option1 = _dialogueRunner.GetDialogueNode("conversation3", n.nextNodes[0]) as TimedDialogueNode; TimedDialogueNode option2 = _dialogueRunner.GetDialogueNode("conversation3", n.nextNodes[1]) as TimedDialogueNode; Assert.AreEqual("Option 1", option1.line); Assert.AreEqual("Option 2", option2.line); Assert.AreEqual("first", option1.nextNode); Assert.AreEqual("second", option2.nextNode); DialogueNode option1response = _dialogueRunner.GetDialogueNode("conversation3", option1.nextNode); DialogueNode option2response = _dialogueRunner.GetDialogueNode("conversation3", option2.nextNode); DialogueNode start = _dialogueRunner.GetDialogueNode("conversation3", "__Start__"); DialogueNode end = _dialogueRunner.GetDialogueNode("conversation3", "__End__"); Assert.IsNotNull(option1response); Assert.IsNotNull(option2response); Assert.IsNotNull(start); Assert.IsNotNull(end); }
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 ShortIf() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(Console.WriteLine); dialogueRunner.AddExpression("Foo", ((string[] args) => (true))); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation30.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation30"); }
public void CustomNodeNames() { DialogueScriptLoader loader = new DialogueScriptLoader(_dialogueRunner); loader.LoadDialogueNodesFromFile("../conversations/conversation2.dia"); Assert.IsNotNull(_dialogueRunner.GetDialogueNode("conversation2", "importantNode")); }
public void ChoiceKeyword() { RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation34.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation34"); }
public void Elif() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(Console.WriteLine); dialogueRunner.AddExpression("A", ((string[] args) => (false))); dialogueRunner.AddExpression("B", ((string[] args) => (false))); dialogueRunner.AddExpression("C", ((string[] args) => (true))); dialogueRunner.AddExpression("D", ((string[] args) => (false))); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation29.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation29"); dialogueRunner.StartConversation("conversation29"); for(int i = 0; i < 100; i++) { dialogueRunner.Update(0.5f); } Assert.AreEqual(2, _lines.Count); Assert.AreEqual("C", _lines[0]); }