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 = require('Module:RarityTier/Data')

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 p._getDataList(key) local orderList = {} for rarity,v in pairs(tiers) do   	orderList[rarity] = v[key] end return orderList 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