From d873a65b7f522b772cd204859748ef99c74532c6 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Fri, 3 Jan 2025 14:06:28 +0100 Subject: [PATCH] feat(match2): support FFA on AoE --- .../ageofempires/match_group_input_custom.lua | 54 ++++++++++++++++++- .../wikis/ageofempires/match_summary_ffa.lua | 41 ++++++++++++++ 2 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 components/match2/wikis/ageofempires/match_summary_ffa.lua diff --git a/components/match2/wikis/ageofempires/match_group_input_custom.lua b/components/match2/wikis/ageofempires/match_group_input_custom.lua index 850c09f0b3..494e8d3936 100644 --- a/components/match2/wikis/ageofempires/match_group_input_custom.lua +++ b/components/match2/wikis/ageofempires/match_group_input_custom.lua @@ -34,17 +34,23 @@ local MapFunctions = { BREAK_ON_EMPTY = true, } +local FffMatchFunctions = { + OPPONENT_CONFIG = OPPONENT_CONFIG, +} +local FfaMapFunctions = {} + ---@param match table ---@param options table? ---@return table function CustomMatchGroupInput.processMatch(match, options) - assert(not Logic.readBool(match.ffa), 'FFA is not yet supported in AoE match2.') Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match)) match.game, match.mapsInfo = MatchFunctions.getGameAndMapsFromTournament(match) - return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) + return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions, FffMatchFunctions) end +--- Normal 2-opponent Match + ---@param match table ---@param opponentIndex integer ---@param options readOpponentOptions @@ -292,4 +298,48 @@ function MapFunctions.getGame(match, map) return Logic.emptyOr(map.game, match.game, Variables.varDefault('tournament_game')) end +--- FFA Match + +---@param match table +---@param opponents table[] +---@param scoreSettings table +---@return table[] +function FffMatchFunctions.extractMaps(match, opponents, scoreSettings) + return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, FfaMapFunctions) +end + +---@param opponents table[] +---@param maps table[] +---@return fun(opponentIndex: integer): integer? +function FffMatchFunctions.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 FffMatchFunctions.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/ageofempires/match_summary_ffa.lua b/components/match2/wikis/ageofempires/match_summary_ffa.lua new file mode 100644 index 0000000000..c28bc90d7b --- /dev/null +++ b/components/match2/wikis/ageofempires/match_summary_ffa.lua @@ -0,0 +1,41 @@ +--- +-- @Liquipedia +-- wiki=ageofempires +-- 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') + +---@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 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