hot-metals/hot-metals/prototypes/hot-metals.lua
2025-02-03 10:34:31 +01:00

77 lines
2.6 KiB
Lua

local defaultSpoilTicks = settings.startup["hot-metals-time"].value * 60
function createHotVariant(config)
local itemName = config
local spoilTicks = defaultSpoilTicks
local iconFolder = "__hot-metals__/graphics/icons/"
if type(config) == "table" then
itemName = config.name
spoilTicks = config.spoilTicks or spoilTicks
iconFolder = config.iconFolder or iconFolder
end
local item = data.raw.item[itemName]
-- Create new item
local hotItem = table.deepcopy(data.raw.item[itemName])
hotItem.name = "hot-" .. itemName
hotItem.localised_name = { "", { "item-name.hot" }, " ", { "item-name." .. itemName } }
if (config.icons) then
hotItem.icons = config.icons
else
hotItem.icon = iconFolder .. "hot-" .. itemName .. ".png"
end
hotItem.order = hotItem.order .. "-hot"
hotItem.spoil_result = itemName
hotItem.spoil_ticks = spoilTicks
data:extend({ hotItem })
-- Change recipes
for _, recipe in pairs(data.raw.recipe) do
if contains(HotMetals.craftingCategories, recipe.category) then
local function isResultMatch(result)
return result.name == itemName
end
local results = table.filter(recipe.results, isResultMatch)
if #results > 0 then
for _, result in pairs(results) do
result.name = hotItem.name
end
recipe.localised_name = { "item-name." .. itemName }
recipe.icon = recipe.icon or item.icon
recipe.icon_size = recipe.icon_size or item.icon_size
recipe.icons = recipe.icons or item.icons
if recipe.main_product == itemName then
recipe.main_product = hotItem.name
end
recipe.preserve_products_in_machine_output = true
recipe.result_is_always_fresh = true
end
end
end
-- Change technology triggers
for _, tech in pairs(data.raw.technology) do
if tech.research_trigger and tech.research_trigger.item == itemName and not contains(HotMetals.skipTechUnlocksFor, itemName) then
tech.research_trigger.item = hotItem.name
end
end
end
-- Checks if a table contains a certain value
-- @param table table The table to check
-- @param value any The value to check for
-- @return boolean
function contains(table, value)
for _, v in pairs(table) do
if v == value then
return true
end
end
return false
end
for _, item in pairs(HotMetals.items) do
createHotVariant(item)
end