Use ClassicAPI bag families for free slot counts

This commit is contained in:
Dusk-92
2026-08-23 21:46:35 +02:00
parent 21a0812cee
commit 7d58a92db0
+24 -61
View File
@@ -35,73 +35,36 @@ module.enable = function(self)
button.count:SetJustifyH("RIGHT") button.count:SetJustifyH("RIGHT")
button.count:SetFontObject(GameFontWhite) button.count:SetFontObject(GameFontWhite)
-- class-specific bags local function UpdateSlots()
local soul = { "Core Felcloth Bag", "D'Sak's Small bag", "Felcloth Bag", "Box of Souls", "Small Soul Pouch", "Soul Pouch" } local freeClass, freeReagent, freeGeneral = 0, 0, 0
local quiver = { "Ancient Sinew Wrapped Lamina", "Harpy Hide Quiver", "Heavy Quiver", "Quickdraw Quiver", "Quiver of the Night Watch", "Ribbly's Quiver", "Hunting Quiver", "Light Leather Quiver", "Light Quiver", "Medium Quiver", "Small Quiver" } local hasClass, hasReagent = false, false
local pouch = { "Gnoll Skin Bandolier", "Bandolier of the Night Watch", "Heavy Leather Ammo Pouch", "Ribbly's Bandolier", "Thick Leather Ammo Pouch", "Hunting Ammo Sack", "Medium Shot Pouch", "Small Ammo Pouch", "Small Leather Ammo Pouch", "Small Shot Pouch" }
-- reagent bags
local herb = { "Cenarion Herb Bag", "Herb Pouch", "Satchel of Cenarius" }
local ench = { "Big Bag of Enchantment", "Enchanted Mageweave Pouch", "Enchanted Runecloth Bag" }
local freeClass = 0 for bag = 0, 4 do
local freeReagent = 0 local free, family = C_Container.GetContainerNumFreeSlots(bag)
free = free or 0
family = family or 0
local function findName(name, names) -- Preserve the original categories exactly:
for _, bagName in ipairs(names) do -- arrows/ammo/soul bags are class bags; herb/enchanting bags are reagents.
if string.find(name, bagName) then return true end if family == 1 or family == 2 or family == 4 then
end hasClass = true
return false freeClass = freeClass + free
end elseif family == 32 or family == 64 then
hasReagent = true
local function classSlots() freeReagent = freeReagent + free
local found, free = false, 0 else
for i = 0, 4 do freeGeneral = freeGeneral + free
local name = GetBagName(i)
if name and (findName(name, soul) or findName(name, quiver) or findName(name, pouch)) then
found = true
for slot = 1, GetContainerNumSlots(i) do
if not GetContainerItemLink(i, slot) then free = free + 1 end
end
end end
end end
freeClass = free
button.class:SetText(found and free or "") button.class:SetText(hasClass and freeClass or "")
button.reagent:SetText(hasReagent and freeReagent or "")
button.count:SetText(freeGeneral)
end end
local function reagentSlots() UpdateSlots()
local found, free = false, 0
for i = 0, 4 do
local name = GetBagName(i)
if name and (findName(name, herb) or findName(name, ench)) then
found = true
for slot = 1, GetContainerNumSlots(i) do
if not GetContainerItemLink(i, slot) then free = free + 1 end
end
end
end
freeReagent = free
button.reagent:SetText(found and free or "")
end
local function freeSlots()
local free = 0
for i = 0, 4 do
for slot = 1, GetContainerNumSlots(i) do
if not GetContainerItemLink(i, slot) then free = free + 1 end
end
end
button.count:SetText(free - freeClass - freeReagent)
end
classSlots()
reagentSlots()
freeSlots()
local events = CreateFrame("Frame") local events = CreateFrame("Frame")
events:RegisterEvent("BAG_UPDATE") events:RegisterEvent("BAG_UPDATE_DELAYED")
events:SetScript("OnEvent", function() events:SetScript("OnEvent", UpdateSlots)
classSlots()
reagentSlots()
freeSlots()
end)
end end