From 77b53a87e76b7b0fb3ae279ab4a8b74c2ba44d2d Mon Sep 17 00:00:00 2001 From: Brevven Date: Sun, 9 Jan 2022 23:42:18 -0800 Subject: [PATCH] update --- data-util.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/data-util.lua b/data-util.lua index 9920d9e..431c6b8 100644 --- a/data-util.lua +++ b/data-util.lua @@ -77,14 +77,33 @@ function util.remove_prerequisite(technology_name, prerequisite) end end + -- Add an effect to a given technology function util.add_effect(technology_name, effect) local technology = data.raw.technology[technology_name] if technology then + if not technology.effects then technology.effects = {} end table.insert(technology.effects, effect) end end +-- remove recipe unlock effect from a given technology +function util.remove_recipe_effect(technology_name, recipe_name) + local technology = data.raw.technology[technology_name] + local index = -1 + if technology then + for i, effect in pairs(technology.effects) do + if effect.type == "unlock-recipe" and effect.recipe == recipe_name then + index = i + break + end + end + if index > -1 then + table.remove(technology.effects, index) + end + end +end + -- Set technology ingredients function util.set_tech_recipe(technology_name, ingredients) local technology = data.raw.technology[technology_name] @@ -93,6 +112,37 @@ function util.set_tech_recipe(technology_name, ingredients) end end +function util.set_enabled(recipe_name, enabled) + if data.raw.recipe[recipe_name] then + if data.raw.recipe[recipe_name].normal then data.raw.recipe[recipe_name].normal.enabled = enabled end + if data.raw.recipe[recipe_name].expensive then data.raw.recipe[recipe_name].expensive.enabled = enabled end + if not data.raw.recipe[recipe_name].normal then data.raw.recipe[recipe_name].enabled = enabled end + end +end + +-- Add a given quantity of ingredient to a given recipe +function util.add_or_add_to_ingredient(recipe_name, ingredient, quantity) + if me.bypass[recipe_name] then return end + if data.raw.recipe[recipe_name] and data.raw.item[ingredient] then + me.add_modified(recipe_name) + add_or_add_to_ingredient(data.raw.recipe[recipe_name], ingredient, quantity) + add_or_add_to_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity) + add_or_add_to_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity) + end +end + +function add_or_add_to_ingredient(recipe, ingredient, quantity) + if recipe ~= nil and recipe.ingredients ~= nil then + for i, existing in pairs(recipe.ingredients) do + if existing[1] == ingredient or existing.name == ingredient then + add_to_ingredient(recipe, ingredient, quantity) + return + end + end + table.insert(recipe.ingredients, {ingredient, quantity}) + end +end + -- Add a given quantity of ingredient to a given recipe function util.add_ingredient(recipe_name, ingredient, quantity) if me.bypass[recipe_name] then return end @@ -115,7 +165,6 @@ function add_ingredient(recipe, ingredient, quantity) table.insert(recipe.ingredients, {ingredient, quantity}) end end - -- Add a given quantity of product to a given recipe. -- Only works for recipes with multiple products function util.add_product(recipe_name, product) @@ -438,7 +487,7 @@ function add_to_ingredient(recipe, it, amount) return end if ingredient[1] == it then - ingredient[2] = ingredients[2] + amount + ingredient[2] = ingredient[2] + amount return end end