Module:RarityTier

-- local getArgs = require('Module:Arguments').getArgs local yesno = require('Module:Yesno') local onmain = require('Module:Mainonly').on_main

local p = {}

local aliases = require('Module:RarityTier/Aliases')

local tiers = { common = { name="Common", color="#ffffff", order=1 }, uncommon = { name="Uncommon", color="#55ff55", order=2 }, rare = { name="Rare", color="#5555ff", order=3 }, epic = { name="Epic", color="#aa00aa", order=4 }, legendary = { name="Legendary", color="#ffaa00", order=5 }, mythic = { name="Mythic", color="#ff55ff", order=6 }, supreme = { name="Supreme", color="#AA0000", order=7 }, special = { name="Special", color="#FF5555", order=8 }, very_special = { name="Very Special", color="#FF5555", order=9 }, }

function p._getTier(tierid) tierid = tierid or error('bad argument #1 to \'_getTier\' (string expected, got no value)', 3) tierid = tierid:lower:gsub(" ", "_") tierid = aliases[tierid] or tierid tier = tiers[tierid] if not tier then return "Unknown rarity tier '"..tierid.."' " end return tier end

function hideAlways(data) text = '' for i=1,data do       text = text..'​' end return ' '..text..' ' end

function p.link(frame) local args = getArgs(frame) return p._link(args[1], args[2], args["addcategory"], args["nolink"]) end

function p._link(tierid, linkText, addcategory, nolink) addcategory = yesno(addcategory, false) local tier = p._getTier(tierid) local name = tier.name if tier.name then return table.concat({       hideAlways(tier.order or 0),        (nolink and "" or ""),            " ",        (nolink and "" or ""),        -- Add category        (addcategory and onmain) and "" or "",    },"") else return tierid end end

-- Colors `text` based on the color of the rarity tierid specific function p._colorText(tierid, text, withFormat, link, nolink) withFormat = withFormat~=false -- default to true if nil local tier = p._getTier(tierid) return table.concat({       (link and "" or ""),            (withFormat and " " or ""),        (link and "" or ""),    },"") end

-- returns the value from a lua table based on the rarity passed in -- aliases are accounted for (ex: tierid="c" will trigger the "common" key in the table) -- ex: _switch("rare", { common="a", uncommon="b", rare="c" }) would return "c" function p._switch(tierid, cases) tierid = string.lower(tierid) tierid = aliases[tierid] or tierid return cases[tierid] or cases["default"] or nil end

return p