fix(db): 🐛 Fixes an issue where personal and realm bank information wouldn't get updated (#11)
* fix(db): 🐛 Fixes an issue where personal and realm bank information wouldn't get updated Introduce the "Blizzard_GuildBankUI" addon in constructor, ensuring that the `GuildBankFrame` is loaded for bank type detection. Hide the Blizzard Guildbank to avoid both Bagnon and Blizzard banks being shown at the same time. This breaks the red color from the bank tabs * refactor(db): ♻️ Use old implementation for personal and guild bank detection * fix: 🐛 Fix issue where personal and realm bank wasn't identified on guild bank change event * fix(db): 🐛 Fixes an issue where only current guild bank tab would be added to db Use `QueryGuildBankTab` to preload items in guild bank tabs and identify trigger in GUILDBANKBAGSLOTS_CHANGED event to update bags when items are ready * fix(db): 🐛 Correctly index realm and personal banks on initial load
This commit is contained in:
committed by
GitHub
parent
53749e8ec5
commit
5b7a73a9c2
@@ -23,6 +23,9 @@ local function GetIDFromLink(link)
|
||||
end
|
||||
|
||||
local function GetAscensionBankType()
|
||||
-- The logic doesn't work because GuildBankFrame is not loaded
|
||||
-- However the sort still works because it can sort using 'guild' as a fallback
|
||||
-- but personal and realm branches are never reached
|
||||
if GuildBankFrame and GuildBankFrame.IsPersonalBank then
|
||||
return "personal"
|
||||
elseif GuildBankFrame and GuildBankFrame.IsRealmBank then
|
||||
|
||||
+75
-43
@@ -15,14 +15,7 @@ BagnonDB:RegisterEvent('ADDON_LOADED')
|
||||
|
||||
ASC_PERSONAL_BANK_OFFSET = 1000;
|
||||
ASC_REALM_BANK_OFFSET = 2000;
|
||||
|
||||
local function IsPersonalBank()
|
||||
return GuildBankFrame and GuildBankFrame.IsPersonalBank
|
||||
end
|
||||
|
||||
local function IsRealmBank()
|
||||
return GuildBankFrame and GuildBankFrame.IsRealmBank
|
||||
end
|
||||
GUILDBANKBAGSLOTS_CHANGED_INIT_OFFSET = 2; -- Offset used to identify when guild bank tabs are loaded
|
||||
|
||||
--constants
|
||||
local L = BAGNON_FOREVER_LOCALS
|
||||
@@ -52,10 +45,10 @@ end
|
||||
local function ToShortLink(link)
|
||||
if link then
|
||||
local a,b,c,d,e,f,g,h = link:match('(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+)')
|
||||
|
||||
|
||||
--ASC sets this to unique id in the personal bank, clear it
|
||||
c = 0;
|
||||
|
||||
|
||||
if(b == '0' and b == c and c == d and d == e and e == f and f == g) then
|
||||
return a
|
||||
end
|
||||
@@ -67,11 +60,11 @@ local function GetBagSize(bag)
|
||||
if bag == KEYRING_CONTAINER then
|
||||
return GetKeyRingSize()
|
||||
end
|
||||
|
||||
|
||||
if (bag >= ASC_PERSONAL_BANK_OFFSET) then
|
||||
return 98
|
||||
end
|
||||
|
||||
|
||||
if bag == 'e' then
|
||||
return NUM_EQUIPMENT_SLOTS
|
||||
end
|
||||
@@ -154,6 +147,7 @@ function BagnonDB:PLAYER_LOGIN()
|
||||
|
||||
self:RegisterEvent('GUILDBANKFRAME_OPENED')
|
||||
self:RegisterEvent('GUILDBANKBAGSLOTS_CHANGED')
|
||||
self:RegisterEvent('GUILDBANKFRAME_CLOSED')
|
||||
self:RegisterEvent('BANKFRAME_OPENED')
|
||||
self:RegisterEvent('BANKFRAME_CLOSED')
|
||||
self:RegisterEvent('PLAYER_MONEY')
|
||||
@@ -199,47 +193,85 @@ end
|
||||
|
||||
|
||||
function BagnonDB:GUILDBANKFRAME_OPENED()
|
||||
if IsPersonalBank() then
|
||||
for i = 1, 6 do
|
||||
local avail = GetGuildBankTabInfo(i)
|
||||
if type(avail) == "string" then
|
||||
self:UpdateBag(i + ASC_PERSONAL_BANK_OFFSET)
|
||||
-- Identify bank type from permissions payload
|
||||
if HasJsonCacheData("BANK_PERMISSIONS_PAYLOAD", 0) then
|
||||
local json = GetJsonCacheData("BANK_PERMISSIONS_PAYLOAD", 0)
|
||||
if json then
|
||||
local jsonObject = C_Serialize:FromJSON(json)
|
||||
if jsonObject then
|
||||
self.IsPersonalBank = jsonObject.IsPersonalBank
|
||||
self.IsRealmBank = jsonObject.IsRealmBank
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if IsRealmBank() then
|
||||
for i = 1, 6 do
|
||||
local avail = GetGuildBankTabInfo(i)
|
||||
if type(avail) == "string" then
|
||||
self:UpdateBag(i + ASC_REALM_BANK_OFFSET)
|
||||
end
|
||||
self.guildBankUpdateCalls = 0
|
||||
self.availableTabs = {} -- table of available tabs
|
||||
|
||||
-- Query all tabs for personal and realm bank to preload data
|
||||
for i = 1, 6 do
|
||||
local avail = GetGuildBankTabInfo(i)
|
||||
if type(avail) == "string" and i ~= currentTab then
|
||||
QueryGuildBankTab(i)
|
||||
self.availableTabs[i] = avail
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
function BagnonDB:GUILDBANKBAGSLOTS_CHANGED()
|
||||
if IsPersonalBank() then
|
||||
for i = 1, 6 do
|
||||
local avail = GetGuildBankTabInfo(i)
|
||||
if type(avail) == "string" then
|
||||
self:UpdateBag(i + ASC_PERSONAL_BANK_OFFSET)
|
||||
self.guildBankUpdateCalls = self.guildBankUpdateCalls + 1
|
||||
local currentTab = GetCurrentGuildBankTab()
|
||||
|
||||
-- Special operation: After 2 initial calls, the QueryGuildBankTab calls above
|
||||
-- trigger the GUILDBANKBAGSLOTS_CHANGED event at which the queried items are available.
|
||||
|
||||
-- Only update the bank if we are within 1-6 range of the initial calls as those
|
||||
-- are likely triggered by the QueryGuildBankTab calls above. Which makes items
|
||||
-- in the tabs available for GetGuildBankItemInfo calls.
|
||||
if ((self.guildBankUpdateCalls > GUILDBANKBAGSLOTS_CHANGED_INIT_OFFSET)
|
||||
and (self.guildBankUpdateCalls <= GUILDBANKBAGSLOTS_CHANGED_INIT_OFFSET + #self.availableTabs)) then
|
||||
for i, avail in pairs(self.availableTabs) do
|
||||
-- Ignore current tab, and only update the tab that is next in the sequence
|
||||
if (i ~= currentTab and self.guildBankUpdateCalls == GUILDBANKBAGSLOTS_CHANGED_INIT_OFFSET + i) then
|
||||
if self.IsPersonalBank then
|
||||
self:UpdateBag(i + ASC_PERSONAL_BANK_OFFSET)
|
||||
elseif self.IsRealmBank then
|
||||
self:UpdateBag(i + ASC_REALM_BANK_OFFSET)
|
||||
else
|
||||
print("[BagnonForever] Error: Unknown bank type")
|
||||
end
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if IsRealmBank() then
|
||||
for i = 1, 6 do
|
||||
local avail = GetGuildBankTabInfo(i)
|
||||
if type(avail) == "string" then
|
||||
self:UpdateBag(i + ASC_REALM_BANK_OFFSET)
|
||||
end
|
||||
-- Normal operation: Update current tab
|
||||
if self.IsPersonalBank then
|
||||
local avail = GetGuildBankTabInfo(currentTab)
|
||||
if type(avail) == "string" then
|
||||
self:UpdateBag(currentTab + ASC_PERSONAL_BANK_OFFSET)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- Update all tabs for realm bank on any change
|
||||
if self.IsRealmBank then
|
||||
local avail = GetGuildBankTabInfo(currentTab)
|
||||
if type(avail) == "string" then
|
||||
self:UpdateBag(currentTab + ASC_REALM_BANK_OFFSET)
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
function BagnonDB:GUILDBANKFRAME_CLOSED()
|
||||
self.IsPersonalBank = nil
|
||||
self.IsRealmBank = nil
|
||||
self.guildBankUpdateCalls = 0
|
||||
end
|
||||
|
||||
function BagnonDB:UNIT_INVENTORY_CHANGED(event, unit)
|
||||
if unit == 'player' then
|
||||
@@ -391,11 +423,11 @@ function BagnonDB:GetItemCount(itemLink, bag, player)
|
||||
local total = 0
|
||||
local itemLink = select(2, GetItemInfo(ToShortLink(itemLink)))
|
||||
local size = (self:GetBagData(bag, player)) or 0
|
||||
|
||||
|
||||
if (bag == "e") then
|
||||
size = NUM_EQUIPMENT_SLOTS
|
||||
end
|
||||
|
||||
|
||||
for slot = 1, size do
|
||||
local link, count = self:GetItemData(bag, slot, player)
|
||||
if link == itemLink then
|
||||
@@ -432,7 +464,7 @@ function BagnonDB:SaveEquipment()
|
||||
local link = ToShortLink(link)
|
||||
local count = GetInventoryItemCount('player', slot)
|
||||
count = count > 1 and count or nil
|
||||
|
||||
|
||||
if(link and count) then
|
||||
self.pdb[index] = format('%s,%d', link, count)
|
||||
else
|
||||
@@ -513,7 +545,7 @@ function BagnonDB:SaveBag(bag)
|
||||
local size = GetBagSize(bag)
|
||||
local index = ToBagIndex(bag)
|
||||
self.pdb[index] = size
|
||||
else
|
||||
else
|
||||
local size = GetBagSize(bag)
|
||||
local index = ToBagIndex(bag)
|
||||
|
||||
@@ -535,11 +567,11 @@ function BagnonDB:SaveBag(bag)
|
||||
else
|
||||
self.pdb[index] = nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user