Skip to content

Commit

Permalink
Stack.fix.4 (#287)
Browse files Browse the repository at this point in the history
* Category functions that misbehave will no longer break all bag rendering.

* Fixed duplicate items in the bank when stacking.

* Added trade window to interaction event list.
  • Loading branch information
Cidan authored Mar 11, 2024
1 parent d66e384 commit a89d623
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions BetterBags.toc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ animations\fade.lua
debug\debug.lua
debug\frames.lua
debug\profile.lua
debug\items.lua

core\events.lua
core\localization.lua
Expand Down
1 change: 1 addition & 0 deletions BetterBags_Vanilla.toc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ animations\fade.lua
debug\debug.lua
debug\frames.lua
debug\profile.lua
debug\items.lua

core\events.lua
core\localization.lua
Expand Down
1 change: 1 addition & 0 deletions BetterBags_Wrath.toc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ animations\fade.lua
debug\debug.lua
debug\frames.lua
debug\profile.lua
debug\items.lua

core\events.lua
core\localization.lua
Expand Down
1 change: 1 addition & 0 deletions core/hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ addon.backpackShouldOpen = false
addon.backpackShouldClose = false

local interactionEvents = {
[Enum.PlayerInteractionType.TradePartner] = true,
[Enum.PlayerInteractionType.Banker] = true,
[Enum.PlayerInteractionType.Merchant] = true,
[Enum.PlayerInteractionType.MailInfo] = true,
Expand Down
3 changes: 3 additions & 0 deletions core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ function addon:OnEnable()

events:RegisterMessage('items/RefreshBank/Done', function(_, itemData)
debug:Log("init/OnInitialize/items", "Drawing bank")
if addon.Bags.Bank.currentView then
addon.Bags.Bank.currentView.fullRefresh = true
end
addon.Bags.Bank:Draw(itemData)

end)
Expand Down
5 changes: 3 additions & 2 deletions data/categories.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ function categories:GetCustomCategory(kind, data)
if self.itemsWithNoCategory[itemID] then return nil end

for _, func in pairs(self.categoryFunctions) do
local category = func(data)
if category then
local success, args = xpcall(func, geterrorhandler(), data)
if success and args ~= nil then
local category = select(1, args) --[[@as string]]
local found = database:ItemCategoryExists(category)
database:SaveItemToCategory(itemID, category)
if not found then
Expand Down
6 changes: 4 additions & 2 deletions data/items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,13 @@ function items:BankLoadFunction()

---@type table<string, ItemData>
local stacks = {}

for bagid, bag in pairs(items.bankItemsByBagAndSlot) do
extraSlotInfo.emptySlotByBagAndSlot[bagid] = extraSlotInfo.emptySlotByBagAndSlot[bagid] or {}
for slotid, data in pairs(bag) do
items:AttachItemInfo(data, const.BAG_KIND.BANK)
data.stackedCount = 0
data.stackedOn = nil
data.stacks = 0
table.insert(items.dirtyBankItems, data)
-- Compute stacking data.
if items:ShouldItemStack(const.BAG_KIND.BANK, data) then
Expand All @@ -498,7 +500,7 @@ function items:BankLoadFunction()
data.stackedCount = data.itemInfo.currentItemCount
stacks[data.itemHash] = data
end
elseif data.stackedOn ~= nil or (data.stacks ~= nil and data.stacks > 0) then
else
data.stackedOn = nil
data.stacks = 0
data.stackedCount = data.itemInfo.currentItemCount
Expand Down
17 changes: 17 additions & 0 deletions debug/items.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
local addonName = ... ---@type string

---@class BetterBags: AceAddon
local addon = LibStub('AceAddon-3.0'):GetAddon(addonName)

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

---@param data ItemData
---@param id number
---@return boolean
function debug:IsItem(data, id)
if data and data.itemInfo and data.itemInfo.itemID == id then
return true
end
return false
end

0 comments on commit a89d623

Please sign in to comment.