Documentation for this module may be created at Module:CircuitPoints/doc
local util_args = require('Module:ArgsUtil')
local util_esports = require('Module:EsportsUtil')
local util_footnote = require('Module:FootnoteUtil')
local util_text = require('Module:TextUtil')
local util_vars = require('Module:VarsUtil')
local Team = require('Module:TeamClass')
local legend = require('Module:Legend')._main
local h = {}
local p = {}
function p.start(frame)
local args = util_args.merge()
h.setStartVariables(args)
local tbl = mw.html.create('table')
:addClass('wikitable circuitpoints')
if args.sortable then tbl:addClass('sortable') end
h.printLegend(tbl, args)
local tr = tbl:tag('tr')
if not args.no_seeds then
tr:tag('th'):wikitext('Seed')
end
if args.path then
util_vars.setBool('path', true)
tr:tag('th'):wikitext('Path')
end
tr:tag('th'):wikitext('Team')
h.printPhaseColumns(tr, args.headings)
if not args.no_totals then
tr:tag('th'):wikitext('Total')
end
--h.printPhaseColumns(tr, args.regionals)
local str = tostring(tbl)
str = str:gsub('</table>$','')
return str
end
function h.castStartArgs(args)
args.show_seeds = not util_args.castAssBool(args.no_seeds)
args.no_totals = util_args.castAsBool(args.no_totals)
args.sortable = util_args.castAsBool(args.sortable)
args.path = util_args.castAsBool(args.path)
end
function h.setStartVariables(args)
util_vars.resetGlobalIndex('cp_place_counter')
util_vars.resetGlobalIndex('cp_place')
util_vars.setVar('standings-outof', args.netplaces)
util_vars.setVar('hasRegionals', args.regionals)
util_vars.setBool('show_totals', not args.no_totals)
util_vars.setBool('show_seeds', not args.no_seeds)
end
function p.line(frame)
local args = util_args.merge()
h.castLineArgs(args)
local tr = mw.html.create('tr')
if args.class then
tr:addClass(util_esports.standingsClasses(args.class))
end
h.addPlace(tr, args)
h.printTeam(tr, args.team, args.footnoteteamn)
local total = h.addPoints(tr, args)
--h.addRegionals(tr, args.regionals)
return tr
end
function h.castLineArgs(args)
args.team = Team(args.team)
end
function p.endtable(frame)
return '</table>'
end
function h.printLegend(tbl, args)
local tr = tbl:tag('tr')
local colspan = (args.headings and #args.headings or 0) + 3
local th = tr:tag('th'):attr('colspan', colspan)
legend(th, args)
end
function h.printPhaseColumns(tr, headings)
for _, v in ipairs(util_text.split(headings)) do
tr:tag('th'):wikitext(v)
end
end
function h.printRegionalsHeader(tr, regionals)
if not regionals then return end
tr:tag('td')
:wikitext(regionals)
:attr('colspan', 2)
end
function h.addPlace(tr, args)
local place_default = util_vars.setGlobalIndex('cp_place_counter')
if util_args.castAsBool(args.sameplaces) then
place_default = util_vars.getGlobalIndex('cp_place')
else
util_vars.resetGlobalIndex('cp_place', place_default)
end
local p = args.p or place_default
local seedIndex = util_vars.getObject('seeds') or {}
if util_vars.getBool('show_seeds') then
tr:tag('td'):addClass(util_esports.standingsClasses(args.pclass)):wikitext(args.seed or seedIndex[p] or p)
end
if util_vars.getBool('path') then
local pathIndex = util_vars.getObject('paths') or {}
tr:tag('td'):addClass(util_esports.standingsClasses(args.pclass)):wikitext(args.path or pathIndex[p])
end
end
function h.printTeam(tr, team, footnote)
local td = tr:tag('td'):addClass('circuitpoints-team'):wikitext(team:flairlink{len='medium'})
if footnote then
util_footnote.tagFootnotePlain(td, footnote)
end
end
function h.addPoints(tr, args)
local total = 0
local points = util_text.split(args.points)
local places = args.places and util_text.split(args.places) or {}
local netplaces = args.netplaces and util_text.split(args.netplaces) or {}
local classes = args.classes and util_text.split(args.classes) or {}
for i, p in ipairs(points) do
local td = tr:tag('td'):wikitext(p)
if classes[i] then
td:addClass(util_esports.standingsClass(classes[i]))
end
local gradient = h.gradient(places[i], netplaces[i])
if gradient then
td:css('background-image', gradient)
end
total = total + (tonumber(p) or 0)
end
if args.total then
total = args.total
end
if util_vars.getBool('show_totals') then
tr:tag('td'):wikitext(total, h.regionalsSeed(args.regionals))
end
end
function h.gradient(str, outof)
local num = tonumber(str or '')
if not num then return nil end
local total = outof and tonumber(outof) or tonumber(util_vars.getVar('standings-outof'))
if not total then
error('Attempted to give places without a total number of places')
end
local css = "linear-gradient(rgba(0,0,0,%s),rgba(0,0,0,%s)"
local percent = (1 - (num / total)) * .3
return css:format(percent, percent)
end
function h.regionalsSeed(regionals)
if true then return nil end
if not regionals then return nil end
local ret = mw.html.create('abbr')
:wikitext(('(#%s)'):format(regionals))
:attr('title', 'Regionals Seed')
return ' ', tostring(ret)
end
-- function h.addRegionals(tr, regionals)
-- if not util_vars.getBool('hasRegionals') then return end
-- for _, n in ipairs(util_text.split(regionals or '')) do
-- tr:tag('td'):wikitext(regionals)
-- end
-- end
return p