Had some issues with table.deepcopy for a different mod, don't know why. Added helper function "table.deepestcopy".
https://pastebin.com/gZ94ePzZ
the code
Example use (I have permission to share):
Code: Select all
local local_create_container = function(item,x)
-- pre-existing icon, adding new icons from item
local base_contain_icons = {
{
icon = "__modmash__/graphics/icons/super-container.png",
icon_size = 32
}}
local contain_icons = create_icon(base_contain_icons, nil, {from = item, rescale = .5})
-- using existing icons, adding new after
local base_uncontain_icons = {}
local uncontain_icons = create_icon(base_uncontain_icons,nil,{from = item})
uncontain_icons = create_icon(base_uncontain_icons,{{icon = "__modmash__/graphics/icons/super-container.png", icon_size = 32, scale = .5, shift = {5,5}}})
...
"options" is a table: "rescale", value between 0-1 to scale newly added icons, "origin", a position { x, y } between -1 and +1 which moves the icon proportionally in the frame, "from", to do the annoying icon, icon_size, icons[1].icon_size logic. If 'type = "recipe"' is passed, all un-sized icons are converted to 32. (explicit compatibility for the 32 -> 64 icon size change from 0.17 -> 0.18)
Short list of all options: { rescale = 1, origin = { 0, 0 }, from = item, type = "recipe" }
Notes: The function works for recipes and technologies, which interpret the same icons table differently. The incoming icons table could be anything that uses the icon/icon.size/icons description, which includes 'tool' and whatnot. There may be some issues with shifting - I don't have good tests for it. Any comments/issues would be very appreciated.
Commented loop "cleans" things that were added to reduce if not/branches. For one-time icons, the function can be used, serpent.block the result, and then use the result instead of calling the function. In the case of modmash, the icons are dynamically generated, so the function is kept.
Results:
icons from above snippet of code
icons from other set of code
I'm often online with Discord for immediate issues: Honktown#2912