diff --git a/data-util.lua b/data-util.lua index 37f09b8..630f4ee 100644 --- a/data-util.lua +++ b/data-util.lua @@ -111,11 +111,16 @@ function util.add_effect(technology_name, effect) end end +-- Add an effect to a given technology to unlock recipe +function util.add_unlock(technology_name, recipe) + util.add_effect(technology_name, {type="unlock-recipe", recipe=recipe}) +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 + if technology and technology.effects then for i, effect in pairs(technology.effects) do if effect.type == "unlock-recipe" and effect.recipe == recipe_name then index = i @@ -144,6 +149,14 @@ function util.set_enabled(recipe_name, enabled) end end +function util.set_hidden(recipe_name) + if data.raw.recipe[recipe_name] then + if data.raw.recipe[recipe_name].normal then data.raw.recipe[recipe_name].normal.hidden = true end + if data.raw.recipe[recipe_name].expensive then data.raw.recipe[recipe_name].expensive.hidden = true end + if not data.raw.recipe[recipe_name].normal then data.raw.recipe[recipe_name].hidden = true 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 @@ -269,6 +282,29 @@ function add_product(recipe, product) end end +function util.replace_ingredient_add_to(recipe_name, old, new) + if me.bypass[recipe_name] then return end + if data.raw.recipe[recipe_name] and (data.raw.item[new] or data.raw.fluid[new]) then + me.add_modified(recipe_name) + replace_ingredient_add_to(data.raw.recipe[recipe_name], old, new) + replace_ingredient_add_to(data.raw.recipe[recipe_name].normal, old, new) + replace_ingredient_add_to(data.raw.recipe[recipe_name].expensive, old, new) + end +end + +function replace_ingredient_add_to(recipe, old, new) + if recipe ~= nil and recipe.ingredients ~= nil then + for i, existing in pairs(recipe.ingredients) do + if existing[1] == new or existing.name == new then + add_to_ingredient(recipe, new, existing[2] and existing[2] or existing.amount) + remove_ingredient(recipe, old) + return + end + end + replace_ingredient(recipe, old, new) + end +end + -- Replace one ingredient with another in a recipe function util.replace_ingredient(recipe_name, old, new, amount) if me.bypass[recipe_name] then return end