Context
I am creating a new object with its own icon. The new object is used in two recipes.What I am trying to do is that each recipe has a different icon.
The following code is functional and the image shows the problem.
Code: Select all
---------------------------------------------------------------------------------------------------
---> data.lua <---
---------------------------------------------------------------------------------------------------
local function DeepCopy(value)
if type(value) ~= "table" then return value end
local Output = {}
for Key, Value in pairs(value) do
Output[Key] = DeepCopy(Value)
end
return Output
end
--- --- --- --- --- --- --- --- --- --- --- --- --- ---
local StackSize = 500
local Ingredients = 1000
local ArrowU = { icon = data.raw["virtual-signal"]["up-arrow"].icon, scale = 0.30 }
local ArrowD = { icon = data.raw["virtual-signal"]["down-arrow"].icon, scale = 0.30 }
local Item = {}
local item_name = "solid-fuel"
local Prefix = "zzzYAIM904-"
--- --- --- --- --- --- --- --- --- --- --- --- --- ---
local item = data.raw.item[item_name]
local Properties = {}
table.insert(Properties, "localised_name")
table.insert(Properties, "inventory_move_sound")
table.insert(Properties, "pick_sound")
table.insert(Properties, "drop_sound")
table.insert(Properties, "subgroup")
table.insert(Properties, "order")
table.insert(Properties, "icons")
for _, key in pairs(Properties) do
Item[key] = DeepCopy(item[key])
end
Item.name = Prefix .. item.name
Item.type = "item"
Item.stack_size = StackSize
Item.localised_description = { "" }
table.insert(Item.localised_description, Ingredients .. " ")
table.insert(Item.localised_description, "[item=" .. item.name .. "] ")
table.insert(Item.icons, ArrowU)
data:extend({ Item })
--- --- --- --- --- --- --- --- --- --- --- --- --- ---
local RecipeD = {}
RecipeD.type = "recipe"
RecipeD.name = Item.name
RecipeD.localised_name = DeepCopy(item.localised_name)
RecipeD.icons = DeepCopy(item.icons)
RecipeD.allow_decomposition = false
RecipeD.allow_as_intermediate = false
RecipeD.hide_from_player_crafting = true
RecipeD.enabled = true
RecipeD.results = { { type = "item", name = Item.name, amount = 1 } }
RecipeD.ingredients = { { type = "item", name = item.name, amount = Ingredients } }
RecipeD.subgroup = item.subgroup
RecipeD.order = item.order
table.insert(RecipeD.icons, ArrowD)
data:extend({ RecipeD })
local RecipeU = {}
RecipeU.type = "recipe"
RecipeU.name = Prefix .. "-u-" .. item.name
RecipeU.localised_name = DeepCopy(item.localised_name)
RecipeU.icons = DeepCopy(item.icons)
RecipeU.allow_decomposition = false
RecipeU.enabled = true
RecipeU.ingredients = { { type = "item", name = Item.name, amount = 1 } }
RecipeU.results = { { type = "item", name = item.name, amount = Ingredients } }
RecipeU.subgroup = item.subgroup
RecipeU.order = item.order
table.insert(RecipeU.icons, ArrowU)
data:extend({ RecipeU })
The recipe has a different icon than the object icon in the code, but the recipe icon is being ignored and the object icon is being used. The object icon is also being used by the second recipe. This results in two recipes with the same icon even though the code says otherwise.