diff --git a/components/game_table/commons/game_table.lua b/components/game_table/commons/game_table.lua
index d627990b15f..b9830f0e8c3 100644
--- a/components/game_table/commons/game_table.lua
+++ b/components/game_table/commons/game_table.lua
@@ -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
@@ -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
@@ -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
diff --git a/components/game_table/commons/game_table_character.lua b/components/game_table/commons/game_table_character.lua
index 500d35d89ca..9589b10b3a8 100644
--- a/components/game_table/commons/game_table_character.lua
+++ b/components/game_table/commons/game_table_character.lua
@@ -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')
@@ -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 = ' : '
@@ -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
@@ -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
@@ -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
@@ -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')
diff --git a/components/game_table/valorant/game_table_character_custom.lua b/components/game_table/valorant/game_table_character_custom.lua
index 19f0b79dee6..7e852cfa179 100644
--- a/components/game_table/valorant/game_table_character_custom.lua
+++ b/components/game_table/valorant/game_table_character_custom.lua
@@ -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
@@ -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
@@ -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
diff --git a/components/infobox/wikis/starcraft2/infobox_person_player_custom.lua b/components/infobox/wikis/starcraft2/infobox_person_player_custom.lua
index beac8e83e60..2e88c2ac043 100644
--- a/components/infobox/wikis/starcraft2/infobox_person_player_custom.lua
+++ b/components/infobox/wikis/starcraft2/infobox_person_player_custom.lua
@@ -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 '),
diff --git a/components/match2/commons/match.lua b/components/match2/commons/match.lua
index dc2a4a62223..cdf3b607cee 100644
--- a/components/match2/commons/match.lua
+++ b/components/match2/commons/match.lua
@@ -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',
diff --git a/components/match2/commons/match_group_display_helper.lua b/components/match2/commons/match_group_display_helper.lua
index ad0922b2346..ac259f427b0 100644
--- a/components/match2/commons/match_group_display_helper.lua
+++ b/components/match2/commons/match_group_display_helper.lua
@@ -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 = {}
@@ -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 .. '(w/o)'
- elseif game.walkover == 'ff' then
- statusText = NONBREAKING_SPACE .. '(ff)'
- elseif game.walkover == 'dq' then
- statusText = NONBREAKING_SPACE .. '(dq)'
- else
- statusText = NONBREAKING_SPACE .. '(def.)'
- 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 .. '()' .. walkoverDisplay .. ')'
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.
@@ -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 = '' .. mapText .. ''
end
return mapText
end
---@param opponent table
----@param status string?
+---@param gameStatus string?
---@return string
function DisplayHelper.MapScore(opponent, gameStatus)
if gameStatus == 'notplayed' then
diff --git a/components/match2/commons/match_group_display_matchlist.lua b/components/match2/commons/match_group_display_matchlist.lua
index 4eaa49013f1..4ecc2f24f29 100644
--- a/components/match2/commons/match_group_display_matchlist.lua
+++ b/components/match2/commons/match_group_display_matchlist.lua
@@ -20,6 +20,8 @@ local OpponentDisplay = OpponentLibrary.OpponentDisplay
local MatchlistDisplay = {propTypes = {}, types = {}}
+local SCORE_DRAW = 0
+
---@class MatchlistConfigOptions
---@field MatchSummaryContainer function?
---@field Opponent function?
@@ -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)
@@ -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)
@@ -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({
@@ -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
@@ -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')
diff --git a/components/match2/commons/match_group_util.lua b/components/match2/commons/match_group_util.lua
index 0d61e2ac47c..a5fbf122465 100644
--- a/components/match2/commons/match_group_util.lua
+++ b/components/match2/commons/match_group_util.lua
@@ -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?
@@ -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?
@@ -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?',
})
@@ -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
@@ -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?',
})
@@ -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 {
@@ -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),
diff --git a/components/match2/commons/match_opponent_helper.lua b/components/match2/commons/match_opponent_helper.lua
new file mode 100644
index 00000000000..1f1b7668c5e
--- /dev/null
+++ b/components/match2/commons/match_opponent_helper.lua
@@ -0,0 +1,34 @@
+---
+-- @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
diff --git a/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft_ffa.lua b/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft_ffa.lua
index 64809a50953..08e8112ee4b 100644
--- a/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft_ffa.lua
+++ b/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft_ffa.lua
@@ -81,7 +81,8 @@ function MatchFunctions.calculateMatchScore(opponents, games)
local opponent = opponents[opponentIndex]
local sum = (opponent.extradata.advantage or 0) - (opponent.extradata.penalty or 0)
Array.forEach(games, function(game)
- sum = sum + ((game.scores or {})[opponentIndex] or 0)
+ local scores = Array.map(game.opponents, Operator.property('score'))
+ sum = sum + ((scores or {})[opponentIndex] or 0)
end)
return sum
end
diff --git a/components/match2/commons/starcraft_starcraft2/match_group_util_starcraft.lua b/components/match2/commons/starcraft_starcraft2/match_group_util_starcraft.lua
index 9099b744ef8..5dcb75099d5 100644
--- a/components/match2/commons/starcraft_starcraft2/match_group_util_starcraft.lua
+++ b/components/match2/commons/starcraft_starcraft2/match_group_util_starcraft.lua
@@ -11,17 +11,19 @@ local Faction = require('Module:Faction')
local Flags = require('Module:Flags')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')
+local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')
local OpponentLibraries = require('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent
---[[
-Utility functions for match group related things specific to the starcraft and starcraft2 wikis.
-]]
+local SCORE_STATUS = MatchGroupInputUtil.STATUS.SCORE
+
+--Utility functions for match group related things specific to the starcraft and starcraft2 wikis.
local StarcraftMatchGroupUtil = Table.deepCopy(MatchGroupUtil)
---@class StarcraftMatchGroupUtilGameOpponent:GameOpponent
@@ -43,11 +45,9 @@ local StarcraftMatchGroupUtil = Table.deepCopy(MatchGroupUtil)
---@class StarcraftMatchGroupUtilSubmatch
---@field games StarcraftMatchGroupUtilGame[]
---@field mode string
+---@field status string?
---@field opponents StarcraftMatchGroupUtilGameOpponent[]
----@field resultType ResultType
----@field scores table
---@field subgroup number
----@field walkover WalkoverType
---@field winner number?
---@field header string?
@@ -88,11 +88,6 @@ function StarcraftMatchGroupUtil.matchFromRecord(record)
StarcraftMatchGroupUtil.groupBySubmatch(match.games),
function(games) return StarcraftMatchGroupUtil.constructSubmatch(games, match) end
)
-
- -- Extract submatch headers from extradata
- for _, submatch in pairs(match.submatches) do
- submatch.header = Table.extract(extradata, 'subGroup' .. submatch.subgroup .. 'header')
- end
end
-- Add vetoes
@@ -195,89 +190,56 @@ end
---@param match StarcraftMatchGroupUtilMatch
---@return StarcraftMatchGroupUtilSubmatch
function StarcraftMatchGroupUtil.constructSubmatch(games, match)
- local opponents = Table.deepCopy(games[1].opponents)
-
- -- If the same faction was played in all games, display that instead of the
- -- player's faction listed in the match.
- for opponentIndex, opponent in pairs(opponents) do
- -- Aggregate factions among games for each player
- local playerFactions = {}
- for _, game in pairs(games) do
- for playerIndex, player in pairs(game.opponents[opponentIndex].players) do
- if not playerFactions[playerIndex] then
- playerFactions[playerIndex] = {}
- end
- playerFactions[playerIndex][player.faction] = true
- end
- end
+ local firstGame = games[1]
+ local opponents = Table.deepCopy(firstGame.opponents)
+ local isSubmatch = String.startsWith(firstGame.map, 'Submatch')
+ if isSubmatch then
+ games = {firstGame}
+ end
- for playerIndex, player in pairs(opponent.players) do
- player.faction = Table.uniqueKey(playerFactions[playerIndex])
+ ---@param opponent table
+ ---@param opponentIndex integer
+ local getOpponentScoreAndStatus = function(opponent, opponentIndex)
+ local statuses = Array.unique(Array.map(games, function(game)
+ return game.opponents[opponentIndex].status
+ end))
+ opponent.status = #statuses == 1 and statuses[1] ~= SCORE_STATUS and statuses[1] or SCORE_STATUS
+ opponent.score = isSubmatch and opponent.score or Array.reduce(Array.map(games, function(game)
+ return (game.winner == opponentIndex and 1 or 0)
+ end), Operator.add)
+
+ Array.forEach(opponent.players, function(player, playerIndex)
+ local playerFactions = {}
+ Array.forEach(games, function(game)
+ local gamePlayer = game.opponents[opponentIndex].players[playerIndex] or {}
+ if not gamePlayer.faction then return end
+ playerFactions[gamePlayer.faction] = true
+ end)
+ player.faction = Table.uniqueKey(playerFactions)
if not player.faction then
local matchPlayer = match.opponents[opponentIndex].players[player.matchPlayerIndex]
player.faction = matchPlayer and matchPlayer.faction or Faction.defaultFaction
end
- end
+ end)
end
- -- Sum up scores
- local scores = {}
- for opponentIndex, _ in pairs(opponents) do
- scores[opponentIndex] = 0
- end
- for _, game in pairs(games) do
- if game.map and String.startsWith(game.map, 'Submatch') and not game.resultType then
- for opponentIndex, score in pairs(scores) do
- scores[opponentIndex] = score + (game.scores[opponentIndex] or 0)
- end
- elseif game.winner then
- scores[game.winner] = (scores[game.winner] or 0) + 1
- end
- end
+ Array.forEach(opponents, getOpponentScoreAndStatus)
- -- Compute winner if all games have been played, skipped, or defaulted
- local allPlayed = Array.all(games, function(game)
- return game.winner ~= nil or game.resultType ~= nil
+ local allPlayed = Array.all(games, function (game)
+ return game.winner ~= nil or game.status == 'notplayed'
+ end)
+ local winner = allPlayed and MatchGroupInputUtil.getWinner('', nil, opponents) or nil
+ Array.forEach(opponents, function(opponent, opponentIndex)
+ opponent.placement = MatchGroupInputUtil.placementFromWinner('', winner, opponentIndex)
end)
-
- local resultType = nil
- local winner = nil
- if allPlayed then
- local diff = (scores[1] or 0) - (scores[2] or 0)
- if diff < 0 then
- winner = 2
- elseif diff == 0 then
- resultType = 'draw'
- else
- winner = 1
- end
- end
-
- -- Set resultType and walkover if every game is a walkover
- local walkovers = {}
- local resultTypes = {}
- for _, game in pairs(games) do
- resultTypes[game.resultType or ''] = true
- walkovers[game.walkover or ''] = true
- end
- local walkover
- local uniqueResult = Table.uniqueKey(resultTypes)
- if uniqueResult == 'default' then
- resultType = 'default'
- walkover = String.nilIfEmpty(Table.uniqueKey(walkovers)) or 'L'
- elseif uniqueResult == 'np' then
- resultType = 'np'
- end
return {
games = games,
- mode = games[1].mode,
+ mode = firstGame.mode,
opponents = opponents,
- resultType = resultType,
- scores = scores,
- subgroup = games[1].subgroup,
- walkover = walkover,
+ subgroup = firstGame.subgroup,
winner = winner,
+ header = Table.extract(match.extradata or {}, 'subgroup' .. firstGame.subgroup .. 'header'),
}
end
diff --git a/components/match2/commons/starcraft_starcraft2/match_summary_starcraft.lua b/components/match2/commons/starcraft_starcraft2/match_summary_starcraft.lua
index 1d9003123f7..99a9217132f 100644
--- a/components/match2/commons/starcraft_starcraft2/match_summary_starcraft.lua
+++ b/components/match2/commons/starcraft_starcraft2/match_summary_starcraft.lua
@@ -231,18 +231,9 @@ function StarcraftMatchSummary.TeamSubMatchOpponnetRow(submatch)
---@param opponentIndex any
---@return Html
local createScore = function(opponentIndex)
- local isWinner = opponentIndex == submatch.winner or submatch.resultType == 'draw'
- if submatch.resultType == 'default' then
- return OpponentDisplay.BlockScore{
- isWinner = isWinner,
- scoreText = isWinner and 'W' or string.upper(submatch.walkover),
- }
- end
-
- local score = submatch.resultType ~= 'np' and (submatch.scores or {})[opponentIndex] or nil
return OpponentDisplay.BlockScore{
- isWinner = isWinner,
- scoreText = score,
+ isWinner = opponentIndex == submatch.winner or submatch.winner == 0,
+ scoreText = DisplayHelper.MapScore(submatch.opponents[opponentIndex], submatch.status),
}
end
diff --git a/components/match2/commons/starcraft_starcraft2/match_summary_starcraft_ffa.lua b/components/match2/commons/starcraft_starcraft2/match_summary_starcraft_ffa.lua
index f446f463f53..e0a56425205 100644
--- a/components/match2/commons/starcraft_starcraft2/match_summary_starcraft_ffa.lua
+++ b/components/match2/commons/starcraft_starcraft2/match_summary_starcraft_ffa.lua
@@ -185,7 +185,7 @@ function StarcraftMatchSummaryFfa._opponents(match)
return Table.merge(opponent, {
placement = opponent.placement,
status = opponent.status or 'S',
- score = opponent.score or (game.scores or {})[opponentIdx],
+ score = opponent.score,
})
end)
end)
diff --git a/components/match2/wikis/ageofempires/match_legacy.lua b/components/match2/wikis/ageofempires/match_legacy.lua
index 2997af52d68..a13bcb40c8e 100644
--- a/components/match2/wikis/ageofempires/match_legacy.lua
+++ b/components/match2/wikis/ageofempires/match_legacy.lua
@@ -11,10 +11,12 @@ local MatchLegacy = {}
local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
local OpponentLibraries = require('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent
@@ -31,7 +33,6 @@ function MatchLegacy.storeGames(match, match2)
local games = {}
for gameIndex, game2 in ipairs(match2.match2games or {}) do
local game = Table.deepCopy(game2)
- local participants = Json.parseIfString(game2.participants) or {}
local opponents = Json.parseIfString(game2.opponents) or {}
-- Extradata
@@ -54,8 +55,8 @@ function MatchLegacy.storeGames(match, match2)
end
end)
elseif game.mode == '1v1' then
- local player1 = participants['1_1'] or {}
- local player2 = participants['2_1'] or {}
+ local player1 = (opponents[1].players or {})[1] or {}
+ local player2 = (opponents[2].players or {})[1] or {}
game.extradata.opponent1civ = player1.civ
game.extradata.opponent2civ = player2.civ
game.extradata.winnerciv =
@@ -75,7 +76,7 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
- local scores = Json.parseIfString(game2.scores) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
local res = mw.ext.LiquipediaDB.lpdb_game(
@@ -95,11 +96,12 @@ function MatchLegacy._convertParameters(match2)
end
end
- match.walkover = match.walkover and string.upper(match.walkover) or nil
- if match.walkover == 'FF' or match.walkover == 'DQ' then
- match.resulttype = match.walkover:lower()
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ match.walkover = walkover and string.upper(walkover) or nil
+ if walkover == 'FF' or walkover == 'DQ' then
+ match.resulttype = walkover:lower()
match.walkover = match.winner
- elseif match.walkover == 'L' then
+ elseif walkover == 'L' then
match.walkover = nil
end
diff --git a/components/match2/wikis/ageofempires/match_summary.lua b/components/match2/wikis/ageofempires/match_summary.lua
index 76fbf39810d..80f8a153e29 100644
--- a/components/match2/wikis/ageofempires/match_summary.lua
+++ b/components/match2/wikis/ageofempires/match_summary.lua
@@ -70,13 +70,11 @@ function CustomMatchSummary._isSolo(match)
end
---@param game MatchGroupUtilGame
----@param paricipantId string
+---@param opponentIndex integer
+---@param playerIndex integer
---@return {displayName: string?, pageName: string?, flag: string?, civ: string?}
-function CustomMatchSummary._getPlayerData(game, paricipantId)
- if not game or not game.participants then
- return {}
- end
- return game.participants[paricipantId] or {}
+function CustomMatchSummary._getPlayerData(game, opponentIndex, playerIndex)
+ return ((game.opponents[opponentIndex] or {}).players or {})[playerIndex]
end
---@param game MatchGroupUtilGame
@@ -97,8 +95,8 @@ function CustomMatchSummary._createGame(game, props)
local faction1, faction2
if props.soloMode then
- faction1 = CustomMatchSummary._createFactionIcon(CustomMatchSummary._getPlayerData(game, '1_1').civ, normGame)
- faction2 = CustomMatchSummary._createFactionIcon(CustomMatchSummary._getPlayerData(game, '2_1').civ, normGame)
+ faction1 = CustomMatchSummary._createFactionIcon(CustomMatchSummary._getPlayerData(game, 1, 1).civ, normGame)
+ faction2 = CustomMatchSummary._createFactionIcon(CustomMatchSummary._getPlayerData(game, 2, 1).civ, normGame)
else
local function createParticipant(player, flipped)
local playerNode = PlayerDisplay.BlockPlayer{player = player, flip = flipped}
diff --git a/components/match2/wikis/arenafps/match_legacy.lua b/components/match2/wikis/arenafps/match_legacy.lua
index 69d12fe000e..eee7e342692 100644
--- a/components/match2/wikis/arenafps/match_legacy.lua
+++ b/components/match2/wikis/arenafps/match_legacy.lua
@@ -10,9 +10,13 @@ local MatchLegacy = {}
local Array = require('Module:Array')
local Json = require('Module:Json')
+local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
---@param match2 table
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -37,7 +41,8 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = Json.parseIfString(game.scores) or {}
+ local opponents = Json.parseIfString(game.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
local res = mw.ext.LiquipediaDB.lpdb_game(
@@ -85,8 +90,9 @@ function MatchLegacy._convertParameters(match2)
handleOpponent(1)
handleOpponent(2)
- if match2.walkover then
- match.resulttype = match2.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover
match.walkover = nil
end
diff --git a/components/match2/wikis/artifact/match_legacy.lua b/components/match2/wikis/artifact/match_legacy.lua
index ce363269445..5e1c42cebb5 100644
--- a/components/match2/wikis/artifact/match_legacy.lua
+++ b/components/match2/wikis/artifact/match_legacy.lua
@@ -10,10 +10,13 @@ local MatchLegacy = {}
local Array = require('Module:Array')
local Json = require('Module:Json')
-local Logic = require('Module:Logic')
+local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
match.games = MatchLegacy.storeGames(match, match2)
@@ -33,8 +36,9 @@ function MatchLegacy._convertParameters(match2)
end
match.links = nil
- if Logic.isNotEmpty(match.walkover) then
- match.resulttype = match.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = match.walkover:lower()
match.walkover = match.winner
end
@@ -105,7 +109,7 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = Json.parseIfString(game2.scores) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
diff --git a/components/match2/wikis/battalion/match_legacy.lua b/components/match2/wikis/battalion/match_legacy.lua
index cb39edff13c..bdd90b4b52d 100644
--- a/components/match2/wikis/battalion/match_legacy.lua
+++ b/components/match2/wikis/battalion/match_legacy.lua
@@ -8,10 +8,15 @@
local MatchLegacy = {}
+local Array = require('Module:Array')
local Json = require('Module:Json')
+local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -33,7 +38,8 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = Json.parseIfString(game2.scores) or {}
+ local opponents = Json.parseIfString(game2.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
local res = mw.ext.LiquipediaDB.lpdb_game(
@@ -53,9 +59,10 @@ function MatchLegacy._convertParameters(match2)
end
end
- if match.walkover == 'ff' or match.walkover == 'dq' then
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover == 'FF' or walkover == 'DQ' then
match.walkover = match.winner
- elseif match.walkover == 'l' then
+ elseif match.walkover == 'L' then
match.walkover = nil
end
diff --git a/components/match2/wikis/brawlhalla/match_legacy.lua b/components/match2/wikis/brawlhalla/match_legacy.lua
index 9896954af65..6609f647f82 100644
--- a/components/match2/wikis/brawlhalla/match_legacy.lua
+++ b/components/match2/wikis/brawlhalla/match_legacy.lua
@@ -10,16 +10,17 @@ local MatchLegacy = {}
local Array = require('Module:Array')
local Json = require('Module:Json')
+local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Set = require('Module:Set')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
local OpponentLibraries = require('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent
-
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -34,11 +35,11 @@ function MatchLegacy._convertParameters(match2)
end
end
- match.walkover = match.walkover and string.upper(match.walkover) or nil
- if match.walkover == 'FF' or match.walkover == 'DQ' then
- match.resulttype = match.walkover:lower()
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover == 'FF' or walkover == 'DQ' then
+ match.resulttype = walkover:lower()
match.walkover = match.winner
- elseif match.walkover == 'L' then
+ elseif walkover == 'L' then
match.walkover = nil
end
@@ -57,13 +58,13 @@ function MatchLegacy._convertParameters(match2)
end
-- Handle Opponents
- local headList = function (participant)
+ local headList = function (opponentIndex, playerIndex)
local heads = Set{}
Array.forEach(match2.match2games or {}, function(game)
- local participants = Json.parseIfString(game.participants) or {}
- if participants[participant] then
- heads:add(participants[participant].char)
- end
+ local opponents = Json.parseIfString(game.opponents) or {}
+ local player = ((opponents[opponentIndex] or {}).players or {})[playerIndex]
+ if Logic.isDeepEmpty(player) then return end
+ heads:add(player.char)
end)
return heads:toArray()
end
@@ -78,7 +79,7 @@ function MatchLegacy._convertParameters(match2)
match[prefix .. 'score'] = (tonumber(opponent.score) or 0) > 0 and opponent.score or 0
match[prefix .. 'flag'] = player.flag
match.extradata[prefix .. 'displayname'] = player.displayname
- match.extradata[prefix .. 'heads'] = table.concat(headList(index .. '_1'), ',')
+ match.extradata[prefix .. 'heads'] = table.concat(headList(index, 1), ',')
if match2.winner == index then
match.winner = player.name
end
@@ -92,7 +93,7 @@ function MatchLegacy._convertParameters(match2)
match.extradata[teamPrefix .. playerPrefix] = player.name or ''
match.extradata[teamPrefix .. playerPrefix .. 'flag'] = player.flag or ''
match.extradata[teamPrefix .. playerPrefix .. 'displayname'] = player.displayname or ''
- match.extradata[teamPrefix .. playerPrefix .. 'heads'] = table.concat(headList(index .. '_' .. i), ',')
+ match.extradata[teamPrefix .. playerPrefix .. 'heads'] = table.concat(headList(index, i), ',')
end
match[prefix..'players'] = mw.ext.LiquipediaDB.lpdb_create_json(opponentPlayers)
match[prefix] = table.concat(Array.extractValues(opponentPlayers), '/')
diff --git a/components/match2/wikis/brawlstars/match_legacy.lua b/components/match2/wikis/brawlstars/match_legacy.lua
index f08f2e6256b..101be08cb5c 100644
--- a/components/match2/wikis/brawlstars/match_legacy.lua
+++ b/components/match2/wikis/brawlstars/match_legacy.lua
@@ -8,11 +8,14 @@
local MatchLegacy = {}
+local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
function MatchLegacy.storeMatch(match2)
@@ -40,10 +43,8 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = game2.scores or {}
- if type(scores) == 'string' then
- scores = Json.parse(scores)
- end
+ local opponents = Json.parseIfString(game2.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
local res = mw.ext.LiquipediaDB.lpdb_game(
@@ -63,11 +64,12 @@ function MatchLegacy._convertParameters(match2)
end
end
- if match.walkover == 'ff' or match.walkover == 'dq' then
- match.resulttype = match.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover == 'FF' or walkover == 'DQ' then
+ match.resulttype = walkover:lower()
match.walkover = match.winner
- elseif match.walkover == 'l' then
- match.resulttype = match.walkover
+ elseif walkover == 'L' then
+ match.resulttype = walkover:lower()
match.walkover = nil
end
diff --git a/components/match2/wikis/callofduty/match_legacy.lua b/components/match2/wikis/callofduty/match_legacy.lua
index 023ad2515bc..6a818e34550 100644
--- a/components/match2/wikis/callofduty/match_legacy.lua
+++ b/components/match2/wikis/callofduty/match_legacy.lua
@@ -8,12 +8,15 @@
local MatchLegacy = {}
+local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -39,10 +42,8 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = game2.scores or {}
- if type(scores) == 'string' then
- scores = Json.parse(scores)
- end
+ local opponents = Json.parseIfString(game2.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
local res = mw.ext.LiquipediaDB.lpdb_game(
@@ -62,9 +63,10 @@ function MatchLegacy._convertParameters(match2)
end
end
- if match.walkover == 'ff' or match.walkover == 'dq' then
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover == 'FF' or walkover == 'DQ' then
match.walkover = match.winner
- elseif match.walkover == 'l' then
+ elseif walkover == 'L' then
match.walkover = nil
end
diff --git a/components/match2/wikis/clashofclans/match_summary.lua b/components/match2/wikis/clashofclans/match_summary.lua
index 09a29e10bc9..febae2d69cb 100644
--- a/components/match2/wikis/clashofclans/match_summary.lua
+++ b/components/match2/wikis/clashofclans/match_summary.lua
@@ -7,7 +7,9 @@
--
local Abbreviation = require('Module:Abbreviation')
+local Array = require('Module:Array')
local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local Table = require('Module:Table')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
@@ -33,8 +35,9 @@ function CustomMatchSummary.createHeader(match)
if match.bestof == 1 and match.games and match.games[1] and
not match.opponents[1].placement2 and not match.opponents[2].placement2 then
- opponentLeft = Table.merge(match.opponents[1], {score = (match.games[1].scores or {})[1] or 0})
- opponentRight = Table.merge(match.opponents[2], {score = (match.games[1].scores or {})[2] or 0})
+ local scores = Array.map(match.games[1].opponents, Operator.property('score'))
+ opponentLeft = Table.merge(match.opponents[1], {score = scores[1] or 0})
+ opponentRight = Table.merge(match.opponents[2], {score = scores[2] or 0})
end
@@ -79,7 +82,8 @@ end
---@param gameIndex integer
---@return Widget?
function CustomMatchSummary.createGame(date, game, gameIndex)
- if Table.isEmpty(game.scores) then
+ local scores = Array.map(game.opponents, Operator.property('score'))
+ if Table.isEmpty(scores) then
return
end
diff --git a/components/match2/wikis/clashroyale/match_summary.lua b/components/match2/wikis/clashroyale/match_summary.lua
index 1320758bd71..5f2e837ece4 100644
--- a/components/match2/wikis/clashroyale/match_summary.lua
+++ b/components/match2/wikis/clashroyale/match_summary.lua
@@ -14,7 +14,6 @@ local FnUtil = require('Module:FnUtil')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Operator = require('Module:Operator')
-local Table = require('Module:Table')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')
@@ -66,16 +65,14 @@ end
---@param date string
---@return Widget
function CustomMatchSummary._createGame(game, gameIndex, date)
- local cardData = {{}, {}}
- for participantKey, participantData in Table.iter.spairs(game.participants or {}) do
- local opponentIndex = tonumber(mw.text.split(participantKey, '_')[1])
- participantData.cards = participantData.cards or {}
- ---@type table
- local cards = Array.map(Array.range(1, NUM_CARDS_PER_PLAYER), function(idx)
- return participantData.cards[idx] or DEFAULT_CARD end)
- cards.tower = participantData.cards.tower
- table.insert(cardData[opponentIndex], cards)
- end
+ local cardData = Array.map(game.opponents, function(opponent)
+ return Array.map(opponent.players, function(player)
+ if Logic.isDeepEmpty(player) then return end
+ local cards = player.cards or {}
+ return Array.map(Array.range(1, NUM_CARDS_PER_PLAYER), function(idx)
+ return cards[idx] or DEFAULT_CARD end)
+ end)
+ end)
return MatchSummaryWidgets.Row{
classes = {'brkts-popup-body-game'},
@@ -173,28 +170,15 @@ end
---@param match MatchGroupUtilMatch
---@return table
function CustomMatchSummary._extractPlayersFromGame(players, game, match)
- for participantKey, participant in Table.iter.spairs(game.participants or {}) do
- participantKey = mw.text.split(participantKey, '_')
- local opponentIndex = tonumber(participantKey[1])
- local match2playerIndex = tonumber(participantKey[2])
-
- local player = match.opponents[opponentIndex].players[match2playerIndex]
-
- if not player then
- player = {
- displayName = participant.displayname,
- pageName = participant.name,
+ return Array.map(game.opponents, function(opponent, opponentIndex)
+ return Array.map(opponent.players, function(player, playerIndex)
+ local matchPlayer = match.opponents[opponentIndex].players[playerIndex]
+ return matchPlayer or {
+ displayName = player.displayname,
+ pageName = player.name,
}
- end
-
- -- make sure we only display each player once
- if not players.hash[opponentIndex][player.pageName] then
- players.hash[opponentIndex][player.pageName] = true
- table.insert(players[opponentIndex], player)
- end
- end
-
- return players
+ end)
+ end)
end
---@param players table
diff --git a/components/match2/wikis/counterstrike/match_legacy.lua b/components/match2/wikis/counterstrike/match_legacy.lua
index f16c4581e06..e176af4b620 100644
--- a/components/match2/wikis/counterstrike/match_legacy.lua
+++ b/components/match2/wikis/counterstrike/match_legacy.lua
@@ -6,14 +6,16 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
+local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
local Logic = require('Module:Logic')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local TextSanitizer = require('Module:TextSanitizer')
-
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
local Opponent = Lua.import('Module:Opponent')
local DRAW = 'draw'
@@ -40,13 +42,14 @@ function MatchLegacy.convertParameters(match2)
end
end
- if match.resulttype == DRAW then
+ if match.winner == 0 then
match.winner = 'draw'
end
match.resulttype = nil
- if match.walkover == 'ff' or match.walkover == 'dq' then
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover == 'FF' or walkover == 'DQ' then
match.walkover = match.winner
else
match.walkover = nil
@@ -86,10 +89,8 @@ function MatchLegacy.convertParameters(match2)
local opponent1Rounds, opponent2Rounds = 0, 0
local maps = {}
for gameIndex, game in ipairs(match2.match2games or {}) do
- local scores = game.scores or {}
- if type(scores) == 'string' then
- scores = Json.parse(game.scores)
- end
+ local opponents = Json.parseIfString(game.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
opponent1Rounds = opponent1Rounds + (tonumber(scores[1] or '') or 0)
opponent2Rounds = opponent2Rounds + (tonumber(scores[2] or '') or 0)
match.extradata['vodgame' .. gameIndex] = game.vod
@@ -178,6 +179,8 @@ function MatchLegacy.storeGames(match, match2)
local game = Table.deepCopy(game2)
-- Extradata
local extradata = Json.parseIfString(game2.extradata)
+ local opponents = Json.parseIfString(game2.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.extradata = {}
local opponent1scores, opponent2scores = {}, {}
@@ -206,14 +209,14 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = game2.scores or {}
if type(scores) == 'string' then
scores = Json.parse(scores)
end
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
- if game2.walkover == 'ff' or game2.walkover == 'dq' then
+ local walkover = MatchOpponentHelper.calculateWalkoverType(opponents)
+ if walkover == 'FF' or walkover == 'DQ' then
game.walkover = 1
end
diff --git a/components/match2/wikis/counterstrike/match_summary.lua b/components/match2/wikis/counterstrike/match_summary.lua
index 8e7d60df263..e37c99771f1 100644
--- a/components/match2/wikis/counterstrike/match_summary.lua
+++ b/components/match2/wikis/counterstrike/match_summary.lua
@@ -221,7 +221,7 @@ function CustomMatchSummary._createMap(game)
local mapInfo = {
mapDisplayName = game.map,
map = game.game and (game.map .. '/' .. game.game) or game.map,
- resultType = game.resultType,
+ status = game.status,
}
return MatchSummaryWidgets.Row{
diff --git a/components/match2/wikis/criticalops/match_legacy.lua b/components/match2/wikis/criticalops/match_legacy.lua
index f729e26ebf4..eed4f4fb5f9 100644
--- a/components/match2/wikis/criticalops/match_legacy.lua
+++ b/components/match2/wikis/criticalops/match_legacy.lua
@@ -6,13 +6,16 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
+local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
local Logic = require('Module:Logic')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local TextSanitizer = require('Module:TextSanitizer')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
local Opponent = Lua.import('Module:Opponent')
local DRAW = 'draw'
@@ -39,13 +42,14 @@ function MatchLegacy.convertParameters(match2)
end
end
- if match.resulttype == DRAW then
+ if match.winner == 0 then
match.winner = 'draw'
end
match.resulttype = nil
- if match.walkover == 'ff' or match.walkover == 'dq' then
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover == 'FF' or walkover == 'DQ' then
match.walkover = match.winner
else
match.walkover = nil
@@ -85,10 +89,8 @@ function MatchLegacy.convertParameters(match2)
local opponent1Rounds, opponent2Rounds = 0, 0
local maps = {}
for gameIndex, game in ipairs(match2.match2games or {}) do
- local scores = game.scores or {}
- if type(scores) == 'string' then
- scores = Json.parse(game.scores)
- end
+ local opponents = Json.parseIfString(game.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
opponent1Rounds = opponent1Rounds + (tonumber(scores[1] or '') or 0)
opponent2Rounds = opponent2Rounds + (tonumber(scores[2] or '') or 0)
match.extradata['vodgame' .. gameIndex] = game.vod
@@ -172,6 +174,8 @@ function MatchLegacy.storeGames(match, match2)
local game = Table.deepCopy(game2)
-- Extradata
local extradata = Json.parseIfString(game2.extradata)
+ local opponents = Json.parseIfString(game2.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.extradata = {}
local opponent1scores, opponent2scores = {}, {}
@@ -200,14 +204,14 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = game2.scores or {}
if type(scores) == 'string' then
scores = Json.parse(scores)
end
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
- if game2.walkover == 'ff' or game2.walkover == 'dq' then
+ local walkover = MatchOpponentHelper.calculateWalkoverType(opponents)
+ if walkover == 'FF' or walkover == 'DQ' then
game.walkover = 1
end
diff --git a/components/match2/wikis/crossfire/match_legacy.lua b/components/match2/wikis/crossfire/match_legacy.lua
index 63440ac4e50..73a385869f4 100644
--- a/components/match2/wikis/crossfire/match_legacy.lua
+++ b/components/match2/wikis/crossfire/match_legacy.lua
@@ -8,12 +8,15 @@
local MatchLegacy = {}
+local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -39,10 +42,8 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = game2.scores or {}
- if type(scores) == 'string' then
- scores = Json.parse(scores)
- end
+ local opponents = Json.parseIfString(game2.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
local res = mw.ext.LiquipediaDB.lpdb_game(
@@ -62,9 +63,10 @@ function MatchLegacy._convertParameters(match2)
end
end
- if match.walkover == 'ff' or match.walkover == 'dq' then
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover == 'FF' or walkover == 'DQ' then
match.walkover = match.winner
- elseif match.walkover == 'l' then
+ elseif walkover == 'L' then
match.walkover = nil
end
diff --git a/components/match2/wikis/deadlock/match_summary.lua b/components/match2/wikis/deadlock/match_summary.lua
index 25f733d351e..7819555e2b3 100644
--- a/components/match2/wikis/deadlock/match_summary.lua
+++ b/components/match2/wikis/deadlock/match_summary.lua
@@ -11,7 +11,7 @@ local DateExt = require('Module:Date/Ext')
local Icon = require('Module:Icon')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
-local Table = require('Module:Table')
+local Operator = require('Module:Operator')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
local MatchSummary = Lua.import('Module:MatchSummary/Base')
@@ -45,15 +45,10 @@ function CustomMatchSummary.createBody(match)
)}
end
----@param participants table
----@param opponentIndex integer
+---@param players table[]
---@return table
-function CustomMatchSummary._getHeroesForOpponent(participants, opponentIndex)
- local characters = {}
- for _, participant in Table.iter.pairsByPrefix(participants, opponentIndex .. '_') do
- table.insert(characters, participant.character)
- end
- return characters
+function CustomMatchSummary._getHeroesForOpponent(players)
+ return Array.map(players or {}, Operator.property('character'))
end
---@param game MatchGroupUtilGame
@@ -68,14 +63,14 @@ function CustomMatchSummary._createGame(game, gameIndex)
children = WidgetUtil.collect(
CustomMatchSummary._createIcon(ICONS[extradata.team1side]),
MatchSummaryWidgets.Characters{
- characters = CustomMatchSummary._getHeroesForOpponent(game.participants, 1),
+ characters = CustomMatchSummary._getHeroesForOpponent(game.opponents[1].players),
flipped = false,
},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1},
MatchSummaryWidgets.GameCenter{children = Logic.nilIfEmpty(game.length) or ('Game ' .. gameIndex)},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2},
MatchSummaryWidgets.Characters{
- characters = CustomMatchSummary._getHeroesForOpponent(game.participants, 2),
+ characters = CustomMatchSummary._getHeroesForOpponent(game.opponents[2].players),
flipped = true,
},
CustomMatchSummary._createIcon(ICONS[extradata.team2side]),
diff --git a/components/match2/wikis/dota2/match_group_input_custom.lua b/components/match2/wikis/dota2/match_group_input_custom.lua
index 5fab22b2f74..c0b55b16f60 100644
--- a/components/match2/wikis/dota2/match_group_input_custom.lua
+++ b/components/match2/wikis/dota2/match_group_input_custom.lua
@@ -236,7 +236,7 @@ function MapFunctions.getPlayersOfMapOpponent(MapParser, map, opponent, opponent
local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, HeroNames)
local participantList = MapParser.getParticipants(map, opponentIndex) or {}
- local participants, unattachedParticipants = MatchGroupInputUtil.parseParticipants(
+ return MatchGroupInputUtil.parseMapPlayers(
opponent.match2players,
participantList,
function (playerIndex)
@@ -249,10 +249,6 @@ function MapFunctions.getPlayersOfMapOpponent(MapParser, map, opponent, opponent
return participant
end
)
- Array.forEach(unattachedParticipants, function(participant)
- table.insert(participants, participant)
- end)
- return participants
end
---@param winnerInput string|integer|nil
diff --git a/components/match2/wikis/dota2/match_legacy.lua b/components/match2/wikis/dota2/match_legacy.lua
index 6418bd9fec4..7fe1caf0a8c 100644
--- a/components/match2/wikis/dota2/match_legacy.lua
+++ b/components/match2/wikis/dota2/match_legacy.lua
@@ -9,12 +9,12 @@
local MatchLegacy = {}
local Json = require('Module:Json')
-local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
local _NUMBER_OF_PLAYERS_TO_STORE = 10
@@ -38,8 +38,9 @@ function MatchLegacy._convertParameters(match2)
end
match.links = nil
- if Logic.isNotEmpty(match.walkover) then
- match.resulttype = match.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover:lower()
match.walkover = match.winner
end
diff --git a/components/match2/wikis/dota2/match_page.lua b/components/match2/wikis/dota2/match_page.lua
index 8d99e652ab1..ab1f279eefb 100644
--- a/components/match2/wikis/dota2/match_page.lua
+++ b/components/match2/wikis/dota2/match_page.lua
@@ -25,7 +25,7 @@ local Display = Lua.import('Module:MatchPage/Template')
local MatchPage = {}
local NO_CHARACTER = 'default'
-local NOT_PLAYED = 'np'
+local NOT_PLAYED = 'notplayed'
local AVAILABLE_FOR_TIERS = {1}
local MATCH_PAGE_START_TIME = 1725148800 -- September 1st 2024 midnight
@@ -75,12 +75,11 @@ function MatchPage.getByMatchId(props)
Array.forEach(viewModel.games, function(game)
game.finished = game.winner ~= nil and game.winner ~= -1
game.teams = Array.map(Array.range(1, 2), function(teamIdx)
- local team = {players = {}}
+ local team = {}
team.scoreDisplay = game.winner == teamIdx and 'winner' or game.finished and 'loser' or '-'
team.side = String.nilIfEmpty(game.extradata['team' .. teamIdx ..'side'])
-
- for _, player in Table.iter.pairsByPrefix(game.participants, teamIdx .. '_') do
+ team.players = Array.map(game.opponents[teamIdx].players or {}, function(player)
local newPlayer = Table.mergeInto(player, {
displayName = player.name or player.player,
link = player.player,
@@ -92,8 +91,8 @@ function MatchPage.getByMatchId(props)
newPlayer.displayDamageDone = MatchPage._abbreviateNumber(player.damagedone)
newPlayer.displayGold = MatchPage._abbreviateNumber(player.gold)
- table.insert(team.players, newPlayer)
- end
+ return newPlayer
+ end)
if game.finished then
-- Aggregate stats
@@ -237,7 +236,7 @@ end
---@return string
function MatchPage.games(model)
local games = Array.map(Array.filter(model.games, function(game)
- return game.resultType ~= NOT_PLAYED
+ return game.status ~= NOT_PLAYED
end), function(game)
return TemplateEngine():render(Display.game, Table.merge(model, game))
end)
diff --git a/components/match2/wikis/easportsfc/match_group_input_custom.lua b/components/match2/wikis/easportsfc/match_group_input_custom.lua
index d111ddb6a72..ae07da502b4 100644
--- a/components/match2/wikis/easportsfc/match_group_input_custom.lua
+++ b/components/match2/wikis/easportsfc/match_group_input_custom.lua
@@ -38,12 +38,13 @@ function CustomMatchGroupInput.processMatch(match, options)
return MatchGroupInputUtil.computeMatchScoreFromMapWinners(maps, opponentIndex)
elseif calculateBy == 'mapScores' then
return Array.reduce(Array.map(maps, function(map)
- return map.scores[opponentIndex] or 0
+ local scores = Array.map(map.opponents, Operator.property('score'))
+ return scores[opponentIndex] or 0
end), Operator.add, 0)
elseif calculateBy == 'penalties' then
- return Array.filter(maps, function(map)
+ return (Array.filter(maps, function(map)
return Logic.readBool(map.penalty)
- end)[1].scores[opponentIndex]
+ end)[1].opponents[opponentIndex] or {}).score
else
error('Unknown calculateBy: ' .. tostring(calculateBy))
end
diff --git a/components/match2/wikis/easportsfc/match_legacy.lua b/components/match2/wikis/easportsfc/match_legacy.lua
index 71df3e7c294..bdf67e19eaf 100644
--- a/components/match2/wikis/easportsfc/match_legacy.lua
+++ b/components/match2/wikis/easportsfc/match_legacy.lua
@@ -9,10 +9,13 @@
local MatchLegacy = {}
local Json = require('Module:Json')
+local Lua = require('Module:Lua')
local Opponent = require('Module:Opponent')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
function MatchLegacy.storeMatch(match2)
return MatchLegacy.convertParameters(match2)
end
@@ -52,8 +55,9 @@ function MatchLegacy.convertParameters(match2)
handleOpponent(1)
handleOpponent(2)
- if match.resulttype == 'default' then
- match.resulttype = string.upper(match.walkover or '')
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover
match.walkover = match.winner
end
diff --git a/components/match2/wikis/easportsfc/match_summary.lua b/components/match2/wikis/easportsfc/match_summary.lua
index 231d65e8487..0fd269c2047 100644
--- a/components/match2/wikis/easportsfc/match_summary.lua
+++ b/components/match2/wikis/easportsfc/match_summary.lua
@@ -11,7 +11,6 @@ local Array = require('Module:Array')
local DateExt = require('Module:Date/Ext')
local Logic = require('Module:Logic')
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')
@@ -93,26 +92,15 @@ end
---@param match MatchGroupUtilMatch
---@return table[][]
function CustomMatchSummary._extractPlayersFromGame(game, match)
- local players = {{}, {}}
-
- for participantKey, participant in Table.iter.spairs(game.participants or {}) do
- participantKey = mw.text.split(participantKey, '_')
- local opponentIndex = tonumber(participantKey[1])
- local match2playerIndex = tonumber(participantKey[2])
-
- local player = match.opponents[opponentIndex].players[match2playerIndex]
-
- if not player then
- player = {
- displayName = participant.displayname,
- pageName = participant.name,
+ return Array.map(game.opponents, function(opponent, opponentIndex)
+ return Array.map(opponent.players, function(player, playerIndex)
+ local matchPlayer = match.opponents[opponentIndex].players[playerIndex]
+ return matchPlayer or {
+ displayName = player.displayname,
+ pageName = player.name,
}
- end
-
- table.insert(players[opponentIndex], player)
- end
-
- return players
+ end)
+ end)
end
---@param score number|string|nil
diff --git a/components/match2/wikis/fighters/match_legacy.lua b/components/match2/wikis/fighters/match_legacy.lua
index b1fcf65119e..5dca29ac210 100644
--- a/components/match2/wikis/fighters/match_legacy.lua
+++ b/components/match2/wikis/fighters/match_legacy.lua
@@ -11,6 +11,7 @@ local MatchLegacy = {}
local Array = require('Module:Array')
local FnUtil = require('Module:FnUtil')
local Json = require('Module:Json')
+local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Operator = require('Module:Operator')
local Set = require('Module:Set')
@@ -18,6 +19,7 @@ local String = require('Module:StringUtils')
local Table = require('Module:Table')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
local OpponentLibraries = require('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent
@@ -32,14 +34,14 @@ end
function MatchLegacy._storeGames(match, match2)
local games = Array.map(match2.match2games or {}, function(game2, gameIndex)
local game = Table.deepCopy(game2)
- local participants = Json.parseIfString(game2.participants) or {}
-- Extradata
game.extradata = {}
if game.mode == 'singles' then
- local player1 = participants['1_1'] or {}
- local player2 = participants['2_1'] or {}
+ local opponents = Json.parseIfString(game2.opponents) or {}
+ local player1 = opponents[1].players[1] or {}
+ local player2 = opponents[2].players[1] or {}
game.extradata.char1 = table.concat(Array.map(player1.characters or {}, Operator.property('name')), ',')
game.extradata.char2 = table.concat(Array.map(player2.characters or {}, Operator.property('name')), ',')
end
@@ -57,7 +59,8 @@ function MatchLegacy._storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
- local scores = Json.parseIfString(game2.scores) or {}
+ local opponents = Json.parseIfString(game2.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
return mw.ext.LiquipediaDB.lpdb_game(
@@ -74,7 +77,7 @@ function MatchLegacy._convertParameters(match2)
return not String.startsWith(key, 'match2')
end)
- match.walkover = match.walkover and string.upper(match.walkover) or nil
+ match.walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
if match.walkover == 'FF' or match.walkover == 'DQ' then
match.resulttype = match.walkover:lower()
match.walkover = match.winner
@@ -100,13 +103,14 @@ function MatchLegacy._convertParameters(match2)
end
-- Handle Opponents
- local headList = function(participant)
+ local headList = function(opponentIndex, playerIndex)
local heads = Set{}
Array.forEach(match2.match2games or {}, function(game)
- local participants = Json.parseIfString(game.participants) or {}
- if participants[participant] and participants[participant].characters then
+ local opponents = Json.parseIfString(game.opponents) or {}
+ local player = (opponents[opponentIndex].players or {})[playerIndex]
+ if player and Logic.isNotEmpty(player.characters) then
Array.forEach(
- Array.map(participants[participant].characters, Operator.property('name')),
+ Array.map(player.characters, Operator.property('name')),
FnUtil.curry(heads.add, heads)
)
end
@@ -124,7 +128,7 @@ function MatchLegacy._convertParameters(match2)
match[prefix .. 'score'] = (tonumber(opponent.score) or 0) > 0 and opponent.score or 0
match[prefix .. 'flag'] = player.flag
match.extradata[prefix .. 'displayname'] = player.displayname
- match.extradata[prefix .. 'heads'] = table.concat(headList(index .. '_1'), ',')
+ match.extradata[prefix .. 'heads'] = table.concat(headList(index, 1), ',')
if match2.winner == index then
match.winner = player.name
end
@@ -138,7 +142,7 @@ function MatchLegacy._convertParameters(match2)
match.extradata[teamPrefix .. playerPrefix] = player.name or ''
match.extradata[teamPrefix .. playerPrefix .. 'flag'] = player.flag or ''
match.extradata[teamPrefix .. playerPrefix .. 'displayname'] = player.displayname or ''
- match.extradata[teamPrefix .. playerPrefix .. 'heads'] = table.concat(headList(index .. '_' .. i), ',')
+ match.extradata[teamPrefix .. playerPrefix .. 'heads'] = table.concat(headList(index, i), ',')
end
match[prefix .. 'players'] = mw.ext.LiquipediaDB.lpdb_create_json(opponentPlayers)
match[prefix] = table.concat(Array.extractValues(opponentPlayers), '/')
@@ -155,7 +159,7 @@ function MatchLegacy._convertParameters(match2)
match.extradata[teamPrefix .. playerPrefix] = player.name or ''
match.extradata[teamPrefix .. playerPrefix .. 'flag'] = player.flag or ''
match.extradata[teamPrefix .. playerPrefix .. 'displayname'] = player.displayname or ''
- match.extradata[teamPrefix .. playerPrefix .. 'heads'] = table.concat(headList(index .. '_' .. i), ',')
+ match.extradata[teamPrefix .. playerPrefix .. 'heads'] = table.concat(headList(index, i), ',')
end
match[prefix .. 'players'] = mw.ext.LiquipediaDB.lpdb_create_json(opponentPlayers)
match[prefix] = opponent.name
diff --git a/components/match2/wikis/fighters/match_summary.lua b/components/match2/wikis/fighters/match_summary.lua
index cdc411915ec..5d13ad75807 100644
--- a/components/match2/wikis/fighters/match_summary.lua
+++ b/components/match2/wikis/fighters/match_summary.lua
@@ -84,11 +84,13 @@ end
---@param props {game: string?, soloMode: boolean, opponents: table[]}
---@return Widget?
function CustomMatchSummary._createStandardGame(game, props)
- if not game or not game.participants then
+ if not game or Array.all(game.opponents, function(opponent) return Logic.isDeepEmpty(opponent.players) end) then
return
end
- local scoreDisplay = (game.scores[1] or '') .. ' - ' .. (game.scores[2] or '')
+ local scores = Array.map(game.opponents, Operator.property('score'))
+
+ local scoreDisplay = table.concat(scores, ' - ')
return MatchSummaryWidgets.Row{
classes = {'brkts-popup-body-game'},
diff --git a/components/match2/wikis/halo/match_legacy.lua b/components/match2/wikis/halo/match_legacy.lua
index 4e4a3a878ef..e9963dc6c5b 100644
--- a/components/match2/wikis/halo/match_legacy.lua
+++ b/components/match2/wikis/halo/match_legacy.lua
@@ -8,10 +8,15 @@
local MatchLegacy = {}
+local Array = require('Module:Array')
local Json = require('Module:Json')
+local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
local MAX_NUM_PLAYERS = 10
function MatchLegacy.storeMatch(match2)
@@ -34,10 +39,8 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = game.scores or {}
- if type(scores) == 'string' then
- scores = Json.parse(scores)
- end
+ local opponents = Json.parseIfString(game.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
local res = mw.ext.LiquipediaDB.lpdb_game(
@@ -88,8 +91,9 @@ function MatchLegacy._convertParameters(match2)
handleOpponent(1)
handleOpponent(2)
- if match2.walkover then
- match.resulttype = match2.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover:lower()
match.walkover = nil
end
diff --git a/components/match2/wikis/hearthstone/match_legacy.lua b/components/match2/wikis/hearthstone/match_legacy.lua
index 63021e1f3fc..ad7350c8c16 100644
--- a/components/match2/wikis/hearthstone/match_legacy.lua
+++ b/components/match2/wikis/hearthstone/match_legacy.lua
@@ -10,11 +10,13 @@ local MatchLegacy = {}
local Array = require('Module:Array')
local Json = require('Module:Json')
-local Logic = require('Module:Logic')
+local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local Opponent = require('Module:Opponent')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -31,8 +33,9 @@ function MatchLegacy._convertParameters(match2)
local match = Table.filterByKey(Table.deepCopy(match2), function(key) return not String.startsWith(key, 'match2') end)
match.links = nil
- if Logic.isNotEmpty(match.walkover) then
- match.resulttype = match.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover:lower()
match.walkover = match.winner
end
diff --git a/components/match2/wikis/heroes/legacy/match_maps_legacy.lua b/components/match2/wikis/heroes/legacy/match_maps_legacy.lua
index f3e90599c58..b1b07dc9083 100644
--- a/components/match2/wikis/heroes/legacy/match_maps_legacy.lua
+++ b/components/match2/wikis/heroes/legacy/match_maps_legacy.lua
@@ -32,6 +32,7 @@ local MatchMapsLegacy = {}
-- invoked by Template:MatchMapsLua
---@param frame Frame
+---@return string
function MatchMapsLegacy.convertMap(frame)
local args = Arguments.getArgs(frame)
args.map = Table.extract(args, 'battleground') or UNKNOWN_MAP
diff --git a/components/match2/wikis/heroes/match_legacy.lua b/components/match2/wikis/heroes/match_legacy.lua
index 4113c67e32a..724871ad5a5 100644
--- a/components/match2/wikis/heroes/match_legacy.lua
+++ b/components/match2/wikis/heroes/match_legacy.lua
@@ -9,11 +9,13 @@
local MatchLegacy = {}
local Json = require('Module:Json')
-local Logic = require('Module:Logic')
+local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local Opponent = require('Module:Opponent')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
local _GAME_EXTRADATA_CONVERTER = {
ban = 'b',
champion = 'h',
@@ -39,8 +41,9 @@ function MatchLegacy._convertParameters(match2)
end
match.links = nil
- if Logic.isNotEmpty(match.walkover) then
- match.resulttype = match.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover:lower()
match.walkover = match.winner
end
diff --git a/components/match2/wikis/honorofkings/match_legacy.lua b/components/match2/wikis/honorofkings/match_legacy.lua
index eb56df53f3d..2f15b98561d 100644
--- a/components/match2/wikis/honorofkings/match_legacy.lua
+++ b/components/match2/wikis/honorofkings/match_legacy.lua
@@ -9,10 +9,12 @@
local MatchLegacy = {}
local Json = require('Module:Json')
-local Logic = require('Module:Logic')
+local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
local _GAME_EXTRADATA_CONVERTER = {
ban = 'b',
champion = 'h',
@@ -37,8 +39,9 @@ function MatchLegacy._convertParameters(match2)
end
match.links = nil
- if Logic.isNotEmpty(match.walkover) then
- match.resulttype = match.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover:lower()
match.walkover = match.winner
end
diff --git a/components/match2/wikis/leagueoflegends/match_group_input_custom.lua b/components/match2/wikis/leagueoflegends/match_group_input_custom.lua
index 3ae16244233..f4962982580 100644
--- a/components/match2/wikis/leagueoflegends/match_group_input_custom.lua
+++ b/components/match2/wikis/leagueoflegends/match_group_input_custom.lua
@@ -179,7 +179,7 @@ function MapFunctions.getPlayersOfMapOpponent(MapParser, map, opponent, opponent
local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, HeroNames)
local participantList = MapParser.getParticipants(map, opponentIndex) or {}
- local participants, unattachedParticipants = MatchGroupInputUtil.parseParticipants(
+ return MatchGroupInputUtil.parseMapPlayers(
opponent.match2players,
participantList,
function (playerIndex)
@@ -192,10 +192,6 @@ function MapFunctions.getPlayersOfMapOpponent(MapParser, map, opponent, opponent
return participant
end
)
- Array.forEach(unattachedParticipants, function(participant)
- table.insert(participants, participant)
- end)
- return participants
end
---@param winnerInput string|integer|nil
diff --git a/components/match2/wikis/leagueoflegends/match_legacy.lua b/components/match2/wikis/leagueoflegends/match_legacy.lua
index 10548f22fe8..62b61762261 100644
--- a/components/match2/wikis/leagueoflegends/match_legacy.lua
+++ b/components/match2/wikis/leagueoflegends/match_legacy.lua
@@ -9,12 +9,12 @@
local MatchLegacy = {}
local Json = require('Module:Json')
-local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
local _NUMBER_OF_PLAYERS_TO_STORE = 10
@@ -38,12 +38,13 @@ function MatchLegacy._convertParameters(match2)
end
match.links = nil
- if Logic.isNotEmpty(match.walkover) then
- match.resulttype = match.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover:lower()
match.walkover = match.winner
end
- if match.resulttype == 'draw' then
+ if match.winner == 0 then
match.resulttype = ''
match.winner = 'draw'
end
diff --git a/components/match2/wikis/leagueoflegends/match_page.lua b/components/match2/wikis/leagueoflegends/match_page.lua
index d6481ab6afb..78e5622087e 100644
--- a/components/match2/wikis/leagueoflegends/match_page.lua
+++ b/components/match2/wikis/leagueoflegends/match_page.lua
@@ -55,7 +55,7 @@ local KEYSTONES = Table.map({
end)
local NO_CHARACTER = 'default'
-local NOT_PLAYED = 'np'
+local NOT_PLAYED = 'notplayed'
local DEFAULT_ITEM = 'EmptyIcon'
local AVAILABLE_FOR_TIERS = {1, 2, 3}
local ITEMS_TO_SHOW = 6
@@ -216,7 +216,7 @@ end
---@return string
function MatchPage.games(model)
local games = Array.map(Array.filter(model.games, function(game)
- return game.resultType ~= NOT_PLAYED
+ return game.status ~= NOT_PLAYED
end), function(game)
return TemplateEngine():render(Display.game, Table.merge(model, game))
end)
diff --git a/components/match2/wikis/mobilelegends/match_legacy.lua b/components/match2/wikis/mobilelegends/match_legacy.lua
index a21184537f1..7b2052290e5 100644
--- a/components/match2/wikis/mobilelegends/match_legacy.lua
+++ b/components/match2/wikis/mobilelegends/match_legacy.lua
@@ -9,10 +9,12 @@
local MatchLegacy = {}
local Json = require('Module:Json')
-local Logic = require('Module:Logic')
+local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
local _GAME_EXTRADATA_CONVERTER = {
ban = 'b',
champion = 'h',
@@ -38,8 +40,9 @@ function MatchLegacy._convertParameters(match2)
end
match.links = nil
- if Logic.isNotEmpty(match.walkover) then
- match.resulttype = match.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover:lower()
match.walkover = match.winner
end
diff --git a/components/match2/wikis/omegastrikers/match_summary.lua b/components/match2/wikis/omegastrikers/match_summary.lua
index 5d78493db17..5b32a944514 100644
--- a/components/match2/wikis/omegastrikers/match_summary.lua
+++ b/components/match2/wikis/omegastrikers/match_summary.lua
@@ -41,7 +41,7 @@ function CustomMatchSummary.createBody(match)
end
function CustomMatchSummary._gameScore(game, opponentIndex)
- return mw.html.create('div'):wikitext(game.scores[opponentIndex])
+ return mw.html.create('div'):wikitext(game.opponents[opponentIndex].score)
end
function CustomMatchSummary._createMapRow(game)
diff --git a/components/match2/wikis/overwatch/match_legacy.lua b/components/match2/wikis/overwatch/match_legacy.lua
index f5e65707d43..2434243784d 100644
--- a/components/match2/wikis/overwatch/match_legacy.lua
+++ b/components/match2/wikis/overwatch/match_legacy.lua
@@ -8,12 +8,15 @@
local MatchLegacy = {}
+local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -39,10 +42,8 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = game2.scores or {}
- if type(scores) == 'string' then
- scores = Json.parse(scores)
- end
+ local opponents = Json.parseIfString(game2.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
local res = mw.ext.LiquipediaDB.lpdb_game(
@@ -62,6 +63,8 @@ function MatchLegacy._convertParameters(match2)
end
end
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ match.walkover = walkover and walkover:lower() or nil
if match.walkover == 'ff' or match.walkover == 'dq' then
match.walkover = match.winner
elseif match.walkover == 'l' then
diff --git a/components/match2/wikis/paladins/match_legacy.lua b/components/match2/wikis/paladins/match_legacy.lua
index caed4ff300b..ade98d77da7 100644
--- a/components/match2/wikis/paladins/match_legacy.lua
+++ b/components/match2/wikis/paladins/match_legacy.lua
@@ -10,10 +10,13 @@ local MatchLegacy = {}
local Array = require('Module:Array')
local Json = require('Module:Json')
-local Logic = require('Module:Logic')
+local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
match.games = MatchLegacy.storeGames(match, match2)
@@ -33,8 +36,9 @@ function MatchLegacy._convertParameters(match2)
end
match.links = nil
- if Logic.isNotEmpty(match.walkover) then
- match.resulttype = match.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover:lower()
match.walkover = match.winner
end
@@ -105,7 +109,7 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = Json.parseIfString(game2.scores) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
diff --git a/components/match2/wikis/pokemon/match_legacy.lua b/components/match2/wikis/pokemon/match_legacy.lua
index 10b96648dbb..2f91b90536c 100644
--- a/components/match2/wikis/pokemon/match_legacy.lua
+++ b/components/match2/wikis/pokemon/match_legacy.lua
@@ -9,10 +9,12 @@
local MatchLegacy = {}
local Json = require('Module:Json')
-local Logic = require('Module:Logic')
+local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
local _GAME_EXTRADATA_CONVERTER = {
ban = 'b',
champion = 'h',
@@ -38,8 +40,9 @@ function MatchLegacy._convertParameters(match2)
end
match.links = nil
- if Logic.isNotEmpty(match.walkover) then
- match.resulttype = match.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = match.walkover:lower()
match.walkover = match.winner
end
diff --git a/components/match2/wikis/pokemon/match_summary.lua b/components/match2/wikis/pokemon/match_summary.lua
index 883fca09808..f2c3aadb5d5 100644
--- a/components/match2/wikis/pokemon/match_summary.lua
+++ b/components/match2/wikis/pokemon/match_summary.lua
@@ -13,6 +13,7 @@ local DateExt = require('Module:Date/Ext')
local FnUtil = require('Module:FnUtil')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
local MatchSummary = Lua.import('Module:MatchSummary/Base')
@@ -55,13 +56,15 @@ function CustomMatchSummary._createGame(date, game, gameIndex)
MatchSummary.buildCharacterList(extradata, 'team2champion', NUM_CHAMPIONS_PICK),
}
- if Logic.isEmpty(game.scores) and Logic.isEmpty(game.winner) and Logic.isDeepEmpty(characterData) then
+ local scores = Array.map(game.opponents, Operator.property('score'))
+
+ if Logic.isEmpty(scores) and Logic.isEmpty(game.winner) and Logic.isDeepEmpty(characterData) then
return nil
end
local score
- if Logic.isNotEmpty(game.scores) then
- score = table.concat(game.scores, '-')
+ if Logic.isNotEmpty(scores) then
+ score = table.concat(scores, '-')
end
return MatchSummaryWidgets.Row{
diff --git a/components/match2/wikis/rainbowsix/match_legacy.lua b/components/match2/wikis/rainbowsix/match_legacy.lua
index 8a825fa3937..5ea27ad9d5f 100644
--- a/components/match2/wikis/rainbowsix/match_legacy.lua
+++ b/components/match2/wikis/rainbowsix/match_legacy.lua
@@ -8,12 +8,15 @@
local MatchLegacy = {}
+local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -32,6 +35,8 @@ function MatchLegacy.storeGames(match, match2)
local game = Table.deepCopy(game2)
-- Extradata
local extradata = Json.parseIfString(game2.extradata)
+ local opponents = Json.parseIfString(game2.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.extradata = {}
game.extradata.gamenumber = gameIndex
if extradata.t1bans and extradata.t2bans then
@@ -75,10 +80,6 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = game2.scores or {}
- if type(scores) == 'string' then
- scores = Json.parse(scores)
- end
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
local res = mw.ext.LiquipediaDB.lpdb_game(
@@ -98,6 +99,8 @@ function MatchLegacy._convertParameters(match2)
end
end
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ match.walkover = walkover and walkover:lower() or nil
if match.walkover == 'ff' or match.walkover == 'dq' then
match.walkover = match.winner
elseif match.walkover == 'l' then
@@ -142,10 +145,11 @@ function MatchLegacy._convertParameters(match2)
local opponentmatch2players = opponent.match2players or {}
if opponent.type == 'team' then
match[prefix] = mw.ext.TeamTemplate.teampage(opponent.template)
- if match2.bestof == 1 then
- if ((match2.match2games or {})[1] or {}).scores then
- match[prefix..'score'] = Json.parseIfString(match2.match2games[1].scores)[index]
- end
+ local firstGame = (match2.match2games or {})[1]
+ if match2.bestof == 1 and firstGame then
+ local opponents = Json.parseIfString(firstGame.opponents) or {}
+ local firstGameScores = Array.map(opponents, Operator.property('score'))
+ match[prefix..'score'] = firstGameScores[index]
end
if not match[prefix..'score'] then
match[prefix..'score'] = (tonumber(opponent.score) or 0) > 0 and opponent.score or 0
diff --git a/components/match2/wikis/rainbowsix/match_summary.lua b/components/match2/wikis/rainbowsix/match_summary.lua
index 4370ded2f3e..4502b47d02d 100644
--- a/components/match2/wikis/rainbowsix/match_summary.lua
+++ b/components/match2/wikis/rainbowsix/match_summary.lua
@@ -76,7 +76,7 @@ function CustomMatchSummary.createGame(date, game, gameIndex)
gameStatusBackground = 'brkts-popup-body-gradient-left'
elseif game.winner == 2 then
gameStatusBackground = 'brkts-popup-body-gradient-right'
- elseif game.resultType == 'draw' then
+ elseif game.winner == 0 then
gameStatusBackground = 'brkts-popup-body-gradient-draw'
end
diff --git a/components/match2/wikis/rocketleague/match_legacy.lua b/components/match2/wikis/rocketleague/match_legacy.lua
index 5d1722258f2..866f345ea3a 100644
--- a/components/match2/wikis/rocketleague/match_legacy.lua
+++ b/components/match2/wikis/rocketleague/match_legacy.lua
@@ -8,10 +8,15 @@
local MatchLegacy = {}
-local json = require('Module:Json')
+local Array = require('Module:Array')
+local Json = require('Module:Json')
+local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -32,10 +37,8 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = game.scores or {}
- if type(scores) == 'string' then
- scores = json.parse(scores)
- end
+ local opponents = Json.parseIfString(game.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
local res = mw.ext.LiquipediaDB.lpdb_game(
@@ -69,7 +72,7 @@ function MatchLegacy._convertParameters(match2)
opponent1players['p' .. i] = player.name or ''
opponent1players['p' .. i .. 'flag'] = player.flag or ''
end
- match.opponent1players = json.stringify(opponent1players)
+ match.opponent1players = Json.stringify(opponent1players)
elseif opponent1.type == 'solo' then
local player = opponent1match2players[1] or {}
match.opponent1 = player.name
@@ -90,7 +93,7 @@ function MatchLegacy._convertParameters(match2)
opponent2players['p' .. i] = player.name or ''
opponent2players['p' .. i .. 'flag'] = player.flag or ''
end
- match.opponent2players = json.stringify(opponent2players)
+ match.opponent2players = Json.stringify(opponent2players)
elseif opponent2.type == 'solo' then
local player = opponent2match2players[1] or {}
match.opponent2 = player.name
@@ -99,9 +102,10 @@ function MatchLegacy._convertParameters(match2)
match.opponent2flag = player.flag
end
- if match2.walkover then
- match.resulttype = match2.walkover
- if match2.walkover == 'ff' or match2.walkover == 'dq' then
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover:lower()
+ if walkover == 'FF' or walkover == 'DQ' then
match.walkover = match.winner
else
match.walkover = nil
diff --git a/components/match2/wikis/runeterra/match_legacy.lua b/components/match2/wikis/runeterra/match_legacy.lua
index 24aec736144..5d80705362a 100644
--- a/components/match2/wikis/runeterra/match_legacy.lua
+++ b/components/match2/wikis/runeterra/match_legacy.lua
@@ -9,9 +9,12 @@
local MatchLegacy = {}
local Json = require('Module:Json')
+local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -29,6 +32,8 @@ function MatchLegacy._convertParameters(match2)
end
end
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ match.walkover = walkover and walkover:lower() or nil
if match.walkover == 'ff' or match.walkover == 'dq' then
match.walkover = match.winner
elseif match.walkover == 'l' then
diff --git a/components/match2/wikis/sideswipe/match_legacy.lua b/components/match2/wikis/sideswipe/match_legacy.lua
index 3543b1a11ea..44f428019a6 100644
--- a/components/match2/wikis/sideswipe/match_legacy.lua
+++ b/components/match2/wikis/sideswipe/match_legacy.lua
@@ -8,10 +8,15 @@
local p = {}
+local Array = require('Module:Array')
local Json = require('Module:Json')
+local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
local MAX_NUM_PLAYERS = 10
function p.storeMatch(match2)
@@ -34,10 +39,8 @@ function p.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = game.scores or {}
- if type(scores) == 'string' then
- scores = Json.parse(scores)
- end
+ local opponents = Json.parseIfString(game.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
local res = mw.ext.LiquipediaDB.lpdb_game(
@@ -88,8 +91,9 @@ function p._convertParameters(match2)
handleOpponent(1)
handleOpponent(2)
- if match2.walkover then
- match.resulttype = match2.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover:lower()
match.walkover = nil
end
diff --git a/components/match2/wikis/smash/match_legacy.lua b/components/match2/wikis/smash/match_legacy.lua
index ea103fc6fc0..9b5fc54c6b0 100644
--- a/components/match2/wikis/smash/match_legacy.lua
+++ b/components/match2/wikis/smash/match_legacy.lua
@@ -11,6 +11,7 @@ local MatchLegacy = {}
local Array = require('Module:Array')
local FnUtil = require('Module:FnUtil')
local Json = require('Module:Json')
+local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Operator = require('Module:Operator')
local Set = require('Module:Set')
@@ -18,6 +19,7 @@ local String = require('Module:StringUtils')
local Table = require('Module:Table')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
local OpponentLibraries = require('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent
@@ -33,6 +35,7 @@ function MatchLegacy._storeGames(match, match2)
local games = Array.map(match2.match2games or {}, function(game2, gameIndex)
local game = Table.deepCopy(game2)
local opponents = Json.parseIfString(game2.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
-- Extradata
game.extradata = {}
@@ -57,7 +60,6 @@ function MatchLegacy._storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
- local scores = Json.parseIfString(game2.scores) or {}
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
return mw.ext.LiquipediaDB.lpdb_game(
@@ -74,11 +76,12 @@ function MatchLegacy._convertParameters(match2)
return not String.startsWith(key, 'match2')
end)
- match.walkover = match.walkover and string.upper(match.walkover) or nil
- if match.walkover == 'FF' or match.walkover == 'DQ' then
- match.resulttype = match.walkover:lower()
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ match.walkover = walkover
+ if walkover == 'FF' or walkover == 'DQ' then
+ match.resulttype = walkover:lower()
match.walkover = match.winner
- elseif match.walkover == 'L' then
+ elseif walkover == 'L' then
match.walkover = nil
end
@@ -100,13 +103,14 @@ function MatchLegacy._convertParameters(match2)
end
-- Handle Opponents
- local headList = function(participant)
+ local headList = function(opponentIndex, playerIndex)
local heads = Set{}
Array.forEach(match2.match2games or {}, function(game)
- local participants = Json.parseIfString(game.participants) or {}
- if participants[participant] and participants[participant].characters then
+ local opponents = Json.parseIfString(game.opponents) or {}
+ local player = (opponents[opponentIndex].players or {})[playerIndex]
+ if player and Logic.isNotEmpty(player.characters) then
Array.forEach(
- Array.map(participants[participant].characters, Operator.property('name')),
+ Array.map(player.characters, Operator.property('name')),
FnUtil.curry(heads.add, heads)
)
end
@@ -124,7 +128,7 @@ function MatchLegacy._convertParameters(match2)
match[prefix .. 'score'] = (tonumber(opponent.score) or 0) > 0 and opponent.score or 0
match[prefix .. 'flag'] = player.flag
match.extradata[prefix .. 'displayname'] = player.displayname
- match.extradata[prefix .. 'heads'] = table.concat(headList(index .. '_1'), ',')
+ match.extradata[prefix .. 'heads'] = table.concat(headList(index, 1), ',')
if match2.winner == index then
match.winner = player.name
end
@@ -138,7 +142,7 @@ function MatchLegacy._convertParameters(match2)
match.extradata[teamPrefix .. playerPrefix] = player.name or ''
match.extradata[teamPrefix .. playerPrefix .. 'flag'] = player.flag or ''
match.extradata[teamPrefix .. playerPrefix .. 'displayname'] = player.displayname or ''
- match.extradata[teamPrefix .. playerPrefix .. 'heads'] = table.concat(headList(index .. '_' .. i), ',')
+ match.extradata[teamPrefix .. playerPrefix .. 'heads'] = table.concat(headList(index, i), ',')
end
match[prefix .. 'players'] = mw.ext.LiquipediaDB.lpdb_create_json(opponentPlayers)
match[prefix] = table.concat(Array.extractValues(opponentPlayers), '/')
@@ -155,7 +159,7 @@ function MatchLegacy._convertParameters(match2)
match.extradata[teamPrefix .. playerPrefix] = player.name or ''
match.extradata[teamPrefix .. playerPrefix .. 'flag'] = player.flag or ''
match.extradata[teamPrefix .. playerPrefix .. 'displayname'] = player.displayname or ''
- match.extradata[teamPrefix .. playerPrefix .. 'heads'] = table.concat(headList(index .. '_' .. i), ',')
+ match.extradata[teamPrefix .. playerPrefix .. 'heads'] = table.concat(headList(index, i), ',')
end
match[prefix .. 'players'] = mw.ext.LiquipediaDB.lpdb_create_json(opponentPlayers)
match[prefix] = opponent.name
diff --git a/components/match2/wikis/splatoon/match_legacy.lua b/components/match2/wikis/splatoon/match_legacy.lua
index 752e77c1c5c..09b1991b84c 100644
--- a/components/match2/wikis/splatoon/match_legacy.lua
+++ b/components/match2/wikis/splatoon/match_legacy.lua
@@ -8,12 +8,15 @@
local MatchLegacy = {}
+local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -40,10 +43,8 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = game2.scores or {}
- if type(scores) == 'string' then
- scores = Json.parse(scores)
- end
+ local opponents = Json.parseIfString(game.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
local res = mw.ext.LiquipediaDB.lpdb_game(
@@ -63,11 +64,12 @@ function MatchLegacy._convertParameters(match2)
end
end
- if match.walkover == 'ff' or match.walkover == 'dq' then
- match.resulttype = match.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover == 'FF' or walkover == 'DQ' then
+ match.resulttype = walkover:lower()
match.walkover = match.winner
- elseif match.walkover == 'l' then
- match.resulttype = match.walkover
+ elseif walkover == 'L' then
+ match.resulttype = walkover:lower()
match.walkover = nil
end
diff --git a/components/match2/wikis/squadrons/match_legacy.lua b/components/match2/wikis/squadrons/match_legacy.lua
index c3a9b9807bf..ad3b79ee1ac 100644
--- a/components/match2/wikis/squadrons/match_legacy.lua
+++ b/components/match2/wikis/squadrons/match_legacy.lua
@@ -9,9 +9,12 @@
local MatchLegacy = {}
local Json = require('Module:Json')
+local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -29,6 +32,8 @@ function MatchLegacy._convertParameters(match2)
end
end
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ match.walkover = walkover and walkover:lower() or nil
if match.walkover == 'ff' or match.walkover == 'dq' then
match.walkover = match.winner
elseif match.walkover == 'l' then
diff --git a/components/match2/wikis/starcraft/match_legacy.lua b/components/match2/wikis/starcraft/match_legacy.lua
index 938487814e6..31889ff686b 100644
--- a/components/match2/wikis/starcraft/match_legacy.lua
+++ b/components/match2/wikis/starcraft/match_legacy.lua
@@ -8,12 +8,17 @@
local MatchLegacy = {}
+local Array = require('Module:Array')
local Json = require('Module:Json')
local Logic = require('Module:Logic')
+local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local Template = require('Module:Template')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
local _MODES = {solo = '1v1', team = 'team'}
function MatchLegacy.storeMatch(match2)
@@ -35,34 +40,31 @@ function MatchLegacy._storeGames(match, match2)
local games = ''
for gameIndex, game in ipairs(match2.match2games or {}) do
game.extradata = Json.parseIfString(game.extradata or '{}') or game.extradata
+ local opponents = Json.parseIfString(game.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
if game.mode == '1v1' then
game.opponent1 = game.extradata.opponent1
game.opponent2 = game.extradata.opponent2
game.date = match.date
- local scores = Json.parseIfString(game.scores or '{}') or {}
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
game.extradata.winnerrace = game.extradata.winnerfaction
game.extradata.loserrace = game.extradata.loserfaction
- -- participants holds additional playerdata per match, e.g. the faction (=race)
- -- participants is stored as opponentID_playerID, so e.g. for opponent2, player1 it is "2_1"
- local playerdata = Table.mapValues(Json.parseIfString(game.participants or '{}') or game.participants or {},
- Logic.nilIfEmpty)
- for key, item in pairs(playerdata) do
- local keyArray = mw.text.split(key or '', '_')
- local l = tonumber(keyArray[2])
- local k = tonumber(keyArray[1])
- game.extradata['opponent' .. k .. 'race'] = item.faction
- local opp = match2.match2opponents[k] or {}
- local pl = opp.match2players or {}
- game['opponent' .. k .. 'flag'] = (pl[l] or {}).flag
- game.extradata['opponent' .. k .. 'name'] = (pl[l] or {}).displayname
- game.extradata['tournament'] = match2.tournament or ''
- game.extradata['series'] = match2.series or ''
- end
+ Array.forEach(opponents, function(opponent, opponentIndex)
+ Array.forEach(opponent.players or {}, function(player, playerIndex)
+ if Logic.isDeepEmpty(player) then return end
+ local matchPlayer = match2.match2opponents[opponentIndex].match2players[playerIndex] or {}
+ game.extradata['opponent' .. opponentIndex .. 'race'] = player.faction
+ game['opponent' .. opponentIndex .. 'flag'] = matchPlayer.flag
+ game.extradata['opponent' .. opponentIndex .. 'name'] = matchPlayer.displayname
+ game.extradata['tournament'] = match2.tournament or ''
+ game.extradata['series'] = match2.series or ''
+ end)
+ end)
+
game.extradata.gamenumber = gameIndex
game.extradata = Json.stringify(game.extradata)
@@ -77,28 +79,24 @@ function MatchLegacy._storeGames(match, match2)
submatch.opponent1 = game.extradata.opponent1
submatch.opponent2 = game.extradata.opponent2
- local scores = Json.parseIfString(game.scores or '{}') or {}
submatch.opponent1score = scores[1] or 0
submatch.opponent2score = scores[2] or 0
submatch.extradata = {}
- local playerdata = Table.mapValues(Json.parseIfString(game.participants or '{}') or game.participants,
- Logic.nilIfEmpty)
- for key, item in pairs(playerdata) do
- local keyArray = mw.text.split(key or '', '_')
- local l = tonumber(keyArray[2])
- local k = tonumber(keyArray[1])
- submatch.extradata['opponent' .. k .. 'race'] = item.faction
- local opp = match2.match2opponents[k] or {}
- local pl = opp.match2players or {}
- submatch['opponent' .. k .. 'flag'] = (pl[l] or {}).flag
- submatch.extradata['opponent' .. k .. 'name'] = (pl[l] or {}).displayname
- end
+
+ Array.forEach(opponents, function(opponent, opponentIndex)
+ Array.forEach(opponent.players or {}, function(player, playerIndex)
+ if Logic.isDeepEmpty(player) then return end
+ local matchPlayer = match2.match2opponents[opponentIndex].match2players[playerIndex] or {}
+ submatch.extradata['opponent' .. opponentIndex .. 'race'] = player.faction
+ submatch['opponent' .. opponentIndex .. 'flag'] = matchPlayer.flag
+ submatch.extradata['opponent' .. opponentIndex .. 'name'] = matchPlayer.displayname
+ end)
+ end)
+
submatch.winner = game.winner or ''
- submatch.walkover = game.walkover or ''
+ local walkover = MatchOpponentHelper.calculateWalkoverType(opponents)
+ submatch.walkover = (walkover or ''):lower()
submatch.finished = match2.finished or '0'
- if game.resulttype ~= 'submatch' then
- submatch.resulttype = game.resulttype
- end
submatch.mode = '1v1'
submatch.date = game.date
submatch.dateexact = match2.dateexact or ''
@@ -175,8 +173,9 @@ function MatchLegacy._convertParameters(match2)
return nil, false
end
- if match.resulttype == 'default' then
- match.resulttype = string.upper(match.walkover or '')
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover
match.walkover = match.winner
end
match.extradata.bestof = match2.bestof ~= 0 and tostring(match2.bestof) or ''
diff --git a/components/match2/wikis/stormgate/match_group_util_custom.lua b/components/match2/wikis/stormgate/match_group_util_custom.lua
index 0a9681a5f6e..d97f076b975 100644
--- a/components/match2/wikis/stormgate/match_group_util_custom.lua
+++ b/components/match2/wikis/stormgate/match_group_util_custom.lua
@@ -11,6 +11,7 @@ local Faction = require('Module:Faction')
local Flags = require('Module:Flags')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local TypeUtil = require('Module:TypeUtil')
@@ -18,8 +19,9 @@ local TypeUtil = require('Module:TypeUtil')
local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')
-- can not use `Module:OpponentLibraries`/`Module:Opponent/Custom` to avoid loop
local Opponent = Lua.import('Module:Opponent')
+local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')
-local SCORE_STATUS = 'S'
+local SCORE_STATUS = MatchGroupInputUtil.STATUS.SCORE
local CustomMatchGroupUtil = Table.deepCopy(MatchGroupUtil)
@@ -59,10 +61,8 @@ CustomMatchGroupUtil.types.GameOpponent = TypeUtil.struct({
---@field games StormgateMatchGroupUtilGame[]
---@field mode string
---@field opponents StormgateMatchGroupUtilGameOpponent[]
----@field resultType ResultType
----@field scores table
+---@field status string?
---@field subgroup number
----@field walkover WalkoverType
---@field winner number?
---@field header string?
@@ -99,11 +99,6 @@ function CustomMatchGroupUtil.matchFromRecord(record)
CustomMatchGroupUtil.groupBySubmatch(match.games),
function(games) return CustomMatchGroupUtil.constructSubmatch(games, match) end
)
-
- -- Extract submatch headers from extradata
- for _, submatch in pairs(match.submatches) do
- submatch.header = Table.extract(extradata, 'subgroup' .. submatch.subgroup .. 'header')
- end
end
-- Add vetoes
@@ -191,71 +186,47 @@ end
---@param match StormgateMatchGroupUtilMatch
---@return StormgateMatchGroupUtilSubmatch
function CustomMatchGroupUtil.constructSubmatch(games, match)
- local opponents = Table.deepCopy(games[1].opponents)
-
- --check the faction of the players
- for opponentIndex in pairs(opponents) do
- CustomMatchGroupUtil._determineSubmatchPlayerFactions(match, games, opponents, opponentIndex)
+ local firstGame = games[1]
+ local opponents = Table.deepCopy(firstGame.opponents)
+ local isSubmatch = String.startsWith(firstGame.map, 'Submatch')
+ if isSubmatch then
+ games = {firstGame}
end
- -- Sum up scores
- local scores = {}
- for opponentIndex, _ in pairs(opponents) do
- scores[opponentIndex] = 0
- end
- for _, game in pairs(games) do
- if game.map and String.startsWith(game.map, 'Submatch') and not game.resultType then
- for opponentIndex, score in pairs(scores) do
- scores[opponentIndex] = score + (tonumber(game.scores[opponentIndex]) or 0)
- end
- elseif game.winner then
- scores[game.winner] = (scores[game.winner] or 0) + 1
- end
+ ---@param opponent table
+ ---@param opponentIndex integer
+ local getOpponentScoreAndStatus = function(opponent, opponentIndex)
+ local statuses = Array.unique(Array.map(games, function(game)
+ return game.opponents[opponentIndex].status
+ end))
+ opponent.status = #statuses == 1 and statuses[1] ~= SCORE_STATUS and statuses[1] or SCORE_STATUS
+ opponent.score = isSubmatch and opponent.score or Array.reduce(Array.map(games, function(game)
+ return (game.winner == opponentIndex and 1 or 0)
+ end), Operator.add)
end
- -- Compute winner if all games have been played, skipped, or defaulted
- local allPlayed = Array.all(games, function(game)
- return game.winner ~= nil or game.resultType ~= nil
- end)
+ Array.forEach(opponents, getOpponentScoreAndStatus)
- local resultType = nil
- local winner = nil
- if allPlayed then
- local diff = (scores[1] or 0) - (scores[2] or 0)
- if diff < 0 then
- winner = 2
- elseif diff == 0 then
- resultType = 'draw'
- else
- winner = 1
- end
- end
+ local allPlayed = Array.all(games, function (game)
+ return game.winner ~= nil or game.status == 'notplayed'
+ end)
+ local winner = allPlayed and MatchGroupInputUtil.getWinner('', nil, opponents) or nil
+ Array.forEach(opponents, function(opponent, opponentIndex)
+ opponent.placement = MatchGroupInputUtil.placementFromWinner('', winner, opponentIndex)
+ end)
- -- Set resultType and walkover if every game is a walkover
- local walkovers = {}
- local resultTypes = {}
- for _, game in pairs(games) do
- resultTypes[game.resultType or ''] = true
- walkovers[game.walkover or ''] = true
- end
- local walkover
- local uniqueResult = Table.uniqueKey(resultTypes)
- if uniqueResult == 'default' then
- resultType = 'default'
- walkover = String.nilIfEmpty(Table.uniqueKey(walkovers)) or 'L'
- elseif uniqueResult == 'np' then
- resultType = 'np'
- end
+ --check the faction of the players
+ Array.forEach(opponents, function(_, opponentIndex)
+ CustomMatchGroupUtil._determineSubmatchPlayerFactions(match, games, opponents, opponentIndex)
+ end)
return {
games = games,
- mode = games[1].mode,
+ mode = firstGame.mode,
opponents = opponents,
- resultType = resultType,
- scores = scores,
- subgroup = games[1].subgroup,
- walkover = walkover,
+ subgroup = firstGame.subgroup,
winner = winner,
+ header = Table.extract(match.extradata or {}, 'subgroup' .. firstGame.subgroup .. 'header'),
}
end
diff --git a/components/match2/wikis/stormgate/match_summary.lua b/components/match2/wikis/stormgate/match_summary.lua
index 2687c139cb0..bb0fdcc4b82 100644
--- a/components/match2/wikis/stormgate/match_summary.lua
+++ b/components/match2/wikis/stormgate/match_summary.lua
@@ -100,9 +100,13 @@ end
---@param match table
---@return boolean
function CustomMatchSummary.hasHeroes(match)
- return Array.any(match.games, function(game) return Table.any(game.participants, function(key, participant)
- return Table.isNotEmpty(participant.heroes)
- end) end)
+ return Array.any(match.games, function(game)
+ return Array.any(game.opponents, function(opponent)
+ return Array.any(opponent.players or {}, function(player)
+ return Logic.isNotEmpty(player.heroes)
+ end)
+ end)
+ end)
end
---@param opponent StarcraftStandardOpponent
@@ -219,7 +223,7 @@ function CustomMatchSummary.TeamSubmatch(submatch)
}
end
----@param submatch StarcraftMatchGroupUtilSubmatch
+---@param submatch StormgateMatchGroupUtilSubmatch
---@return Widget
function CustomMatchSummary.TeamSubMatchOpponnetRow(submatch)
local opponents = submatch.opponents or {{}, {}}
@@ -240,18 +244,9 @@ function CustomMatchSummary.TeamSubMatchOpponnetRow(submatch)
---@param opponentIndex any
---@return Html
local createScore = function(opponentIndex)
- local isWinner = opponentIndex == submatch.winner or submatch.resultType == 'draw'
- if submatch.resultType == 'default' then
- return OpponentDisplay.BlockScore{
- isWinner = isWinner,
- scoreText = isWinner and 'W' or string.upper(submatch.walkover),
- }
- end
-
- local score = submatch.resultType ~= 'np' and (submatch.scores or {})[opponentIndex] or nil
return OpponentDisplay.BlockScore{
- isWinner = isWinner,
- scoreText = score,
+ isWinner = opponentIndex == submatch.winner or submatch.winner == 0,
+ scoreText = DisplayHelper.MapScore(submatch.opponents[opponentIndex], submatch.status),
}
end
diff --git a/components/match2/wikis/teamfortress/match_legacy.lua b/components/match2/wikis/teamfortress/match_legacy.lua
index 25606c4cccd..8f0ea071e5a 100644
--- a/components/match2/wikis/teamfortress/match_legacy.lua
+++ b/components/match2/wikis/teamfortress/match_legacy.lua
@@ -9,10 +9,13 @@
local MatchLegacy = {}
local Json = require('Module:Json')
+local Lua = require('Module:Lua')
local Opponent = require('Module:Opponent')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
function MatchLegacy.storeMatch(match2)
return mw.ext.LiquipediaDB.lpdb_match(
'legacymatch_' .. match2.match2id,
@@ -28,6 +31,8 @@ function MatchLegacy._convertParameters(match2)
end
end
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ match.walkover = walkover and walkover:lower() or nil
if match.walkover == 'ff' or match.walkover == 'dq' then
match.walkover = match.winner
elseif match.walkover == 'l' then
diff --git a/components/match2/wikis/tetris/match_legacy.lua b/components/match2/wikis/tetris/match_legacy.lua
index a82b8e3b2f0..ed62ed2a3f7 100644
--- a/components/match2/wikis/tetris/match_legacy.lua
+++ b/components/match2/wikis/tetris/match_legacy.lua
@@ -9,9 +9,12 @@
local MatchLegacy = {}
local Json = require('Module:Json')
+local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
function MatchLegacy.storeMatch(match2)
return MatchLegacy.convertParameters(match2)
end
@@ -57,8 +60,9 @@ function MatchLegacy.convertParameters(match2)
return nil
end
- if match.resulttype == 'default' then
- match.resulttype = string.upper(match.walkover or '')
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover
match.walkover = match.winner
end
match.extradata.bestof = match2.bestof ~= 0 and tostring(match2.bestof) or ''
diff --git a/components/match2/wikis/trackmania/match_legacy.lua b/components/match2/wikis/trackmania/match_legacy.lua
index 5173753e6ca..cc693ffa3be 100644
--- a/components/match2/wikis/trackmania/match_legacy.lua
+++ b/components/match2/wikis/trackmania/match_legacy.lua
@@ -8,13 +8,17 @@
local MatchLegacy = {}
+local Array = require('Module:Array')
local Json = require('Module:Json')
+local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local OpponentLibraries = require('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -36,7 +40,8 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = Json.parseIfString(game.scores or {})
+ local opponents = Json.parseIfString(game.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
local res = mw.ext.LiquipediaDB.lpdb_game(
@@ -58,9 +63,10 @@ function MatchLegacy._convertParameters(match2)
match.staticid = match2.match2id
- if match2.walkover then
- match.resulttype = match2.walkover
- if match2.walkover == 'ff' or match2.walkover == 'dq' then
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover:lower()
+ if walkover == 'FF' or walkover == 'DQ' then
match.walkover = match.winner
else
match.walkover = nil
diff --git a/components/match2/wikis/valorant/match_legacy.lua b/components/match2/wikis/valorant/match_legacy.lua
index 56817674da7..8cbde3f4df9 100644
--- a/components/match2/wikis/valorant/match_legacy.lua
+++ b/components/match2/wikis/valorant/match_legacy.lua
@@ -12,11 +12,13 @@ local Array = require('Module:Array')
local Json = require('Module:Json')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local Variables = require('Module:Variables')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -35,6 +37,8 @@ function MatchLegacy.storeGames(match, match2)
local game = Table.deepCopy(game2)
-- Extradata
local extradata = Json.parseIfString(game2.extradata)
+ local opponents = Json.parseIfString(game2.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.extradata = {}
game.extradata.gamenumber = gameIndex
if extradata then
@@ -84,7 +88,6 @@ function MatchLegacy.storeGames(match, match2)
game.extradata['t' .. teamId .. 'a' .. playerId] = data.agent
end
end
- local opponents = Json.parseIfString(game2.opponents) or {}
for teamId, opponent in ipairs(opponents) do
local counter = 0
for _, player in pairs(opponent.players) do
@@ -101,7 +104,6 @@ function MatchLegacy.storeGames(match, match2)
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = Json.parseIfString(game2.scores) or {}
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
@@ -122,10 +124,11 @@ function MatchLegacy._convertParameters(match2)
end
end
- match.resulttype = match.walkover
- if match.walkover == 'ff' or match.walkover == 'dq' then
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ match.resulttype = walkover and walkover:lower() or nil
+ if walkover == 'FF' or match.walkover == 'DQ' then
match.walkover = match.winner
- elseif match.walkover == 'l' then
+ elseif walkover == 'L' then
match.walkover = nil
end
@@ -147,9 +150,11 @@ function MatchLegacy._convertParameters(match2)
local opponent1score = 0
local opponent2score = 0
- local scores = MatchLegacy._getAllInGames(match2, 'scores')
- for _, stringScore in pairs(scores) do
- local score = Json.parseIfString(stringScore)
+ local scores = Array.map(match2.match2games or {}, function(game)
+ local opponents = Json.parseIfString(game.opponents) or {}
+ return Array.map(opponents, Operator.property('score'))
+ end)
+ for _, score in pairs(scores) do
opponent1score = opponent1score + (tonumber(score[1]) or 0)
opponent2score = opponent2score + (tonumber(score[2]) or 0)
end
@@ -185,10 +190,8 @@ function MatchLegacy._convertParameters(match2)
local opponent = match2.match2opponents[index] or {}
if opponent.type == 'team' then
match[prefix] = opponent.name
- if match2.bestof == 1 then
- if ((match2.match2games or {})[1] or {}).scores then
- match[prefix .. 'score'] = Json.parseIfString(match2.match2games[1].scores)[index]
- end
+ if match2.bestof == 1 and scores[1] then
+ match[prefix .. 'score'] = scores[1][index]
end
if not match[prefix..'score'] then
match[prefix..'score'] = (tonumber(opponent.score) or 0) > 0 and opponent.score or 0
diff --git a/components/match2/wikis/warcraft/match_group_util_custom.lua b/components/match2/wikis/warcraft/match_group_util_custom.lua
index e241445b8db..0296ea21d7a 100644
--- a/components/match2/wikis/warcraft/match_group_util_custom.lua
+++ b/components/match2/wikis/warcraft/match_group_util_custom.lua
@@ -11,16 +11,18 @@ local Faction = require('Module:Faction')
local Flags = require('Module:Flags')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')
-- can not use `Module:OpponentLibraries`/`Module:Opponent/Custom` to avoid loop
local Opponent = Lua.import('Module:Opponent')
+local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')
local TEAM_DISPLAY_MODE = 'team'
local UNIFORM_DISPLAY_MODE = 'uniform'
-local SCORE_STATUS = 'S'
+local SCORE_STATUS = MatchGroupInputUtil.STATUS.SCORE
local CustomMatchGroupUtil = Table.deepCopy(MatchGroupUtil)
@@ -47,10 +49,8 @@ local CustomMatchGroupUtil = Table.deepCopy(MatchGroupUtil)
---@field games WarcraftMatchGroupUtilGame[]
---@field mode string
---@field opponents WarcraftMatchGroupUtilGameOpponent[]
----@field resultType ResultType
----@field scores table
+---@field status string?
---@field subgroup number
----@field walkover WalkoverType
---@field winner number?
---@field header string?
@@ -89,11 +89,6 @@ function CustomMatchGroupUtil.matchFromRecord(record)
CustomMatchGroupUtil.groupBySubmatch(match.games),
function(games) return CustomMatchGroupUtil.constructSubmatch(games, match) end
)
-
- -- Extract submatch headers from extradata
- for _, submatch in pairs(match.submatches) do
- submatch.header = Table.extract(extradata, 'subgroup' .. submatch.subgroup .. 'header')
- end
end
-- Add vetoes
@@ -182,71 +177,47 @@ end
---@param match WarcraftMatchGroupUtilMatch
---@return WarcraftMatchGroupUtilSubmatch
function CustomMatchGroupUtil.constructSubmatch(games, match)
- local opponents = Table.deepCopy(games[1].opponents)
-
- --check the faction of the players
- for opponentIndex in pairs(opponents) do
- CustomMatchGroupUtil._determineSubmatchPlayerFactions(match, games, opponents, opponentIndex)
+ local firstGame = games[1]
+ local opponents = Table.deepCopy(firstGame.opponents)
+ local isSubmatch = String.startsWith(firstGame.map, 'Submatch')
+ if isSubmatch then
+ games = {firstGame}
end
- -- Sum up scores
- local scores = {}
- for opponentIndex, _ in pairs(opponents) do
- scores[opponentIndex] = 0
- end
- for _, game in pairs(games) do
- if game.map and String.startsWith(game.map, 'Submatch') and not game.resultType then
- for opponentIndex, score in pairs(scores) do
- scores[opponentIndex] = score + (tonumber(game.scores[opponentIndex]) or 0)
- end
- elseif game.winner then
- scores[game.winner] = (scores[game.winner] or 0) + 1
- end
+ ---@param opponent table
+ ---@param opponentIndex integer
+ local getOpponentScoreAndStatus = function(opponent, opponentIndex)
+ local statuses = Array.unique(Array.map(games, function(game)
+ return game.opponents[opponentIndex].status
+ end))
+ opponent.status = #statuses == 1 and statuses[1] ~= SCORE_STATUS and statuses[1] or SCORE_STATUS
+ opponent.score = isSubmatch and opponent.score or Array.reduce(Array.map(games, function(game)
+ return (game.winner == opponentIndex and 1 or 0)
+ end), Operator.add)
end
- -- Compute winner if all games have been played, skipped, or defaulted
- local allPlayed = Array.all(games, function(game)
- return game.winner ~= nil or game.resultType ~= nil
- end)
+ Array.forEach(opponents, getOpponentScoreAndStatus)
- local resultType = nil
- local winner = nil
- if allPlayed then
- local diff = (scores[1] or 0) - (scores[2] or 0)
- if diff < 0 then
- winner = 2
- elseif diff == 0 then
- resultType = 'draw'
- else
- winner = 1
- end
- end
+ local allPlayed = Array.all(games, function (game)
+ return game.winner ~= nil or game.status == 'notplayed'
+ end)
+ local winner = allPlayed and MatchGroupInputUtil.getWinner('', nil, opponents) or nil
+ Array.forEach(opponents, function(opponent, opponentIndex)
+ opponent.placement = MatchGroupInputUtil.placementFromWinner('', winner, opponentIndex)
+ end)
- -- Set resultType and walkover if every game is a walkover
- local walkovers = {}
- local resultTypes = {}
- for _, game in pairs(games) do
- resultTypes[game.resultType or ''] = true
- walkovers[game.walkover or ''] = true
- end
- local walkover
- local uniqueResult = Table.uniqueKey(resultTypes)
- if uniqueResult == 'default' then
- resultType = 'default'
- walkover = String.nilIfEmpty(Table.uniqueKey(walkovers)) or 'L'
- elseif uniqueResult == 'np' then
- resultType = 'np'
- end
+ --check the faction of the players
+ Array.forEach(opponents, function(_, opponentIndex)
+ CustomMatchGroupUtil._determineSubmatchPlayerFactions(match, games, opponents, opponentIndex)
+ end)
return {
games = games,
- mode = games[1].mode,
+ mode = firstGame.mode,
opponents = opponents,
- resultType = resultType,
- scores = scores,
- subgroup = games[1].subgroup,
- walkover = walkover,
+ subgroup = firstGame.subgroup,
winner = winner,
+ header = Table.extract(match.extradata or {}, 'subgroup' .. firstGame.subgroup .. 'header'),
}
end
diff --git a/components/match2/wikis/warcraft/match_legacy.lua b/components/match2/wikis/warcraft/match_legacy.lua
index 4b6f74061bb..5ff8c489e7c 100644
--- a/components/match2/wikis/warcraft/match_legacy.lua
+++ b/components/match2/wikis/warcraft/match_legacy.lua
@@ -13,11 +13,13 @@ local Json = require('Module:Json')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Namespace = require('Module:Namespace')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local Variables = require('Module:Variables')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
local OpponentLibrary = require('Module:OpponentLibraries')
local Opponent = OpponentLibrary.Opponent
@@ -126,9 +128,10 @@ function MatchLegacy._convertParameters(match2)
extradata.tournamentstagename = Logic.emptyOr(Variables.varDefault('Group_name'),
match.header .. ' - ' .. (match.opponent1 or '') .. ' vs ' .. (match.opponent2 or ''))
- if match.resulttype == 'default' then
- match.resulttype = string.upper(match.walkover or '')
- if match.resulttype == UNKNOWNREASON_DEFAULT_LOSS then
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = walkover
+ if walkover == UNKNOWNREASON_DEFAULT_LOSS then
--needs to be converted because in match1 storage it was marked this way
match.resulttype = 'unk'
end
@@ -167,17 +170,20 @@ function MatchLegacy._groupIntoSubmatches(match2, objectName)
local submatchIndex = tonumber(game.subgroup)
if game.mode ~= '1v1' or not submatchIndex then return end
+ local opponents = Json.parseIfString(game.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
+
if not submatches[submatchIndex] then
submatches[submatchIndex] = {
games = {},
objectName = objectName .. '_Submatch_' .. submatchIndex,
- opponents = MatchLegacy._fromParticipantToOpponent(game.participants or {}, match2.match2opponents)
+ opponents = MatchLegacy._constructSubmatchOpponents(opponents, match2.match2opponents)
}
end
local submatch = submatches[submatchIndex]
table.insert(submatch.games, game)
- submatch.opponents[1].score = submatch.opponents[1].score + (tonumber((game.scores or {})[1]) or 0)
- submatch.opponents[2].score = submatch.opponents[2].score + (tonumber((game.scores or {})[2]) or 0)
+ submatch.opponents[1].score = submatch.opponents[1].score + (scores[1] or 0)
+ submatch.opponents[2].score = submatch.opponents[2].score + (scores[2] or 0)
end)
return submatches
@@ -211,22 +217,22 @@ function MatchLegacy._storeSubMatch(submatch, submatchIndex, match)
mw.ext.LiquipediaDB.lpdb_match(submatchStorageObject.objectName, submatchStorageObject)
end
----@param participants table
----@param opponents table
+---@param gameOpponents table[]
+---@param matchOpponents table[]
---@return {match2players: table[], score: number, type: OpponentType}
-function MatchLegacy._fromParticipantToOpponent(participants, opponents)
- local submatchOpponents = {
- {match2players = {}, score = 0, type = Opponent.solo},
- {match2players = {}, score = 0, type = Opponent.solo},
- }
- for participantKey in Table.iter.spairs(Table.mapValues(participants, Logic.nilIfEmpty)) do
- local opponentKey, playerKey = string.match(participantKey, '^(%d+)_(%d+)$')
- opponentKey = tonumber(opponentKey)
- table.insert(submatchOpponents[opponentKey].match2players,
- opponents[opponentKey].match2players[tonumber(playerKey)])
- end
-
- return submatchOpponents
+function MatchLegacy._constructSubmatchOpponents(gameOpponents, matchOpponents)
+ return Array.map(gameOpponents, function(gameOpponent, opponentIndex)
+ return {
+ type = Opponent.solo,
+ score = 0,
+ match2players = Table.map(gameOpponent.players, function(playerIndex, gamePlayer)
+ if Logic.isDeepEmpty(gamePlayer) then
+ return playerIndex, nil
+ end
+ return playerIndex, matchOpponents[opponentIndex].match2players[playerIndex]
+ end)
+ }
+ end)
end
---@param game2 table
@@ -234,7 +240,10 @@ end
---@param match table
---@return string?
function MatchLegacy._storeGame(game2, gameIndex, match)
- if game2.resulttype == 'np' then return end
+ if game2.status == 'notplayed' then return end
+
+ local opponents = Json.parseIfString(game2.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
local objectName = match.objectName .. '_Map_' .. gameIndex
@@ -243,11 +252,10 @@ function MatchLegacy._storeGame(game2, gameIndex, match)
game.vod = game2.vod
game.map = game2.map
- game2.scores = game2.scores or {}
- game.opponent1score = game2.scores[1]
- game.opponent2score = game2.scores[2]
+ game.opponent1score = scores[1]
+ game.opponent2score = scores[2]
- local factions, heroes = MatchLegacy._heroesAndFactionFromParticipants(game2.participants)
+ local factions, heroes = MatchLegacy._heroesAndFactionFromGameOpponents(opponents)
for opponentIndex = 1, 2 do
game.extradata['opponent' .. opponentIndex .. 'race'] = factions[opponentIndex]
or game.extradata['opponent' .. opponentIndex .. 'race']
@@ -262,9 +270,10 @@ function MatchLegacy._storeGame(game2, gameIndex, match)
game.resulttype = nil
game.walkover = nil
- if game2.resulttype == 'default' then
- game.resulttype = string.upper(game2.walkover or '')
- if game.resulttype == UNKNOWNREASON_DEFAULT_LOSS then
+ local walkover = MatchOpponentHelper.calculateWalkoverType(opponents)
+ if walkover then
+ game.resulttype = walkover
+ if walkover == UNKNOWNREASON_DEFAULT_LOSS then
--needs to be converted because in match1 storage it was marked this way
game.resulttype = 'unk'
end
@@ -274,18 +283,16 @@ function MatchLegacy._storeGame(game2, gameIndex, match)
return mw.ext.LiquipediaDB.lpdb_game(objectName, game)
end
----@param participants table
+---@param opponents table[]
---@return string[]
---@return string[][]
-function MatchLegacy._heroesAndFactionFromParticipants(participants)
+function MatchLegacy._heroesAndFactionFromGameOpponents(opponents)
local factions, heroes = {}, {}
- for participantKey, participant in pairs(Table.mapValues(participants or {}, Logic.nilIfEmpty)) do
- local opponentKey = string.match(participantKey, '^(%d+)_%d+$')
- opponentKey = tonumber(opponentKey)
- ---@cast opponentKey -nil
- factions[opponentKey] = participant.faction
- heroes[opponentKey] = participant.heroes
- end
+ Array.forEach(opponents, function(opponent, opponentIndex)
+ local player = Array.map(opponent.players or {}, Logic.nilIfEmpty)[1] or {}
+ factions[opponentIndex] = player.faction
+ heroes[opponentIndex] = player.heroes
+ end)
return factions, heroes
end
diff --git a/components/match2/wikis/warcraft/match_summary.lua b/components/match2/wikis/warcraft/match_summary.lua
index d421dd0b791..f80d02accab 100644
--- a/components/match2/wikis/warcraft/match_summary.lua
+++ b/components/match2/wikis/warcraft/match_summary.lua
@@ -101,9 +101,13 @@ end
---@param match table
---@return boolean
function CustomMatchSummary.hasHeroes(match)
- return Array.any(match.games, function(game) return Table.any(game.participants, function(key, participant)
- return Table.isNotEmpty(participant.heroes)
- end) end)
+ return Array.any(match.games, function(game)
+ return Array.any(game.opponents, function(opponent)
+ return Array.any(opponent.players or {}, function(player)
+ return Logic.isNotEmpty(player.heroes)
+ end)
+ end)
+ end)
end
---@param opponent StarcraftStandardOpponent
@@ -220,7 +224,7 @@ function CustomMatchSummary.TeamSubmatch(submatch)
}
end
----@param submatch StarcraftMatchGroupUtilSubmatch
+---@param submatch WarcraftMatchGroupUtilSubmatch
---@return Widget
function CustomMatchSummary.TeamSubMatchOpponnetRow(submatch)
local opponents = submatch.opponents or {{}, {}}
@@ -241,18 +245,9 @@ function CustomMatchSummary.TeamSubMatchOpponnetRow(submatch)
---@param opponentIndex any
---@return Html
local createScore = function(opponentIndex)
- local isWinner = opponentIndex == submatch.winner or submatch.resultType == 'draw'
- if submatch.resultType == 'default' then
- return OpponentDisplay.BlockScore{
- isWinner = isWinner,
- scoreText = isWinner and 'W' or string.upper(submatch.walkover),
- }
- end
-
- local score = submatch.resultType ~= 'np' and (submatch.scores or {})[opponentIndex] or nil
return OpponentDisplay.BlockScore{
- isWinner = isWinner,
- scoreText = score,
+ isWinner = opponentIndex == submatch.winner or submatch.winner == 0,
+ scoreText = DisplayHelper.MapScore(submatch.opponents[opponentIndex], submatch.status),
}
end
diff --git a/components/match2/wikis/wildrift/match_legacy.lua b/components/match2/wikis/wildrift/match_legacy.lua
index 8ab4e36f023..052906f307d 100644
--- a/components/match2/wikis/wildrift/match_legacy.lua
+++ b/components/match2/wikis/wildrift/match_legacy.lua
@@ -9,10 +9,12 @@
local MatchLegacy = {}
local Json = require('Module:Json')
-local Logic = require('Module:Logic')
+local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
+
function MatchLegacy.storeMatch(match2)
local match = MatchLegacy._convertParameters(match2)
@@ -33,8 +35,9 @@ function MatchLegacy._convertParameters(match2)
end
match.links = nil
- if Logic.isNotEmpty(match.walkover) then
- match.resulttype = match.walkover
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover then
+ match.resulttype = match.walkover:lower()
match.walkover = match.winner
end
diff --git a/components/match2/wikis/zula/match_legacy.lua b/components/match2/wikis/zula/match_legacy.lua
index 461e81bf4fe..55b6f4b4320 100644
--- a/components/match2/wikis/zula/match_legacy.lua
+++ b/components/match2/wikis/zula/match_legacy.lua
@@ -6,16 +6,19 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
+local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
local Logic = require('Module:Logic')
+local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local TextSanitizer = require('Module:TextSanitizer')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
local Opponent = Lua.import('Module:Opponent')
-local DRAW = 'draw'
+local DRAW = 0
local LOSER_STATUSES = {'FF', 'DQ', 'L'}
local MatchLegacy = {}
@@ -39,13 +42,14 @@ function MatchLegacy.convertParameters(match2)
end
end
- if match.resulttype == DRAW then
+ if match2.winner == DRAW then
match.winner = 'draw'
end
match.resulttype = nil
- if match.walkover == 'ff' or match.walkover == 'dq' then
+ local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents)
+ if walkover == 'FF' or walkover == 'DQ' then
match.walkover = match.winner
else
match.walkover = nil
@@ -85,10 +89,8 @@ function MatchLegacy.convertParameters(match2)
local opponent1Rounds, opponent2Rounds = 0, 0
local maps = {}
for gameIndex, game in ipairs(match2.match2games or {}) do
- local scores = game.scores or {}
- if type(scores) == 'string' then
- scores = Json.parse(game.scores)
- end
+ local gameOpponents = Json.parseIfString(game.opponents) or {}
+ local scores = Array.map(gameOpponents, Operator.property('score'))
opponent1Rounds = opponent1Rounds + (tonumber(scores[1] or '') or 0)
opponent2Rounds = opponent2Rounds + (tonumber(scores[2] or '') or 0)
match.extradata['vodgame' .. gameIndex] = game.vod
@@ -172,6 +174,8 @@ function MatchLegacy.storeGames(match, match2)
local game = Table.deepCopy(game2)
-- Extradata
local extradata = Json.parseIfString(game2.extradata)
+ local opponents = Json.parseIfString(game2.opponents) or {}
+ local scores = Array.map(opponents, Operator.property('score'))
game.extradata = {}
local opponent1scores, opponent2scores = {}, {}
@@ -200,14 +204,14 @@ function MatchLegacy.storeGames(match, match2)
game.opponent1flag = match.opponent1flag
game.opponent2flag = match.opponent2flag
game.date = match.date
- local scores = game2.scores or {}
if type(scores) == 'string' then
scores = Json.parse(scores)
end
game.opponent1score = scores[1] or 0
game.opponent2score = scores[2] or 0
- if game2.walkover == 'ff' or game2.walkover == 'dq' then
+ local walkover = MatchOpponentHelper.calculateWalkoverType(opponents)
+ if walkover == 'FF' or walkover == 'DQ' then
game.walkover = 1
end
diff --git a/components/match_table/commons/match_table.lua b/components/match_table/commons/match_table.lua
index 255243b7ae3..511e44c9d60 100644
--- a/components/match_table/commons/match_table.lua
+++ b/components/match_table/commons/match_table.lua
@@ -24,9 +24,10 @@ local Team = require('Module:Team')
local Tier = require('Module:Tier/Custom')
local VodLink = require('Module:VodLink')
+local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper')
local PlayerExt = Lua.import('Module:Player/Ext')
-local OpponentLibraries = require('Module:OpponentLibraries')
+local OpponentLibraries = Lua.import('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent
local OpponentDisplay = OpponentLibraries.OpponentDisplay
@@ -38,8 +39,7 @@ local BooleanOperator = Condition.BooleanOperator
local ColumnName = Condition.ColumnName
local UTC = 'UTC'
-local DRAW = 'draw'
-local RESULT_TYPE_DEFAULT = 'default'
+local DRAW_WINNER = 0
local INVALID_TIER_DISPLAY = 'Undefined'
local INVALID_TIER_SORT = 'ZZ'
local SCORE_STATUS = 'S'
@@ -89,7 +89,6 @@ local SCORE_CONCAT = ' : '
---@field opponent match2opponent
---@field vs match2opponent
---@field winner number
----@field resultType string?
---@field countGames boolean
---@class MatchTable
@@ -288,7 +287,7 @@ function MatchTable:query()
conditions = self:buildConditions(),
order = 'date desc',
query = 'match2opponents, match2games, date, dateexact, icon, icondark, liquipediatier, game, type, '
- .. 'liquipediatiertype, tournament, pagename, tickername, vod, winner, walkover, resulttype, extradata',
+ .. 'liquipediatiertype, tournament, pagename, tickername, vod, winner, extradata',
}, function(match)
table.insert(self.matches, self:matchFromRecord(match) or nil)
end, self.config.limit)
@@ -357,7 +356,7 @@ end
function MatchTable:buildAdditionalConditions()
local args = self.args
local conditions = ConditionTree(BooleanOperator.all)
- :add{ConditionNode(ColumnName('resulttype'), Comparator.neq, 'np')}
+ :add{ConditionNode(ColumnName('status'), Comparator.neq, 'notplayed')}
local hasAdditionalConditions = false
local getOrCondition = function(lpdbKey, input)
@@ -467,7 +466,6 @@ function MatchTable:resultFromRecord(record)
opponent = record.match2opponents[indexes[1]],
vs = record.match2opponents[indexes[2]],
winner = winner,
- resultType = record.resultType,
countGames = countGames,
}
@@ -490,10 +488,10 @@ function MatchTable:statsFromMatches()
end
Array.forEach(self.matches, function(match)
- if match.result.resultType == RESULT_TYPE_DEFAULT then
- return
- elseif match.result.resultType == DRAW then
+ if match.result.winner == DRAW_WINNER then
totalMatches.d = totalMatches.d + 1
+ elseif MatchOpponentHelper.calculateWalkoverType{match.result.opponent, match.result.vs} then
+ return
elseif match.result.winner == 1 then
totalMatches.w = totalMatches.w + 1
elseif match.result.winner == 2 then
diff --git a/definitions/liquipedia_db.lua b/definitions/liquipedia_db.lua
index 985701f43df..52a4c9483b9 100644
--- a/definitions/liquipedia_db.lua
+++ b/definitions/liquipedia_db.lua
@@ -249,8 +249,6 @@ local lpdb = {}
---@field match2id string
---@field match2bracketid string
---@field winner integer
----@field walkover WalkoverType
----@field resulttype ResultType
---@field finished integer
---@field mode string
---@field type string
@@ -292,11 +290,7 @@ local lpdb = {}
---@field match2id string
---@field match2gameid integer
---@field subgroup integer
----@field scores number[]
----@field participants table
---@field winner integer
----@field walkover WalkoverType
----@field resulttype ResultType
---@field mode string
---@field type string
---@field game string
diff --git a/spec/orm_spec.lua b/spec/orm_spec.lua
index c52372b1d48..a39de6abd09 100644
--- a/spec/orm_spec.lua
+++ b/spec/orm_spec.lua
@@ -55,7 +55,6 @@ describe('LPDB Object-Relational Mapping', function()
parent = '',
patch = '',
publishertier = '',
- resulttype = '',
section = '',
series = '',
shortname = '',
@@ -64,7 +63,6 @@ describe('LPDB Object-Relational Mapping', function()
tournament = '',
type = '',
vod = '',
- walkover = '',
winner = '',
})
stub:revert()
diff --git a/standard/lpdb.lua b/standard/lpdb.lua
index 566ed9cbb54..da9f1cfcd65 100644
--- a/standard/lpdb.lua
+++ b/standard/lpdb.lua
@@ -41,7 +41,7 @@ example:
conditions = conditions,
order = 'date ' .. args.order,
limit = _LPDB_QUERY_LIMIT,
- query = 'pagename, winner, walkover, finished, date, dateexact, links, '
+ query = 'pagename, winner, finished, date, dateexact, links, '
.. 'bestof, vod, tournament, tickername, shortname, icon, icondark, '
.. 'extradata, match2opponents, match2games, mode, match2id, match2bracketid',
}
@@ -197,8 +197,6 @@ Lpdb.Match2 = Model('match2', {
{name = 'match2id', fieldType = 'string'},
{name = 'match2bracketid', fieldType = 'string'},
{name = 'winner', fieldType = 'string', default = ''},
- {name = 'walkover', fieldType = 'string', default = ''},
- {name = 'resulttype', fieldType = 'string', default = ''},
{name = 'finished', fieldType = 'number', default = 0},
{name = 'mode', fieldType = 'string', default = ''},
{name = 'type', fieldType = 'string', default = ''},