diff --git a/lua/wikis/tarkovarena/GetMatchGroupCopyPaste/wiki.lua b/lua/wikis/tarkovarena/GetMatchGroupCopyPaste/wiki.lua index 52fb1ab9fef..102dc4ac83f 100644 --- a/lua/wikis/tarkovarena/GetMatchGroupCopyPaste/wiki.lua +++ b/lua/wikis/tarkovarena/GetMatchGroupCopyPaste/wiki.lua @@ -26,12 +26,27 @@ local INDENT = WikiCopyPaste.Indent ---@param args table ---@return string function WikiCopyPaste.getMatchCode(bestof, mode, index, opponents, args) - local showScore = bestof == 0 + if opponents > 2 then + return WikiCopyPaste.getFfaMatchCode(bestof, mode, index, opponents, args) + else + return WikiCopyPaste.getStandardMatchCode(bestof, mode, index, opponents, args) + end +end + +---@param bestof integer +---@param mode string +---@param index integer +---@param opponents integer +---@param args table +---@return string +function WikiCopyPaste.getStandardMatchCode(bestof, mode, index, opponents, args) + local showScore = Logic.nilOr(Logic.readBool(args.score), bestof == 0) local opponent = WikiCopyPaste.getOpponent(mode, showScore) local lines = Array.extendWith({}, '{{Match', - showScore and (INDENT .. '|finished=') or nil, + index == 1 and (INDENT .. '|bestof=' .. (bestof ~= 0 and bestof or '')) or nil, + Logic.readBool(args.needsWinner) and (INDENT .. '|winner=') or nil, INDENT .. '|date=', Logic.readBool(args.streams) and (INDENT .. '|twitch=|youtube=|vod=') or nil, Array.map(Array.range(1, opponents), function(opponentIndex) @@ -46,4 +61,27 @@ function WikiCopyPaste.getMatchCode(bestof, mode, index, opponents, args) return table.concat(lines, '\n') end +---@param bestof integer +---@param mode string +---@param index integer +---@param opponents integer +---@param args table +---@return string +function WikiCopyPaste.getFfaMatchCode(bestof, mode, index, opponents, args) + local lines = Array.extend( + '{{Match|finished=', + INDENT .. '|p_kill=1 |p1=12 |p2=9 |p3=7 |p4=5 |p5=4 |p6=3 |p7=3 |p8=2 |p9=2 |p10=2 ' .. + INDENT .. '|twitch=|youtube=', + Array.map(Array.range(1, bestof), function(mapIndex) + return INDENT .. '|map' .. mapIndex .. '={{Map|map=|date=|finished=|vod=}}' + end), + Array.map(Array.range(1, opponents), function(opponentIndex) + return INDENT .. '|opponent' .. opponentIndex .. '=' .. WikiCopyPaste.getFfaOpponent(mode, bestof) + end), + '}}' + ) + + return table.concat(lines, '\n') +end + return WikiCopyPaste diff --git a/lua/wikis/tarkovarena/MatchGroup/Input/Custom.lua b/lua/wikis/tarkovarena/MatchGroup/Input/Custom.lua index e5b32f7bf80..87b8b52eff4 100644 --- a/lua/wikis/tarkovarena/MatchGroup/Input/Custom.lua +++ b/lua/wikis/tarkovarena/MatchGroup/Input/Custom.lua @@ -7,27 +7,39 @@ local Lua = require('Module:Lua') +local Array = Lua.import('Module:Array') local FnUtil = Lua.import('Module:FnUtil') +local Operator = Lua.import('Module:Operator') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') local CustomMatchGroupInput = {} + +---@class TarkovArenaMatchParser: MatchParserInterface local MatchFunctions = { DEFAULT_MODE = 'team', getBestOf = MatchGroupInputUtil.getBestOf, } + +---@class TarkovArenaMapParser: MapParserInterface local MapFunctions = {} +---@class TarkovArenaFfaMatchParser: FfaMatchParserInterface +local FfaMatchFunctions = { + DEFAULT_MODE = 'team', +} + +---@class TarkovArenaFfaMapParser: FfaMapParserInterface +local FfaMapFunctions = {} + ---@param match table ---@param options table? ---@return table function CustomMatchGroupInput.processMatch(match, options) - return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) + return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions, FfaMatchFunctions) end --- --- match related functions --- +-- "Normal" match ---@param match table ---@param opponents MGIParsedOpponent[] ---@return table[] @@ -41,4 +53,25 @@ function MatchFunctions.calculateMatchScore(maps) return FnUtil.curry(MatchGroupInputUtil.computeMatchScoreFromMapWinners, maps) end +--- FFA Match + +---@param match table +---@param opponents MGIParsedOpponent[] +---@param scoreSettings table +---@return table[] +function FfaMatchFunctions.extractMaps(match, opponents, scoreSettings) + return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, FfaMapFunctions) +end + +---@param opponents MGIParsedOpponent[] +---@param maps table[] +---@return fun(opponentIndex: integer): integer? +function FfaMatchFunctions.calculateMatchScore(opponents, maps) + return function(opponentIndex) + return Array.reduce(Array.map(maps, function(map) + return map.opponents[opponentIndex].score or 0 + end), Operator.add, 0) + (opponents[opponentIndex].extradata.startingpoints or 0) + end +end + return CustomMatchGroupInput diff --git a/lua/wikis/tarkovarena/MatchSummary.lua b/lua/wikis/tarkovarena/MatchSummary.lua index c80ab7f4487..60911d3df58 100644 --- a/lua/wikis/tarkovarena/MatchSummary.lua +++ b/lua/wikis/tarkovarena/MatchSummary.lua @@ -25,10 +25,6 @@ end ---@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}, diff --git a/lua/wikis/tarkovarena/MatchSummary/Ffa.lua b/lua/wikis/tarkovarena/MatchSummary/Ffa.lua new file mode 100644 index 00000000000..7d5f0dfc0cf --- /dev/null +++ b/lua/wikis/tarkovarena/MatchSummary/Ffa.lua @@ -0,0 +1,42 @@ +--- +-- @Liquipedia +-- page=Module:MatchSummary/Ffa +-- +-- Please see https://github.com/Liquipedia/Lua-Modules to contribute +-- + +local CustomMatchSummary = {} + +local Lua = require('Module:Lua') + +local MatchGroupUtil = Lua.import('Module:MatchGroup/Util/Custom') +local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa') + +local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All') +local Html = Lua.import('Module:Widget/Html') +local WidgetUtil = Lua.import('Module:Widget/Util') + +---@param props {bracketId: string, matchId: string} +---@return Widget +function CustomMatchSummary.getByMatchId(props) + ---@class FFAMatchGroupUtilMatch + local match = MatchGroupUtil.fetchMatchForBracketDisplay(props.bracketId, props.matchId) + SummaryHelper.updateMatchOpponents(match) + local scoringData = SummaryHelper.createScoringData(match) + + return Html.Fragment{children = { + MatchSummaryWidgets.Header{matchId = match.matchId, games = match.games}, + MatchSummaryWidgets.Tab{ + matchId = match.matchId, + idx = 0, + children = WidgetUtil.collect( + MatchSummaryWidgets.GamesSchedule{match = match}, + MatchSummaryWidgets.PointsDistribution{scores = scoringData}, + MatchSummaryWidgets.MatchInformation(match), + SummaryHelper.standardMatch(match) + ) + } + }} +end + +return CustomMatchSummary