diff --git a/src/caches.lua b/src/caches.lua index a1a792b..fd67726 100644 --- a/src/caches.lua +++ b/src/caches.lua @@ -28,28 +28,32 @@ local function cache_groups(groupname, groups) i3.groups[groupname].items = groups_to_items(groups, true) local items = i3.groups[groupname].items - local nb_items = #items + if #items <= 1 then return end - if nb_items > 1 then - local px = 256 - local sprite = fmt("[combine:%ux%u", px, px * nb_items) + local c = 0 + local px = 256 + local sprite = "[combine:WxH" - for i = 1, nb_items do - local item = items[i] - local def = reg_items[item] - local texture = def.inventory_image or def.wield_image + for _, item in ipairs(items) do + local def = reg_items[item] + local texture = def.inventory_image or def.wield_image - if is_cube(def.drawtype) then - texture = get_cube(def.tiles) - elseif true_str(texture) then - texture = texture .. "\\^[resize\\:150x150" - end - - sprite = sprite .. fmt(":0,%u=%s", (i - 1) * px, texture) + if true_str(texture) then + texture = texture .. "\\^[resize\\:150x150" + elseif is_cube(def.drawtype) then + texture = get_cube(def.tiles) end - i3.groups[groupname].sprite = sprite + if true_str(texture) then + sprite = sprite .. fmt(":0,%u=%s", c * px, texture) + c++ + end end + + sprite = sprite:gsub("WxH", px .. "x" .. px * c) + + i3.groups[groupname].sprite = sprite + i3.groups[groupname].count = c end local function get_item_usages(item, recipe, added) diff --git a/src/gui.lua b/src/gui.lua index 62964a8..7b8de2d 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -1035,7 +1035,7 @@ local function get_grid_fs(fs, data, rcp, is_recipe) local sprite = ESC(group_cache.sprite) fs("item_image_button", X, Y, btn_size, btn_size, "", btn_name, "") - fs("animated_image", X + 0.01, Y + 0.01, 1.89, 1.89, sprite, #group_cache.items, 1000) + fs("animated_image", X + 0.01, Y + 0.01, 1.89, 1.89, sprite, group_cache.count, 1000) fs("label", X + 0.45, Y + 0.18, label) if _count > 1 then