Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Provides rarity type data and rendering for use in templates like Template:Rarity.


local Rarity = {}

local rarityColors = {
    common    = 'var(--color-rarity-common)',
    uncommon  = 'var(--color-rarity-uncommon)',
    rare      = 'var(--color-rarity-rare)',
    epic      = 'var(--color-rarity-epic)',
    legendary = 'var(--color-rarity-legendary)'
}

-- Returns the canonical rarity key, or nil if absent or empty.
local function normalize(rarity)
    if not rarity or rarity == '' then return nil end
    return string.lower(rarity)
end

--- Returns a CSS color value for a given rarity.
function Rarity.main(frame)
    local rarity = frame.args.rarity
    local key = normalize(rarity)
    local color = key and rarityColors[key]
    if not color then
        error('Module:Rarity: unknown rarity type "' .. tostring(rarity) .. '"')
    end
    return color
end

return Rarity