public Recipe(BinaryReader reader) { Rarity = (RecipeRarity)reader.ReadInt32(); InternalName = reader.ReadString(); ExternalName = reader.ReadString(); Enhancement = reader.ReadString(); Item = new RecipeEntry[reader.ReadInt32() + 1]; for (int index1 = 0; index1 < Item.Length; ++index1) { Item[index1] = new RecipeEntry { Level = reader.ReadInt32(), BuyCost = reader.ReadInt32(), CraftCost = reader.ReadInt32(), BuyCostM = reader.ReadInt32(), CraftCostM = reader.ReadInt32() }; int num = reader.ReadInt32(); Item[index1].Salvage = new string[num + 1]; Item[index1].Count = new int[num + 1]; Item[index1].SalvageIdx = new int[num + 1]; for (int index2 = 0; index2 < Item[index1].Salvage.Length; ++index2) { Item[index1].Salvage[index2] = reader.ReadString(); Item[index1].Count[index2] = reader.ReadInt32(); Item[index1].SalvageIdx[index2] = reader.ReadInt32(); } } }
public Recipe(BinaryReader reader) { Rarity = (RecipeRarity)reader.ReadInt32(); InternalName = reader.ReadString(); ExternalName = reader.ReadString(); Enhancement = reader.ReadString(); Item = new RecipeEntry[reader.ReadInt32() + 1]; for (var index1 = 0; index1 < Item.Length; index1++) { Item[index1] = new RecipeEntry { Level = reader.ReadInt32(), BuyCost = reader.ReadInt32(), CraftCost = reader.ReadInt32(), BuyCostM = reader.ReadInt32(), CraftCostM = reader.ReadInt32() }; var num = reader.ReadInt32(); Item[index1].Salvage = new string[num + 1]; Item[index1].Count = new int[num + 1]; Item[index1].SalvageIdx = new int[num + 1]; for (var index2 = 0; index2 < Item[index1].Salvage.Length; ++index2) { Item[index1].Salvage[index2] = reader.ReadString(); Item[index1].Count[index2] = reader.ReadInt32(); Item[index1].SalvageIdx[index2] = reader.ReadInt32(); Item[index1].RecipeIdx[index2] = reader.ReadInt32(); } } //IsGeneric = reader.ReadBoolean(); //IsVirtual = reader.ReadBoolean(); //IsHidden = reader.ReadBoolean(); }
public async Task SaveMyRecipesItemAsync(RecipeEntry item, bool isNewItem = false) { var uri = new Uri(string.Format(Constants.RestUrl, string.Empty)); try { var json = JsonConvert.SerializeObject(item); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = null; if (isNewItem) { response = await client.PostAsync(uri, content); } else { response = await client.PutAsync(uri, content); } if (response.IsSuccessStatusCode) { Debug.WriteLine(@" MyRecipesItem successfully saved."); } } catch (Exception ex) { Debug.WriteLine(@" ERROR {0}", ex.Message); } }
public Recipe(ref Recipe iRecipe) { Rarity = iRecipe.Rarity; InternalName = iRecipe.InternalName; ExternalName = iRecipe.ExternalName; Enhancement = iRecipe.Enhancement; EnhIdx = iRecipe.EnhIdx; Item = new RecipeEntry[iRecipe.Item.Length]; IsVirtual = iRecipe.IsVirtual; IsGeneric = iRecipe.IsGeneric; IsHidden = iRecipe.IsHidden; for (var index1 = 0; index1 < iRecipe.Item.Length; index1++) { Item[index1] = new RecipeEntry { Level = iRecipe.Item[index1].Level, BuyCost = iRecipe.Item[index1].BuyCost, CraftCost = iRecipe.Item[index1].CraftCost, BuyCostM = iRecipe.Item[index1].BuyCostM, CraftCostM = iRecipe.Item[index1].CraftCostM, Salvage = new string[iRecipe.Item[index1].Salvage.Length], SalvageIdx = new int[iRecipe.Item[index1].Salvage.Length], Count = new int[iRecipe.Item[index1].Salvage.Length] }; for (var index2 = 0; index2 <= Item[index1].Salvage.Length - 1; ++index2) { Item[index1].Salvage[index2] = iRecipe.Item[index1].Salvage[index2]; Item[index1].SalvageIdx[index2] = iRecipe.Item[index1].SalvageIdx[index2]; Item[index1].Count[index2] = iRecipe.Item[index1].Count[index2]; } } }
private IEnumerator PopulateRecipesRoutine() { ClearExistingRecipes(); loadingText.text = "Loading..."; UnityWebRequest request = Postman.CreateGetRequest(Endpoints.instance.RECIPES()); yield return(request.SendWebRequest()); string response = request.downloadHandler.text; JSONNode json = JSON.Parse(response); foreach (JSONNode recipe in json) { RecipeEntry entry = Instantiate(recipeEntryPrefab.gameObject, scrollViewContent).GetComponent <RecipeEntry>(); entry.SetIngredients(recipe["ingredients"].AsArray); entry.SetParentDialog(this); entry.SetRecipeText(recipe["name"]); entry.SetSteps(recipe["steps"].AsArray); } loadingText.text = ""; }
public void EditRecipe(int id, RecipeEntry recipe) { var editRecipe = RecipeContext.Recipes.Find(id); editRecipe = recipe; RecipeContext.Recipes.Update(editRecipe); RecipeContext.SaveChanges(); }
int IComparer <RecipeEntry> .Compare(RecipeEntry x, RecipeEntry y) { if (x.entryStatus != y.entryStatus) { return(y.entryStatus - x.entryStatus); } if (x.flow != y.flow) { return(y.flow.CompareTo(x.flow)); } return(x.recipe.RecipeWaste().CompareTo(y.recipe.RecipeWaste())); }
public async Task <RecipeEntry> GetRecipe(string recipename) { var uri = new Uri(string.Format(Constants.RestUrl, recipename)); var response = await client.GetAsync(uri); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); Recipe = JsonConvert.DeserializeObject <RecipeEntry>(content); } return(Recipe); }
public string CreateRecipe(RecipeEntry recipe) { RecipeContext.Recipes.Add(recipe); RecipeContext.SaveChanges(); if (RecipeContext.SaveChanges() == 1) { return("Save Successful"); } else { return("Save Failed"); } }
private async void SaveButton_Clicked(object sender, EventArgs e) { myRecipe = new RecipeEntry(); // myRecipe.RecipeID = int.Parse(ID.Text); myRecipe.RecipeName = RecipeName.Text; myRecipe.Ingredients = Ingredients.Text; myRecipe.Notes = Notes.Text; myRecipe.ImageFilePath = ImageFilePath.Text; myRecipe.Category = Category.Text; _restService = new RestService(); await _restService.SaveMyRecipesItemAsync(myRecipe, true); }
public static void AddRecipe(RecipeEntry entry) { var ingredients = MakeElements(entry.ingredients); var results = MakeElements(entry.results); var fabricators = new List <Tag>(); if (entry.fabricator != null) { fabricators.Add(entry.fabricator); } if (entry.fabricators != null) { fabricators.AddRange(entry.fabricators.Select(x => x.ToTag())); } var firstFabricator = fabricators.Count > 0 ? fabricators[0].ToString() : "missing_fabricator"; var id = entry.id ?? ComplexRecipeManager.MakeRecipeID(firstFabricator, ingredients, results); Log.Spam($"Adding recipe {id}"); if (ingredients.Length == 0) { Log.Error($"Recipe {id} has no ingredients"); return; } if (results.Length == 0) { Log.Error($"Recipe {id} has no results"); return; } if (fabricators.Count == 0) { Log.Error($"Recipe {id} has no fabricator"); return; } var recipe = new ComplexRecipe(id, ingredients, results); recipe.time = entry.time; recipe.nameDisplay = entry.nameDisplay; recipe.description = entry.description; recipe.fabricators = fabricators; recipe.sortOrder = entry.sortOrder; recipe.requiredTech = entry.requiredTech; }
public RecipeEntry(RecipeEntry iRe) { Level = iRe.Level; BuyCost = iRe.BuyCost; CraftCost = iRe.CraftCost; BuyCostM = iRe.BuyCostM; CraftCostM = iRe.CraftCostM; Salvage = new string[iRe.Salvage.Length]; SalvageIdx = new int[iRe.Salvage.Length]; Count = new int[iRe.Salvage.Length]; for (int index = 0; index < iRe.Salvage.Length; ++index) { Salvage[index] = iRe.Salvage[index]; SalvageIdx[index] = iRe.SalvageIdx[index]; Count[index] = iRe.Count[index]; } }
public ActionResult Create([FromForm] RecipeEntry myRecipe) { try { if (!ModelState.IsValid) { return(View()); } _recipeRepository.CreateRecipe(myRecipe); return(RedirectToAction(nameof(Index))); } catch (Exception e) { Console.WriteLine(e); return(View()); } }
public ActionResult Edit(int id, RecipeEntry recipeEdited) { try { if (!ModelState.IsValid) { return(View()); } _recipeRepository.EditRecipe(id, recipeEdited); return(RedirectToAction(nameof(Index))); } catch (Exception e) { Console.WriteLine(e); return(View()); } }
int IComparer <RecipeEntry> .Compare(RecipeEntry x, RecipeEntry y) { if (x.entryStatus != y.entryStatus) { return(y.entryStatus - x.entryStatus); } if (x.entryStatus == EntryStatus.NotAccessibleWithCurrentMilestones) { var xMilestone = DataUtils.GetMilestoneOrder(x.recipe.id); var yMilestone = DataUtils.GetMilestoneOrder(y.recipe.id); if (xMilestone != yMilestone) { return(xMilestone.CompareTo(yMilestone)); } } if (x.flow != y.flow) { return(y.flow.CompareTo(x.flow)); } return(x.recipe.RecipeWaste(atCurrentMilestones).CompareTo(y.recipe.RecipeWaste(atCurrentMilestones))); }
public void Put(int id, [FromBody] RecipeEntry recipe) { _recipeRepository.EditRecipe(id, recipe); }
public void Post([FromBody] RecipeEntry recipe) { _recipeRepository.CreateRecipe(recipe); }
private void DrawRecipeEntry(ImGui gui, RecipeEntry entry, bool production) { var textcolor = SchemeColor.BackgroundText; var bgColor = SchemeColor.Background; var isBuilding = gui.isBuilding; var recipe = entry.recipe; var waste = recipe.RecipeWaste(); if (isBuilding) { if (entry.entryStatus == EntryStatus.NotAccessible) { bgColor = SchemeColor.None; textcolor = SchemeColor.BackgroundTextFaint; } else if (entry.flow > 0f) { bgColor = SchemeColor.Secondary; textcolor = SchemeColor.SecondaryText; } else if (waste > 0.95f) { bgColor = SchemeColor.Error; textcolor = SchemeColor.ErrorText; } } using (gui.EnterGroup(new Padding(0.5f), production ? RectAllocator.LeftRow : RectAllocator.RightRow, textcolor)) { using (gui.EnterFixedPositioning(4f, 0f, default)) { gui.allocator = RectAllocator.Stretch; gui.spacing = 0f; gui.BuildFactorioObjectButton(entry.recipe, 4f, MilestoneDisplay.Contained); gui.BuildText(DataUtils.FormatAmount(recipe.Cost(), UnitOfMeasure.None, "¥"), align: RectAlignment.Middle); } gui.AllocateSpacing(); gui.allocator = production ? RectAllocator.LeftAlign : RectAllocator.RightAlign; gui.BuildText(recipe.locName, wrap: true); if (recipe.ingredients.Length + recipe.products.Length <= 8) { using (gui.EnterRow()) { DrawIngredients(gui, entry.recipe); gui.allocator = RectAllocator.RightRow; DrawProducts(gui, entry.recipe); if (recipe.products.Length < 3 && recipe.ingredients.Length < 5) { gui.AllocateSpacing((3 - entry.recipe.products.Length) * 3f); } else if (recipe.products.Length < 3) { gui.allocator = RectAllocator.RemainigRow; } gui.BuildIcon(Icon.ArrowRight, 3f); } } else { using (gui.EnterRow()) DrawIngredients(gui, entry.recipe); using (gui.EnterRow()) { gui.BuildIcon(Icon.ArrowDownRight, 3f); gui.allocator = RectAllocator.RightRow; DrawProducts(gui, entry.recipe); } } var importance = CostAnalysis.Instance.GetBuildingAmount(recipe, entry.recipeFlow); if (importance != null) { gui.BuildText(importance, wrap: true); } } if (isBuilding) { var rect = gui.lastRect; if (entry.flow > 0f) { var percentFlow = MathUtils.Clamp(entry.flow / currentFlow, 0f, 1f); rect.Width *= percentFlow; gui.DrawRectangle(rect, SchemeColor.Primary); } else if (waste <= 0f) { bgColor = SchemeColor.Secondary; } else { rect.Width *= (1f - entry.recipe.RecipeWaste()); gui.DrawRectangle(rect, SchemeColor.Secondary); } gui.DrawRectangle(gui.lastRect, bgColor); } }
private void DrawRecipeEntry(ImGui gui, RecipeEntry entry, bool production) { var textcolor = SchemeColor.BackgroundText; var bgColor = SchemeColor.Background; var isBuilding = gui.isBuilding; var recipe = entry.recipe; var waste = recipe.RecipeWaste(atCurrentMilestones); if (isBuilding) { if (entry.entryStatus == EntryStatus.NotAccessible) { bgColor = SchemeColor.None; textcolor = SchemeColor.BackgroundTextFaint; } else if (entry.flow > 0f) { bgColor = SchemeColor.Secondary; textcolor = SchemeColor.SecondaryText; } } using (gui.EnterGroup(new Padding(0.5f), production ? RectAllocator.LeftRow : RectAllocator.RightRow, textcolor)) { using (gui.EnterFixedPositioning(4f, 0f, default)) { gui.allocator = RectAllocator.Stretch; gui.BuildFactorioObjectButton(entry.recipe, 4f, MilestoneDisplay.Contained); using (gui.EnterRow()) { gui.BuildIcon(Icon.Time); gui.BuildText(DataUtils.FormatAmount(entry.recipe.time, UnitOfMeasure.Second), align: RectAlignment.Middle); } var bh = CostAnalysis.Instance.GetBuildingHours(recipe, entry.recipeFlow); if (bh > 20) { gui.BuildText(DataUtils.FormatAmount(bh, UnitOfMeasure.None, suffix: "bh"), align: RectAlignment.Middle); if (gui.BuildButton(gui.lastRect, SchemeColor.None, SchemeColor.Grey) == ImGuiUtils.Event.MouseOver) { gui.ShowTooltip(g => g.BuildText("Building-hours.\nAmount of building-hours required for all researches", wrap: true)); } } } gui.AllocateSpacing(); gui.allocator = production ? RectAllocator.LeftAlign : RectAllocator.RightAlign; gui.BuildText(recipe.locName, wrap: true); if (recipe.ingredients.Length + recipe.products.Length <= 8) { using (gui.EnterRow()) { DrawIngredients(gui, entry.recipe); gui.allocator = RectAllocator.RightRow; DrawProducts(gui, entry.recipe); if (recipe.products.Length < 3 && recipe.ingredients.Length < 5) { gui.AllocateSpacing((3 - entry.recipe.products.Length) * 3f); } else if (recipe.products.Length < 3) { gui.allocator = RectAllocator.RemainigRow; } gui.BuildIcon(Icon.ArrowRight, 3f); } } else { using (gui.EnterRow()) DrawIngredients(gui, entry.recipe); using (gui.EnterRow()) { gui.BuildIcon(Icon.ArrowDownRight, 3f); gui.allocator = RectAllocator.RightRow; DrawProducts(gui, entry.recipe); } } } if (isBuilding) { var rect = gui.lastRect; if (entry.flow > 0f) { var percentFlow = MathUtils.Clamp(entry.flow / currentFlow, 0f, 1f); rect.Width *= percentFlow; gui.DrawRectangle(rect, SchemeColor.Primary); } else if (waste <= 0f) { bgColor = SchemeColor.Secondary; } else { rect.Width *= (1f - waste); gui.DrawRectangle(rect, SchemeColor.Secondary); } gui.DrawRectangle(gui.lastRect, bgColor); } }