예제 #1
0
        public static List<items> PopulateItems()
        {
            List<items> ItemList = new List<items>();

            string itemJSON = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "data", "en_US", "item.json"));
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            Dictionary<string, object> deserializedJSON = serializer.Deserialize<Dictionary<string, object>>(itemJSON);
            Dictionary<string, object> itemData = deserializedJSON["data"] as Dictionary<string, object>;

            foreach (KeyValuePair<string, object> item in itemData)
            {
                items newItem = new items();
                Dictionary<string, object> singularItemData = item.Value as Dictionary<string, object>;
                newItem.id = Convert.ToInt32(item.Key);
                newItem.name = singularItemData["name"] as string;
                newItem.description = singularItemData["description"] as string;

                Dictionary<string, object> goldData = singularItemData["gold"] as Dictionary<string, object>;
                newItem.price = Convert.ToInt32(goldData["total"]);
                newItem.sellprice = Convert.ToInt32(goldData["sell"]);

                Dictionary<string, object> imageData = singularItemData["image"] as Dictionary<string, object>;
                newItem.iconPath = imageData["full"] as string;

                ItemList.Add(newItem);
            }

            return ItemList;
        }
예제 #2
0
        public static List<items> PopulateItems()
        {
            var itemList = new List<items>();

            string itemJson =
                File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "data", "en_US", "item.json"));
            var serializer = new JavaScriptSerializer();
            var deserializedJson = serializer.Deserialize<Dictionary<string, object>>(itemJson);
            var itemData = deserializedJson["data"] as Dictionary<string, object>;

            if (itemData == null)
                return itemList;

            foreach (var item in itemData)
            {
                var singularItemData = item.Value as Dictionary<string, object>;
                if (singularItemData == null)
                    continue;

                var newItem = new items
                {
                    id = Convert.ToInt32(item.Key),
                    name = singularItemData["name"] as string,
                    description = singularItemData["description"] as string
                };

                var goldData = singularItemData["gold"] as Dictionary<string, object>;
                if (goldData != null)
                {
                    newItem.price = Convert.ToInt32(goldData["total"]);
                    newItem.sellprice = Convert.ToInt32(goldData["sell"]);
                }

                var imageData = singularItemData["image"] as Dictionary<string, object>;
                if (imageData != null)
                    newItem.iconPath = imageData["full"] as string;

                itemList.Add(newItem);
            }

            return itemList;
        }