Homepage
Games
News
News βΎ
All
Transfers
Drama
Business
Sponsors
Mergers
Investors
Hires
Companies
More
People
Tournaments
Brands
Brands βΎ
Companies
Organizations
Sponsors
Other
Locations
Search
Editing
Module:Match
From TwogPedia
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
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 = args.bestof or VariablesLua.varexists('bestof') and VariablesLua.var('bestof') or 3 local solo = VariablesLua.varexists('solo') args.twitch = args.twitch or (VariablesLua.varexists('twitch') and VariablesLua.var('twitch') ~= '0' ) and VariablesLua.var('twitch') or nil args.youtube = args.youtube or (VariablesLua.varexists('youtube ') and VariablesLua.var('youtube ') ~= '0' ) and VariablesLua.var('youtube ') or nil 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) 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 local p1Team = (not solo and args.p1) and getTeamPage(args.p1) or nil local p2Team = (not solo and args.p2) and getTeamPage(args.p2) or nil args.p1 = args.p1 and ( solo and 'People/' .. args.p1 or p1Team.page ) args.p2 = args.p2 and ( solo and 'People/' .. args.p2 or p2Team.page ) -- Start creation of output html local team1 = html.team(args.p1, p1score, args.date) local team2 = html.team(args.p2, p2score, args.date, true) local container = mw.html.create('div'):addClass('match'):node(team1):node(team2) 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 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 end end -- local hover = mw.html.create('div'):addClass('match-details') local hover = html.teamHover(args.p1, args.p2, p1score, p2score, args.date, args.twitch, args.youtube, casters, observers, winner) local isNotTranscluded = not VariablesLua.varexists('transclude') or VariablesLua.var('transclude') == '0' local stage = (VariablesLua.varexists('stage') and VariablesLua.var('stage') ~= "0") and VariablesLua.var('stage') or nil -- Only enter into db when page is not being transcluded if isNotTranscluded then 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, tiebreak = args.tiebreak and 1, twitch = args.twitch, youtube = args.youtube, api_id = args.api}} end -- Don't add to database if no teams are entered if args.p1 ~= nil and args.p2 ~= nil then local pageTitle = mw.title.getCurrentTitle().text -- Start setting up query for to find which row was added and add 'People/' to casters and observers local date = args.date or '' local whereStr = '_pageName="' .. pageTitle .. '" AND p1="' .. args.p1 .. '" AND p2="' .. args.p2 .. '" AND date="' .. date .. '" AND p1score="' .. p1score .. '" AND p2score="' .. p2score .. '" AND winner="' .. winner .. '" AND bestof="' .. bestof .. '"' if stage then whereStr = whereStr .. ' AND stage="' .. stage.. '"' end local tables = 'AllMatches' local fields = '_ID' if #casters > 0 then for i = 1, #casters do whereStr = whereStr .. ' AND casters HOLDS "' .. casters[i] .. '"' end end if #observers > 0 then for i = 1, #observers do whereStr = whereStr .. ' AND observers HOLDS "' .. observers[i] .. '"' end end 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 #maps > 0 then if string.find(pageTitle, 'Dota2/') then local dota = require('Module:Match/Dota') dota.picksBans(maps, not solo and p1Team.api_id, not solo and p2Team.api_id, hover, results, frame) 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, api_id' local cargoArgs = { where = '_pageName LIKE "' .. gameCategory .. '/%" AND ( shorthand = "' .. team .. '" OR _pageName="' .. gameCategory .. '/' .. team .. '")' } local results = cargo.query(tables, fields, cargoArgs) local returnTable = { page = #results > 0 and results[1]._pageName or gameCategory .. '/' .. team, api_id = #results > 0 and results[1].api_id or nil } return returnTable end return Match
Summary:
Please note that all contributions to TwogPedia may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
TwogPedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Template used on this page:
Module:Match/doc
(
edit
)
No categories
Edit