Add personal bank support to database function (#4)

* Add personal bank support to database function (#1)

* Update localization.lua

Add new localization for personal bank

* Update db.lua

Add support for personal bank

* Update tooltips.lua

Use personal bank info in tooltip

* Update db.lua

Fix duplicated function

* Update db.lua

Remove accidently added equality sign that is unneeded
This commit is contained in:
timothy-adam
2022-11-16 13:53:05 -05:00
committed by GitHub
parent ac47731f19
commit 8802eb045b
3 changed files with 148 additions and 33 deletions
+122 -27
View File
@@ -12,6 +12,8 @@ BagnonDB:SetScript('OnEvent', function(self, event, arg1)
end)
BagnonDB:RegisterEvent('ADDON_LOADED')
ASC_PERSONAL_BANK_OFFSET = 1000;
--constants
local L = BAGNON_FOREVER_LOCALS
local CURRENT_VERSION = GetAddOnMetadata('Bagnon_Forever', 'Version')
@@ -40,6 +42,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
@@ -51,6 +57,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
@@ -124,6 +135,10 @@ function BagnonDB:PLAYER_LOGIN()
self:SaveEquipment()
self:SaveNumBankSlots()
self:RegisterEvent('GUILDBANKFRAME_OPENED')
self:RegisterEvent('GUILDBANKFRAME_CLOSED')
self:RegisterEvent('GUILDBANKBAGSLOTS_CHANGED')
self:RegisterEvent('BANKFRAME_OPENED')
self:RegisterEvent('BANKFRAME_CLOSED')
self:RegisterEvent('PLAYER_MONEY')
@@ -164,6 +179,48 @@ function BagnonDB:BANKFRAME_CLOSED()
self.atBank = nil
end
function BagnonDB:GUILDBANKFRAME_OPENED()
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
end
if (self.IsPersonalBank) then
for i = 1, 6 do
local avail = GetGuildBankTabInfo(i)
if type(avail) == "string" then
self:UpdateBag(i + ASC_PERSONAL_BANK_OFFSET)
end
end
end
end
function BagnonDB:GUILDBANKFRAME_CLOSED()
self.IsPersonalBank = nil
self.IsRealmBank = nil
end
function BagnonDB:GUILDBANKBAGSLOTS_CHANGED()
if (self.IsPersonalBank) then
for i = 1, 6 do
local avail = GetGuildBankTabInfo(i)
if type(avail) == "string" then
self:UpdateBag(i + ASC_PERSONAL_BANK_OFFSET)
end
end
end
end
function BagnonDB:UNIT_INVENTORY_CHANGED(event, unit)
if unit == 'player' then
self:SaveEquipment()
@@ -314,6 +371,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
@@ -350,7 +412,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
@@ -364,48 +426,81 @@ end
--saves data about a specific item the current player has
function BagnonDB:SaveItem(bag, slot)
local texture, count = GetContainerItemInfo(bag, slot)
local index = ToIndex(bag, slot)
if texture then
local link = ToShortLink(GetContainerItemLink(bag, slot))
count = count > 1 and count or nil
if (bag > ASC_PERSONAL_BANK_OFFSET) then
local texture, count = GetGuildBankItemInfo(bag - ASC_PERSONAL_BANK_OFFSET, slot)
if(link and count) then
self.pdb[index] = format('%s,%d', link, count)
local index = ToIndex(bag, slot)
if texture then
local link = ToShortLink(GetGuildBankItemLink(bag - ASC_PERSONAL_BANK_OFFSET, slot))
count = count > 1 and count or nil
if(link and count) then
self.pdb[index] = format('%s,%d', link, count)
else
self.pdb[index] = link
end
else
self.pdb[index] = link
self.pdb[index] = nil
end
else
self.pdb[index] = nil
local texture, count = GetContainerItemInfo(bag, slot)
local index = ToIndex(bag, slot)
if texture then
local link = ToShortLink(GetContainerItemLink(bag, slot))
count = count > 1 and count or nil
if(link and count) then
self.pdb[index] = format('%s,%d', link, count)
else
self.pdb[index] = link
end
else
self.pdb[index] = nil
end
end
end
--saves all information about the given bag, EXCEPT the bag's contents
function BagnonDB:SaveBag(bag)
local data = self.pdb
local size = GetBagSize(bag)
local index = ToBagIndex(bag)
if size > 0 then
local equipSlot = bag > 0 and ContainerIDToInventoryID(bag)
local link = ToShortLink(GetInventoryItemLink('player', equipSlot))
local count = GetInventoryItemCount('player', equipSlot)
if count < 1 then
count = nil
end
if (bag >= ASC_PERSONAL_BANK_OFFSET) then
local size = GetBagSize(bag)
local index = ToBagIndex(bag)
self.pdb[index] = size
else
local size = GetBagSize(bag)
local index = ToBagIndex(bag)
if(size and link and count) then
self.pdb[index] = format('%d,%s,%d', size, link, count)
elseif(size and link) then
self.pdb[index] = format('%d,%s', size, link)
if size > 0 then
local equipSlot = bag > 0 and ContainerIDToInventoryID(bag)
local link = ToShortLink(GetInventoryItemLink('player', equipSlot))
local count = GetInventoryItemCount('player', equipSlot)
if count < 1 then
count = nil
end
if(size and link and count) then
self.pdb[index] = format('%d,%s,%d', size, link, count)
elseif(size and link) then
self.pdb[index] = format('%d,%s', size, link)
else
self.pdb[index] = size
end
else
self.pdb[index] = size
self.pdb[index] = nil
end
else
self.pdb[index] = nil
end
end
--saves both relevant information about the given bag, and all information about items in the given bag
@@ -451,4 +546,4 @@ function BagnonDB:RemovePlayer(player, realm)
end
end
end
end
end
@@ -5,4 +5,5 @@
BAGNON_NUM_BAGS = 'Bags: %d'
BAGNON_NUM_BANK = 'Bank: %d'
BAGNON_EQUIPPED = 'Equipped'
BAGNON_EQUIPPED = 'Equipped'
BAGNON_NUM_PBANK = 'PBank: %d'
+24 -5
View File
@@ -8,9 +8,9 @@ local itemInfo = {}
local SILVER = '|cffc7c7cf%s|r'
local TEAL = '|cff00ff9a%s|r'
local function CountsToInfoString(invCount, bankCount, equipCount)
local function CountsToInfoString(invCount, bankCount, equipCount, pbankCount)
local info
local total = invCount + bankCount + equipCount
local total = invCount + bankCount + equipCount + pbankCount
if invCount > 0 then
info = BAGNON_NUM_BAGS:format(invCount)
@@ -24,6 +24,15 @@ local function CountsToInfoString(invCount, bankCount, equipCount)
info = count
end
end
if pbankCount > 0 then
local count = BAGNON_NUM_PBANK:format(pbankCount)
if info then
info = strjoin(', ', info, count)
else
info = count
end
end
if equipCount > 0 then
if info then
@@ -57,10 +66,15 @@ do
for i = 1, NUM_BANKBAGSLOTS do
bankCount = bankCount + BagnonDB:GetItemCount(link, NUM_BAG_SLOTS + i, player)
end
local personalBankCount = 0
for i = 1, 6 do
personalBankCount = personalBankCount + BagnonDB:GetItemCount(link, i + ASC_PERSONAL_BANK_OFFSET, player)
end
local equipCount = BagnonDB:GetItemCount(link, 'e', player)
self[link] = CountsToInfoString(invCount or 0, bankCount or 0, equipCount or 0) or ''
self[link] = CountsToInfoString(invCount or 0, bankCount or 0, equipCount or 0, personalBankCount or 0) or ''
return self[link]
end})
end
@@ -80,10 +94,15 @@ local function AddOwners(frame, link)
for i = 1, NUM_BANKBAGSLOTS do
bankCount = bankCount + BagnonDB:GetItemCount(link, NUM_BAG_SLOTS + i, player)
end
local personalBankCount = 0
for i = 1, 6 do
personalBankCount = personalBankCount + BagnonDB:GetItemCount(link, i + ASC_PERSONAL_BANK_OFFSET, player)
end
local equipCount = BagnonDB:GetItemCount(link, 'e', player)
infoString = CountsToInfoString(invCount or 0, bankCount or 0, equipCount or 0)
infoString = CountsToInfoString(invCount or 0, bankCount or 0, equipCount or 0, personalBankCount or 0)
else
infoString = itemInfo[player][link]
end
@@ -105,4 +124,4 @@ local function HookTip(tooltip)
end
HookTip(GameTooltip)
HookTip(ItemRefTooltip)
HookTip(ItemRefTooltip)