Skip to content

Commit

Permalink
18 tooltip showing wrong itemrankings (#19)
Browse files Browse the repository at this point in the history
* moved table sorting from tooltip trigger to db import function

* increased version
  • Loading branch information
zahdr authored Jun 26, 2023
1 parent 0ea090e commit 338594e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion LootplanIt.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: LootPlanIt
## Author: zahdr
## Notes: Make Loot Council easy!
## Version: v0.2.3
## Version: v0.2.4
## DefaultState: enabled
## SavedVariables: LootPlanItDB
## X-Curse-Project-ID: 876058
Expand Down
32 changes: 27 additions & 5 deletions classes/db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ local _, LPI = ...;
LPI.db = {}
db = LPI.db


local function sortByItemRating(a, b)
local ratingA = tonumber(string.sub(a["itemRating"], 1, -2))
local ratingB = tonumber(string.sub(b["itemRating"], 1, -2))

return ratingA > ratingB
end

local function sortSubTablesByItemRating(tbl)
for key, subTable in pairs(tbl) do
if #subTable > 1 then
table.sort(subTable, sortByItemRating)
end
end
end


function db:init()
if not LootPlanItDB then
LootPlanItDB = {}
Expand Down Expand Up @@ -31,6 +48,8 @@ function db:resetLootCouncilData()
end

function LPI:importLootCouncilData(data)
local tmpTbl = {}

if type(data) == "string" then
data = LPI:convertStringToTable(data)
end
Expand All @@ -40,9 +59,9 @@ function LPI:importLootCouncilData(data)
local itemRating = entry[2]
local itemPrio = entry[3]
local playerName = entry[4]
if not LootPlanItDB.lootCouncil.itemIds[itemId] then
LootPlanItDB.lootCouncil.itemIds[itemId] = {}

if not tmpTbl[itemId] then
tmpTbl[itemId] = {}
end

local record = {
Expand All @@ -51,8 +70,11 @@ function LPI:importLootCouncilData(data)
playerName = playerName
}

table.insert(LootPlanItDB.lootCouncil.itemIds[itemId], record)
end
table.insert(tmpTbl[itemId], record)
end

sortSubTablesByItemRating(tmpTbl)
LootPlanItDB.lootCouncil.itemIds = tmpTbl
LPI:infoMessage("Loot Council Items imported successfully!")
end

Expand Down
3 changes: 2 additions & 1 deletion classes/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ function LPI:convertStringToTable(string)
end
table.insert(dataTable, tmpTable)
end

return dataTable
end
end
8 changes: 0 additions & 8 deletions classes/tooltip.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
local _, LPI = ...;

local function compareItemRating(a, b)
local ratingA = tonumber(a.itemRating:sub(1, -2)) / 100
local ratingB = tonumber(b.itemRating:sub(1, -2)) / 100

return ratingA > ratingB
end

function tooltipAddPrios(tooltip)
local _, itemLink = tooltip:GetItem()
local itemId = tostring(GetItemInfoFromHyperlink(itemLink))
local loopStop = 0

if LootPlanItDB.lootCouncil.itemIds[itemId] then
table.sort(LootPlanItDB.lootCouncil.itemIds[itemId], compareItemRating)
for _, record in pairs(LootPlanItDB.lootCouncil.itemIds[itemId]) do
if loopStop == 0 then
loopStop = 1
Expand Down

0 comments on commit 338594e

Please sign in to comment.