Skip to content

Commit

Permalink
Fix stdlib not checking for existing ingredients
Browse files Browse the repository at this point in the history
  • Loading branch information
notnotmelon committed Jun 26, 2024
1 parent 4bd7f9e commit c6a22ed
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/metas/recipe.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local table_insert = table.insert

---@class data.RecipePrototype
---@field public standardize fun(self: data.RecipePrototype): data.RecipePrototype
---@field public allow_productivity fun(self: data.RecipePrototype): data.RecipePrototype
Expand Down Expand Up @@ -79,7 +81,7 @@ metas.allow_productivity = function(self)
end

for module in pairs(productivity_modules) do
table.insert(module.limitation, self.name)
table_insert(module.limitation, self.name)
end

return self
Expand Down Expand Up @@ -118,7 +120,7 @@ metas.add_unlock = function(self, technology_name)
technology.effects = {}
end

table.insert(technology.effects, {type = 'unlock-recipe', recipe = self.name})
table_insert(technology.effects, {type = 'unlock-recipe', recipe = self.name})

self.enabled = false

Expand Down Expand Up @@ -199,15 +201,28 @@ metas.add_ingredient = function(self, ingredient)
ingredient = py.standardize_product(ingredient)
if not FLUID[ingredient.name] and not ITEM[ingredient.name] then
log('WARNING @ \'' .. self.name .. '\':add_ingredient(): Ingredient ' .. ingredient.name .. ' does not exist')
else
table.insert(self.ingredients, ingredient)
return self
end

-- Ensure that this ingredient does not already exist in this recipe.
-- If so, combine their amounts and catalyst amounts.
for _, existing in pairs(self.ingredients) do
if existing.name == ingredient.name and existing.type == ingredient.type then
if existing.amount and ingredient.amount then
existing.amount = existing.amount + ingredient.amount
existing.catalyst_amount = (existing.catalyst_amount or 0) + (ingredient.catalyst_amount or 0)
return self
end
end
end

table_insert(self.ingredients, ingredient)
return self
end

metas.add_result = function(self, result)
self:standardize()
table.insert(self.results, py.standardize_product(result))
table_insert(self.results, py.standardize_product(result))
return self
end

Expand Down

0 comments on commit c6a22ed

Please sign in to comment.