Fix trying to add ingredients to recipes that already have them.

This commit is contained in:
Amuxix 2023-04-16 23:35:53 +01:00
parent 30d9f83a0d
commit 9ebf6572fb

View file

@ -1,18 +1,28 @@
if settings.startup['overhaul_mode'].value then if settings.startup['overhaul_mode'].value then
-- indent ignored -- indent ignored
local function add_ingredient(ingredients, item, item_amount)
for _, ingredient in ipairs(ingredients) do
if ingredient.name == item then
ingredient.amount = math.max(ingredient.amount, item_amount)
return --leave early if we already found this ingredient
end
end
table.insert(ingredients, {type="item", name=item, amount=item_amount})
end
local function add_to_recipe(recipe, item, item_amount) local function add_to_recipe(recipe, item, item_amount)
if not data.raw.recipe[recipe] then if not data.raw.recipe[recipe] then
return return
end end
if data.raw.recipe[recipe].ingredients then if data.raw.recipe[recipe].ingredients then
table.insert(data.raw.recipe[recipe].ingredients, {type="item", name=item, amount=item_amount}) add_ingredient(data.raw.recipe[recipe].ingredients, item, item_amount )
end end
if data.raw.recipe[recipe].normal and data.raw.recipe[recipe].expensive then if data.raw.recipe[recipe].normal and data.raw.recipe[recipe].expensive then
table.insert(data.raw.recipe[recipe].normal.ingredients, {type="item", name=item, amount=item_amount}) add_ingredient(data.raw.recipe[recipe].normal.ingredients, item, item_amount )
table.insert(data.raw.recipe[recipe].expensive.ingredients, {type="item", name=item, amount=item_amount}) add_ingredient(data.raw.recipe[recipe].expensive.ingredients, item, item_amount )
end end
end end