From 6bb5e14e4fd3e4c941cae0fac820b8467e70c987 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Mon, 2 Dec 2024 23:38:48 +0100 Subject: [PATCH] Refactoring Add modding support --- README.md | 16 +++++++- hot-metals/data-updates.lua | 2 +- hot-metals/data.lua | 21 +++++++++++ hot-metals/info.json | 4 +- hot-metals/prototypes/hot-metals.lua | 55 ++++++++++++++++++++++++++++ hot-metals/prototypes/hot.lua | 41 --------------------- 6 files changed, 94 insertions(+), 45 deletions(-) create mode 100644 hot-metals/data.lua create mode 100644 hot-metals/prototypes/hot-metals.lua delete mode 100644 hot-metals/prototypes/hot.lua diff --git a/README.md b/README.md index 30dc01c..78cd388 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ # Hot metals -A Factorio mod. \ No newline at end of file +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. \ No newline at end of file diff --git a/hot-metals/data-updates.lua b/hot-metals/data-updates.lua index 85f98ef..1f5d2dc 100644 --- a/hot-metals/data-updates.lua +++ b/hot-metals/data-updates.lua @@ -1 +1 @@ -require("prototypes.hot") \ No newline at end of file +require("prototypes.hot-metals") \ No newline at end of file diff --git a/hot-metals/data.lua b/hot-metals/data.lua new file mode 100644 index 0000000..7d94db8 --- /dev/null +++ b/hot-metals/data.lua @@ -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" + } +} \ No newline at end of file diff --git a/hot-metals/info.json b/hot-metals/info.json index 659b79d..1f08fc5 100644 --- a/hot-metals/info.json +++ b/hot-metals/info.json @@ -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 } \ No newline at end of file diff --git a/hot-metals/prototypes/hot-metals.lua b/hot-metals/prototypes/hot-metals.lua new file mode 100644 index 0000000..01e9ffa --- /dev/null +++ b/hot-metals/prototypes/hot-metals.lua @@ -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 diff --git a/hot-metals/prototypes/hot.lua b/hot-metals/prototypes/hot.lua deleted file mode 100644 index d5ce29b..0000000 --- a/hot-metals/prototypes/hot.lua +++ /dev/null @@ -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")