From 6b843906578ae54a2440735e11fbe241524f5d22 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sat, 21 Dec 2024 12:06:16 +0100 Subject: [PATCH 01/18] feat(various): remove some `resulttype` usage --- components/game_table/commons/game_table.lua | 4 ++-- .../game_table/commons/game_table_character.lua | 6 +++--- .../starcraft2/infobox_person_player_custom.lua | 2 +- components/match_table/commons/match_table.lua | 16 +++++++--------- definitions/liquipedia_db.lua | 4 ++-- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/components/game_table/commons/game_table.lua b/components/game_table/commons/game_table.lua index d627990b15f..98bb7fa03ba 100644 --- a/components/game_table/commons/game_table.lua +++ b/components/game_table/commons/game_table.lua @@ -15,7 +15,7 @@ local VodLink = require('Module:VodLink') local MatchTable = Lua.import('Module:MatchTable') -local NOT_PLAYED = 'np' +local NOT_PLAYED = 'notplayed' local SCORE_CONCAT = ' : ' ---@class GameTableMatch: MatchTableMatch @@ -31,7 +31,7 @@ end) ---@return match2game? function GameTable:gameFromRecord(game) if self.countGames == self.config.limit then return nil end - if game.resulttype == NOT_PLAYED or Logic.isEmpty(game.winner) then + if game.status == NOT_PLAYED or Logic.isEmpty(game.winner) then return nil end diff --git a/components/game_table/commons/game_table_character.lua b/components/game_table/commons/game_table_character.lua index 500d35d89ca..c4fd1076ed8 100644 --- a/components/game_table/commons/game_table_character.lua +++ b/components/game_table/commons/game_table_character.lua @@ -23,7 +23,7 @@ local Comparator = Condition.Comparator local BooleanOperator = Condition.BooleanOperator local ColumnName = Condition.ColumnName -local DRAW = 'draw' +local DRAW_WINNER = 0 local CHARACTER_MODE = 'character' local SCORE_CONCAT = ' : ' @@ -181,6 +181,7 @@ end ---@param game CharacterGameTableGame ---@param maxNumber number ---@param keyMaker fun(self, opponentIndex, playerIndex) +---@return table[] function CharacterGameTable:getCharacters(game, maxNumber, keyMaker) ---@param opponentIndex number ---@return table @@ -246,7 +247,6 @@ function CharacterGameTable:resultFromRecord(record) opponent = record.match2opponents[1], vs = record.match2opponents[2], winner = tonumber(record.winner), - resultType = record.resultType, countGames = true, } end @@ -260,7 +260,7 @@ function CharacterGameTable:statsFromMatches() Array.forEach(match.games, function (game, index) local winner = tonumber(game.winner) - if game.resulttype == DRAW then + if game.winner == DRAW_WINNER then totalGames.d = totalGames.d + 1 elseif game.pickedBy == winner then totalGames.w = totalGames.w + 1 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/match_table/commons/match_table.lua b/components/match_table/commons/match_table.lua index 255243b7ae3..6ffbdca1a21 100644 --- a/components/match_table/commons/match_table.lua +++ b/components/match_table/commons/match_table.lua @@ -38,8 +38,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 +88,6 @@ local SCORE_CONCAT = ' : ' ---@field opponent match2opponent ---@field vs match2opponent ---@field winner number ----@field resultType string? ---@field countGames boolean ---@class MatchTable @@ -288,7 +286,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, walkover, extradata', }, function(match) table.insert(self.matches, self:matchFromRecord(match) or nil) end, self.config.limit) @@ -357,7 +355,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 +465,6 @@ function MatchTable:resultFromRecord(record) opponent = record.match2opponents[indexes[1]], vs = record.match2opponents[indexes[2]], winner = winner, - resultType = record.resultType, countGames = countGames, } @@ -490,10 +487,11 @@ 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 Array.any({match.result.opponent, match.result.vs}, function(opponent) + return opponent.status ~= SCORE_STATUS + end) 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..d2828583b53 100644 --- a/definitions/liquipedia_db.lua +++ b/definitions/liquipedia_db.lua @@ -250,7 +250,7 @@ local lpdb = {} ---@field match2bracketid string ---@field winner integer ---@field walkover WalkoverType ----@field resulttype ResultType +---@field resulttype ResultType ---@deprecated ---@field finished integer ---@field mode string ---@field type string @@ -296,7 +296,7 @@ local lpdb = {} ---@field participants table ---@field winner integer ---@field walkover WalkoverType ----@field resulttype ResultType +---@field resulttype ResultType ---@deprecated ---@field mode string ---@field type string ---@field game string From b20bf8cb4562a5db9e1689555d6d30d441eb7f81 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sat, 21 Dec 2024 12:53:35 +0100 Subject: [PATCH 02/18] some more --- .../commons/match_group_display_helper.lua | 27 +++++++------- .../commons/match_group_display_matchlist.lua | 11 +++--- .../match2/commons/match_group_util.lua | 21 ++++------- .../match2/commons/match_opponent_helper.lua | 36 +++++++++++++++++++ .../match_table/commons/match_table.lua | 8 ++--- 5 files changed, 67 insertions(+), 36 deletions(-) create mode 100644 components/match2/commons/match_opponent_helper.lua diff --git a/components/match2/commons/match_group_display_helper.lua b/components/match2/commons/match_group_display_helper.lua index 7e4940dcc0d..9d0ac82a390 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,7 +171,7 @@ function DisplayHelper.Map(game, config) else mapText = game.map or 'Unknown' end - if game.resultType == 'np' then + if game.status == 'notplayed' then mapText = '' .. mapText .. '' end return mapText 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 c487cf6890f..2cbafc6495c 100644 --- a/components/match2/commons/match_group_util.lua +++ b/components/match2/commons/match_group_util.lua @@ -209,13 +209,14 @@ MatchGroupUtil.types.Walkover = TypeUtil.literalUnion('l', 'ff', 'dq') ---@field mode string? ---@field opponents {players: table[]}[] ---@field participants table ----@field resultType ResultType? +---@field resultType ResultType? ---@deprecated ---@field scores number[] ---@field subgroup number? ---@field type string? ---@field vod string? ---@field walkover WalkoverType? ---@field winner integer? +---@field status string? ---@field extradata table? MatchGroupUtil.types.Game = TypeUtil.struct({ comment = 'string?', @@ -249,7 +250,7 @@ MatchGroupUtil.types.Game = TypeUtil.struct({ ---@field matchId string? ---@field mode string? ---@field opponents standardOpponent[] ----@field resultType ResultType? +---@field resultType ResultType? ---@deprecated ---@field status MatchStatus ---@field stream table ---@field tickername string? @@ -622,18 +623,9 @@ function MatchGroupUtil.opponentFromRecord(matchRecord, record, opponentIndex) local bestof = tonumber(matchRecord.bestof) local game1 = (matchRecord.match2games or {})[1] if bestof == 1 and Info.config.match2.gameScoresIfBo1 and game1 then - local winner = tonumber(game1.winner) - if game1.resulttype == 'default' then - score = -1 - if winner == 0 then - status = 'D' - else - status = winner == opponentIndex and 'W' or string.upper(game1.walkover) - end - elseif game1.scores[opponentIndex] then - score = game1.scores[opponentIndex] - status = 'S' - end + local mapOpponent = (game1.opponnets or {})[opponentIndex] or {} + score = mapOpponent.score + status = mapOpponent.status end return { @@ -699,6 +691,7 @@ function MatchGroupUtil.gameFromRecord(record, opponentCount) opponents = record.opponents, participants = Json.parseIfString(record.participants) or {}, resultType = nilIfEmpty(record.resulttype), + status = nilIfEmpty(record.status), scores = Json.parseIfString(record.scores) or {}, subgroup = tonumber(record.subgroup), type = nilIfEmpty(record.type), diff --git a/components/match2/commons/match_opponent_helper.lua b/components/match2/commons/match_opponent_helper.lua new file mode 100644 index 00000000000..f8f3ecd8910 --- /dev/null +++ b/components/match2/commons/match_opponent_helper.lua @@ -0,0 +1,36 @@ +--- +-- @Liquipedia +-- wiki=commons +-- page=Module:MatchOpponentHelper +-- +-- Please see https://github.com/Liquipedia/Lua-Modules to contribute +-- + +local Array = require('Module:Array') +local Logic = require('Module:Logic') +local Operator = require('Module:Operator') + + +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/match_table/commons/match_table.lua b/components/match_table/commons/match_table.lua index 6ffbdca1a21..f4fcadaffac 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 @@ -489,9 +490,8 @@ function MatchTable:statsFromMatches() Array.forEach(self.matches, function(match) if match.result.winner == DRAW_WINNER then totalMatches.d = totalMatches.d + 1 - elseif Array.any({match.result.opponent, match.result.vs}, function(opponent) - return opponent.status ~= SCORE_STATUS - end) then return + 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 From 37a4e637cfd3cb9c33618672c4029cc25712c2b7 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sat, 21 Dec 2024 14:04:25 +0100 Subject: [PATCH 03/18] some more --- .../match2/commons/match_opponent_helper.lua | 2 - .../match_group_util_starcraft.lua | 118 ++++++------------ .../match_summary_starcraft.lua | 13 +- .../wikis/ageofempires/match_legacy.lua | 10 +- .../match2/wikis/arenafps/match_legacy.lua | 8 +- .../wikis/counterstrike/match_summary.lua | 2 +- components/match2/wikis/dota2/match_page.lua | 4 +- .../wikis/leagueoflegends/match_page.lua | 4 +- .../match2/wikis/rainbowsix/match_summary.lua | 2 +- .../match2/wikis/stormgate/match_summary.lua | 2 +- .../match2/wikis/warcraft/match_summary.lua | 2 +- .../match_table/commons/match_table.lua | 2 +- 12 files changed, 61 insertions(+), 108 deletions(-) diff --git a/components/match2/commons/match_opponent_helper.lua b/components/match2/commons/match_opponent_helper.lua index f8f3ecd8910..1f1b7668c5e 100644 --- a/components/match2/commons/match_opponent_helper.lua +++ b/components/match2/commons/match_opponent_helper.lua @@ -7,8 +7,6 @@ -- local Array = require('Module:Array') -local Logic = require('Module:Logic') -local Operator = require('Module:Operator') local MatchOpponentHelper = {} 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..0bf5448753c 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 @@ -44,10 +46,7 @@ local StarcraftMatchGroupUtil = Table.deepCopy(MatchGroupUtil) ---@field games StarcraftMatchGroupUtilGame[] ---@field mode string ---@field opponents StarcraftMatchGroupUtilGameOpponent[] ----@field resultType ResultType ----@field scores table ---@field subgroup number ----@field walkover WalkoverType ---@field winner number? ---@field header string? @@ -88,11 +87,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 +189,53 @@ 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 {} + 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 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/wikis/ageofempires/match_legacy.lua b/components/match2/wikis/ageofempires/match_legacy.lua index 2997af52d68..4cc463427d4 100644 --- a/components/match2/wikis/ageofempires/match_legacy.lua +++ b/components/match2/wikis/ageofempires/match_legacy.lua @@ -15,6 +15,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 @@ -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/arenafps/match_legacy.lua b/components/match2/wikis/arenafps/match_legacy.lua index 69d12fe000e..f598027c929 100644 --- a/components/match2/wikis/arenafps/match_legacy.lua +++ b/components/match2/wikis/arenafps/match_legacy.lua @@ -10,9 +10,12 @@ local MatchLegacy = {} local Array = require('Module:Array') 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') + ---@param match2 table function MatchLegacy.storeMatch(match2) local match = MatchLegacy._convertParameters(match2) @@ -85,8 +88,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/counterstrike/match_summary.lua b/components/match2/wikis/counterstrike/match_summary.lua index 5a931e3ce3d..a3dc504f105 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/dota2/match_page.lua b/components/match2/wikis/dota2/match_page.lua index 8d99e652ab1..73009d897a7 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 @@ -237,7 +237,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/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/rainbowsix/match_summary.lua b/components/match2/wikis/rainbowsix/match_summary.lua index 79e46e8b62b..0982d4be597 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/stormgate/match_summary.lua b/components/match2/wikis/stormgate/match_summary.lua index 2687c139cb0..cd3ab718815 100644 --- a/components/match2/wikis/stormgate/match_summary.lua +++ b/components/match2/wikis/stormgate/match_summary.lua @@ -219,7 +219,7 @@ function CustomMatchSummary.TeamSubmatch(submatch) } end ----@param submatch StarcraftMatchGroupUtilSubmatch +---@param submatch StormgateMatchGroupUtilSubmatch ---@return Widget function CustomMatchSummary.TeamSubMatchOpponnetRow(submatch) local opponents = submatch.opponents or {{}, {}} diff --git a/components/match2/wikis/warcraft/match_summary.lua b/components/match2/wikis/warcraft/match_summary.lua index d421dd0b791..608407de2ae 100644 --- a/components/match2/wikis/warcraft/match_summary.lua +++ b/components/match2/wikis/warcraft/match_summary.lua @@ -220,7 +220,7 @@ function CustomMatchSummary.TeamSubmatch(submatch) } end ----@param submatch StarcraftMatchGroupUtilSubmatch +---@param submatch WarcraftMatchGroupUtilSubmatch ---@return Widget function CustomMatchSummary.TeamSubMatchOpponnetRow(submatch) local opponents = submatch.opponents or {{}, {}} diff --git a/components/match_table/commons/match_table.lua b/components/match_table/commons/match_table.lua index f4fcadaffac..511e44c9d60 100644 --- a/components/match_table/commons/match_table.lua +++ b/components/match_table/commons/match_table.lua @@ -287,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, extradata', + .. 'liquipediatiertype, tournament, pagename, tickername, vod, winner, extradata', }, function(match) table.insert(self.matches, self:matchFromRecord(match) or nil) end, self.config.limit) From e427d9012a99f74f5ab9008f7de4b50f7535dc53 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sat, 21 Dec 2024 14:13:46 +0100 Subject: [PATCH 04/18] some more --- components/match2/wikis/criticalops/match_legacy.lua | 9 ++++++--- components/match2/wikis/zula/match_legacy.lua | 11 +++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/components/match2/wikis/criticalops/match_legacy.lua b/components/match2/wikis/criticalops/match_legacy.lua index f729e26ebf4..cc28ace6569 100644 --- a/components/match2/wikis/criticalops/match_legacy.lua +++ b/components/match2/wikis/criticalops/match_legacy.lua @@ -13,6 +13,7 @@ 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 +40,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 @@ -207,7 +209,8 @@ function MatchLegacy.storeGames(match, match2) 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(game.opponents) + if walkover == 'FF' or walkover == 'DQ' then game.walkover = 1 end diff --git a/components/match2/wikis/zula/match_legacy.lua b/components/match2/wikis/zula/match_legacy.lua index 461e81bf4fe..933fcd7d677 100644 --- a/components/match2/wikis/zula/match_legacy.lua +++ b/components/match2/wikis/zula/match_legacy.lua @@ -13,9 +13,10 @@ 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 +40,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 @@ -207,7 +209,8 @@ function MatchLegacy.storeGames(match, match2) 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(game2.opponents) + if walkover == 'FF' or walkover == 'DQ' then game.walkover = 1 end From 09027d06483f8eebd30d5ab3dcb13b4ad07fe552 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sat, 21 Dec 2024 15:01:04 +0100 Subject: [PATCH 05/18] some more --- .../match2/wikis/artifact/match_legacy.lua | 9 ++++++--- .../match2/wikis/brawlhalla/match_legacy.lua | 10 +++++----- .../match2/wikis/brawlstars/match_legacy.lua | 10 ++++++---- .../wikis/counterstrike/match_legacy.lua | 10 ++++++---- .../match2/wikis/criticalops/match_legacy.lua | 2 +- components/match2/wikis/dota2/match_legacy.lua | 6 ++++-- .../match2/wikis/rocketleague/match_legacy.lua | 18 +++++++++++------- .../match2/wikis/sideswipe/match_legacy.lua | 8 ++++++-- components/match2/wikis/smash/match_legacy.lua | 10 ++++++---- .../match2/wikis/splatoon/match_legacy.lua | 10 ++++++---- .../match2/wikis/starcraft/match_legacy.lua | 14 ++++++++------ .../match2/wikis/tetris/match_legacy.lua | 8 ++++++-- .../match2/wikis/trackmania/match_legacy.lua | 9 ++++++--- .../match2/wikis/valorant/match_legacy.lua | 8 +++++--- .../match2/wikis/warcraft/match_legacy.lua | 17 ++++++++++------- .../match2/wikis/wildrift/match_legacy.lua | 8 ++++++-- 16 files changed, 98 insertions(+), 59 deletions(-) diff --git a/components/match2/wikis/artifact/match_legacy.lua b/components/match2/wikis/artifact/match_legacy.lua index ce363269445..6d30df3ddc3 100644 --- a/components/match2/wikis/artifact/match_legacy.lua +++ b/components/match2/wikis/artifact/match_legacy.lua @@ -10,10 +10,12 @@ 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 MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper') + function MatchLegacy.storeMatch(match2) local match = MatchLegacy._convertParameters(match2) match.games = MatchLegacy.storeGames(match, 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/brawlhalla/match_legacy.lua b/components/match2/wikis/brawlhalla/match_legacy.lua index 9896954af65..95872b8d89c 100644 --- a/components/match2/wikis/brawlhalla/match_legacy.lua +++ b/components/match2/wikis/brawlhalla/match_legacy.lua @@ -16,10 +16,10 @@ 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 +34,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 diff --git a/components/match2/wikis/brawlstars/match_legacy.lua b/components/match2/wikis/brawlstars/match_legacy.lua index f08f2e6256b..8230ac2f026 100644 --- a/components/match2/wikis/brawlstars/match_legacy.lua +++ b/components/match2/wikis/brawlstars/match_legacy.lua @@ -13,6 +13,7 @@ local Lua = require('Module:Lua') 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) @@ -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/counterstrike/match_legacy.lua b/components/match2/wikis/counterstrike/match_legacy.lua index f16c4581e06..66a6e24046a 100644 --- a/components/match2/wikis/counterstrike/match_legacy.lua +++ b/components/match2/wikis/counterstrike/match_legacy.lua @@ -13,7 +13,7 @@ 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 +40,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 @@ -213,7 +214,8 @@ function MatchLegacy.storeGames(match, match2) 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(game2.opponents) + if walkover == 'FF' or walkover == 'DQ' then game.walkover = 1 end diff --git a/components/match2/wikis/criticalops/match_legacy.lua b/components/match2/wikis/criticalops/match_legacy.lua index cc28ace6569..6067bbded8b 100644 --- a/components/match2/wikis/criticalops/match_legacy.lua +++ b/components/match2/wikis/criticalops/match_legacy.lua @@ -209,7 +209,7 @@ function MatchLegacy.storeGames(match, match2) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 - local walkover = MatchOpponentHelper.calculateWalkoverType(game.opponents) + local walkover = MatchOpponentHelper.calculateWalkoverType(game2.opponents) if walkover == 'FF' or walkover == 'DQ' then game.walkover = 1 end diff --git a/components/match2/wikis/dota2/match_legacy.lua b/components/match2/wikis/dota2/match_legacy.lua index 6418bd9fec4..0451d3075a8 100644 --- a/components/match2/wikis/dota2/match_legacy.lua +++ b/components/match2/wikis/dota2/match_legacy.lua @@ -15,6 +15,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 _NUMBER_OF_PLAYERS_TO_STORE = 10 @@ -38,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/rocketleague/match_legacy.lua b/components/match2/wikis/rocketleague/match_legacy.lua index 5d1722258f2..d640b6ac699 100644 --- a/components/match2/wikis/rocketleague/match_legacy.lua +++ b/components/match2/wikis/rocketleague/match_legacy.lua @@ -8,10 +8,13 @@ local MatchLegacy = {} -local json = require('Module:Json') +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) @@ -34,7 +37,7 @@ function MatchLegacy.storeGames(match, match2) game.date = match.date local scores = game.scores or {} if type(scores) == 'string' then - scores = json.parse(scores) + scores = Json.parse(scores) end game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 @@ -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/sideswipe/match_legacy.lua b/components/match2/wikis/sideswipe/match_legacy.lua index 3543b1a11ea..07dfd6140eb 100644 --- a/components/match2/wikis/sideswipe/match_legacy.lua +++ b/components/match2/wikis/sideswipe/match_legacy.lua @@ -9,9 +9,12 @@ local p = {} 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') + local MAX_NUM_PLAYERS = 10 function p.storeMatch(match2) @@ -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..199b1e3ba52 100644 --- a/components/match2/wikis/smash/match_legacy.lua +++ b/components/match2/wikis/smash/match_legacy.lua @@ -18,6 +18,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 @@ -74,11 +75,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 diff --git a/components/match2/wikis/splatoon/match_legacy.lua b/components/match2/wikis/splatoon/match_legacy.lua index 752e77c1c5c..57a46dc9df1 100644 --- a/components/match2/wikis/splatoon/match_legacy.lua +++ b/components/match2/wikis/splatoon/match_legacy.lua @@ -14,6 +14,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') function MatchLegacy.storeMatch(match2) local match = MatchLegacy._convertParameters(match2) @@ -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/starcraft/match_legacy.lua b/components/match2/wikis/starcraft/match_legacy.lua index 938487814e6..be794398ef4 100644 --- a/components/match2/wikis/starcraft/match_legacy.lua +++ b/components/match2/wikis/starcraft/match_legacy.lua @@ -10,10 +10,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 Template = require('Module:Template') +local MatchOpponentHelper = Lua.import('Module:MatchOpponentHelper') + local _MODES = {solo = '1v1', team = 'team'} function MatchLegacy.storeMatch(match2) @@ -94,11 +97,9 @@ function MatchLegacy._storeGames(match, match2) submatch.extradata['opponent' .. k .. 'name'] = (pl[l] or {}).displayname end submatch.winner = game.winner or '' - submatch.walkover = game.walkover or '' + local walkover = MatchOpponentHelper.calculateWalkoverType(game.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 +176,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/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..71d090620d1 100644 --- a/components/match2/wikis/trackmania/match_legacy.lua +++ b/components/match2/wikis/trackmania/match_legacy.lua @@ -9,12 +9,14 @@ local MatchLegacy = {} local Json = require('Module:Json') +local Lua = require('Module:Lua') 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) @@ -58,9 +60,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..acec0c6f768 100644 --- a/components/match2/wikis/valorant/match_legacy.lua +++ b/components/match2/wikis/valorant/match_legacy.lua @@ -17,6 +17,7 @@ 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) @@ -122,10 +123,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 diff --git a/components/match2/wikis/warcraft/match_legacy.lua b/components/match2/wikis/warcraft/match_legacy.lua index 4b6f74061bb..4412ff1ea83 100644 --- a/components/match2/wikis/warcraft/match_legacy.lua +++ b/components/match2/wikis/warcraft/match_legacy.lua @@ -18,6 +18,7 @@ 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 +127,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 @@ -234,7 +236,7 @@ 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 objectName = match.objectName .. '_Map_' .. gameIndex @@ -262,9 +264,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(game2.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 diff --git a/components/match2/wikis/wildrift/match_legacy.lua b/components/match2/wikis/wildrift/match_legacy.lua index 8ab4e36f023..44c5da76481 100644 --- a/components/match2/wikis/wildrift/match_legacy.lua +++ b/components/match2/wikis/wildrift/match_legacy.lua @@ -10,9 +10,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 +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 From 755680d85be66c26d4435a253129413e73158ab4 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sat, 21 Dec 2024 15:08:49 +0100 Subject: [PATCH 06/18] some more --- components/match2/wikis/easportsfc/match_legacy.lua | 8 ++++++-- components/match2/wikis/fighters/match_legacy.lua | 3 ++- components/match2/wikis/halo/match_legacy.lua | 8 ++++++-- components/match2/wikis/hearthstone/match_legacy.lua | 9 ++++++--- components/match2/wikis/heroes/match_legacy.lua | 8 ++++++-- components/match2/wikis/honorofkings/match_legacy.lua | 9 ++++++--- components/match2/wikis/leagueoflegends/match_legacy.lua | 8 +++++--- components/match2/wikis/mobilelegends/match_legacy.lua | 9 ++++++--- components/match2/wikis/paladins/match_legacy.lua | 8 ++++++-- components/match2/wikis/pokemon/match_legacy.lua | 8 ++++++-- 10 files changed, 55 insertions(+), 23 deletions(-) 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/fighters/match_legacy.lua b/components/match2/wikis/fighters/match_legacy.lua index b1fcf65119e..4b992461fb3 100644 --- a/components/match2/wikis/fighters/match_legacy.lua +++ b/components/match2/wikis/fighters/match_legacy.lua @@ -18,6 +18,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 @@ -74,7 +75,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 diff --git a/components/match2/wikis/halo/match_legacy.lua b/components/match2/wikis/halo/match_legacy.lua index 4e4a3a878ef..1c88c28ff9a 100644 --- a/components/match2/wikis/halo/match_legacy.lua +++ b/components/match2/wikis/halo/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') + local MAX_NUM_PLAYERS = 10 function MatchLegacy.storeMatch(match2) @@ -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/match_legacy.lua b/components/match2/wikis/heroes/match_legacy.lua index 4113c67e32a..fe411d8a4dc 100644 --- a/components/match2/wikis/heroes/match_legacy.lua +++ b/components/match2/wikis/heroes/match_legacy.lua @@ -10,10 +10,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 +42,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_legacy.lua b/components/match2/wikis/leagueoflegends/match_legacy.lua index 10548f22fe8..7cada31e557 100644 --- a/components/match2/wikis/leagueoflegends/match_legacy.lua +++ b/components/match2/wikis/leagueoflegends/match_legacy.lua @@ -15,6 +15,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 _NUMBER_OF_PLAYERS_TO_STORE = 10 @@ -38,12 +39,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/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/paladins/match_legacy.lua b/components/match2/wikis/paladins/match_legacy.lua index caed4ff300b..decb0319ede 100644 --- a/components/match2/wikis/paladins/match_legacy.lua +++ b/components/match2/wikis/paladins/match_legacy.lua @@ -11,9 +11,12 @@ 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 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 diff --git a/components/match2/wikis/pokemon/match_legacy.lua b/components/match2/wikis/pokemon/match_legacy.lua index 10b96648dbb..28f0571fe26 100644 --- a/components/match2/wikis/pokemon/match_legacy.lua +++ b/components/match2/wikis/pokemon/match_legacy.lua @@ -10,9 +10,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 +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 = match.walkover:lower() match.walkover = match.winner end From df671a087f5636b9cb9bafd1b73e28222b1aaeee Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sat, 21 Dec 2024 15:22:05 +0100 Subject: [PATCH 07/18] some more --- .../match_group_util_starcraft.lua | 1 + .../stormgate/match_group_util_custom.lua | 95 +++++++------------ .../match2/wikis/stormgate/match_summary.lua | 13 +-- .../warcraft/match_group_util_custom.lua | 95 +++++++------------ .../match2/wikis/warcraft/match_summary.lua | 13 +-- 5 files changed, 69 insertions(+), 148 deletions(-) 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 0bf5448753c..3dfc3657bd1 100644 --- a/components/match2/commons/starcraft_starcraft2/match_group_util_starcraft.lua +++ b/components/match2/commons/starcraft_starcraft2/match_group_util_starcraft.lua @@ -45,6 +45,7 @@ local StarcraftMatchGroupUtil = Table.deepCopy(MatchGroupUtil) ---@class StarcraftMatchGroupUtilSubmatch ---@field games StarcraftMatchGroupUtilGame[] ---@field mode string +---@field status string? ---@field opponents StarcraftMatchGroupUtilGameOpponent[] ---@field subgroup number ---@field winner number? diff --git a/components/match2/wikis/stormgate/match_group_util_custom.lua b/components/match2/wikis/stormgate/match_group_util_custom.lua index 0a9681a5f6e..34afad6f1c7 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,45 @@ 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 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 cd3ab718815..af5d443ac01 100644 --- a/components/match2/wikis/stormgate/match_summary.lua +++ b/components/match2/wikis/stormgate/match_summary.lua @@ -240,18 +240,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/warcraft/match_group_util_custom.lua b/components/match2/wikis/warcraft/match_group_util_custom.lua index e241445b8db..b702f233bdb 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,45 @@ 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 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_summary.lua b/components/match2/wikis/warcraft/match_summary.lua index 608407de2ae..531d21f04d2 100644 --- a/components/match2/wikis/warcraft/match_summary.lua +++ b/components/match2/wikis/warcraft/match_summary.lua @@ -241,18 +241,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 From 24aac3c7e4ce35b119cbef19deb01e2a4d63e391 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sat, 21 Dec 2024 15:26:33 +0100 Subject: [PATCH 08/18] linter: unused import --- components/match2/wikis/dota2/match_legacy.lua | 1 - components/match2/wikis/heroes/match_legacy.lua | 1 - components/match2/wikis/leagueoflegends/match_legacy.lua | 1 - components/match2/wikis/paladins/match_legacy.lua | 1 - components/match2/wikis/pokemon/match_legacy.lua | 1 - components/match2/wikis/wildrift/match_legacy.lua | 1 - 6 files changed, 6 deletions(-) diff --git a/components/match2/wikis/dota2/match_legacy.lua b/components/match2/wikis/dota2/match_legacy.lua index 0451d3075a8..7fe1caf0a8c 100644 --- a/components/match2/wikis/dota2/match_legacy.lua +++ b/components/match2/wikis/dota2/match_legacy.lua @@ -9,7 +9,6 @@ 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') diff --git a/components/match2/wikis/heroes/match_legacy.lua b/components/match2/wikis/heroes/match_legacy.lua index fe411d8a4dc..724871ad5a5 100644 --- a/components/match2/wikis/heroes/match_legacy.lua +++ b/components/match2/wikis/heroes/match_legacy.lua @@ -9,7 +9,6 @@ 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') diff --git a/components/match2/wikis/leagueoflegends/match_legacy.lua b/components/match2/wikis/leagueoflegends/match_legacy.lua index 7cada31e557..62b61762261 100644 --- a/components/match2/wikis/leagueoflegends/match_legacy.lua +++ b/components/match2/wikis/leagueoflegends/match_legacy.lua @@ -9,7 +9,6 @@ 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') diff --git a/components/match2/wikis/paladins/match_legacy.lua b/components/match2/wikis/paladins/match_legacy.lua index decb0319ede..c773218e191 100644 --- a/components/match2/wikis/paladins/match_legacy.lua +++ b/components/match2/wikis/paladins/match_legacy.lua @@ -10,7 +10,6 @@ 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') diff --git a/components/match2/wikis/pokemon/match_legacy.lua b/components/match2/wikis/pokemon/match_legacy.lua index 28f0571fe26..2f91b90536c 100644 --- a/components/match2/wikis/pokemon/match_legacy.lua +++ b/components/match2/wikis/pokemon/match_legacy.lua @@ -9,7 +9,6 @@ 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') diff --git a/components/match2/wikis/wildrift/match_legacy.lua b/components/match2/wikis/wildrift/match_legacy.lua index 44c5da76481..052906f307d 100644 --- a/components/match2/wikis/wildrift/match_legacy.lua +++ b/components/match2/wikis/wildrift/match_legacy.lua @@ -9,7 +9,6 @@ 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') From f139b259ec81331ee2f2b2dcec459fe964f0a75f Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Sun, 22 Dec 2024 21:30:19 +0100 Subject: [PATCH 09/18] Apply suggestions from code review --- .../starcraft_starcraft2/match_group_util_starcraft.lua | 5 ++++- .../match2/wikis/stormgate/match_group_util_custom.lua | 4 +++- components/match2/wikis/warcraft/match_group_util_custom.lua | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) 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 3dfc3657bd1..5dcb75099d5 100644 --- a/components/match2/commons/starcraft_starcraft2/match_group_util_starcraft.lua +++ b/components/match2/commons/starcraft_starcraft2/match_group_util_starcraft.lua @@ -212,6 +212,7 @@ function StarcraftMatchGroupUtil.constructSubmatch(games, match) 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) @@ -224,7 +225,9 @@ function StarcraftMatchGroupUtil.constructSubmatch(games, match) Array.forEach(opponents, getOpponentScoreAndStatus) - local allPlayed = Array.all(games, function (game) return game.winner ~= nil 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) diff --git a/components/match2/wikis/stormgate/match_group_util_custom.lua b/components/match2/wikis/stormgate/match_group_util_custom.lua index 34afad6f1c7..d97f076b975 100644 --- a/components/match2/wikis/stormgate/match_group_util_custom.lua +++ b/components/match2/wikis/stormgate/match_group_util_custom.lua @@ -207,7 +207,9 @@ function CustomMatchGroupUtil.constructSubmatch(games, match) Array.forEach(opponents, getOpponentScoreAndStatus) - local allPlayed = Array.all(games, function (game) return game.winner ~= nil 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) diff --git a/components/match2/wikis/warcraft/match_group_util_custom.lua b/components/match2/wikis/warcraft/match_group_util_custom.lua index b702f233bdb..0296ea21d7a 100644 --- a/components/match2/wikis/warcraft/match_group_util_custom.lua +++ b/components/match2/wikis/warcraft/match_group_util_custom.lua @@ -198,7 +198,9 @@ function CustomMatchGroupUtil.constructSubmatch(games, match) Array.forEach(opponents, getOpponentScoreAndStatus) - local allPlayed = Array.all(games, function (game) return game.winner ~= nil 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) From c9d81b2d6ea4e53bc056b69e8a5feec89e53456a Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Mon, 23 Dec 2024 08:48:50 +0100 Subject: [PATCH 10/18] remove `game.participants` usage --- .../valorant/game_table_character_custom.lua | 20 +++---- .../match2/commons/match_group_util.lua | 4 -- .../wikis/ageofempires/match_legacy.lua | 5 +- .../wikis/ageofempires/match_summary.lua | 14 +++-- .../match2/wikis/brawlhalla/match_legacy.lua | 15 +++--- .../wikis/clashroyale/match_summary.lua | 48 ++++++----------- .../match2/wikis/deadlock/match_summary.lua | 17 +++--- .../wikis/dota2/match_group_input_custom.lua | 6 +-- components/match2/wikis/dota2/match_page.lua | 9 ++-- .../match2/wikis/easportsfc/match_summary.lua | 28 +++------- .../match2/wikis/fighters/match_legacy.lua | 22 ++++---- .../match2/wikis/fighters/match_summary.lua | 2 +- .../match_group_input_custom.lua | 6 +-- .../match2/wikis/smash/match_legacy.lua | 16 +++--- .../match2/wikis/starcraft/match_legacy.lua | 54 +++++++++---------- .../match2/wikis/stormgate/match_summary.lua | 10 ++-- .../match2/wikis/warcraft/match_legacy.lua | 53 +++++++++--------- .../match2/wikis/warcraft/match_summary.lua | 10 ++-- 18 files changed, 152 insertions(+), 187 deletions(-) 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/match2/commons/match_group_util.lua b/components/match2/commons/match_group_util.lua index 2cbafc6495c..4a5a3d8e7d3 100644 --- a/components/match2/commons/match_group_util.lua +++ b/components/match2/commons/match_group_util.lua @@ -208,8 +208,6 @@ MatchGroupUtil.types.Walkover = TypeUtil.literalUnion('l', 'ff', 'dq') ---@field mapDisplayName string? ---@field mode string? ---@field opponents {players: table[]}[] ----@field participants table ----@field resultType ResultType? ---@deprecated ---@field scores number[] ---@field subgroup number? ---@field type string? @@ -227,7 +225,6 @@ 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?', @@ -689,7 +686,6 @@ 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 {}, diff --git a/components/match2/wikis/ageofempires/match_legacy.lua b/components/match2/wikis/ageofempires/match_legacy.lua index 4cc463427d4..a7d3f1cad00 100644 --- a/components/match2/wikis/ageofempires/match_legacy.lua +++ b/components/match2/wikis/ageofempires/match_legacy.lua @@ -32,7 +32,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 @@ -55,8 +54,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 = 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/brawlhalla/match_legacy.lua b/components/match2/wikis/brawlhalla/match_legacy.lua index 95872b8d89c..6609f647f82 100644 --- a/components/match2/wikis/brawlhalla/match_legacy.lua +++ b/components/match2/wikis/brawlhalla/match_legacy.lua @@ -10,6 +10,7 @@ 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') @@ -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/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/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_page.lua b/components/match2/wikis/dota2/match_page.lua index 73009d897a7..ab1f279eefb 100644 --- a/components/match2/wikis/dota2/match_page.lua +++ b/components/match2/wikis/dota2/match_page.lua @@ -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 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 4b992461fb3..cef3851bf8c 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') @@ -33,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] + local player2 = opponents[2].players[1] 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 @@ -101,13 +102,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 @@ -125,7 +127,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 @@ -139,7 +141,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), '/') @@ -156,7 +158,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..299a0246ac9 100644 --- a/components/match2/wikis/fighters/match_summary.lua +++ b/components/match2/wikis/fighters/match_summary.lua @@ -84,7 +84,7 @@ 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 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/smash/match_legacy.lua b/components/match2/wikis/smash/match_legacy.lua index 199b1e3ba52..5d447db1c83 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') @@ -102,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 @@ -126,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 @@ -140,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), '/') @@ -157,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/starcraft/match_legacy.lua b/components/match2/wikis/starcraft/match_legacy.lua index be794398ef4..ff7b1a0b3d0 100644 --- a/components/match2/wikis/starcraft/match_legacy.lua +++ b/components/match2/wikis/starcraft/match_legacy.lua @@ -8,6 +8,7 @@ local MatchLegacy = {} +local Array = require('Module:Array') local Json = require('Module:Json') local Logic = require('Module:Logic') local Lua = require('Module:Lua') @@ -50,22 +51,19 @@ function MatchLegacy._storeGames(match, match2) 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 + local opponents = Json.parseIfString(game.opponents) or {} + 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) @@ -84,18 +82,18 @@ function MatchLegacy._storeGames(match, match2) 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 + + local opponents = Json.parseIfString(game.opponents) or {} + 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 '' local walkover = MatchOpponentHelper.calculateWalkoverType(game.opponents) submatch.walkover = (walkover or ''):lower() diff --git a/components/match2/wikis/stormgate/match_summary.lua b/components/match2/wikis/stormgate/match_summary.lua index af5d443ac01..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 diff --git a/components/match2/wikis/warcraft/match_legacy.lua b/components/match2/wikis/warcraft/match_legacy.lua index 4412ff1ea83..175989abb27 100644 --- a/components/match2/wikis/warcraft/match_legacy.lua +++ b/components/match2/wikis/warcraft/match_legacy.lua @@ -169,11 +169,13 @@ 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 {} + 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] @@ -213,22 +215,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 @@ -249,7 +251,8 @@ function MatchLegacy._storeGame(game2, gameIndex, match) game.opponent1score = game2.scores[1] game.opponent2score = game2.scores[2] - local factions, heroes = MatchLegacy._heroesAndFactionFromParticipants(game2.participants) + local opponents = Json.parseIfString(game2.opponents) or {} + local factions, heroes = MatchLegacy._heroesAndFactionFromGameOpponents(opponents) for opponentIndex = 1, 2 do game.extradata['opponent' .. opponentIndex .. 'race'] = factions[opponentIndex] or game.extradata['opponent' .. opponentIndex .. 'race'] @@ -277,18 +280,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 531d21f04d2..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 From e1e3c943c33d40ecc056188200b0df93468b609b Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 23 Dec 2024 09:04:47 +0100 Subject: [PATCH 11/18] some improvements --- components/match2/commons/match_group_display_helper.lua | 2 +- components/match2/wikis/counterstrike/match_legacy.lua | 7 +++++-- components/match2/wikis/criticalops/match_legacy.lua | 7 +++++-- components/match2/wikis/starcraft/match_legacy.lua | 9 ++++----- components/match2/wikis/warcraft/match_legacy.lua | 2 +- components/match2/wikis/zula/match_legacy.lua | 3 ++- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/components/match2/commons/match_group_display_helper.lua b/components/match2/commons/match_group_display_helper.lua index 82bb0532597..ac259f427b0 100644 --- a/components/match2/commons/match_group_display_helper.lua +++ b/components/match2/commons/match_group_display_helper.lua @@ -178,7 +178,7 @@ function DisplayHelper.Map(game, config) 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/wikis/counterstrike/match_legacy.lua b/components/match2/wikis/counterstrike/match_legacy.lua index 66a6e24046a..34067dac34c 100644 --- a/components/match2/wikis/counterstrike/match_legacy.lua +++ b/components/match2/wikis/counterstrike/match_legacy.lua @@ -6,9 +6,11 @@ -- 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') @@ -179,6 +181,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 = {}, {} @@ -207,14 +211,13 @@ 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 walkover = MatchOpponentHelper.calculateWalkoverType(game2.opponents) + local walkover = MatchOpponentHelper.calculateWalkoverType(opponents) if walkover == 'FF' or walkover == 'DQ' then game.walkover = 1 end diff --git a/components/match2/wikis/criticalops/match_legacy.lua b/components/match2/wikis/criticalops/match_legacy.lua index 6067bbded8b..bdb5c25d046 100644 --- a/components/match2/wikis/criticalops/match_legacy.lua +++ b/components/match2/wikis/criticalops/match_legacy.lua @@ -6,9 +6,11 @@ -- 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') @@ -174,6 +176,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 = {}, {} @@ -202,14 +206,13 @@ 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 walkover = MatchOpponentHelper.calculateWalkoverType(game2.opponents) + local walkover = MatchOpponentHelper.calculateWalkoverType(opponents) if walkover == 'FF' or walkover == 'DQ' then game.walkover = 1 end diff --git a/components/match2/wikis/starcraft/match_legacy.lua b/components/match2/wikis/starcraft/match_legacy.lua index ff7b1a0b3d0..31889ff686b 100644 --- a/components/match2/wikis/starcraft/match_legacy.lua +++ b/components/match2/wikis/starcraft/match_legacy.lua @@ -12,6 +12,7 @@ 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') @@ -39,19 +40,19 @@ 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 - local opponents = Json.parseIfString(game.opponents) or {} Array.forEach(opponents, function(opponent, opponentIndex) Array.forEach(opponent.players or {}, function(player, playerIndex) if Logic.isDeepEmpty(player) then return end @@ -78,12 +79,10 @@ 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 opponents = Json.parseIfString(game.opponents) or {} Array.forEach(opponents, function(opponent, opponentIndex) Array.forEach(opponent.players or {}, function(player, playerIndex) if Logic.isDeepEmpty(player) then return end @@ -95,7 +94,7 @@ function MatchLegacy._storeGames(match, match2) end) submatch.winner = game.winner or '' - local walkover = MatchOpponentHelper.calculateWalkoverType(game.opponents) + local walkover = MatchOpponentHelper.calculateWalkoverType(opponents) submatch.walkover = (walkover or ''):lower() submatch.finished = match2.finished or '0' submatch.mode = '1v1' diff --git a/components/match2/wikis/warcraft/match_legacy.lua b/components/match2/wikis/warcraft/match_legacy.lua index 175989abb27..320f409869c 100644 --- a/components/match2/wikis/warcraft/match_legacy.lua +++ b/components/match2/wikis/warcraft/match_legacy.lua @@ -267,7 +267,7 @@ function MatchLegacy._storeGame(game2, gameIndex, match) game.resulttype = nil game.walkover = nil - local walkover = MatchOpponentHelper.calculateWalkoverType(game2.opponents) + local walkover = MatchOpponentHelper.calculateWalkoverType(opponents) if walkover then game.resulttype = walkover if walkover == UNKNOWNREASON_DEFAULT_LOSS then diff --git a/components/match2/wikis/zula/match_legacy.lua b/components/match2/wikis/zula/match_legacy.lua index 933fcd7d677..dceebcce770 100644 --- a/components/match2/wikis/zula/match_legacy.lua +++ b/components/match2/wikis/zula/match_legacy.lua @@ -209,7 +209,8 @@ function MatchLegacy.storeGames(match, match2) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 - local walkover = MatchOpponentHelper.calculateWalkoverType(game2.opponents) + local opponents = Json.parseIfString(game2.opponents) or {} + local walkover = MatchOpponentHelper.calculateWalkoverType(opponents) if walkover == 'FF' or walkover == 'DQ' then game.walkover = 1 end From ac95eb95b415103221b99c81ed9d91571f24ff7c Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 23 Dec 2024 09:58:12 +0100 Subject: [PATCH 12/18] kick game.scores --- components/game_table/commons/game_table.lua | 4 +++- .../commons/game_table_character.lua | 4 +++- .../match_group_input_starcraft_ffa.lua | 3 ++- .../match_summary_starcraft_ffa.lua | 2 +- .../match2/wikis/ageofempires/match_legacy.lua | 3 ++- .../match2/wikis/arenafps/match_legacy.lua | 4 +++- .../match2/wikis/artifact/match_legacy.lua | 3 ++- .../match2/wikis/battalion/match_legacy.lua | 5 ++++- .../match2/wikis/brawlstars/match_legacy.lua | 8 ++++---- .../match2/wikis/callofduty/match_legacy.lua | 8 ++++---- .../wikis/clashofclans/match_summary.lua | 10 +++++++--- .../wikis/counterstrike/match_legacy.lua | 6 ++---- .../match2/wikis/criticalops/match_legacy.lua | 6 ++---- .../match2/wikis/crossfire/match_legacy.lua | 8 ++++---- .../easportsfc/match_group_input_custom.lua | 7 ++++--- .../match2/wikis/fighters/match_legacy.lua | 3 ++- .../match2/wikis/fighters/match_summary.lua | 4 +++- components/match2/wikis/halo/match_legacy.lua | 8 ++++---- .../wikis/omegastrikers/match_summary.lua | 2 +- .../match2/wikis/overwatch/match_legacy.lua | 8 ++++---- .../match2/wikis/paladins/match_legacy.lua | 3 ++- .../match2/wikis/pokemon/match_summary.lua | 9 ++++++--- .../match2/wikis/rainbowsix/match_legacy.lua | 17 +++++++++-------- .../match2/wikis/rocketleague/match_legacy.lua | 8 ++++---- .../match2/wikis/sideswipe/match_legacy.lua | 8 ++++---- components/match2/wikis/smash/match_legacy.lua | 2 +- .../match2/wikis/splatoon/match_legacy.lua | 8 ++++---- .../match2/wikis/trackmania/match_legacy.lua | 5 ++++- .../match2/wikis/valorant/match_legacy.lua | 18 ++++++++++-------- .../match2/wikis/warcraft/match_legacy.lua | 14 +++++++++----- components/match2/wikis/zula/match_legacy.lua | 11 ++++++----- 31 files changed, 120 insertions(+), 89 deletions(-) diff --git a/components/game_table/commons/game_table.lua b/components/game_table/commons/game_table.lua index 98bb7fa03ba..b9830f0e8c3 100644 --- a/components/game_table/commons/game_table.lua +++ b/components/game_table/commons/game_table.lua @@ -11,6 +11,7 @@ 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') @@ -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 c4fd1076ed8..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') @@ -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/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_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 a7d3f1cad00..a13bcb40c8e 100644 --- a/components/match2/wikis/ageofempires/match_legacy.lua +++ b/components/match2/wikis/ageofempires/match_legacy.lua @@ -11,6 +11,7 @@ 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') @@ -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( diff --git a/components/match2/wikis/arenafps/match_legacy.lua b/components/match2/wikis/arenafps/match_legacy.lua index f598027c929..eee7e342692 100644 --- a/components/match2/wikis/arenafps/match_legacy.lua +++ b/components/match2/wikis/arenafps/match_legacy.lua @@ -11,6 +11,7 @@ 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') @@ -40,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( diff --git a/components/match2/wikis/artifact/match_legacy.lua b/components/match2/wikis/artifact/match_legacy.lua index 6d30df3ddc3..5e1c42cebb5 100644 --- a/components/match2/wikis/artifact/match_legacy.lua +++ b/components/match2/wikis/artifact/match_legacy.lua @@ -11,6 +11,7 @@ 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') @@ -108,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..f542770b8a7 100644 --- a/components/match2/wikis/battalion/match_legacy.lua +++ b/components/match2/wikis/battalion/match_legacy.lua @@ -8,7 +8,9 @@ local MatchLegacy = {} +local Array = require('Module:Array') local Json = require('Module:Json') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -33,7 +35,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( diff --git a/components/match2/wikis/brawlstars/match_legacy.lua b/components/match2/wikis/brawlstars/match_legacy.lua index 8230ac2f026..101be08cb5c 100644 --- a/components/match2/wikis/brawlstars/match_legacy.lua +++ b/components/match2/wikis/brawlstars/match_legacy.lua @@ -8,8 +8,10 @@ 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') @@ -41,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( diff --git a/components/match2/wikis/callofduty/match_legacy.lua b/components/match2/wikis/callofduty/match_legacy.lua index 023ad2515bc..9cf5bc8e1b0 100644 --- a/components/match2/wikis/callofduty/match_legacy.lua +++ b/components/match2/wikis/callofduty/match_legacy.lua @@ -8,8 +8,10 @@ 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') @@ -39,10 +41,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( 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/counterstrike/match_legacy.lua b/components/match2/wikis/counterstrike/match_legacy.lua index 34067dac34c..e176af4b620 100644 --- a/components/match2/wikis/counterstrike/match_legacy.lua +++ b/components/match2/wikis/counterstrike/match_legacy.lua @@ -89,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 diff --git a/components/match2/wikis/criticalops/match_legacy.lua b/components/match2/wikis/criticalops/match_legacy.lua index bdb5c25d046..eed4f4fb5f9 100644 --- a/components/match2/wikis/criticalops/match_legacy.lua +++ b/components/match2/wikis/criticalops/match_legacy.lua @@ -89,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 diff --git a/components/match2/wikis/crossfire/match_legacy.lua b/components/match2/wikis/crossfire/match_legacy.lua index 63440ac4e50..bf6ef8d8463 100644 --- a/components/match2/wikis/crossfire/match_legacy.lua +++ b/components/match2/wikis/crossfire/match_legacy.lua @@ -8,8 +8,10 @@ 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') @@ -39,10 +41,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( 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/fighters/match_legacy.lua b/components/match2/wikis/fighters/match_legacy.lua index cef3851bf8c..9a9fa03bf0d 100644 --- a/components/match2/wikis/fighters/match_legacy.lua +++ b/components/match2/wikis/fighters/match_legacy.lua @@ -59,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( diff --git a/components/match2/wikis/fighters/match_summary.lua b/components/match2/wikis/fighters/match_summary.lua index 299a0246ac9..5d13ad75807 100644 --- a/components/match2/wikis/fighters/match_summary.lua +++ b/components/match2/wikis/fighters/match_summary.lua @@ -88,7 +88,9 @@ function CustomMatchSummary._createStandardGame(game, props) 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 1c88c28ff9a..e9963dc6c5b 100644 --- a/components/match2/wikis/halo/match_legacy.lua +++ b/components/match2/wikis/halo/match_legacy.lua @@ -8,8 +8,10 @@ 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') @@ -37,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( 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..31646ccf250 100644 --- a/components/match2/wikis/overwatch/match_legacy.lua +++ b/components/match2/wikis/overwatch/match_legacy.lua @@ -8,8 +8,10 @@ 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') @@ -39,10 +41,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( diff --git a/components/match2/wikis/paladins/match_legacy.lua b/components/match2/wikis/paladins/match_legacy.lua index c773218e191..ade98d77da7 100644 --- a/components/match2/wikis/paladins/match_legacy.lua +++ b/components/match2/wikis/paladins/match_legacy.lua @@ -11,6 +11,7 @@ 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') @@ -108,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_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..beb6f83cee8 100644 --- a/components/match2/wikis/rainbowsix/match_legacy.lua +++ b/components/match2/wikis/rainbowsix/match_legacy.lua @@ -8,8 +8,10 @@ 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') @@ -32,6 +34,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 +79,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( @@ -142,10 +142,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/rocketleague/match_legacy.lua b/components/match2/wikis/rocketleague/match_legacy.lua index d640b6ac699..866f345ea3a 100644 --- a/components/match2/wikis/rocketleague/match_legacy.lua +++ b/components/match2/wikis/rocketleague/match_legacy.lua @@ -8,8 +8,10 @@ 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') @@ -35,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( diff --git a/components/match2/wikis/sideswipe/match_legacy.lua b/components/match2/wikis/sideswipe/match_legacy.lua index 07dfd6140eb..44f428019a6 100644 --- a/components/match2/wikis/sideswipe/match_legacy.lua +++ b/components/match2/wikis/sideswipe/match_legacy.lua @@ -8,8 +8,10 @@ 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') @@ -37,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( diff --git a/components/match2/wikis/smash/match_legacy.lua b/components/match2/wikis/smash/match_legacy.lua index 5d447db1c83..9b5fc54c6b0 100644 --- a/components/match2/wikis/smash/match_legacy.lua +++ b/components/match2/wikis/smash/match_legacy.lua @@ -35,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 = {} @@ -59,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( diff --git a/components/match2/wikis/splatoon/match_legacy.lua b/components/match2/wikis/splatoon/match_legacy.lua index 57a46dc9df1..09b1991b84c 100644 --- a/components/match2/wikis/splatoon/match_legacy.lua +++ b/components/match2/wikis/splatoon/match_legacy.lua @@ -8,8 +8,10 @@ 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') @@ -41,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( diff --git a/components/match2/wikis/trackmania/match_legacy.lua b/components/match2/wikis/trackmania/match_legacy.lua index 71d090620d1..cc693ffa3be 100644 --- a/components/match2/wikis/trackmania/match_legacy.lua +++ b/components/match2/wikis/trackmania/match_legacy.lua @@ -8,8 +8,10 @@ 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') @@ -38,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( diff --git a/components/match2/wikis/valorant/match_legacy.lua b/components/match2/wikis/valorant/match_legacy.lua index acec0c6f768..4f9880bafe1 100644 --- a/components/match2/wikis/valorant/match_legacy.lua +++ b/components/match2/wikis/valorant/match_legacy.lua @@ -12,6 +12,7 @@ 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') @@ -36,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 @@ -102,7 +105,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 @@ -149,9 +151,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 @@ -187,10 +191,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_legacy.lua b/components/match2/wikis/warcraft/match_legacy.lua index 320f409869c..5045ba846d9 100644 --- a/components/match2/wikis/warcraft/match_legacy.lua +++ b/components/match2/wikis/warcraft/match_legacy.lua @@ -13,6 +13,7 @@ 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') @@ -170,6 +171,7 @@ function MatchLegacy._groupIntoSubmatches(match2, objectName) 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] = { @@ -180,8 +182,8 @@ function MatchLegacy._groupIntoSubmatches(match2, objectName) 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 @@ -240,6 +242,9 @@ end function MatchLegacy._storeGame(game2, gameIndex, match) 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 local game = Table.deepCopy(match) @@ -247,9 +252,8 @@ 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 opponents = Json.parseIfString(game2.opponents) or {} local factions, heroes = MatchLegacy._heroesAndFactionFromGameOpponents(opponents) diff --git a/components/match2/wikis/zula/match_legacy.lua b/components/match2/wikis/zula/match_legacy.lua index dceebcce770..239b21e1831 100644 --- a/components/match2/wikis/zula/match_legacy.lua +++ b/components/match2/wikis/zula/match_legacy.lua @@ -6,9 +6,11 @@ -- 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') @@ -87,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 @@ -174,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 = {}, {} @@ -202,7 +204,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 From 36d5479650dbc5e8511266c83c4188d7aea96834 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 23 Dec 2024 10:02:06 +0100 Subject: [PATCH 13/18] linter: don't shadow with dupes --- components/match2/wikis/valorant/match_legacy.lua | 1 - components/match2/wikis/warcraft/match_legacy.lua | 1 - components/match2/wikis/zula/match_legacy.lua | 1 - 3 files changed, 3 deletions(-) diff --git a/components/match2/wikis/valorant/match_legacy.lua b/components/match2/wikis/valorant/match_legacy.lua index 4f9880bafe1..8cbde3f4df9 100644 --- a/components/match2/wikis/valorant/match_legacy.lua +++ b/components/match2/wikis/valorant/match_legacy.lua @@ -88,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 diff --git a/components/match2/wikis/warcraft/match_legacy.lua b/components/match2/wikis/warcraft/match_legacy.lua index 5045ba846d9..5ff8c489e7c 100644 --- a/components/match2/wikis/warcraft/match_legacy.lua +++ b/components/match2/wikis/warcraft/match_legacy.lua @@ -255,7 +255,6 @@ function MatchLegacy._storeGame(game2, gameIndex, match) game.opponent1score = scores[1] game.opponent2score = scores[2] - local opponents = Json.parseIfString(game2.opponents) or {} local factions, heroes = MatchLegacy._heroesAndFactionFromGameOpponents(opponents) for opponentIndex = 1, 2 do game.extradata['opponent' .. opponentIndex .. 'race'] = factions[opponentIndex] diff --git a/components/match2/wikis/zula/match_legacy.lua b/components/match2/wikis/zula/match_legacy.lua index 239b21e1831..55b6f4b4320 100644 --- a/components/match2/wikis/zula/match_legacy.lua +++ b/components/match2/wikis/zula/match_legacy.lua @@ -210,7 +210,6 @@ function MatchLegacy.storeGames(match, match2) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 - local opponents = Json.parseIfString(game2.opponents) or {} local walkover = MatchOpponentHelper.calculateWalkoverType(opponents) if walkover == 'FF' or walkover == 'DQ' then game.walkover = 1 From 339ce6d020840042e3b59fcbeece4d2465642109 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 23 Dec 2024 10:24:56 +0100 Subject: [PATCH 14/18] kick walkover --- components/match2/commons/match.lua | 4 ++-- components/match2/commons/match_group_util.lua | 11 ----------- components/match2/wikis/battalion/match_legacy.lua | 8 ++++++-- components/match2/wikis/callofduty/match_legacy.lua | 8 +++++--- components/match2/wikis/crossfire/match_legacy.lua | 6 ++++-- .../match2/wikis/heroes/legacy/match_maps_legacy.lua | 1 + components/match2/wikis/overwatch/match_legacy.lua | 3 +++ components/match2/wikis/rainbowsix/match_legacy.lua | 3 +++ components/match2/wikis/runeterra/match_legacy.lua | 5 +++++ components/match2/wikis/squadrons/match_legacy.lua | 5 +++++ components/match2/wikis/teamfortress/match_legacy.lua | 5 +++++ definitions/liquipedia_db.lua | 6 ------ standard/lpdb.lua | 4 +--- 13 files changed, 40 insertions(+), 29 deletions(-) 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_util.lua b/components/match2/commons/match_group_util.lua index 4a5a3d8e7d3..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? @@ -212,7 +208,6 @@ MatchGroupUtil.types.Walkover = TypeUtil.literalUnion('l', 'ff', 'dq') ---@field subgroup number? ---@field type string? ---@field vod string? ----@field walkover WalkoverType? ---@field winner integer? ---@field status string? ---@field extradata table? @@ -225,12 +220,10 @@ MatchGroupUtil.types.Game = TypeUtil.struct({ map = 'string?', mapDisplayName = 'string?', mode = 'string?', - 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?', }) @@ -247,14 +240,12 @@ MatchGroupUtil.types.Game = TypeUtil.struct({ ---@field matchId string? ---@field mode string? ---@field opponents standardOpponent[] ----@field resultType ResultType? ---@deprecated ---@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 @@ -271,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?', }) diff --git a/components/match2/wikis/battalion/match_legacy.lua b/components/match2/wikis/battalion/match_legacy.lua index f542770b8a7..bdd90b4b52d 100644 --- a/components/match2/wikis/battalion/match_legacy.lua +++ b/components/match2/wikis/battalion/match_legacy.lua @@ -10,10 +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') + function MatchLegacy.storeMatch(match2) local match = MatchLegacy._convertParameters(match2) @@ -56,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/callofduty/match_legacy.lua b/components/match2/wikis/callofduty/match_legacy.lua index 9cf5bc8e1b0..dd9c9ebcd85 100644 --- a/components/match2/wikis/callofduty/match_legacy.lua +++ b/components/match2/wikis/callofduty/match_legacy.lua @@ -16,6 +16,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') function MatchLegacy.storeMatch(match2) local match = MatchLegacy._convertParameters(match2) @@ -62,9 +63,10 @@ function MatchLegacy._convertParameters(match2) end end - if match.walkover == 'ff' or match.walkover == 'dq' then - match.walkover = match.winner - elseif match.walkover == 'l' then + local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents) + if walkover == 'FF' or match.walkover == 'DQ!' then + walkover = match.winner + elseif walkover == 'L' then match.walkover = nil end diff --git a/components/match2/wikis/crossfire/match_legacy.lua b/components/match2/wikis/crossfire/match_legacy.lua index bf6ef8d8463..73a385869f4 100644 --- a/components/match2/wikis/crossfire/match_legacy.lua +++ b/components/match2/wikis/crossfire/match_legacy.lua @@ -16,6 +16,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') function MatchLegacy.storeMatch(match2) local match = MatchLegacy._convertParameters(match2) @@ -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/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/overwatch/match_legacy.lua b/components/match2/wikis/overwatch/match_legacy.lua index 31646ccf250..2434243784d 100644 --- a/components/match2/wikis/overwatch/match_legacy.lua +++ b/components/match2/wikis/overwatch/match_legacy.lua @@ -16,6 +16,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') function MatchLegacy.storeMatch(match2) local match = MatchLegacy._convertParameters(match2) @@ -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/rainbowsix/match_legacy.lua b/components/match2/wikis/rainbowsix/match_legacy.lua index beb6f83cee8..5ea27ad9d5f 100644 --- a/components/match2/wikis/rainbowsix/match_legacy.lua +++ b/components/match2/wikis/rainbowsix/match_legacy.lua @@ -16,6 +16,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') function MatchLegacy.storeMatch(match2) local match = MatchLegacy._convertParameters(match2) @@ -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 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/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/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/definitions/liquipedia_db.lua b/definitions/liquipedia_db.lua index d2828583b53..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 ---@deprecated ---@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 ---@deprecated ---@field mode string ---@field type string ---@field game string 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 = ''}, From bf2bc4ecad92dcfdf24d3d179f365113ac349ede Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 23 Dec 2024 10:26:44 +0100 Subject: [PATCH 15/18] thanks linter --- components/match2/wikis/callofduty/match_legacy.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/match2/wikis/callofduty/match_legacy.lua b/components/match2/wikis/callofduty/match_legacy.lua index dd9c9ebcd85..6a818e34550 100644 --- a/components/match2/wikis/callofduty/match_legacy.lua +++ b/components/match2/wikis/callofduty/match_legacy.lua @@ -64,8 +64,8 @@ function MatchLegacy._convertParameters(match2) end local walkover = MatchOpponentHelper.calculateWalkoverType(match2.match2opponents) - if walkover == 'FF' or match.walkover == 'DQ!' then - walkover = match.winner + if walkover == 'FF' or walkover == 'DQ' then + match.walkover = match.winner elseif walkover == 'L' then match.walkover = nil end From 6ed52b419d98a064415013fa27edf3fcc67715a2 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 23 Dec 2024 10:28:03 +0100 Subject: [PATCH 16/18] maybe --- spec/orm_spec.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/orm_spec.lua b/spec/orm_spec.lua index c52372b1d48..aa1b628d0c4 100644 --- a/spec/orm_spec.lua +++ b/spec/orm_spec.lua @@ -64,7 +64,6 @@ describe('LPDB Object-Relational Mapping', function() tournament = '', type = '', vod = '', - walkover = '', winner = '', }) stub:revert() From 42367570924d54bb6d1e8a33c73ca295a8707795 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 23 Dec 2024 10:28:19 +0100 Subject: [PATCH 17/18] maybe2 --- spec/orm_spec.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/orm_spec.lua b/spec/orm_spec.lua index aa1b628d0c4..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 = '', From 8fba716f3f8df494fcb1972ee9bc30d15332336a Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Tue, 24 Dec 2024 04:52:42 +0100 Subject: [PATCH 18/18] Update match_legacy.lua --- components/match2/wikis/fighters/match_legacy.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/match2/wikis/fighters/match_legacy.lua b/components/match2/wikis/fighters/match_legacy.lua index 9a9fa03bf0d..5dca29ac210 100644 --- a/components/match2/wikis/fighters/match_legacy.lua +++ b/components/match2/wikis/fighters/match_legacy.lua @@ -40,8 +40,8 @@ function MatchLegacy._storeGames(match, match2) if game.mode == 'singles' then local opponents = Json.parseIfString(game2.opponents) or {} - local player1 = opponents[1].players[1] - local player2 = opponents[2].players[1] + 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