Skip to content

Commit

Permalink
3.0.2
Browse files Browse the repository at this point in the history
Fixed issue causing Session data to be incorrect
Updated process of adding/removing filters to not reset session data for all items
  • Loading branch information
Noshei committed Oct 31, 2024
1 parent 4d030d6 commit 81c0ea1
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 124 deletions.
7 changes: 5 additions & 2 deletions Config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,7 @@ local generalOptions = {
[3] = "Debug",
[4] = "Trace (Very Spammy)",
[5] = "Notification Spam",
[6] = "Mass Item Spam"
},
get = function()
if type(GT.db.profile.General.debugOption) == "boolean" then
Expand Down Expand Up @@ -1351,7 +1352,8 @@ for expansion, expansionData in pairs(GT.ItemData) do
GT.db.profile.Filters[itemData.id] = nil
end

GT:RebuildIDTables()
GT:UpdateIDTable(itemData.id, key)
GT:RemoveItemData(key, itemData.id)
GT:InventoryUpdate("Filters " .. expansion .. " " .. category .. " " .. itemData.name .. " option clicked", true)
end,
width = 1.2,
Expand Down Expand Up @@ -1394,7 +1396,8 @@ function GT:CreateCustomFilterOptions()
GT.db.profile.CustomFiltersTable[id] = false
end

GT:RebuildIDTables()
GT:UpdateIDTable(itemID, key)
GT:RemoveItemData(key, itemID)
GT:InventoryUpdate("Filters Custom " .. itemName .. " option clicked", true)
end,
imageCoords = function()
Expand Down
28 changes: 10 additions & 18 deletions FilterButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ function GT:GenerateFiltersMenu(frame)
for _, itemData in ipairs(categoryData) do
if not (itemData.id == -1) then
GT.db.profile.Filters[itemData.id] = key or nil
GT:UpdateIDTable(itemData.id, key)
GT:RemoveItemData(key, itemData.id)
end
end
end

GT:RebuildIDTables()
GT:InventoryUpdate(expansion .. " clicked", false)
end

Expand All @@ -166,11 +166,11 @@ function GT:GenerateFiltersMenu(frame)
for _, itemData in ipairs(GT.ItemData[expansion][category]) do
if not (itemData.id == -1) then
GT.db.profile.Filters[itemData.id] = key or nil
GT:UpdateIDTable(itemData.id, key)
GT:RemoveItemData(key, itemData.id)
end
end

GT:RebuildIDTables()
GT:InventoryUpdate(expansion .. " " .. category .. " clicked", false)
end

Expand All @@ -189,14 +189,11 @@ function GT:GenerateFiltersMenu(frame)
end
local function SetSelected_Item()
GT.Debug("Item Button Clicked", 2, expansion, category, itemData.name)
if GT.db.profile.Filters[itemData.id] == true then
GT.db.profile.Filters[itemData.id] = nil
else
GT.db.profile.Filters[itemData.id] = true
end
local key = not IsSelected_Item()
GT.db.profile.Filters[itemData.id] = key or nil

GT:RebuildIDTables()
GT:RemoveItemData(IsSelected_Item(), itemData.id)
GT:UpdateIDTable(itemData.id, key)
GT:RemoveItemData(key, itemData.id)
GT:InventoryUpdate(expansion .. " " .. category .. " " .. itemData.name .. " menu clicked", false)
end

Expand Down Expand Up @@ -373,10 +370,10 @@ function GT:CreateCustomFiltersList(frame, rootDescription)
local key = not IsSelected_CustomFilter()
for id, data in pairs(GT.db.profile.CustomFiltersTable) do
GT.db.profile.CustomFiltersTable[tostring(id)] = key
GT:UpdateIDTable(id, key)
GT:RemoveItemData(key, id)
end

GT:RebuildIDTables()
GT:InventoryUpdate("Custom Filters clicked", false)
end

Expand All @@ -388,13 +385,10 @@ function GT:CreateCustomFiltersList(frame, rootDescription)
end
local function SetSelected_CustomFilterItem()
GT.Debug("Custom Filter Item Button Clicked", 2, itemData.text)
if GT.db.profile.CustomFiltersTable[tostring(itemData.id)] == true then
GT.db.profile.CustomFiltersTable[tostring(itemData.id)] = false
else
GT.db.profile.CustomFiltersTable[tostring(itemData.id)] = true
end
local key = not IsSelected_CustomFilterItem()
GT.db.profile.CustomFiltersTable[tostring(itemData.id)] = key

GT:RebuildIDTables()
GT:UpdateIDTable(itemData.id, key)
GT:RemoveItemData(IsSelected_CustomFilterItem(), itemData.id)
GT:InventoryUpdate("Custom Filter " .. itemData.text .. " menu clicked", false)
end
Expand Down Expand Up @@ -434,8 +428,6 @@ function GT:CreateProfilesList(frame, rootDescription)

local function SetSelected_Profile()
GT.Debug("Profile Button Clicked", 2, name)
--this closes the menu when the profile is changed
--ToggleDropDownMenu(1, nil, GT.baseFrame.menu, "cursor", 0, 0, GT.baseFrame.filterMenu, nil)
GT.db:SetProfile(name)
end

Expand Down
136 changes: 50 additions & 86 deletions GatheringTracker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,12 @@ function GT:DestroyDisplay()
end

function GT:RemoveItemData(key, itemID)
GT.Debug("Remove Item Data", 3, key, itemID)
if key then
return
end

GT.Debug("Remove Item Data", 3, key, itemID)

if GT.InventoryData[itemID] then
GT.Debug("Remove Item Data: remove Inventory", 3, key, itemID)
GT.InventoryData[itemID] = nil
Expand Down Expand Up @@ -492,13 +493,11 @@ function GT:PrepareDataForDisplay(event, wait)
GT:SetTSMPriceSource()

if not GT.NotificationPause then
GT.Debug("Trigger Notification Handler for all", 2)
GT.Debug("Trigger Notification Handler for all", 6)
local count, value = GT:CalculatePlayerTotal(true, GT.db.profile.General.sessionOnly)
GT:NotificationHandler("all", "all", count, value)
end

GT:CleanUpInventoryData()

GT:SetupItemRows()

GT:SetupTotalsRow()
Expand All @@ -514,7 +513,7 @@ end
function GT:SetupItemRows()
GT.Debug("SetupItemRows", 1)
for itemID, itemData in pairs(GT.InventoryData) do
GT.Debug("Setup Item Row", 2, itemID)
GT.Debug("Setup Item Row", 6, itemID)
if itemID <= #GT.ItemData.Other.Other then
GT:InitiateFrameProcess(
itemID,
Expand All @@ -531,20 +530,25 @@ function GT:SetupItemRows()
count = GT.InventoryData[itemID].count
end

local pricePerItem = nil
if GT.priceSources then
pricePerItem = GT:GetItemPrice(itemID)
end
local priceTotalItem = count * (pricePerItem or 0)
local itemsPerHour = GT:CalculateItemsPerHour(itemID)
local goldPerHour = itemsPerHour * (pricePerItem or 0)

local iconQuality = nil
if GT.gameVersion == "retail" then
iconQuality = C_TradeSkillUI.GetItemReagentQualityByItemInfo(itemID)
end

if count > 0 or GT.db.profile.General.allFiltered then
local pricePerItem = nil
local itemsPerHour = nil
local goldPerHour = nil
if GT.priceSources then
pricePerItem = GT:GetItemPrice(itemID)
end
local priceTotalItem = count * (pricePerItem or 0)

if GT.db.profile.General.itemsPerHour or GT.db.profile.General.goldPerHour then
itemsPerHour = GT:CalculateItemsPerHour(itemID)
goldPerHour = itemsPerHour * (pricePerItem or 0)
end

local iconQuality = nil
if GT.gameVersion == "retail" then
iconQuality = C_TradeSkillUI.GetItemReagentQualityByItemInfo(itemID)
end

GT:InitiateFrameProcess(
tonumber(itemID),
C_Item.GetItemIconByID(itemID),
Expand Down Expand Up @@ -627,6 +631,8 @@ function GT:SetupTotalsRow()
GT.Debug("SetupTotalsRow", 1)
local playerTotals = {}
local priceTotal = 0
local itemsPerHour = nil
local goldPerHour = nil

local playerTotal, playerPrice = GT:CalculatePlayerTotal(
true,
Expand All @@ -642,7 +648,9 @@ function GT:SetupTotalsRow()
table.insert(playerTotals, playerTotalSession)
end
if playerTotal > 0 or GT.db.profile.General.collapseDisplay then
local itemsPerHour, goldPerHour = GT:CalculateItemsPerHourTotal(playerTotal)
if GT.db.profile.General.itemsPerHour or GT.db.profile.General.goldPerHour then
itemsPerHour, goldPerHour = GT:CalculateItemsPerHourTotal(playerTotal)
end

GT:InitiateFrameProcess(
9999999998,
Expand Down Expand Up @@ -713,17 +721,6 @@ function GT:RefreshPerHourDisplay(stop, wait)
end
end

function GT:CleanUpInventoryData()
GT.Debug("CleanUpInventoryData", 1)
for itemID, itemData in pairs(GT.InventoryData) do
-- Removes Items that have a total count of 0
if itemData.count == 0 and not GT.db.profile.General.allFiltered then
GT.Debug("CleanUpInventoryData", 2, itemID, itemData.count)
GT:RemoveItemData(false, itemID)
end
end
end

function GT:InventoryUpdate(event, wait)
GT.Debug("InventoryUpdate", 1, event, wait)
if wait then
Expand Down Expand Up @@ -756,102 +753,69 @@ end

function GT:ProcessData(event)
GT.Debug("ProcessData", 1, event)
local itemTable = {}

for index, id in ipairs(GT.IDs) do
for index, data in ipairs(GT.IDs) do
local itemCount = 0
if id == GT.ItemData.Other.Other[1].id then
if data.id == GT.ItemData.Other.Other[1].id then
itemCount = math.floor((GetMoney() / 10000) + 0.5)
elseif id == GT.ItemData.Other.Other[2].id then
elseif data.id == GT.ItemData.Other.Other[2].id then
for bagIndex = 0, 4 do
itemCount = itemCount + C_Container.GetContainerNumFreeSlots(bagIndex)
end
else
itemCount = C_Item.GetItemCount(
id,
data.id,
GT.db.profile.General.includeBank,
false,
GT.db.profile.General.includeReagent,
GT.db.profile.General.includeWarband
)
end

if itemCount > 0 or (itemCount == 0 and GT.InventoryData[id]) or GT.db.profile.General.allFiltered then
itemTable[id] = itemCount
end

if event and (event == "InventoryUpdate" or event == "BAG_UPDATE") and itemCount > 0 then
GT.Debug("Trigger Notification Handler for each", 5)
GT.NotificationPause = false
GT:NotificationHandler("each", id, itemCount)
GT:NotificationHandler("each", data.id, itemCount)
end
end

GT:UpdateInventoryData(itemTable)
GT.InventoryData[data.id] = GT.InventoryData[data.id] or GT:ItemDataConstructor(data.id)
GT.InventoryData[data.id].count = itemCount

GT:PrepareDataForDisplay("Process Solo Data")
end
if not GT.IDs[index].processed then
GT.InventoryData[data.id].startAmount = itemCount
GT.IDs[index].processed = true
end

--[[if GT.InventoryData[data.id].startAmount == -1 then
GT.InventoryData[data.id].startAmount = itemCount
end]]

--- Creates a table from a string that is formatted with id=count and space seperated
---@param message string Message string
---@return table itemTable
function GT:CreateItemTable(message)
GT.Debug("CreateItemTable", 3, message)
--create messageText table
local str = " " .. message .. "\n"
str = str:gsub("%s(%S-)=", "\n%1=")
local itemTable = {}
GT.InventoryData[data.id].sessionCount =
GT.InventoryData[data.id].count - GT.InventoryData[data.id].startAmount
end

for itemID, value in string.gmatch(str, "(%S-)=(.-)\n") do
local itemID = tonumber(itemID)
---@diagnostic disable-next-line: need-check-nil
itemTable[itemID] = value
if GT.GlobalStartTime == 0 then
GT.GlobalStartTime = time()
end

return itemTable
GT:PrepareDataForDisplay("Process Data")
end

--- Creates an itemData Construct
---@param itemID integer ID of the item to create
---@return table itemData
function GT:ItemDataConstructor(itemID)
GT.Debug("ItemDataConstructor", 1, itemID)
GT.Debug("ItemDataConstructor", 6, itemID)

local itemData = {}
itemData.count = 0
itemData.startAmount = -1
itemData.startAmount = 0
itemData.sessionCount = 0
itemData.startTime = time()

return itemData
end

--- Updates the Inventory data for a Sender
---@param itemTable table
function GT:UpdateInventoryData(itemTable)
GT.Debug("UpdateInventoryData", 1)
for itemID, value in pairs(itemTable) do
GT.Debug("UpdateInventoryData", 3, itemID, value)
local value = tonumber(value)
if GT:TableFind(GT.IDs, itemID) then
GT.InventoryData[itemID] = GT.InventoryData[itemID] or GT:ItemDataConstructor(itemID)
GT.InventoryData[itemID].count = value
if GT.InventoryData[itemID].startAmount == -1 then
GT.InventoryData[itemID].startAmount = value
end

GT.InventoryData[itemID].sessionCount =
GT.InventoryData[itemID].count - GT.InventoryData[itemID].startAmount
else
itemTable[itemID] = nil
end
end

if GT.GlobalStartTime == 0 then
GT.GlobalStartTime = time()
end
end

---@param calcSenderValue boolean If true calculates value of all filtered items from sender
---@param useSessionData boolean If true only uses session data for calculations
---@return integer total Total count of items for sender
Expand Down
2 changes: 1 addition & 1 deletion GatheringTracker.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: Gathering Tracker
## Notes: Addon for tracking gathered items, supports solo players and groups
## Author: Noshei
## Version: 3.0.1
## Version: 3.0.2
## OptionalDeps: TradeSkillMaster, RECrystallize, Auctionator
## SavedVariables: GatheringTrackerDB
## AddonCompartmentFunc: GatheringTracker_OnAddonCompartmentClick
Expand Down
20 changes: 9 additions & 11 deletions NotificationHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function GT:NotificationHandler(mode, id, amount, value)
end

if passedValue >= threshold then
GT.Debug(notiType .. " Notifications Threshold Exceeded", 2, mode, id, amount, value)
GT.Debug(notiType .. " Notifications Threshold Exceeded", 5, mode, id, amount, value)
if GT.db.profile.Notifications[notiType].interval == 1 then --Interval
if GT.Notifications[id] and GT.Notifications[id][notiType] > 0 then
if (passedValue - GT.Notifications[id][notiType]) >= threshold then
Expand Down Expand Up @@ -143,16 +143,14 @@ function GT:NotificationHandler(mode, id, amount, value)
GT.Debug("Generate Notification Table", 1)
local playerTotal = 0
for itemID, data in pairs(GT.InventoryData) do
if GT:TableFind(GT.IDs, tonumber(itemID)) then
id = tonumber(itemID)
amount = data.count
playerTotal = playerTotal + amount
NotificationCheck("Count", true)
if GT.db.profile.General.tsmPrice > 0 then
local eprice = GT:GetItemPrice(itemID)
value = math.ceil(eprice * amount)
NotificationCheck("Gold", true)
end
id = tonumber(itemID)
amount = data.count
playerTotal = playerTotal + amount
NotificationCheck("Count", true)
if GT.db.profile.General.tsmPrice > 0 then
local eprice = GT:GetItemPrice(itemID)
value = math.ceil(eprice * amount)
NotificationCheck("Gold", true)
end
end
id = "all"
Expand Down
Loading

0 comments on commit 81c0ea1

Please sign in to comment.