bypass setting
This commit is contained in:
parent
1f042c54bf
commit
85c7992605
5 changed files with 162 additions and 90 deletions
|
|
@ -1,4 +1,9 @@
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
|
Version: 0.12.0
|
||||||
|
Date: 2021-06-16
|
||||||
|
Features:
|
||||||
|
- Bypass setting
|
||||||
|
---------------------------------------------------------------------------------------------------
|
||||||
Version: 0.11.0
|
Version: 0.11.0
|
||||||
Date: 2021-06-14
|
Date: 2021-06-14
|
||||||
Features:
|
Features:
|
||||||
|
|
|
||||||
232
data-util.lua
232
data-util.lua
|
|
@ -1,22 +1,52 @@
|
||||||
local data_util = {}
|
local util = {}
|
||||||
|
|
||||||
data_util.titanium_plate = ""
|
util.name = "bztitanium"
|
||||||
data_util.titanium_processing = ""
|
util.titanium_plate = ""
|
||||||
|
util.titanium_processing = ""
|
||||||
|
|
||||||
if mods["FactorioExtended-Plus-Core"] then
|
if mods["FactorioExtended-Plus-Core"] then
|
||||||
data_util.titanium_plate = "titanium-alloy"
|
util.titanium_plate = "titanium-alloy"
|
||||||
else
|
else
|
||||||
data_util.titanium_plate = "titanium-plate"
|
util.titanium_plate = "titanium-plate"
|
||||||
end
|
end
|
||||||
|
|
||||||
if mods["pyrawores"] then
|
if mods["pyrawores"] then
|
||||||
data_util.titanium_processing = "titanium-mk01"
|
util.titanium_processing = "titanium-mk01"
|
||||||
else
|
else
|
||||||
data_util.titanium_processing = "titanium-processing"
|
util.titanium_processing = "titanium-processing"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function util.steel_to_titanium(name)
|
||||||
|
util.replace_ingredient(name, "steel-plate", util.titanium_plate)
|
||||||
|
end
|
||||||
|
|
||||||
function data_util.get_stack_size(default)
|
function util.add_titanium_ingredient(amount, name)
|
||||||
|
util.add_ingredient(name, util.titanium_plate, amount)
|
||||||
|
end
|
||||||
|
|
||||||
|
function util.rare_to_titanium(name)
|
||||||
|
util.replace_ingredient(name, "rare-metals", util.titanium_plate)
|
||||||
|
end
|
||||||
|
|
||||||
|
function util.add_titanium_prerequisite(name)
|
||||||
|
util.add_prerequisite(name, util.titanium_processing)
|
||||||
|
end
|
||||||
|
|
||||||
|
function util.get_setting(name)
|
||||||
|
if settings.startup[name] == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return settings.startup[name].value
|
||||||
|
end
|
||||||
|
|
||||||
|
local bypass = {}
|
||||||
|
if util.get_setting(util.name.."-recipe-bypass") then
|
||||||
|
for recipe in string.gmatch(util.get_setting(util.name.."-recipe-bypass"), '[^",%s]+') do
|
||||||
|
bypass[recipe] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function util.get_stack_size(default)
|
||||||
if mods["Krastorio2"] then
|
if mods["Krastorio2"] then
|
||||||
size = tonumber(krastorio.general.getSafeSettingValue("kr-stack-size"))
|
size = tonumber(krastorio.general.getSafeSettingValue("kr-stack-size"))
|
||||||
return size or default
|
return size or default
|
||||||
|
|
@ -24,62 +54,64 @@ function data_util.get_stack_size(default)
|
||||||
return default
|
return default
|
||||||
end
|
end
|
||||||
|
|
||||||
function data_util.steel_to_titanium(name)
|
-- check if a table contains a sought value
|
||||||
data_util.replace_ingredient(name, "steel-plate", data_util.titanium_plate)
|
function util.contains(table, sought)
|
||||||
end
|
for i, value in pairs(table) do
|
||||||
|
if value == sought then
|
||||||
function data_util.add_titanium_ingredient(amount, name)
|
return true
|
||||||
data_util.add_ingredient(name, data_util.titanium_plate, amount)
|
|
||||||
end
|
|
||||||
|
|
||||||
function data_util.rare_to_titanium(name)
|
|
||||||
data_util.replace_ingredient(name, "rare-metals", data_util.titanium_plate)
|
|
||||||
end
|
|
||||||
|
|
||||||
function data_util.add_titanium_prerequisite(name)
|
|
||||||
data_util.add_prerequisite(name, data_util.titanium_processing)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Remove an element of type t and name from data.raw
|
|
||||||
function data_util.remove_raw(t, name)
|
|
||||||
for i, elem in pairs(data.raw[t]) do
|
|
||||||
if elem.name == name then
|
|
||||||
data.raw[t][i] = nil
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
return false
|
||||||
|
|
||||||
-- Set technology recipe
|
|
||||||
function data_util.set_tech_recipe(technology_name, ingredients)
|
|
||||||
if data.raw.technology[technology_name] then
|
|
||||||
data.raw.technology[technology_name].unit.ingredients = ingredients
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add a prerequisite to a given technology
|
-- Add a prerequisite to a given technology
|
||||||
function data_util.add_prerequisite(technology_name, prerequisite)
|
function util.add_prerequisite(technology_name, prerequisite)
|
||||||
technology = data.raw.technology[technology_name]
|
technology = data.raw.technology[technology_name]
|
||||||
if technology then
|
if technology and data.raw.technology[prerequisite] then
|
||||||
table.insert(technology.prerequisites, prerequisite)
|
if technology.prerequisites then
|
||||||
|
table.insert(technology.prerequisites, prerequisite)
|
||||||
|
else
|
||||||
|
technology.prerequisites = {prerequisite}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- removes a prerequisite tech
|
-- Remove a prerequisite from a given technology
|
||||||
function data_util.remove_prerequisite(tech, prereq)
|
function util.remove_prerequisite(technology_name, prerequisite)
|
||||||
if data.raw.technology[tech] then
|
technology = data.raw.technology[technology_name]
|
||||||
for i, prerequisite in pairs(data.raw.technology[tech].prerequisites) do
|
local index = -1
|
||||||
if data.raw.technology[tech].prerequisites[i] == prereq then
|
if technology and data.raw.technology[prerequisite] then
|
||||||
table.remove(data.raw.technology[tech].prerequisites, i)
|
for i, prereq in pairs(technology.prerequisites) do
|
||||||
|
if prereq == prerequisite then
|
||||||
|
index = i
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if index > -1 then
|
||||||
|
table.remove(technology.prerequisites, index)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add an effect to a given technology
|
||||||
|
function util.add_effect(technology_name, effect)
|
||||||
|
technology = data.raw.technology[technology_name]
|
||||||
|
if technology then
|
||||||
|
table.insert(technology.effects, effect)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set technology ingredients
|
||||||
|
function util.set_tech_recipe(technology_name, ingredients)
|
||||||
|
technology = data.raw.technology[technology_name]
|
||||||
|
if technology then
|
||||||
|
technology.unit.ingredients = ingredients
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add a given quantity of ingredient to a given recipe
|
-- Add a given quantity of ingredient to a given recipe
|
||||||
function data_util.add_ingredient(recipe_name, ingredient, quantity)
|
function util.add_ingredient(recipe_name, ingredient, quantity)
|
||||||
|
if bypass[recipe_name] then return end
|
||||||
if data.raw.recipe[recipe_name] then
|
if data.raw.recipe[recipe_name] then
|
||||||
add_ingredient(data.raw.recipe[recipe_name], ingredient, quantity)
|
add_ingredient(data.raw.recipe[recipe_name], ingredient, quantity)
|
||||||
add_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity)
|
add_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity)
|
||||||
|
|
@ -89,8 +121,9 @@ end
|
||||||
|
|
||||||
function add_ingredient(recipe, ingredient, quantity)
|
function add_ingredient(recipe, ingredient, quantity)
|
||||||
if recipe ~= nil and recipe.ingredients ~= nil then
|
if recipe ~= nil and recipe.ingredients ~= nil then
|
||||||
for _, existing in ipairs(recipe.ingredients) do
|
for i, existing in pairs(recipe.ingredients) do
|
||||||
if ingredient == existing.name or ingredient == existing[1] then
|
if existing[1] == ingredient or existing.name == ingredient then
|
||||||
|
log("Not adding "..ingredient.." -- duplicate")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -98,28 +131,50 @@ function add_ingredient(recipe, ingredient, quantity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Replace one ingredien with another in a recipe
|
-- Add a given quantity of product to a given recipe.
|
||||||
function data_util.replace_ingredient(recipe_name, old, new)
|
-- Only works for recipes with multiple products
|
||||||
|
function util.add_product(recipe_name, product)
|
||||||
if data.raw.recipe[recipe_name] then
|
if data.raw.recipe[recipe_name] then
|
||||||
replace_ingredient(data.raw.recipe[recipe_name], old, new)
|
add_product(data.raw.recipe[recipe_name], product)
|
||||||
replace_ingredient(data.raw.recipe[recipe_name].normal, old, new)
|
add_product(data.raw.recipe[recipe_name].normal, product)
|
||||||
replace_ingredient(data.raw.recipe[recipe_name].expensive, old, new)
|
add_product(data.raw.recipe[recipe_name].expensive, product)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function add_product(recipe, product)
|
||||||
|
if recipe ~= nil and recipe.results ~= nil then
|
||||||
|
table.insert(recipe.results, product)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Replace one ingredient with another in a recipe
|
||||||
|
function util.replace_ingredient(recipe_name, old, new)
|
||||||
|
if bypass[recipe_name] then return end
|
||||||
|
if data.raw.recipe[recipe_name] then
|
||||||
|
replace_ingredient(data.raw.recipe[recipe_name], old, new)
|
||||||
|
replace_ingredient(data.raw.recipe[recipe_name].normal, old, new)
|
||||||
|
replace_ingredient(data.raw.recipe[recipe_name].expensive, old, new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function replace_ingredient(recipe, old, new)
|
function replace_ingredient(recipe, old, new)
|
||||||
if recipe ~= nil and recipe.ingredients ~= nil then
|
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
|
||||||
|
log("Not adding "..new.." -- duplicate")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
for i, ingredient in pairs(recipe.ingredients) do
|
for i, ingredient in pairs(recipe.ingredients) do
|
||||||
-- For final fixes
|
|
||||||
if ingredient.name == old then ingredient.name = new end
|
if ingredient.name == old then ingredient.name = new end
|
||||||
-- For updates
|
|
||||||
if ingredient[1] == old then ingredient[1] = new end
|
if ingredient[1] == old then ingredient[1] = new end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Remove an ingredient from a recipe
|
-- Remove an ingredient from a recipe
|
||||||
function data_util.remove_ingredient(recipe_name, old)
|
function util.remove_ingredient(recipe_name, old)
|
||||||
|
if bypass[recipe_name] then return end
|
||||||
if data.raw.recipe[recipe_name] then
|
if data.raw.recipe[recipe_name] then
|
||||||
remove_ingredient(data.raw.recipe[recipe_name], old)
|
remove_ingredient(data.raw.recipe[recipe_name], old)
|
||||||
remove_ingredient(data.raw.recipe[recipe_name].normal, old)
|
remove_ingredient(data.raw.recipe[recipe_name].normal, old)
|
||||||
|
|
@ -144,18 +199,29 @@ end
|
||||||
|
|
||||||
|
|
||||||
-- Replace an amount of an ingredient in a recipe. Keep at least 1 of old.
|
-- Replace an amount of an ingredient in a recipe. Keep at least 1 of old.
|
||||||
function data_util.replace_some_ingredient(recipe_name, old, old_amount, new, new_amount)
|
function util.replace_some_ingredient(recipe_name, old, old_amount, new, new_amount)
|
||||||
replace_some_ingredient(data.raw.recipe[recipe_name], old, old_amount, new, new_amount)
|
if bypass[recipe_name] then return end
|
||||||
replace_some_ingredient(data.raw.recipe[recipe_name].normal, old, old_amount, new, new_amount)
|
if data.raw.recipe[recipe_name] then
|
||||||
replace_some_ingredient(data.raw.recipe[recipe_name].expensive, old, old_amount, new, new_amount)
|
replace_some_ingredient(data.raw.recipe[recipe_name], old, old_amount, new, new_amount)
|
||||||
|
replace_some_ingredient(data.raw.recipe[recipe_name].normal, old, old_amount, new, new_amount)
|
||||||
|
replace_some_ingredient(data.raw.recipe[recipe_name].expensive, old, old_amount, new, new_amount)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function replace_some_ingredient(recipe, old, old_amount, new, new_amount)
|
function replace_some_ingredient(recipe, old, old_amount, new, new_amount)
|
||||||
if recipe ~= nil and recipe.ingredients ~= nil then
|
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
|
||||||
|
log("Not adding "..new.." -- duplicate")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
for i, ingredient in pairs(recipe.ingredients) do
|
for i, ingredient in pairs(recipe.ingredients) do
|
||||||
|
-- For final fixes
|
||||||
if ingredient.name == old then
|
if ingredient.name == old then
|
||||||
ingredient.amount = math.max(1, ingredient.amount - old_amount)
|
ingredient.amount = math.max(1, ingredient.amount - old_amount)
|
||||||
end
|
end
|
||||||
|
-- For updates
|
||||||
if ingredient[1] == old then
|
if ingredient[1] == old then
|
||||||
ingredient[2] = math.max(1, ingredient[2] - old_amount)
|
ingredient[2] = math.max(1, ingredient[2] - old_amount)
|
||||||
end
|
end
|
||||||
|
|
@ -164,30 +230,14 @@ function replace_some_ingredient(recipe, old, old_amount, new, new_amount)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add an effect to a given technology
|
|
||||||
function data_util.add_effect(technology_name, effect)
|
|
||||||
technology = data.raw.technology[technology_name]
|
|
||||||
if technology then
|
|
||||||
table.insert(technology.effects, effect)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if a table contains a sought value
|
|
||||||
function data_util.contains(table, sought)
|
|
||||||
for i, value in pairs(table) do
|
|
||||||
if value == sought then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- multiply the cost, energy, and results of a recipe by a multiple
|
-- multiply the cost, energy, and results of a recipe by a multiple
|
||||||
function data_util.multiply_recipe(recipe_name, multiple)
|
function util.multiply_recipe(recipe_name, multiple)
|
||||||
multiply_recipe(data.raw.recipe[recipe_name], multiple)
|
if bypass[recipe_name] then return end
|
||||||
multiply_recipe(data.raw.recipe[recipe_name].normal, multiple)
|
if data.raw.recipe[recipe_name] then
|
||||||
multiply_recipe(data.raw.recipe[recipe_name].expensive, multiple)
|
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
|
end
|
||||||
|
|
||||||
function multiply_recipe(recipe, multiple)
|
function multiply_recipe(recipe, multiple)
|
||||||
|
|
@ -234,4 +284,14 @@ function multiply_recipe(recipe, multiple)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return data_util
|
-- Remove an element of type t and name from data.raw
|
||||||
|
function util.remove_raw(t, name)
|
||||||
|
for i, elem in pairs(data.raw[t]) do
|
||||||
|
if elem.name == name then
|
||||||
|
data.raw[t][i] = nil
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return util
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "bztitanium",
|
"name": "bztitanium",
|
||||||
"version": "0.11.0",
|
"version": "0.12.0",
|
||||||
"factorio_version": "1.1",
|
"factorio_version": "1.1",
|
||||||
"title": "Titanium",
|
"title": "Titanium",
|
||||||
"author": "Brevven",
|
"author": "Brevven",
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,11 @@ dirty-water-filtration-titanium=Filter dirty water, giving titanium ore [item=ti
|
||||||
# Settings
|
# Settings
|
||||||
|
|
||||||
[mod-setting-name]
|
[mod-setting-name]
|
||||||
|
bztitanium-recipe-bypass=Bypass recipes
|
||||||
bztitanium-mining-fluid=Experimental: Titanium mining fluid
|
bztitanium-mining-fluid=Experimental: Titanium mining fluid
|
||||||
|
|
||||||
[mod-setting-description]
|
[mod-setting-description]
|
||||||
|
bztitanium-recipe-bypass=Skip modifying these recipes (comma-separated list).
|
||||||
bztitanium-mining-fluid=Choose which fluid to use when mining Titanium.\n[color=orange]Lubricant is recommended![/color]\n[color=red]This setting is experimental and might not be compatible.[/color]
|
bztitanium-mining-fluid=Choose which fluid to use when mining Titanium.\n[color=orange]Lubricant is recommended![/color]\n[color=red]This setting is experimental and might not be compatible.[/color]
|
||||||
[string-mod-setting]
|
[string-mod-setting]
|
||||||
bztitanium-mining-fluid-lubricant=Lubricant
|
bztitanium-mining-fluid-lubricant=Lubricant
|
||||||
|
|
|
||||||
11
settings.lua
11
settings.lua
|
|
@ -1,11 +1,16 @@
|
||||||
data:extend(
|
data:extend({
|
||||||
{
|
{
|
||||||
|
type = "string-setting",
|
||||||
|
name = "bztitanium-recipe-bypass",
|
||||||
|
setting_type = "startup",
|
||||||
|
default_value = "",
|
||||||
|
allow_blank = true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type = "string-setting",
|
type = "string-setting",
|
||||||
name = "bztitanium-mining-fluid",
|
name = "bztitanium-mining-fluid",
|
||||||
setting_type = "startup",
|
setting_type = "startup",
|
||||||
default_value = "lubricant",
|
default_value = "lubricant",
|
||||||
allowed_values = (mods["Krastorio2"] and {"lubricant", "sulfuric-acid", "chlorine"} or {"lubricant", "sulfuric-acid"}),
|
allowed_values = (mods["Krastorio2"] and {"lubricant", "sulfuric-acid", "chlorine"} or {"lubricant", "sulfuric-acid"}),
|
||||||
order = "a1",
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue