Modulo:TeamBracket: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
fix
Moroboshi (discussione | contributi)
Nessun oggetto della modifica
Riga 19:
path1 = "border:0 solid black;border-right-width:2px",
path2 = "border:0 solid black",
path3 = "border:0 solid black;border-bottom-width:2px",
group = "text-align:center",
winner = {'font-weight' , 'bold'},
first_place = {'background-color', 'gold'},
second_place = {'background-color', 'silver'},
third_place = {'background-color', 'bronze#C96'},
row_height = "3px",
buffer_sx_width = "5px",
Line 70 ⟶ 71:
self.argname_pattern = 'RD%d-%s' .. padding
self.scorename_pattern = 'RD%d-score' .. padding
local autobold_par = self.args['bold_winner'] or ''
self.scores = {}
self.bold_winner = not in_array(self.args[autobold_par], no_replies)
self.low_winner = self.bold_winner and (autobold_par == 'low')
self.medals = self.bold_winner and not in_array(self.args['medals'], no_replies)
-- load number of scores for each round
self.scores = {}
local scores_raw = args['scores'] or '1'
local max_scores = 1
Line 146 ⟶ 151:
Il valore di default di width è 0
=============================================================================== --]]
function TeamBracket:addGap(row, col, width, debug_textdebug_info)
width = width or 0
if self.last_element[row] + 1 < col then
local gap = tostring(col - self.last_element[row] - 1)
local cell=self.rows[row]:tag('td'):css('background-color', (debug and '#F5F5DC') or ''):attr('colspan', gap)
if debug then
--:wikitext(self.last_element[row] .. " c:".. col .. " w gap:" .. gap .. " w add:" .. width .. " n col:" .. col + width)
cell:wikitext(string.format('<div style="text-align:center;" title="row=%d, colonna:%d, last_col=%d, width:%d, gap:%s, last_col_set:%d, round:%d, deb:%s">info</div>',
row, col, self.last_element[row], width, gap, col+width, self.current_round, debug_info or ''))
end
end
self.last_element[row] = col + width
end
 
function TeamBracket:getWidth(param, default)
local arg = self.args[param .. '-width']
if not arg or arg == '' then arg = default end
if tonumber(arg) ~= nil then
arg = arg .. 'px'
end
return arg
end
 
function TeamBracket:getTeamArgName(round, argname, team)
return string.format(self.argname_pattern, round, argname, team)
end
 
function TeamBracket:getTeamArg(round, argname, team)
return self.args[self:getTeamArgName(round, argname, team)]
end
 
function TeamBracket:getScoreArg(round, team, score)
return self.args[string.format(self.scorename_pattern, round, team, score)]
end
 
function TeamBracket:getRoundName(round)
local name = self.args['RD' .. round]
if name then return name end
local round_names = {"Finale", "Semifinali", "Quarti", "Ottavi"}
local roundFromLast = self.rounds - round + 1
if roundFromLast < 5 then
return round_names[roundFromLast]
else
return tostring(round) .. "° turno"
end
end
 
Line 167 ⟶ 208:
nulli la funzione non disegna niente.
===============================================================================]]
function TeamBracket:addPath(row1, row2, row_gap, col, next_match)
if not (row1 or row2) then return end
self.render_match[self.current_round+1][next_match] = false
return
else
self.render_match[self.current_round+1][next_match] = true
end
local start_row = row1 and row1 + 2
local end_row = row2
Line 184 ⟶ 230:
end
if start_row then
for i = start_row, middle_row -1 do self:addGap(i, col, 0, 'ap1') end
end
self:addGap(middle_row, col, 1, 'ap2')
if end_row then
for i = middle_row +1, end_row+1 do self:addGap(i, col, 0, 'ap3') end
end
 
Line 205 ⟶ 251:
end
 
--[[ ------------------------------------------------------------
function TeamBracket:getWidth(param, default)
Compare score values and return and return the winner of the match
local arg = self.args[param .. '-width']
(team with majority of win, 0 mean parity, 1 fist team win, 2
if not arg or arg == '' then arg = default end
second team win) and and array with winner for single scores (for
if tonumber(arg) ~= nil then
each single score 0 parity, 1 first team win, 2 second team win.
arg = arg .. 'px'
------------------------------------------------------------ --]]
function TeamBracket:getWinner(first_team_number)
local victories1 = 0
local victories2 = 0
local score_results = {}
for i = 1, self.scores[self.current_round] do
local score1 = self:getScore(self.current_round, first_team_number, i)
local score2 = self:getScore(self.current_round, first_team_number+1, i)
if score1 and score2 then
if score1 ~= score2 then
local first_winner = score1 > score2
if self.low_winner then first_winner = not first_winner end
if first_winner then
victories1 = victories1 + 1
score_results[i] = 1
else
victories2 = victories2 + 1
score_results[i] = 2
end
end
end
score_results[i] = score_results[i] or 0
end
if victories1 == victories2 then return 0, score_results end
return arg
if victories1 > victories2 then return 1, score_results end
return 2, score_results
end
 
--[[ ===============================================================================
function TeamBracket:getTeamArgName(round, argname, team)
Disegna la cella per il team.
return string.format(self.argname_pattern, round, argname, team)
-- team_name: il nome del team
end
-- team_numer: il numero del team nella sequenza del round
 
-- row: la riga della prima cella in cui disegnare il team
function TeamBracket:getTeamArg(round, argname, team)
-- top: true se è il primo team del match
return self.args[self:getTeamArgName(round, argname, team)]
-- winner: il vincitore del match (1: il primo, 2: il secondo, 0:pari)
end
-- score_results: risultato degli scores individuali (1: vinto dal primo team, 2 vinto dal secondo, 3 pari)
 
===============================================================================]]
function TeamBracket:getScoreArg(round, team, score)
function TeamBracket:renderTeam(team_name, team_number, row, show_seed, top, winner, score_results)
return self.args[string.format(self.scorename_pattern, round, team, score)]
end
 
function TeamBracket:getRoundName(round)
local name = self.args['RD' .. round]
if name then return name end
local round_names = {"Finale", "Semifinali", "Quarti", "Ottavi"}
local roundFromLast = self.rounds - round + 1
if roundFromLast < 5 then
return round_names[roundFromLast]
else
return tostring(round) .. "° turno"
end
end
 
function TeamBracket:renderTeam(round, team_name, team_number, row, show_seed, top, winner, score_results, debug_info)
 
self:addGap(row, self.current_col, self.current_width, 'rt')
self:addGap(row+1, self.current_col, self.current_width, 'rt')
-- seed cell
local seedCell
local seedArgpos = self:getTeamArg(round,top 'seed',and team_number1) or 2
local seedArg = self:getTeamArg(self.current_round, 'seed', team_number)
if show_seed and (not self.hideSeeds) then
seedCell = self.rows[row]:tag('td'):attr('rowspan', '2'):cssText(style.seed_cell):wikitext(seedArg):newline()
if self.not_draw_top then seedCell:css('border-top-width', '0' ) end
if self.bold_winner and (winner == pos) then
seedCell:css(style.winner[1], style.winner[2])
end
end
-- team cell
local teamCell = self.rows[row]:tag('td'):attr('rowspan', '2'):cssText(style.team_cell):wikitext(team_name):newline()
--local teamCell = self.rows[row]:tag('td'):attr('rowspan', '2'):cssText(style.team_cell):wikitext(mw.text.jsonEncode(self.scores)):newline()
if not show_seed and (not self.hideSeeds) then
teamCell:attr('colspan', '2')
Line 258 ⟶ 317:
teamCell:css('border-top-width', '0' )
end
if self.bold_winner and winner == pos then
teamCell:css(style.winner[1], style.winner[2])
end
if roundself.current_round == self.rounds and winner ~= 0 and self.medals then
if winner then== pos then
if team_number < 3 then
teamCell:css(style.first_place[1], style.first_place[2])
teamCell:css(style.first_place[1], style.first_place[2])
else
else
teamCell:css(style.third_place[1], style.third_place[2])
end
elseif team_number < 3 then
teamCell:css(style.second_place[1], style.second_place[2])
end
end
-- scores cells
for i = 1, self.scores[roundself.current_round] do
local scoreCell = self.rows[row]
:tag('td')
:attr('rowspan', '2')
:cssText(style.score_cell)
:wikitext(self:getScoreArg(roundself.current_round, team_number, i))
:newline()
if self.not_draw_top then scoreCell:css('border-top-width', '0') end
if score_results[i] == pos then scoreCell:css(style.winner[1], style.winner[2]) end
end
if roundself.current_round == 1 then self.not_draw_top = not self.not_draw_top end
end
 
function TeamBracket:getScore(round, team_number, i)
returnlocal tonumberscore = string.gsub(self:getScoreArg(round, team_number, i)) or 0'', '%D', '')
return tonumber(score)
end
 
function TeamBracket:getWinnerrenderMatch(roundmatch_number, first_team_numberrow_base)
local victory1 = 0
local victory2 = 0
local winners = {}
for i = 1, self.scores[round] do
local score1 = self:getScore(round, first_team_number, i)
local score2 = self:getScore(round, first_team_number+1, i)
if score1 > score2 then
victory1 = victory1 + 1
winners[i] = 1
else
victory2 = victory2 + 1
winners[i] = 2
end
end
if victory1 == victory2 then return 0, winners end
if victory1 > victory2 then return 1, winners end
return 2, winners
end
 
function TeamBracket:renderMatch(round, match_number, row_base, debug_info)
local team_number2 = match_number * 2
local team_number1 = team_number2 - 1
local team_name1 = self:getTeamArg(roundself.current_round, 'team', team_number1) --or 'bye'
local team_name2 = self:getTeamArg(roundself.current_round, 'team', team_number2) --or 'bye'
if team_name1 == 'bye' or team_name2 == 'bye' then
self.not_draw_top = false
if self.render_match[self.current_round][match_number] then
return nil
self:addGap(row_base, self.current_col, self.current_width, 'rm')
self:addGap(row_base+1, self.current_col, self.current_width, 'rm')
self.rows[row_base]:tag('td')
:attr('rowspan', '2')
:attr('colspan', '3')
--:css('background-color', 'blue')
:cssText(style.path3)
:wikitext(match_number)
return row_base
end
end
local seedArg1 = self:getTeamArg(roundself.current_round, 'seed', team_number1)
local seedArg2 = self:getTeamArg(roundself.current_round, 'seed', team_number2)
local showSeed = self.showSeeds
or (seedArg1 and seedArg1 == '-')
or (seedArg2 and seedArg2 == '-')
local winner, score_results = self:getWinner(round0, team_number1){}
if self.bold_winner then
self:renderTeam(round, team_name1, team_number1, row_base, showSeed, true, winner == 1, score_results, debug_info)
winner, score_results = self:getWinner(team_number1)
self:renderTeam(round, team_name2, team_number2, row_base+2, showSeed, false, winner ==2, score_results, debug_info)
end
self:renderTeam(team_name1, team_number1, row_base, showSeed, true, winner, score_results)
self:renderTeam(team_name2, team_number2, row_base+2, showSeed, false, winner, score_results)
return row_base
end
Line 335 ⟶ 394:
or (seedArg1 and seedArg1 == '-')
or (seedArg2 and seedArg2 == '-')
local winner, score_results = self:getWinner(self.rounds0, 3){}
if self.bold_winner then
winner, score_results = self:getWinner(self.rounds, 3)
end
local seedArg1 = self:getTeamArg(self.rounds, 'seed', 3)
local seedArg2 = self:getTeamArg(self.rounds, 'seed', 4)
self:addGap(row, self.current_col, self.current_width, 'f3')
self.rows[row]:tag('td')
:cssText(style.header_third_place)
Line 344 ⟶ 406:
:wikitext("Finale 3° posto")
:newline()
self:renderTeam(self.rounds, team_name1, 3, row+2, showSeed, true, winner==1, score_results)
self:renderTeam(self.rounds, team_name2, 4, row+4, showSeed, truefalse, winner==1, score_results)
end
 
function TeamBracket:AddGroup(round, row, group_number)
local name = self.args[string.format('RD%d-group%d', roundself.current_round, group_number)]
if name then
local span = self.current_col + self.current_width - 1
self:addGap(row, self.current_col, self.current_col + span, 'g')
self:addGap(row+1, self.current_col, self.current_col + span, 'g')
self.rows[row]:tag('td')
:attr('rowspan', '2')
Line 381 ⟶ 443:
end
self.current_col = 2
self.render_match = {}
self.render_match[1] = {}
for round =1, self.rounds do
self.current_round = round
self.render_match[round+1] = {}
self.current_width = (self.hideSeeds and 2 or 1) + self.scores[round]
local match_number = math.pow(2, self.rounds - round)
Line 388 ⟶ 454:
local group_number = 1
for n = 1, match_number, 2 do
local match1 = self:renderMatch(round, n, row_base)
if round < self.rounds then
local match2 = self:renderMatch(round, n+1, row_base + gap + 4)
if not self.compact and round % 4 == 1 then
self:AddGroup(round, row_base+4, group_number)
group_number = group_number + 1
end
self:addPath(match1, match2, gap + 4, self.current_col + self.current_width + 1, (n+1)/2)
row_base = row_base + 2 * gap + 8
end
Line 470 ⟶ 536:
}
)
if args['debug'] then
debug = in_array(args['debug'], yes_replies) or debug
end
--return TeamBracket:new(args)
debug = in_array(args['debug'], yes_replies) or debug
local team_bracket = TeamBracket:new(args)
return tostring(team_bracket)