mNo edit summary |
mNo edit summary |
||
Line 10: | Line 10: | ||
local bestof = VariablesLua.varexists('bestof') and VariablesLua.var('bestof') or args.bestof or 3 | local bestof = VariablesLua.varexists('bestof') and VariablesLua.var('bestof') or args.bestof or 3 | ||
local maps = {} | local maps = {} | ||
Line 28: | Line 27: | ||
local neededScore = math.ceil(bestof / 2) | local neededScore = math.ceil(bestof / 2) | ||
local winner = (p1score < neededScore and p2score < neededScore ) and 0 or #maps >= neededScore and p1score > p2score and 1 or 2 or 0 | -- If a draw is possible | ||
local winner = ( bestof % 2 == 0 and p1score + p2score >= neededScore and p1score == p2score) and 3 or (p1score < neededScore and p2score < neededScore ) and 0 or #maps >= neededScore and p1score > p2score and 1 or 2 or 0 | |||
args.p1 = args.p1 and ( | |||
args.p2 = args.p2 and ( | args.p1 = args.p1 and getTeamPage(args.p1) | ||
args.p2 = args.p2 and getTeamPage(args.p2) | |||
-- Start creation of output html | -- Start creation of output html | ||
local team1 = html.team(args.p1, p1score) | local team1 = html.team(args.p1, p1score) | ||
Line 44: | Line 44: | ||
-- Don't add to database if no teams are entered | -- Don't add to database if no teams are entered | ||
if args.p1 ~= nil and args.p2 ~= nil then | if args.p1 ~= nil and args.p2 ~= nil then | ||
local stage = VariablesLua.varexists('stage') and VariablesLua.var('stage') or nil | |||
local pageTitle = mw.title.getCurrentTitle().text | local pageTitle = mw.title.getCurrentTitle().text | ||
-- Start setting up query for to find which row was added and add 'People/' to casters and observers | -- Start setting up query for to find which row was added and add 'People/' to casters and observers | ||
if stage then whereStr = whereStr .. ' AND stage="' .. stage .. '"' end | |||
local casters = {} | local casters = {} | ||
Line 68: | Line 67: | ||
end | end | ||
end | end | ||
local whereStr = '_pageName="' .. pageTitle .. '" AND p1="' .. args.p1 .. '" AND p2="' .. args.p2 .. '" AND date="' .. args.date .. '" AND p1score="' .. p1score .. '" AND p2score="' .. p2score .. '" AND winner="' .. winner .. '" AND bestof="' .. bestof .. '"' | |||
frame:callParserFunction{name = '#cargo_store:', args = {_table = 'AllMatches', p1 = args.p1, p2 = args.p2, p1score = p1score, p2score = p2score, date = args.date, winner = winner, bestof= bestof, stage = stage, casters = #casters > 0 and table.concat(casters, ",") or nil, observers = #observers > 0 and table.concat(observers, ",") or nil | frame:callParserFunction{name = '#cargo_store:', args = {_table = 'AllMatches', p1 = args.p1, p2 = args.p2, p1score = p1score, p2score = p2score, date = args.date, winner = winner, bestof= bestof, stage = stage, casters = #casters > 0 and table.concat(casters, ",") or nil, observers = #observers > 0 and table.concat(observers, ",") or nil, twitch = args.twitch, youtube = args.youtube}} | ||
local tables = 'AllMatches' | local tables = 'AllMatches' | ||
local fields = '_ID' | local fields = '_ID' | ||
Line 81: | Line 82: | ||
local results = cargo.query(tables, fields, cargoArgs) | local results = cargo.query(tables, fields, cargoArgs) | ||
if #results > 0 and #maps > 0 then | if #results > 0 and #maps > 0 then | ||
for i = 1, #maps do | for i = 1, #maps do | ||
Line 87: | Line 88: | ||
if string.find(pageTitle, 'Dota2/') then | if string.find(pageTitle, 'Dota2/') then | ||
local dota = require('Module:Match/Dota') | local dota = require('Module:Match/Dota') | ||
dota.picksBans(map | dota.picksBans(map) | ||
frame:callParserFunction{name = '#cargo_store:', args = {_table = 'Maps_Dota', map=i, api_id = map.id, matchID = results[1]._ID, duration = map.duration, p1picks = map.p1picks, p2picks = map.p2picks, p1bans = map.p1bans, p2bans = map.p2bans, dire = map.dire | frame:callParserFunction{name = '#cargo_store:', args = {_table = 'Maps_Dota', map=i, api_id = map.id, 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, vod = map.vod}} | ||
dota.main(map, hover, i, results) | dota.main(map, hover, i, results) | ||
Line 106: | Line 107: | ||
-- Check if shorthand of a team was used | -- Check if shorthand of a team was used | ||
local tables = 'Teams' | local tables = 'Teams' | ||
local fields = '_pageName, shorthand | local fields = '_pageName, shorthand' | ||
local cargoArgs = { | local cargoArgs = { | ||
where = '_pageName LIKE "' .. gameCategory .. '/%" AND | where = '_pageName LIKE "' .. gameCategory .. '/%" AND shorthand = "' .. team .. '"' | ||
} | } | ||
local results = cargo.query(tables, fields, cargoArgs) | local results = cargo.query(tables, fields, cargoArgs) | ||
if #results > 0 then return results[1]._pageName else return gameCategory .. '/' .. team end | |||
end | end | ||
return Match | return Match |
Revision as of 07:51, 14 October 2023
Documentation for this module may be created at Module:Match/doc
local getArgs = require('Module:Arguments').getArgs
local cargo = mw.ext.cargo
local html = require('Module:MatchHTML')
local Match = {}
local VariablesLua = mw.ext.VariablesLua
function Match.main(frame)
local args = getArgs(frame)
local bestof = VariablesLua.varexists('bestof') and VariablesLua.var('bestof') or 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 map.winner and 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 neededScore = math.ceil(bestof / 2)
-- If a draw is possible
local winner = ( bestof % 2 == 0 and p1score + p2score >= neededScore and p1score == p2score) and 3 or (p1score < neededScore and p2score < neededScore ) and 0 or #maps >= neededScore and p1score > p2score and 1 or 2 or 0
args.p1 = args.p1 and getTeamPage(args.p1)
args.p2 = args.p2 and getTeamPage(args.p2)
-- Start creation of output html
local team1 = html.team(args.p1, p1score)
local team2 = html.team(args.p2, p2score, true)
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
local stage = VariablesLua.varexists('stage') and VariablesLua.var('stage') or nil
local pageTitle = mw.title.getCurrentTitle().text
-- Start setting up query for to find which row was added and add 'People/' to casters and observers
if stage then whereStr = whereStr .. ' AND stage="' .. stage .. '"' end
local casters = {}
if args.casters then
casters = mw.text.split(args.casters, ',')
for i = 1, #casters do
local caster = 'People/' .. mw.text.trim(casters[i])
casters[i] = caster
whereStr = whereStr .. ' AND casters HOLDS "' .. caster .. '"'
end
end
observers = {}
if args.observers then
observers = mw.text.split(args.observers, ',')
for i = 1, #observers do
local observer = 'People/' .. mw.text.trim(observers[i])
observers[i] = observer
whereStr = whereStr .. ' AND observers HOLDS "' .. observer .. '"'
end
end
local whereStr = '_pageName="' .. pageTitle .. '" AND p1="' .. args.p1 .. '" AND p2="' .. args.p2 .. '" AND date="' .. args.date .. '" AND p1score="' .. p1score .. '" AND p2score="' .. p2score .. '" AND winner="' .. winner .. '" AND bestof="' .. bestof .. '"'
frame:callParserFunction{name = '#cargo_store:', args = {_table = 'AllMatches', p1 = args.p1, p2 = args.p2, p1score = p1score, p2score = p2score, date = args.date, winner = winner, bestof= bestof, stage = stage, casters = #casters > 0 and table.concat(casters, ",") or nil, observers = #observers > 0 and table.concat(observers, ",") or nil, twitch = args.twitch, youtube = args.youtube}}
local tables = 'AllMatches'
local fields = '_ID'
if args.twitch then whereStr = whereStr .. ' AND twitch="' .. args.twitch .. '"' end
if args.youtube then whereStr = whereStr .. ' AND youtube="' .. args.youtube .. '"' end
local cargoArgs = {
where = whereStr
}
local results = cargo.query(tables, fields, cargoArgs)
if #results > 0 and #maps > 0 then
for i = 1, #maps do
local map = maps[i]
if string.find(pageTitle, 'Dota2/') then
local dota = require('Module:Match/Dota')
dota.picksBans(map)
frame:callParserFunction{name = '#cargo_store:', args = {_table = 'Maps_Dota', map=i, api_id = map.id, 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, vod = map.vod}}
dota.main(map, hover, i, results)
end
end
end
end
container:node(hover)
return container
end
function getTeamPage(team)
local currentTitle = mw.title.getCurrentTitle().text
local gameCategory = mw.text.split(currentTitle, '/')[1]
-- Check if shorthand of a team was used
local tables = 'Teams'
local fields = '_pageName, shorthand'
local cargoArgs = {
where = '_pageName LIKE "' .. gameCategory .. '/%" AND shorthand = "' .. team .. '"'
}
local results = cargo.query(tables, fields, cargoArgs)
if #results > 0 then return results[1]._pageName else return gameCategory .. '/' .. team end
end
return Match