Example #1
0
        public void ChildShouldOverrideParent()
        {
            var s   = new ThingSerialization();
            var xml = @"
                <?xml version='1.0' encoding='utf-8'?>
                <ThingSerializationLayout xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'  xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
                    <Parents>
                        <Thing>
                            <Name>Floor</Name>
                            <Floor>true</Floor>
                            <Hitpoints>12345</Hitpoints>
                        </Thing>
                    </Parents>
                    <Things>
                        <Thing>
                            <Name>grass</Name>
                            <Sprite>colored_5</Sprite>
                            <TypeOfThing>Grass</TypeOfThing>
                            <BuildSite>true</BuildSite>
                            <Parent>Floor</Parent>
                            <Hitpoints>6789</Hitpoints>
                        </Thing>
                    </Things>
                </ThingSerializationLayout>
            ";

            var things = s.LoadFromString(xml);

            Assert.IsInstanceOf <ThingConfig[]>(things);
            Assert.AreEqual(1, things.Length);
            Assert.AreEqual(6789, things[0].Hitpoints);
        }
Example #2
0
        public void ShouldSetFactoryConfig()
        {
            var s   = new ThingSerialization();
            var xml = @"
                <?xml version='1.0' encoding='utf-8'?>
                <ThingSerializationLayout xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'  xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
                    <Parents>
                        <Thing>
                            <Name>factory</Name>
                        </Thing>
                    </Parents>
                    <Things>
                        <Thing>
                            <Name>grass</Name>
                            <Sprite>colored_5</Sprite>
                            <TypeOfThing>Grass</TypeOfThing>
                            <BuildSite>true</BuildSite>
                            <FactoryConfig>
                                <Produces>
                                    <TypeOfThing>Iron</TypeOfThing>
                                </Produces>
                            </FactoryConfig>
                            <Parent>factory</Parent>
                        </Thing>
                    </Things>
                </ThingSerializationLayout>
            ";

            var things = s.LoadFromString(xml);

            Assert.IsInstanceOf <ThingConfig[]>(things);
            Assert.AreEqual(1, things.Length);
            Assert.IsNotNull(things[0].FactoryConfig);
            Assert.AreEqual(1, things[0].FactoryConfig.Produces.Length);
        }
Example #3
0
        public void ShouldSetBuildConfig()
        {
            var s   = new ThingSerialization();
            var xml = @"
                <?xml version='1.0' encoding='utf-8'?>
                <ThingSerializationLayout xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'  xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
                    <Parents></Parents>
                    <Things>
                        <Thing>
                            <Name>grass</Name>
                            <Sprite>colored_5</Sprite>
                            <TypeOfThing>Grass</TypeOfThing>
                            <BuildSite>true</BuildSite>
                            <ConstructionConfig>
                                <Group>Floors</Group>
                                <Requires>None</Requires>
                            </ConstructionConfig>
                        </Thing>
                    </Things>
                </ThingSerializationLayout>
            ";

            var things = s.LoadFromString(xml);

            Assert.IsInstanceOf <ThingConfig[]>(things);
            Assert.AreEqual(1, things.Length);
            Assert.IsNotNull(things[0].ConstructionConfig);
            Assert.AreEqual(ConstructionGroup.Floors, things[0].ConstructionConfig.Group);
            Assert.AreEqual(TypeOfThing.None, things[0].ConstructionConfig.Requires);
        }
Example #4
0
        public void ShouldSetTileRuleConfig()
        {
            var s   = new ThingSerialization();
            var xml = @"
                <?xml version='1.0' encoding='utf-8'?>
                <ThingSerializationLayout xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'  xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
                    <Parents></Parents>
                    <Things>
                        <Thing>
                            <Name>grass</Name>
                            <Sprite>colored_5</Sprite>
                            <TypeOfThing>Grass</TypeOfThing>
                            <BuildSite>true</BuildSite>
                            <TileRuleConfig>
                                <Sprites>
                                    <string>colored_5</string>
                                    <string>colored_6</string>
                                    <string>colored_7</string>
                                </Sprites>
                                <Type>RandomTiles</Type>
                            </TileRuleConfig>
                        </Thing>
                    </Things>
                </ThingSerializationLayout>
            ";

            var things = s.LoadFromString(xml);

            Assert.IsInstanceOf <ThingConfig[]>(things);
            Assert.AreEqual(1, things.Length);
            Assert.IsNotNull(things[0].TileRuleConfig);
            Assert.AreEqual(3, things[0].TileRuleConfig.Sprites.Length);
            Assert.AreEqual("RandomTiles", things[0].TileRuleConfig.Type);
        }
Example #5
0
    static void SetupThings()
    {
        _thingSerialization = new ThingSerialization();
        var xml = Resources.Load <TextAsset>("Config/Things").text;

        _things          = _thingSerialization.LoadFromString(xml);
        _thingDictionary = _things.ToDictionary(t => t.TypeOfThing);
    }
Example #6
0
        public void ShouldGetThignsFromString()
        {
            var s   = new ThingSerialization();
            var xml = @"
                <?xml version='1.0' encoding='utf-8'?>
                <ThingSerializationLayout xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'  xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
                    <Parents></Parents>
                    <Things>
                        <Thing>
                            <Name>grass</Name>
                            <Sprite>colored_5</Sprite>
                            <TypeOfThing>Grass</TypeOfThing>
                            <BuildSite>true</BuildSite>
                        </Thing>
                    </Things>
                </ThingSerializationLayout>
            ";

            var things = s.LoadFromString(xml);

            Assert.IsInstanceOf <ThingConfig[]>(things);
            Assert.Greater(things.Length, 0);
        }