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,2 +1,16 @@
# Hot metals # Hot metals
A Factorio mod. Did you ever wonder how fast the metals in furnaces and foundries cool down ready to be used? Well, that's over now!
All metal products from furnaces and foundries will be too hot to use initially. Wait for them to cool own first.
Good look with direct insertion setups :-)
## Modding support
This mod adds a global variable named `HotMetals`. Add things to it to add support for your mod. Some mods have baked in support.
It has the following properties.
### `items`
Add an item name as string or a table with `name` and optional `spoilTicks` and `iconFolder`. The icon file will be `iconFolder .. "hot-" .. itemName .. ".png"`.
### `craftingCategories`
A table containing all supported crafting categories. This mod uses a white list to prevent unwanted categories by default. Only categories used by smelting buildings like the furnace and the foundry should be added.

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": "", "homepage": "",
"factorio_version": "2.0", "factorio_version": "2.0",
"dependencies": [ "dependencies": [
"base >= 2.0.0", "base",
"space-age" "space-age >= 2.0.0"
], ],
"space_travel_required": true "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")