refactor
This commit is contained in:
parent
54f0009446
commit
f11cf11ae3
9 changed files with 166 additions and 57 deletions
|
|
@ -1,4 +1,9 @@
|
|||
---------------------------------------------------------------------------------------------------
|
||||
Version: 0.5.7
|
||||
Date: 2021-07-26
|
||||
Changes:
|
||||
- Minor refactor
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 0.5.6
|
||||
Date: 2021-07-25
|
||||
Features:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "bzlead",
|
||||
"version": "0.5.6",
|
||||
"version": "0.5.7",
|
||||
"factorio_version": "1.1",
|
||||
"title": "Lead",
|
||||
"author": "Brevven",
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ if mods["5dim_core"] then
|
|||
enabled = true,
|
||||
energy_required = 65,
|
||||
ingredients = {{"lead-ore", 85}},
|
||||
result = util.lead_plate,
|
||||
result = util.me.lead_plate,
|
||||
result_count = 100,
|
||||
}
|
||||
})
|
||||
|
|
@ -49,7 +49,7 @@ if mods["5dim_core"] then
|
|||
ingredients = {
|
||||
{"lead-dust", 1}
|
||||
},
|
||||
result = util.lead_plate
|
||||
result = util.me.lead_plate
|
||||
},
|
||||
{
|
||||
type = "recipe",
|
||||
|
|
@ -79,7 +79,7 @@ if mods["5dim_core"] then
|
|||
enabled = true,
|
||||
energy_required = 65,
|
||||
ingredients = {{"lead-dust", 85}},
|
||||
result = util.lead_plate,
|
||||
result = util.me.lead_plate,
|
||||
result_count = 100,
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
local util = require("__bzlead__.util");
|
||||
|
||||
if mods["space-exploration"] then
|
||||
se_delivery_cannon_recipes[util.lead_ore] = {name= util.lead_ore}
|
||||
se_delivery_cannon_recipes[util.lead_plate] = {name= util.lead_plate}
|
||||
se_delivery_cannon_recipes[util.me.lead_ore] = {name= util.me.lead_ore}
|
||||
se_delivery_cannon_recipes[util.me.lead_plate] = {name= util.me.lead_plate}
|
||||
if mods["Krastorio2"] then
|
||||
data:extend({
|
||||
{
|
||||
|
|
@ -20,7 +20,7 @@ if mods["space-exploration"] then
|
|||
{name = "se-vulcanite-block", amount = 1},
|
||||
},
|
||||
results = {
|
||||
{name = util.lead_plate, amount = 12},
|
||||
{name = util.me.lead_plate, amount = 12},
|
||||
},
|
||||
icons =
|
||||
{
|
||||
|
|
@ -50,7 +50,7 @@ if mods["space-exploration"] then
|
|||
{name = "se-vulcanite-block", amount = 1},
|
||||
},
|
||||
results = {
|
||||
{name = util.lead_plate, amount = 6},
|
||||
{name = util.me.lead_plate, amount = 6},
|
||||
},
|
||||
icons =
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ if (not mods["pyrawores"] and not mods["bobplates"] and not mods["angelssmelting
|
|||
util.replace_ingredient("battery", "iron-plate", "lead-plate")
|
||||
|
||||
|
||||
if util.sulfuric() then
|
||||
if util.me.sulfuric() then
|
||||
util.replace_ingredient("sulfuric-acid", "iron-plate", "lead-plate")
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ if (not mods["pyrawores"] and not mods["bobplates"] and not mods["angelssmelting
|
|||
data:extend({
|
||||
{
|
||||
type = "recipe",
|
||||
name = util.lead_plate,
|
||||
name = util.me.lead_plate,
|
||||
category = "smelting",
|
||||
subgroup = "raw-material",
|
||||
order = "d[lead-plate]",
|
||||
|
|
@ -24,7 +24,7 @@ data:extend({
|
|||
energy_required = 16,
|
||||
ingredients = {{"lead-ore", 10}},
|
||||
results = {
|
||||
{type="item", name = util.lead_plate, amount_min=4, amount_max=5},
|
||||
{type="item", name = util.me.lead_plate, amount_min=4, amount_max=5},
|
||||
{type="item", name = "copper-ore", amount_min=1, amount_max=2},
|
||||
}
|
||||
} or
|
||||
|
|
@ -33,7 +33,7 @@ data:extend({
|
|||
energy_required = 6.4,
|
||||
ingredients = {{"lead-ore", 2}},
|
||||
results = {
|
||||
{type="item", name = util.lead_plate, amount=2, probability=5/6},
|
||||
{type="item", name = util.me.lead_plate, amount=2, probability=5/6},
|
||||
{type="item", name = "copper-ore", amount=1, probability=1/3},
|
||||
}
|
||||
}),
|
||||
|
|
@ -43,14 +43,14 @@ data:extend({
|
|||
energy_required = 12.8,
|
||||
ingredients = {{"lead-ore", 4}},
|
||||
results = {
|
||||
{type="item", name = util.lead_plate, amount=2, probability=5/6},
|
||||
{type="item", name = util.me.lead_plate, amount=2, probability=5/6},
|
||||
{type="item", name = "copper-ore", amount=2, probability=1/3},
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type = "item",
|
||||
name = util.lead_plate,
|
||||
name = util.me.lead_plate,
|
||||
icon = "__bzlead__/graphics/icons/lead-plate.png",
|
||||
icon_size = 64, icon_mipmaps = 3,
|
||||
subgroup = "raw-material",
|
||||
|
|
@ -70,7 +70,7 @@ data:extend({
|
|||
energy_required = 7,
|
||||
ingredients = {{"lead-ore", 100}},
|
||||
results = {
|
||||
{type="item", name = util.lead_plate, amount=100, probability=5/6},
|
||||
{type="item", name = util.me.lead_plate, amount=100, probability=5/6},
|
||||
{type="item", name = "copper-ore", amount=50, probability=1/3},
|
||||
}
|
||||
},
|
||||
|
|
|
|||
30
me.lua
Normal file
30
me.lua
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
local me = {}
|
||||
|
||||
me.name = "bzlead"
|
||||
me.lead_ore = "lead-ore"
|
||||
me.lead_plate = "lead-plate"
|
||||
|
||||
|
||||
function me.more_entities()
|
||||
return me.get_setting("bzlead-more-entities") == "yes"
|
||||
end
|
||||
|
||||
function me.sulfuric()
|
||||
return me.get_setting("bzlead-sulfuric") == "yes"
|
||||
end
|
||||
|
||||
function me.get_setting(name)
|
||||
if settings.startup[name] == nil then
|
||||
return nil
|
||||
end
|
||||
return settings.startup[name].value
|
||||
end
|
||||
|
||||
me.bypass = {}
|
||||
if me.get_setting(me.name.."-recipe-bypass") then
|
||||
for recipe in string.gmatch(me.get_setting(me.name.."-recipe-bypass"), '[^",%s]+') do
|
||||
me.bypass[recipe] = true
|
||||
end
|
||||
end
|
||||
|
||||
return me
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
local leadutil = require("__bzlead__.util");
|
||||
require("util")
|
||||
|
||||
if leadutil.more_entities() then
|
||||
if leadutil.me.more_entities() then
|
||||
data:extend({
|
||||
|
||||
{
|
||||
|
|
|
|||
156
util.lua
156
util.lua
|
|
@ -1,29 +1,12 @@
|
|||
local me = require("me")
|
||||
local util = {}
|
||||
|
||||
util.name = "bzlead"
|
||||
util.lead_ore = "lead-ore"
|
||||
util.lead_plate = "lead-plate"
|
||||
util.me = me
|
||||
util.get_setting = util.me.get_setting
|
||||
|
||||
|
||||
function util.more_entities()
|
||||
return util.get_setting("bzlead-more-entities") == "yes"
|
||||
end
|
||||
|
||||
function util.sulfuric()
|
||||
return util.get_setting("bzlead-sulfuric") == "yes"
|
||||
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
|
||||
function util.fe_plus(sub)
|
||||
if mods["FactorioExtended-Plus-"..sub] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -92,8 +75,8 @@ 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
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if me.bypass[recipe_name] then return end
|
||||
if data.raw.recipe[recipe_name] and data.raw.item[ingredient] then
|
||||
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].expensive, ingredient, quantity)
|
||||
|
|
@ -115,7 +98,7 @@ 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 data.raw.recipe[recipe_name] then
|
||||
if data.raw.recipe[recipe_name] and data.raw.item[product] 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)
|
||||
|
|
@ -130,8 +113,8 @@ 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
|
||||
if me.bypass[recipe_name] then return end
|
||||
if data.raw.recipe[recipe_name] and data.raw.item[new] 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)
|
||||
|
|
@ -155,7 +138,7 @@ end
|
|||
|
||||
-- Remove an ingredient from a recipe
|
||||
function util.remove_ingredient(recipe_name, old)
|
||||
if bypass[recipe_name] then return end
|
||||
if me.bypass[recipe_name] then return end
|
||||
if data.raw.recipe[recipe_name] then
|
||||
remove_ingredient(data.raw.recipe[recipe_name], old)
|
||||
remove_ingredient(data.raw.recipe[recipe_name].normal, old)
|
||||
|
|
@ -178,11 +161,10 @@ function remove_ingredient(recipe, old)
|
|||
end
|
||||
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
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if me.bypass[recipe_name] then return end
|
||||
if data.raw.recipe[recipe_name] and data.raw.item[new] then
|
||||
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)
|
||||
|
|
@ -198,11 +180,9 @@ function replace_some_ingredient(recipe, old, old_amount, new, new_amount)
|
|||
end
|
||||
end
|
||||
for i, ingredient in pairs(recipe.ingredients) do
|
||||
-- For final fixes
|
||||
if ingredient.name == old then
|
||||
ingredient.amount = math.max(1, ingredient.amount - old_amount)
|
||||
end
|
||||
-- For updates
|
||||
if ingredient[1] == old then
|
||||
ingredient[2] = math.max(1, ingredient[2] - old_amount)
|
||||
end
|
||||
|
|
@ -213,7 +193,7 @@ end
|
|||
|
||||
-- multiply the cost, energy, and results of a recipe by a multiple
|
||||
function util.multiply_recipe(recipe_name, multiple)
|
||||
if bypass[recipe_name] then return end
|
||||
if me.bypass[recipe_name] then return end
|
||||
if data.raw.recipe[recipe_name] then
|
||||
multiply_recipe(data.raw.recipe[recipe_name], multiple)
|
||||
multiply_recipe(data.raw.recipe[recipe_name].normal, multiple)
|
||||
|
|
@ -265,14 +245,108 @@ function multiply_recipe(recipe, multiple)
|
|||
end
|
||||
end
|
||||
|
||||
-- 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
|
||||
-- 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) or
|
||||
has_ingredient(data.raw.recipe[recipe_name].normal, ingredient))
|
||||
end
|
||||
|
||||
function has_ingredient(recipe, ingredient)
|
||||
if recipe ~= nil and recipe.ingredients ~= nil then
|
||||
for i, existing in pairs(recipe.ingredients) do
|
||||
if existing[1] == ingredient or existing.name == ingredient then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Replace one product with another in a recipe
|
||||
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
|
||||
|
||||
function replace_product(recipe, old, new)
|
||||
if recipe ~= nil and recipe.results ~= nil then
|
||||
if recipe.result == old then
|
||||
recipe.results = new
|
||||
return
|
||||
end
|
||||
for i, result in pairs(recipe.results) do
|
||||
if result.name == old then result.name = new end
|
||||
if result[1] == old then result[1] = new end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Remove an element of type t and name from data.raw
|
||||
function util.remove_raw(t, name)
|
||||
if data.raw[t][name] then
|
||||
for i, elem in pairs(data.raw[t]) do
|
||||
if elem.name == name then
|
||||
data.raw[t][i] = nil
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Multiply energy required
|
||||
function util.multiply_time(recipe, factor)
|
||||
if me.bypass[recipe_name] then return end
|
||||
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
|
||||
|
||||
function multiply_time(recipe, factor)
|
||||
if recipe then
|
||||
if recipe.energy_required then
|
||||
recipe.energy_required = recipe.energy_required * factor
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Set recipe category
|
||||
function util.set_category(recipe, category)
|
||||
if me.bypass[recipe_name] then return end
|
||||
if data.raw.recipe[recipe] then
|
||||
data.raw.recipe[recipe].category = category
|
||||
end
|
||||
end
|
||||
|
||||
-- Set recipe subgroup
|
||||
function util.set_subgroup(recipe, subgroup)
|
||||
if me.bypass[recipe_name] then return end
|
||||
if data.raw.recipe[recipe] then
|
||||
data.raw.recipe[recipe].subgroup = subgroup
|
||||
end
|
||||
end
|
||||
|
||||
function util.set_to_founding(recipe)
|
||||
util.set_category(recipe, "founding")
|
||||
util.set_subgroup(recipe, "foundry-intermediate")
|
||||
end
|
||||
|
||||
-- Add crafting category to an entity
|
||||
function util.add_crafting_category(entity_type, entity, category)
|
||||
if data.raw[entity_type][entity] then
|
||||
for i, existing in pairs(data.raw[entity_type][entity].crafting_categories) do
|
||||
if existing == category then
|
||||
log(entity.." not adding "..new.." -- duplicate")
|
||||
return
|
||||
end
|
||||
end
|
||||
table.insert(data.raw[entity_type][entity].crafting_categories, category)
|
||||
end
|
||||
end
|
||||
|
||||
return util
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue