Compare commits
No commits in common. "f1de5a7c6e7560ceab4ffc62f557df9efb01faa4" and "f4289dca70632ec9258cf61bf975e4268479c9b4" have entirely different histories.
f1de5a7c6e
...
f4289dca70
4 changed files with 140 additions and 33 deletions
|
@ -1,5 +1,13 @@
|
|||
local util = {}
|
||||
|
||||
function util.get_stack_size(default)
|
||||
if mods["Krastorio2"] then
|
||||
size = tonumber(settings.startup["kr-stack-size"].value)
|
||||
return size or default
|
||||
end
|
||||
return default
|
||||
end
|
||||
|
||||
-- se landfill
|
||||
-- params: ore, icon_size
|
||||
function util.se_landfill(params)
|
||||
|
@ -145,7 +153,9 @@ end
|
|||
function util.get_normal(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
recipe = data.raw.recipe[recipe_name]
|
||||
if recipe.ingredients then
|
||||
if recipe.normal and recipe.normal.ingredients then
|
||||
return recipe.normal
|
||||
elseif recipe.ingredients then
|
||||
return recipe
|
||||
end
|
||||
end
|
||||
|
@ -247,13 +257,17 @@ end
|
|||
|
||||
function util.set_enabled(recipe_name, enabled)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
data.raw.recipe[recipe_name].enabled = enabled
|
||||
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
|
||||
|
||||
function util.set_hidden(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
data.raw.recipe[recipe_name].hidden = true
|
||||
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
|
||||
|
||||
|
@ -261,6 +275,8 @@ end
|
|||
function util.add_or_add_to_ingredient(recipe_name, ingredient, quantity)
|
||||
if data.raw.recipe[recipe_name] and data.raw.item[ingredient] then
|
||||
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
|
||||
|
||||
|
@ -281,20 +297,22 @@ function util.add_ingredient(recipe_name, ingredient, quantity)
|
|||
local is_fluid = not not data.raw.fluid[ingredient]
|
||||
if data.raw.recipe[recipe_name] and (data.raw.item[ingredient] or is_fluid) then
|
||||
add_ingredient(data.raw.recipe[recipe_name], ingredient, quantity, is_fluid)
|
||||
add_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity, is_fluid)
|
||||
add_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity, is_fluid)
|
||||
end
|
||||
end
|
||||
|
||||
function add_ingredient(recipe, ingredient, quantity, is_fluid)
|
||||
if recipe ~= nil and recipe.ingredients ~= nil then
|
||||
for i, existing in pairs(recipe.ingredients) do
|
||||
if existing.name == ingredient then
|
||||
if existing[1] == ingredient or existing.name == ingredient then
|
||||
return
|
||||
end
|
||||
end
|
||||
if is_fluid then
|
||||
table.insert(recipe.ingredients, {type="fluid", name=ingredient, amount=quantity})
|
||||
else
|
||||
table.insert(recipe.ingredients, {type = "item", name = ingredient, amount = quantity})
|
||||
table.insert(recipe.ingredients, {ingredient, quantity})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -303,6 +321,8 @@ end
|
|||
function util.add_ingredient_raw(recipe_name, ingredient)
|
||||
if data.raw.recipe[recipe_name] and (data.raw.item[ingredient.name] or data.raw.item[ingredient[1]]) then
|
||||
add_ingredient_raw(data.raw.recipe[recipe_name], ingredient)
|
||||
add_ingredient_raw(data.raw.recipe[recipe_name].normal, ingredient)
|
||||
add_ingredient_raw(data.raw.recipe[recipe_name].expensive, ingredient)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -324,6 +344,8 @@ end
|
|||
function util.set_ingredient(recipe_name, ingredient, quantity)
|
||||
if data.raw.recipe[recipe_name] and data.raw.item[ingredient] then
|
||||
set_ingredient(data.raw.recipe[recipe_name], ingredient, quantity)
|
||||
set_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity)
|
||||
set_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -347,18 +369,25 @@ end
|
|||
-- Only works for recipes with multiple products
|
||||
function util.add_product(recipe_name, product)
|
||||
if data.raw.recipe[recipe_name] and
|
||||
(data.raw.item[product.name] or data.raw.fluid[product.name]) then
|
||||
local is_fluid = data.raw.fluid[product.name]
|
||||
add_product(data.raw.recipe[recipe_name], product, is_fluid)
|
||||
(data.raw.item[product[1]] or data.raw.item[product.name] or
|
||||
data.raw.fluid[product[1]] or data.raw.fluid[product.name]
|
||||
) then
|
||||
add_product(data.raw.recipe[recipe_name], product)
|
||||
add_product(data.raw.recipe[recipe_name].normal, product)
|
||||
add_product(data.raw.recipe[recipe_name].expensive, product)
|
||||
end
|
||||
end
|
||||
|
||||
function add_product(recipe, product, is_fluid)
|
||||
function add_product(recipe, product)
|
||||
if recipe ~= nil then
|
||||
if recipe.results == nil then
|
||||
recipe.results = {}
|
||||
if not recipe.normal then
|
||||
if recipe.results == nil then
|
||||
recipe.results = {{recipe.result, recipe.result_count and recipe.result_count or 1}}
|
||||
end
|
||||
recipe.result = nil
|
||||
recipe.result_count = nil
|
||||
table.insert(recipe.results, product)
|
||||
end
|
||||
table.insert(recipe.results, {type = is_fluid and "fluid" or "item", name = product.result, amount = product.result_count and product.result_count or 1})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -366,8 +395,14 @@ end
|
|||
function util.get_ingredient_amount(recipe_name, ingredient_name)
|
||||
local recipe = data.raw.recipe[recipe_name]
|
||||
if recipe then
|
||||
if recipe.ingredients then
|
||||
if recipe.normal and recipe.normal.ingredients then
|
||||
for i, ingredient in pairs(recipe.normal.ingredients) do
|
||||
if ingredient[1] == ingredient_name then return ingredient[2] end
|
||||
if ingredient.name == ingredient_name then return ingredient.amount end
|
||||
end
|
||||
elseif recipe.ingredients then
|
||||
for i, ingredient in pairs(recipe.ingredients) do
|
||||
if ingredient[1] == ingredient_name then return ingredient[2] end
|
||||
if ingredient.name == ingredient_name then return ingredient.amount end
|
||||
end
|
||||
end
|
||||
|
@ -381,10 +416,35 @@ function util.get_amount(recipe_name, product)
|
|||
if not product then product = recipe_name end
|
||||
local recipe = data.raw.recipe[recipe_name]
|
||||
if recipe then
|
||||
if recipe.results then
|
||||
for i, result in pairs(recipe.results) do
|
||||
if recipe.normal and recipe.normal.results then
|
||||
for i, result in pairs(recipe.normal.results) do
|
||||
if result[1] == product then return result[2] end
|
||||
if result.name == product then return result.amount end
|
||||
end
|
||||
elseif recipe.normal and recipe.normal.result_count then
|
||||
return recipe.normal.result_count
|
||||
elseif recipe.results then
|
||||
for i, result in pairs(recipe.results) do
|
||||
if result[1] == product then return result[2] end
|
||||
if result.name == product then return result.amount end
|
||||
end
|
||||
elseif recipe.result_count then
|
||||
return recipe.result_count
|
||||
end
|
||||
return 1
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
-- Get the count of results
|
||||
function util.get_result_count(recipe_name, product)
|
||||
if not product then product = recipe_name end
|
||||
local recipe = data.raw.recipe[recipe_name]
|
||||
if recipe then
|
||||
if recipe.normal and recipe.normal.results then
|
||||
return #(recipe.normal.results)
|
||||
elseif recipe.results then
|
||||
return #(recipe.results)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
@ -396,24 +456,38 @@ end
|
|||
function util.replace_ingredient(recipe_name, old, new, amount, multiply)
|
||||
if data.raw.recipe[recipe_name] and (data.raw.item[new] or data.raw.fluid[new]) then
|
||||
replace_ingredient(data.raw.recipe[recipe_name], old, new, amount, multiply)
|
||||
replace_ingredient(data.raw.recipe[recipe_name].normal, old, new, amount, multiply)
|
||||
replace_ingredient(data.raw.recipe[recipe_name].expensive, old, new, amount, multiply)
|
||||
end
|
||||
end
|
||||
|
||||
function replace_ingredient(recipe, old, new, amount, multiply)
|
||||
if recipe ~= nil and recipe.ingredients ~= nil then
|
||||
for i, existing in pairs(recipe.ingredients) do
|
||||
if existing.name == new then
|
||||
if existing[1] == new or existing.name == new then
|
||||
return
|
||||
end
|
||||
end
|
||||
for i, ingredient in pairs(recipe.ingredients) do
|
||||
if ingredient.name == old then
|
||||
ingredient.name = new
|
||||
if amount then
|
||||
if multiply then
|
||||
ingredient.amount = amount * ingredient.amount
|
||||
else
|
||||
ingredient.amount = amount
|
||||
end
|
||||
end
|
||||
end
|
||||
if ingredient[1] == old then
|
||||
ingredient[1] = new
|
||||
if amount then
|
||||
if multiply then
|
||||
ingredient[2] = amount * ingredient[2]
|
||||
else
|
||||
ingredient[2] = amount
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -423,6 +497,8 @@ end
|
|||
function util.remove_ingredient(recipe_name, old)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
remove_ingredient(data.raw.recipe[recipe_name], old)
|
||||
remove_ingredient(data.raw.recipe[recipe_name].normal, old)
|
||||
remove_ingredient(data.raw.recipe[recipe_name].expensive, old)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -430,7 +506,7 @@ function remove_ingredient(recipe, old)
|
|||
index = -1
|
||||
if recipe ~= nil and recipe.ingredients ~= nil then
|
||||
for i, ingredient in pairs(recipe.ingredients) do
|
||||
if ingredient.name == old then
|
||||
if ingredient.name == old or ingredient[1] == old then
|
||||
index = i
|
||||
break
|
||||
end
|
||||
|
@ -446,6 +522,8 @@ function util.replace_some_ingredient(recipe_name, old, old_amount, new, new_amo
|
|||
local is_fluid = not not data.raw.fluid[new]
|
||||
if data.raw.recipe[recipe_name] and (data.raw.item[new] or is_fluid) then
|
||||
replace_some_ingredient(data.raw.recipe[recipe_name], old, old_amount, new, new_amount, is_fluid)
|
||||
replace_some_ingredient(data.raw.recipe[recipe_name].normal, old, old_amount, new, new_amount, is_fluid)
|
||||
replace_some_ingredient(data.raw.recipe[recipe_name].expensive, old, old_amount, new, new_amount, is_fluid)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -472,6 +550,8 @@ end
|
|||
function util.set_product_amount(recipe_name, product, amount)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
set_product_amount(data.raw.recipe[recipe_name], product, amount)
|
||||
set_product_amount(data.raw.recipe[recipe_name].normal, product, amount)
|
||||
set_product_amount(data.raw.recipe[recipe_name].expensive, product, amount)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -508,6 +588,8 @@ end
|
|||
function util.multiply_recipe(recipe_name, multiple)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
multiply_recipe(data.raw.recipe[recipe_name], multiple)
|
||||
multiply_recipe(data.raw.recipe[recipe_name].normal, multiple)
|
||||
multiply_recipe(data.raw.recipe[recipe_name].expensive, multiple)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -557,8 +639,9 @@ end
|
|||
|
||||
-- Returns true if a recipe has an ingredient
|
||||
function util.has_ingredient(recipe_name, ingredient)
|
||||
return data.raw.recipe[recipe_name] and
|
||||
has_ingredient(data.raw.recipe[recipe_name], ingredient)
|
||||
return data.raw.recipe[recipe_name] and (
|
||||
has_ingredient(data.raw.recipe[recipe_name], ingredient) or
|
||||
has_ingredient(data.raw.recipe[recipe_name].normal, ingredient))
|
||||
end
|
||||
|
||||
function has_ingredient(recipe, ingredient)
|
||||
|
@ -576,6 +659,8 @@ end
|
|||
function util.remove_product(recipe_name, old)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
remove_product(data.raw.recipe[recipe_name], old)
|
||||
remove_product(data.raw.recipe[recipe_name].normal, old)
|
||||
remove_product(data.raw.recipe[recipe_name].expensive, old)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -597,6 +682,8 @@ end
|
|||
function util.set_main_product(recipe_name, product)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
set_main_product(data.raw.recipe[recipe_name], product)
|
||||
set_main_product(data.raw.recipe[recipe_name].normal, product)
|
||||
set_main_product(data.raw.recipe[recipe_name].expensive, product)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -610,6 +697,8 @@ end
|
|||
function util.replace_product(recipe_name, old, new)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
replace_product(data.raw.recipe[recipe_name], old, new)
|
||||
replace_product(data.raw.recipe[recipe_name].normal, old, new)
|
||||
replace_product(data.raw.recipe[recipe_name].expensive, old, new)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -651,6 +740,8 @@ end
|
|||
function util.set_recipe_time(recipe_name, time)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
set_recipe_time(data.raw.recipe[recipe_name], time)
|
||||
set_recipe_time(data.raw.recipe[recipe_name].normal, time)
|
||||
set_recipe_time(data.raw.recipe[recipe_name].expensive, time)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -666,6 +757,8 @@ end
|
|||
function util.multiply_time(recipe_name, factor)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
multiply_time(data.raw.recipe[recipe_name], factor)
|
||||
multiply_time(data.raw.recipe[recipe_name].normal, factor)
|
||||
multiply_time(data.raw.recipe[recipe_name].expensive, factor)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -681,6 +774,8 @@ end
|
|||
function util.add_time(recipe_name, amount)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
add_time(data.raw.recipe[recipe_name], amount)
|
||||
add_time(data.raw.recipe[recipe_name].normal, amount)
|
||||
add_time(data.raw.recipe[recipe_name].expensive, amount)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -779,6 +874,8 @@ end
|
|||
function util.add_to_ingredient(recipe, ingredient, amount)
|
||||
if data.raw.recipe[recipe] then
|
||||
add_to_ingredient(data.raw.recipe[recipe], ingredient, amount)
|
||||
add_to_ingredient(data.raw.recipe[recipe].normal, ingredient, amount)
|
||||
add_to_ingredient(data.raw.recipe[recipe].expensive, ingredient, amount)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -800,6 +897,8 @@ end
|
|||
function util.add_to_product(recipe_name, product, amount)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
add_to_product(data.raw.recipe[recipe_name], product, amount)
|
||||
add_to_product(data.raw.recipe[recipe_name].normal, product, amount)
|
||||
add_to_product(data.raw.recipe[recipe_name].expensive, product, amount)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -934,7 +1033,15 @@ function util.sum_products(recipe_name)
|
|||
end
|
||||
|
||||
function util.add_productivity(recipe)
|
||||
data.raw.recipe[recipe].allow_productivity = true
|
||||
for i, module in pairs(data.raw.module) do
|
||||
if module.effect then
|
||||
for effect_name, effect in pairs(module.effect) do
|
||||
if effect_name == "productivity" and effect.bonus > 0 and module.limitation and #module.limitation > 0 then
|
||||
table.insert(module.limitation, recipe)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return util
|
|
@ -65,6 +65,6 @@ data:extend({
|
|||
icon = "__Chromium__/graphics/icons/chromite-ore.png",
|
||||
subgroup = "raw-resource",
|
||||
order = "t-c-a",
|
||||
stack_size = 50
|
||||
stack_size = util.get_stack_size(50)
|
||||
},
|
||||
})
|
||||
|
|
|
@ -11,7 +11,7 @@ data:extend(
|
|||
group ="raw-material",
|
||||
subgroup = "chromium",
|
||||
order = "a",
|
||||
stack_size = 100
|
||||
stack_size = util.get_stack_size(100)
|
||||
},
|
||||
{
|
||||
type = "recipe",
|
||||
|
|
|
@ -22,7 +22,7 @@ data:extend({
|
|||
icon_size = 64,
|
||||
subgroup = "chromium",
|
||||
order = "b[chromium-plate]",
|
||||
stack_size = 100
|
||||
stack_size = util.get_stack_size(100)
|
||||
},
|
||||
{
|
||||
type = "recipe",
|
||||
|
@ -91,7 +91,7 @@ data:extend({
|
|||
icon_size = 64,
|
||||
subgroup = "chromium",
|
||||
order = "b[stainless-steel-plate]",
|
||||
stack_size = 100,
|
||||
stack_size = util.get_stack_size(100),
|
||||
},
|
||||
{
|
||||
type = "recipe",
|
||||
|
@ -147,7 +147,7 @@ data:extend({
|
|||
icon_size = 64,
|
||||
subgroup = "chromium",
|
||||
order = "c[chromel-r-fabric]",
|
||||
stack_size = 100,
|
||||
stack_size = util.get_stack_size(100),
|
||||
},
|
||||
{
|
||||
type = "recipe",
|
||||
|
@ -173,7 +173,7 @@ data:extend({
|
|||
icon_size = 128,
|
||||
subgroup = "intermediate-product",
|
||||
order = "v[basic-vehicle-frame]",
|
||||
stack_size = 100,
|
||||
stack_size = util.get_stack_size(100),
|
||||
},
|
||||
{
|
||||
type = "recipe",
|
||||
|
@ -199,7 +199,7 @@ data:extend({
|
|||
icon_size = 128,
|
||||
subgroup = "intermediate-product",
|
||||
order = "v[vehicle-frame]",
|
||||
stack_size = 100,
|
||||
stack_size = util.get_stack_size(100),
|
||||
},
|
||||
{
|
||||
type = "recipe",
|
||||
|
@ -232,7 +232,7 @@ data:extend({
|
|||
group = "intermediate-products",
|
||||
subgroup = inconel_subgroup,
|
||||
order = "i",
|
||||
stack_size = 100,
|
||||
stack_size = util.get_stack_size(100),
|
||||
},
|
||||
{
|
||||
type = "recipe",
|
||||
|
@ -261,7 +261,7 @@ end
|
|||
group = "intermediate-product",
|
||||
subgroup = automation_core3_subgroup,
|
||||
order = "d",
|
||||
stack_size = 50,
|
||||
stack_size = util.get_stack_size(50),
|
||||
},
|
||||
{
|
||||
type = "recipe",
|
||||
|
@ -295,7 +295,7 @@ data:extend({
|
|||
group = "intermediate-products",
|
||||
subgroup = turbines_blade_subgroup,
|
||||
order = "t",
|
||||
stack_size = 50,
|
||||
stack_size = util.get_stack_size(50),
|
||||
},
|
||||
{
|
||||
type = "recipe",
|
||||
|
@ -326,7 +326,7 @@ data:extend({
|
|||
group = "intermediate-products",
|
||||
subgroup = hrld_structure_subgroup,
|
||||
order = "h",
|
||||
stack_size = 50,
|
||||
stack_size = util.get_stack_size(50),
|
||||
},
|
||||
{
|
||||
type = "recipe",
|
||||
|
@ -349,7 +349,7 @@ data:extend({
|
|||
group = "intermediate-products",
|
||||
subgroup = "intermediate-product",
|
||||
order = "h",
|
||||
stack_size = 100,
|
||||
stack_size = util.get_stack_size(100),
|
||||
},
|
||||
{
|
||||
type = "recipe",
|
||||
|
@ -380,7 +380,7 @@ data:extend({
|
|||
group = "intermediate-products",
|
||||
subgroup = advanced_electric_motor_subgroup,
|
||||
order = "g",
|
||||
stack_size = 50,
|
||||
stack_size = util.get_stack_size(50),
|
||||
},
|
||||
{
|
||||
type = "recipe",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue