Пример #1
0
        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"));
        }
Пример #2
0
        //, TingRunner pTingRunner)
        public TimetableRunner(RelayTwo pRelay)
        {
            _timetableTable = pRelay.GetTable(Timetable.TABLE_NAME);

            foreach(var timetable in InstantiatorTwo.Process<Timetable>(_timetableTable)) {
                _timetables[timetable.name] = timetable;
            }
        }
Пример #3
0
        public TimetableRunner(RelayTwo pRelay)         //, TingRunner pTingRunner)
        {
            _timetableTable = pRelay.GetTable(Timetable.TABLE_NAME);

            foreach (var timetable in InstantiatorTwo.Process <Timetable>(_timetableTable))
            {
                _timetables[timetable.name] = timetable;
            }
        }
Пример #4
0
 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"));
        }
Пример #6
0
 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);
     }
 }
Пример #8
0
 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);
     }
 }
Пример #9
0
        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));
 }
 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));
 }
Пример #13
0
        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"));
            }
        }
Пример #14
0
        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));
        }
Пример #15
0
        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();
        }
Пример #16
0
        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"));
            }
        }
Пример #17
0
        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"));
            }
        }
Пример #18
0
		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"));
			}
		}
Пример #19
0
        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"));
			}
        }
Пример #20
0
        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"));
			}
        }
Пример #21
0
		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"));
			}
		}
Пример #22
0
        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"));
			}
        }
Пример #23
0
 public WorldSettings(RelayTwo pRelay)
 {
     _table = pRelay.GetTable(TABLE_NAME);
     SetupCells();
 }
Пример #24
0
 public RoomRunner(RelayTwo pRelay)
 {
     D.isNull(pRelay);
     _roomTable = pRelay.GetTable(Room.TABLE_NAME);
     _rooms     = InstantiatorTwo.Process <Room>(_roomTable);
 }
Пример #25
0
 public WorldSettings(RelayTwo pRelay)
 {
     _table = pRelay.GetTable(TABLE_NAME);
     SetupCells();
 }
Пример #26
0
        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"));
            }
        }