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 11 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
4 changes: 2 additions & 2 deletions components/game_table/commons/game_table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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 +31,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
6 changes: 3 additions & 3 deletions components/game_table/commons/game_table_character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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 +181,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 +247,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 +260,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
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
27 changes: 14 additions & 13 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,7 +171,7 @@ 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
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
20 changes: 6 additions & 14 deletions components/match2/commons/match_group_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ MatchGroupUtil.types.Walkover = TypeUtil.literalUnion('l', 'ff', 'dq')
---@field mode string?
---@field opponents {players: table[]}[]
---@field participants table
---@field resultType ResultType?
---@field resultType ResultType? ---@deprecated
---@field scores number[]
---@field subgroup number?
---@field type string?
Expand Down Expand Up @@ -250,7 +250,7 @@ MatchGroupUtil.types.Game = TypeUtil.struct({
---@field matchId string?
---@field mode string?
---@field opponents standardOpponent[]
---@field resultType ResultType?
---@field resultType ResultType? ---@deprecated
---@field status MatchStatus
---@field stream table
---@field tickername string?
Expand Down Expand Up @@ -623,18 +623,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 @@ -700,6 +691,7 @@ function MatchGroupUtil.gameFromRecord(record, opponentCount)
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
34 changes: 34 additions & 0 deletions components/match2/commons/match_opponent_helper.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should i move it into Module:Opponent instead? or somehwere else???

-- @Liquipedia
-- wiki=commons
-- page=Module:MatchOpponentHelper
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Array = require('Module:Array')


local MatchOpponentHelper = {}

MatchOpponentHelper.STATUS = {
SCORE = 'S',
FORFEIT = 'FF',
DISQUALIFIED = 'DQ',
LOSS = 'L',
WIN = 'W',
}

---@param opponents table[]
---@return string?
function MatchOpponentHelper.calculateWalkoverType(opponents)
return (Array.find(opponents or {}, function(opponent)
return opponent.status == MatchOpponentHelper.STATUS.FORFEIT
or opponent.status == MatchOpponentHelper.STATUS.DISQUALIFIED
or opponent.status == MatchOpponentHelper.STATUS.LOSS
end) or {}).status
end



return MatchOpponentHelper
Loading
Loading