Module:RarityHandler: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary Tag: Reverted |
||
Line 1: | Line 1: | ||
function p.getSortValue(frame) | function p.getSortValue(frame) | ||
local raw = frame.args[1] | local raw = frame.args[1] | ||
if not raw or type(raw) ~= "string" then return 999999999 end | if not raw or type(raw) ~= "string" then | ||
return 999999999 | |||
end | |||
local rarity = clean(raw) | local rarity = clean(raw) | ||
Line 27: | Line 18: | ||
end | end | ||
local numStr = lowered:match("^1/(%d+%.?%d*)$") | local numStr = lowered:match("^1/(%d+%.?%d*)$") | ||
if numStr then | if numStr then | ||
local | local n = tonumber(numStr) | ||
if | if n then | ||
return tonumber(math.floor(n)) -- <- THIS is the key | |||
end | |||
end | end | ||
return 999999999 | return 999999999 | ||
end | end | ||
Revision as of 13:59, 19 May 2025
Documentation for this module may be created at Module:RarityHandler/doc
function p.getSortValue(frame)
local raw = frame.args[1]
if not raw or type(raw) ~= "string" then
return 999999999
end
local rarity = clean(raw)
if not rarity then return 999999999 end
local lowered = rarity:lower()
if lowered == "1" or lowered == "always" then
return 1
elseif lowered == "rare" then
return 999999998
elseif lowered == "never" then
return 0
end
local numStr = lowered:match("^1/(%d+%.?%d*)$")
if numStr then
local n = tonumber(numStr)
if n then
return tonumber(math.floor(n)) -- <- THIS is the key
end
end
return 999999999
end