Documentation for this module may be created at Module:Match/Dota/doc
local getArgs = require('Module:Arguments').getArgs
local cargo = mw.ext.cargo
local html = require('Module:MatchHTML')
local DotaMatch = {}
local VariablesLua = mw.ext.VariablesLua
function DotaMatch.main(frame)
local args = getArgs(frame)
local bestof = args.bestof or 3
local maps = {}
p1score = args.p1score or 0
p2score = args.p2score or 0
for i = 1, bestof do
if args['map' .. i] ~= nil then
local map = mw.text.jsonDecode(args['map' .. i])
-- If no score is manually set in template, then add to score
if args.p1score == nil and args.p2score == nil then _G['p' .. map.winner .. 'score'] = _G['p' .. map.winner .. 'score'] + 1 end
maps[i] = map
end
end
local winner = #maps >= math.ceil(args.bestof / 2) and p1score > p2score and 1 or 2 or 0
-- Start creation of output html
local team1 = html.team(args.p1, p1score)
local team2 = html.team(args.p2, p2score, true)
-- local team1 = mw.html.create('div'):addClass('team')
-- :node(mw.html.create('div'):wikitext(mw.ext.displaytitle.get(p1)):addClass('teamName'))
-- :node(mw.html.create('div'):wikitext(p1score):addClass('score'))
-- local team2 = mw.html.create('div'):addClass('team'):addClass(VariablesLua.var( 'matchList', 0 ) == '1' and ' reverse' or '')
-- :node(mw.html.create('div'):wikitext(mw.ext.displaytitle.get(p2)):addClass('teamName'))
-- :node(mw.html.create('div'):wikitext(p2score):addClass('score'))
local container = mw.html.create('div'):addClass('match'):node(team1):node(team2)
-- local hover = mw.html.create('div'):addClass('match-details')
local hover = html.teamHover(args.p1, args.p2, p1score, p2score, args.date)
-- Don't add to database if no teams are entered
if args.p1 ~= nil and args.p2 ~= nil then
-- Create hover div content
-- local header = mw.html.create('div'):addClass('details-header')
-- local hover1 = mw.html.create('div'):addClass('team')
-- :node(mw.html.create('div'):wikitext('[[' .. args.p1 .. ']]'):addClass('teamName'))
-- :node(mw.html.create('div'):wikitext(p1score):addClass('score'))
-- local hover2 = mw.html.create('div'):addClass('team reverse')
-- :node(mw.html.create('div'):wikitext('[[' .. args.p2 .. ']]'):addClass('teamName'))
-- :node(mw.html.create('div'):wikitext(p2score):addClass('score'))
-- local date = mw.html.create('div'):addClass('tc'):wikitext(args.date)
-- hover:node(header:node(hover1):node(hover2)):node(date)
frame:callParserFunction{name = '#cargo_store:', args = {_table = 'DotaMatches', p1 = args.p1, p2 = args.p2, p1score = p1score, p2score = p2score, date = args.date, winner = winner, bestof= args.bestof, casters = args.casters, twitch = args.twitch, youtube = args.youtube}}
local tables = 'DotaMatches'
local fields = '_ID'
local cargoArgs = {
where = '_pageName="' .. mw.title.getCurrentTitle().text .. '"'
}
local results = cargo.query(tables, fields, cargoArgs)
if #results > 0 and #maps > 0 then
for i = 1, #maps do
local map = maps[i]
frame:callParserFunction{name = '#cargo_store:', args = {_table = 'DotaMaps', map=i, matchID = results[1]._ID, duration = map.duration, p1picks = map.p1picks, p2picks = map.p2picks, p1bans = map.p1bans, p2bans = map.p2bans, dire = map.dire, winner = map.winner, dotaID = map.dotaid, vod = map.vod}}
-- frame:callParserFunction{name = '#cargo_store:', args = {_table = 'DotaMaps', map=i, matchID = results[1]._ID, duration = map.duration, p1picks = map.p1picks, p2picks = map.p2picks, p1bans = map.p1bans, p2bans = map.p2bans, dire = map.dire, winner = map.winner, dotaID = map.dotaid, vod = map.vod}}
-- add picks/bans to hover
hover:node(mw.html.create('div'):wikitext('Map ' .. i .. ' picks'))
local picks = mw.html.create('div'):addClass('details-game')
local p1picks = mw.html.create('div'):addClass('details-picks')
local p2picks = mw.html.create('div'):addClass('details-picks')
-- Loop through first teams picks
if map.p1picks then
local p1picksSplit = mw.text.split(map.p1picks, ',')
for j = 1, #p1picksSplit do
local hero = mw.text.trim(p1picksSplit[j])
--p1picks:wikitext('[[File:' .. w .. '-icon.png|20px]]')
p1picks:node(mw.html.create('div'):wikitext(hero:sub(1, 1)))
end
end
-- create the duration/winner part
local duration = mw.html.create('div'):addClass('details-duration')
:node(mw.html.create('div'):wikitext(map.winner == '1' and 'W' or ''))
:node(mw.html.create('div'):wikitext(map.duration))
:node(mw.html.create('div'):wikitext(map.winner == '2' and 'W' or ''))
-- Loop through second teams picks
if map.p2picks then
local p2picksSplit = mw.text.split(map.p2picks, ',')
for j = 1, #p2picksSplit do
local hero = mw.text.trim(p2picksSplit[j])
--p1picks:wikitext('[[File:' .. w .. '-icon.png|20px]]')
p2picks:node(mw.html.create('div'):wikitext(hero:sub(1, 1)))
end
end
hover:node(picks:node(p1picks):node(duration):node(p2picks))
hover:node(mw.html.create('div'):wikitext('Map ' .. i .. ' bans'))
local bans = mw.html.create('div'):addClass('details-game')
local p1bans = mw.html.create('div'):addClass('details-picks')
local p2bans = mw.html.create('div'):addClass('details-picks')
-- Loop through first teams bans
if map.p1bans then
local p1bansSplit = mw.text.split(map.p1bans, ',')
for j = 1, #p1bansSplit do
local hero = mw.text.trim(p1bansSplit[j])
--p1picks:wikitext('[[File:' .. w .. '-icon.png|20px]]')
p1bans:node(mw.html.create('div'):wikitext(hero:sub(1, 1)))
end
end
-- Loop through second teams bans
if map.p2bans then
local p2bansSplit = mw.text.split(map.p2bans, ',')
for j = 1, #p2bansSplit do
local hero = mw.text.trim(p2bansSplit[j])
--p1picks:wikitext('[[File:' .. w .. '-icon.png|20px]]')
p2bans:node(mw.html.create('div'):wikitext(hero:sub(1, 1)))
end
end
hover:node(bans:node(p1bans):node(p2bans))
-- VODs etc
hover:node(mw.html.create('div'):wikitext('VOD links etc'))
end
end
end
container:node(hover)
-- local tables = 'DotaMatches, DotaMaps'
-- local fields = 'map, duration, p1picks, p2picks, p1bans, p2bans, dire, DotaMaps.winner, dotaID, vod'
-- local cargoArgs = {
-- join = 'DotaMaps.matchID=DotaMatches._ID'
-- }
-- local results = cargo.query(tables, fields, cargoArgs)
-- reset value
return container
end
return DotaMatch