From ab4695db5810015789122cd90dfa3cd437a879e8 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Tue, 10 Dec 2024 18:39:21 +0100 Subject: [PATCH] feat(match2): standardize br-map opponent enrichment (#5189) * feat(match2): standardize map opponent enrichment * lint * incorrectly merged * review comment --- .../match2/commons/match_summary_ffa.lua | 22 +++++++++++++++- .../match2/wikis/apexlegends/game_summary.lua | 25 +------------------ .../match2/wikis/fortnite/game_summary.lua | 25 +------------------ .../match2/wikis/freefire/game_summary.lua | 25 +------------------ .../match2/wikis/naraka/game_summary.lua | 25 +------------------ components/match2/wikis/pubg/game_summary.lua | 25 +------------------ .../match2/wikis/pubgmobile/game_summary.lua | 25 +------------------ .../match2/wikis/underlords/game_summary.lua | 25 +------------------ 8 files changed, 28 insertions(+), 169 deletions(-) diff --git a/components/match2/commons/match_summary_ffa.lua b/components/match2/commons/match_summary_ffa.lua index ea695c0bed..e759ae5e9d 100644 --- a/components/match2/commons/match_summary_ffa.lua +++ b/components/match2/commons/match_summary_ffa.lua @@ -359,7 +359,7 @@ function MatchSummaryFfa.placementSortFunction(opponent1, opponent2) if opponent1.score and opponent2.score and opponent1.score ~= opponent2.score then return opponent1.score > opponent2.score end - return (opponent1.name or '') < (opponent2.name or '') + return (opponent1.name or ''):lower() < (opponent2.name or ''):lower() end ---@param match table @@ -571,4 +571,24 @@ function MatchSummaryFfa.updateMatchOpponents(match) Array.sortInPlaceBy(match.opponents, FnUtil.identity, MatchSummaryFfa.placementSortFunction) end +---@param game table +---@param matchOpponents table[] +function MatchSummaryFfa.updateGameOpponents(game, matchOpponents) + -- Add match opponent data to game opponent + game.opponents = Array.map(game.opponents, + function(gameOpponent, opponentIdx) + local matchOpponent = matchOpponents[opponentIdx] + local newGameOpponent = Table.merge(matchOpponent, gameOpponent) + -- These values are only allowed to come from Game and not Match + newGameOpponent.placement = gameOpponent.placement + newGameOpponent.score = gameOpponent.score + newGameOpponent.status = gameOpponent.status + return newGameOpponent + end + ) + + -- Sort game level based on placement + Array.sortInPlaceBy(game.opponents, FnUtil.identity, MatchSummaryFfa.placementSortFunction) +end + return MatchSummaryFfa diff --git a/components/match2/wikis/apexlegends/game_summary.lua b/components/match2/wikis/apexlegends/game_summary.lua index 14654ba447..cacc964114 100644 --- a/components/match2/wikis/apexlegends/game_summary.lua +++ b/components/match2/wikis/apexlegends/game_summary.lua @@ -8,11 +8,8 @@ local CustomGameSummary = {} -local Array = require('Module:Array') -local FnUtil = require('Module:FnUtil') local Lua = require('Module:Lua') local Page = require('Module:Page') -local Table = require('Module:Table') local MatchGroupUtil = Lua.import('Module:MatchGroup/Util') @@ -35,7 +32,7 @@ function CustomGameSummary.getGameByMatchId(props) game.stream = match.stream - CustomGameSummary._opponents(game, match.opponents) + SummaryHelper.updateGameOpponents(game, match.opponents) local scoringData = SummaryHelper.createScoringData(match) return MatchSummaryWidgets.Tab{ @@ -66,24 +63,4 @@ function CustomGameSummary._createGameDetails(game) } end ----@param game table ----@param matchOpponents table[] -function CustomGameSummary._opponents(game, matchOpponents) - -- Add match opponent data to game opponent - game.opponents = Array.map(game.opponents, - function(gameOpponent, opponentIdx) - local matchOpponent = matchOpponents[opponentIdx] - local newGameOpponent = Table.merge(matchOpponent, gameOpponent) - -- These values are only allowed to come from Game and not Match - newGameOpponent.placement = gameOpponent.placement - newGameOpponent.score = gameOpponent.score - newGameOpponent.status = gameOpponent.status - return newGameOpponent - end - ) - - -- Sort game level based on placement - Array.sortInPlaceBy(game.opponents, FnUtil.identity, SummaryHelper.placementSortFunction) -end - return CustomGameSummary diff --git a/components/match2/wikis/fortnite/game_summary.lua b/components/match2/wikis/fortnite/game_summary.lua index 089ec0f1cc..15596b5a0e 100644 --- a/components/match2/wikis/fortnite/game_summary.lua +++ b/components/match2/wikis/fortnite/game_summary.lua @@ -8,11 +8,8 @@ local CustomGameSummary = {} -local Array = require('Module:Array') -local FnUtil = require('Module:FnUtil') local Lua = require('Module:Lua') local Page = require('Module:Page') -local Table = require('Module:Table') local MatchGroupUtil = Lua.import('Module:MatchGroup/Util') @@ -35,7 +32,7 @@ function CustomGameSummary.getGameByMatchId(props) game.stream = match.stream - CustomGameSummary._opponents(game, match.opponents) + SummaryHelper.updateGameOpponents(game, match.opponents) local scoringData = SummaryHelper.createScoringData(match) return MatchSummaryWidgets.Tab{ @@ -66,24 +63,4 @@ function CustomGameSummary._createGameDetails(game) } end ----@param game table ----@param matchOpponents table[] -function CustomGameSummary._opponents(game, matchOpponents) - -- Add match opponent data to game opponent - game.opponents = Array.map(game.opponents, - function(gameOpponent, opponentIdx) - local matchOpponent = matchOpponents[opponentIdx] - local newGameOpponent = Table.merge(matchOpponent, gameOpponent) - -- These values are only allowed to come from Game and not Match - newGameOpponent.placement = gameOpponent.placement - newGameOpponent.score = gameOpponent.score - newGameOpponent.status = gameOpponent.status - return newGameOpponent - end - ) - - -- Sort game level based on placement - Array.sortInPlaceBy(game.opponents, FnUtil.identity, SummaryHelper.placementSortFunction) -end - return CustomGameSummary diff --git a/components/match2/wikis/freefire/game_summary.lua b/components/match2/wikis/freefire/game_summary.lua index a7ef857512..a532577f33 100644 --- a/components/match2/wikis/freefire/game_summary.lua +++ b/components/match2/wikis/freefire/game_summary.lua @@ -8,11 +8,8 @@ local CustomGameSummary = {} -local Array = require('Module:Array') -local FnUtil = require('Module:FnUtil') local Lua = require('Module:Lua') local Page = require('Module:Page') -local Table = require('Module:Table') local MatchGroupUtil = Lua.import('Module:MatchGroup/Util') @@ -35,7 +32,7 @@ function CustomGameSummary.getGameByMatchId(props) game.stream = match.stream - CustomGameSummary._opponents(game, match.opponents) + SummaryHelper.updateGameOpponents(game, match.opponents) local scoringData = SummaryHelper.createScoringData(match) return MatchSummaryWidgets.Tab{ @@ -66,24 +63,4 @@ function CustomGameSummary._createGameDetails(game) } end ----@param game table ----@param matchOpponents table[] -function CustomGameSummary._opponents(game, matchOpponents) - -- Add match opponent data to game opponent - game.opponents = Array.map(game.opponents, - function(gameOpponent, opponentIdx) - local matchOpponent = matchOpponents[opponentIdx] - local newGameOpponent = Table.merge(matchOpponent, gameOpponent) - -- These values are only allowed to come from Game and not Match - newGameOpponent.placement = gameOpponent.placement - newGameOpponent.score = gameOpponent.score - newGameOpponent.status = gameOpponent.status - return newGameOpponent - end - ) - - -- Sort game level based on placement - Array.sortInPlaceBy(game.opponents, FnUtil.identity, SummaryHelper.placementSortFunction) -end - return CustomGameSummary diff --git a/components/match2/wikis/naraka/game_summary.lua b/components/match2/wikis/naraka/game_summary.lua index 497fc355ce..5d68def207 100644 --- a/components/match2/wikis/naraka/game_summary.lua +++ b/components/match2/wikis/naraka/game_summary.lua @@ -8,11 +8,8 @@ local CustomGameSummary = {} -local Array = require('Module:Array') -local FnUtil = require('Module:FnUtil') local Lua = require('Module:Lua') local Page = require('Module:Page') -local Table = require('Module:Table') local MatchGroupUtil = Lua.import('Module:MatchGroup/Util') @@ -35,7 +32,7 @@ function CustomGameSummary.getGameByMatchId(props) game.stream = match.stream - CustomGameSummary._opponents(game, match.opponents) + SummaryHelper.updateGameOpponents(game, match.opponents) local scoringData = SummaryHelper.createScoringData(match) return MatchSummaryWidgets.Tab{ @@ -66,24 +63,4 @@ function CustomGameSummary._createGameDetails(game) } end ----@param game table ----@param matchOpponents table[] -function CustomGameSummary._opponents(game, matchOpponents) - -- Add match opponent data to game opponent - game.opponents = Array.map(game.opponents, - function(gameOpponent, opponentIdx) - local matchOpponent = matchOpponents[opponentIdx] - local newGameOpponent = Table.merge(matchOpponent, gameOpponent) - -- These values are only allowed to come from Game and not Match - newGameOpponent.placement = gameOpponent.placement - newGameOpponent.score = gameOpponent.score - newGameOpponent.status = gameOpponent.status - return newGameOpponent - end - ) - - -- Sort game level based on placement - Array.sortInPlaceBy(game.opponents, FnUtil.identity, SummaryHelper.placementSortFunction) -end - return CustomGameSummary diff --git a/components/match2/wikis/pubg/game_summary.lua b/components/match2/wikis/pubg/game_summary.lua index 8b1cc6b97e..cc0e6e617f 100644 --- a/components/match2/wikis/pubg/game_summary.lua +++ b/components/match2/wikis/pubg/game_summary.lua @@ -8,11 +8,8 @@ local CustomGameSummary = {} -local Array = require('Module:Array') -local FnUtil = require('Module:FnUtil') local Lua = require('Module:Lua') local Page = require('Module:Page') -local Table = require('Module:Table') local MatchGroupUtil = Lua.import('Module:MatchGroup/Util') @@ -35,7 +32,7 @@ function CustomGameSummary.getGameByMatchId(props) game.stream = match.stream - CustomGameSummary._opponents(game, match.opponents) + SummaryHelper.updateGameOpponents(game, match.opponents) local scoringData = SummaryHelper.createScoringData(match) return MatchSummaryWidgets.Tab{ @@ -66,24 +63,4 @@ function CustomGameSummary._createGameDetails(game) } end ----@param game table ----@param matchOpponents table[] -function CustomGameSummary._opponents(game, matchOpponents) - -- Add match opponent data to game opponent - game.opponents = Array.map(game.opponents, - function(gameOpponent, opponentIdx) - local matchOpponent = matchOpponents[opponentIdx] - local newGameOpponent = Table.merge(matchOpponent, gameOpponent) - -- These values are only allowed to come from Game and not Match - newGameOpponent.placement = gameOpponent.placement - newGameOpponent.score = gameOpponent.score - newGameOpponent.status = gameOpponent.status - return newGameOpponent - end - ) - - -- Sort game level based on placement - Array.sortInPlaceBy(game.opponents, FnUtil.identity, SummaryHelper.placementSortFunction) -end - return CustomGameSummary diff --git a/components/match2/wikis/pubgmobile/game_summary.lua b/components/match2/wikis/pubgmobile/game_summary.lua index f472c4e43c..76233faebe 100644 --- a/components/match2/wikis/pubgmobile/game_summary.lua +++ b/components/match2/wikis/pubgmobile/game_summary.lua @@ -8,11 +8,8 @@ local CustomGameSummary = {} -local Array = require('Module:Array') -local FnUtil = require('Module:FnUtil') local Lua = require('Module:Lua') local Page = require('Module:Page') -local Table = require('Module:Table') local MatchGroupUtil = Lua.import('Module:MatchGroup/Util') @@ -35,7 +32,7 @@ function CustomGameSummary.getGameByMatchId(props) game.stream = match.stream - CustomGameSummary._opponents(game, match.opponents) + SummaryHelper.updateGameOpponents(game, match.opponents) local scoringData = SummaryHelper.createScoringData(match) return MatchSummaryWidgets.Tab{ @@ -66,24 +63,4 @@ function CustomGameSummary._createGameDetails(game) } end ----@param game table ----@param matchOpponents table[] -function CustomGameSummary._opponents(game, matchOpponents) - -- Add match opponent data to game opponent - game.opponents = Array.map(game.opponents, - function(gameOpponent, opponentIdx) - local matchOpponent = matchOpponents[opponentIdx] - local newGameOpponent = Table.merge(matchOpponent, gameOpponent) - -- These values are only allowed to come from Game and not Match - newGameOpponent.placement = gameOpponent.placement - newGameOpponent.score = gameOpponent.score - newGameOpponent.status = gameOpponent.status - return newGameOpponent - end - ) - - -- Sort game level based on placement - Array.sortInPlaceBy(game.opponents, FnUtil.identity, SummaryHelper.placementSortFunction) -end - return CustomGameSummary diff --git a/components/match2/wikis/underlords/game_summary.lua b/components/match2/wikis/underlords/game_summary.lua index 689a6ca935..a204cbd2e9 100644 --- a/components/match2/wikis/underlords/game_summary.lua +++ b/components/match2/wikis/underlords/game_summary.lua @@ -8,11 +8,8 @@ local CustomGameSummary = {} -local Array = require('Module:Array') -local FnUtil = require('Module:FnUtil') local Lua = require('Module:Lua') local Page = require('Module:Page') -local Table = require('Module:Table') local MatchGroupUtil = Lua.import('Module:MatchGroup/Util') @@ -35,7 +32,7 @@ function CustomGameSummary.getGameByMatchId(props) game.stream = match.stream - CustomGameSummary._opponents(game, match.opponents) + SummaryHelper.updateGameOpponents(game, match.opponents) local scoringData = SummaryHelper.createScoringData(match) return MatchSummaryWidgets.Tab{ @@ -66,24 +63,4 @@ function CustomGameSummary._createGameDetails(game) } end ----@param game table ----@param matchOpponents table[] -function CustomGameSummary._opponents(game, matchOpponents) - -- Add match opponent data to game opponent - game.opponents = Array.map(game.opponents, - function(gameOpponent, opponentIdx) - local matchOpponent = matchOpponents[opponentIdx] - local newGameOpponent = Table.merge(matchOpponent, gameOpponent) - -- These values are only allowed to come from Game and not Match - newGameOpponent.placement = gameOpponent.placement - newGameOpponent.score = gameOpponent.score - newGameOpponent.status = gameOpponent.status - return newGameOpponent - end - ) - - -- Sort game level based on placement - Array.sortInPlaceBy(game.opponents, FnUtil.identity, SummaryHelper.placementSortFunction) -end - return CustomGameSummary