Skip to content

Commit

Permalink
aoe use standardProcessMaps
Browse files Browse the repository at this point in the history
  • Loading branch information
hjpalpha committed Dec 16, 2024
1 parent a49349d commit f1c0cd9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 46 deletions.
8 changes: 7 additions & 1 deletion components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,7 @@ end
---@field extendMapOpponent? fun(map: table, opponentIndex: integer): table
---@field getMapBestOf? fun(map: table): integer?
---@field computeOpponentScore? fun(props: table, autoScore?: fun(opponentIndex: integer):integer?): integer?, string?
---@field getGame? fun(match: table, map:table): string?
---@field ADD_SUB_GROUP? boolean
---@field BREAK_ON_EMPTY? boolean

Expand All @@ -1183,6 +1184,7 @@ end
--- - extendMapOpponent(map, opponentIndex): table
--- - getMapBestOf(map): integer?
--- - computeOpponentScore(props, autoScore): integer?, string?
--- - getGame(match, map): string?
---
--- Additionally, the Parser may have the following properties:
--- - ADD_SUB_GROUP boolean?
Expand Down Expand Up @@ -1224,6 +1226,10 @@ function MatchGroupInputUtil.standardProcessMaps(match, opponents, Parser)
map.patch = Parser.getPatch(map)
end

if Parser.getGame then
map.game = Parser.getGame(match, map)
end

map.opponents = Array.map(opponents, function(opponent, opponentIndex)
local computeOpponentScore = Parser.computeOpponentScore or MatchGroupInputUtil.computeOpponentScore
local score, status = computeOpponentScore({
Expand Down Expand Up @@ -1269,7 +1275,7 @@ end
---@class FfaMatchParserInterface
---@field extractMaps fun(match: table, opponents: table[], mapProps: any?): table[]
---@field parseSettings? fun(match: table, opponentCount: integer): table
---@field calculateMatchScore? fun(maps: table[], opponents table[]): fun(opponentIndex: integer): integer?
---@field calculateMatchScore? fun(maps: table[], opponents: table[]): fun(opponentIndex: integer): integer?
---@field getExtraData? fun(match: table, games: table[], opponents: table[], settings: table): table?
---@field getMode? fun(opponents: table[]): string
---@field readDate? fun(match: table): table
Expand Down
66 changes: 21 additions & 45 deletions components/match2/wikis/ageofempires/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ local Opponent = Lua.import('Module:Opponent')
local Streams = Lua.import('Module:Links/Stream')

local CustomMatchGroupInput = {}
local MapFunctions = {}
local MapFunctions = {
BREAK_ON_EMPTY = true,
}

local OPPONENT_CONFIG = {
resolveRedirect = true,
Expand Down Expand Up @@ -148,43 +150,7 @@ end
---@param opponents table[]
---@return table[]
function CustomMatchGroupInput.extractMaps(match, opponents)
local maps = {}
for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
if map.map == nil and map.winner == nil then
break
end
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

map.extradata = MapFunctions.getExtraData(match, map, opponents)
map.map, map.extradata.displayname = CustomMatchGroupInput._getMapName(map, match.mapsInfo)
map.extradata.mapmode = Table.extract(map, 'mode')

Table.mergeInto(map, MatchGroupInputUtil.getTournamentContext(map, match))

map.finished = MatchGroupInputUtil.mapIsFinished(map)
map.opponents = Array.map(opponents, function(opponent, opponentIndex)
local score, status = MatchGroupInputUtil.computeOpponentScore({
walkover = map.walkover,
winner = map.winner,
opponentIndex = opponentIndex,
score = map['score' .. opponentIndex],
}, CustomMatchGroupInput.calculateMapScore(map.winner, map.finished))
local players = CustomMatchGroupInput.getPlayersOfMapOpponent(map, opponent, opponentIndex)
return {score = score, status = status, players = players}
end)

map.scores = Array.map(map.opponents, Operator.property('score'))
if map.finished then
map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput)
map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents)
end

table.insert(maps, map)
match[key] = nil
end

return maps
return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions)
end

---@param bestofInput string|integer?
Expand Down Expand Up @@ -268,10 +234,13 @@ function CustomMatchGroupInput.getHeadToHeadLink(match, opponents)
end

---@param map table
---@param mapsInfo {name: string, link: string}[]?
---@param mapIndex integer
---@param match table
---@return string?
---@return string?
function CustomMatchGroupInput._getMapName(map, mapsInfo)
function MapFunctions.getMapName(map, mapIndex, match)
---@type {name: string, link: string}[]?
local mapsInfo = match.mapsInfo
if String.isEmpty(map.map) or map.map == 'TBD' then
return
end
Expand Down Expand Up @@ -325,14 +294,13 @@ function CustomMatchGroupInput.getPlayersOfMapOpponent(map, opponent, opponentIn

end

---@param winnerInput string|integer|nil
---@param finished boolean
---@param map table
---@return fun(opponentIndex: integer): integer?
function CustomMatchGroupInput.calculateMapScore(winnerInput, finished)
local winner = tonumber(winnerInput)
function MapFunctions.calculateMapScore(map)
local winner = tonumber(map.winner)
return function(opponentIndex)
-- TODO Better to check if map has started, rather than finished, for a more correct handling
if not winner and not finished then
if not winner and not map.finished then
return
end
return winner == opponentIndex and 1 or 0
Expand All @@ -346,7 +314,15 @@ end
function MapFunctions.getExtraData(match, map, opponents)
return {
comment = map.comment,
mapmode = Table.extract(map, 'mode'),
}
end

---@param match table
---@param map table
---@return string?
function MapFunctions.getGame(match, map)
return Logic.emptyOr(map.game, match.game, Variables.varGet('tournament_game'))
end

return CustomMatchGroupInput

0 comments on commit f1c0cd9

Please sign in to comment.