private void BuildEntityMenu(ImGui gui, ref bool closed) { if (gui.BuildButton("Mass set assembler") && (closed = true)) { SelectObjectPanel.Select(Database.entities.all.Where(x => x.recipes.Count > 0), "Set assembler for all recipes", set => { DataUtils.FavouriteCrafter.AddToFavourite(set, 10); foreach (var recipe in GetRecipesRecursive()) { if (recipe.recipe.crafters.Contains(set)) { recipe.RecordUndo().entity = set; if (!set.energy.fuels.Contains(recipe.fuel)) { recipe.fuel = recipe.entity.energy.fuels.AutoSelect(DataUtils.FavouriteFuel); } } } }, DataUtils.FavouriteCrafter, false); } if (gui.BuildButton("Mass set fuel") && (closed = true)) { SelectObjectPanel.Select(Database.goods.all.Where(x => x.fuelValue > 0), "Set fuel for all recipes", set => { DataUtils.FavouriteFuel.AddToFavourite(set, 10); foreach (var recipe in GetRecipesRecursive()) { if (recipe.entity != null && recipe.entity.energy.fuels.Contains(set)) { recipe.RecordUndo().fuel = set; } } }, DataUtils.FavouriteFuel, false); } if (gui.BuildButton("Shopping list") && (closed = true)) { var shopList = new Dictionary <FactorioObject, int>(); foreach (var recipe in GetRecipesRecursive()) { if (recipe.entity != null) { shopList.TryGetValue(recipe.entity, out var prev); var count = MathUtils.Ceil(recipe.buildingCount); shopList[recipe.entity] = prev + count; if (recipe.parameters.modules.module != null) { shopList.TryGetValue(recipe.parameters.modules.module, out prev); shopList[recipe.parameters.modules.module] = prev + count * recipe.parameters.modules.count; } } } ShoppingListScreen.Show(shopList); } }
private void BuildShoppngList(RecipeRow recipeRoot) { var shopList = new Dictionary <FactorioObject, int>(); var recipes = recipeRoot == null?GetRecipesRecursive() : GetRecipesRecursive(recipeRoot); foreach (var recipe in recipes) { if (recipe.entity != null) { shopList.TryGetValue(recipe.entity, out var prev); var count = MathUtils.Ceil(recipe.buildingCount); shopList[recipe.entity] = prev + count; if (recipe.parameters.modules.modules != null) { foreach (var module in recipe.parameters.modules.modules) { shopList.TryGetValue(module.module, out prev); shopList[module.module] = prev + count * module.count; } } } } ShoppingListScreen.Show(shopList); }