Refactoring

Add modding support
This commit is contained in:
Simon Brodtmann 2024-12-02 23:38:48 +01:00
parent 851ced08fb
commit 6bb5e14e4f
6 changed files with 94 additions and 45 deletions

View file

@ -1 +1 @@
require("prototypes.hot")
require("prototypes.hot-metals")

21
hot-metals/data.lua Normal file
View file

@ -0,0 +1,21 @@
HotMetals = {
items = {
"copper-cable",
"copper-plate",
"holmium-plate",
"iron-gear-wheel",
"iron-plate",
"iron-stick",
"pipe",
"pipe-to-ground",
"steel-plate",
"tungsten-plate"
-- Disabled because of https://forums.factorio.com/viewtopic.php?f=7&t=123081
--"low-density-structure"
},
craftingCategories = {
"smelting",
"metallurgy",
"crafting-with-fluid-or-metallurgy"
}
}

View file

@ -7,8 +7,8 @@
"homepage": "",
"factorio_version": "2.0",
"dependencies": [
"base >= 2.0.0",
"space-age"
"base",
"space-age >= 2.0.0"
],
"space_travel_required": true
}

View file

@ -0,0 +1,55 @@
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

View file

@ -1,41 +0,0 @@
local spoil_ticks = settings.startup["hot-metals-time"].value * 60
function createHotVariant(itemName, _spoil_ticks)
-- 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 = "__hot-metals__/graphics/icons/hot-" .. itemName .. ".png"
hotItem.order = hotItem.order .. "-hot"
hotItem.spoil_result = itemName
hotItem.spoil_ticks = _spoil_ticks or spoil_ticks
data:extend({ hotItem })
-- Change recipes
for _, recipe in pairs(data.raw.recipe) do
if ((recipe.category == "smelting" or recipe.category == "metallurgy" or recipe.category == "crafting-with-fluid-or-metallurgy") 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
createHotVariant("copper-cable")
createHotVariant("copper-plate")
createHotVariant("holmium-plate")
createHotVariant("iron-gear-wheel")
createHotVariant("iron-plate")
createHotVariant("iron-stick")
-- Disabled because of https://forums.factorio.com/viewtopic.php?f=7&t=123081
--createHotVariant("low-density-structure")
createHotVariant("pipe")
createHotVariant("pipe-to-ground")
createHotVariant("steel-plate")
createHotVariant("tungsten-plate")