From 4ce8577095fc61bf850f1e75fea5b4763e5f660b Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Thu, 12 Dec 2024 17:24:17 +0100 Subject: [PATCH] feat(match2): support TFT FFA (#5196) * feat(match2): support TFT FFA * updaet paths --- .../get_match_group_copy_paste_wiki.lua | 2 +- components/match2/wikis/tft/game_summary.lua | 46 +++++++++++++++ .../tft/get_match_group_copy_paste_wiki.lua | 59 +++++++++++++++++++ .../wikis/tft/match_group_input_custom.lua | 58 +++++++++++++++++- .../match2/wikis/tft/match_summary_ffa.lua | 44 ++++++++++++++ .../get_match_group_copy_paste_wiki.lua | 2 +- 6 files changed, 206 insertions(+), 5 deletions(-) create mode 100644 components/match2/wikis/tft/game_summary.lua create mode 100644 components/match2/wikis/tft/match_summary_ffa.lua diff --git a/components/match2/wikis/autochess/get_match_group_copy_paste_wiki.lua b/components/match2/wikis/autochess/get_match_group_copy_paste_wiki.lua index 8e3074426ea..f914cfe523d 100644 --- a/components/match2/wikis/autochess/get_match_group_copy_paste_wiki.lua +++ b/components/match2/wikis/autochess/get_match_group_copy_paste_wiki.lua @@ -34,7 +34,7 @@ function WikiCopyPaste.getMatchCode(bestof, mode, index, opponents, args) INDENT .. '|p1=9 |p2=7 |p3=6 |p4=5 |p5=3 |p6=2 |p7=1 |p8=0', {INDENT .. '|twitch=|youtube='}, Array.map(Array.range(1, bestof), function(mapIndex) - return INDENT .. '|map' .. mapIndex .. '={{Map|date=|finished=|map=|vod=}}' + return INDENT .. '|map' .. mapIndex .. '={{Map|date=|finished=|vod=}}' end), Array.map(Array.range(1, opponents), function(opponentIndex) return INDENT .. '|opponent' .. opponentIndex .. '=' .. WikiCopyPaste._getOpponent(mode, bestof) diff --git a/components/match2/wikis/tft/game_summary.lua b/components/match2/wikis/tft/game_summary.lua new file mode 100644 index 00000000000..65a5af46f7d --- /dev/null +++ b/components/match2/wikis/tft/game_summary.lua @@ -0,0 +1,46 @@ +--- +-- @Liquipedia +-- wiki=tft +-- page=Module:GameSummary +-- +-- Please see https://github.com/Liquipedia/Lua-Modules to contribute +-- + +local CustomGameSummary = {} + +local Lua = require('Module:Lua') + +local MatchGroupUtil = Lua.import('Module:MatchGroup/Util') + +local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa') +local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All') + +---@class TftMatchGroupUtilGame: MatchGroupUtilGame +---@field stream table + +---@param props {bracketId: string, matchId: string, gameIdx: integer} +---@return Html +function CustomGameSummary.getGameByMatchId(props) + ---@class ApexMatchGroupUtilMatch + local match = MatchGroupUtil.fetchMatchForBracketDisplay(props.bracketId, props.matchId) + + local game = match.games[props.gameIdx] + assert(game, 'Error Game ID ' .. tostring(props.gameIdx) .. ' not found') + + game.stream = match.stream + + SummaryHelper.updateGameOpponents(game, match.opponents) + local scoringData = SummaryHelper.createScoringData(match) + + return MatchSummaryWidgets.Tab{ + matchId = match.matchId, + idx = props.gameIdx, + children = { + MatchSummaryWidgets.GameDetails{game = game}, + MatchSummaryWidgets.PointsDistribution{scores = scoringData}, + SummaryHelper.standardGame(game) + } + } +end + +return CustomGameSummary diff --git a/components/match2/wikis/tft/get_match_group_copy_paste_wiki.lua b/components/match2/wikis/tft/get_match_group_copy_paste_wiki.lua index 5329807af16..dd34ec8bad9 100644 --- a/components/match2/wikis/tft/get_match_group_copy_paste_wiki.lua +++ b/components/match2/wikis/tft/get_match_group_copy_paste_wiki.lua @@ -13,6 +13,9 @@ local Lua = require('Module:Lua') local BaseCopyPaste = Lua.import('Module:GetMatchGroupCopyPaste/wiki/Base') +local OpponentLibraries = require('Module:OpponentLibraries') +local Opponent = OpponentLibraries.Opponent + ---@class TftMatch2CopyPaste: Match2CopyPasteBase local WikiCopyPaste = Class.new(BaseCopyPaste) @@ -26,6 +29,20 @@ local INDENT = WikiCopyPaste.Indent ---@param args table ---@return string function WikiCopyPaste.getMatchCode(bestof, mode, index, opponents, args) + 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) @@ -48,4 +65,46 @@ 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 .. '|p1=8|p2=7|p3=6|p4=5|p5=4|p6=3|p7=2|p8=1', + INDENT .. '|twitch=|youtube=', + Array.map(Array.range(1, bestof), function(mapIndex) + return INDENT .. '|map' .. mapIndex .. '={{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 + +---@param mode string +---@param mapCount integer +---@return string +function WikiCopyPaste._getFfaOpponent(mode, mapCount) + local mapScores = table.concat(Array.map(Array.range(1, mapCount), function(idx) + return '|m' .. idx .. '={{MS||}}' + end)) + + if mode == Opponent.solo then + return '{{SoloOpponent||flag=' .. mapScores .. '}}' + elseif mode == Opponent.team then + return '{{TeamOpponent|' .. mapScores .. '}}' + elseif mode == Opponent.literal then + return '{{Literal|}}' + end + + return '' +end + return WikiCopyPaste diff --git a/components/match2/wikis/tft/match_group_input_custom.lua b/components/match2/wikis/tft/match_group_input_custom.lua index 0a57d1b2e7d..415cb76d9a2 100644 --- a/components/match2/wikis/tft/match_group_input_custom.lua +++ b/components/match2/wikis/tft/match_group_input_custom.lua @@ -8,24 +8,32 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') +local Operator = require('Module:Operator') local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') local CustomMatchGroupInput = {} -local MatchFunctions = {} +local MatchFunctions = { + DEFAULT_MODE = 'team', +} +local FfaMatchFunctions = { + DEFAULT_MODE = 'solos', +} local MapFunctions = {} +local FfaMapFunctions = {} local DEFAULT_BESTOF = 3 -MatchFunctions.DEFAULT_MODE = 'team' ---@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 +--- Normal 2-opponent Match + ---@param match table ---@param opponents table[] ---@return table[] @@ -91,5 +99,49 @@ function MapFunctions.calculateMapScore(map) end end +--- FFA Match + +---@param match table +---@param opponents table[] +---@param scoreSettings table +---@return table[] +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 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 + +---@param match table +---@param games table[] +---@param opponents table[] +---@param settings table +---@return table +function FfaMatchFunctions.getExtraData(match, games, opponents, settings) + return { + placementinfo = settings.placementInfo, + settings = settings.settings, + } +end + +---@param match table +---@param map table +---@param opponents table[] +---@return table +function FfaMapFunctions.getExtraData(match, map, opponents) + return { + dateexact = map.dateexact, + comment = map.comment, + } +end + return CustomMatchGroupInput diff --git a/components/match2/wikis/tft/match_summary_ffa.lua b/components/match2/wikis/tft/match_summary_ffa.lua new file mode 100644 index 00000000000..580f915ec23 --- /dev/null +++ b/components/match2/wikis/tft/match_summary_ffa.lua @@ -0,0 +1,44 @@ +--- +-- @Liquipedia +-- wiki=tft +-- 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') +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') + +---@class TftMatchGroupUtilMatch: MatchGroupUtilMatch +---@field games TftMatchGroupUtilGame[] + +---@param props {bracketId: string, matchId: string} +---@return Widget +function CustomMatchSummary.getByMatchId(props) + ---@class TftMatchGroupUtilMatch + local match = MatchGroupUtil.fetchMatchForBracketDisplay(props.bracketId, props.matchId) + SummaryHelper.updateMatchOpponents(match) + local scoringData = SummaryHelper.createScoringData(match) + + return HtmlWidgets.Fragment{children = { + MatchSummaryWidgets.Header{matchId = match.matchId, games = match.games}, + MatchSummaryWidgets.Tab{ + matchId = match.matchId, + idx = 0, + children = { + MatchSummaryWidgets.GamesSchedule{games = match.games}, + MatchSummaryWidgets.PointsDistribution{scores = scoringData}, + SummaryHelper.standardMatch(match), + } + } + }} +end + +return CustomMatchSummary diff --git a/components/match2/wikis/underlords/get_match_group_copy_paste_wiki.lua b/components/match2/wikis/underlords/get_match_group_copy_paste_wiki.lua index 2492b6b2dfb..8519ebb70d3 100644 --- a/components/match2/wikis/underlords/get_match_group_copy_paste_wiki.lua +++ b/components/match2/wikis/underlords/get_match_group_copy_paste_wiki.lua @@ -34,7 +34,7 @@ function WikiCopyPaste.getMatchCode(bestof, mode, index, opponents, args) INDENT .. '|p1=14 |p2=12 |p3=10 |p4=8 |p5=6 |p6=4 |p7=2 |p8=0', {INDENT .. '|twitch=|youtube='}, Array.map(Array.range(1, bestof), function(mapIndex) - return INDENT .. '|map' .. mapIndex .. '={{Map|date=|finished=|map=|vod=}}' + return INDENT .. '|map' .. mapIndex .. '={{Map|date=|finished=|vod=}}' end), Array.map(Array.range(1, opponents), function(opponentIndex) return INDENT .. '|opponent' .. opponentIndex .. '=' .. WikiCopyPaste._getOpponent(mode, bestof)