Item with quality in sprite-button LuaGuiElement
Posted: Mon Dec 16, 2024 9:43 pm
How to draw item with quality in slot-like sprite-button correctly?
www.factorio.com
https://forums.factorio.com/
Code: Select all
local function make_sprites(item)
for _, quality in pairs(data.raw.quality) do
if quality.icon or quality.icons and quality.icons[1] and (quality.icons[1].filename or quality.icons[1][1]) then
local spr = {
type="sprite",
name = item.name.."-"..quality.name,
priority = "extra-high",
layers = {}
}
if item.icons then
for _, icon in pairs(item.icons) do
table.insert(spr.layers,{
filename = icon.filename or icon[1],
height = icon.icon_size or 64,
width = icon.icon_size or 64,
})
end
elseif item.icon then
table.insert(spr.layers,{
filename = item.icon,
height = item.icon_size or 64,
width = item.icon_size or 64,
})
end
if quality.name ~="normal" then
if quality.icon then
table.insert(spr.layers,{
filename = quality.icon,
height = quality.icon_size or 64,
width = quality.icon_size or 64,
scale = 24/( quality.icon_size or 64),
shift = {-20,20},
})
elseif quality.icons then
table.insert(spr.layers,{
filename = quality.icons[1].filename or quality.icons[1][1],
height = quality.icons[1].icon_size or 64,
width = quality.icons[1].icon_size or 64,
scale = 24/(quality.icons[1].icon_size or 64),
shift = {-20,20},
})
end
end
if #spr.layers >0 then
data:extend{spr}
else
--error(item.name.." "..quality.name)
end
end
end
end