up
This commit is contained in:
parent
db81ee44e2
commit
bbf1ce8aba
1 changed files with 54 additions and 50 deletions
104
data-util.lua
104
data-util.lua
|
@ -47,6 +47,10 @@ function util.is_foundry()
|
|||
return mods.bzfoundry and not me.get_setting("bzfoundry-minimal")
|
||||
end
|
||||
|
||||
function should_force(options)
|
||||
return options and options.force
|
||||
end
|
||||
|
||||
|
||||
function bypass(recipe_name)
|
||||
if me.bypass[recipe_name] then return true end
|
||||
|
@ -193,8 +197,8 @@ function util.set_hidden(recipe_name)
|
|||
end
|
||||
|
||||
-- Add a given quantity of ingredient to a given recipe
|
||||
function util.add_or_add_to_ingredient(recipe_name, ingredient, quantity)
|
||||
if bypass(recipe_name) then return end
|
||||
function util.add_or_add_to_ingredient(recipe_name, ingredient, quantity, options)
|
||||
if not should_force(options) and 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)
|
||||
|
@ -216,8 +220,8 @@ function add_or_add_to_ingredient(recipe, ingredient, quantity)
|
|||
end
|
||||
|
||||
-- Add a given quantity of ingredient to a given recipe
|
||||
function util.add_ingredient(recipe_name, ingredient, quantity)
|
||||
if bypass(recipe_name) then return end
|
||||
function util.add_ingredient(recipe_name, ingredient, quantity, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
local is_fluid = not not data.raw.fluid[ingredient]
|
||||
if data.raw.recipe[recipe_name] and (data.raw.item[ingredient] or is_fluid) then
|
||||
me.add_modified(recipe_name)
|
||||
|
@ -243,8 +247,8 @@ function add_ingredient(recipe, ingredient, quantity, is_fluid)
|
|||
end
|
||||
|
||||
-- Add a given ingredient prototype to a given recipe
|
||||
function util.add_ingredient_raw(recipe_name, ingredient)
|
||||
if bypass(recipe_name) then return end
|
||||
function util.add_ingredient_raw(recipe_name, ingredient, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] and (data.raw.item[ingredient.name] or data.raw.item[ingredient[1]]) then
|
||||
me.add_modified(recipe_name)
|
||||
add_ingredient_raw(data.raw.recipe[recipe_name], ingredient)
|
||||
|
@ -268,8 +272,8 @@ function add_ingredient_raw(recipe, ingredient)
|
|||
end
|
||||
|
||||
-- Set an ingredient to a given quantity
|
||||
function util.set_ingredient(recipe_name, ingredient, quantity)
|
||||
if bypass(recipe_name) then return end
|
||||
function util.set_ingredient(recipe_name, ingredient, quantity, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] and data.raw.item[ingredient] then
|
||||
me.add_modified(recipe_name)
|
||||
set_ingredient(data.raw.recipe[recipe_name], ingredient, quantity)
|
||||
|
@ -296,8 +300,8 @@ function set_ingredient(recipe, ingredient, quantity)
|
|||
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)
|
||||
if bypass(recipe_name) then return end
|
||||
function util.add_product(recipe_name, product, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] and
|
||||
(data.raw.item[product[1]] or data.raw.item[product.name] or
|
||||
data.raw.fluid[product[1]] or data.raw.fluid[product.name]
|
||||
|
@ -368,8 +372,8 @@ end
|
|||
|
||||
-- Replace one ingredient with another in a recipe
|
||||
-- Use amount to set an amount. If that amount is a multiplier instead of an exact amount, set multiply true.
|
||||
function util.replace_ingredient(recipe_name, old, new, amount, multiply)
|
||||
if bypass(recipe_name) then return end
|
||||
function util.replace_ingredient(recipe_name, old, new, amount, multiply, options)
|
||||
if not should_force(options) and 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(data.raw.recipe[recipe_name], old, new, amount, multiply)
|
||||
|
@ -411,8 +415,8 @@ function replace_ingredient(recipe, old, new, amount, multiply)
|
|||
end
|
||||
|
||||
-- Remove an ingredient from a recipe
|
||||
function util.remove_ingredient(recipe_name, old)
|
||||
if bypass(recipe_name) then return end
|
||||
function util.remove_ingredient(recipe_name, old, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] then
|
||||
me.add_modified(recipe_name)
|
||||
remove_ingredient(data.raw.recipe[recipe_name], old)
|
||||
|
@ -437,8 +441,8 @@ function remove_ingredient(recipe, old)
|
|||
end
|
||||
|
||||
-- Replace an amount of an ingredient in a recipe. Keep at least 1 of old.
|
||||
function util.replace_some_ingredient(recipe_name, old, old_amount, new, new_amount)
|
||||
if bypass(recipe_name) then return end
|
||||
function util.replace_some_ingredient(recipe_name, old, old_amount, new, new_amount, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
local is_fluid = not not data.raw.fluid[new]
|
||||
if data.raw.recipe[recipe_name] and (data.raw.item[new] or is_fluid) then
|
||||
me.add_modified(recipe_name)
|
||||
|
@ -468,10 +472,10 @@ function replace_some_ingredient(recipe, old, old_amount, new, new_amount, is_fl
|
|||
end
|
||||
|
||||
-- set the amount of a product.
|
||||
function util.set_product_amount(recipe_name, product, amount)
|
||||
function util.set_product_amount(recipe_name, product, amount, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if bypass(recipe_name) then return end
|
||||
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)
|
||||
|
@ -508,10 +512,10 @@ function set_product_amount(recipe, product, amount)
|
|||
end
|
||||
|
||||
-- multiply the cost, energy, and results of a recipe by a multiple
|
||||
function util.multiply_recipe(recipe_name, multiple)
|
||||
function util.multiply_recipe(recipe_name, multiple, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if bypass(recipe_name) then return end
|
||||
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)
|
||||
|
@ -581,10 +585,10 @@ function has_ingredient(recipe, ingredient)
|
|||
end
|
||||
|
||||
-- Remove a product from a recipe, WILL NOT remove the only product
|
||||
function util.remove_product(recipe_name, old)
|
||||
function util.remove_product(recipe_name, old, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if bypass(recipe_name) then return end
|
||||
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)
|
||||
|
@ -606,8 +610,8 @@ function remove_product(recipe, old)
|
|||
end
|
||||
end
|
||||
|
||||
function util.set_main_product(recipe_name, product)
|
||||
if bypass(recipe_name) then return end
|
||||
function util.set_main_product(recipe_name, product, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
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)
|
||||
|
@ -622,8 +626,8 @@ function set_main_product(recipe, product)
|
|||
end
|
||||
|
||||
-- Replace one product with another in a recipe
|
||||
function util.replace_product(recipe_name, old, new)
|
||||
if bypass(recipe_name) then return end
|
||||
function util.replace_product(recipe_name, old, new, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
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)
|
||||
|
@ -666,10 +670,10 @@ function util.remove_raw(t, name)
|
|||
end
|
||||
|
||||
-- Set energy required
|
||||
function util.set_recipe_time(recipe_name, time)
|
||||
function util.set_recipe_time(recipe_name, time, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if bypass(recipe_name) then return end
|
||||
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)
|
||||
|
@ -685,10 +689,10 @@ function set_recipe_time(recipe, time)
|
|||
end
|
||||
|
||||
-- Multiply energy required
|
||||
function util.multiply_time(recipe_name, factor)
|
||||
function util.multiply_time(recipe_name, factor, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if bypass(recipe_name) then return end
|
||||
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)
|
||||
|
@ -704,10 +708,10 @@ function multiply_time(recipe, factor)
|
|||
end
|
||||
|
||||
-- Add to energy required
|
||||
function util.add_time(recipe_name, amount)
|
||||
function util.add_time(recipe_name, amount, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if bypass(recipe_name) then return end
|
||||
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)
|
||||
|
@ -723,8 +727,8 @@ function add_time(recipe, amount)
|
|||
end
|
||||
|
||||
-- Set recipe category
|
||||
function util.set_category(recipe_name, category)
|
||||
if bypass(recipe_name) then return end
|
||||
function util.set_category(recipe_name, category, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] and data.raw["recipe-category"][category] then
|
||||
me.add_modified(recipe_name)
|
||||
data.raw.recipe[recipe_name].category = category
|
||||
|
@ -732,8 +736,8 @@ function util.set_category(recipe_name, category)
|
|||
end
|
||||
|
||||
-- Set recipe subgroup
|
||||
function util.set_subgroup(recipe_name, subgroup)
|
||||
if bypass(recipe_name) then return end
|
||||
function util.set_subgroup(recipe_name, subgroup, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] then
|
||||
me.add_modified(recipe_name)
|
||||
data.raw.recipe[recipe_name].subgroup = subgroup
|
||||
|
@ -741,16 +745,16 @@ function util.set_subgroup(recipe_name, subgroup)
|
|||
end
|
||||
|
||||
-- Set item subgroup
|
||||
function util.set_item_subgroup(item, subgroup)
|
||||
if bypass(item) then return end
|
||||
function util.set_item_subgroup(item, subgroup, options)
|
||||
if not should_force(options) and bypass(item) then return end -- imperfect, close enough for now?
|
||||
if data.raw.item[item] and data.raw["item-subgroup"][subgroup] then
|
||||
data.raw.item[item].subgroup = subgroup
|
||||
end
|
||||
end
|
||||
|
||||
-- Set recipe icons
|
||||
function util.set_icons(recipe_name, icons)
|
||||
if bypass(recipe_name) then return end
|
||||
function util.set_icons(recipe_name, icons, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] then
|
||||
me.add_modified(recipe_name)
|
||||
data.raw.recipe[recipe_name].icons = icons
|
||||
|
@ -808,12 +812,12 @@ function add_to_ingredient(recipe, it, amount)
|
|||
end
|
||||
end
|
||||
|
||||
function util.add_to_product(recipe, product, amount)
|
||||
if bypass(recipe) then return end
|
||||
if data.raw.recipe[recipe] then
|
||||
add_to_product(data.raw.recipe[recipe], product, amount)
|
||||
add_to_product(data.raw.recipe[recipe].normal, product, amount)
|
||||
add_to_product(data.raw.recipe[recipe].expensive, product, amount)
|
||||
function util.add_to_product(recipe_name, product, amount, options)
|
||||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
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
|
||||
|
||||
|
@ -936,7 +940,7 @@ function remove_prior_unlocks(tech, recipe)
|
|||
util.remove_recipe_effect(tech, recipe)
|
||||
if technology.prerequisites then
|
||||
for i, prerequisite in pairs(technology.prerequisites) do
|
||||
-- log("BZZZ removing prior unlocks, checking " .. prerequisite)
|
||||
-- log("BZZZ removing prior unlocks for " .. tech ..", checking " .. prerequisite) -- Handy Debug :|
|
||||
remove_prior_unlocks(prerequisite, recipe)
|
||||
end
|
||||
end
|
||||
|
@ -954,7 +958,7 @@ function util.replace_ingredients_prior_to(tech, old, new, multiplier)
|
|||
and (not recipe.hidden or recipe.hidden == 'true') -- probably don't want to change hidden recipes
|
||||
and string.sub(recipe.name, 1, 3) ~= 'se-' -- have to exlude SE in general :(
|
||||
then
|
||||
-- log("BZZZ due to 'enabled' replacing " .. old .. " with " .. new .." in " .. recipe.name)
|
||||
-- log("BZZZ due to 'enabled' replacing " .. old .. " with " .. new .." in " .. recipe.name) -- Handy Debug :|
|
||||
util.replace_ingredient(recipe.name, old, new, multiplier, true)
|
||||
end
|
||||
end
|
||||
|
@ -971,14 +975,14 @@ function replace_ingredients_prior_to(tech, old, new, multiplier)
|
|||
if technology.effects then
|
||||
for i, effect in pairs(technology.effects) do
|
||||
if effect.type == "unlock-recipe" then
|
||||
-- log("BZZZ replacing " .. old .. " with " .. new .." in " .. effect.recipe)
|
||||
-- log("BZZZ replacing " .. old .. " with " .. new .." in " .. effect.recipe) -- Handy Debug :|
|
||||
util.replace_ingredient(effect.recipe, old, new, multiplier, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
if technology.prerequisites then
|
||||
for i, prerequisite in pairs(technology.prerequisites) do
|
||||
-- log("BZZZ checking " .. prerequisite)
|
||||
-- log("BZZZ checking " .. prerequisite) -- Handy Debug :|
|
||||
replace_ingredients_prior_to(prerequisite, old, new, multiplier)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue