hot-metals/hot-metals/prototypes/hot-metals.lua
Simon Brodtmann 6bb5e14e4f Refactoring
Add modding support
2024-12-03 00:02:55 +01:00

55 lines
1.7 KiB
Lua

local defaultSpoilTicks = settings.startup["hot-metals-time"].value * 60
function createHotVariant(item)
local itemName = item
local spoilTicks = defaultSpoilTicks
local iconFolder = "__hot-metals__/graphics/icons/"
if type(item) == "table" then
itemName = item.name
spoilTicks = item.spoilTicks or spoilTicks
iconFolder = item.iconFolder or iconFolder
end
-- Create new item
local hotItem = table.deepcopy(data.raw.item[itemName])
hotItem.name = "hot-" .. itemName
hotItem.localised_name = { "", { "item-name.hot" }, " ", { "item-name." .. itemName } }
hotItem.icon = iconFolder .. "hot-" .. itemName .. ".png"
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) and recipe.results[1].name == itemName then
recipe.results[1].name = hotItem.name
recipe.localised_name = { "item-name." .. itemName }
end
end
-- Change technology triggers
for _, tech in pairs(data.raw.technology) do
if tech.research_trigger and tech.research_trigger.item == 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