From 8bfbbb0415d7c621d5aff06a8d706a26f44518ad Mon Sep 17 00:00:00 2001 From: Kevin Lyles Date: Sun, 16 Jan 2011 07:39:35 -0600 Subject: [PATCH] Removed one layer of nesting --- WeightsWatcher.lua | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/WeightsWatcher.lua b/WeightsWatcher.lua index 36115ef..a3408ca 100644 --- a/WeightsWatcher.lua +++ b/WeightsWatcher.lua @@ -772,31 +772,29 @@ function WeightsWatcher.bestGemsForWeight(weightScale) for gemType, gems in pairs(gems) do if ww_vars.options.gems.types[gemType] then for quality = qualityLimit, 1, -1 do - if gems[quality] then - for gemId, gemStats in pairs(gems[quality]) do - weight = WeightsWatcher.calculateWeight({normalStats = {}}, {gemStats = {{gemStats}}}, weightScale) - for socketColor in pairs(ww_localizedSocketColors) do - if WeightsWatcher.matchesSocket(gemStats[1], socketColor) then - for i = #(ww_gemMinIlvls), 1, -1 do - local ilvl = ww_gemMinIlvls[i] - if ilvl < WeightsWatcher.GemInfo(gemId).minIlvl then - break - end - if weight > bestGems[ilvl][socketColor .. "Score"] then - bestGems[ilvl][socketColor] = {gemId} - bestGems[ilvl][socketColor .. "Score"] = weight - elseif weight == bestGems[ilvl][socketColor .. "Score"] then - local duplicate = false - for _, gem in pairs(bestGems[ilvl][socketColor]) do - if WeightsWatcher.GemInfo(gem).info[2] == gemStats[2] then - duplicate = true - break - end - end - if not duplicate then - table.insert(bestGems[ilvl][socketColor], gemId) + for gemId, gemStats in pairs(gems[quality] or {}) do + weight = WeightsWatcher.calculateWeight({normalStats = {}}, {gemStats = {{gemStats}}}, weightScale) + for socketColor in pairs(ww_localizedSocketColors) do + if WeightsWatcher.matchesSocket(gemStats[1], socketColor) then + for i = #(ww_gemMinIlvls), 1, -1 do + local ilvl = ww_gemMinIlvls[i] + if ilvl < WeightsWatcher.GemInfo(gemId).minIlvl then + break + end + if weight > bestGems[ilvl][socketColor .. "Score"] then + bestGems[ilvl][socketColor] = {gemId} + bestGems[ilvl][socketColor .. "Score"] = weight + elseif weight == bestGems[ilvl][socketColor .. "Score"] then + local duplicate = false + for _, gem in pairs(bestGems[ilvl][socketColor]) do + if WeightsWatcher.GemInfo(gem).info[2] == gemStats[2] then + duplicate = true + break end end + if not duplicate then + table.insert(bestGems[ilvl][socketColor], gemId) + end end end end -- 1.7.9.5