Пример #1
0
            private void loadList(string listName)
            {
                try
                {
                    string appdir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                    XmlDocument doc = new XmlDocument();
                    doc.Load(File.OpenRead(Path.Combine(Path.Combine(appdir, "SavedObjectInfo"), Path.ChangeExtension(listName, ".xml"))));

                    XmlNodeList itemNodes = doc.GetElementsByTagName("item");

                    string[] attributeNames = new string[] {
                        "oid",
                        "iid",
                        "x",
                        "y",
                        "itemname",
                        "icon"
                    };

                    foreach (XmlNode n in itemNodes)
                    {
                        Dictionary<string, string> dict = new Dictionary<string, string>();

                        dict = getAttributes(attributeNames, dict, n);

                        string name = dict["itemname"];
                        string iconName = dict["icon"];
                        uint oid = uint.Parse(dict["oid"], System.Globalization.NumberStyles.HexNumber, null);
                        uint iid = uint.Parse(dict["iid"], System.Globalization.NumberStyles.HexNumber, null);

                        // test stuff not part of a settlement
                        /*
                        if (SettlementInfoLookup.SettlementToItemList.ContainsKey(iid))
                        {
                            continue;
                        }
                        */
                        
                        string category = getName(null, n);
                        if (!_categories.Contains(category)) _categories.Add(category);

                        if (_totalCountByCategory.ContainsKey(category)) _totalCountByCategory[category] = _totalCountByCategory[category] + 1;
                        else _totalCountByCategory.Add(category, 1);

                        double x = double.Parse(dict["x"], System.Globalization.CultureInfo.InvariantCulture);
                        double y = double.Parse(dict["y"], System.Globalization.CultureInfo.InvariantCulture);
                        bool bitSet = false;
                        if (n.Attributes["set"] != null)
                        {
                            if(n.Attributes["set"].Value.ToLowerInvariant() == "true" || n.Attributes["set"].Value == "1") bitSet = true;
                        }

                        ulong id = oid;
                        id <<= 32;
                        id |= iid;

                        SavedObjectInfo soi = new SavedObjectInfo(oid, iid, x, y, category, name, iconName, bitSet);
                        
                        _items.Add(id, soi);
                    }
                }
                catch {
                    throw;
                }
            }        
Пример #2
0
            private void loadList(string listName)
            {
                try
                {
                    string appdir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                    XmlDocument doc = new XmlDocument();
                    doc.Load(File.OpenRead(Path.Combine(Path.Combine(appdir, "SavedObjectInfo"), Path.ChangeExtension(listName, ".xml"))));

                    XmlNodeList itemNodes = doc.GetElementsByTagName("item");

                    string[] attributeNames = new string[] {
                        "oid",
                        "iid",
                        "x",
                        "y",
                        "itemname",
                        "icon"
                    };

                    foreach (XmlNode n in itemNodes)
                    {
                        Dictionary <string, string> dict = new Dictionary <string, string>();

                        dict = getAttributes(attributeNames, dict, n);

                        string name     = dict["itemname"];
                        string iconName = dict["icon"];
                        uint   oid      = uint.Parse(dict["oid"], System.Globalization.NumberStyles.HexNumber, null);
                        uint   iid      = uint.Parse(dict["iid"], System.Globalization.NumberStyles.HexNumber, null);

                        // test stuff not part of a settlement

                        /*
                         * if (SettlementInfoLookup.SettlementToItemList.ContainsKey(iid))
                         * {
                         *  continue;
                         * }
                         */

                        string category = getName(null, n);
                        if (!_categories.Contains(category))
                        {
                            _categories.Add(category);
                        }

                        if (_totalCountByCategory.ContainsKey(category))
                        {
                            _totalCountByCategory[category] = _totalCountByCategory[category] + 1;
                        }
                        else
                        {
                            _totalCountByCategory.Add(category, 1);
                        }

                        double x      = double.Parse(dict["x"], System.Globalization.CultureInfo.InvariantCulture);
                        double y      = double.Parse(dict["y"], System.Globalization.CultureInfo.InvariantCulture);
                        bool   bitSet = false;
                        if (n.Attributes["set"] != null)
                        {
                            if (n.Attributes["set"].Value.ToLowerInvariant() == "true" || n.Attributes["set"].Value == "1")
                            {
                                bitSet = true;
                            }
                        }

                        ulong id = oid;
                        id <<= 32;
                        id  |= iid;

                        SavedObjectInfo soi = new SavedObjectInfo(oid, iid, x, y, category, name, iconName, bitSet);

                        _items.Add(id, soi);
                    }
                }
                catch {
                    throw;
                }
            }