Content deleted Content added
S.A. Julio (talk | contribs) improve logic |
S.A. Julio (talk | contribs) allow for determining winner on away goals |
||
Line 9:
end
-- Function to check the existence of template passed via |flag=
local function templateExists(templateName)
local title = mw.title.new('Template:' .. templateName)
Line 77 ⟶ 78:
-- Function to determine the winner based on scores within parentheses (first) or regular format (second)
local function determineWinner(
local team1Winner, team2Winner = false, false
local score1, score2
Line 103 ⟶ 104:
end
-- Handling for manual coloring of team or aggregate cells
if team1 and type(team1) == 'string' then
manualColor1 = team1:find("''") and not (team1:gsub("''", ""):match("^%s*$"))
Line 140 ⟶ 141:
-- Regular winner determination logic if manual bolding or coloring is not conclusive
if not team1Winner and not team2Winner and not isDraw and (boldWinner or colorWinner or isFBRStyle) then
local parenthetical =
local outsideParenthetical =
if parenthetical then -- Prioritize checking score inside parenthetical
score1, score2 = parenthetical:match('(%d+)%-+(%d+)')
elseif outsideParenthetical then
Line 149 ⟶ 150:
if score1 and score2 then
team2Winner = tonumber(score1) < tonumber(score2)▼
if
elseif score1 == score2 and legs == 2 and not disableAwayGoals then
local cleanLeg1 = cleanScore(leg1Score):gsub('[()]', '')
local cleanLeg2 = cleanScore(leg2Score):gsub('[()]', '')
local _, team2AwayGoals = cleanLeg1:match('(%d+)%-+(%d+)')
local team1AwayGoals = cleanLeg2:match('(%d+)%-+(%d+)')
team1AwayGoals, team2AwayGoals = tonumber(team1AwayGoals), tonumber(team2AwayGoals)
team2Winner = true
end
end
end
if (colorWinner or isFBRStyle) and legs == 0 then
isDraw = not team1Winner and not team2Winner
end
end
Line 170 ⟶ 194:
end
-- Function to add a legend to below the table when |matches_style=FBR
local function createFBRLegend()
return mw.html.create('div')
Line 197 ⟶ 222:
local fillBlanks = args.fill_blanks and (args.fill_blanks == 'y' or args.fill_blanks == 'yes' or args.fill_blanks == '1' or args.fill_blanks == 'true')
-- Process the font size parameter
local size
if args.size then
Line 252 ⟶ 277:
local isFBRStyle = matchesStyle and matchesStyle:upper() == "FBR"
local isHA = args.h_a == 'y' or args.h_a == 'yes' or args.h_a == '1' or args.h_a == 'true'
local disableAwayGoals = args.away_goals == 'n' or args.away_goals == 'no' or args.away_goals == '0' or args.away_goals == 'false' or args.away_goals == 'null'
local tableClass = 'wikitable'
Line 367 ⟶ 393:
local team1, aggregateScore, team2
local team1Winner, team2Winner, manualBold, manualColor, isDraw = false, false, false, false, false
local leg1Score, leg2Score = false, false
local team1Asterick, team2Asterick = false, false
Line 390 ⟶ 417:
-- Clean the aggregate score
local cleanAggregate = cleanScore(aggregateScore)
-- Name the 1st/2nd leg scores for two-legged ties for possibly determining the winner on away goals
if legs == 2 then
leg1Score = args[i+3]
leg2Score = args[i+4]
end
-- Determine the winning team on aggregate
team1, team2, team1Winner, team2Winner, manualBold, manualColor, isDraw, aggregateScore = determineWinner(cleanAggregate, matchType, team1, team2, boldWinner, colorWinner, aggregateScore, isFBRStyle, legs, leg1Score, leg2Score, disableAwayGoals)
-- Add background-color for winning team if set by user
local team1Style = team1Winner and ((colorWinner or manualColor) and 'background-color: #CCFFCC;' or '') .. 'text-align: right;' or 'text-align: right;'
Line 415 ⟶ 447:
-- Create aggregate score cell with conditional styling
local aggregateStyle = 'text-align: center;'
if isFBRStyle and legs == 0
if
elseif team2Winner then
aggregateStyle = aggregateStyle .. '; background-color: # ▲ elseif team2Winner then
aggregateStyle = aggregateStyle .. '; background-color: #FFBBBB;'▼
▲ elseif isDraw then
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'▼
▲ end
elseif isDraw then
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'
end
elseif isDraw then
end
-- Create rows for aggregate score and team names, bolded if set by user
Line 446 ⟶ 476:
-- Clean the aggregate score
local cleanAggregate = cleanScore(aggregateScore)
-- Name the 1st/2nd leg scores for two-legged ties for possibly determining the winner on away goals
if legs == 2 then
if noFlagIcons then
leg1Score = args[i+3]
leg2Score = args[i+4]
else
leg1Score = args[i+5]
leg2Score = args[i+6]
end
end
-- Determine the winning team on aggregate
team1, team2, team1Winner, team2Winner, manualBold, manualColor, isDraw, aggregateScore = determineWinner(cleanAggregate, matchType, team1, team2, boldWinner, colorWinner, aggregateScore, isFBRStyle, legs, leg1Score, leg2Score, disableAwayGoals)
-- Add background-color for winning team if set by user
local team1Style = team1Winner and ((colorWinner or manualColor) and 'background-color: #CCFFCC;' or '') .. 'text-align: right;' or 'text-align: right;'
Line 467 ⟶ 507:
-- Create aggregate score cell with conditional styling
local aggregateStyle = 'text-align: center;'
if isFBRStyle and legs == 0
if
elseif team2Winner then
aggregateStyle = aggregateStyle .. '; background-color: # ▲ elseif team2Winner then
▲ elseif isDraw then
▲ end
elseif isDraw then
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'
end
elseif isDraw then
end
-- Create rows for aggregate score and team names, bolded if set by user
|