Skip to content

Commit

Permalink
kick game.scores
Browse files Browse the repository at this point in the history
  • Loading branch information
hjpalpha committed Dec 23, 2024
1 parent e1e3c94 commit ac95eb9
Show file tree
Hide file tree
Showing 31 changed files with 120 additions and 89 deletions.
4 changes: 3 additions & 1 deletion components/game_table/commons/game_table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion components/game_table/commons/game_table_character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion components/match2/wikis/ageofempires/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion components/match2/wikis/arenafps/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion components/match2/wikis/artifact/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion components/match2/wikis/battalion/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions components/match2/wikis/brawlstars/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions components/match2/wikis/callofduty/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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(
Expand Down
10 changes: 7 additions & 3 deletions components/match2/wikis/clashofclans/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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


Expand Down Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions components/match2/wikis/counterstrike/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions components/match2/wikis/criticalops/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions components/match2/wikis/crossfire/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion components/match2/wikis/fighters/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion components/match2/wikis/fighters/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down
8 changes: 4 additions & 4 deletions components/match2/wikis/halo/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/omegastrikers/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions components/match2/wikis/overwatch/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion components/match2/wikis/paladins/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit ac95eb9

Please sign in to comment.