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') local hexColors = require("Module:Color/Data").hexColors

function p._getTier(tierid) if not tierid then return '' end tierid = tierid:lower:gsub(" ", "_") tierid = aliases[tierid] or tierid tier = tiers[tierid] or tierid if not tier then return "Unknown rarity tier '"..tierid.."' " end return tier end

function p.getHexColor(r) -- gets hex color of a rarity return hexColors[p._getTier(r).color] 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 not tierid then return '' end 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 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