Skip to content

Commit

Permalink
Fixed a bug where items in an equipment set with duplicate ID's can b…
Browse files Browse the repository at this point in the history
…e marked as in a set.
  • Loading branch information
Cidan committed Dec 4, 2023
1 parent 6d60c04 commit e3365f5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion BetterBags.toc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ debug\frames.lua

theme\masque.lua

data\items.lua
data\equipmentsets.lua
data\items.lua
data\categories.lua

util\color.lua
Expand Down
5 changes: 5 additions & 0 deletions annotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ function MinimalScrollBar:SetInterpolateScroll(interpolate) end
---@class EventFrame
local EventFrame = {}

---@param location number
---@return boolean, boolean, boolean, boolean, number, number
function EquipmentManager_UnpackLocation(location) end

-- ItemInfo is the information about an item that is returned by GetItemInfo.
---@class (exact) ExpandedItemInfo
---@field itemID number
Expand Down Expand Up @@ -182,6 +186,7 @@ local EventFrame = {}
---@field currentItemCount number
---@field category string
---@field currentItemLevel number
---@field equipmentSet string|nil

--[[
---@class ItemMixin
Expand Down
30 changes: 15 additions & 15 deletions data/equipmentsets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,42 @@ local addonName = ... ---@type string
local addon = LibStub('AceAddon-3.0'):GetAddon(addonName)

---@class EquipmentSets: AceModule
---@field itemToSet table<number, string>
---@field bagAndSlotToSet table<number, table<number, string>>
local equipmentSets = addon:NewModule('EquipmentSets')

---@class Events: AceModule
local events = addon:GetModule('Events')

---@class Items: AceModule
local items = addon:GetModule('Items')

function equipmentSets:OnInitialize()
self.itemToSet = {}
self.bagAndSlotToSet = {}
end

function equipmentSets:OnEnable()
events:RegisterEvent('EQUIPMENT_SETS_CHANGED', function() self:Update() end)
self:Update()
end

function equipmentSets:Update()
wipe(self.itemToSet)
wipe(self.bagAndSlotToSet)
local sets = C_EquipmentSet.GetEquipmentSetIDs()
for _, setID in ipairs(sets) do
local setName = C_EquipmentSet.GetEquipmentSetInfo(setID)
local itemIDs = C_EquipmentSet.GetItemIDs(setID)
for _, itemID in ipairs(itemIDs) do
self.itemToSet[itemID] = setName
local setLocations = C_EquipmentSet.GetItemLocations(setID)
for _, location in ipairs(setLocations) do
local _, bank, bags, _, slot, bag = EquipmentManager_UnpackLocation(location)
if (bank or bags) and slot ~= nil and bag ~= nil then
self.bagAndSlotToSet[bag] = self.bagAndSlotToSet[bag] or {}
self.bagAndSlotToSet[bag][slot] = setName
end
end
end
items:RefreshAll()
end

---@param itemID number|nil
---@param bagid number
---@param slotid number
---@return string|nil
function equipmentSets:GetItemSet(itemID)
if not itemID then return nil end
return self.itemToSet[itemID]
function equipmentSets:GetItemSet(bagid, slotid)
if not bagid or not slotid then return nil end
return self.bagAndSlotToSet[bagid] and self.bagAndSlotToSet[bagid][slotid]
end

equipmentSets:Enable()
7 changes: 7 additions & 0 deletions data/items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ local events = addon:GetModule('Events')
---@class Constants: AceModule
local const = addon:GetModule('Constants')

---@class EquipmentSets: AceModule
local equipmentSets = addon:GetModule('EquipmentSets')

---@class Debug: AceModule
local debug = addon:GetModule('Debug')

Expand Down Expand Up @@ -41,6 +44,7 @@ end
function items:OnEnable()
--events:RegisterMessage('items/RefreshAllItems/Done', printDirtyItems)
--events:RegisterEvent('BAG_UPDATE_DELAYED', self.RefreshAll, self)
events:RegisterEvent('EQUIPMENT_SETS_CHANGED', function() self:RefreshAll() end)
events:BucketEvent('BAG_UPDATE_DELAYED', function() self:RefreshAll() end)
events:RegisterEvent('BANKFRAME_OPENED', self.RefreshBank, self)
end
Expand Down Expand Up @@ -74,6 +78,7 @@ function items:RefreshReagentBank()
end

function items:RefreshBank()
equipmentSets:Update()
self._bankContainer = ContinuableContainer:Create()

-- This is a small hack to force the bank bag quality data to be cached
Expand All @@ -100,6 +105,7 @@ function items:RefreshBackpack()
if self._doingRefreshAll then
return
end
equipmentSets:Update()
self._doingRefreshAll = true
self._container = ContinuableContainer:Create()
wipe(self.dirtyItems)
Expand Down Expand Up @@ -195,6 +201,7 @@ function items:AttachItemInfo(data)
currentItemCount = C_Item.GetStackCount(itemLocation),
category = "",
currentItemLevel = C_Item.GetCurrentItemLevel(itemLocation) --[[@as number]],
equipmentSet = equipmentSets:GetItemSet(bagid, slotid),
}
end

Expand Down
5 changes: 2 additions & 3 deletions frames/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,8 @@ function itemProto:GetCategory()
end

-- Check for equipment sets next.
local equipmentSet = equipmentSets:GetItemSet(self.data.itemInfo.itemID)
if equipmentSet then
self.data.itemInfo.category = "Gear: " .. equipmentSet
if self.data.itemInfo.equipmentSet then
self.data.itemInfo.category = "Gear: " .. self.data.itemInfo.equipmentSet
return self.data.itemInfo.category
end

Expand Down

0 comments on commit e3365f5

Please sign in to comment.