Пример #1
0
        public EmbeddedData(string path = "assets/xmls")
        {
            bool loaded = false;

            ObjectTypeToElement = new ReadOnlyDictionary <ushort, XElement>(type2elem_obj = new Dictionary <ushort, XElement>());
            ObjectTypeToId      = new ReadOnlyDictionary <ushort, string>(type2id_obj = new Dictionary <ushort, string>());
            IdToObjectType      = new ReadOnlyDictionary <string, ushort>(id2type_obj = new Dictionary <string, ushort>(StringComparer.InvariantCultureIgnoreCase));
            TileTypeToElement   = new ReadOnlyDictionary <ushort, XElement>(type2elem_tile = new Dictionary <ushort, XElement>());
            TileTypeToId        = new ReadOnlyDictionary <ushort, string>(type2id_tile = new Dictionary <ushort, string>());
            IdToTileType        = new ReadOnlyDictionary <string, ushort>(id2type_tile = new Dictionary <string, ushort>(StringComparer.InvariantCultureIgnoreCase));
            Tiles        = new ReadOnlyDictionary <ushort, TileDesc>(tiles = new Dictionary <ushort, TileDesc>());
            Items        = new artic.ReadOnlyDictionary <ushort, Item>(items = new Dictionary <ushort, Item>());
            ObjectDescs  = new ReadOnlyDictionary <ushort, ObjectDesc>(objDescs = new Dictionary <ushort, ObjectDesc>());
            Portals      = new ReadOnlyDictionary <ushort, PortalDesc>(portals = new Dictionary <ushort, PortalDesc>());
            TypeToPet    = new ReadOnlyDictionary <ushort, PetStruct>(type2pet = new Dictionary <ushort, PetStruct>());
            IdToPetSkin  = new ReadOnlyDictionary <string, PetSkin>(id2pet_skin = new Dictionary <string, PetSkin>());
            SetTypeSkins = new ReadOnlyDictionary <ushort, SetTypeSkin>(setTypeSkins = new Dictionary <ushort, SetTypeSkin>());

            assign = new AutoAssign(this);

            addition = new XElement("Additions");

            string basePath = Path.Combine(AssemblyDirectory, path);

            string[] xmls = Directory.EnumerateFiles(basePath, "*.xml", SearchOption.AllDirectories).ToArray();
            try
            {
                for (int i = 0; i < xmls.Length; i++)
                {
                    _(xmls[i].Split('/')[1], i, xmls.Length);
                    using (Stream stream = File.OpenRead(xmls[i]))
                        ProcessXml(XElement.Load(stream));
                    if (i + 1 == xmls.Length)
                    {
                        loaded = true;
                    }
                }
            } catch (Exception ex)
            {
                log.Error(ex);
            }

            if (!loaded)
            {
                return;
            }

            _(path, xmls.Length);
            _($"addition{(addition.Elements().Count() > 1 ? "s" : "")}", addition.Elements().Count());
            _($"item{(items.Count > 1 ? "s" : "")}", items.Count);
            _($"tile{(tiles.Count > 1 ? "s" : "")}", tiles.Count);
            _($"object{(objDescs.Count > 1 ? "s" : "")}", objDescs.Count);
            _($"portal{(portals.Count > 1 ? "s" : "")}", portals.Count);
            _($"pet{(type2pet.Count > 1 ? "s" : "")}", type2pet.Count);
            _($"pet skin{(id2pet_skin.Count > 1 ? "s" : "")}", id2pet_skin.Count);
            _($"special themed item{(setTypeSkins.Count > 1 ? "s" : "")}", setTypeSkins.Count);
        }
Пример #2
0
        public XmlData(string path = "data")
        {
            ObjectTypeToElement = new ReadOnlyDictionary <ushort, XElement>(
                type2elem_obj   = new Dictionary <ushort, XElement>());

            ObjectTypeToId  = new ReadOnlyDictionary <ushort, string>(
                type2id_obj = new Dictionary <ushort, string>());
            IdToObjectType  = new ReadOnlyDictionary <string, ushort>(
                id2type_obj = new Dictionary <string, ushort>(StringComparer.InvariantCultureIgnoreCase));

            TileTypeToElement  = new ReadOnlyDictionary <ushort, XElement>(
                type2elem_tile = new Dictionary <ushort, XElement>());

            TileTypeToId     = new ReadOnlyDictionary <ushort, string>(
                type2id_tile = new Dictionary <ushort, string>());
            IdToTileType     = new ReadOnlyDictionary <string, ushort>(
                id2type_tile = new Dictionary <string, ushort>(StringComparer.InvariantCultureIgnoreCase));

            Tiles            = new ReadOnlyDictionary <ushort, TileDesc>(
                tiles        = new Dictionary <ushort, TileDesc>());
            Items            = new artic.ReadOnlyDictionary <ushort, Item>(
                items        = new Dictionary <ushort, Item>());
            ObjectDescs      = new ReadOnlyDictionary <ushort, ObjectDesc>(
                objDescs     = new Dictionary <ushort, ObjectDesc>());
            Portals          = new ReadOnlyDictionary <ushort, PortalDesc>(
                portals      = new Dictionary <ushort, PortalDesc>());
            TypeToPet        = new ReadOnlyDictionary <ushort, PetStruct>(
                type2pet     = new Dictionary <ushort, PetStruct>());
            IdToPetSkin      = new ReadOnlyDictionary <string, PetSkin>(
                id2pet_skin  = new Dictionary <string, PetSkin>());
            SetTypeSkins     = new ReadOnlyDictionary <ushort, SetTypeSkin>(
                setTypeSkins = new Dictionary <ushort, SetTypeSkin>());

            addition = new XElement("ExtData");

            assign = new AutoAssign(this);

            string basePath = Path.Combine(AssemblyDirectory, path);

            log.InfoFormat("Loading game data from '{0}'...", basePath);
            string[] xmls = Directory.EnumerateFiles(basePath, "*.xml", SearchOption.AllDirectories).ToArray();
            for (int i = 0; i < xmls.Length; i++)
            {
                log.InfoFormat("Loading '{0}'({1}/{2})...", xmls[i], i + 1, xmls.Length);
                using (Stream stream = File.OpenRead(xmls[i]))
                    ProcessXml(XElement.Load(stream));
            }
            log.Info("Finish loading game data.");
            log.InfoFormat("{0} Items", items.Count);
            log.InfoFormat("{0} Tiles", tiles.Count);
            log.InfoFormat("{0} Objects", objDescs.Count);
            log.InfoFormat("{0} Additions", addition.Elements().Count());
        }