Velora


A Nauvis-like moon in orbit around Gleba. The surface shows structures from a more advanced civilization.

Content
11 days ago
2.0 - 2.1
5.57K
Planets Combat Environment Manufacturing Power

g "any-quality" icon

11 days ago

Subject: Bug: Science pack items get the "any-quality" icon appended to their own icons

Hi,

I found a bug in the science pack upcycling script (science_packs generation).

Problem

A few science packs end up showing the "any-quality" icon in the bottom-right corner of their item icon, even though the script is only supposed to add that overlay to the recipe icons.

Cause

In this block:

local icons = {}
if pack_item.icons then
    icons = pack_item.icons
else
    icons = {
        {
            icon = pack_item.icon,
            icon_size = pack_item.icon_size
        }
    }
end
table.insert(icons, {
    icon = "__core__/graphics/icons/any-quality.png",
    icon_size = 64,
    scale = 0.25,
    shift = { 11.5, 11.5 },
    floating = true
})

When pack_item.icons exists, icons = pack_item.icons is a reference assignment, not a copy. So icons and pack_item.icons point to the same Lua table. The subsequent table.insert(icons, ...) then mutates the original item's icons table, permanently appending the any-quality icon to the item itself.

This only affects science packs that are defined with the plural icons table. Packs defined with a single icon + icon_size go through the else branch, which creates a new table, so they are unaffected. That's why only a few science packs show the extra icon.

Fix

Deep-copy the original icons before modifying them:

if pack_item.icons then
    icons = table.deepcopy(pack_item.icons)
else
    icons = {
        {
            icon = pack_item.icon,
            icon_size = pack_item.icon_size
        }
    }
end

This way table.insert only modifies the copy used for the recipe icon, and the item's own icons stay untouched.

Thanks!

11 days ago

Wow, to be honest, I made the block with the icons more as a fallback (even though it's the first one), so I didn't notice that. Thanks—I'll fix it in the next update.

New response