Restore Classic compatibility

This commit is contained in:
Robin Hüskes 2023-01-22 12:50:18 +01:00
parent ef759c0ed1
commit b711bb8fc4
4 changed files with 85 additions and 29 deletions

View File

@ -9,14 +9,44 @@ local modul = {
}
local db
local desc = format('%sCount', modulname)
local GetContainerItemInfo = GetContainerItemInfo
if(C_Container and C_Container.GetContainerItemInfo) then
GetContainerItemInfo2 = C_Container.GetContainerItemInfo
else
GetContainerItemInfo2 = function(bag, slot)
local icon, itemCount, locked, quality, readable, lootable, itemLink, isFiltered, noValue, itemID, isBound = GetContainerItemInfo(bag, slot)
if(icon) then
return {
['iconFileID'] = icon,
['stackCount'] = itemCount,
['isLocked'] = locked,
['quality'] = quality,
['isReadable'] = readable,
['hasLoot'] = lootable,
['hyperlink'] = itemLink,
['isFiltered'] = isFiltered,
['hasNoValue'] = noValue,
['itemID'] = itemID,
['isBound'] = isBound
}
end
end
end
local function GetContainerNumSlots2(bag, slot)
if(C_Container and C_Container.GetContainerNumSlots) then
return C_Container.GetContainerNumSlots(bag, slot)
end
return GetContainerNumSlots(bag, slot)
end
function child:scanBag(bag)
local slot = 1
local itemlist = {}
local empty = true
while(slot<=C_Container.GetContainerNumSlots(bag)) do
while(slot<=GetContainerNumSlots2(bag)) do
local item = Item:CreateFromBagAndSlot(bag, slot)
if(item) then
local itemInfo = C_Container.GetContainerItemInfo(bag, slot)
local itemInfo = GetContainerItemInfo2(bag, slot)
local id = item:GetItemID()
if(itemInfo and id) then
empty = false
@ -30,16 +60,25 @@ function child:scanBag(bag)
end
return empty and nil or itemlist
end
local startbag, endbag
if(Enum and Enum.BagIndex) then
startbag = Enum.BagIndex.Backpack
endbag = Enum.BagIndex.ReagentBag
else
startbag = BACKPACK_CONTAINER
endbag = NUM_BAG_SLOTS
end
local function scanAllBags(delayed)
if(not child:funcSync(scanAllBags, delayed)) then return end
local playerID = child.getPID()
if(playerID) then
local tab = modul['db'][playerID]
for bag=Enum.BagIndex.Backpack ,Enum.BagIndex.ReagentBag do
print()
for bag=startbag ,endbag do
tab[bag] = child:scanBag(bag) -- loop all bought bags
end
for k,v in pairs(modul['db'][playerID]) do
if(k<Enum.BagIndex.Backpack or k>Enum.BagIndex.ReagentBag) then
if(k < startbag or k > endbag) then
tab[k] = nil -- prevent bogus bags
end
end

View File

@ -11,6 +11,20 @@ local db
local desc = format('%sCount', modulname)
local desc2 = 'reagentCount'
local BankIsOpen = false
local startbag, endbag, bankbag, reagentbankbag = 0, 4, -1, -3
if(Enum and Enum.BagIndex) then
startbag = Enum.BagIndex.Backpack
endbag = Enum.BagIndex.ReagentBag
bankbag = Enum.BagIndex.Bank
reagentbankbag = Enum.BagIndex.Reagentbank
reagentbag = Enum.BagIndex.ReagentBag
else
startbag = 6
endbag = startbag + GetNumBankSlots()
bankbag = BANK_CONTAINER
reagentbankbag = -3
reagentbag = BACKPACK_CONTAINER + NUM_BAG_SLOTS + 1
end
function modul.Guess(id)
local dbcount = modul.Get(id)
local count = GetItemCount(id,true)
@ -20,7 +34,7 @@ function modul.Guess(id)
local dif = dbcount - count
modul['db'][playerID] = modul['db'][playerID] or {}
local tab = modul['db'][playerID]
for bag = Enum.BagIndex.BankBag_1 ,Enum.BagIndex.BankBag_1 + GetNumBankSlots() - 1 do
for bag = startbag ,endbag - 1 do
local btab = tab[bag]
if(btab and btab[id] and btab[id]['count'] > 0) then
while(dif > 0 and btab[id]['count'] > 0) do
@ -54,7 +68,7 @@ local function scanAllBankBags(delayed)
if(playerID) then
modul['db'][playerID] = modul['db'][playerID] or {}
local tab = modul['db'][playerID]
for bag = Enum.BagIndex.BankBag_1 ,Enum.BagIndex.BankBag_1 + GetNumBankSlots() - 1 do
for bag = startbag ,endbag - 1 do
tab[bag] = tab[bag] or {}
if(BankIsOpen) then
tab[bag] = child:scanBag(bag) -- loop all bought bankbags
@ -63,17 +77,17 @@ local function scanAllBankBags(delayed)
end
end
if(BankIsOpen) then
tab[Enum.BagIndex.Bank] = child:scanBag(Enum.BagIndex.Bank) -- Main bankbag
tab[bankbag] = child:scanBag(bankbag) -- Main bankbag
else
guess(tab[Enum.BagIndex.Bank])
guess(tab[bankbag])
end
if(BankIsOpen) then
tab[Enum.BagIndex.Reagentbank] = child:scanBag(Enum.BagIndex.Reagentbank) -- Main reagentbag
tab[reagentbankbag] = child:scanBag(reagentbankbag) -- Main reagentbag
else
guess(tab[Enum.BagIndex.Reagentbank])
guess(tab[reagentbankbag])
end
for k,v in pairs(modul['db'][playerID]) do
if(not(k == Enum.BagIndex.Bank) and not(k == Enum.BagIndex.Reagentbank) and not(k > Enum.BagIndex.ReagentBag and k <= GetNumBankSlots() + Enum.BagIndex.ReagentBag)) then
if(not(k == bankbag) and not(k == reagentbankbag) and not(k > reagentbag and k <= GetNumBankSlots() + reagentbag)) then
tab[k] = nil -- prevent bogus bankbags
end
end
@ -89,7 +103,7 @@ local function bagLoop(id, res)
if(playerID and units[k]['faction'] == units[playerID]['faction']) then
local unitname = units[k]['name']
for bag, list in pairs(v) do
dName = (bag == Enum.BagIndex.Reagentbank) and desc2 or desc
dName = (bag == reagentbankbag) and desc2 or desc
for a, b in pairs(list) do
if(a == id) then
res[unitname] = res[unitname] or {
@ -135,7 +149,9 @@ function events:PLAYERBANKBAGSLOTS_CHANGED(...)
scanAllBankBags()
end
events.PLAYERBANKSLOTS_CHANGED = events.PLAYERBANKBAGSLOTS_CHANGED
events.PLAYERREAGENTBANKSLOTS_CHANGED = events.PLAYERBANKBAGSLOTS_CHANGED
if(BuyReagentBank) then
events.PLAYERREAGENTBANKSLOTS_CHANGED = events.PLAYERBANKBAGSLOTS_CHANGED
end
events.ITEM_UNLOCKED = events.PLAYERBANKBAGSLOTS_CHANGED
events.BAG_UPDATE_DELAYED = events.PLAYERBANKBAGSLOTS_CHANGED
local function OnEvent(self, event, ...)
@ -171,15 +187,13 @@ function modul:Delete(id, typ)
self['db'][id] = nil
end
end
local skip = {
[WOW_PROJECT_WRATH_CLASSIC] = {
['PLAYERREAGENTBANKSLOTS_CHANGED'] = true
},
[WOW_PROJECT_MAINLINE] = {
local skip = {}
if(WOW_PROJECT_MAINLINE) then
skip[WOW_PROJECT_MAINLINE] = {
['BANKFRAME_OPENED'] = true,
['BANKFRAME_CLOSED'] = true
}
}
}
end
function modul:Enable()
self['status'] = true
local list = {}

View File

@ -201,7 +201,7 @@ function modul:Disable()
end
end
end
if(LE_EXPANSION_LEVEL_CURRENT<LE_EXPANSION_WRATH_OF_THE_LICH_KING or not _G['GetCurrencyListInfo']) then
if(not LE_EXPANSION_WRATH_OF_THE_LICH_KING or LE_EXPANSION_LEVEL_CURRENT<LE_EXPANSION_WRATH_OF_THE_LICH_KING or not _G['GetCurrencyListInfo']) then
child:addIgnore(WOW_PROJECT_ID, modulname)
end
local init = {

View File

@ -111,16 +111,19 @@ end
local function MFClose()
voidOpen = false
end
local skip = {
[WOW_PROJECT_MAINLINE] = {
['VOID_STORAGE_CLOSE'] = true,
['VOID_STORAGE_OPEN'] = true
},
[WOW_PROJECT_WRATH_CLASSIC] = {
local skip = {}
if(WOW_PROJECT_MAINLINE) then
skip[WOW_PROJECT_MAINLINE] = {
['VOID_STORAGE_CLOSE'] = true,
['VOID_STORAGE_OPEN'] = true
}
}
end
if(WOW_PROJECT_WRATH_CLASSIC) then
skip[WOW_PROJECT_WRATH_CLASSIC] = {
['VOID_STORAGE_CLOSE'] = true,
['VOID_STORAGE_OPEN'] = true
}
end
function modul:Enable()
self['status'] = true
local list = {}
@ -144,7 +147,7 @@ function modul:Disable()
self['frame']:UnregisterEvent(event)
end
end
if(LE_EXPANSION_LEVEL_CURRENT<LE_EXPANSION_CATACLYSM or not _G['GetVoidItemInfo']) then
if(not LE_EXPANSION_CATACLYSM or LE_EXPANSION_LEVEL_CURRENT<LE_EXPANSION_CATACLYSM or not _G['GetVoidItemInfo']) then
child:addIgnore(WOW_PROJECT_ID, modulname)
end
local init = {