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 db
local desc = format('%sCount', modulname) 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) function child:scanBag(bag)
local slot = 1 local slot = 1
local itemlist = {} local itemlist = {}
local empty = true local empty = true
while(slot<=C_Container.GetContainerNumSlots(bag)) do while(slot<=GetContainerNumSlots2(bag)) do
local item = Item:CreateFromBagAndSlot(bag, slot) local item = Item:CreateFromBagAndSlot(bag, slot)
if(item) then if(item) then
local itemInfo = C_Container.GetContainerItemInfo(bag, slot) local itemInfo = GetContainerItemInfo2(bag, slot)
local id = item:GetItemID() local id = item:GetItemID()
if(itemInfo and id) then if(itemInfo and id) then
empty = false empty = false
@ -30,16 +60,25 @@ function child:scanBag(bag)
end end
return empty and nil or itemlist return empty and nil or itemlist
end 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) local function scanAllBags(delayed)
if(not child:funcSync(scanAllBags, delayed)) then return end if(not child:funcSync(scanAllBags, delayed)) then return end
local playerID = child.getPID() local playerID = child.getPID()
if(playerID) then if(playerID) then
local tab = modul['db'][playerID] 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 tab[bag] = child:scanBag(bag) -- loop all bought bags
end end
for k,v in pairs(modul['db'][playerID]) do 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 tab[k] = nil -- prevent bogus bags
end end
end end

View File

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

View File

@ -201,7 +201,7 @@ function modul:Disable()
end end
end 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) child:addIgnore(WOW_PROJECT_ID, modulname)
end end
local init = { local init = {

View File

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