示例#1
0
        public World(PackReader pack)
        {
            this.Regions = new List <Region>();

            Dictionary <int, PropClass> propClasses;

            using (var ms = pack.GetEntry(@"db\propdb.xml").GetDataAsStream())
                propClasses = PropClass.ReadFromXml(ms);

            FeaturesFile features;

            using (var ms = pack.GetEntry(@"features.xml.compiled").GetDataAsStream())
                features = new FeaturesFile(ms, "Regular, USA");

            using (var ms = pack.GetEntry(@"world\world.trn").GetDataAsStream())
                using (var trnReader = XmlReader.Create(ms))
                {
                    if (!trnReader.ReadToDescendant("regions"))
                    {
                        return;
                    }

                    using (var trnRegionsReader = trnReader.ReadSubtree())
                    {
                        var i = 1;
                        while (trnRegionsReader.ReadToFollowing("region"))
                        {
                            var workDir  = trnRegionsReader.GetAttribute("workdir");
                            var fileName = trnReader.GetAttribute("name");

                            Console.Write("\r".PadRight(70) + "\r");
                            Console.Write("Reading {0}: {1}...", i++, fileName);

                            var region = new Region(pack, workDir, fileName, propClasses, features);
                            this.Regions.Add(region);
                        }

                        Console.WriteLine("\r".PadRight(70) + "\r");
                    }
                }

            Regions = Regions.OrderBy(a => a.RegionId).ToList();
            Regions.ForEach(region =>
            {
                region.Areas = region.Areas.ToList();
                region.Areas.ForEach(area =>
                {
                    area.Props  = area.Props.OrderBy(prop => prop.PropId).ToList();
                    area.Events = area.Events.OrderBy(ev => ev.EventId).ToList();
                });
            });
        }
示例#2
0
        public static Dictionary <int, PropClass> ReadFromXml(Stream stream)
        {
            var result = new Dictionary <int, PropClass>();

            using (var reader = XmlReader.Create(stream))
            {
                while (reader.ReadToFollowing("PropClass"))
                {
                    var data = new PropClass();

                    data.ClassID    = Convert.ToInt32(reader.GetAttribute("ClassID"));
                    data.ClassName  = reader.GetAttribute("ClassName");
                    data.StringID   = reader.GetAttribute("StringID") ?? "";
                    data.UsedServer = (reader.GetAttribute("UsedServer").ToLower() == "true");

                    var extraXml = reader.GetAttribute("ExtraXML");
                    if (!string.IsNullOrWhiteSpace(extraXml))
                    {
                        if (!extraXml.Trim().EndsWith("/>") && !extraXml.Trim().EndsWith("</xml>"))
                        {
                            extraXml = extraXml.Trim('>') + "/>";
                        }

                        var xel = XElement.Parse(extraXml);
                        foreach (var attr in xel.Attributes())
                        {
                            data.ExtraXML[attr.Name.ToString()] = attr.Value;
                        }
                    }

                    result[data.ClassID] = data;
                }
            }

            return(result);
        }