public void InstantiateFromDatabase() { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable(Ting.TABLE_NAME); relay.CreateTable(Room.TABLE_NAME); table.AddField<string>(RelayObjectTwo.CSHARP_CLASS_FIELD_NAME); table.AddField<string>("species"); table.AddField<string>("name"); table.AddField<int>("age"); int row0 = table.CreateRow().row; int row1 = table.CreateRow().row; table.SetValue(row0, RelayObjectTwo.CSHARP_CLASS_FIELD_NAME, "Animal"); table.SetValue(row0, "species", "Monkey"); table.SetValue(row0, "name", "Herr Nilsson"); table.SetValue(row0, "age", 78); table.SetValue(row1, RelayObjectTwo.CSHARP_CLASS_FIELD_NAME, "Animal"); table.SetValue(row1, "species", "Horse"); table.SetValue(row1, "name", "Lilla Gubben"); table.SetValue(row1, "age", 50); TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay)); Animal herrNilsson = tingRunner.GetTing("Herr Nilsson") as Animal; Animal lillaGubben = tingRunner.GetTing("Lilla Gubben") as Animal; Assert.IsNotNull(herrNilsson); Assert.IsNotNull(lillaGubben); Assert.AreEqual(78, herrNilsson.age); Assert.AreEqual(50, lillaGubben.age); }
public void InstantiateFromDatabase() { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable(Ting.TABLE_NAME); relay.CreateTable(Room.TABLE_NAME); table.AddField <string>(RelayObjectTwo.CSHARP_CLASS_FIELD_NAME); table.AddField <string>("species"); table.AddField <string>("name"); table.AddField <int>("age"); int row0 = table.CreateRow().row; int row1 = table.CreateRow().row; table.SetValue(row0, RelayObjectTwo.CSHARP_CLASS_FIELD_NAME, "Animal"); table.SetValue(row0, "species", "Monkey"); table.SetValue(row0, "name", "Herr Nilsson"); table.SetValue(row0, "age", 78); table.SetValue(row1, RelayObjectTwo.CSHARP_CLASS_FIELD_NAME, "Animal"); table.SetValue(row1, "species", "Horse"); table.SetValue(row1, "name", "Lilla Gubben"); table.SetValue(row1, "age", 50); TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay)); Animal herrNilsson = tingRunner.GetTing("Herr Nilsson") as Animal; Animal lillaGubben = tingRunner.GetTing("Lilla Gubben") as Animal; Assert.IsNotNull(herrNilsson); Assert.IsNotNull(lillaGubben); Assert.AreEqual(78, herrNilsson.age); Assert.AreEqual(50, lillaGubben.age); }
TingRunner CreateTingRunnerWithSomeRoom() { relay = new RelayTwo(); relay.CreateTable(Ting.TABLE_NAME); relay.CreateTable(Room.TABLE_NAME); RoomRunner rr = new RoomRunner(relay); rr.CreateRoom <Room>("SomeRoom"); TingRunner tingRunner = new TingRunner(relay, rr); return(tingRunner); }
public void TryingToGetTingWithWrongName() { RelayTwo relay = new RelayTwo(); relay.CreateTable(Ting.TABLE_NAME); relay.CreateTable(Room.TABLE_NAME); TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay)); Assert.Throws <CantFindTingException>(() => { tingRunner.GetTing("wrong ting name"); }); }
public void TryingToInstantiateNonexistingClass() { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable(Ting.TABLE_NAME); relay.CreateTable(Room.TABLE_NAME); table.AddField <string>(RelayObjectTwo.CSHARP_CLASS_FIELD_NAME); table.CreateRow().Set(RelayObjectTwo.CSHARP_CLASS_FIELD_NAME, "invalid class name"); Assert.Throws <CantFindClassWithNameException>(() => { new TingRunner(relay, new RoomRunner(relay)); }); }
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); } }
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); } }
public void CanNotStartDialogueNodeInAnotherConversation() { RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH); TimedDialogueNode n1 = runner.Create <TimedDialogueNode>("Conversation1", Language.SWEDISH, "DialogueNode1"); n1.nextNode = "DialogueNode2"; n1.timer = 1; runner.Create <TimedDialogueNode>("Conversation2", Language.SWEDISH, "DialogueNode2"); n1.Start(); string msg = null; D.onDLog += (pMessage) => { Console.WriteLine("DLog: " + pMessage); msg = pMessage; }; runner.Update(1.0f); runner.Update(1.0f); Assert.NotNull(msg); }
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 MergeTwoSubsets() { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable("Table1"); table.AddField <string>("name"); table.AddField <bool>("1337"); TableRow row1 = table.CreateRow(); TableRow row2 = table.CreateRow(); TableRow row3 = table.CreateRow(); row1.Set("name", "Arne"); row1.Set("1337", false); row2.Set("name", "Björn"); row2.Set("1337", true); row3.Set("name", "Charlie"); row3.Set("1337", false); Assert.AreEqual(3, table.GetRows().Length); RelayTwo subsetA = relay.Subset("Table1", (o => o.Get <bool>("1337") == true)); RelayTwo subsetB = relay.Subset("Table1", (o => o.Get <bool>("1337") == false)); subsetA.MergeWith(subsetB); Assert.Throws <RelayTwo.RelayMergeException>(() => subsetB.MergeWith(relay)); Assert.AreEqual(true, subsetA.Equals(relay)); Assert.AreEqual(false, subsetB.Equals(relay)); }
public void CompileAndRun() { GameTypes.D.onDLog += Console.WriteLine; output = new List <string>(); RelayTwo relay = new RelayTwo(); TableTwo programsTable = relay.CreateTable(Program.TABLE_NAME); FunctionDefinition print = new FunctionDefinition("void", "print", new string[] { "string" }, new string[] { "s" }, API_print, FunctionDocumentation.Default()); Program p1 = new Program(); p1.CreateNewRelayEntry(programsTable, "Program"); p1.Init(new ProgramRunner(relay)); p1.sourceCodeContent = "print(42)"; p1.FunctionDefinitions.Add(print); p1.Compile(); Assert.AreEqual(0, p1.GetErrors().Length); for (int i = 0; i < 100; i++) { if (p1.sprakRunner.interpreter != null) { p1.Update(0.1f); } } Assert.AreEqual(1, output.Count); Assert.AreEqual("42", output[0]); }
public void CompileAndRun() { GameTypes.D.onDLog += Console.WriteLine; output = new List<string>(); RelayTwo relay = new RelayTwo(); TableTwo programsTable = relay.CreateTable(Program.TABLE_NAME); FunctionDefinition print = new FunctionDefinition("void", "print", new string[] { "string" }, new string[] { "s" }, API_print, FunctionDocumentation.Default()); Program p1 = new Program(); p1.CreateNewRelayEntry(programsTable, "Program"); p1.Init(new ProgramRunner(relay)); p1.sourceCodeContent = "print(42)"; p1.FunctionDefinitions.Add(print); p1.Compile(); Assert.AreEqual(0, p1.GetErrors().Length); for(int i = 0; i < 100; i++) { if(p1.sprakRunner.interpreter != null) { p1.Update(0.1f); } } Assert.AreEqual(1, output.Count); Assert.AreEqual("42", output[0]); }
public void Setup() { _relay = new RelayTwo(); _table = _relay.CreateTable(Ting.TABLE_NAME); _relay.CreateTable(Room.TABLE_NAME); _roomRunner = new RoomRunner(_relay); Room room = _roomRunner.CreateRoom<Room>(ROOM_NAME); for (int i = 0; i < 100; i++) { room.AddTile(new PointTileNode(new IntPoint(i % 10, i / 10), room)); } _tingRunner = new TingRunner(_relay, _roomRunner); _tingRunner.CreateTing<MyTing>("Ting0", new WorldCoordinate(ROOM_NAME, new IntPoint(0, 0))); _tingRunner.CreateTing<MyTing>("Ting1", new WorldCoordinate(ROOM_NAME, new IntPoint(1, 0))); }
public void Setup() { _relay = new RelayTwo(); _table = _relay.CreateTable(Ting.TABLE_NAME); _relay.CreateTable(Room.TABLE_NAME); _roomRunner = new RoomRunner(_relay); Room room = _roomRunner.CreateRoom <Room>(ROOM_NAME); for (int i = 0; i < 100; i++) { room.AddTile(new PointTileNode(new IntPoint(i % 10, i / 10), room)); } _tingRunner = new TingRunner(_relay, _roomRunner); _tingRunner.CreateTing <MyTing>("Ting0", new WorldCoordinate(ROOM_NAME, new IntPoint(0, 0))); _tingRunner.CreateTing <MyTing>("Ting1", new WorldCoordinate(ROOM_NAME, new IntPoint(1, 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 DontTriggerEventOnWaitingNodeUnlessEventHappensWhenExpressionIsTrue() { RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH); runner.logger.AddListener (msg => Console.WriteLine ("Dialog runner log: " + msg)); bool sunny = false; runner.AddExpression ("IsSunny", new DialogueRunner.Expression (args => { return sunny; })); var expression = runner.Create<ExpressionDialogueNode>("Conversation1", Language.SWEDISH, "ExpressionNode"); expression.expression = "IsSunny"; expression.args = new string[] { }; var waitNode = runner.Create<WaitDialogueNode>("Conversation1", Language.SWEDISH, "WaitNode"); waitNode.eventName = "bam!"; waitNode.expressions = new ExpressionDialogueNode[] { expression }; var start = runner.Create<ConversationStartDialogueNode>("Conversation1", Language.SWEDISH, "Start"); var end = runner.Create<ConversationEndDialogueNode>("Conversation1", Language.SWEDISH, "End"); start.nextNode = waitNode.name; waitNode.nextNode = end.name; runner.StartConversation ("Conversation1"); runner.Update (0.1f); runner.Update (0.1f); runner.Update (0.1f); Assert.IsTrue (waitNode.isOn); Assert.IsTrue (runner.ConversationIsRunning("Conversation1")); // Event should not occur since it's not sunny yet runner.EventHappened("bam!"); runner.Update (0.1f); Assert.IsTrue (waitNode.isOn); Assert.IsTrue (runner.ConversationIsRunning("Conversation1")); sunny = true; // Now, even though it's sunny the event should still not happen since we're not bam!:ing runner.Update (0.1f); Assert.IsTrue (waitNode.isOn); Assert.IsTrue (runner.ConversationIsRunning("Conversation1")); // But if the bam! event happens while sunny, the conversation should end runner.EventHappened("bam!"); runner.Update (0.1f); runner.Update (0.1f); runner.Update (0.1f); Assert.IsFalse (waitNode.isOn); Assert.IsFalse (runner.ConversationIsRunning("Conversation1")); }
private TableTwo AssertTable(Type t, RelayTwo pRelay) { string tableName = GetTableName(t); if (!pRelay.tables.ContainsKey(tableName)) { pRelay.CreateTable(tableName); } return(pRelay.tables[tableName]); }
public void CompileWithError() { RelayTwo relay = new RelayTwo(); TableTwo programsTable = relay.CreateTable(Program.TABLE_NAME); Program p1 = new Program(); p1.CreateNewRelayEntry(programsTable, "Program"); p1.sourceCodeContent = "var x = "; p1.Compile(); Assert.AreEqual(1, p1.GetErrors().Length); }
public void MergeSavesWithDifferentFields() { { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable("Table"); table.AddField <string>("oldField"); TableRow row1 = table.CreateRow(); TableRow row2 = table.CreateRow(); TableRow row3 = table.CreateRow(); row1.Set("oldField", "kottar"); row2.Set("oldField", "stenar"); row3.Set("oldField", "gräs"); relay.Subset("Table", (o => o.row == 0)).SaveAll("s0.json"); relay.Subset("Table", (o => o.row == 1)).SaveAll("s1.json"); relay.Subset("Table", (o => o.row == 2)).SaveAll("s2.json"); table.AddField <int>("newField"); TableRow row4 = table.CreateRow(); TableRow row5 = table.CreateRow(); row4.Set("newField", 500); row5.Set("newField", 1000); relay.Subset("Table", (o => o.row == 3)).SaveAll("s3.json"); relay.Subset("Table", (o => o.row == 4)).SaveAll("s4.json"); } { RelayTwo relay = new RelayTwo(); relay.MergeWith(new RelayTwo("s4.json")); relay.MergeWith(new RelayTwo("s0.json")); relay.MergeWith(new RelayTwo("s1.json")); relay.MergeWith(new RelayTwo("s2.json")); relay.MergeWith(new RelayTwo("s3.json")); TableTwo table = relay.GetTable("Table"); Assert.AreEqual(5, table.GetRows().Length); Assert.AreEqual("kottar", table.GetRow(0).Get <string>("oldField")); Assert.AreEqual("stenar", table.GetRow(1).Get <string>("oldField")); Assert.AreEqual("gräs", table.GetRow(2).Get <string>("oldField")); Assert.AreEqual(500, table.GetRow(3).Get <int>("newField")); Assert.AreEqual(1000, table.GetRow(4).Get <int>("newField")); } }
public void CreateTimedDialogueNode() { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable(DialogueNode.TABLE_NAME); TimedDialogueNode t = new TimedDialogueNode(); t.CreateNewRelayEntry(table, "TimedDialogueNode"); t.timer = 100; t.Update(1.0f); Assert.AreEqual(99, t.timer, 0.001f); }
public void CreateRoomsWithDuplicateNames() { RelayTwo relay = new RelayTwo(); relay.CreateTable(Room.TABLE_NAME); RoomRunner roomRunner = new RoomRunner(relay); roomRunner.CreateRoom <Room>("Hallway"); Assert.Throws <TingTingException>(() => { roomRunner.CreateRoom <Room>("Hallway"); }); }
public void BasicUsage() { { RelayTwo relay = new RelayTwo(); relay.CreateTable(Room.TABLE_NAME); RoomRunner roomRunner = new RoomRunner(relay); foreach (string s in roomRunner.Preload()) ; Room r1 = roomRunner.CreateRoom<Room>("r1"); PointTileNode door1 = null; for(int i = 0; i < 100; i++) { int x = i % 10; int y = i / 10; if(x == 9 && y == 9) { door1 = new PointTileNode(new IntPoint(9, 9), r1); r1.AddTile(door1); } else { r1.AddTile(new PointTileNode(new IntPoint(x, y), r1 )); } } r1.worldPosition = new IntPoint(50, 0); relay.SaveAll("room_test.json"); } { RelayTwo relay = new RelayTwo("room_test.json"); RoomRunner roomRunner = new RoomRunner(relay); foreach (string s in roomRunner.Preload()) ; Room r1 = roomRunner.GetRoom("r1"); PointTileNode start = r1.GetTile(new IntPoint(0, 5)); PointTileNode goal = r1.GetTile(new IntPoint(9, 5)); D.isNull(start); D.isNull(goal); PathSolver pathSolver = new PathSolver(); Path path = pathSolver.FindPath(start, goal, roomRunner, true); Console.WriteLine("path resolved using " + path.pathSearchTestCount + " node tests"); Console.WriteLine("path tile count " + path.nodes.Length); Assert.AreEqual(PathStatus.FOUND_GOAL, path.status); } }
public void GetListOfRowIdsInTable() { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable("Table"); table.CreateRow(); table.CreateRow(); table.CreateRow(); int[] allObjectIds = table.GetIndexesOfPopulatedRows(); Assert.AreEqual(3, allObjectIds.Length); CollectionAssert.AllItemsAreUnique(allObjectIds); }
private static void UsingNormalAccessor() { RelayTwo relay = new RelayTwo(); relay.CreateTable(Ting.TABLE_NAME); TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay)); TestTing2UsingNormalAccessor t = tingRunner.CreateTing<TestTing2UsingNormalAccessor>("TestTing", WorldCoordinate.NONE); Console.WriteLine("Using class " + t.ToString()); for(int i = 0; i < COUNTER; i++) { float a = t.awesome; a += 1.0f; t.awesome = a; } Console.WriteLine("2. awesome = " + t.awesome); }
private static void UsingCellId() { RelayTwo relay = new RelayTwo(); relay.CreateTable(Ting.TABLE_NAME); TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay)); TestTing1UsingCellIdWithConvenienceFunctions t = tingRunner.CreateTing<TestTing1UsingCellIdWithConvenienceFunctions>("TestTing", WorldCoordinate.NONE); Console.WriteLine("Using class " + t.ToString()); for(int i = 0; i < COUNTER; i++) { float a = t.awesome; a += 1.0f; t.awesome = a; } Console.WriteLine("1. awesome = " + t.awesome); }
public void MergeSaves() { { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable("Table"); table.AddField <string>("name"); TableRow row1 = table.CreateRow(); TableRow row2 = table.CreateRow(); TableRow row3 = table.CreateRow(); row1.Set("name", "a"); row2.Set("name", "b"); row3.Set("name", "c"); Assert.AreEqual(3, table.GetRows().Length); Assert.AreEqual("a", table.GetRow(0).Get <string>("name")); Assert.AreEqual("b", table.GetRow(1).Get <string>("name")); Assert.AreEqual("c", table.GetRow(2).Get <string>("name")); RelayTwo save1 = relay.Subset("Table", (o => o.Get <string>("name") == "a")); RelayTwo save2 = relay.Subset("Table", (o => o.Get <string>("name") == "b")); RelayTwo save3 = relay.Subset("Table", (o => o.Get <string>("name") == "c")); Assert.AreEqual(1, save1.GetTable("Table").GetRows().Length); Assert.AreEqual(1, save2.GetTable("Table").GetRows().Length); Assert.AreEqual(1, save3.GetTable("Table").GetRows().Length); save1.SaveAll("PartialSave1.json"); save2.SaveAll("PartialSave2.json"); save3.SaveAll("PartialSave3.json"); } { RelayTwo relay = new RelayTwo(); relay.MergeWith(new RelayTwo("PartialSave1.json")); relay.MergeWith(new RelayTwo("PartialSave2.json")); relay.MergeWith(new RelayTwo("PartialSave3.json")); TableTwo table = relay.GetTable("Table"); Assert.AreEqual(3, table.GetRows().Length); Assert.AreEqual("a", table.GetRow(0).Get <string>("name")); Assert.AreEqual("b", table.GetRow(1).Get <string>("name")); Assert.AreEqual("c", table.GetRow(2).Get <string>("name")); } }
public RelayTwo CreateEmptyRelay() { RelayTwo relay = new RelayTwo(); relay.CreateTable(Ting.TABLE_NAME); relay.CreateTable(Room.TABLE_NAME); relay.CreateTable(DialogueNode.TABLE_NAME); relay.CreateTable(SourceCode.TABLE_NAME); relay.CreateTable(Program.TABLE_NAME); relay.CreateTable(WorldSettings.TABLE_NAME); relay.CreateTable(Timetable.TABLE_NAME); return(relay); }
public void CanNotStartDialogueNodeInAnotherConversation() { RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH); TimedDialogueNode n1 = runner.Create<TimedDialogueNode>("Conversation1", Language.SWEDISH, "DialogueNode1"); n1.nextNode = "DialogueNode2"; n1.timer = 1; runner.Create<TimedDialogueNode>("Conversation2", Language.SWEDISH, "DialogueNode2"); n1.Start(); Assert.Throws<GrimmException>(() => { runner.Update(1.0f); }); }
private static void UsingNormalAccessor() { RelayTwo relay = new RelayTwo(); relay.CreateTable(Ting.TABLE_NAME); TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay)); TestTing2UsingNormalAccessor t = tingRunner.CreateTing <TestTing2UsingNormalAccessor>("TestTing", WorldCoordinate.NONE); Console.WriteLine("Using class " + t.ToString()); for (int i = 0; i < COUNTER; i++) { float a = t.awesome; a += 1.0f; t.awesome = a; } Console.WriteLine("2. awesome = " + t.awesome); }
private static void UsingCellId() { RelayTwo relay = new RelayTwo(); relay.CreateTable(Ting.TABLE_NAME); TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay)); TestTing1UsingCellIdWithConvenienceFunctions t = tingRunner.CreateTing <TestTing1UsingCellIdWithConvenienceFunctions>("TestTing", WorldCoordinate.NONE); Console.WriteLine("Using class " + t.ToString()); for (int i = 0; i < COUNTER; i++) { float a = t.awesome; a += 1.0f; t.awesome = a; } Console.WriteLine("1. awesome = " + t.awesome); }
public void BasicUsage() { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable("Stuffs"); table.AddField<string>("name"); table.AddField<string>(RelayObjectTwo.CSHARP_CLASS_FIELD_NAME); table.CreateRow().Set(RelayObjectTwo.CSHARP_CLASS_FIELD_NAME, "Stuff").Set("name", "first"); table.CreateRow().Set(RelayObjectTwo.CSHARP_CLASS_FIELD_NAME, "Stuff").Set("name", "second"); List<Stuff> objects = InstantiatorTwo.Process<Stuff>(table); Assert.AreEqual(2, objects.Count); Stuff first = objects[0]; Stuff second = objects[1]; Assert.AreEqual("first", first.name); Assert.AreEqual("second", second.name); }
public void CreatingEmptyRoom() { string saveName = "MyEmptyRoomSave.json"; { RelayTwo relay = new RelayTwo(); relay.CreateTable(Room.TABLE_NAME); RoomRunner roomRunner = new RoomRunner(relay); roomRunner.CreateRoom <Room>("MyRoom"); relay.SaveAll(saveName); } { RelayTwo relay = new RelayTwo(saveName); RoomRunner roomRunner = new RoomRunner(relay); Room room = roomRunner.GetRoom("MyRoom"); Assert.IsNotNull(room); Assert.AreEqual("MyRoom", room.name); Assert.AreEqual(0, room.tilePoints.Length); } }
public void CreatingEmptyRoom() { string saveName = "MyEmptyRoomSave.json"; { RelayTwo relay = new RelayTwo(); relay.CreateTable(Room.TABLE_NAME); RoomRunner roomRunner = new RoomRunner(relay); roomRunner.CreateRoom<Room>("MyRoom"); relay.SaveAll(saveName); } { RelayTwo relay = new RelayTwo(saveName); RoomRunner roomRunner = new RoomRunner(relay); Room room = roomRunner.GetRoom("MyRoom"); Assert.IsNotNull(room); Assert.AreEqual("MyRoom", room.name); Assert.AreEqual(new PointTileNode[] {}, room.tiles); } }
public void BasicUsage() { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable("Stuffs"); table.AddField <string>("name"); table.AddField <string>(RelayObjectTwo.CSHARP_CLASS_FIELD_NAME); table.CreateRow().Set(RelayObjectTwo.CSHARP_CLASS_FIELD_NAME, "Stuff").Set("name", "first"); table.CreateRow().Set(RelayObjectTwo.CSHARP_CLASS_FIELD_NAME, "Stuff").Set("name", "second"); List <Stuff> objects = InstantiatorTwo.Process <Stuff>(table); Assert.AreEqual(2, objects.Count); Stuff first = objects[0]; Stuff second = objects[1]; Assert.AreEqual("first", first.name); Assert.AreEqual("second", second.name); }
public void TestSimpleSerialization() { SomeStruct s = new SomeStruct(); s.header = "dkjkgk"; s.later = 911100299; s.ater = true; s.color = HairColor.WHITE; r2.CreateTable("characters"); TableTwo c = r2.GetTable("characters"); c.AddField <string>("name"); c.AddField <int>("age"); c.AddField <HairColor>("hairColor"); c.AddField <SomeStruct>("other"); c.CreateRow().Set("name", @"Johann3||¤%¤%&'''\'es").Set("age", 23).Set("hairColor", HairColor.RAT).Set("other", s); Console.WriteLine(String.Join("|", c[0].valuesAsStrings)); }
public void CreatingRoomConveniently() { RelayTwo relay = new RelayTwo(); relay.CreateTable(Room.TABLE_NAME); RoomRunner roomRunner = new RoomRunner(relay); SimpleRoomBuilder srb = new SimpleRoomBuilder(roomRunner); Room closet = srb.CreateRoomWithSize("Closet", 4, 3); Assert.AreEqual(12, closet.tilePoints.Length); for (int x = 0; x < 4; x++) { for (int y = 0; y < 3; y++) { Assert.IsNotNull(closet.GetTile(new IntPoint(x, y))); } } }
public void UsingTheDialogueRunner() { RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH); runner.AddOnSomeoneSaidSomethingListener(LogDialogue); _dialogueLog = new List <string>(); TimedDialogueNode d1 = runner.Create <TimedDialogueNode>("FirstConverstation", Language.SWEDISH, "DialogueNode1"); d1.nextNode = "DialogueNode2"; d1.timer = 0.5f; d1.speaker = "Helan"; d1.line = "Hi, what's up?"; TimedDialogueNode d2 = runner.Create <TimedDialogueNode>("FirstConverstation", Language.SWEDISH, "DialogueNode2"); d2.speaker = "Halvan"; d2.line = "I'm fine, thanks"; // Frame 0 d1.Start(); Assert.IsTrue(d1.isOn); Assert.IsFalse(d2.isOn); runner.LogNodesThatAreOn(); // Frame 1 runner.Update(0.2f); runner.Update(0.2f); runner.Update(0.2f); runner.Update(0.2f); runner.LogNodesThatAreOn(); Assert.IsFalse(d1.isOn); Assert.IsTrue(d2.isOn); }
public void Setup() { D.onDLog += Log; _relay = new RelayTwo(); TableTwo table1 = _relay.CreateTable("Table1"); table1.AddField<float>("a"); table1.AddField<float>("b"); TableRow row0 = table1.CreateRow(); TableRow row1 = table1.CreateRow(); _rowIndex0 = row0.row; _rowIndex1 = row1.row; row0.Set("a", 3.5f); row0.Set("b", 7.0f); row1.Set("a", 2.0f); row1.Set("a", 5.0f); }
public void Setup() { D.onDLog += Log; _relay = new RelayTwo(); TableTwo table1 = _relay.CreateTable("Table1"); table1.AddField <float>("a"); table1.AddField <float>("b"); TableRow row0 = table1.CreateRow(); TableRow row1 = table1.CreateRow(); _rowIndex0 = row0.row; _rowIndex1 = row1.row; row0.Set("a", 3.5f); row0.Set("b", 7.0f); row1.Set("a", 2.0f); row1.Set("a", 5.0f); }
public void DeleteRoomAndCreateNewOneAfterThat() { RelayTwo relay = new RelayTwo(); relay.CreateTable(Room.TABLE_NAME); RoomRunner roomRunner = new RoomRunner(relay); { Room bathroom = roomRunner.CreateRoom <Room>("Bathroom"); bathroom.AddTile(new PointTileNode(new IntPoint(7, 9), bathroom)); bathroom.AddTile(new PointTileNode(new IntPoint(8, 9), bathroom)); Assert.AreEqual(2, bathroom.tilePoints.Length); Assert.AreEqual(new IntPoint(7, 9), bathroom.tilePoints[0]); } { roomRunner.DestroyRoom("Bathroom"); Room bathroomAgain = roomRunner.CreateRoom <Room>("Bathroom"); Assert.AreEqual(0, bathroomAgain.tilePoints.Length); bathroomAgain.AddTile(new PointTileNode(new IntPoint(7, 9), bathroomAgain)); // should be able to add node Assert.AreEqual(1, bathroomAgain.tilePoints.Length); } }
public void RemoveConversation() { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH); runner.Create <TimedDialogueNode>("Convo1", Language.SWEDISH, "Node1"); runner.Create <TimedDialogueNode>("Convo2", Language.SWEDISH, "Node2"); runner.Create <TimedDialogueNode>("Convo1", Language.SWEDISH, "Node3"); runner.Create <TimedDialogueNode>("Convo2", Language.SWEDISH, "Node4"); runner.Create <TimedDialogueNode>("Convo1", Language.SWEDISH, "Node5"); runner.Create <TimedDialogueNode>("Convo2", Language.SWEDISH, "Node6"); Assert.IsTrue(runner.HasConversation("Convo1")); Assert.IsTrue(runner.HasConversation("Convo2")); Assert.AreEqual(6, table.GetRows().Length); runner.RemoveConversation("Convo1"); Assert.IsFalse(runner.HasConversation("Convo1")); Assert.IsTrue(runner.HasConversation("Convo2")); Assert.AreEqual(3, table.GetRows().Length); }
public void SaveAndLoad() { int rowNr0, rowNr1, rowNr2; { RelayTwo r1 = new RelayTwo(); r1.CreateTable("Table1"); TableTwo table = r1.GetTable("Table1"); rowNr0 = table.CreateRow().row; rowNr1 = table.CreateRow().row; rowNr2 = table.CreateRow().row; table.GetValueEntryEnsureDefault <float>(rowNr0, "a", 3.5f); table.GetValueEntryEnsureDefault <float>(rowNr0, "b", 7.0f); table.GetValueEntryEnsureDefault <float>(rowNr1, "a", 2.0f); table.SetValue <float>(rowNr0, "a", 5.0f); table.GetValueEntryEnsureDefault <string>(rowNr2, "blehu", "ap\na"); Assert.AreEqual(5.0f, table[rowNr0].Get <float>("a")); Assert.AreEqual(7.0f, table[rowNr0].Get <float>("b")); Assert.AreEqual(2.0f, table[rowNr1].Get <float>("a")); Assert.AreEqual("ap\na", table[rowNr2].Get <string>("blehu")); r1.SaveAll("sdfsdf.json"); } { RelayTwo r2 = new RelayTwo("sdfsdf.json"); TableTwo table = r2.GetTable("Table1"); Assert.AreEqual(5.0f, table[rowNr0].Get <float>("a")); Assert.AreEqual(7.0f, table[rowNr0].Get <float>("b")); Assert.AreEqual(2.0f, table[rowNr1].Get <float>("a")); Assert.AreEqual("ap\na", table[rowNr2].Get <string>("blehu")); } }
public void SaveSubsetOfDatabase() { { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable("Table1"); table.AddField <string>("name"); table.AddField <bool>("1337"); TableRow row1 = table.CreateRow(); TableRow row2 = table.CreateRow(); TableRow row3 = table.CreateRow(); row1.Set("name", "Arne"); row1.Set("1337", false); row2.Set("name", "Björn"); row2.Set("1337", true); row3.Set("name", "Charlie"); row3.Set("1337", false); Assert.AreEqual(3, table.GetRows().Length); RelayTwo subset = relay.Subset("Table1", (o => o.Get <bool>("1337") == true)); subset.SaveAll("Only1337People.json"); } { RelayTwo relay = new RelayTwo("Only1337People.json"); TableTwo table = relay.GetTable("Table1"); TableRow[] rows = table.GetRows(); Assert.AreEqual(1, rows.Length); Assert.AreEqual("Björn", table.First().Get <string>("name")); } }
public void BasicUsage() { const string saveName = "SourceCodeDispenserTest.json"; { RelayTwo relay = new RelayTwo(); relay.CreateTable(SourceCode.TABLE_NAME); SourceCodeDispenser sourceCodeDispenser = new SourceCodeDispenser(relay); sourceCodeDispenser.LoadSourceCode(WorldTestHelper.INIT_DATA_PATH + "Sprak/helloworld.sprak"); SourceCode s = sourceCodeDispenser.GetSourceCode("helloworld"); Assert.AreEqual("print(\"Hello World!\")", s.content); relay.SaveAll(saveName); } { RelayTwo relay = new RelayTwo(saveName); SourceCodeDispenser sourceCodeDispenser = new SourceCodeDispenser(relay); SourceCode s = sourceCodeDispenser.GetSourceCode("helloworld"); Assert.AreEqual("print(\"Hello World!\")", s.content); } }
public void CanNotStartDialogueNodeInAnotherConversation() { RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH); TimedDialogueNode n1 = runner.Create<TimedDialogueNode>("Conversation1", Language.SWEDISH, "DialogueNode1"); n1.nextNode = "DialogueNode2"; n1.timer = 1; runner.Create<TimedDialogueNode>("Conversation2", Language.SWEDISH, "DialogueNode2"); n1.Start(); string msg = null; D.onDLog += (pMessage) => { Console.WriteLine("DLog: " + pMessage); msg = pMessage; }; runner.Update(1.0f); runner.Update(1.0f); Assert.NotNull(msg); }
public void MergeSavesWithDifferentFields() { { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable("Table"); table.AddField<string>("oldField"); TableRow row1 = table.CreateRow(); TableRow row2 = table.CreateRow(); TableRow row3 = table.CreateRow(); row1.Set("oldField", "kottar"); row2.Set("oldField", "stenar"); row3.Set("oldField", "gräs"); relay.Subset("Table", (o => o.row == 0)).SaveAll("s0.json"); relay.Subset("Table", (o => o.row == 1)).SaveAll("s1.json"); relay.Subset("Table", (o => o.row == 2)).SaveAll("s2.json"); table.AddField<int>("newField"); TableRow row4 = table.CreateRow(); TableRow row5 = table.CreateRow(); row4.Set("newField", 500); row5.Set("newField", 1000); relay.Subset("Table", (o => o.row == 3)).SaveAll("s3.json"); relay.Subset("Table", (o => o.row == 4)).SaveAll("s4.json"); } { RelayTwo relay = new RelayTwo(); relay.MergeWith(new RelayTwo("s4.json")); relay.MergeWith(new RelayTwo("s0.json")); relay.MergeWith(new RelayTwo("s1.json")); relay.MergeWith(new RelayTwo("s2.json")); relay.MergeWith(new RelayTwo("s3.json")); TableTwo table = relay.GetTable("Table"); Assert.AreEqual(5, table.GetRows().Length); Assert.AreEqual("kottar", table.GetRow(0).Get<string>("oldField")); Assert.AreEqual("stenar", table.GetRow(1).Get<string>("oldField")); Assert.AreEqual("gräs", table.GetRow(2).Get<string>("oldField")); Assert.AreEqual(500, table.GetRow(3).Get<int>("newField")); Assert.AreEqual(1000, table.GetRow(4).Get<int>("newField")); } }
public void SaveSubsetOfDatabase() { { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable("Table1"); table.AddField<string>("name"); table.AddField<bool>("1337"); TableRow row1 = table.CreateRow(); TableRow row2 = table.CreateRow(); TableRow row3 = table.CreateRow(); row1.Set("name", "Arne"); row1.Set("1337", false); row2.Set("name", "Björn"); row2.Set("1337", true); row3.Set("name", "Charlie"); row3.Set("1337", false); Assert.AreEqual(3, table.GetRows().Length); RelayTwo subset = relay.Subset("Table1", (o => o.Get<bool>("1337") == true)); subset.SaveAll("Only1337People.json"); } { RelayTwo relay = new RelayTwo("Only1337People.json"); TableTwo table = relay.GetTable("Table1"); TableRow[] rows = table.GetRows(); Assert.AreEqual(1, rows.Length); Assert.AreEqual("Björn", table.First().Get<string>("name")); } }
public void MergeTwoSubsets() { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable("Table1"); table.AddField<string>("name"); table.AddField<bool>("1337"); TableRow row1 = table.CreateRow(); TableRow row2 = table.CreateRow(); TableRow row3 = table.CreateRow(); row1.Set("name", "Arne"); row1.Set("1337", false); row2.Set("name", "Björn"); row2.Set("1337", true); row3.Set("name", "Charlie"); row3.Set("1337", false); Assert.AreEqual(3, table.GetRows().Length); RelayTwo subsetA = relay.Subset("Table1", (o => o.Get<bool>("1337") == true)); RelayTwo subsetB = relay.Subset("Table1", (o => o.Get<bool>("1337") == false)); subsetA.MergeWith(subsetB); Assert.Throws<RelayTwo.RelayMergeException>(() => subsetB.MergeWith(relay)); Assert.AreEqual(true, subsetA.Equals(relay)); Assert.AreEqual(false, subsetB.Equals(relay)); }
public void MergeSaves() { { RelayTwo relay = new RelayTwo(); TableTwo table = relay.CreateTable("Table"); table.AddField<string>("name"); TableRow row1 = table.CreateRow(); TableRow row2 = table.CreateRow(); TableRow row3 = table.CreateRow(); row1.Set("name", "a"); row2.Set("name", "b"); row3.Set("name", "c"); Assert.AreEqual(3, table.GetRows().Length); Assert.AreEqual("a", table.GetRow(0).Get<string>("name")); Assert.AreEqual("b", table.GetRow(1).Get<string>("name")); Assert.AreEqual("c", table.GetRow(2).Get<string>("name")); RelayTwo save1 = relay.Subset("Table", (o => o.Get<string>("name") == "a")); RelayTwo save2 = relay.Subset("Table", (o => o.Get<string>("name") == "b")); RelayTwo save3 = relay.Subset("Table", (o => o.Get<string>("name") == "c")); Assert.AreEqual(1, save1.GetTable("Table").GetRows().Length); Assert.AreEqual(1, save2.GetTable("Table").GetRows().Length); Assert.AreEqual(1, save3.GetTable("Table").GetRows().Length); save1.SaveAll("PartialSave1.json"); save2.SaveAll("PartialSave2.json"); save3.SaveAll("PartialSave3.json"); } { RelayTwo relay = new RelayTwo(); relay.MergeWith(new RelayTwo("PartialSave1.json")); relay.MergeWith(new RelayTwo("PartialSave2.json")); relay.MergeWith(new RelayTwo("PartialSave3.json")); TableTwo table = relay.GetTable("Table"); Assert.AreEqual(3, table.GetRows().Length); Assert.AreEqual("a", table.GetRow(0).Get<string>("name")); Assert.AreEqual("b", table.GetRow(1).Get<string>("name")); Assert.AreEqual("c", table.GetRow(2).Get<string>("name")); } }
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 LoadFromSeveralPartialDatabases() { { RelayTwo r1 = new RelayTwo(); TableTwo t = r1.CreateTable("Table"); t.AddField<string>("animal"); t.AddField<int>("age"); TableRow row0 = t.CreateRow(); row0.Set("animal", "rabbit"); row0.Set("age", 5); TableRow row1 = t.CreateRow(); row1.Set("animal", "salmon"); row1.Set("age", 10); TableRow row2 = t.CreateRow(); row2.Set("animal", "spider"); row2.Set("age", 1); r1.SaveAll("r1.json"); } { RelayTwo r2 = new RelayTwo(); TableTwo t = r2.CreateTable("Table"); t.AddField<string>("animal"); t.AddField<bool>("carnivore"); TableRow row0 = t.CreateRow(); row0.Set("animal", "mouse"); row0.Set("carnivore", false); TableRow row1 = t.CreateRow(); row1.Set("animal", "fox"); row1.Set("carnivore", true); r2.SaveAll("r2.json"); } { RelayTwo combined = new RelayTwo(); combined.AppendTables("r1.json"); combined.AppendTables("r2.json"); Assert.AreEqual(1, combined.tables.Count); TableTwo t = combined.GetTable("Table"); Assert.AreEqual(3, t.fieldNames.Length); Console.WriteLine("The merged table contains the following rows: "); foreach(int rowIndex in t.GetIndexesOfPopulatedRows()) { TableRow row = t[rowIndex]; Console.WriteLine("Values in row " + rowIndex); foreach(string s in row.valuesAsStrings) { Console.Write(s + ", "); } Console.WriteLine("\n"); } Assert.AreEqual(5, t.GetIndexesOfPopulatedRows().Length); TableRow rabbit = t[0]; TableRow salmon = t[1]; TableRow spider = t[2]; TableRow mouse = t[3]; TableRow fox = t[4]; Assert.AreEqual("rabbit", rabbit.Get<string>("animal")); Assert.AreEqual("salmon", salmon.Get<string>("animal")); Assert.AreEqual("spider", spider.Get<string>("animal")); Assert.AreEqual("mouse", mouse.Get<string>("animal")); Assert.AreEqual("fox", fox.Get<string>("animal")); Assert.AreEqual(5, rabbit.Get<int>("age")); Assert.AreEqual(10, salmon.Get<int>("age")); Assert.AreEqual(1, spider.Get<int>("age")); Assert.Throws<RelayException>(() => { Assert.AreEqual(0, mouse.Get<int>("age")); }); Assert.Throws<RelayException>(() => { Assert.AreEqual(0, fox.Get<int>("age")); }); Assert.AreEqual(true, fox.Get<bool>("carnivore")); } }
public void SaveAndLoad() { int rowNr0, rowNr1, rowNr2; { RelayTwo r1 = new RelayTwo(); r1.CreateTable("Table1"); TableTwo table = r1.GetTable("Table1"); rowNr0 = table.CreateRow().row; rowNr1 = table.CreateRow().row; rowNr2 = table.CreateRow().row; table.GetValueEntryEnsureDefault<float>(rowNr0, "a", 3.5f); table.GetValueEntryEnsureDefault<float>(rowNr0, "b", 7.0f); table.GetValueEntryEnsureDefault<float>(rowNr1, "a", 2.0f); table.SetValue<float>(rowNr0, "a", 5.0f); table.GetValueEntryEnsureDefault<string>(rowNr2, "blehu", "ap\na"); Assert.AreEqual(5.0f, table[rowNr0].Get<float>("a")); Assert.AreEqual(7.0f, table[rowNr0].Get<float>("b")); Assert.AreEqual(2.0f, table[rowNr1].Get<float>("a")); Assert.AreEqual("ap\na", table[rowNr2].Get<string>("blehu")); r1.SaveAll("sdfsdf.json"); } { RelayTwo r2 = new RelayTwo("sdfsdf.json"); TableTwo table = r2.GetTable("Table1"); Assert.AreEqual(5.0f, table[rowNr0].Get<float>("a")); Assert.AreEqual(7.0f, table[rowNr0].Get<float>("b")); Assert.AreEqual(2.0f, table[rowNr1].Get<float>("a")); Assert.AreEqual("ap\na", table[rowNr2].Get<string>("blehu")); } }
public void SetUp() { _relay = new RelayTwo(); _relay.CreateTable(DialogueNode.TABLE_NAME); _dialogueRunner = new DialogueRunner(_relay, Language.SWEDISH); }
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 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 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"); }