Module:RaritySort: Difference between revisions

From HighSpell Wiki
Jump to navigation Jump to search
Created page with "local p = {} function p.getSortValue(rarity) if not rarity then return 99 end rarity = rarity:lower() if rarity == "always" then return 1 elseif rarity:match("^1/%d+") then return 2 elseif rarity == "rare" then return 3 elseif rarity == "never" then return 4 else return 99 -- Unknown or fallback end end return p"
 
No edit summary
Line 2: Line 2:


function p.getSortValue(rarity)
function p.getSortValue(rarity)
     if not rarity then return 99 end
     if type(rarity) ~= "string" then
        return 99 -- Default fallback for nil or non-string
    end


     rarity = rarity:lower()
     local r = rarity:lower()


     if rarity == "always" then
     if r == "always" then
         return 1
         return 1
     elseif rarity:match("^1/%d+") then
     elseif r:match("^1/%d+") then
         return 2
         return 2
     elseif rarity == "rare" then
     elseif r == "rare" then
         return 3
         return 3
     elseif rarity == "never" then
     elseif r == "never" then
         return 4
         return 4
     else
     else

Revision as of 17:09, 15 May 2025

Documentation for this module may be created at Module:RaritySort/doc

local p = {}

function p.getSortValue(rarity)
    if type(rarity) ~= "string" then
        return 99 -- Default fallback for nil or non-string
    end

    local r = rarity:lower()

    if r == "always" then
        return 1
    elseif r:match("^1/%d+") then
        return 2
    elseif r == "rare" then
        return 3
    elseif r == "never" then
        return 4
    else
        return 99 -- Unknown or fallback
    end
end

return p