Skip to content

Commit

Permalink
parse opponents from strinigified to table
Browse files Browse the repository at this point in the history
  • Loading branch information
hjpalpha committed Dec 21, 2024
1 parent 160e0ee commit a09c24b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion components/match2/wikis/brawlhalla/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ function MatchLegacy._convertParameters(match2)
local headList = function (opponentIndex, playerIndex)
local heads = Set{}
Array.forEach(match2.match2games or {}, function(game)
local player = ((game.opponents[opponentIndex] or {}).players or {})[playerIndex]
local opponents = Json.parseIfString(game.opponents) or {}
local player = ((opponents[opponentIndex] or {}).players or {})[playerIndex]
if Logic.isDeepEmpty(player) then return end
heads:add(player.char)
end)
Expand Down
8 changes: 5 additions & 3 deletions components/match2/wikis/fighters/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ function MatchLegacy._storeGames(match, match2)
game.extradata = {}

if game.mode == 'singles' then
local player1 = game2.opponents[1].players[1]
local player2 = game2.opponents[2].players[1]
local opponents = Json.parseIfString(game2.opponents) or {}
local player1 = opponents[1].players[1]
local player2 = opponents[2].players[1]
game.extradata.char1 = table.concat(Array.map(player1.characters or {}, Operator.property('name')), ',')
game.extradata.char2 = table.concat(Array.map(player2.characters or {}, Operator.property('name')), ',')
end
Expand Down Expand Up @@ -103,7 +104,8 @@ function MatchLegacy._convertParameters(match2)
local headList = function(opponentIndex, playerIndex)
local heads = Set{}
Array.forEach(match2.match2games or {}, function(game)
local player = (game.opponents[opponentIndex].players or {})[playerIndex]
local opponents = Json.parseIfString(game.opponents) or {}
local player = (opponents[opponentIndex].players or {})[playerIndex]
if player and Logic.isNotEmpty(player.characters) then
Array.forEach(
Array.map(player.characters, Operator.property('name')),
Expand Down
3 changes: 2 additions & 1 deletion components/match2/wikis/smash/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ function MatchLegacy._convertParameters(match2)
local headList = function(opponentIndex, playerIndex)
local heads = Set{}
Array.forEach(match2.match2games or {}, function(game)
local player = (game.opponents[opponentIndex].players or {})[playerIndex]
local opponents = Json.parseIfString(game.opponents) or {}
local player = (opponents[opponentIndex].players or {})[playerIndex]
if player and Logic.isNotEmpty(player.characters) then
Array.forEach(
Array.map(player.characters, Operator.property('name')),
Expand Down
6 changes: 4 additions & 2 deletions components/match2/wikis/starcraft/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ function MatchLegacy._storeGames(match, match2)
game.extradata.winnerrace = game.extradata.winnerfaction
game.extradata.loserrace = game.extradata.loserfaction

Array.forEach(game.opponents, function(opponent, opponentIndex)
local opponents = Json.parseIfString(game.opponents) or {}
Array.forEach(opponents, function(opponent, opponentIndex)
Array.forEach(opponent.players or {}, function(player, playerIndex)
if Logic.isDeepEmpty(player) then return end
local matchPlayer = match2.match2opponents[opponentIndex].match2players[playerIndex] or {}
Expand Down Expand Up @@ -79,7 +80,8 @@ function MatchLegacy._storeGames(match, match2)
submatch.opponent2score = scores[2] or 0
submatch.extradata = {}

Array.forEach(game.opponents, function(opponent, opponentIndex)
local opponents = Json.parseIfString(game.opponents) or {}
Array.forEach(opponents, function(opponent, opponentIndex)
Array.forEach(opponent.players or {}, function(player, playerIndex)
if Logic.isDeepEmpty(player) then return end
local matchPlayer = match2.match2opponents[opponentIndex].match2players[playerIndex] or {}
Expand Down
7 changes: 5 additions & 2 deletions components/match2/wikis/warcraft/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,13 @@ function MatchLegacy._groupIntoSubmatches(match2, objectName)
local submatchIndex = tonumber(game.subgroup)
if game.mode ~= '1v1' or not submatchIndex then return end

local opponents = Json.parseIfString(game.opponents) or {}

if not submatches[submatchIndex] then
submatches[submatchIndex] = {
games = {},
objectName = objectName .. '_Submatch_' .. submatchIndex,
opponents = MatchLegacy._constructSubmatchOpponents(game.opponents or {}, match2.match2opponents)
opponents = MatchLegacy._constructSubmatchOpponents(opponents, match2.match2opponents)
}
end
local submatch = submatches[submatchIndex]
Expand Down Expand Up @@ -247,7 +249,8 @@ function MatchLegacy._storeGame(game2, gameIndex, match)
game.opponent1score = game2.scores[1]
game.opponent2score = game2.scores[2]

local factions, heroes = MatchLegacy._heroesAndFactionFromGameOpponents(game2.opponents)
local opponents = Json.parseIfString(game2.opponents) or {}
local factions, heroes = MatchLegacy._heroesAndFactionFromGameOpponents(opponents)
for opponentIndex = 1, 2 do
game.extradata['opponent' .. opponentIndex .. 'race'] = factions[opponentIndex]
or game.extradata['opponent' .. opponentIndex .. 'race']
Expand Down

0 comments on commit a09c24b

Please sign in to comment.