Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(various): remove usage of deprecated match2 and match2game fields #5229

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions components/game_table/commons/game_table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ local Class = require('Module:Class')
local Game = require('Module:Game')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Operator = require('Module:Operator')
local VodLink = require('Module:VodLink')

local MatchTable = Lua.import('Module:MatchTable')

local NOT_PLAYED = 'np'
local NOT_PLAYED = 'notplayed'
local SCORE_CONCAT = ' : '

---@class GameTableMatch: MatchTableMatch
Expand All @@ -31,7 +32,7 @@ end)
---@return match2game?
function GameTable:gameFromRecord(game)
if self.countGames == self.config.limit then return nil end
if game.resulttype == NOT_PLAYED or Logic.isEmpty(game.winner) then
if game.status == NOT_PLAYED or Logic.isEmpty(game.winner) then
return nil
end

Expand Down Expand Up @@ -76,9 +77,10 @@ end
---@param game match2game
---@return Html?
function GameTable:_displayGameScore(result, game)
local scores = Array.map(game.opponents, Operator.property('score'))
local toScore = function(opponentRecord)
local isWinner = opponentRecord.id == tonumber(game.winner)
local score = (game.scores or {})[opponentRecord.id] or (isWinner and 1) or 0
local score = scores[opponentRecord.id] or (isWinner and 1) or 0
return mw.html.create(isWinner and 'b' or nil)
:wikitext(score)
end
Expand Down
10 changes: 6 additions & 4 deletions components/game_table/commons/game_table_character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local CharacterIcon = require('Module:CharacterIcon')
local Class = require('Module:Class')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Operator = require('Module:Operator')
local Table = require('Module:Table')

local GameTable = Lua.import('Module:GameTable')
Expand All @@ -23,7 +24,7 @@ local Comparator = Condition.Comparator
local BooleanOperator = Condition.BooleanOperator
local ColumnName = Condition.ColumnName

local DRAW = 'draw'
local DRAW_WINNER = 0
local CHARACTER_MODE = 'character'
local SCORE_CONCAT = ' : '

Expand Down Expand Up @@ -181,6 +182,7 @@ end
---@param game CharacterGameTableGame
---@param maxNumber number
---@param keyMaker fun(self, opponentIndex, playerIndex)
---@return table[]
function CharacterGameTable:getCharacters(game, maxNumber, keyMaker)
---@param opponentIndex number
---@return table
Expand Down Expand Up @@ -246,7 +248,6 @@ function CharacterGameTable:resultFromRecord(record)
opponent = record.match2opponents[1],
vs = record.match2opponents[2],
winner = tonumber(record.winner),
resultType = record.resultType,
countGames = true,
}
end
Expand All @@ -260,7 +261,7 @@ function CharacterGameTable:statsFromMatches()
Array.forEach(match.games, function (game, index)
local winner = tonumber(game.winner)

if game.resulttype == DRAW then
if game.winner == DRAW_WINNER then
totalGames.d = totalGames.d + 1
elseif game.pickedBy == winner then
totalGames.w = totalGames.w + 1
Expand Down Expand Up @@ -386,11 +387,12 @@ end
---@return Html
function CharacterGameTable:_displayScore(game, pickedBy, pickedVs)
local winner = tonumber(game.winner)
local scores = Array.map(game.opponents, Operator.property('score'))

local toScore = function(opponentId)
local isWinner = winner == opponentId
return mw.html.create(isWinner and 'b' or nil)
:wikitext(game.scores[opponentId] or (isWinner and 'W' or 'L'))
:wikitext(scores[opponentId] or (isWinner and 'W' or 'L'))
end

return mw.html.create('td')
Expand Down
20 changes: 11 additions & 9 deletions components/game_table/valorant/game_table_character_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ local Class = require('Module:Class')
local Lua = require('Module:Lua')
local MathUtil = require('Module:MathUtil')
local Page = require('Module:Page')
local Table = require('Module:Table')

local OpponentLibraries = require('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent
Expand All @@ -39,14 +38,17 @@ function CustomCharacterGameTable:getCharacterPick(game)
end
local aliases = self.config.aliases
local found
Table.iter.forEachPair(game.participants, function (participantId, participant)

Array.forEach(game.opponents, function(opponent, opponentIndex)
if found then return end
if aliases[participant.player] then
local pKey = Array.parseCommaSeparatedString(participantId, '_')
game.pickedByplayer = tonumber(pKey[2])
found = tonumber(pKey[1])
return
end
Array.forEach(opponent.players, function(player, playerIndex)
if found then return end
if aliases[player.player] then
game.pickedByplayer = playerIndex
found = opponentIndex
return
end
end)
end)

return found
Expand Down Expand Up @@ -141,7 +143,7 @@ function CustomCharacterGameTable:displayGame(match, game)
:node(makeCell(Page.makeInternalLink(game.map)))

if self.config.mode ~= Opponent.team then
local participant = game.participants[game.pickedBy .. '_' .. game.pickedByplayer]
local participant = game.opponents[game.pickedBy].players[game.pickedByplayer]
if self.config.mode == Opponent.solo then
local index = Array.indexOf(game.picks[game.pickedBy], function (pick)
return participant.agent == pick
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function CustomPlayer:_getMatchupData(player)
'[[finished::1]]', -- only finished matches
'[[winner::!]]', -- expect a winner
'[[walkover::]]', -- exclude default wins/losses
'[[resulttype::!np]]', -- i.e. ignore not played matches
'[[status::!notplayed]]', -- i.e. ignore not played matches
'[[date::!' .. DateExt.defaultDate .. ']]', --i.e. wrongly set up
'([[opponent::' .. player .. ']] OR [[opponent::' .. playerWithoutUnderscore .. ']])'
}, ' AND '),
Expand Down
4 changes: 2 additions & 2 deletions components/match2/commons/match.lua
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,12 @@ Match.gameFields = Table.map({
'map',
'mode',
'parent',
'participants',
'participants', -- LPDB API v3: backwards compatibility
'patch',
'opponents',
'resulttype', -- LPDB API v3: backwards compatibility
'rounds',
'scores',
'scores', -- LPDB API v3: backwards compatibility
'status',
'subgroup',
'tournament',
Expand Down
29 changes: 15 additions & 14 deletions components/match2/commons/match_group_display_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ local Lua = require('Module:Lua')
local Table = require('Module:Table')
local Timezone = require('Module:Timezone')

local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
local Opponent = Lua.import('Module:Opponent')

local DisplayHelper = {}
Expand Down Expand Up @@ -125,20 +126,20 @@ end
function DisplayHelper.MapAndStatus(game, config)
local mapText = DisplayHelper.Map(game, config)

local statusText = nil
if game.resultType == 'default' then
if game.walkover == 'l' then
statusText = NONBREAKING_SPACE .. '<i>(w/o)</i>'
elseif game.walkover == 'ff' then
statusText = NONBREAKING_SPACE .. '<i>(ff)</i>'
elseif game.walkover == 'dq' then
statusText = NONBREAKING_SPACE .. '<i>(dq)</i>'
else
statusText = NONBREAKING_SPACE .. '<i>(def.)</i>'
end
local walkoverType = MatchOpponentHelper.calculateWalkoverType(game.opponents)
if not walkoverType then return mapText end

---@param walkoverDisplay string
---@return string
local toDisplay = function(walkoverDisplay)
return mapText .. NONBREAKING_SPACE .. '<i>()' .. walkoverDisplay .. ')</i>'
end

return mapText .. (statusText or '')
if walkoverType == MatchOpponentHelper.STATUS.LOSS then
return toDisplay('w/o')
else
return toDisplay(walkoverType:lower())
end
end

---Displays the map name and map-mode.
Expand Down Expand Up @@ -170,14 +171,14 @@ function DisplayHelper.Map(game, config)
else
mapText = game.map or 'Unknown'
end
if game.resultType == 'np' then
if game.status == 'notplayed' then
mapText = '<s>' .. mapText .. '</s>'
end
return mapText
end

---@param opponent table
---@param status string?
---@param gameStatus string?
---@return string
function DisplayHelper.MapScore(opponent, gameStatus)
if gameStatus == 'notplayed' then
Expand Down
11 changes: 6 additions & 5 deletions components/match2/commons/match_group_display_matchlist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ local OpponentDisplay = OpponentLibrary.OpponentDisplay

local MatchlistDisplay = {propTypes = {}, types = {}}

local SCORE_DRAW = 0

---@class MatchlistConfigOptions
---@field MatchSummaryContainer function?
---@field Opponent function?
Expand Down Expand Up @@ -126,7 +128,7 @@ function MatchlistDisplay.Match(props)

local opponentNode = props.Opponent({
opponent = opponent,
resultType = match.resultType,
winner = match.winner,
side = opponentIx == 1 and 'left' or 'right',
})
return DisplayHelper.addOpponentHighlight(opponentNode, opponent)
Expand All @@ -137,7 +139,6 @@ function MatchlistDisplay.Match(props)

local scoreNode = props.Score({
opponent = opponent,
resultType = match.resultType,
side = opponentIx == 1 and 'left' or 'right',
})
return DisplayHelper.addOpponentHighlight(scoreNode, opponent)
Expand Down Expand Up @@ -204,7 +205,7 @@ This is the default implementation used by the Matchlist component. Specific
wikis may override this by passing a different props.Opponent to the Matchlist
component.
]]
---@param props {opponent: standardOpponent, resultType: ResultType, side: string}
---@param props {opponent: standardOpponent, winner: integer?, side: string}
---@return Html
function MatchlistDisplay.Opponent(props)
local contentNode = OpponentDisplay.BlockOpponent({
Expand All @@ -217,7 +218,7 @@ function MatchlistDisplay.Opponent(props)
:addClass('brkts-matchlist-cell-content')
return mw.html.create('div')
:addClass('brkts-matchlist-cell brkts-matchlist-opponent')
:addClass(props.resultType == 'draw' and 'brkts-matchlist-slot-bold bg-draw' or
:addClass(props.winner == SCORE_DRAW and 'brkts-matchlist-slot-bold bg-draw' or
props.opponent.placement == 1 and 'brkts-matchlist-slot-winner' or nil)
:node(contentNode)
end
Expand All @@ -229,7 +230,7 @@ This is the default implementation used by the Matchlist component. Specific
wikis may override this by passing a different props.Score to the Matchlist
component.
]]
---@param props {opponent: standardOpponent, resultType: ResultType, side: string}
---@param props {opponent: standardOpponent, side: string}
---@return Html
function MatchlistDisplay.Score(props)
local contentNode = mw.html.create('div'):addClass('brkts-matchlist-cell-content')
Expand Down
31 changes: 4 additions & 27 deletions components/match2/commons/match_group_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ MatchGroupUtil.types.GameOpponent = TypeUtil.struct({

---@alias MatchStatus 'notplayed'|''|nil
MatchGroupUtil.types.Status = TypeUtil.optional(TypeUtil.literalUnion('notplayed', ''))
---@alias ResultType 'default'|'draw'|'np'
MatchGroupUtil.types.ResultType = TypeUtil.literalUnion('default', 'draw', 'np')
---@alias WalkoverType 'l'|'ff'|'dq'
MatchGroupUtil.types.Walkover = TypeUtil.literalUnion('l', 'ff', 'dq')

---@class MatchGroupUtilGame
---@field comment string?
Expand All @@ -208,13 +204,10 @@ MatchGroupUtil.types.Walkover = TypeUtil.literalUnion('l', 'ff', 'dq')
---@field mapDisplayName string?
---@field mode string?
---@field opponents {players: table[]}[]
---@field participants table
---@field resultType ResultType?
---@field scores number[]
---@field subgroup number?
---@field type string?
---@field vod string?
---@field walkover WalkoverType?
---@field winner integer?
---@field status string?
---@field extradata table?
Expand All @@ -227,13 +220,10 @@ MatchGroupUtil.types.Game = TypeUtil.struct({
map = 'string?',
mapDisplayName = 'string?',
mode = 'string?',
participants = 'table',
resultType = TypeUtil.optional(MatchGroupUtil.types.ResultType),
scores = TypeUtil.array('number'),
subgroup = 'number?',
type = 'string?',
vod = 'string?',
walkover = TypeUtil.optional(MatchGroupUtil.types.Walkover),
winner = 'number?',
extradata = 'table?',
})
Expand All @@ -250,14 +240,12 @@ MatchGroupUtil.types.Game = TypeUtil.struct({
---@field matchId string?
---@field mode string?
---@field opponents standardOpponent[]
---@field resultType ResultType?
---@field status MatchStatus
---@field stream table
---@field tickername string?
---@field tournament string?
---@field type string?
---@field vod string?
---@field walkover WalkoverType?
---@field winner string?
---@field extradata table?
---@field timestamp number
Expand All @@ -274,14 +262,12 @@ MatchGroupUtil.types.Match = TypeUtil.struct({
matchId = 'string?',
mode = 'string',
opponents = TypeUtil.array(MatchGroupUtil.types.Opponent),
resultType = 'string?',
status = MatchGroupUtil.types.Status,
stream = 'table',
tickername = 'string?',
tournament = 'string?',
type = 'string?',
vod = 'string?',
walkover = 'string?',
winner = 'number?',
extradata = 'table?',
})
Expand Down Expand Up @@ -623,18 +609,9 @@ function MatchGroupUtil.opponentFromRecord(matchRecord, record, opponentIndex)
local bestof = tonumber(matchRecord.bestof)
local game1 = (matchRecord.match2games or {})[1]
if bestof == 1 and Info.config.match2.gameScoresIfBo1 and game1 then
local winner = tonumber(game1.winner)
if game1.resulttype == 'default' then
score = -1
if winner == 0 then
status = 'D'
else
status = winner == opponentIndex and 'W' or string.upper(game1.walkover)
end
elseif game1.scores[opponentIndex] then
score = game1.scores[opponentIndex]
status = 'S'
end
local mapOpponent = (game1.opponnets or {})[opponentIndex] or {}
score = mapOpponent.score
status = mapOpponent.status
end

return {
Expand Down Expand Up @@ -698,8 +675,8 @@ function MatchGroupUtil.gameFromRecord(record, opponentCount)
mapDisplayName = nilIfEmpty(Table.extract(extradata, 'displayname')),
mode = nilIfEmpty(record.mode),
opponents = record.opponents,
participants = Json.parseIfString(record.participants) or {},
resultType = nilIfEmpty(record.resulttype),
status = nilIfEmpty(record.status),
scores = Json.parseIfString(record.scores) or {},
subgroup = tonumber(record.subgroup),
type = nilIfEmpty(record.type),
Expand Down
Loading
Loading