From 9da2afc3a940e2f9db670b33b7b37cde05d35333 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Tue, 10 Dec 2024 13:44:11 +0100 Subject: [PATCH] feat(match2): standardize map opponent enrichment --- .../match2/commons/match_summary_ffa.lua | 19 ++++++++++++++ .../match2/wikis/apexlegends/game_summary.lua | 22 +--------------- .../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, 26 insertions(+), 165 deletions(-) diff --git a/components/match2/commons/match_summary_ffa.lua b/components/match2/commons/match_summary_ffa.lua index e470c0b045..9d9a15c0ac 100644 --- a/components/match2/commons/match_summary_ffa.lua +++ b/components/match2/commons/match_summary_ffa.lua @@ -570,7 +570,26 @@ function MatchSummaryFfa.updateMatchOpponents(match) Array.forEach(match.opponents, function(opponent, idx) opponent.placementStatus = match.extradata.status[idx] end) +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..4013893746 100644 --- a/components/match2/wikis/apexlegends/game_summary.lua +++ b/components/match2/wikis/apexlegends/game_summary.lua @@ -35,7 +35,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 +66,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