Skip to content

Commit

Permalink
feat(match2): support FFA on AoE
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz committed Jan 3, 2025
1 parent 55ee2f6 commit d873a65
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
54 changes: 52 additions & 2 deletions components/match2/wikis/ageofempires/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
41 changes: 41 additions & 0 deletions components/match2/wikis/ageofempires/match_summary_ffa.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d873a65

Please sign in to comment.