Module:EsportsUtil

local util_math = require('Module:MathUtil') local util_text = require('Module:TextUtil') local util_title = require('Module:TitleUtil') local util_vars = require('Module:VarsUtil')

local defaultsep = '%s*,%s*'

local p = {}

function p.getOverviewPage(str, frame) if str then return util_title.target(str) else local var = util_vars.getVar('overviewpage', frame) return var or mw.title.getCurrentTitle.text end end

function p.otherTeamN(n) local num = tonumber(n) return 3 - num end

function p.makeLinks(links, display) if not links then links = display end local tbl = {} for k, v in ipairs(display) do		if not links[k] or links[k] == '' then tbl[k] = ('%s'):format(v) else tbl[k] = ('%s'):format(links[k], v)		end end return tbl end

function p.concatLinks(links, display, sep) if not links then links = display end return table.concat(p.makeLinks(links, display), sep or ',') end

function p.concatLinksFromStrings(links, display, sep1, sep2) if not links and not display then return nil end if not links then links = display end local links_tbl = util_text.split(links, sep1 or defaultsep) local display_tbl = util_text.split(display, sep1 or defaultsep) return p.concatLinks(links_tbl, display_tbl, sep2 or ', ') end

function p.ucfirstLink(link, display) if not link and not display then return nil end local lang = mw.getLanguage('en') link = link or display return lang:ucfirst(link) end

function p.ucfirstLinks(links, displays, sep) if not links and not displays then return nil end local lang = mw.getLanguage('en') links = links or displays sep = sep or defaultsep local tbl = util_text.split(links, sep) for k, v in ipairs(tbl) do		tbl[k] = lang:ucfirst(v) end return table.concat(tbl, ',') end

function p.winrate(w, l, round) if w + l == 0 then return 0 end if round then return util_math.roundnum(w / (w + l) * 100, round) else return 100 * w / (w + l)	end end

function p.winrateRanked(w, l, round) return (w - l) + (w + l) * .01 end

function p.addTeamHighlighter(tbl, team) tbl:addClass('teamhighlight') :addClass('teamhighlighter') :attr('data-teamhighlight',team) end

function p.KDA(k, d, a)	return ('%s/%s/%s'):format(k, d, a) end

function p.roundedGold(gold) if not gold then return nil end gold = tonumber(gold) local output = util_math.roundnum(gold / 1000, .1) return ('%sk'):format(output) end

return p