From 6e44caba795c1dcb894f8e848f1cefc2147c5a2c Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Tue, 17 Sep 2024 17:20:45 +0200 Subject: [PATCH] fix(match2): valorant participant issue in legacy (#4754) * fix(match2): valorant participant issue in legacy * fix format, fix typo * allow it through the clamping * allow gaps in input of players * change these to pairs too --- components/match2/commons/match.lua | 11 +++++++- .../valorant/match_group_input_custom.lua | 26 +++++++++---------- .../match2/wikis/valorant/match_legacy.lua | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/components/match2/commons/match.lua b/components/match2/commons/match.lua index 113cccf575d..accc893b66d 100644 --- a/components/match2/commons/match.lua +++ b/components/match2/commons/match.lua @@ -164,7 +164,7 @@ end ---and removes direct references between a match record and its subobject records. ---@param match table ---@return {matchRecord: table, gameRecords: table[], opponentRecords: table[], playerRecords: table[]} ----@overload fun(match: table): {} +---@overload fun(match: any): {} function Match.splitRecordsByType(match) if match == nil or type(match) ~= 'table' then return {} @@ -385,6 +385,14 @@ end function Match._prepareGameRecordForStore(matchRecord, gameRecord) gameRecord.parent = matchRecord.parent gameRecord.tournament = matchRecord.tournament + if not gameRecord.participants and gameRecord.opponents then + gameRecord.participants = {} + for opponentId, opponent in ipairs(gameRecord.opponents) do + for playerId, player in pairs(opponent.players) do + gameRecord.participants[opponentId .. '_' .. playerId] = player + end + end + end Match.clampFields(gameRecord, Match.gameFields) end @@ -452,6 +460,7 @@ Match.gameFields = Table.map({ 'parent', 'participants', 'patch', + 'opponents', -- Not a real field yet, but will be in the future. Also for use in Match/Legacy 'resulttype', 'rounds', 'scores', diff --git a/components/match2/wikis/valorant/match_group_input_custom.lua b/components/match2/wikis/valorant/match_group_input_custom.lua index 827a615d1c7..ade2636532d 100644 --- a/components/match2/wikis/valorant/match_group_input_custom.lua +++ b/components/match2/wikis/valorant/match_group_input_custom.lua @@ -88,8 +88,8 @@ function CustomMatchGroupInput.extractMaps(match, opponents) local finishedInput = map.finished --[[@as string?]] local winnerInput = map.winner --[[@as string?]] - map.participants = MapFunctions.getParticipants(map, opponents) - map.extradata = MapFunctions.getExtraData(map, map.participants) + map.opponents = MapFunctions.getParticipants(map, opponents) + map.extradata = MapFunctions.getExtraData(map, map.opponents) map.finished = MatchGroupInputUtil.mapIsFinished(map) local opponentInfo = Array.map(opponents, function(_, opponentIndex) @@ -179,8 +179,8 @@ function MapFunctions.keepMap(map) end ---@param map table ----@param participants table ----@return table +---@param participants {players: {player: string?, agent: string?}[]}[] +---@return table function MapFunctions.getExtraData(map, participants) ---@type table local extraData = { @@ -190,10 +190,11 @@ function MapFunctions.getExtraData(map, participants) t2halfs = {atk = map.t2atk, def = map.t2def, otatk = map.t2otatk, otdef = map.t2otdef}, } - for key, participant in pairs(participants) do - local opponentIdx, playerIdx = unpack(mw.text.split(key, '_', true)) - extraData['t' .. opponentIdx .. 'p' .. playerIdx] = participant.player - extraData['t' .. opponentIdx .. 'p' .. playerIdx .. 'agent'] = participant.agent + for opponentIdx, opponent in ipairs(participants) do + for playerIdx, player in pairs(opponent.players) do + extraData['t' .. opponentIdx .. 'p' .. playerIdx] = player.player + extraData['t' .. opponentIdx .. 'p' .. playerIdx .. 'agent'] = player.agent + end end return extraData @@ -201,12 +202,11 @@ end ---@param map table ---@param opponents MGIParsedOpponent[] ----@return table +---@return {players: table[]}[] function MapFunctions.getParticipants(map, opponents) - local allParticipants = {} local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, AgentNames) - Array.forEach(opponents, function(opponent, opponentIndex) + return Array.map(opponents, function(opponent, opponentIndex) local players = Array.mapIndexes(function(playerIndex) return opponent.match2players[playerIndex] or (map['t' .. opponentIndex .. 'p' .. playerIndex] and {}) or @@ -234,10 +234,8 @@ function MapFunctions.getParticipants(map, opponents) Array.forEach(unattachedParticipants, function(participant) table.insert(participants, participant) end) - Table.mergeInto(allParticipants, Table.map(participants, MatchGroupInputUtil.prefixPartcipants(opponentIndex))) + return {players = participants} end) - - return allParticipants end ---@param map table diff --git a/components/match2/wikis/valorant/match_legacy.lua b/components/match2/wikis/valorant/match_legacy.lua index 1705abe3723..e20b017c0c8 100644 --- a/components/match2/wikis/valorant/match_legacy.lua +++ b/components/match2/wikis/valorant/match_legacy.lua @@ -85,7 +85,7 @@ function MatchLegacy.storeGames(match, match2) end local opponents = Json.parseIfString(game2.opponents) or {} for teamId, opponent in ipairs(opponents) do - for playerId, player in ipairs(opponent.players) do + for playerId, player in pairs(opponent.players) do addPlayer(teamId, playerId, player) end end