示例#1
0
        private static void AddParserTestStructs(TCODFileParser parser)
        {
            string[] strList = new string[3];
            strList[0] = "moo";
            strList[1] = "foo";
            strList[2] = "bar";

            TCODParserStructure item = parser.RegisterNewStructure("item_type");
            item.AddProperty("cost", TCODValueType.TCOD_TYPE_INT, true);
            item.AddProperty("weight", TCODValueType.TCOD_TYPE_FLOAT, true);
            item.AddProperty("deal_damage", TCODValueType.TCOD_TYPE_BOOL, true);
            item.AddProperty("damages", TCODValueType.TCOD_TYPE_DICE, true);
            item.AddProperty("color", TCODValueType.TCOD_TYPE_COLOR, true);
            item.AddProperty("damaged_color", TCODValueType.TCOD_TYPE_COLOR, true);
            item.AddProperty("damage_type", TCODValueType.TCOD_TYPE_STRING, true);
            item.AddValueList("list", strList, true);
            item.AddFlag("abstract");

            TCODParserStructure video = parser.RegisterNewStructure("video");
            video.AddProperty("mode", TCODValueType.TCOD_TYPE_STRING, true);
            video.AddProperty("fullscreen", TCODValueType.TCOD_TYPE_BOOL, true);

            TCODParserStructure input = parser.RegisterNewStructure("input");
            TCODParserStructure mouse = parser.RegisterNewStructure("mouse");
            mouse.AddProperty("sensibility", TCODValueType.TCOD_TYPE_FLOAT, true);
            input.AddSubStructure(mouse);
        }
示例#2
0
        public void DefaultParserTest()
        {
            using (TCODFileParser parser = new TCODFileParser())
            {
                AddParserTestStructs(parser);
                parser.Run("exampleConfig.txt");

                Assert.IsTrue(parser.GetIntProperty("item_type.cost") == 300);
                Assert.IsTrue(parser.GetFloatProperty("item_type.weight") == 3.5);
                Assert.IsTrue(parser.GetBoolProperty("item_type.deal_damage") == true);

                TCODDice testDice = new TCODDice(3, 6, 1, 2);
                Assert.IsTrue(parser.GetDiceProperty("item_type.damages") == testDice);

                Color color1 = Color.FromRGB(255, 0, 0);
                Color color2 = Color.FromRGB(128, 96, 96);
                Assert.IsTrue(parser.GetColorProperty("item_type.color") == color1);
                Assert.IsTrue(parser.GetColorProperty("item_type.damaged_color") == color2);
                Assert.IsTrue(parser.GetStringProperty("item_type.damage_type") == "slash");

                //parser.getValueList("list");
                //parser.GetFlag("abstract");
                Assert.IsTrue(parser.GetStringProperty("video.mode") == "800x600");
                Assert.IsTrue(parser.GetBoolProperty("video.fullscreen") == false);
                Assert.IsTrue(parser.GetFloatProperty("input.mouse.sensibility") == .5);
            }
        }
示例#3
0
        public void ImplementedParserTest()
        {
            TCODParserCallbackStruct callback = new TCODParserCallbackStruct(new NewStructureCallback(NewStructCallbackTest), new NewFlagCallback(NewFlagCallbackTest),
                                                                             new NewPropertyCallback(NewPropertyCallbackTest), new EndStructureCallback(EndStructCallbackTest),
                                                                             new ErrorCallback(ErrorCallbackTest));

            using (TCODFileParser parser = new TCODFileParser())
            {
                AddParserTestStructs(parser);
                parser.Run("exampleConfig.txt", ref callback);
            }
        }