From 4e828922619fcd6fff111ec6fc30ef9752f9bb06 Mon Sep 17 00:00:00 2001 From: DBFBlackbull Date: Sat, 2 Aug 2025 16:56:20 +0200 Subject: [PATCH] helpers: add GetItemIDFromLink function --- helpers.lua | 18 ++++++++++++++++-- mods/sell-junk.lua | 5 +++-- mods/vendor-values.lua | 11 ++++++----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/helpers.lua b/helpers.lua index 8fa3521..f71c174 100644 --- a/helpers.lua +++ b/helpers.lua @@ -330,6 +330,20 @@ ShaguTweaks.spairs = function(t) return orderedNext, t, nil end +ShaguTweaks.GetItemIDFromLink = function(itemLink) + if not itemLink then + return + end + + local foundID, _ , itemID = string.find(itemLink, "item:(%d+)") + if not foundID then + return + end + + return tonumber(itemID) +end + + ShaguTweaks.GetItemCount = function(itemName) local count = 0 for bag = 4, 0, -1 do @@ -337,8 +351,8 @@ ShaguTweaks.GetItemCount = function(itemName) local _, itemCount = GetContainerItemInfo(bag, slot) if itemCount then local itemLink = GetContainerItemLink(bag,slot) - local _, _, itemParse = strfind(itemLink, "(%d+):") - local queryName = GetItemInfo(itemParse) + local itemID = ShaguTweaks.GetItemIDFromLink(itemLink) + local queryName = GetItemInfo(itemID) if queryName and queryName ~= "" then if queryName == itemName then count = count + itemCount diff --git a/mods/sell-junk.lua b/mods/sell-junk.lua index 7818ae4..ab26566 100644 --- a/mods/sell-junk.lua +++ b/mods/sell-junk.lua @@ -1,5 +1,6 @@ local _G = ShaguTweaks.GetGlobalEnv() local T = ShaguTweaks.T +local GetItemIDFromLink = ShaguTweaks.GetItemIDFromLink local module = ShaguTweaks:register({ title = T["Sell Junk"], @@ -85,8 +86,8 @@ module.enable = function(self) -- get value local _, icount = GetContainerItemInfo(bag, slot) - local _, _, id = string.find(GetContainerItemLink(bag, slot), "item:(%d+):%d+:%d+:%d+") - local price = ShaguTweaks.SellValueDB[tonumber(id)] or 0 + local itemID = GetItemIDFromLink(GetContainerItemLink(bag, slot)) + local price = ShaguTweaks.SellValueDB[itemID] or 0 if this.price then this.price = this.price + ( price * ( icount or 1 ) ) this.count = this.count + 1 diff --git a/mods/vendor-values.lua b/mods/vendor-values.lua index 700e39a..4af0f51 100644 --- a/mods/vendor-values.lua +++ b/mods/vendor-values.lua @@ -2,6 +2,7 @@ local _G = ShaguTweaks.GetGlobalEnv() local T = ShaguTweaks.T local GetExpansion = ShaguTweaks.GetExpansion local GetItemLinkByName = ShaguTweaks.GetItemLinkByName +local GetItemIDFromLink = ShaguTweaks.GetItemIDFromLink local module = ShaguTweaks:register({ title = T["Vendor Values"], @@ -3887,18 +3888,18 @@ module.enable = function(self) tooltip:SetScript("OnShow", function() if GameTooltip.itemLink and (GameTooltip.ignoreMerchant or not MerchantFrame:IsShown()) then - local _, _, id = string.find(GameTooltip.itemLink, "item:(%d+):%d+:%d+:%d+") + local itemID = GetItemIDFromLink(GameTooltip.itemLink) local count = tonumber(GameTooltip.itemCount) or 1 - AddVendorPrices(GameTooltip, tonumber(id), math.max(count, 1)) + AddVendorPrices(GameTooltip, itemID, math.max(count, 1)) end end) local HookSetItemRef = SetItemRef SetItemRef = function(link, text, button) - local item, _, id = string.find(link, "item:(%d+):.*") + local itemID = GetItemIDFromLink(GameTooltip.itemLink) HookSetItemRef(link, text, button) - if not IsAltKeyDown() and not IsShiftKeyDown() and not IsControlKeyDown() and item then - AddVendorPrices(ItemRefTooltip, tonumber(id), 1) + if not IsAltKeyDown() and not IsShiftKeyDown() and not IsControlKeyDown() and itemID then + AddVendorPrices(ItemRefTooltip, itemID, 1) end end