function for generating 0.18+ compatible icons

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

function for generating 0.18+ compatible icons

Post by Honktown »

0.17 - > 0.18 changed many default icon sizes from 32x32 to 64x64. This creates a lot of issues. Took some time to work out code for shifting, scaling, and layering differently sized icons. This code is covered by the Unlicense. The function edits the original icon table in-place, which if not desired, can be easily changed to make a new table and return that instead. Works with recipes AND technologies.

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}}})
...
The above code is not the best example. It was adapted from previous code, and since the original table is edited, there's no need to return/assign from the function. The function reflects this (edits in place but returns table).

"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
I have mods! I guess!
Link

Post Reply

Return to “Modding discussion”