Skip to content

Commit

Permalink
refactor: bring out the test items to its own function
Browse files Browse the repository at this point in the history
  • Loading branch information
zeevallin committed Dec 19, 2020
1 parent 05871db commit 501e370
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions Loot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -375,21 +375,9 @@ end

function Addon:OnEnable()
-- Iterate over all bags and add the contents to the items array.
-- TODO: Make this a bit nicer to make sure the items are rendered on demand when test mode is disabled at runtime.
self.items = {}
if self.db.profile.test then
self.items = {}
local player = Player:GetCurrent()
local i1 = 0
for i = 4, 0, -1 do
for i2 = GetContainerNumSlots(i), 0, -1 do
local link = select(7, GetContainerItemInfo(i,i2))
if link and (i1 < 100) then
local item = LootItem:new(player, link)
table.insert(self.items, item)
i1 = i1+1
end
end
end
self.items = GenerateTestItems()
end

-- Clear out all sessions older than a set amount of hours when adodn loads.
Expand Down Expand Up @@ -1179,3 +1167,21 @@ function dump(o)
return tostring(o)
end
end

-- Generate test items to be used during addon testing based on what's in the player's backpack.
function GenerateTestItems()
local items = {}
local player = Player:GetCurrent()
local i1 = 0
for i = 4, 0, -1 do
for i2 = GetContainerNumSlots(i), 0, -1 do
local link = select(7, GetContainerItemInfo(i,i2))
if link and (i1 < 100) then
local item = LootItem:new(player, link)
table.insert(items, item)
i1 = i1+1
end
end
end
return items
end

0 comments on commit 501e370

Please sign in to comment.