updates, thumbnail, fixes

This commit is contained in:
Brevven 2022-01-18 02:31:58 -08:00
parent e07cf3dbe2
commit ffd4340b0c
8 changed files with 187 additions and 32 deletions

View file

@ -1,4 +1,16 @@
---------------------------------------------------------------------------------------------------
Version: 0.0.8
Date: 2022-01-08
Changes:
- New icon
Fixes:
- K2 issue with nil ingredients
---------------------------------------------------------------------------------------------------
Version: 0.0.7
Date: 2022-01-02
Fixes:
- Fix issue with more efficient founding recipes
---------------------------------------------------------------------------------------------------
Version: 0.0.6
Date: 2022-01-01
Features:

View file

@ -77,14 +77,33 @@ function util.remove_prerequisite(technology_name, prerequisite)
end
end
-- Add an effect to a given technology
function util.add_effect(technology_name, effect)
local technology = data.raw.technology[technology_name]
if technology then
if not technology.effects then technology.effects = {} end
table.insert(technology.effects, effect)
end
end
-- remove recipe unlock effect from a given technology
function util.remove_recipe_effect(technology_name, recipe_name)
local technology = data.raw.technology[technology_name]
local index = -1
if technology then
for i, effect in pairs(technology.effects) do
if effect.type == "unlock-recipe" and effect.recipe == recipe_name then
index = i
break
end
end
if index > -1 then
table.remove(technology.effects, index)
end
end
end
-- Set technology ingredients
function util.set_tech_recipe(technology_name, ingredients)
local technology = data.raw.technology[technology_name]
@ -93,10 +112,19 @@ function util.set_tech_recipe(technology_name, ingredients)
end
end
function util.set_enabled(recipe_name, enabled)
if data.raw.recipe[recipe_name] then
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
-- Add a given quantity of ingredient to a given recipe
function util.add_ingredient(recipe_name, ingredient, quantity)
if me.bypass[recipe_name] then return end
if data.raw.recipe[recipe_name] and data.raw.item[ingredient] then
me.add_modified(recipe_name)
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)
@ -135,6 +163,7 @@ end
function util.replace_ingredient(recipe_name, old, new)
if me.bypass[recipe_name] then return end
if data.raw.recipe[recipe_name] and data.raw.item[new] then
me.add_modified(recipe_name)
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)
@ -160,6 +189,7 @@ end
function util.remove_ingredient(recipe_name, old)
if me.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)
remove_ingredient(data.raw.recipe[recipe_name].normal, old)
remove_ingredient(data.raw.recipe[recipe_name].expensive, old)
@ -185,6 +215,7 @@ end
function util.replace_some_ingredient(recipe_name, old, old_amount, new, new_amount)
if me.bypass[recipe_name] then return end
if data.raw.recipe[recipe_name] and data.raw.item[new] then
me.add_modified(recipe_name)
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)
@ -213,8 +244,9 @@ end
-- multiply the cost, energy, and results of a recipe by a multiple
function util.multiply_recipe(recipe_name, multiple)
if me.bypass[recipe_name] then return end
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then
if me.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)
@ -285,8 +317,9 @@ end
-- Remove a product from a recipe, WILL NOT remove the only product
function util.remove_product(recipe_name, old)
if me.bypass[recipe_name] then return end
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then
if me.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)
@ -343,9 +376,10 @@ function util.remove_raw(t, name)
end
-- Multiply energy required
function util.multiply_time(recipe, factor)
if me.bypass[recipe_name] then return end
function util.multiply_time(recipe_name, factor)
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then
if me.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)
@ -360,19 +394,40 @@ function multiply_time(recipe, factor)
end
end
-- Set recipe category
function util.set_category(recipe, category)
-- Add to energy required
function util.add_time(recipe_name, amount)
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then
if me.bypass[recipe_name] then return end
if data.raw.recipe[recipe] then
data.raw.recipe[recipe].category = category
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
function add_time(recipe, amount)
if recipe then
if recipe.energy_required then
recipe.energy_required = recipe.energy_required + amount
end
end
end
-- Set recipe category
function util.set_category(recipe_name, category)
if me.bypass[recipe_name] then return end
if data.raw.recipe[recipe_name] then
me.add_modified(recipe_name)
data.raw.recipe[recipe_name].category = category
end
end
-- Set recipe subgroup
function util.set_subgroup(recipe, subgroup)
function util.set_subgroup(recipe_name, subgroup)
if me.bypass[recipe_name] then return end
if data.raw.recipe[recipe] then
data.raw.recipe[recipe].subgroup = subgroup
if data.raw.recipe[recipe_name] then
me.add_modified(recipe_name)
data.raw.recipe[recipe_name].subgroup = subgroup
end
end
@ -444,10 +499,90 @@ function add_to_product(recipe, product, amount)
end
end
-- Adds a result to a mineable type
function util.add_minable_result(t, name, result)
if data.raw[t] and data.raw[t][name] and data.raw[t][name].minable and data.raw[t][name].minable.results then
if data.raw[t] and data.raw[t][name] and data.raw[t][name].minable then
if data.raw[t][name].minable.result and not data.raw[t][name].minable.results then
data.raw[t][name].minable.results = {
{data.raw[t][name].minable.result ,data.raw[t][name].minable.count}}
data.raw[t][name].minable.result = nil
data.raw[t][name].minable.result_count = nil
end
if data.raw[t][name].minable.results then
table.insert(data.raw[t][name].minable.results, result)
end
end
end
local function insert(nodes, node, value)
table.insert(node, value) -- store as parameter
if 21 == #node then
node = {""}
table.insert(nodes, node)
end
return node
end
local function encode(data)
local node = {""}
local root = {node}
local n = string.len(data)
for i = 1,n,200 do
local value = string.sub(data, i, i+199)
node = insert(root, node, value)
end
while #root > 20 do
local nodes,node = {},{""}
for _, value in ipairs(root) do
node = insert(nodes, node, value)
end
root = nodes
end
if #root == 1 then root = root[1] else
table.insert(root, 1, "") -- no locale template
end
return #root < 3 and (root[2] or "") or root
end
function decode(data)
if type(data) == "string" then return data end
local str = {}
for i = 2, #data do
str[i-1] = decode(data[i])
end
return table.concat(str, "")
end
function util.create_list()
if #me.list>0 then
if not data.raw.item[me.name.."-list"] then
data:extend({{
type="item",
name=me.name.."-list",
localised_description = "",
enabled=false,
icon = "__core__/graphics/empty.png",
icon_size = 1,
stack_size = 1,
flags = {"hidden", "hide-from-bonus-gui"}
}})
end
local have = {}
local list = {}
for i, recipe in pairs(me.list) do
if not have[recipe] then
have[recipe] = true
table.insert(list, recipe)
end
end
if #list>0 then
data.raw.item[me.name.."-list"].localised_description =
encode(decode(data.raw.item[me.name.."-list"].localised_description).."\n"..table.concat(list, "\n"))
end
end
end
return util

View file

@ -1,6 +1,6 @@
{
"name": "bzfoundry",
"version": "0.0.6",
"version": "0.0.9",
"factorio_version": "1.1",
"title": "Foundry",
"author": "Brevven",

6
me.lua
View file

@ -48,4 +48,10 @@ if me.get_setting(me.name.."-recipe-bypass") then
end
end
function me.add_modified(name)
if me.get_setting(me.name.."-list") then
table.insert(me.list, name)
end
end
return me

View file

@ -6,6 +6,14 @@ data:extend({
{ type = "item-subgroup", name = "foundry-intermediate", group = "intermediate-products"},
})
local foundry_ingredients = {{"stone-brick", 20}, {"iron-plate", 10}, {"copper-plate", 5}}
if mods.bzlead then table.insert(foundry_ingredients, {"lead-plate", 8}) end
if mods.Krastorio2 or mods["aai-industry"] then
table.insert(foundry_ingredients, {"sand", 10})
elseif data.raw.item["silica"] and data.raw.technology["silica-processing"] then
table.insert(foundry_ingredients, {"silica", 20})
end
data:extend({
{
type = "item",
@ -22,14 +30,7 @@ data:extend({
name = "foundry",
result = "foundry",
enabled = false,
ingredients = {
{"stone-brick", 20},
{"iron-plate", 10},
{"copper-plate", 5},
(mods.bzlead and {"lead-plate", 10} or nil),
((mods.Krastorio2 or mods["aai-industry"]) and {"sand", 10}) or
(data.raw.item["silica"] and data.raw.technology["silica-processing"] and {"silica", 20}) or nil,
},
ingredients = foundry_ingredients,
},
{
type = "technology",

View file

@ -106,21 +106,21 @@ function make_recipe(recipe)
if not has_normal and not has_exp then
r.results = new_results
make_ingredients_and_products(r)
make_ingredients_and_products(r, r.name)
end
if has_normal then
r.normal.results = new_normal_results
r.normal.result = nil
r.normal.result_count = nil
r.normal.enabled = false
make_ingredients_and_products(r.normal)
make_ingredients_and_products(r.normal, r.name)
end
if has_exp then
r.expensive.results = new_exp_results
r.expensive.result = nil
r.expensive.result_count = nil
r.expensive.enabled = false
make_ingredients_and_products(r.expensive)
make_ingredients_and_products(r.expensive, r.name)
end
return r
end
@ -129,16 +129,17 @@ end
-- Gets refractories for a recipe (currently all recipes use same refractories)
function get_refractories(recipe)
-- TODO make this more varied and interesting based on reality
function get_refractories(recipe, name)
local refractories = {}
if mods.bzcarbon then table.insert(refractories, "graphite") end
if mods.bzsilicon then table.insert(refractories, "silica") end
if #refractories < 2 and mods.bzzirconium then table.insert("zirconia") end
if #refractories < 2 and mods.bzzirconium and name ~= "zirconium-plate-refractory" then table.insert(refractories, "zirconia") end
return refractories
end
function make_ingredients_and_products(r)
local refractories = get_refractories(r)
function make_ingredients_and_products(r, name)
local refractories = get_refractories(r, name)
local max_count = 1
for i, ingredient in pairs(r.ingredients) do
if ingredient[2] and ingredient[2] > max_count then

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 45 KiB

Before After
Before After

Binary file not shown.