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
…5195)

* feat(match2): support both normal and ffa handling for a single wiki

* init value

* rename commons file

* fix tests

* type safety

* unused

* missing anno

* adjust logic based on feedback
  • Loading branch information
Rathoz authored Dec 12, 2024
1 parent 02498b5 commit 8745b73
Show file tree
Hide file tree
Showing 33 changed files with 101 additions and 54 deletions.
7 changes: 4 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,10 @@ 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 (maxOpponentCount > 2 or not Lua.moduleExists('Module:MatchSummary')) and
Lua.moduleExists('Module:MatchSummary/Ffa') 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
8 changes: 8 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,14 @@ function MatchGroupInput.applyOverrideArgs(matches, args)
end
end

---@param matches {match2opponents: table[]}[]
---@return integer
function MatchGroupInput.getMaxOpponentCount(matches)
return Array.reduce(matches, function(cur, match)
return math.max(#match.match2opponents, cur)
end, 0)
end

---@param headerInput string?
---@return string?
function MatchGroupInput._inheritedHeader(headerInput)
Expand Down
18 changes: 12 additions & 6 deletions components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1088,12 +1088,13 @@ end
--- - DATE_FALLBACKS: string[]
--- - OPPONENT_CONFIG: table
---@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 +1108,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 +1136,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 @@ -1351,6 +1356,7 @@ end
---
---@param match table
---@param opponents table[]
---@param scoreSettings table
---@param Parser MapParserInterface
---@return table
function MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, Parser)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
-- @Liquipedia
-- wiki=commons
-- page=Module:MatchSummary/Ffa
-- page=Module:MatchSummary/Base/Ffa
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
Expand Down Expand Up @@ -140,7 +140,7 @@ local MATCH_OVERVIEW_COLUMNS = {
class = 'cell--match-points',
icon = 'matchpoint',
show = function(match)
return match.extradata.settings.matchPointThreshold
return (match.extradata.settings or {}).matchPointThreshold
end,
header = {
value = 'MPe Game',
Expand All @@ -161,7 +161,7 @@ local MATCH_OVERVIEW_COLUMNS = {
local GAME_OVERVIEW_COLUMNS = {
{
show = function(match)
return match.extradata.settings.showGameDetails
return (match.extradata.settings or {}).showGameDetails
end,
class = 'panel-table__cell__game-placement',
icon = 'placement',
Expand Down Expand Up @@ -191,7 +191,7 @@ local GAME_OVERVIEW_COLUMNS = {
},
{
show = function(match)
if match.extradata.settings.showGameDetails == false then
if (match.extradata.settings or {}).showGameDetails == false then
return false
end
return Table.any(match.extradata.placementinfo or {}, function(_, value)
Expand All @@ -211,7 +211,7 @@ local GAME_OVERVIEW_COLUMNS = {
},
{
show = function(match)
return not match.extradata.settings.showGameDetails
return not (match.extradata.settings or {}).showGameDetails
end,
class = 'panel-table__cell__game-total-points',
icon = 'points',
Expand Down Expand Up @@ -551,7 +551,7 @@ function MatchSummaryFfa.updateMatchOpponents(match)
end)
end)

local matchPointThreshold = match.extradata.settings.matchPointThreshold
local matchPointThreshold = (match.extradata.settings or {}).matchPointThreshold
if matchPointThreshold then
Array.forEach(match.opponents, function(opponent)
local matchPointReachedIn
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/apexlegends/game_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local Lua = require('Module:Lua')

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

local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')

---@class ApexMatchGroupUtilGame: MatchGroupUtilGame
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 All @@ -11,7 +11,7 @@ local CustomMatchSummary = {}
local Lua = require('Module:Lua')

local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')
local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')

local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')
Expand Down
6 changes: 3 additions & 3 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 All @@ -12,7 +12,7 @@ local Lua = require('Module:Lua')

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

local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')

---@class AutochessMatchGroupUtilGame: MatchGroupUtilGame
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 All @@ -11,7 +11,7 @@ local CustomMatchSummary = {}
local Lua = require('Module:Lua')

local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')
local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')

local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')
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
2 changes: 1 addition & 1 deletion components/match2/wikis/fortnite/game_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local Lua = require('Module:Lua')

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

local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')

---@class FortniteMatchGroupUtilGame: MatchGroupUtilGame
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 All @@ -11,7 +11,7 @@ local CustomMatchSummary = {}
local Lua = require('Module:Lua')

local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')
local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')

local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/freefire/game_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local Lua = require('Module:Lua')

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

local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')

---@class FreefireMatchGroupUtilGame: MatchGroupUtilGame
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 All @@ -11,7 +11,7 @@ local CustomMatchSummary = {}
local Lua = require('Module:Lua')

local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')
local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')

local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')
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
2 changes: 1 addition & 1 deletion components/match2/wikis/naraka/game_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local Lua = require('Module:Lua')

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

local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')

---@class NarakaMatchGroupUtilGame: MatchGroupUtilGame
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 All @@ -11,7 +11,7 @@ local CustomMatchSummary = {}
local Lua = require('Module:Lua')

local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')
local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')

local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/pubg/game_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local Lua = require('Module:Lua')

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

local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')

---@class PubgMatchGroupUtilGame: MatchGroupUtilGame
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 All @@ -11,7 +11,7 @@ local CustomMatchSummary = {}
local Lua = require('Module:Lua')

local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')
local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')

local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/pubgmobile/game_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local Lua = require('Module:Lua')

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

local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')

---@class PubgmMatchGroupUtilGame: MatchGroupUtilGame
Expand Down
Loading

0 comments on commit 8745b73

Please sign in to comment.