/// <summary> /// Try to add a recipe to the this <see cref="FactorioItem"/> /// </summary> /// <param name="item">Item to add reipe for</param> /// <param name="xmlData">Xml data for this item</param> /// <param name="knownItems">List of all known items</param> /// <param name="unknownItems">List of all unkown items</param> public static void TryAddRecipeData(FactorioItem item, XElement xmlData, List <FactorioItem> knownItems, List <FactorioItem> unknownItems) { if (xmlData.Descendants(XmlCraftingElement).FirstOrDefault() != null) { try { // Get a list of all recipe parts of XElement var recipes = xmlData.Descendants(XmlCraftingElement); foreach (var recipe in recipes) { // Id of the recipe item int id = Convert.ToInt32(recipe.Attribute(XmlCraftingAttributeId).Value); // Quantity of the recipe item int quantity = Convert.ToInt32(recipe.Attribute(XmlCraftingAttributeQuantity).Value); // Look for a known item with id of the recipe item FactorioItem recipeItem = knownItems.Find(i => i.Id == id); if (recipeItem != null) { item.AddRecipeItem(recipeItem, quantity); } // If the recipe item is not known create a dummy item with its id and add it to unkown items else if (unknownItems.Exists(i => i.Id == id) == false) { recipeItem = new FactorioItem(id); unknownItems.Add(recipeItem); item.AddRecipeItem(recipeItem, quantity); } } } catch (FormatException) { throw; } } }
/// <summary> /// Try creating a new item. Closing the window if successfull, else show error message. /// </summary> private void Ok_Click() { // Check if entries are existing if ( TxtItemName == "" || string.IsNullOrWhiteSpace(TxtItemName) || TxtItemOutput == null || TxtItemOutput == "" || TxtItemTime == null || TxtItemTime == "" ) { throw new ArgumentNullException("Enter a value."); } // Convert entries string name = TxtItemName; int output = Convert.ToInt32(TxtItemOutput); double time = Convert.ToDouble(TxtItemTime); CraftingType crafting = (CraftingType)Enum.Parse(typeof(CraftingType), SelectedCrafting); m_item.Name = name; m_item.CraftingOutput = output; m_item.CraftingTime = time; m_item.DefaultCraftingType = crafting; m_item.ImagePath = this.PicturePath; m_item.Recipe.Clear(); // Copy recipe from the dummy item to the original foreach (var recipeItem in m_itemDummy.Recipe) { m_item.AddRecipeItem(recipeItem.Key, recipeItem.Value); } if (m_itemDummy.Id == -1) { m_fLogic.Items.Add(m_item); } m_fLogic.SaveItems(); m_currentWindow?.Close(); }
private void AddRecipeItem() { int quantity = Convert.ToInt32(TxtRecipeQuantity); m_itemDummy.AddRecipeItem(SelectedComboBoxRecipeItem, quantity); }
public void AddRecipe(FactorioItem item, int quantity, FactorioItem recipeItem) { item.AddRecipeItem(recipeItem, quantity); }