public void BasicUsage() { TableTwo table1 = _relay.GetTable("Table1"); Assert.AreEqual(3.5f, table1[_rowIndex0].Get <float>("a")); Assert.AreEqual(7.0f, table1[_rowIndex0].Get <float>("b")); Assert.AreEqual(5.0f, table1[_rowIndex1].Get <float>("a")); }
//, TingRunner pTingRunner) public TimetableRunner(RelayTwo pRelay) { _timetableTable = pRelay.GetTable(Timetable.TABLE_NAME); foreach(var timetable in InstantiatorTwo.Process<Timetable>(_timetableTable)) { _timetables[timetable.name] = timetable; } }
public TimetableRunner(RelayTwo pRelay) //, TingRunner pTingRunner) { _timetableTable = pRelay.GetTable(Timetable.TABLE_NAME); foreach (var timetable in InstantiatorTwo.Process <Timetable>(_timetableTable)) { _timetables[timetable.name] = timetable; } }
public ProgramRunner(RelayTwo pRelay) { D.isNull(pRelay); _programTable = pRelay.GetTable(Program.TABLE_NAME); _programsList = InstantiatorTwo.Process<Program>(_programTable); foreach (var program in _programsList) { program.Init(this); _programsDictionary.Add(program.objectId, program); } }
public void CreateInitialSaveFromInitData1() { InitialSaveFileCreator i = new InitialSaveFileCreator(); i.CreateSaveFile("../InitData1/", WorldTestHelper.INITIAL_SAVE_1); RelayTwo relay = new RelayTwo(WorldTestHelper.INITIAL_SAVE_1); AssertThatCanFindAllTables(relay); TableTwo tingTable = relay.GetTable(Character.TABLE_NAME); Assert.AreEqual("Adam", tingTable.GetRow(0).Get<string>("name")); Assert.AreEqual("Eva", tingTable.GetRow(1).Get<string>("name")); Assert.AreEqual("PowerCube", relay.GetTable(MysticalCube.TABLE_NAME).GetRow(0).Get<string>("name")); TableTwo roomTable = relay.GetTable(Room.TABLE_NAME); Assert.AreEqual("Eden", roomTable.GetRow(0).Get<string>("name")); Assert.AreEqual("Hallway", roomTable.GetRow(1).Get<string>("name")); Assert.AreEqual("Kitchen", roomTable.GetRow(2).Get<string>("name")); Assert.AreEqual("Bedroom", roomTable.GetRow(3).Get<string>("name")); }
public SourceCodeDispenser(RelayTwo pRelay) { _sourceCodeTable = pRelay.GetTable(SourceCode.TABLE_NAME); //Console.WriteLine("Getting source code from " + _sourceCodeTable.name); _sourceCodes = InstantiatorTwo.Process <SourceCode>(_sourceCodeTable); foreach (SourceCode sc in _sourceCodes) { //Console.WriteLine("found source code " + sc.name); } }
public SourceCodeDispenser(RelayTwo pRelay) { _sourceCodeTable = pRelay.GetTable(SourceCode.TABLE_NAME); //Console.WriteLine("Getting source code from " + _sourceCodeTable.name); _sourceCodes = InstantiatorTwo.Process<SourceCode>(_sourceCodeTable); foreach (SourceCode sc in _sourceCodes) { //Console.WriteLine("found source code " + sc.name); } }
public ProgramRunner(RelayTwo pRelay) { D.isNull(pRelay); _programTable = pRelay.GetTable(Program.TABLE_NAME); _programsList = InstantiatorTwo.Process <Program>(_programTable); foreach (var program in _programsList) { program.Init(this); _programsDictionary.Add(program.objectId, program); } }
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 CreateInitialSaveFromInitData1() { InitialSaveFileCreator i = new InitialSaveFileCreator(); i.CreateSaveFile("../InitData1/", WorldTestHelper.INITIAL_SAVE_1); RelayTwo relay = new RelayTwo(WorldTestHelper.INITIAL_SAVE_1); AssertThatCanFindAllTables(relay); TableTwo tingTable = relay.GetTable(Character.TABLE_NAME); Assert.AreEqual("Adam", tingTable.GetRow(0).Get <string>("name")); Assert.AreEqual("Eva", tingTable.GetRow(1).Get <string>("name")); Assert.AreEqual("PowerCube", relay.GetTable(MysticalCube.TABLE_NAME).GetRow(0).Get <string>("name")); TableTwo roomTable = relay.GetTable(Room.TABLE_NAME); Assert.AreEqual("Eden", roomTable.GetRow(0).Get <string>("name")); Assert.AreEqual("Hallway", roomTable.GetRow(1).Get <string>("name")); Assert.AreEqual("Kitchen", roomTable.GetRow(2).Get <string>("name")); Assert.AreEqual("Bedroom", roomTable.GetRow(3).Get <string>("name")); }
void AssertThatCanFindAllTables(RelayTwo pRelay) { Assert.IsNotNull(pRelay.GetTable(Ting.TABLE_NAME)); Assert.IsNotNull(pRelay.GetTable(Room.TABLE_NAME)); Assert.IsNotNull(pRelay.GetTable(DialogueNode.TABLE_NAME)); Assert.IsNotNull(pRelay.GetTable(SourceCode.TABLE_NAME)); Assert.IsNotNull(pRelay.GetTable(Program.TABLE_NAME)); Assert.IsNotNull(pRelay.GetTable(WorldSettings.TABLE_NAME)); }
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 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 DialogueRunner(RelayTwo pRelay, Language pLanguage) { D.isNull(pRelay); _dialogueTable = pRelay.GetTable(DialogueNode.TABLE_NAME); _language = pLanguage; _dialogueNodes = InstantiatorTwo.Process <DialogueNode>(_dialogueTable); foreach (DialogueNode n in _dialogueNodes) { n.SetRunner(this); if (n is IRegisteredDialogueNode) { IRegisteredDialogueNode ir = n as IRegisteredDialogueNode; _registeredDialogueNodes.Add(ir); } if (n.isOn) { _nodesThatAreOn.Add(n); } AddNodeToNodeForConversationDictionary(n.conversation, n); } RegisterBuiltInAPIExpressions(); }
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 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 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 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 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 WorldSettings(RelayTwo pRelay) { _table = pRelay.GetTable(TABLE_NAME); SetupCells(); }
public RoomRunner(RelayTwo pRelay) { D.isNull(pRelay); _roomTable = pRelay.GetTable(Room.TABLE_NAME); _rooms = InstantiatorTwo.Process <Room>(_roomTable); }
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")); } }