From 46259858216db3fdaf4360a854dd50617c1b2ec8 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Thu, 12 Dec 2024 15:18:54 +0100 Subject: [PATCH 1/2] feat(match2): support arenafps FFA --- .../match2/wikis/arenafps/game_summary.lua | 46 +++++++++++++ .../get_match_group_copy_paste_wiki.lua | 59 +++++++++++++++++ .../arenafps/match_group_input_custom.lua | 65 ++++++++++++++++--- .../wikis/arenafps/match_summary_ffa.lua | 44 +++++++++++++ 4 files changed, 204 insertions(+), 10 deletions(-) create mode 100644 components/match2/wikis/arenafps/game_summary.lua create mode 100644 components/match2/wikis/arenafps/match_summary_ffa.lua diff --git a/components/match2/wikis/arenafps/game_summary.lua b/components/match2/wikis/arenafps/game_summary.lua new file mode 100644 index 00000000000..2fe9992b113 --- /dev/null +++ b/components/match2/wikis/arenafps/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 ArenaFpsFfaMatchGroupUtilGame: MatchGroupUtilGame +---@field stream table + +---@param props {bracketId: string, matchId: string, gameIdx: integer} +---@return Html +function CustomGameSummary.getGameByMatchId(props) + ---@class ArenaFpsFfaMatchGroupUtilMatch + 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/arenafps/get_match_group_copy_paste_wiki.lua b/components/match2/wikis/arenafps/get_match_group_copy_paste_wiki.lua index 779978586c9..221c5d8e88e 100644 --- a/components/match2/wikis/arenafps/get_match_group_copy_paste_wiki.lua +++ b/components/match2/wikis/arenafps/get_match_group_copy_paste_wiki.lua @@ -13,6 +13,9 @@ local Logic = require('Module:Logic') local BaseCopyPaste = Lua.import('Module:GetMatchGroupCopyPaste/wiki/Base') +local OpponentLibraries = require('Module:OpponentLibraries') +local Opponent = OpponentLibraries.Opponent + ---@class ArenaFPSMatchCopyPaste: 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.readBoolOrNil(args.score), bestof == 0) local lines = Array.extend( @@ -45,4 +62,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=5|p2=4|p3=3|p4=2|p5=1', + 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 + +---@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/arenafps/match_group_input_custom.lua b/components/match2/wikis/arenafps/match_group_input_custom.lua index b8d2cde0b54..107c8ff6687 100644 --- a/components/match2/wikis/arenafps/match_group_input_custom.lua +++ b/components/match2/wikis/arenafps/match_group_input_custom.lua @@ -8,6 +8,7 @@ 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') @@ -15,21 +16,25 @@ local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') local DEFAULT_BESTOF = 3 local CustomMatchGroupInput = {} -local MatchFunctions = {} +local MatchFunctions = { + DEFAULT_MODE = 'Duel' +} local MapFunctions = {} -MatchFunctions.DEFAULT_MODE = 'Duel' +local FfaMatchFunctions = { + DEFAULT_MODE = 'Duel' +} +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 table[] @@ -67,10 +72,6 @@ function MatchFunctions.calculateMatchScore(maps) end end --- --- map related functions --- - ---@param match table ---@param map table ---@param opponents table[] @@ -81,4 +82,48 @@ function MapFunctions.getExtraData(match, map, opponents) } 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/arenafps/match_summary_ffa.lua b/components/match2/wikis/arenafps/match_summary_ffa.lua new file mode 100644 index 00000000000..b104ebe6680 --- /dev/null +++ b/components/match2/wikis/arenafps/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 ArenaFpsFfaMatchGroupUtilMatch: MatchGroupUtilMatch +---@field games ArenaFpsFfaMatchGroupUtilGame[] + +---@param props {bracketId: string, matchId: string} +---@return Widget +function CustomMatchSummary.getByMatchId(props) + ---@class ArenaFpsFfaMatchGroupUtilMatch + 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 From 90a54cc78aedd41141a6d40d6ae074b4dadfbe8e Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Thu, 12 Dec 2024 15:24:02 +0100 Subject: [PATCH 2/2] deploy header --- components/match2/wikis/arenafps/game_summary.lua | 2 +- components/match2/wikis/arenafps/match_summary_ffa.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/match2/wikis/arenafps/game_summary.lua b/components/match2/wikis/arenafps/game_summary.lua index 2fe9992b113..96831967ada 100644 --- a/components/match2/wikis/arenafps/game_summary.lua +++ b/components/match2/wikis/arenafps/game_summary.lua @@ -1,6 +1,6 @@ --- -- @Liquipedia --- wiki=tft +-- wiki=arenafps -- page=Module:GameSummary -- -- Please see https://github.com/Liquipedia/Lua-Modules to contribute diff --git a/components/match2/wikis/arenafps/match_summary_ffa.lua b/components/match2/wikis/arenafps/match_summary_ffa.lua index b104ebe6680..773b9d3d410 100644 --- a/components/match2/wikis/arenafps/match_summary_ffa.lua +++ b/components/match2/wikis/arenafps/match_summary_ffa.lua @@ -1,6 +1,6 @@ --- -- @Liquipedia --- wiki=tft +-- wiki=arenafps -- page=Module:MatchSummary/Ffa -- -- Please see https://github.com/Liquipedia/Lua-Modules to contribute