Rename IsStatsMatch for reusability

This commit is contained in:
higurush
2021-06-04 02:48:20 +02:00
parent 7d6f5b0b4a
commit 80d18456b4
+13 -11
View File
@@ -206,15 +206,15 @@ function AtlasLoot:Search(Text)
end end
return nil; return nil;
end end
local function IsStatsMatch(operator, statValue, searchedStat) local function CompareNumbersByOperator (operator, baseValue, valueToCompare)
if searchedStat ~= nil and statValue ~= nil if baseValue ~= nil and valueToCompare ~= nil
and ((operator == "<>") and (statValue ~= searchedStat) and ((operator == "<>") and (baseValue ~= valueToCompare)
or (operator == "<=") and (statValue <= searchedStat) or (operator == "<=") and (baseValue <= valueToCompare)
or (operator == ">=") and (statValue >= searchedStat) or (operator == ">=") and (baseValue >= valueToCompare)
or (operator == "=") and (statValue == searchedStat) or (operator == "=") and (baseValue == valueToCompare)
or (operator == "<") and (statValue < searchedStat) or (operator == "<") and (baseValue < valueToCompare)
or (operator == ">") and (statValue > searchedStat)) or (operator == ">") and (baseValue > valueToCompare))
then then
return true; return true;
end end
@@ -227,7 +227,7 @@ function AtlasLoot:Search(Text)
if statFilterFound then if statFilterFound then
local statValue = tonumber(stats[statFilterFound]); local statValue = tonumber(stats[statFilterFound]);
local searchedStat = tonumber(string.match(searchTextItem, "%d+")); local searchedStat = tonumber(string.match(searchTextItem, "%d+"));
if IsStatsMatch(operator, statValue, searchedStat) then if CompareNumbersByOperator(operator, statValue, searchedStat) then
return true; return true;
end end
end end
@@ -246,8 +246,10 @@ function AtlasLoot:Search(Text)
local operator = HaveOperator(text); local operator = HaveOperator(text);
if operator ~= nil then if operator ~= nil then
local itemId = tostring(v[2]);
-- Stat Filter -- Stat Filter
local stats = GetItemStats("item:"..tostring(v[2])); local stats = GetItemStats("item:"..itemId);
if stats then if stats then
-- Currently only supports "&" -- Currently only supports "&"
local binaryOperator = HaveBinaryOperator(text); local binaryOperator = HaveBinaryOperator(text);