Пример #1
0
        public void PlayingCardReadWriteTest()
        {
            DynamicDataType playingCardType = new DynamicDataType("Playing Card",
                                                                  bools: new string[] { "Face Card" },
                                                                  bytes: new string[] { "Value", "Suit" });

            DynamicDataEntry card1 = new DynamicDataEntry(playingCardType);

            card1.SetBool("Face Card", true);
            card1.SetByte("Value", 12);
            card1.SetByte("Suit", 3);

            TestEntry(card1);

            DynamicDataEntry card2 = new DynamicDataEntry(playingCardType);

            card2.SetBool("Face Card", false);
            card2.SetByte("Value", 3);
            card2.SetByte("Suit", 1);

            TestEntry(card2);

            DynamicDataEntry card3 = new DynamicDataEntry(playingCardType);

            card3.SetBool("Face Card", false);
            card3.SetByte("Value", 8);
            card3.SetByte("Suit", 2);

            TestEntry(card3);
        }
Пример #2
0
        public DynamicData(IReadOnlyDictionary <string, object> properties) : this()
        {
            var store = new DictionaryStore(properties);

            store.Freeze();
            _data = store;
            _type = DynamicDataType.Properties;
        }
Пример #3
0
        public void TCGCardReadWriteTest()
        {
            DynamicDataType tcgCardType = new DynamicDataType("TCG Card",
                                                              bools: new string[] { "Instant" },
                                                              bytes: new string[] { "Fire Cost", "Water Cost", "Rock Cost", "Wind Cost" },
                                                              ints: new string[] { "Health", "Attack", "Armor" },
                                                              strings: new string[] { "Name", "Description" });

            {
                DynamicDataEntry card = new DynamicDataEntry(tcgCardType);

                card.SetBool("Instant", false);

                card.SetByte("Fire Cost", 2);
                card.SetByte("Water Cost", 0);
                card.SetByte("Rock Cost", 1);
                card.SetByte("Wind Cost", 7);

                card.SetInt("Health", 100);
                card.SetInt("Attack", -7);
                card.SetInt("Armor", 8);

                card.SetString("Name", "Silver Spear");
                card.SetString("Description", "A very straightforward card");

                TestEntry(card);
            }

            {
                DynamicDataEntry card = new DynamicDataEntry(tcgCardType);

                card.SetBool("Instant", false);

                card.SetByte("Fire Cost", 0);
                card.SetByte("Water Cost", 35);
                card.SetByte("Rock Cost", 1);
                card.SetByte("Wind Cost", 0);

                card.SetInt("Health", 0);
                card.SetInt("Attack", 99999);
                card.SetInt("Armor", -1);

                card.SetString("Name", "Guard Tower");
                card.SetString("Description", "This structure does a modest and reasonable amount of damage with its " +
                               "balanced attack level. This description is reasonably long as well and " +
                               "definitely isn't too long, certainly not too long in an attempt to test " +
                               "how the system handles splitting very long strings. No difficulties will" +
                               " be undertaken in the effort to reconstruct this string. Living on easy" +
                               " street is all we do here.");

                TestEntry(card);
            }
        }
Пример #4
0
        private void TestType(DynamicDataType type)
        {
            DynamicDataType secondType = new DynamicDataType("UNLOADED");

            // test the header
            int hlen     = type.GetHeaderLength();
            int hwritten = type.WriteHeader(Data, 0);

            Assert.AreEqual(hlen, hwritten);

            int hread = secondType.LoadHeader(Data, 0);

            Assert.AreEqual(hlen, hread);

            // affirm the results
            Assert.AreEqual(type.TypeName, secondType.TypeName);
            Assert.AreEqual(type.Bools, secondType.Bools);
            Assert.AreEqual(type.Bytes, secondType.Bytes);
            Assert.AreEqual(type.UShorts, secondType.UShorts);
            Assert.AreEqual(type.Ints, secondType.Ints);
            Assert.AreEqual(type.Floats, secondType.Floats);
            Assert.AreEqual(type.Doubles, secondType.Doubles);
            Assert.AreEqual(type.Strings, secondType.Strings);
            Assert.AreEqual(type.TotalCount, secondType.TotalCount);

            // test the names
            type.BeginNamesWrite();
            int npackets = type.GetNamesCount();

            for (int i = 0; i < npackets; i++)
            {
                int nlen     = type.GetNextNamesLength();
                int nwritten = type.WriteNextNames(Data, 0);
                Assert.AreEqual(nlen, nwritten);

                int nread = secondType.LoadNames(Data, 0);
                Assert.AreEqual(nlen, nread);
            }

            // affirm the results
            for (int i = 0; i < type.TotalCount; i++)
            {
                Assert.AreEqual(type.Names[i], secondType.Names[i]);
            }
        }
Пример #5
0
        public void ManyIntsReadWriteTest()
        {
            string[] ints = new string[100];
            for (int i = 0; i < ints.Length; i++)
            {
                ints[i] = i.ToString();
            }

            DynamicDataType manyIntsType = new DynamicDataType("Many Ints",
                                                               bools: new string[] { "Face Card" },
                                                               bytes: new string[] { "Value", "Suit" },
                                                               ints: ints);

            DynamicDataEntry card1 = new DynamicDataEntry(manyIntsType);

            card1.SetBool("Face Card", true);
            card1.SetByte("Value", 12);
            card1.SetByte("Suit", 3);
            for (int i = 0; i < ints.Length; i++)
            {
                card1.SetInt(ints[i], i);
            }

            TestEntry(card1);

            DynamicDataEntry card2 = new DynamicDataEntry(manyIntsType);

            card2.SetBool("Face Card", false);
            card2.SetByte("Value", 3);
            card2.SetByte("Suit", 1);
            for (int i = 0; i < ints.Length; i++)
            {
                card1.SetInt(ints[i], i * 2);
            }

            TestEntry(card2);

            DynamicDataEntry card3 = new DynamicDataEntry(manyIntsType);

            card3.SetBool("Face Card", false);
            card3.SetByte("Value", 8);
            card3.SetByte("Suit", 2);

            TestEntry(card3);
        }
Пример #6
0
        public void ManyIntsReadWriteTest()
        {
            string[] ints = new string[100];
            for (int i = 0; i < ints.Length; i++)
            {
                ints[i] = i.ToString();
            }

            DynamicDataType manyIntsType = new DynamicDataType("Many Ints",
                                                               bools: new string[] { "Face Card" },
                                                               bytes: new string[] { "Value", "Suit" },
                                                               ints: ints);

            DynamicDataEntry card1 = new DynamicDataEntry(manyIntsType);

            card1.SetBool("Face Card", true);
            card1.SetByte("Value", 12);
            card1.SetByte("Suit", 3);
            for (int i = 0; i < ints.Length; i++)
            {
                card1.SetInt(ints[i], i);
            }

            DynamicDataClone clone1 = new DynamicDataClone(card1);

            clone1.SetInt(ints[10], 55);
            clone1.SetInt(ints[11], 1003);
            clone1.SetInt(ints[56], 990002);
            clone1.SetByte("Suit", 5);

            DynamicDataClone clone2 = TestCloneFull(clone1);

            clone1.SetInt(ints[33], 60);
            clone1.SetInt(ints[10], 5);

            TestCloneStale(clone1, clone2);

            clone1.SetByte("Suit", 7);

            TestCloneStale(clone1, clone2);
        }
Пример #7
0
        public void BackToDefaultTest()
        {
            DynamicDataType tcgCardType = new DynamicDataType("Unit",
                                                              bools: new string[] { "Instant" },
                                                              bytes: new string[] { "Fire Cost" },
                                                              ints: new string[] { "Health", "Attack", "Armor" });

            {
                DynamicDataEntry card = new DynamicDataEntry(tcgCardType);

                card.SetBool("Instant", false);

                card.SetByte("Fire Cost", 2);

                card.SetInt("Health", 100);
                card.SetInt("Attack", -7);
                card.SetInt("Armor", 8);

                DynamicDataClone clone1 = new DynamicDataClone(card);
                clone1.SetBool("Instant", true);
                clone1.SetInt("Health", 99);
                clone1.SetByte("Fire Cost", 3);

                DynamicDataClone clone2 = TestCloneFull(clone1);

                // now set health back to default and see if it gets networked properly
                clone1.SetInt("Health", 100);

                TestCloneStale(clone1, clone2);

                // reset instant and fire cost and see if they are networked right
                clone1.SetBool("Instant", false);
                clone1.SetByte("Fire Cost", 2);

                TestCloneStale(clone1, clone2);
            }
        }
Пример #8
0
 public DynamicData(DynamicData[] array) : this()
 {
     _data = array;
     _type = DynamicDataType.Array;
 }
Пример #9
0
 public DynamicData(PropertyStore properties) : this()
 {
     _data = properties;
     _type = DynamicDataType.Properties;
 }
Пример #10
0
 public DynamicData(string text, DataConverter converter) : this()
 {
     _data       = text;
     _type       = DynamicDataType.String;
     _converters = converter;
 }
Пример #11
0
 public DynamicData(DataSchema schema) : this()
 {
     _type   = DynamicDataType.Null;
     _schema = schema;
 }
Пример #12
0
 public DynamicData()
 {
     _converters = DataConverter.CommonConverters;
     _type       = DynamicDataType.Null;
 }