Category5.XmlSettingsFile.ReadMegaTileType C# (CSharp) Method

ReadMegaTileType() private static method

private static ReadMegaTileType ( XmlTextReader reader, Microsoft.Xna.Framework.Content.ContentManager content ) : void
reader System.Xml.XmlTextReader
content Microsoft.Xna.Framework.Content.ContentManager
return void
        private static void ReadMegaTileType(XmlTextReader reader, ContentManager content)
        {
            // TODO: add an "index" field to the tile description that you use for the flat level file, instead of basing it off order.

            string tempString;

            //Move to first attribute for this mega tile
            if (reader.MoveToFirstAttribute())
            {
                //Create a new mega tile type
                MegaTileType tempMegaType = new MegaTileType();

                //Loop through all attributes
                do
                {
                    //Get the attribute name
                    tempString = reader.Name.ToUpper();
                    try
                    {
                        //Check for all valid attributes
                        if (tempString == "NAME")
                        {
                            tempMegaType.Name = reader.Value;
                        }
                        else if (tempString == "NUMBER")
                        {
                            tempMegaType.Number = int.Parse(reader.Value);
                        }
                        else if (tempString == "WIDTH")
                        {
                            tempMegaType.Width = int.Parse(reader.Value);
                        }
                        else if (tempString == "HEIGHT")
                        {
                            tempMegaType.Height = int.Parse(reader.Value);
                        }
                        else if (tempString == "BACKGROUNDTEXTURE")
                        {
                            tempMegaType.BackgroundTexture = content.Load<Texture2D>(reader.Value);
                        }
                        else if (tempString == "CANHAVEROADS")
                        {
                            tempMegaType.CanHaveRoads = bool.Parse(reader.Value);
                        }
                        //Set all the road textures given the prefix to use for all of them
                        else if(tempString  == "ROADTEXTUREPREFIX"){
                            tempMegaType.RoadTexturePrefix = reader.Value;
                            tempMegaType.RoadHorizontalTexture = content.Load<Texture2D>(reader.Value + roadHorizonalSuffix);
                            tempMegaType.RoadVerticalTexture = content.Load<Texture2D>(reader.Value + roadVerticalSuffix);
                            tempMegaType.Road4WayTexture = content.Load<Texture2D>(reader.Value + road4WaySuffix);
                        }
                        else if (tempString == "ROADHORIZONTALTEXTURE")
                        {
                            tempMegaType.RoadHorizontalTexture = content.Load<Texture2D>(reader.Value);
                        }
                        else if (tempString == "ROADVERTICALTEXTURE")
                        {
                            tempMegaType.RoadVerticalTexture = content.Load<Texture2D>(reader.Value);
                        }
                        else if (tempString == "ROADWIDTH")
                        {
                            tempMegaType.RoadWidth = int.Parse(reader.Value);
                        }
                        else
                        {
                            throw new ApplicationException("Invalid Mega Tile Type attribute '" + tempString + "' on line " + reader.LineNumber);
                        }
                    }
                    catch (Exception e)
                    {
                        throw new ApplicationException("Error parsing Mega Tile Type attribute on line " + reader.LineNumber +
                                ": " + e.Message);
                    }

                } while (reader.MoveToNextAttribute());

                //Look for nested elements
                string attName;
                while (!(reader.NodeType == XmlNodeType.EndElement && reader.Name.ToUpper() == "MEGATILETYPE"))
                {
                    reader.Read();
                    reader.MoveToContent();

                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        tempString = reader.Name.ToUpper();

                        //Look for valid Victim type sub-elements
                        if (tempString == "VICTIM")
                        {
                            MegaTileVictimConfig mtvConfig = ReadMegaTileVictimConfig(reader, content);

                            tempMegaType.PossibleVictims.Add(mtvConfig);

                        }
                        else
                        {
                            throw new ApplicationException("Invalid Mega Tile Type Sub-Element '" + tempString + "' on line " + reader.LineNumber);
                        }
                    }

                }

                //Add the Mega tile type to the list
                megaTileTypes.Add(tempMegaType);
            }
        }