Example #1
0
        /// <summary>
        /// Loads the stage penalty descriptions from the given XML
        /// file and sets up the internal structures.
        /// </summary>
        static StagePenaltyInfo()
        {
            try
            {
                // Get the manifest string
                Stream stream = typeof(StagePenaltyInfo).Assembly
                                .GetManifestResourceStream("CuteGod.penalties.xml");

                // Create an XML reader out of it
                XmlTextReader    xml  = new XmlTextReader(stream);
                StagePenaltyInfo sp   = null;
                StagePenaltyType type = StagePenaltyType.Maximum;

                // Loop through the file
                while (xml.Read())
                {
                    // See if we finished a node
                    if (xml.NodeType == XmlNodeType.EndElement &&
                        xml.LocalName == "penalty")
                    {
                        hash[type] = sp;
                        sp         = null;
                    }

                    // Ignore all but start elements
                    if (xml.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    // Check for name
                    if (xml.LocalName == "penalty")
                    {
                        sp   = new StagePenaltyInfo();
                        type = (StagePenaltyType)Enum
                               .Parse(typeof(StagePenaltyType), xml["type"]);
                        sp.type = type;
                    }
                    else if (xml.LocalName == "title")
                    {
                        sp.Title = xml.ReadString();
                    }
                    else if (xml.LocalName == "block")
                    {
                        sp.BlockKey = xml.ReadString();
                    }
                    else if (xml.LocalName == "description")
                    {
                        sp.Description = xml.ReadString();
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error(typeof(StagePenaltyInfo),
                             "Cannot load penalties: {0}", e.Message);
                throw e;
            }
        }
Example #2
0
        /// <summary>
        /// Loads the stage penalty descriptions from the given XML
        /// file and sets up the internal structures.
        /// </summary>
        static StagePenaltyInfo()
        {
            try
            {
                // Get the manifest string
                Stream stream = typeof(StagePenaltyInfo).Assembly
                    .GetManifestResourceStream("CuteGod.penalties.xml");

                // Create an XML reader out of it
                XmlTextReader xml = new XmlTextReader(stream);
                StagePenaltyInfo sp = null;
                StagePenaltyType type = StagePenaltyType.Maximum;

                // Loop through the file
                while (xml.Read())
                {
                    // See if we finished a node
                    if (xml.NodeType == XmlNodeType.EndElement &&
                        xml.LocalName == "penalty")
                    {
                        hash[type] = sp;
                        sp = null;
                    }

                    // Ignore all but start elements
                    if (xml.NodeType != XmlNodeType.Element)
                        continue;

                    // Check for name
                    if (xml.LocalName == "penalty")
                    {
                        sp = new StagePenaltyInfo();
                        type = (StagePenaltyType) Enum
                            .Parse(typeof(StagePenaltyType), xml["type"]);
                        sp.type = type;
                    }
                    else if (xml.LocalName == "title")
                        sp.Title = xml.ReadString();
                    else if (xml.LocalName == "block")
                        sp.BlockKey = xml.ReadString();
                    else if (xml.LocalName == "description")
                        sp.Description = xml.ReadString();
                }
            }
            catch (Exception e)
            {
                Logger.Error(typeof(StagePenaltyInfo),
                    "Cannot load penalties: {0}", e.Message);
                throw e;
            }
        }