Skip to content

Commit

Permalink
feat(match2): switch DisplayHelper.MapScore from old data to using ne…
Browse files Browse the repository at this point in the history
…w data (#5228)

* feat(match2): switch DisplayHelper.MapScore from old data to using new data

* customs

* fix: show map scores on trackmania
(using the in this PR modified function)

* fix splatoon

* Apply suggestions from code review
  • Loading branch information
hjpalpha authored Dec 22, 2024
1 parent 41c3f0a commit 954dc8f
Show file tree
Hide file tree
Showing 30 changed files with 57 additions and 74 deletions.
17 changes: 7 additions & 10 deletions components/match2/commons/match_group_display_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,16 @@ function DisplayHelper.Map(game, config)
return mapText
end

---@param score string|number|nil
---@param opponentIndex integer
---@param resultType string?
---@param walkover string?
---@param winner integer?
---@param opponent table
---@param status string?
---@return string
function DisplayHelper.MapScore(score, opponentIndex, resultType, walkover, winner)
if resultType == 'np' then
function DisplayHelper.MapScore(opponent, gameStatus)
if gameStatus == 'notplayed' then
return ''
elseif resultType == 'default' then
return opponentIndex == winner and 'W' or string.upper(walkover or '')
elseif opponent.status and opponent.status ~= 'S' then
return opponent.status
end
return score and tostring(score) or ''
return opponent.score and tostring(opponent.score) or ''
end

--[[
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/arenafps/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
local function makeTeamSection(opponentIndex)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/artifact/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
end

local scoreOfOpponnent = function(opponentIndex)
return DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
return DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
end

local scoreDisplay = (scoreOfOpponnent(1) or '') .. ' - ' .. (scoreOfOpponnent(2) or '')
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/battalion/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
local function makeTeamSection(opponentIndex)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/brawlstars/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function CustomMatchSummary._createMapRow(game)
bg = 'brkts-popup-side-color-' .. teamColor,
},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/callofduty/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
local function makeTeamSection(opponentIndex)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

Expand Down
8 changes: 1 addition & 7 deletions components/match2/wikis/clashofclans/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,7 @@ end
function CustomMatchSummary._gameScore(game, opponentIndex)
return mw.html.create('div')
:css('width', '16px')
:wikitext(DisplayHelper.MapScore(
game.scores[opponentIndex],
opponentIndex,
game.resultType,
game.walkover,
game.winner
))
:wikitext(DisplayHelper.MapScore(game.opponents[opponentIndex], game.status))
end

function CustomMatchSummary._percentage(game, opponentIndex)
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/counterstrike/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function CustomMatchSummary._createMap(game)
end

local function score(oppIdx)
return DisplayHelper.MapScore(game.scores[oppIdx], oppIdx, game.resultType, game.walkover, game.winner)
return DisplayHelper.MapScore(game.opponents[oppIdx], game.status)
end

-- Teams scores
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/criticalops/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
end

local function score(oppIdx)
return DisplayHelper.MapScore(game.scores[oppIdx], oppIdx, game.resultType, game.walkover, game.winner)
return DisplayHelper.MapScore(game.opponents[oppIdx], game.status)
end

-- Teams scores
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/crossfire/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
local function makeTeamSection(opponentIndex)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

Expand Down
8 changes: 4 additions & 4 deletions components/match2/wikis/easportsfc/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ function CustomMatchSummary._createGame(game)
css = {['font-size'] = '84%', padding = '4px'},
children = WidgetUtil.collect(
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1},
DisplayHelper.MapScore(game.scores[1], 2, game.resultType, game.walkover, game.winner),
DisplayHelper.MapScore(game.opponents[1], game.status),
MatchSummaryWidgets.GameCenter{children = DisplayHelper.Map(game)},
DisplayHelper.MapScore(game.scores[2], 2, game.resultType, game.walkover, game.winner),
DisplayHelper.MapScore(game.opponents[2], game.status),
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2},
MatchSummaryWidgets.GameComment{children = game.comment}
)
Expand All @@ -78,11 +78,11 @@ function CustomMatchSummary._createSubMatch(game, match)
css = {['font-size'] = '84%', padding = '4px'},
children = WidgetUtil.collect(
CustomMatchSummary._players(players[1], 1, game.winner),
DisplayHelper.MapScore(game.scores[1], 2, game.resultType, game.walkover, game.winner),
DisplayHelper.MapScore(game.opponents[1], game.status),
CustomMatchSummary._score(CustomMatchSummary._subMatchPenaltyScore(game, 1)),
MatchSummaryWidgets.GameCenter{children = ' vs '},
CustomMatchSummary._score(CustomMatchSummary._subMatchPenaltyScore(game, 2)),
DisplayHelper.MapScore(game.scores[2], 2, game.resultType, game.walkover, game.winner),
DisplayHelper.MapScore(game.opponents[2], game.status),
CustomMatchSummary._players(players[2], 2, game.winner),
MatchSummaryWidgets.GameComment{children = game.comment}
)
Expand Down
11 changes: 1 addition & 10 deletions components/match2/wikis/geoguessr/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ function CustomMatchSummary.getByMatchId(args)
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args)
end

---@param game MatchGroupUtilGame
---@param opponentIndex integer
---@return Html
function CustomMatchSummary._gameScore(game, opponentIndex)
local score = game.scores[opponentIndex]
local scoreDisplay = DisplayHelper.MapScore(score, opponentIndex, game.resultType, game.walkover, game.winner)
return mw.html.create('div'):wikitext(scoreDisplay)
end

---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
Expand All @@ -38,7 +29,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
local function makeTeamSection(opponentIndex)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

Expand Down
4 changes: 2 additions & 2 deletions components/match2/wikis/goals/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
css = {['font-size'] = '80%', padding = '4px'},
children = WidgetUtil.collect(
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1},
DisplayHelper.MapScore(game.scores[1], 1, game.resultType, game.walkover, game.winner),
DisplayHelper.MapScore(game.opponents[1], game.status),
MatchSummaryWidgets.GameCenter{children = ('Game ' .. gameIndex)},
DisplayHelper.MapScore(game.scores[2], 2, game.resultType, game.walkover, game.winner),
DisplayHelper.MapScore(game.opponents[2], game.status),
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2},
MatchSummaryWidgets.GameComment{children = game.comment}
)
Expand Down
8 changes: 1 addition & 7 deletions components/match2/wikis/halo/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
end

local displayScore = function(opponentIndex)
local score = DisplayHelper.MapScore(
game.scores[opponentIndex],
opponentIndex,
game.resultType,
game.walkover,
game.winner
)
local score = DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
local points = game.extradata['points' .. opponentIndex]
if not points then
return score
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/marvelrivals/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
local function makeTeamSection(opponentIndex)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/omegastrikers/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function CustomMatchSummary._createMapRow(game)
bg = opponentIndex == 1 and 'brkts-popup-side-color-blue' or 'brkts-popup-side-color-red',
},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/osu/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function CustomMatchSummary._createMapRow(game)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
displayNumericScore(
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
)
}
end
Expand Down
10 changes: 6 additions & 4 deletions components/match2/wikis/overwatch/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--

local Lua = require('Module:Lua')
local Table = require('Module:Table')

local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
local MatchSummary = Lua.import('Module:MatchSummary/Base')
Expand Down Expand Up @@ -52,11 +53,12 @@ end
---@param opponentIndex integer
---@return Html
function CustomMatchSummary._gameScore(game, opponentIndex)
local score = game.scores[opponentIndex] --[[@as number|string?]]
if score and game.mode == 'Push' then
score = score .. 'm'
local opponentCopy = Table.deepCopy(game.opponents[opponentIndex])
if opponentCopy.score and game.mode == 'Push' then
opponentCopy.score = opponentCopy.score .. 'm'
end
local scoreDisplay = DisplayHelper.MapScore(score, opponentIndex, game.resultType, game.walkover, game.winner)

local scoreDisplay = DisplayHelper.MapScore(opponentCopy, game.status)
return mw.html.create('div'):wikitext(scoreDisplay)
end

Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/paladins/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
MatchSummaryWidgets.Characters{characters = characterData[opponentIndex], flipped = flipped},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner),
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status),
}
end

Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/rainbowsix/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
local extradata = game.extradata or {}

local function scoreDisplay(oppIdx)
return DisplayHelper.MapScore(game.scores[oppIdx], oppIdx, game.resultType, game.walkover, game.winner)
return DisplayHelper.MapScore(game.opponents[oppIdx], game.status)
end

local function operatorDisplay(operators)
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/rocketleague/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)

local function makeTeamSection(opponentIndex)
return {
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner),
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status),
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
}
end
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/sideswipe/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)

local function makeTeamSection(opponentIndex)
return {
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner),
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status),
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
}
end
Expand Down
9 changes: 5 additions & 4 deletions components/match2/wikis/splatoon/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local Lua = require('Module:Lua')
local MapTypeIcon = require('Module:MapType')
local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local WeaponIcon = require('Module:WeaponIcon')

local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
Expand Down Expand Up @@ -77,11 +78,11 @@ end
---@param opponentIndex integer
---@return Html
function CustomMatchSummary._gameScore(game, opponentIndex)
local score = game.scores[opponentIndex] --[[@as number|string?]]
if score and game.mode == 'Turf War' then
score = score .. '%'
local opponentCopy = Table.deepCopy(game.opponents[opponentIndex])
if opponentCopy.score and game.mode == 'Turf War' then
opponentCopy.score = opponentCopy.score .. '%'
end
local scoreDisplay = DisplayHelper.MapScore(score, opponentIndex, game.resultType, game.walkover, game.winner)
local scoreDisplay = DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
return mw.html.create('div')
:addClass('brkts-popup-body-element-vertical-centered')
:css('min-width', '24px')
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/splitgate/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
local function makeTeamSection(opponentIndex)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/teamfortress/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
local function makeTeamSection(opponentIndex)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/tetris/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
local function makeTeamSection(opponentIndex)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/tft/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
local function makeTeamSection(opponentIndex)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

Expand Down
14 changes: 9 additions & 5 deletions components/match2/wikis/trackmania/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local Abbreviation = require('Module:Abbreviation')
local Class = require('Module:Class')
local Lua = require('Module:Lua')

local HtmlWidgets = Lua.import('Module:Widget/Html/All')
local MatchSummary = Lua.import('Module:MatchSummary/Base')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
Expand Down Expand Up @@ -155,9 +156,11 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
classes = {'brkts-popup-body-game'},
children = WidgetUtil.collect(
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1},
DisplayHelper.MapScore(game.opponents[1], game.status),
extradata.overtime and CustomMatchSummary._iconDisplay(OVERTIME, 'Overtime') or nil,
MatchSummaryWidgets.GameCenter{children = DisplayHelper.Map(game)},
MatchSummaryWidgets.GameCenter{children = DisplayHelper.Map(game, {noLink = true})},
extradata.overtime and CustomMatchSummary._iconDisplay(OVERTIME, 'Overtime') or nil,
DisplayHelper.MapScore(game.opponents[2], game.status),
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2},
MatchSummaryWidgets.GameComment{children = game.comment}
)
Expand All @@ -168,10 +171,11 @@ end
---@param hoverText string|number|nil
---@return Html
function CustomMatchSummary._iconDisplay(icon, hoverText)
return mw.html.create('div')
:addClass('brkts-popup-spaced')
:node(icon)
:attr('title', hoverText)
return HtmlWidgets.Div{
classes = {'brkts-popup-spaced'},
attributes = {title = hoverText},
children = {icon},
}
end

return CustomMatchSummary
2 changes: 1 addition & 1 deletion components/match2/wikis/valorant/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
end

local function scoreDisplay(oppIdx)
return DisplayHelper.MapScore(game.scores[oppIdx], oppIdx, game.resultType, game.walkover, game.winner)
return DisplayHelper.MapScore(game.opponents[oppIdx], game.status)
end

local function makePartialScores(halves, firstSide)
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/worldoftanks/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
local function makeTeamSection(opponentIndex)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

Expand Down

0 comments on commit 954dc8f

Please sign in to comment.