Was wondering if someone could give me a quick rundown on how to properly use the icons property on items?
Basically, I'm looping through all items, and for each one that has a fuel_category of "chemical", I'm creating a new recipe and item that takes this item as an input. But I'm going to need different icons for them all so they are distinguishable from each other as they'll have different fuel_value(s) themselves based on the input item. I was thinking of just simply using the compilatron-chest.png icon for the base icon, then layer the fuel icon on top of it (though ideally I'd want to shrink it some) and want it to work with mod added fuels.
It's either that or I just use 1 output item with just the one fuel_value from multiple recipes and just scale the input quantity of the fuel item based on its fuel_value, but that seems boring and restrictive. :/
How to use item.icons?
-
- Smart Inserter
- Posts: 2593
- Joined: Tue Apr 25, 2017 2:01 pm
- Contact:
How to use item.icons?
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
Re: How to use item.icons?
Can't really give a rundown right now, but I CAN copy/paste the code I use to do a similar thing for Asteroid Mining
Should give you an idea on how to do it for your case. Note the shift + scale in the last layer - scale is how you resize the layer, and shift lets you place the layer within your icon. IIRC it starts centered in the icon, and this shifts it down and left 8 pixels each.
Each layer is drawn on top of the previous in order they appear in the table.
Code: Select all
--This is to generate the layered icons for the mining module, or whatever else needs it
function advancedicon(name, atint)
--log("Making " .. name .. " " .. serpent.block(data.raw.item[name]))
if data.raw.resource[name] then -- EVERYTHING we generate should be a resource
itempath = data.raw.resource
elseif data.raw.item[name] then -- We can try an item form.
itempath = data.raw.item
else -- Tenemut is a tool so try that?
itempath = data.raw.tool
end
icon = itempath[name].icon
iconsize = itempath[name].icon_size
iconmip = itempath[name].icon_mipmaps
tint = nil --Non-layered doesn't seem to support tints
--For layered icons, get the first layer for now
if icon == nil then
icon = itempath[name].icons[1].icon
if not iconsize then
iconsize = itempath[name].icons[1].icon_size
end
iconmip = itempath[name].icons[1].icon_mipmaps
tint = itempath[name].icons[1].tint
end
--The return is our layered icons we'll set to the new items .icons property.
return {
{
icon = "__Asteroid_Mining__/graphics/mining-sat.png",
icon_mipmaps = 4,
icon_size = 64
},
{
icon = "__Asteroid_Mining__/graphics/mining-sat-mask2.png",
icon_mipmaps = 4,
icon_size = 64,
tint = atint
},
{
icon = icon,
--icon_mipmaps = 4, --For now, no mipmaps
icon_size = iconsize,
scale = 16/iconsize, --They should be 16 pixels
shift = {
-8,
8
},
tint = tint
}
}
end
Each layer is drawn on top of the previous in order they appear in the table.
-
- Smart Inserter
- Posts: 2593
- Joined: Tue Apr 25, 2017 2:01 pm
- Contact:
Re: How to use item.icons?
Awesome, thanks! Just the stuff I was looking for!
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
-
- Smart Inserter
- Posts: 2593
- Joined: Tue Apr 25, 2017 2:01 pm
- Contact:
Re: How to use item.icons?
Ok, I just need to play around with the scaling and offsets to get my desired effect, but otherwise it works! Thanks again!
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics