Skip to content

Commit

Permalink
feat(match2): support both normal and ffa handling for a single wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz committed Dec 12, 2024
1 parent 02498b5 commit 8143485
Show file tree
Hide file tree
Showing 22 changed files with 60 additions and 30 deletions.
5 changes: 2 additions & 3 deletions components/match2/commons/brkts_wiki_specific_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ Called from MatchGroup
-- @returns module
]]
function WikiSpecificBase.getMatchGroupContainer(matchGroupType)
-- TODO Add a check if opponent count is > 2
if Lua.moduleExists('Module:GameSummary') then
function WikiSpecificBase.getMatchGroupContainer(matchGroupType, maxOpponentCount)
if Lua.moduleExists('Module:MatchSummary/Ffa') and maxOpponentCount > 2 then
local Horizontallist = Lua.import('Module:MatchGroup/Display/Horizontallist')
return Horizontallist.BracketContainer
elseif matchGroupType == 'matchlist' then
Expand Down
9 changes: 6 additions & 3 deletions components/match2/commons/match_group.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ function MatchGroup.MatchList(args)

local matchlistNode
if options.show then
local maxOpponentCount = MatchGroupInput.getMaxOpponentCount(matches)
local MatchlistDisplay = Lua.import('Module:MatchGroup/Display/Matchlist')
local MatchlistContainer = WikiSpecific.getMatchGroupContainer('matchlist')
local MatchlistContainer = WikiSpecific.getMatchGroupContainer('matchlist', maxOpponentCount)
matchlistNode = MatchlistContainer({
bracketId = options.bracketId,
config = MatchlistDisplay.configFromArgs(args),
Expand All @@ -62,8 +63,9 @@ function MatchGroup.Bracket(args)

local bracketNode
if options.show then
local maxOpponentCount = MatchGroupInput.getMaxOpponentCount(matches)
local BracketDisplay = Lua.import('Module:MatchGroup/Display/Bracket')
local BracketContainer = WikiSpecific.getMatchGroupContainer('bracket')
local BracketContainer = WikiSpecific.getMatchGroupContainer('bracket', maxOpponentCount)
bracketNode = BracketContainer({
bracketId = options.bracketId,
config = BracketDisplay.configFromArgs(args),
Expand Down Expand Up @@ -153,7 +155,8 @@ function MatchGroup.MatchGroupById(args)

Logic.wrapTryOrLog(MatchGroupInput.applyOverrideArgs)(matches, args)

local MatchGroupContainer = WikiSpecific.getMatchGroupContainer(matchGroupType)
local maxOpponentCount = MatchGroupInput.getMaxOpponentCount(matches)
local MatchGroupContainer = WikiSpecific.getMatchGroupContainer(matchGroupType, maxOpponentCount)
return MatchGroupContainer({
bracketId = bracketId,
config = config,
Expand Down
10 changes: 10 additions & 0 deletions components/match2/commons/match_group_display_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ function DisplayHelper.DefaultMatchSummaryContainer(props)
return MatchSummaryModule.getByMatchId(props)
end

---@param props table
---@return Html
function DisplayHelper.DefaultFfaMatchSummaryContainer(props)
local MatchSummaryModule = Lua.import('Module:MatchSummary/Ffa')

assert(MatchSummaryModule.getByMatchId, 'Expected MatchSummary/Ffa.getByMatchId to be a function')

return MatchSummaryModule.getByMatchId(props)
end

---@param props table
---@return Html
function DisplayHelper.DefaultGameSummaryContainer(props)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ end
---@return Html
function HorizontallistDisplay.Bracket(props)
local config = {
MatchSummaryContainer = DisplayHelper.DefaultMatchSummaryContainer,
MatchSummaryContainer = DisplayHelper.DefaultFfaMatchSummaryContainer,
}
local list = mw.html.create('ul'):addClass('navigation-tabs__list'):attr('role', 'tablist')

Expand Down
6 changes: 6 additions & 0 deletions components/match2/commons/match_group_input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ function MatchGroupInput.applyOverrideArgs(matches, args)
end
end

function MatchGroupInput.getMaxOpponentCount(matches)
return Array.reduce(matches, function(cur, match)
return math.max(#match.match2opponents, cur)
end)
end

---@param headerInput string?
---@return string?
function MatchGroupInput._inheritedHeader(headerInput)
Expand Down
20 changes: 14 additions & 6 deletions components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@ end
---@field DEFAULT_MODE? string
---@field DATE_FALLBACKS? string[]
---@field OPPONENT_CONFIG? readOpponentOptions
---@field HAS_FFA? boolean

--- The standard way to process a match input.
---
Expand All @@ -1087,13 +1088,15 @@ end
--- - DEFAULT_MODE: string
--- - DATE_FALLBACKS: string[]
--- - OPPONENT_CONFIG: table
--- - HAS_FFA: boolean
---@param match table
---@param Parser MatchParserInterface
---@param Parser MatchParserInterface?
---@param FfaParser FfaMatchParserInterface?
---@param mapProps any?
---@return table
function MatchGroupInputUtil.standardProcessMatch(match, Parser, mapProps)
local finishedInput = match.finished --[[@as string?]]
local winnerInput = match.winner --[[@as string?]]
function MatchGroupInputUtil.standardProcessMatch(match, Parser, FfaParser, mapProps)
Parser = Parser or {}
local matchInput = Table.deepCopy(match)

local dateProps = Parser.readDate and Parser.readDate(match)
or MatchGroupInputUtil.readDate(match.date, Parser.DATE_FALLBACKS)
Expand All @@ -1107,6 +1110,10 @@ function MatchGroupInputUtil.standardProcessMatch(match, Parser, mapProps)
return opponent
end)

if FfaParser and #opponents > 2 then
return MatchGroupInputUtil.standardProcessFfaMatch(matchInput, FfaParser, mapProps)
end

local games = Parser.extractMaps(match, opponents, mapProps)
match.bestof = Parser.getBestOf(match.bestof, games)
games = Parser.removeUnsetMaps and Parser.removeUnsetMaps(games) or games
Expand All @@ -1131,8 +1138,8 @@ function MatchGroupInputUtil.standardProcessMatch(match, Parser, mapProps)
match.finished = MatchGroupInputUtil.matchIsFinished(match, opponents)

if match.finished then
match.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput)
match.winner = MatchGroupInputUtil.getWinner(match.status, winnerInput, opponents)
match.status = MatchGroupInputUtil.getMatchStatus(matchInput.winner, matchInput.finished)
match.winner = MatchGroupInputUtil.getWinner(match.status, matchInput.winner, opponents)
Array.forEach(opponents, function(opponent, opponentIndex)
opponent.placement = MatchGroupInputUtil.placementFromWinner(match.status, match.winner, opponentIndex)
end)
Expand Down Expand Up @@ -1337,6 +1344,7 @@ function MatchGroupInputUtil.standardProcessFfaMatch(match, Parser, mapProps)
match.stream = Streams.processStreams(match)
match.links = MatchGroupInputUtil.getLinks(match)
match.extradata = Parser.getExtraData and Parser.getExtraData(match, games, opponents, settings) or {}
match.extradata.ffa = true

match.games = games
match.opponents = opponents
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
-- @Liquipedia
-- wiki=apexlegends
-- page=Module:MatchSummary
-- page=Module:MatchSummary/Ffa
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
Expand Down
4 changes: 2 additions & 2 deletions components/match2/wikis/autochess/game_summary.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
-- @autochess
-- wiki=underlords
-- @Liquipedia
-- wiki=autochess
-- page=Module:GameSummary
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
-- @Liquipedia
-- wiki=autochess
-- page=Module:MatchSummary
-- page=Module:MatchSummary/Ffa
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/dota2/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ end
---@param match table
---@return table
function CustomMatchGroupInput.processMatchWithoutStandalone(MapParser, match)
return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions, MapParser)
return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions, nil, MapParser)
end

---@param match table
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
-- @Liquipedia
-- wiki=fortnite
-- page=Module:MatchSummary
-- page=Module:MatchSummary/Ffa
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
-- @Liquipedia
-- wiki=freefire
-- page=Module:MatchSummary
-- page=Module:MatchSummary/Ffa
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ end
---@param match table
---@return table
function CustomMatchGroupInput.processMatchWithoutStandalone(MapParser, match)
return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions, MapParser)
return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions, nil, MapParser)
end

---@param match table
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
-- @Liquipedia
-- wiki=naraka
-- page=Module:MatchSummary
-- page=Module:MatchSummary/Ffa
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
-- @Liquipedia
-- wiki=pubg
-- page=Module:MatchSummary
-- page=Module:MatchSummary/Ffa
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
-- @Liquipedia
-- wiki=pubgmobile
-- page=Module:MatchSummary
-- page=Module:MatchSummary/Ffa
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
Expand Down
3 changes: 2 additions & 1 deletion components/match2/wikis/rocketleague/brkts_wiki_specific.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ local BaseWikiSpecific = Lua.import('Module:Brkts/WikiSpecific/Base')
local WikiSpecific = Table.copy(BaseWikiSpecific)

---@param matchGroupType string
---@param maxOpponentCount integer
---@return function
function WikiSpecific.getMatchGroupContainer(matchGroupType)
function WikiSpecific.getMatchGroupContainer(matchGroupType, maxOpponentCount)
return matchGroupType == 'matchlist'
and Lua.import('Module:MatchGroup/Display/Matchlist').MatchlistContainer
or Lua.import('Module:MatchGroup/Display/Bracket/Custom').BracketContainer
Expand Down
3 changes: 2 additions & 1 deletion components/match2/wikis/smash/brkts_wiki_specific.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ WikiSpecific.matchFromRecord = FnUtil.lazilyDefineFunction(function()
end)

---@param matchGroupType string
---@param maxOpponentCount integer
---@return function
function WikiSpecific.getMatchGroupContainer(matchGroupType)
function WikiSpecific.getMatchGroupContainer(matchGroupType, maxOpponentCount)
return matchGroupType == 'matchlist'
and Lua.import('Module:MatchGroup/Display/Matchlist').MatchlistContainer
or Lua.import('Module:MatchGroup/Display/Bracket/Custom').BracketContainer
Expand Down
3 changes: 2 additions & 1 deletion components/match2/wikis/starcraft/brkts_wiki_specific.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ WikiSpecific.processMatch = FnUtil.lazilyDefineFunction(function()
end)

---@param matchGroupType string
---@param maxOpponentCount integer
---@return function
function WikiSpecific.getMatchGroupContainer(matchGroupType)
function WikiSpecific.getMatchGroupContainer(matchGroupType, maxOpponentCount)
if matchGroupType == 'matchlist' then
local MatchList = Lua.import('Module:MatchGroup/Display/Matchlist')
return WikiSpecific.adjustMatchGroupContainerConfig(MatchList.MatchlistContainer)
Expand Down
3 changes: 2 additions & 1 deletion components/match2/wikis/starcraft2/brkts_wiki_specific.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ WikiSpecific.processMatch = FnUtil.lazilyDefineFunction(function()
end)

---@param matchGroupType string
---@param maxOpponentCount integer
---@return function
function WikiSpecific.getMatchGroupContainer(matchGroupType)
function WikiSpecific.getMatchGroupContainer(matchGroupType, maxOpponentCount)
if matchGroupType == 'matchlist' then
local MatchList = Lua.import('Module:MatchGroup/Display/Matchlist')
return WikiSpecific.adjustMatchGroupContainerConfig(MatchList.MatchlistContainer)
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/trackmania/brkts_wiki_specific.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local BaseWikiSpecific = Lua.import('Module:Brkts/WikiSpecific/Base')
---@class TrackmaniaBrktsWikiSpecific: BrktsWikiSpecific
local WikiSpecific = Table.copy(BaseWikiSpecific)

function WikiSpecific.getMatchGroupContainer(matchGroupType)
function WikiSpecific.getMatchGroupContainer(matchGroupType, maxOpponentCount)
return matchGroupType == 'matchlist'
and Lua.import('Module:MatchGroup/Display/Matchlist').MatchlistContainer
or Lua.import('Module:MatchGroup/Display/Bracket/Custom').BracketContainer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
-- @Liquipedia
-- wiki=underlords
-- page=Module:MatchSummary
-- page=Module:MatchSummary/Ffa
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
Expand Down

0 comments on commit 8143485

Please sign in to comment.