From 6b843906578ae54a2440735e11fbe241524f5d22 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sat, 21 Dec 2024 12:06:16 +0100 Subject: [PATCH 1/9] 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 2/9] 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 3/9] 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 4/9] 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 5/9] 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 6/9] 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 7/9] 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 8/9] 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 9/9] 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)