Skip to content

Commit

Permalink
feat(match2): further standarize BR (#5179)
Browse files Browse the repository at this point in the history
* feat(match2): further standarize BR

* function call
  • Loading branch information
Rathoz authored Dec 10, 2024
1 parent 0c81760 commit 9664dbe
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 382 deletions.
40 changes: 40 additions & 0 deletions components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1453,8 +1453,48 @@ function MatchGroupInputUtil.parseSettings(match, opponentCount)
status = statusSettings,
settings = {
showGameDetails = Logic.nilOr(Logic.readBoolOrNil(match.showgamedetails), true),
matchPointThreshold = tonumber(match.matchpoint),
}
}
end

---@param scoreDataInput table?
---@param scoreSettings {kill: integer[], placement: integer[]}
---@return table
function MatchGroupInputUtil.makeBattleRoyaleMapOpponentDetails(scoreDataInput, scoreSettings)
if not scoreDataInput then
return {}
end

local scoreBreakdown = {}

local placement, kills = tonumber(scoreDataInput[1]), tonumber(scoreDataInput[2])
local manualPoints = tonumber(scoreDataInput.p)
if placement or kills then
local minimumKillPoints = Array.reduce(scoreSettings.kill, math.min, math.huge)
if placement then
scoreBreakdown.placePoints = scoreSettings.placement[placement] or 0
end
if kills then
scoreBreakdown.killPoints = kills * (scoreSettings.kill[placement] or minimumKillPoints)
scoreBreakdown.kills = kills
end
scoreBreakdown.totalPoints = (scoreBreakdown.placePoints or 0) + (scoreBreakdown.killPoints or 0)
end

local opponent = {
status = MatchGroupInputUtil.STATUS.SCORE,
scoreBreakdown = scoreBreakdown,
placement = placement,
score = manualPoints or scoreBreakdown.totalPoints,
}

if scoreDataInput[1] == '-' then
opponent.status = MatchGroupInputUtil.STATUS.FORFEIT
opponent.score = 0
end

return opponent
end

return MatchGroupInputUtil
37 changes: 36 additions & 1 deletion components/match2/commons/match_summary_ffa.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--

local Array = require('Module:Array')
local FnUtil = require('Module:FnUtil')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Table = require('Module:Table')
Expand Down Expand Up @@ -140,7 +141,7 @@ local MATCH_OVERVIEW_COLUMNS = {
class = 'cell--match-points',
icon = 'matchpoint',
show = function(match)
return match.matchPointThreshold
return match.extradata.settings.matchPointThreshold
end,
header = {
value = 'MPe Game',
Expand Down Expand Up @@ -537,5 +538,39 @@ function MatchSummaryFfa.standardGame(game)
}}
end

---@param match table
function MatchSummaryFfa.updateMatchOpponents(match)
-- Add games opponent data to the match opponent
Array.forEach(match.opponents, function (opponent, idx)
opponent.games = Array.map(match.games, function (game)
return game.opponents[idx]
end)
end)

local matchPointThreshold = match.extradata.settings.matchPointThreshold
if matchPointThreshold then
Array.forEach(match.opponents, function(opponent)
local matchPointReachedIn
local sum = opponent.extradata.startingpoints or 0
for gameIdx, game in ipairs(opponent.games) do
if sum >= matchPointThreshold then
matchPointReachedIn = gameIdx
break
end
sum = sum + (game.score or 0)
end
opponent.matchPointReachedIn = matchPointReachedIn
end)
end

-- Sort match level based on final placement & score
Array.sortInPlaceBy(match.opponents, FnUtil.identity, MatchSummaryFfa.placementSortFunction)

-- Set the status of the current placement
Array.forEach(match.opponents, function(opponent, idx)
opponent.placementStatus = match.extradata.status[idx]
end)

end

return MatchSummaryFfa
38 changes: 1 addition & 37 deletions components/match2/wikis/apexlegends/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function MatchFunctions.extractMaps(match, opponents, scoreSettings)

map.opponents = Array.map(opponents, function(matchOpponent)
local opponentMapInput = Json.parseIfString(matchOpponent['m' .. mapIndex])
return MapFunctions.makeMapOpponentDetails(opponentMapInput, scoreSettings)
return MatchGroupInputUtil.makeBattleRoyaleMapOpponentDetails(opponentMapInput, scoreSettings)
end)

map.scores = Array.map(map.opponents, Operator.property('score'))
Expand Down Expand Up @@ -106,40 +106,4 @@ function MapFunctions.getExtraData(map)
}
end

---@param scoreDataInput table?
---@param scoreSettings table
---@return table
function MapFunctions.makeMapOpponentDetails(scoreDataInput, scoreSettings)
if not scoreDataInput then
return {}
end

local scoreBreakdown = {}

local placement, kills = tonumber(scoreDataInput[1]), tonumber(scoreDataInput[2])
if placement or kills then
if placement then
scoreBreakdown.placePoints = scoreSettings.placement[placement] or 0
end
if kills then
scoreBreakdown.killPoints = kills * scoreSettings.kill
scoreBreakdown.kills = kills
end
scoreBreakdown.totalPoints = (scoreBreakdown.placePoints or 0) + (scoreBreakdown.killPoints or 0)
end
local opponent = {
status = MatchGroupInputUtil.STATUS.SCORE,
scoreBreakdown = scoreBreakdown,
placement = placement,
score = scoreBreakdown.totalPoints,
}

if scoreDataInput[1] == '-' then
opponent.status = MatchGroupInputUtil.STATUS.FORFEIT
opponent.score = 0
end

return opponent
end

return CustomMatchGroupInput
38 changes: 1 addition & 37 deletions components/match2/wikis/apexlegends/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

local CustomMatchSummary = {}

local Array = require('Module:Array')
local FnUtil = require('Module:FnUtil')
local Lua = require('Module:Lua')
local Table = require('Module:Table')

local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')
local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
Expand All @@ -27,8 +24,7 @@ local HtmlWidgets = Lua.import('Module:Widget/Html/All')
function CustomMatchSummary.getByMatchId(props)
---@class ApexMatchGroupUtilMatch
local match = MatchGroupUtil.fetchMatchForBracketDisplay(props.bracketId, props.matchId)
match.matchPointThreshold = Table.extract(match.extradata.scoring, 'matchPointThreshold')
CustomMatchSummary._opponents(match)
SummaryHelper.updateMatchOpponents(match)
local scoringData = SummaryHelper.createScoringData(match)

return HtmlWidgets.Fragment{children = {
Expand All @@ -45,36 +41,4 @@ function CustomMatchSummary.getByMatchId(props)
}}
end

function CustomMatchSummary._opponents(match)
-- Add games opponent data to the match opponent
Array.forEach(match.opponents, function (opponent, idx)
opponent.games = Array.map(match.games, function (game)
return game.opponents[idx]
end)
end)

if match.matchPointThreshold then
Array.forEach(match.opponents, function(opponent)
local matchPointReachedIn
local sum = opponent.extradata.startingpoints or 0
for gameIdx, game in ipairs(opponent.games) do
if sum >= match.matchPointThreshold then
matchPointReachedIn = gameIdx
break
end
sum = sum + (game.score or 0)
end
opponent.matchPointReachedIn = matchPointReachedIn
end)
end

-- Sort match level based on final placement & score
Array.sortInPlaceBy(match.opponents, FnUtil.identity, SummaryHelper.placementSortFunction)

-- Set the status of the current placement
Array.forEach(match.opponents, function(opponent, idx)
opponent.placementStatus = match.extradata.status[idx]
end)
end

return CustomMatchSummary
40 changes: 1 addition & 39 deletions components/match2/wikis/fortnite/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function MatchFunctions.extractMaps(match, opponents, scoreSettings)

map.opponents = Array.map(opponents, function(matchOpponent)
local opponentMapInput = Json.parseIfString(matchOpponent['m' .. mapIndex])
return MapFunctions.makeMapOpponentDetails(opponentMapInput, scoreSettings)
return MatchGroupInputUtil.makeBattleRoyaleMapOpponentDetails(opponentMapInput, scoreSettings)
end)

map.scores = Array.map(map.opponents, Operator.property('score'))
Expand Down Expand Up @@ -106,42 +106,4 @@ function MapFunctions.getExtraData(map)
}
end

---@param scoreDataInput table?
---@param scoreSettings table
---@return table
function MapFunctions.makeMapOpponentDetails(scoreDataInput, scoreSettings)
if not scoreDataInput then
return {}
end

local scoreBreakdown = {}

local placement, kills = tonumber(scoreDataInput[1]), tonumber(scoreDataInput[2])
local points = tonumber(scoreDataInput.p)
if placement or kills then
if placement then
scoreBreakdown.placePoints = scoreSettings.placement[placement] or 0
end
if kills then
scoreBreakdown.killPoints = kills * scoreSettings.kill
scoreBreakdown.kills = kills
end
scoreBreakdown.totalPoints = (scoreBreakdown.placePoints or 0) + (scoreBreakdown.killPoints or 0)
end

local opponent = {
status = MatchGroupInputUtil.STATUS.SCORE,
scoreBreakdown = scoreBreakdown,
placement = placement,
score = points or scoreBreakdown.totalPoints,
}

if scoreDataInput[1] == '-' then
opponent.status = MatchGroupInputUtil.STATUS.FORFEIT
opponent.score = 0
end

return opponent
end

return CustomMatchGroupInput
26 changes: 3 additions & 23 deletions components/match2/wikis/fortnite/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

local CustomMatchSummary = {}

local Array = require('Module:Array')
local FnUtil = require('Module:FnUtil')
local Lua = require('Module:Lua')

local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')
Expand All @@ -19,14 +17,14 @@ local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')

---@class FortniteMatchGroupUtilMatch: MatchGroupUtilMatch
---@field games ApexMatchGroupUtilGame[]
---@field games FortniteMatchGroupUtilGame[]

---@param props {bracketId: string, matchId: string}
---@return Widget
function CustomMatchSummary.getByMatchId(props)
---@class ApexMatchGroupUtilMatch
---@class FortniteMatchGroupUtilMatch
local match = MatchGroupUtil.fetchMatchForBracketDisplay(props.bracketId, props.matchId)
CustomMatchSummary._opponents(match)
SummaryHelper.updateMatchOpponents(match)
local scoringData = SummaryHelper.createScoringData(match)

return HtmlWidgets.Fragment{children = {
Expand All @@ -43,22 +41,4 @@ function CustomMatchSummary.getByMatchId(props)
}}
end

---@param match table
function CustomMatchSummary._opponents(match)
-- Add games opponent data to the match opponent
Array.forEach(match.opponents, function (opponent, idx)
opponent.games = Array.map(match.games, function (game)
return game.opponents[idx]
end)
end)

-- Sort match level based on final placement & score
Array.sortInPlaceBy(match.opponents, FnUtil.identity, SummaryHelper.placementSortFunction)

-- Set the status of the current placement
Array.forEach(match.opponents, function(opponent, idx)
opponent.placementStatus = match.extradata.status[idx]
end)
end

return CustomMatchSummary
40 changes: 1 addition & 39 deletions components/match2/wikis/freefire/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function MatchFunctions.extractMaps(match, opponents, scoreSettings)

map.opponents = Array.map(opponents, function(matchOpponent)
local opponentMapInput = Json.parseIfString(matchOpponent['m' .. mapIndex])
return MapFunctions.makeMapOpponentDetails(opponentMapInput, scoreSettings)
return MatchGroupInputUtil.makeBattleRoyaleMapOpponentDetails(opponentMapInput, scoreSettings)
end)

map.scores = Array.map(map.opponents, Operator.property('score'))
Expand Down Expand Up @@ -106,42 +106,4 @@ function MapFunctions.getExtraData(map)
}
end

---@param scoreDataInput table?
---@param scoreSettings table
---@return table
function MapFunctions.makeMapOpponentDetails(scoreDataInput, scoreSettings)
if not scoreDataInput then
return {}
end

local scoreBreakdown = {}

local placement, kills = tonumber(scoreDataInput[1]), tonumber(scoreDataInput[2])
local points = tonumber(scoreDataInput.p)
if placement or kills then
if placement then
scoreBreakdown.placePoints = scoreSettings.placement[placement] or 0
end
if kills then
scoreBreakdown.killPoints = kills * scoreSettings.kill
scoreBreakdown.kills = kills
end
scoreBreakdown.totalPoints = (scoreBreakdown.placePoints or 0) + (scoreBreakdown.killPoints or 0)
end

local opponent = {
status = MatchGroupInputUtil.STATUS.SCORE,
scoreBreakdown = scoreBreakdown,
placement = placement,
score = points or scoreBreakdown.totalPoints,
}

if scoreDataInput[1] == '-' then
opponent.status = MatchGroupInputUtil.STATUS.FORFEIT
opponent.score = 0
end

return opponent
end

return CustomMatchGroupInput
Loading

0 comments on commit 9664dbe

Please sign in to comment.