From b892eb1435e8a9ba1cedc40e457b7328ad65cc92 Mon Sep 17 00:00:00 2001 From: Kevin Lyles Date: Wed, 16 Dec 2009 04:16:20 -0600 Subject: [PATCH] factored out the format string code --- WeightsWatcher.lua | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/WeightsWatcher.lua b/WeightsWatcher.lua index c46fd08..fa3304b 100644 --- a/WeightsWatcher.lua +++ b/WeightsWatcher.lua @@ -289,6 +289,20 @@ function splitItemLink(link) return bareLink, {gemId1, gemId2, gemId3, gemId4} end +local function colorizeDifferences(difference) + if difference then + if difference < 0 then + return "%.3f (|cffff0000%+.3f|r)" + elseif difference > 0 then + return "%.3f (|cff00ff00%+.3f|r)" + else + return "%.3f (%+.3f)" + end + else + return "%.3f" + end +end + function WeightsWatcher:displayItemStats(tooltip, ttname) local link, bareLink, itemType, stackSize, sockets, gemStats local stat, value, str, formatStr @@ -336,17 +350,8 @@ function WeightsWatcher:displayItemStats(tooltip, ttname) end end compareScore = currentScore - compareScore - if compareScore < 0 then - formatStr = "%.3f (|cffff0000%+.3f|r)" - elseif compareScore > 0 then - formatStr = "%.3f (|cff00ff00%+.3f|r)" - else - formatStr = "%.3f (%+.3f)" - end - tooltip:AddDoubleLine(str, string.format(formatStr, currentScore, compareScore)) - else - tooltip:AddDoubleLine(str, string.format("%.3f", currentScore)) end + tooltip:AddDoubleLine(str, string.format(colorizeDifferences(compareScore), currentScore, compareScore)) end end end @@ -376,17 +381,8 @@ function WeightsWatcher:displayItemStats(tooltip, ttname) end end compareScore = currentScore - compareScore - if compareScore < 0 then - formatStr = "%.3f (|cffff0000%+.3f|r)" - elseif compareScore > 0 then - formatStr = "%.3f (|cff00ff00%+.3f|r)" - else - formatStr = "%.3f (%+.3f)" - end - tooltip:AddDoubleLine(str, string.format(formatStr, currentScore, compareScore)) - else - tooltip:AddDoubleLine(str, string.format("%.3f", currentScore)) end + tooltip:AddDoubleLine(str, string.format(colorizeDifferences(compareScore), currentScore, compareScore)) if keyDetectors[ww_vars.options.tooltip.showIdealGems]() then gemStats = ww_weightIdealCache[class][weight][bareLink].gemStats for _, gem in ipairs(gemStats) do -- 1.7.9.5