diff --git a/components/game_table/commons/game_table.lua b/components/game_table/commons/game_table.lua index 98bb7fa03b..b9830f0e8c 100644 --- a/components/game_table/commons/game_table.lua +++ b/components/game_table/commons/game_table.lua @@ -11,6 +11,7 @@ local Class = require('Module:Class') local Game = require('Module:Game') local Logic = require('Module:Logic') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local VodLink = require('Module:VodLink') local MatchTable = Lua.import('Module:MatchTable') @@ -76,9 +77,10 @@ end ---@param game match2game ---@return Html? function GameTable:_displayGameScore(result, game) + local scores = Array.map(game.opponents, Operator.property('score')) local toScore = function(opponentRecord) local isWinner = opponentRecord.id == tonumber(game.winner) - local score = (game.scores or {})[opponentRecord.id] or (isWinner and 1) or 0 + local score = scores[opponentRecord.id] or (isWinner and 1) or 0 return mw.html.create(isWinner and 'b' or nil) :wikitext(score) end diff --git a/components/game_table/commons/game_table_character.lua b/components/game_table/commons/game_table_character.lua index c4fd1076ed..9589b10b3a 100644 --- a/components/game_table/commons/game_table_character.lua +++ b/components/game_table/commons/game_table_character.lua @@ -12,6 +12,7 @@ local CharacterIcon = require('Module:CharacterIcon') local Class = require('Module:Class') local Logic = require('Module:Logic') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local Table = require('Module:Table') local GameTable = Lua.import('Module:GameTable') @@ -386,11 +387,12 @@ end ---@return Html function CharacterGameTable:_displayScore(game, pickedBy, pickedVs) local winner = tonumber(game.winner) + local scores = Array.map(game.opponents, Operator.property('score')) local toScore = function(opponentId) local isWinner = winner == opponentId return mw.html.create(isWinner and 'b' or nil) - :wikitext(game.scores[opponentId] or (isWinner and 'W' or 'L')) + :wikitext(scores[opponentId] or (isWinner and 'W' or 'L')) end return mw.html.create('td') diff --git a/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft_ffa.lua b/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft_ffa.lua index 64809a5095..08e8112ee4 100644 --- a/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft_ffa.lua +++ b/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft_ffa.lua @@ -81,7 +81,8 @@ function MatchFunctions.calculateMatchScore(opponents, games) local opponent = opponents[opponentIndex] local sum = (opponent.extradata.advantage or 0) - (opponent.extradata.penalty or 0) Array.forEach(games, function(game) - sum = sum + ((game.scores or {})[opponentIndex] or 0) + local scores = Array.map(game.opponents, Operator.property('score')) + sum = sum + ((scores or {})[opponentIndex] or 0) end) return sum end diff --git a/components/match2/commons/starcraft_starcraft2/match_summary_starcraft_ffa.lua b/components/match2/commons/starcraft_starcraft2/match_summary_starcraft_ffa.lua index f446f463f5..e0a5642520 100644 --- a/components/match2/commons/starcraft_starcraft2/match_summary_starcraft_ffa.lua +++ b/components/match2/commons/starcraft_starcraft2/match_summary_starcraft_ffa.lua @@ -185,7 +185,7 @@ function StarcraftMatchSummaryFfa._opponents(match) return Table.merge(opponent, { placement = opponent.placement, status = opponent.status or 'S', - score = opponent.score or (game.scores or {})[opponentIdx], + score = opponent.score, }) end) end) diff --git a/components/match2/wikis/ageofempires/match_legacy.lua b/components/match2/wikis/ageofempires/match_legacy.lua index a7d3f1cad0..a13bcb40c8 100644 --- a/components/match2/wikis/ageofempires/match_legacy.lua +++ b/components/match2/wikis/ageofempires/match_legacy.lua @@ -11,6 +11,7 @@ local MatchLegacy = {} local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -75,7 +76,7 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag - local scores = Json.parseIfString(game2.scores) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 local res = mw.ext.LiquipediaDB.lpdb_game( diff --git a/components/match2/wikis/arenafps/match_legacy.lua b/components/match2/wikis/arenafps/match_legacy.lua index f598027c92..eee7e34269 100644 --- a/components/match2/wikis/arenafps/match_legacy.lua +++ b/components/match2/wikis/arenafps/match_legacy.lua @@ -11,6 +11,7 @@ local MatchLegacy = {} local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -40,7 +41,8 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = Json.parseIfString(game.scores) or {} + local opponents = Json.parseIfString(game.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 local res = mw.ext.LiquipediaDB.lpdb_game( diff --git a/components/match2/wikis/artifact/match_legacy.lua b/components/match2/wikis/artifact/match_legacy.lua index 6d30df3ddc..5e1c42cebb 100644 --- a/components/match2/wikis/artifact/match_legacy.lua +++ b/components/match2/wikis/artifact/match_legacy.lua @@ -11,6 +11,7 @@ local MatchLegacy = {} local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -108,7 +109,7 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = Json.parseIfString(game2.scores) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 diff --git a/components/match2/wikis/battalion/match_legacy.lua b/components/match2/wikis/battalion/match_legacy.lua index cb39edff13..f542770b8a 100644 --- a/components/match2/wikis/battalion/match_legacy.lua +++ b/components/match2/wikis/battalion/match_legacy.lua @@ -8,7 +8,9 @@ local MatchLegacy = {} +local Array = require('Module:Array') local Json = require('Module:Json') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -33,7 +35,8 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = Json.parseIfString(game2.scores) or {} + local opponents = Json.parseIfString(game2.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 local res = mw.ext.LiquipediaDB.lpdb_game( diff --git a/components/match2/wikis/brawlstars/match_legacy.lua b/components/match2/wikis/brawlstars/match_legacy.lua index 8230ac2f02..101be08cb5 100644 --- a/components/match2/wikis/brawlstars/match_legacy.lua +++ b/components/match2/wikis/brawlstars/match_legacy.lua @@ -8,8 +8,10 @@ local MatchLegacy = {} +local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -41,10 +43,8 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = game2.scores or {} - if type(scores) == 'string' then - scores = Json.parse(scores) - end + local opponents = Json.parseIfString(game2.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 local res = mw.ext.LiquipediaDB.lpdb_game( diff --git a/components/match2/wikis/callofduty/match_legacy.lua b/components/match2/wikis/callofduty/match_legacy.lua index 023ad2515b..9cf5bc8e1b 100644 --- a/components/match2/wikis/callofduty/match_legacy.lua +++ b/components/match2/wikis/callofduty/match_legacy.lua @@ -8,8 +8,10 @@ local MatchLegacy = {} +local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -39,10 +41,8 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = game2.scores or {} - if type(scores) == 'string' then - scores = Json.parse(scores) - end + local opponents = Json.parseIfString(game2.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 local res = mw.ext.LiquipediaDB.lpdb_game( diff --git a/components/match2/wikis/clashofclans/match_summary.lua b/components/match2/wikis/clashofclans/match_summary.lua index 09a29e10bc..febae2d69c 100644 --- a/components/match2/wikis/clashofclans/match_summary.lua +++ b/components/match2/wikis/clashofclans/match_summary.lua @@ -7,7 +7,9 @@ -- local Abbreviation = require('Module:Abbreviation') +local Array = require('Module:Array') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local Table = require('Module:Table') local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper') @@ -33,8 +35,9 @@ function CustomMatchSummary.createHeader(match) if match.bestof == 1 and match.games and match.games[1] and not match.opponents[1].placement2 and not match.opponents[2].placement2 then - opponentLeft = Table.merge(match.opponents[1], {score = (match.games[1].scores or {})[1] or 0}) - opponentRight = Table.merge(match.opponents[2], {score = (match.games[1].scores or {})[2] or 0}) + local scores = Array.map(match.games[1].opponents, Operator.property('score')) + opponentLeft = Table.merge(match.opponents[1], {score = scores[1] or 0}) + opponentRight = Table.merge(match.opponents[2], {score = scores[2] or 0}) end @@ -79,7 +82,8 @@ end ---@param gameIndex integer ---@return Widget? function CustomMatchSummary.createGame(date, game, gameIndex) - if Table.isEmpty(game.scores) then + local scores = Array.map(game.opponents, Operator.property('score')) + if Table.isEmpty(scores) then return end diff --git a/components/match2/wikis/counterstrike/match_legacy.lua b/components/match2/wikis/counterstrike/match_legacy.lua index 34067dac34..e176af4b62 100644 --- a/components/match2/wikis/counterstrike/match_legacy.lua +++ b/components/match2/wikis/counterstrike/match_legacy.lua @@ -89,10 +89,8 @@ function MatchLegacy.convertParameters(match2) local opponent1Rounds, opponent2Rounds = 0, 0 local maps = {} for gameIndex, game in ipairs(match2.match2games or {}) do - local scores = game.scores or {} - if type(scores) == 'string' then - scores = Json.parse(game.scores) - end + local opponents = Json.parseIfString(game.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) opponent1Rounds = opponent1Rounds + (tonumber(scores[1] or '') or 0) opponent2Rounds = opponent2Rounds + (tonumber(scores[2] or '') or 0) match.extradata['vodgame' .. gameIndex] = game.vod diff --git a/components/match2/wikis/criticalops/match_legacy.lua b/components/match2/wikis/criticalops/match_legacy.lua index bdb5c25d04..eed4f4fb5f 100644 --- a/components/match2/wikis/criticalops/match_legacy.lua +++ b/components/match2/wikis/criticalops/match_legacy.lua @@ -89,10 +89,8 @@ function MatchLegacy.convertParameters(match2) local opponent1Rounds, opponent2Rounds = 0, 0 local maps = {} for gameIndex, game in ipairs(match2.match2games or {}) do - local scores = game.scores or {} - if type(scores) == 'string' then - scores = Json.parse(game.scores) - end + local opponents = Json.parseIfString(game.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) opponent1Rounds = opponent1Rounds + (tonumber(scores[1] or '') or 0) opponent2Rounds = opponent2Rounds + (tonumber(scores[2] or '') or 0) match.extradata['vodgame' .. gameIndex] = game.vod diff --git a/components/match2/wikis/crossfire/match_legacy.lua b/components/match2/wikis/crossfire/match_legacy.lua index 63440ac4e5..bf6ef8d846 100644 --- a/components/match2/wikis/crossfire/match_legacy.lua +++ b/components/match2/wikis/crossfire/match_legacy.lua @@ -8,8 +8,10 @@ local MatchLegacy = {} +local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -39,10 +41,8 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = game2.scores or {} - if type(scores) == 'string' then - scores = Json.parse(scores) - end + local opponents = Json.parseIfString(game2.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 local res = mw.ext.LiquipediaDB.lpdb_game( diff --git a/components/match2/wikis/easportsfc/match_group_input_custom.lua b/components/match2/wikis/easportsfc/match_group_input_custom.lua index d111ddb6a7..ae07da502b 100644 --- a/components/match2/wikis/easportsfc/match_group_input_custom.lua +++ b/components/match2/wikis/easportsfc/match_group_input_custom.lua @@ -38,12 +38,13 @@ function CustomMatchGroupInput.processMatch(match, options) return MatchGroupInputUtil.computeMatchScoreFromMapWinners(maps, opponentIndex) elseif calculateBy == 'mapScores' then return Array.reduce(Array.map(maps, function(map) - return map.scores[opponentIndex] or 0 + local scores = Array.map(map.opponents, Operator.property('score')) + return scores[opponentIndex] or 0 end), Operator.add, 0) elseif calculateBy == 'penalties' then - return Array.filter(maps, function(map) + return (Array.filter(maps, function(map) return Logic.readBool(map.penalty) - end)[1].scores[opponentIndex] + end)[1].opponents[opponentIndex] or {}).score else error('Unknown calculateBy: ' .. tostring(calculateBy)) end diff --git a/components/match2/wikis/fighters/match_legacy.lua b/components/match2/wikis/fighters/match_legacy.lua index cef3851bf8..9a9fa03bf0 100644 --- a/components/match2/wikis/fighters/match_legacy.lua +++ b/components/match2/wikis/fighters/match_legacy.lua @@ -59,7 +59,8 @@ function MatchLegacy._storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag - local scores = Json.parseIfString(game2.scores) or {} + local opponents = Json.parseIfString(game2.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 return mw.ext.LiquipediaDB.lpdb_game( diff --git a/components/match2/wikis/fighters/match_summary.lua b/components/match2/wikis/fighters/match_summary.lua index 299a0246ac..5d13ad7580 100644 --- a/components/match2/wikis/fighters/match_summary.lua +++ b/components/match2/wikis/fighters/match_summary.lua @@ -88,7 +88,9 @@ function CustomMatchSummary._createStandardGame(game, props) return end - local scoreDisplay = (game.scores[1] or '') .. ' - ' .. (game.scores[2] or '') + local scores = Array.map(game.opponents, Operator.property('score')) + + local scoreDisplay = table.concat(scores, ' - ') return MatchSummaryWidgets.Row{ classes = {'brkts-popup-body-game'}, diff --git a/components/match2/wikis/halo/match_legacy.lua b/components/match2/wikis/halo/match_legacy.lua index 1c88c28ff9..e9963dc6c5 100644 --- a/components/match2/wikis/halo/match_legacy.lua +++ b/components/match2/wikis/halo/match_legacy.lua @@ -8,8 +8,10 @@ local MatchLegacy = {} +local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -37,10 +39,8 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = game.scores or {} - if type(scores) == 'string' then - scores = Json.parse(scores) - end + local opponents = Json.parseIfString(game.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 local res = mw.ext.LiquipediaDB.lpdb_game( diff --git a/components/match2/wikis/omegastrikers/match_summary.lua b/components/match2/wikis/omegastrikers/match_summary.lua index 5d78493db1..5b32a94451 100644 --- a/components/match2/wikis/omegastrikers/match_summary.lua +++ b/components/match2/wikis/omegastrikers/match_summary.lua @@ -41,7 +41,7 @@ function CustomMatchSummary.createBody(match) end function CustomMatchSummary._gameScore(game, opponentIndex) - return mw.html.create('div'):wikitext(game.scores[opponentIndex]) + return mw.html.create('div'):wikitext(game.opponents[opponentIndex].score) end function CustomMatchSummary._createMapRow(game) diff --git a/components/match2/wikis/overwatch/match_legacy.lua b/components/match2/wikis/overwatch/match_legacy.lua index f5e65707d4..31646ccf25 100644 --- a/components/match2/wikis/overwatch/match_legacy.lua +++ b/components/match2/wikis/overwatch/match_legacy.lua @@ -8,8 +8,10 @@ local MatchLegacy = {} +local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -39,10 +41,8 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = game2.scores or {} - if type(scores) == 'string' then - scores = Json.parse(scores) - end + local opponents = Json.parseIfString(game2.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 local res = mw.ext.LiquipediaDB.lpdb_game( diff --git a/components/match2/wikis/paladins/match_legacy.lua b/components/match2/wikis/paladins/match_legacy.lua index c773218e19..ade98d77da 100644 --- a/components/match2/wikis/paladins/match_legacy.lua +++ b/components/match2/wikis/paladins/match_legacy.lua @@ -11,6 +11,7 @@ local MatchLegacy = {} local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -108,7 +109,7 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = Json.parseIfString(game2.scores) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 diff --git a/components/match2/wikis/pokemon/match_summary.lua b/components/match2/wikis/pokemon/match_summary.lua index 883fca0980..f2c3aadb5d 100644 --- a/components/match2/wikis/pokemon/match_summary.lua +++ b/components/match2/wikis/pokemon/match_summary.lua @@ -13,6 +13,7 @@ local DateExt = require('Module:Date/Ext') local FnUtil = require('Module:FnUtil') local Logic = require('Module:Logic') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper') local MatchSummary = Lua.import('Module:MatchSummary/Base') @@ -55,13 +56,15 @@ function CustomMatchSummary._createGame(date, game, gameIndex) MatchSummary.buildCharacterList(extradata, 'team2champion', NUM_CHAMPIONS_PICK), } - if Logic.isEmpty(game.scores) and Logic.isEmpty(game.winner) and Logic.isDeepEmpty(characterData) then + local scores = Array.map(game.opponents, Operator.property('score')) + + if Logic.isEmpty(scores) and Logic.isEmpty(game.winner) and Logic.isDeepEmpty(characterData) then return nil end local score - if Logic.isNotEmpty(game.scores) then - score = table.concat(game.scores, '-') + if Logic.isNotEmpty(scores) then + score = table.concat(scores, '-') end return MatchSummaryWidgets.Row{ diff --git a/components/match2/wikis/rainbowsix/match_legacy.lua b/components/match2/wikis/rainbowsix/match_legacy.lua index 8a825fa393..beb6f83cee 100644 --- a/components/match2/wikis/rainbowsix/match_legacy.lua +++ b/components/match2/wikis/rainbowsix/match_legacy.lua @@ -8,8 +8,10 @@ local MatchLegacy = {} +local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -32,6 +34,8 @@ function MatchLegacy.storeGames(match, match2) local game = Table.deepCopy(game2) -- Extradata local extradata = Json.parseIfString(game2.extradata) + local opponents = Json.parseIfString(game2.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.extradata = {} game.extradata.gamenumber = gameIndex if extradata.t1bans and extradata.t2bans then @@ -75,10 +79,6 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = game2.scores or {} - if type(scores) == 'string' then - scores = Json.parse(scores) - end game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 local res = mw.ext.LiquipediaDB.lpdb_game( @@ -142,10 +142,11 @@ function MatchLegacy._convertParameters(match2) local opponentmatch2players = opponent.match2players or {} if opponent.type == 'team' then match[prefix] = mw.ext.TeamTemplate.teampage(opponent.template) - if match2.bestof == 1 then - if ((match2.match2games or {})[1] or {}).scores then - match[prefix..'score'] = Json.parseIfString(match2.match2games[1].scores)[index] - end + local firstGame = (match2.match2games or {})[1] + if match2.bestof == 1 and firstGame then + local opponents = Json.parseIfString(firstGame.opponents) or {} + local firstGameScores = Array.map(opponents, Operator.property('score')) + match[prefix..'score'] = firstGameScores[index] end if not match[prefix..'score'] then match[prefix..'score'] = (tonumber(opponent.score) or 0) > 0 and opponent.score or 0 diff --git a/components/match2/wikis/rocketleague/match_legacy.lua b/components/match2/wikis/rocketleague/match_legacy.lua index d640b6ac69..866f345ea3 100644 --- a/components/match2/wikis/rocketleague/match_legacy.lua +++ b/components/match2/wikis/rocketleague/match_legacy.lua @@ -8,8 +8,10 @@ local MatchLegacy = {} +local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -35,10 +37,8 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = game.scores or {} - if type(scores) == 'string' then - scores = Json.parse(scores) - end + local opponents = Json.parseIfString(game.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 local res = mw.ext.LiquipediaDB.lpdb_game( diff --git a/components/match2/wikis/sideswipe/match_legacy.lua b/components/match2/wikis/sideswipe/match_legacy.lua index 07dfd6140e..44f428019a 100644 --- a/components/match2/wikis/sideswipe/match_legacy.lua +++ b/components/match2/wikis/sideswipe/match_legacy.lua @@ -8,8 +8,10 @@ local p = {} +local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -37,10 +39,8 @@ function p.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = game.scores or {} - if type(scores) == 'string' then - scores = Json.parse(scores) - end + local opponents = Json.parseIfString(game.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 local res = mw.ext.LiquipediaDB.lpdb_game( diff --git a/components/match2/wikis/smash/match_legacy.lua b/components/match2/wikis/smash/match_legacy.lua index 5d447db1c8..9b5fc54c6b 100644 --- a/components/match2/wikis/smash/match_legacy.lua +++ b/components/match2/wikis/smash/match_legacy.lua @@ -35,6 +35,7 @@ function MatchLegacy._storeGames(match, match2) local games = Array.map(match2.match2games or {}, function(game2, gameIndex) local game = Table.deepCopy(game2) local opponents = Json.parseIfString(game2.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) -- Extradata game.extradata = {} @@ -59,7 +60,6 @@ function MatchLegacy._storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag - local scores = Json.parseIfString(game2.scores) or {} game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 return mw.ext.LiquipediaDB.lpdb_game( diff --git a/components/match2/wikis/splatoon/match_legacy.lua b/components/match2/wikis/splatoon/match_legacy.lua index 57a46dc9df..09b1991b84 100644 --- a/components/match2/wikis/splatoon/match_legacy.lua +++ b/components/match2/wikis/splatoon/match_legacy.lua @@ -8,8 +8,10 @@ local MatchLegacy = {} +local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -41,10 +43,8 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = game2.scores or {} - if type(scores) == 'string' then - scores = Json.parse(scores) - end + local opponents = Json.parseIfString(game.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 local res = mw.ext.LiquipediaDB.lpdb_game( diff --git a/components/match2/wikis/trackmania/match_legacy.lua b/components/match2/wikis/trackmania/match_legacy.lua index 71d090620d..cc693ffa3b 100644 --- a/components/match2/wikis/trackmania/match_legacy.lua +++ b/components/match2/wikis/trackmania/match_legacy.lua @@ -8,8 +8,10 @@ local MatchLegacy = {} +local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') @@ -38,7 +40,8 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = Json.parseIfString(game.scores or {}) + local opponents = Json.parseIfString(game.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 local res = mw.ext.LiquipediaDB.lpdb_game( diff --git a/components/match2/wikis/valorant/match_legacy.lua b/components/match2/wikis/valorant/match_legacy.lua index acec0c6f76..4f9880bafe 100644 --- a/components/match2/wikis/valorant/match_legacy.lua +++ b/components/match2/wikis/valorant/match_legacy.lua @@ -12,6 +12,7 @@ local Array = require('Module:Array') local Json = require('Module:Json') local Logic = require('Module:Logic') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') local Variables = require('Module:Variables') @@ -36,6 +37,8 @@ function MatchLegacy.storeGames(match, match2) local game = Table.deepCopy(game2) -- Extradata local extradata = Json.parseIfString(game2.extradata) + local opponents = Json.parseIfString(game2.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.extradata = {} game.extradata.gamenumber = gameIndex if extradata then @@ -102,7 +105,6 @@ function MatchLegacy.storeGames(match, match2) game.opponent2flag = match.opponent2flag game.date = match.date - local scores = Json.parseIfString(game2.scores) or {} game.opponent1score = scores[1] or 0 game.opponent2score = scores[2] or 0 @@ -149,9 +151,11 @@ function MatchLegacy._convertParameters(match2) local opponent1score = 0 local opponent2score = 0 - local scores = MatchLegacy._getAllInGames(match2, 'scores') - for _, stringScore in pairs(scores) do - local score = Json.parseIfString(stringScore) + local scores = Array.map(match2.match2games or {}, function(game) + local opponents = Json.parseIfString(game.opponents) or {} + return Array.map(opponents, Operator.property('score')) + end) + for _, score in pairs(scores) do opponent1score = opponent1score + (tonumber(score[1]) or 0) opponent2score = opponent2score + (tonumber(score[2]) or 0) end @@ -187,10 +191,8 @@ function MatchLegacy._convertParameters(match2) local opponent = match2.match2opponents[index] or {} if opponent.type == 'team' then match[prefix] = opponent.name - if match2.bestof == 1 then - if ((match2.match2games or {})[1] or {}).scores then - match[prefix .. 'score'] = Json.parseIfString(match2.match2games[1].scores)[index] - end + if match2.bestof == 1 and scores[1] then + match[prefix .. 'score'] = scores[1][index] end if not match[prefix..'score'] then match[prefix..'score'] = (tonumber(opponent.score) or 0) > 0 and opponent.score or 0 diff --git a/components/match2/wikis/warcraft/match_legacy.lua b/components/match2/wikis/warcraft/match_legacy.lua index 320f409869..5045ba846d 100644 --- a/components/match2/wikis/warcraft/match_legacy.lua +++ b/components/match2/wikis/warcraft/match_legacy.lua @@ -13,6 +13,7 @@ local Json = require('Module:Json') local Logic = require('Module:Logic') local Lua = require('Module:Lua') local Namespace = require('Module:Namespace') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') local Variables = require('Module:Variables') @@ -170,6 +171,7 @@ function MatchLegacy._groupIntoSubmatches(match2, objectName) if game.mode ~= '1v1' or not submatchIndex then return end local opponents = Json.parseIfString(game.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) if not submatches[submatchIndex] then submatches[submatchIndex] = { @@ -180,8 +182,8 @@ function MatchLegacy._groupIntoSubmatches(match2, objectName) end local submatch = submatches[submatchIndex] table.insert(submatch.games, game) - submatch.opponents[1].score = submatch.opponents[1].score + (tonumber((game.scores or {})[1]) or 0) - submatch.opponents[2].score = submatch.opponents[2].score + (tonumber((game.scores or {})[2]) or 0) + submatch.opponents[1].score = submatch.opponents[1].score + (scores[1] or 0) + submatch.opponents[2].score = submatch.opponents[2].score + (scores[2] or 0) end) return submatches @@ -240,6 +242,9 @@ end function MatchLegacy._storeGame(game2, gameIndex, match) if game2.status == 'notplayed' then return end + local opponents = Json.parseIfString(game2.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) + local objectName = match.objectName .. '_Map_' .. gameIndex local game = Table.deepCopy(match) @@ -247,9 +252,8 @@ function MatchLegacy._storeGame(game2, gameIndex, match) game.vod = game2.vod game.map = game2.map - game2.scores = game2.scores or {} - game.opponent1score = game2.scores[1] - game.opponent2score = game2.scores[2] + game.opponent1score = scores[1] + game.opponent2score = scores[2] local opponents = Json.parseIfString(game2.opponents) or {} local factions, heroes = MatchLegacy._heroesAndFactionFromGameOpponents(opponents) diff --git a/components/match2/wikis/zula/match_legacy.lua b/components/match2/wikis/zula/match_legacy.lua index dceebcce77..239b21e183 100644 --- a/components/match2/wikis/zula/match_legacy.lua +++ b/components/match2/wikis/zula/match_legacy.lua @@ -6,9 +6,11 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- +local Array = require('Module:Array') local Json = require('Module:Json') local Lua = require('Module:Lua') local Logic = require('Module:Logic') +local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') local TextSanitizer = require('Module:TextSanitizer') @@ -87,10 +89,8 @@ function MatchLegacy.convertParameters(match2) local opponent1Rounds, opponent2Rounds = 0, 0 local maps = {} for gameIndex, game in ipairs(match2.match2games or {}) do - local scores = game.scores or {} - if type(scores) == 'string' then - scores = Json.parse(game.scores) - end + local gameOpponents = Json.parseIfString(game.opponents) or {} + local scores = Array.map(gameOpponents, Operator.property('score')) opponent1Rounds = opponent1Rounds + (tonumber(scores[1] or '') or 0) opponent2Rounds = opponent2Rounds + (tonumber(scores[2] or '') or 0) match.extradata['vodgame' .. gameIndex] = game.vod @@ -174,6 +174,8 @@ function MatchLegacy.storeGames(match, match2) local game = Table.deepCopy(game2) -- Extradata local extradata = Json.parseIfString(game2.extradata) + local opponents = Json.parseIfString(game2.opponents) or {} + local scores = Array.map(opponents, Operator.property('score')) game.extradata = {} local opponent1scores, opponent2scores = {}, {} @@ -202,7 +204,6 @@ function MatchLegacy.storeGames(match, match2) game.opponent1flag = match.opponent1flag game.opponent2flag = match.opponent2flag game.date = match.date - local scores = game2.scores or {} if type(scores) == 'string' then scores = Json.parse(scores) end