Ejemplo n.º 1
0
        private static void LoadXMLSettings(string file)
        {
            // Populate Defaults
            for (int i = 0; i <= byte.MaxValue; i++)
            {
                _tiles[i] = new TileProperty { Color = Colors.Magenta, ID = (byte)i, Name = "UNKNOWN" };
                _walls[i] = new ColorProperty { Color = Colors.Magenta, ID = (byte)i, Name = "UNKNOWN" };
            }
            _globals.Clear();
            _items.Clear();

            // load xml file
            var xmlSettings = XElement.Load(file);

            // read tiles
            foreach (var tile in xmlSettings.Elements("Tiles").Elements("Tile"))
            {
                var curTile = _tiles[(int)tile.Attribute("num")];

                curTile.IsFramed = ((bool?)tile.Attribute("isFramed") ?? false);
                curTile.IsSolid = ((bool?)tile.Attribute("isSolid") ?? false);
                curTile.IsSolidTop = ((bool?)tile.Attribute("isSolidTop") ?? false);
                curTile.Name = (string)tile.Attribute("name");
                curTile.Color = (Color)ColorConverter.ConvertFromString((string)tile.Attribute("color")) ;
            }

            // read walls
            foreach (var wall in xmlSettings.Elements("Walls").Elements("Wall"))
            {
                var curWall = _walls[(int)wall.Attribute("num")];
                curWall.Name = (string)wall.Attribute("name");
                curWall.Color = (Color)ColorConverter.ConvertFromString((string)wall.Attribute("color"));
            }

            // read items
            foreach (var item in xmlSettings.Elements("Items").Elements("Item"))
            {
                //var curItem = new ItemProperty
                //{
                //    Id = (int) item.Attribute("num"),
                //    Name = (string) item.Attribute("name")
                //};
                _items.Add((string)item.Attribute("name"));
            }

            // read global colors
            foreach (var globalColor in xmlSettings.Elements("GlobalColors").Elements("GlobalColor"))
            {
                _globals.Add((string)globalColor.Attribute("name"),(Color)ColorConverter.ConvertFromString((string)globalColor.Attribute("color")));
            }
        }
Ejemplo n.º 2
0
        private static void LoadXMLSettings(string file)
        {
            // Populate Defaults
            for (ushort i = 0; i <= byte.MaxValue; i++)
            {
                _tiles[i] = new TileProperty((byte)i);
                _walls[i] = new ColorProperty((byte)i);
            }
            _globals.Clear();
            _items.Clear();

            // load xml file
            var xmlSettings = XElement.Load(file);

            // read tiles
            foreach (var tile in xmlSettings.Elements("Tiles").Elements("Tile"))
            {
                var curTile = _tiles[(int)tile.Attribute("num")];

                curTile.CanMixFrames = curTile.XMLConvert(curTile.CanMixFrames, tile.Attribute("canMixFrames"));
                curTile.Color        = curTile.XMLConvert(curTile.Color,        tile.Attribute("color"));
                curTile.IsFramed     = curTile.XMLConvert(curTile.IsFramed,     tile.Attribute("isFramed"));
                ParseFrameAttributes(tile, curTile);

                if (tile.Elements().Any(x => x.Name == "Frames"))
                {
                    //byte c = 0;
                    foreach (var frame in tile.Elements("Frames").Elements("Frame"))
                    {
                        var curFrame = (FrameProperty)curTile.Clone();  // carry over the properties of the parent Tile
                        ParseFrameAttributes(frame, curFrame);
                        curTile.Frames.Add(curFrame);
                    }
                }
                else if (curTile.IsFramed)
                {
                    curTile.Frames.Add((FrameProperty)curTile);
                }
            }

            // read walls
            foreach (var wall in xmlSettings.Elements("Walls").Elements("Wall"))
            {
                var curWall   = _walls[(int)wall.Attribute("num")];
                curWall.ID    = curWall.XMLConvert(curWall.ID,    wall.Attribute("num"));
                curWall.Name  = curWall.XMLConvert(curWall.Name,  wall.Attribute("name"));
                curWall.Color = curWall.XMLConvert(curWall.Color, wall.Attribute("color"));
            }

            // read items
            foreach (var item in xmlSettings.Elements("Items").Elements("Item"))
            {

                var curItem = new ItemProperty();
                curItem.ID           = curItem.XMLConvert(curItem.ID,           item.Attribute("num"));
                curItem.Name         = curItem.XMLConvert(curItem.Name,         item.Attribute("name"));
                curItem.MaxStack     = curItem.XMLConvert(curItem.MaxStack,     item.Attribute("maxStack"));
                curItem.Description  = curItem.XMLConvert(curItem.Description,  item.Attribute("description"));
                curItem.Description2 = curItem.XMLConvert(curItem.Description2, item.Attribute("description2"));
                _items.Add(curItem);
                _itemNames.Add(curItem.Name);
            }

            // read global colors
            foreach (var global in xmlSettings.Elements("GlobalColors").Elements("GlobalColor"))
            {
                var curGlobal = new ColorProperty();
                curGlobal.Name  = curGlobal.XMLConvert(curGlobal.Name,  global.Attribute("name"));
                curGlobal.Color = curGlobal.XMLConvert(curGlobal.Color, global.Attribute("color"));
                _globals.Add(curGlobal.Name, curGlobal);
            }
        }
Ejemplo n.º 3
0
        private static void LoadXMLSettings(string file)
        {
            // Populate Defaults
            for (ushort i = 0; i <= byte.MaxValue; i++)
            {
                _tiles[i] = new TileProperty((byte)i);
                _walls[i] = new ColorProperty((byte)i);
            }
            _globals.Clear();
            _items.Clear();

            // load xml file
            var xmlSettings = XElement.Load(file);

            // read tiles
            foreach (var tile in xmlSettings.Elements("Tiles").Elements("Tile"))
            {
                var curTile = _tiles[(int)tile.Attribute("num")];

                curTile.CanMixFrames = curTile.XMLConvert(curTile.CanMixFrames, tile.Attribute("canMixFrames"));
                curTile.Color        = curTile.XMLConvert(curTile.Color, tile.Attribute("color"));
                curTile.IsFramed     = curTile.XMLConvert(curTile.IsFramed, tile.Attribute("isFramed"));
                ParseFrameAttributes(tile, curTile);

                if (tile.Elements().Any(x => x.Name == "Frames"))
                {
                    //byte c = 0;
                    foreach (var frame in tile.Elements("Frames").Elements("Frame"))
                    {
                        var curFrame = (FrameProperty)curTile.Clone();  // carry over the properties of the parent Tile
                        ParseFrameAttributes(frame, curFrame);
                        curTile.Frames.Add(curFrame);
                    }
                }
                else if (curTile.IsFramed)
                {
                    curTile.Frames.Add((FrameProperty)curTile);
                }
            }

            // read walls
            foreach (var wall in xmlSettings.Elements("Walls").Elements("Wall"))
            {
                var curWall = _walls[(int)wall.Attribute("num")];
                curWall.ID    = curWall.XMLConvert(curWall.ID, wall.Attribute("num"));
                curWall.Name  = curWall.XMLConvert(curWall.Name, wall.Attribute("name"));
                curWall.Color = curWall.XMLConvert(curWall.Color, wall.Attribute("color"));
            }

            // read items
            foreach (var item in xmlSettings.Elements("Items").Elements("Item"))
            {
                var curItem = new ItemProperty();
                curItem.ID           = curItem.XMLConvert(curItem.ID, item.Attribute("num"));
                curItem.Name         = curItem.XMLConvert(curItem.Name, item.Attribute("name"));
                curItem.MaxStack     = curItem.XMLConvert(curItem.MaxStack, item.Attribute("maxStack"));
                curItem.Description  = curItem.XMLConvert(curItem.Description, item.Attribute("description"));
                curItem.Description2 = curItem.XMLConvert(curItem.Description2, item.Attribute("description2"));
                _items.Add(curItem);
                _itemNames.Add(curItem.Name);
            }

            // read global colors
            foreach (var global in xmlSettings.Elements("GlobalColors").Elements("GlobalColor"))
            {
                var curGlobal = new ColorProperty();
                curGlobal.Name  = curGlobal.XMLConvert(curGlobal.Name, global.Attribute("name"));
                curGlobal.Color = curGlobal.XMLConvert(curGlobal.Color, global.Attribute("color"));
                _globals.Add(curGlobal.Name, curGlobal);
            }
        }