Skip to content

Commit

Permalink
feat(match2): Add non-BR support for PUBG Mobile (#5278)
Browse files Browse the repository at this point in the history
* feat(match2): Add non-BR support for PUBG Mobile

* Create match_summary

* Update components/match2/wikis/pubgmobile/match_group_input_custom.lua

Co-authored-by: Rikard Blixt <[email protected]>

* Rename match_summary to match_summary.lua

---------

Co-authored-by: Rikard Blixt <[email protected]>
  • Loading branch information
thangcoi02 and Rathoz authored Jan 3, 2025
1 parent d45a1dd commit 0f0c2c2
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 14 deletions.
84 changes: 70 additions & 14 deletions components/match2/wikis/pubgmobile/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,100 @@ local Operator = require('Module:Operator')

local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')

local MapFunctions = {}
local MatchFunctions = {
OPPONENT_CONFIG = {
resolveRedirect = true,
applyUnderScores = true,
maxNumPlayers = 4,
},
DEFAULT_MODE = 'tdm',
getBestOf = MatchGroupInputUtil.getBestOf,
}
local MapFunctions = {}

local FfaMatchFunctions = {
OPPONENT_CONFIG = {
resolveRedirect = true,
applyUnderScores = true,
maxNumPlayers = 4,
},
DEFAULT_MODE = 'team'
}
local FfaMapFunctions = {}

local CustomMatchGroupInput = {}

---@param match table
---@param options table?
---@return table
function CustomMatchGroupInput.processMatch(match, options)
return MatchGroupInputUtil.standardProcessFfaMatch(match, MatchFunctions)
return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions, FfaMatchFunctions)
end

--
-- match related functions
--
--- Normal 2-opponent Match

---@param match table
---@param opponents table[]
---@return table[]
function MatchFunctions.extractMaps(match, opponents)
return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions)
end

---@param maps table[]
---@return fun(opponentIndex: integer): integer?
function MatchFunctions.calculateMatchScore(maps)
return function(opponentIndex)
return MatchGroupInputUtil.computeMatchScoreFromMapWinners(maps, opponentIndex)
end
end

---@param match table
---@param games table[]
---@param opponents table[]
---@return table
function MatchFunctions.getExtraData(match, games, opponents)
return {
mvp = MatchGroupInputUtil.readMvp(match, opponents),
}
end

---@param match table
---@param map table
---@param opponents table[]
---@return table
function MapFunctions.getExtraData(match, map, opponents)
return {
comment = map.comment,
}
end

---@param map table
---@return fun(opponentIndex: integer): integer?
function MapFunctions.calculateMapScore(map)
local winner = tonumber(map.winner)
return function(opponentIndex)
-- TODO Better to check if map has started, rather than finished, for a more correct handling
if not winner then
return
end
return winner == opponentIndex and 1 or 0
end
end

--- FFA Match

---@param match table
---@param opponents table[]
---@param scoreSettings table
---@return table[]
function MatchFunctions.extractMaps(match, opponents, scoreSettings)
return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, MapFunctions)
function FfaMatchFunctions.extractMaps(match, opponents, scoreSettings)
return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, FfaMapFunctions)
end

---@param opponents table[]
---@param maps table[]
---@return fun(opponentIndex: integer): integer?
function MatchFunctions.calculateMatchScore(opponents, maps)
function FfaMatchFunctions.calculateMatchScore(opponents, maps)
return function(opponentIndex)
return Array.reduce(Array.map(maps, function(map)
return map.opponents[opponentIndex].score or 0
Expand All @@ -58,22 +118,18 @@ end
---@param opponents table[]
---@param settings table
---@return table
function MatchFunctions.getExtraData(match, games, opponents, settings)
function FfaMatchFunctions.getExtraData(match, games, opponents, settings)
return {
placementinfo = settings.placementInfo,
settings = settings.settings,
}
end

--
-- map related functions
--

---@param match table
---@param map table
---@param opponents table[]
---@return table
function MapFunctions.getExtraData(match, map, opponents)
function FfaMapFunctions.getExtraData(match, map, opponents)
return {
dateexact = map.dateexact,
comment = map.comment,
Expand Down
51 changes: 51 additions & 0 deletions components/match2/wikis/pubgmobile/match_summary.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
-- @Liquipedia
-- wiki=pubgmobile
-- page=Module:MatchSummary
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Lua = require('Module:Lua')

local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
local MatchSummary = Lua.import('Module:MatchSummary/Base')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')
local WidgetUtil = Lua.import('Module:Widget/Util')

local CustomMatchSummary = {}

---@param args table
---@return Html
function CustomMatchSummary.getByMatchId(args)
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args)
end

---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
---@return Widget?
function CustomMatchSummary.createGame(date, game, gameIndex)
if not game.map then
return
end

local function makeTeamSection(opponentIndex)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

return MatchSummaryWidgets.Row{
classes = {'brkts-popup-body-game'},
children = WidgetUtil.collect(
MatchSummaryWidgets.GameTeamWrapper{children = makeTeamSection(1)},
MatchSummaryWidgets.GameCenter{children = DisplayHelper.Map(game)},
MatchSummaryWidgets.GameTeamWrapper{children = makeTeamSection(2), flipped = true},
MatchSummaryWidgets.GameComment{children = game.comment}
)
}
end

return CustomMatchSummary

0 comments on commit 0f0c2c2

Please sign in to comment.