Skip to content

Commit

Permalink
fix(match2): valorant participant issue in legacy (#4754)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Rathoz authored Sep 17, 2024
1 parent 5ce1047 commit 6e44cab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
11 changes: 10 additions & 1 deletion components/match2/commons/match.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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',
Expand Down
26 changes: 12 additions & 14 deletions components/match2/wikis/valorant/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -179,8 +179,8 @@ function MapFunctions.keepMap(map)
end

---@param map table
---@param participants table<string, {player: string?, agent: string?}>
---@return table
---@param participants {players: {player: string?, agent: string?}[]}[]
---@return table<string, any>
function MapFunctions.getExtraData(map, participants)
---@type table<string, any>
local extraData = {
Expand All @@ -190,23 +190,23 @@ 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
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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/valorant/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6e44cab

Please sign in to comment.