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 SetupTingsThenSaveAndLoadFromDisk() { { TingRunner tingRunner = CreateTingRunnerWithSomeRoom(); Animal bo = tingRunner.CreateTing <Animal>("Bo", new WorldCoordinate("SomeRoom", IntPoint.Zero)); bo.species = "cow"; bo.age = 10; Animal howly = tingRunner.CreateTing <Animal>("Howly", new WorldCoordinate("SomeRoom", IntPoint.Zero)); howly.species = "owl"; Assert.AreEqual("cow", bo.species); Assert.AreEqual(10, bo.age); Assert.AreEqual("owl", howly.species); Assert.AreEqual(0, howly.age); // <- default value howly.age = 35; relay.SaveAll("farm.json"); } { relay = new RelayTwo(); relay.LoadAll("farm.json"); TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay)); Animal bo = tingRunner.GetTing("Bo") as Animal; Animal howly = tingRunner.GetTing("Howly") as Animal; Assert.AreEqual("cow", bo.species); Assert.AreEqual(10, bo.age); Assert.AreEqual("owl", howly.species); Assert.AreEqual(35, howly.age); } }
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 CreateAndSaveEmptyRelay() { InitialSaveFileCreator i = new InitialSaveFileCreator(); RelayTwo emptyRelay = i.CreateEmptyRelay(); AssertThatCanFindAllTables(emptyRelay); emptyRelay.SaveAll("empty.json"); emptyRelay.tables.Clear(); emptyRelay.LoadAll("empty.json"); AssertThatCanFindAllTables(emptyRelay); }
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 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 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 SaveAndLoadAProgram() { const string saveName = "SaveAndLoadAProgramTest.json"; const string programName = "PrintMagicNumber"; const string sourceCode = "print(42)"; int programObjectId; { Program p = _programRunner.CreateProgram(programName, sourceCode, "unknown"); programObjectId = p.objectId; _relay.SaveAll(saveName); } { RelayTwo relay = new RelayTwo(saveName); ProgramRunner programRunner = new ProgramRunner(relay); Program p = programRunner.GetProgram(programObjectId); Assert.AreEqual(programName, p.name); Assert.AreEqual(sourceCode, p.sourceCodeContent); } }
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 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 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 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 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 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 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"); Room r2 = roomRunner.CreateRoom <Room>("r2"); PointTileNode door1 = null; PointTileNode door2 = 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)); } } for (int i = 0; i < 100; i++) { int x = i % 10; int y = i / 10; if (x == 0 && y == 0) { door2 = new PointTileNode(new IntPoint(0, 0), r2); r2.AddTile(door2); } else { r2.AddTile(new PointTileNode(new IntPoint(x, y), r2)); } } r1.worldPosition = new IntPoint(50, 0); door1.teleportTarget = door2; door2.teleportTarget = door1; 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"); Room r2 = roomRunner.GetRoom("r2"); r1.GetTile(9, 9).teleportTarget = r2.GetTile(0, 0); r2.worldPosition = new IntPoint(0, 0); PointTileNode start = r1.GetTile(new IntPoint(0, 5)); PointTileNode goal = r2.GetTile(new IntPoint(9, 5)); D.isNull(start); D.isNull(goal); PathSolver <PointTileNode> pathSolver = new PathSolver <PointTileNode>(); Path <PointTileNode> path = pathSolver.FindPath(start, goal, roomRunner); Assert.AreEqual(PathStatus.FOUND_GOAL, path.status); Console.WriteLine("path resolved using " + path.pathSearchTestCount + " node tests"); Console.WriteLine("path tile count " + path.nodes.Length); } }
/// <summary> /// Creates a Relay save file suitable for loading into World when a new game of Miman is created. /// The input directory specified will be searched through recursively and all files with approperiate /// file endings (.dia, .sprak, etc) will be added to the save. /// </summary> public void CreateSaveFile(string pInputDirectory, string pOutputFilepath, bool pOnlyLoadTingsAndRooms) { CreateRelay(pInputDirectory, pOnlyLoadTingsAndRooms); _relay.SaveAll(pOutputFilepath); }
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 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); } }