Module:Rank

local getArgs = require('Module:Arguments').getArgs local loader = require('Module:Loader')

local string, table, yesno = loader.require('String', 'Table', 'Yesno')

local rankData, rankAliases = loader.loadData('Rank/Data', 'Rank/Aliases')

local p = {}

-- Template:Rank function p.serverRank(frame) local args = getArgs(frame) local rankname = args.rankname or args[1] local opts = { size = (args.size or 12)..'px', bracket = yesno(args.brackets or args.bracket or args.br, true), }	return p._serverRank(rankname, opts) end

-- Template:RankName function p.playerName(frame) local args = getArgs(frame) local skyshiiyumoe = yesno(args.skyshiiyumoe, args.ssm) local profile = args.profile or args.prof local rankname = args.rankname or args[1] local rank = yesno(args.rank, true) local playername = args[2] local plus_color = args.plus_color or nil local bracket_color = args.bracket_color or nil skyshiiyumoe = (skyshiiyumoe or profile) and ('https://sky.shiiyu.moe/%s'):format(profile and 'stats/'..playername..'/'..profile or 'stats/'..playername) or nil local opts = { size = (args.size or 12)..'px', bracket = true, append = args.player or args[2], link = skyshiiyumoe, rankless = not rank, pluscolor = plus_color, bracketcolor = bracket_color, }	return p._serverRank(rankname, opts) end

-- Access Point function p._serverRank(name, opts) local function colorize(text, c)		if string.trim(text) ==  then return  end return string.wrapHtml(text, 'span', { class = ('format-%s'):format(c) }) end local function typeHandler(d) if type(d) == 'table' then d = table.deepCopy(d, true) d = #d < 2 and table.concat(d) or d		end return d	end local rank = rankData[rankAliases[string.upper(name)] or string.upper(name)] if not rank then return string._error('No such rank: '..name) end local bracket = (not rank.noncanon) and yesno(opts.bracket, true) local append_ = string.trim(opts.append or '') local rankdisp, colorcode = typeHandler(rank.display), typeHandler(rank.colorcode) local rankless = opts.rankless or (append_ ~= '' and rank.noncanon) local delta = type(colorcode) == 'table' and colorcode[1] or colorcode local gamma = opts.bracketcolor or rank.bracketcolor or delta delta = not bracket and (rank.bracketcolor or delta) or delta if not rankless then if type(colorcode) == 'table' then if type(rankdisp) == 'table' then rankdisp = table.concat(table.map(rankdisp, function(v, i)					return colorize(v, colorcode[i]) end)) else local r, s = string.match(rankdisp, '(%w+)(%++)') if r and s then rankdisp = ('%s%s'):format(colorize(r, opts.bracketcolor or colorcode[1]), colorize(s, opts.pluscolor or colorcode[2])) else rankdisp = colorize(rankdisp, colorcode[1]) end end else if bracket and not rank.bracketcolor then -- special case: wrap bracket early, colorize as a whole rankdisp = colorize(('&#91;%s&#93;'):format(rankdisp), delta) bracket = false -- Done else rankdisp = colorize(('%s'):format(rankdisp), delta) -- If no bracket, done here -- If needs bracket, this part only colorizes the rank part end end -- wrap brackets, colorize separately if bracket then rankdisp = ('%s%s%s'):format(				colorize('&#91;', gamma),				rankdisp,				colorize('&#93;', gamma)				) -- Done end end local text if rankless then text = (''):format(rank.index) else text = ('%s'):format(rank.index, rank.link, rankdisp) end if append_ ~= '' then if opts.link then text = ('%s [%s %s]'):format(text, opts.link, colorize(append_, gamma)) else text = ('%s %s'):format(text, colorize(append_, gamma)) end end local ret = string.wrapHtml(text, 'span', {		class = 'mcui-text',		style = {			display = 'inline',			['flex-wrap'] = 'wrap',			['font-size'] = opts.size,		}	}) return mw.getCurrentFrame:preprocess(ret) end

return p