Module:RarityHandler: Difference between revisions

No edit summary
No edit summary
Line 12: Line 12:


function p.getSortValue(frame)
function p.getSortValue(frame)
     local rarity = clean(frame.args[1])
     local raw = frame.args[1]
     if not rarity then return 999999999 end
     if not raw or type(raw) ~= "string" then return 999999999 end


     local lowered = string.lower(rarity)
    local trimmed = mw.text.trim(raw)
    if trimmed:sub(1, 1) == "~" then
        trimmed = trimmed:sub(2)
    end
 
     local lowered = string.lower(trimmed)


     if lowered == "1" or lowered == "always" then
     if lowered == "1" or lowered == "always" then
Line 25: Line 30:
     end
     end


    -- Match "1/number" including decimals
     local chance = lowered:match("^1/(%d+%.?%d*)$")
     local chance = lowered:match("^1/(%d+%.?%d*)$")
     if chance then
     if chance then
Line 31: Line 35:
     end
     end


    -- fallback
     return 999999999
     return 999999999
end
end