public void Add(Recipe recipe)
 {
     if (recipe != null)
     {
         List<Recipe> tempList = new List<Recipe>();
         Clear();
         recipe.IsRoot = true;
         recipe.BuildRecipe(HotItemController);
         tempList.Add(recipe);
         Recipes = new ObservableCollection<Recipe>(tempList);
         SelectedRecipe = recipe;
     }
 }
Пример #2
0
        public void BuildRecipe(HotItemController c)
        {
            this.IsExpanded = true;
            if (c.ItemIdToDataId.ContainsKey(CreatedItemId))
            {
                Name = "loading...";
                this.DataId = c.ItemIdToDataId[CreatedItemId];
            }

            if (!IsRoot)
            {
                if (c.CreatedIdToRecipe.ContainsKey(ItemId))
                {
                    List<Recipe> tempList = new List<Recipe>();
                    for (int i = 0; i < c.CreatedIdToRecipe[ItemId].RecipeItems.Count; i++)
                    {
                        var r = c.CreatedIdToRecipe[ItemId].RecipeItems[i];
                        Recipe recipe = new Recipe(r.DataId, r.Quantity * this.Quantity);
                        recipe.ItemId = r.ItemId;
                        recipe.CreatedItemId = r.CreatedItemId;
                        recipe.RecipeItems = r.RecipeItems;
                        recipe.Name = "loading...";
                        tempList.Add(recipe);
                    }
                    RecipeItems = new ObservableCollection<Recipe>(tempList);
                }
            }

            c.RegisterRecipeItem(this);
            for (int i = 0; i < RecipeItems.Count; i++)
            {
                RecipeItems[i].BuildRecipe(c);
            }
        }
Пример #3
0
 public Recipe AddDeep(int dataId, int quantity)
 {
     Recipe r = new Recipe(dataId, quantity);
     RecipeItems.Add(r);
     return r;
 }
Пример #4
0
 public Recipe Add(Recipe recipe)
 {
     RecipeItems.Add(recipe);
     return recipe;
 }
Пример #5
0
        public static Recipe CreateSample()
        {
            Recipe r = new Recipe(13901, 1) { IsRoot = true };
            r.AddDeep(12973, 1).AddDeep(19712, 6).AddDeep(19725, 18);

            r.AddDeep(13261, 1).AddDeep(19712, 2).AddDeep(19725, 6);

            var o = r.AddDeep(19922, 1);
            var o2 = o.AddDeep(12988, 5);
            o2.AddDeep(19685, 15).AddDeep(19701, 30);
            o2.AddDeep(19712, 10).AddDeep(19725, 30);

            o.AddDeep(19721, 5);
            o.AddDeep(24289, 5);

            return r;
        }
        private void LoadRecipes()
        {
            String file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, recipesFile);
            if (File.Exists(file))
            {
                using (var streamReader = new StreamReader(file))
                {
                    using (var jsonTextReader = new JsonTextReader(streamReader))
                    {
                        JToken token = JObject.ReadFrom(jsonTextReader);
                        for (int i = 0; i < token.Count(); i++)
                        {
                            Recipe r = new Recipe()
                            {
                                Id = token[i]["ID"].ToObject<int>(),
                                ExternalId = token[i]["ExternalID"].ToObject<int>(),
                                DataId = token[i]["DataID"].ToObject<int>(),
                                Name = token[i]["Name"].ToObject<String>(),
                                Rating = token[i]["Rating"].ToObject<int>(),
                                Type = token[i]["Type"].ToObject<int>(),
                                Quantity = token[i]["Count"].ToObject<int>(),
                                CreatedItemId = token[i]["CreatedItemId"].ToObject<int>()
                            };

                            for (int j = 0; j < token[i]["Ingredients"].Count(); j++)
                            {
                                Recipe ingredients = new Recipe()
                                {
                                    ItemId = token[i]["Ingredients"][j]["ItemID"].ToObject<int>(),
                                    Quantity = token[i]["Ingredients"][j]["Count"].ToObject<int>(),
                                };

                                int dataId = ItemIdToDataId[ingredients.ItemId];
                                //SlimItem item = DataIdToSlimItem[dataId];
                                ingredients.DataId = dataId;

                                r.RecipeItems.Add(ingredients);
                            }

                            if (!CreatedIdToRecipe.ContainsKey(r.CreatedItemId))
                            {
                                CreatedIdToRecipe.Add(r.CreatedItemId, r);
                            }

                            RecipeIdToRecipe.Add(r.Id, r);

                            RecipeDB.Add(r);
                        }
                    }
                }
            }

            if (RecipesLoaded != null)
            {
                RecipesLoaded(this, new EventArgs());
            }
        }