diff --git a/components/match2/commons/match_group_input_util.lua b/components/match2/commons/match_group_input_util.lua index 3c42f128059..37970ebfaba 100644 --- a/components/match2/commons/match_group_input_util.lua +++ b/components/match2/commons/match_group_input_util.lua @@ -1099,10 +1099,10 @@ end ---@class MatchParserInterface ---@field extractMaps fun(match: table, opponents: table[], mapProps: any?): table[] ----@field getBestOf fun(bestOfInput: string|integer, maps: table[]): integer ----@field calculateMatchScore? fun(maps: table[], opponents: table[]): fun(opponentIndex: integer): integer +---@field getBestOf fun(bestOfInput: string|integer|nil, maps: table[]): integer? +---@field calculateMatchScore? fun(maps: table[], opponents: table[]): fun(opponentIndex: integer): integer? ---@field removeUnsetMaps? fun(maps: table[]): table[] ----@field getExtraData? fun(match: table, games: table[], opponents: table[]): table +---@field getExtraData? fun(match: table, games: table[], opponents: table[]): table? ---@field adjustOpponent? fun(opponent: MGIParsedOpponent, opponentIndex: integer) ---@field getLinks? fun(match: table, games: table[]): table ---@field getHeadToHeadLink? fun(match: table, opponents: table[]): string? @@ -1122,17 +1122,17 @@ end --- --- The Parser injection must have the following functions: --- - extractMaps(match, opponents, mapProps): table[] ---- - getBestOf(bestOfInput, maps): integer +--- - getBestOf(bestOfInput, maps): integer? --- --- It may optionally have the following functions: ---- - calculateMatchScore(maps, opponents): fun(opponentIndex): integer +--- - calculateMatchScore(maps, opponents): fun(opponentIndex): integer? --- - removeUnsetMaps(maps): table[] ---- - getExtraData(match, games, opponents): table +--- - getExtraData(match, games, opponents): table? --- - adjustOpponent(opponent, opponentIndex) ---- - getLinks(match, games) ---- - getHeadToHeadLink(match, opponents) ---- - readDate(match) ---- - getMode(opponents) +--- - getLinks(match, games): table? +--- - getHeadToHeadLink(match, opponents): string? +--- - readDate(match): table +--- - getMode(opponents): string? --- --- Additionally, the Parser may have the following properties: --- - DEFAULT_MODE: string @@ -1202,4 +1202,49 @@ function MatchGroupInputUtil.standardProcessMatch(match, Parser, mapProps) return match end +---@class MapParserInterface +---@field calculateMapScore? fun(map: table): fun(opponentIndex: integer): integer? +---@field getExtraData? fun(match: table, games: table, opponents: table[]): table? + +--- It may optionally have the following functions: +--- - calculateMatchScore(map): fun(opponentIndex): integer? +--- - getExtraData(match, map, opponents): table? +---@param match table +---@param opponents table[] +---@param Parser MapParserInterface +---@return table +function MatchGroupInputUtil.standardProcessMaps(match, opponents, Parser) + local maps = {} + for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do + local finishedInput = map.finished --[[@as string?]] + local winnerInput = map.winner --[[@as string?]] + + map.finished = MatchGroupInputUtil.mapIsFinished(map) + + local opponentInfo = Array.map(opponents, function(_, opponentIndex) + local score, status = MatchGroupInputUtil.computeOpponentScore({ + walkover = map.walkover, + winner = map.winner, + opponentIndex = opponentIndex, + score = map['score' .. opponentIndex], + }, Parser.calculateMapScore and Parser.calculateMapScore(map) or nil) + return {score = score, status = status} + end) + + map.scores = Array.map(opponentInfo, Operator.property('score')) + if map.finished then + map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) + map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) + map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) + end + + map.extradata = Parser.getExtraData and Parser.getExtraData(match, map, opponents) or nil + + table.insert(maps, map) + match[key] = nil + end + + return maps +end + return MatchGroupInputUtil diff --git a/components/match2/wikis/arenafps/match_group_input_custom.lua b/components/match2/wikis/arenafps/match_group_input_custom.lua index c8aab617474..b8d2cde0b54 100644 --- a/components/match2/wikis/arenafps/match_group_input_custom.lua +++ b/components/match2/wikis/arenafps/match_group_input_custom.lua @@ -8,8 +8,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -34,42 +32,18 @@ end -- ---@param match table ----@param opponents MGIParsedOpponent[] +---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) +end - return maps +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) end ---@param bestofInput string|integer? @@ -97,9 +71,11 @@ end -- map related functions -- +---@param match table ---@param map table +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map) +function MapFunctions.getExtraData(match, map, opponents) return { comment = map.comment, } diff --git a/components/match2/wikis/battlerite/match_group_input_custom.lua b/components/match2/wikis/battlerite/match_group_input_custom.lua index 82616e52b32..2e74bbf0bd7 100644 --- a/components/match2/wikis/battlerite/match_group_input_custom.lua +++ b/components/match2/wikis/battlerite/match_group_input_custom.lua @@ -8,8 +8,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -17,6 +15,7 @@ local CustomMatchGroupInput = {} local MatchFunctions = {} local MapFunctions = {} +MatchFunctions.getBestOf = MatchGroupInputUtil.getBestOf MatchFunctions.OPPONENT_CONFIG = { resolveRedirect = true, pagifyTeamNames = true, @@ -33,50 +32,20 @@ end -- -- match related functions -- -MatchFunctions.getBestOf = MatchGroupInputUtil.getBestOf - --- These maps however shouldn't be stored --- The keepMap function will check if a map should be kept ----@param games table[] ----@return table[] -function MatchFunctions.removeUnsetMaps(games) - return Array.filter(games, MapFunctions.keepMap) -end ---@param match table ----@param opponents MGIParsedOpponent[] +---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map, #opponents) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) +end - return maps +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) end ---@param maps table[] @@ -99,17 +68,11 @@ end -- map related functions -- --- Check if a map should be discarded due to being redundant ----@param map table ----@return boolean -function MapFunctions.keepMap(map) - return map.map ~= nil -end - +---@param match table ---@param map table ----@param opponentCount integer +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map, opponentCount) +function MapFunctions.getExtraData(match, map, opponents) return { comment = map.comment, } diff --git a/components/match2/wikis/callofduty/match_group_input_custom.lua b/components/match2/wikis/callofduty/match_group_input_custom.lua index fe35442b335..d5ad2f01e0f 100644 --- a/components/match2/wikis/callofduty/match_group_input_custom.lua +++ b/components/match2/wikis/callofduty/match_group_input_custom.lua @@ -9,8 +9,6 @@ local Array = require('Module:Array') local Logic = require('Module:Logic') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -30,48 +28,23 @@ function CustomMatchGroupInput.processMatch(match, options) return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) end +-- +-- match related functions +-- ---@param match table ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end --- --- match related functions --- +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) +end ---@param maps table[] ---@return fun(opponentIndex: integer): integer? @@ -101,10 +74,11 @@ end -- map related functions -- --- Parse extradata information +---@param match table ---@param map table +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map) +function MapFunctions.getExtraData(match, map, opponents) return { comment = map.comment, } diff --git a/components/match2/wikis/counterstrike/match_group_input_custom.lua b/components/match2/wikis/counterstrike/match_group_input_custom.lua index 04bf9da556a..582fa441ceb 100644 --- a/components/match2/wikis/counterstrike/match_group_input_custom.lua +++ b/components/match2/wikis/counterstrike/match_group_input_custom.lua @@ -47,7 +47,7 @@ function CustomMatchGroupInput.processMatch(match, options) local opponents = Array.mapIndexes(function(opponentIndex) return MatchGroupInputUtil.readOpponent(match, opponentIndex, OPPONENT_CONFIG) end) - local games = MatchFunctions.extractMaps(match, #opponents) + local games = MatchFunctions.extractMaps(match, opponents) match.bestof = MatchGroupInputUtil.getBestOf(nil, games) games = MatchFunctions.removeUnsetMaps(games) match.links = MatchFunctions.getLinks(match, games) @@ -93,45 +93,12 @@ end -- ---@param match table ----@param opponentCount integer +---@param opponents table[] ---@return table[] -function MatchFunctions.extractMaps(match, opponentCount) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(Array.range(1, opponentCount), function(opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }, MapFunctions.calculateMapScore(map)) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps +function MatchFunctions.extractMaps(match, opponents) + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end --- --- match related functions --- - ---@param maps table[] ---@return fun(opponentIndex: integer): integer? function MatchFunctions.calculateMatchScore(maps) @@ -140,13 +107,12 @@ function MatchFunctions.calculateMatchScore(maps) end end --- Template:Map sets a default map name so we can count the number of maps. --- These maps however shouldn't be stored --- The keepMap function will check if a map should be kept ---@param games table[] ---@return table[] function MatchFunctions.removeUnsetMaps(games) - return Array.filter(games, MapFunctions.keepMap) + return Array.filter(games, function(map) + return map.map ~= nil + end) end ---@param match table @@ -255,17 +221,11 @@ end -- map related functions -- --- Check if a map should be discarded due to being redundant ----@param map table ----@return boolean -function MapFunctions.keepMap(map) - return map.map ~= nil -end - --- Parse extradata information +---@param match table ---@param map table +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map) +function MapFunctions.getExtraData(match, map, opponents) local extradata = { comment = map.comment, } diff --git a/components/match2/wikis/criticalops/match_group_input_custom.lua b/components/match2/wikis/criticalops/match_group_input_custom.lua index 7c0c797a31a..ea85f3ebe21 100644 --- a/components/match2/wikis/criticalops/match_group_input_custom.lua +++ b/components/match2/wikis/criticalops/match_group_input_custom.lua @@ -37,48 +37,19 @@ end -- match related functions -- --- These maps however shouldn't be stored --- The keepMap function will check if a map should be kept ----@param games table[] ----@return table[] -function MatchFunctions.removeUnsetMaps(games) - return Array.filter(games, MapFunctions.keepMap) -end - ---@param match table ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }, MapFunctions.calculateMapScore(map)) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) +end - return maps +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) end ---@param maps table[] @@ -101,16 +72,11 @@ end -- map related functions -- --- Check if a map should be discarded due to being redundant ----@param map table ----@return boolean -function MapFunctions.keepMap(map) - return map.map ~= nil -end - +---@param match table ---@param map table +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map) +function MapFunctions.getExtraData(match, map, opponents) local extradata = MapFunctions.getSideData(map) return Table.merge(extradata, {comment = map.comment}) diff --git a/components/match2/wikis/crossfire/match_group_input_custom.lua b/components/match2/wikis/crossfire/match_group_input_custom.lua index 1cdc28d372b..6ce4d3f8bf3 100644 --- a/components/match2/wikis/crossfire/match_group_input_custom.lua +++ b/components/match2/wikis/crossfire/match_group_input_custom.lua @@ -8,8 +8,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -41,39 +39,15 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map, #opponents) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) +end - return maps +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) end ---@param bestofInput string|integer? @@ -110,10 +84,11 @@ end -- map related functions -- +---@param match table ---@param map table ----@param opponentCount integer +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map, opponentCount) +function MapFunctions.getExtraData(match, map, opponents) return { comment = map.comment, } diff --git a/components/match2/wikis/geoguessr/match_group_input_custom.lua b/components/match2/wikis/geoguessr/match_group_input_custom.lua index aae789a21a5..43d20f184e4 100644 --- a/components/match2/wikis/geoguessr/match_group_input_custom.lua +++ b/components/match2/wikis/geoguessr/match_group_input_custom.lua @@ -8,8 +8,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -25,49 +23,23 @@ MatchFunctions.getBestOf = MatchGroupInputUtil.getBestOf function CustomMatchGroupInput.processMatch(match, options) return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) end - +-- +-- match related functions +-- ---@param match table ----@param matchOpponents table[] +---@param opponents table[] ---@return table[] -function MatchFunctions.extractMaps(match, matchOpponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(matchOpponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps +function MatchFunctions.extractMaps(match, opponents) + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end --- --- match related functions --- +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) +end ---@param maps table[] ---@return fun(opponentIndex: integer): integer @@ -81,10 +53,11 @@ end -- map related functions -- --- Parse extradata information +---@param match table ---@param map table +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map) +function MapFunctions.getExtraData(match, map, opponents) return { comment = map.comment, } diff --git a/components/match2/wikis/halo/match_group_input_custom.lua b/components/match2/wikis/halo/match_group_input_custom.lua index fe6f97940f4..4bae286f095 100644 --- a/components/match2/wikis/halo/match_group_input_custom.lua +++ b/components/match2/wikis/halo/match_group_input_custom.lua @@ -8,7 +8,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') local Table = require('Module:Table') local Variables = require('Module:Variables') @@ -38,39 +37,15 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) +end - return maps +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) end ---@param bestofInput string|integer? @@ -141,9 +116,11 @@ end -- map related functions -- +---@param match table ---@param map table +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map) +function MapFunctions.getExtraData(match, map, opponents) return { comment = map.comment, points1 = map.points1, diff --git a/components/match2/wikis/heroes/match_group_input_custom.lua b/components/match2/wikis/heroes/match_group_input_custom.lua index e61a7ceb5dd..3fbe2335337 100644 --- a/components/match2/wikis/heroes/match_group_input_custom.lua +++ b/components/match2/wikis/heroes/match_group_input_custom.lua @@ -6,12 +6,10 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- -local Array = require('Module:Array') local ChampionNames = mw.loadData('Module:HeroNames') local FnUtil = require('Module:FnUtil') local Logic = require('Module:Logic') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') local Table = require('Module:Table') local Variables = require('Module:Variables') @@ -40,36 +38,7 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map, #opponents) - - map.finished = MatchGroupInputUtil.mapIsFinished(map) - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }, MapFunctions.calculateMapScore(map.winner, map.finished)) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end -- @@ -107,17 +76,18 @@ end -- -- Parse extradata information +---@param match table ---@param map table ----@param opponentCount integer +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map, opponentCount) +function MapFunctions.getExtraData(match, map, opponents) local extraData = { comment = map.comment, } local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, ChampionNames) - for opponentIndex = 1, opponentCount do + for opponentIndex = 1, #opponents do extraData['team' .. opponentIndex .. 'side'] = string.lower(map['team' .. opponentIndex .. 'side'] or '') for _, heroInput, heroIndex in Table.iter.pairsByPrefix(map, 't' .. opponentIndex .. 'h') do extraData['team' .. opponentIndex .. 'champion' .. heroIndex] = getCharacterName(heroInput) diff --git a/components/match2/wikis/mobilelegends/match_group_input_custom.lua b/components/match2/wikis/mobilelegends/match_group_input_custom.lua index 929e6cd07fb..89aa0963b2d 100644 --- a/components/match2/wikis/mobilelegends/match_group_input_custom.lua +++ b/components/match2/wikis/mobilelegends/match_group_input_custom.lua @@ -11,7 +11,6 @@ local FnUtil = require('Module:FnUtil') local Logic = require('Module:Logic') local Lua = require('Module:Lua') local Operator = require('Module:Operator') -local String = require('Module:StringUtils') local Table = require('Module:Table') local Variables = require('Module:Variables') local ChampionNames = mw.loadData('Module:HeroNames') @@ -41,11 +40,10 @@ end ---@return table[] function MatchFunctions.extractMaps(match, opponents) local maps = {} - for key, map, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do + for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do local finishedInput = map.finished --[[@as string?]] local winnerInput = map.winner --[[@as string?]] - map.vod = map.vod or String.nilIfEmpty(match['vodgame' .. mapIndex]) map.participants = MapFunctions.getParticipants(map, opponents) map.extradata = MapFunctions.getExtraData(map, #opponents) diff --git a/components/match2/wikis/pokemon/match_group_input_custom.lua b/components/match2/wikis/pokemon/match_group_input_custom.lua index 125639de11c..1bfa54986a1 100644 --- a/components/match2/wikis/pokemon/match_group_input_custom.lua +++ b/components/match2/wikis/pokemon/match_group_input_custom.lua @@ -6,12 +6,10 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- -local Array = require('Module:Array') local ChampionNames = mw.loadData('Module:HeroNames') local FnUtil = require('Module:FnUtil') local Logic = require('Module:Logic') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') local Table = require('Module:Table') local Variables = require('Module:Variables') @@ -46,42 +44,12 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map, #opponents) - - map.finished = MatchGroupInputUtil.mapIsFinished(map) - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }, MapFunctions.calculateMapScore(map.winner, map.finished)) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end -- -- match related functions -- - ---@param maps table[] ---@return fun(opponentIndex: integer): integer function MatchFunctions.calculateMatchScore(maps) @@ -110,10 +78,11 @@ end -- map related functions -- +---@param match table ---@param map table ----@param opponentCount integer +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map, opponentCount) +function MapFunctions.getExtraData(match, map, opponents) local extradata = { comment = map.comment, team1side = string.lower(map.team1side or ''), @@ -121,7 +90,7 @@ function MapFunctions.getExtraData(map, opponentCount) } local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, ChampionNames) - for opponentIndex = 1, opponentCount do + for opponentIndex = 1, #opponents do for _, ban, banIndex in Table.iter.pairsByPrefix(map, 't' .. opponentIndex .. 'b') do extradata['team' .. opponentIndex .. 'ban' .. banIndex] = getCharacterName(ban) end diff --git a/components/match2/wikis/rainbowsix/match_group_input_custom.lua b/components/match2/wikis/rainbowsix/match_group_input_custom.lua index 8c83a19bbea..18d0a4cf575 100644 --- a/components/match2/wikis/rainbowsix/match_group_input_custom.lua +++ b/components/match2/wikis/rainbowsix/match_group_input_custom.lua @@ -10,8 +10,6 @@ local Array = require('Module:Array') local CharacterNames = require('Module:CharacterNames') local FnUtil = require('Module:FnUtil') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -38,45 +36,15 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map, #opponents) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }, MapFunctions.calculateMapScore(map)) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end --- Template:Map sets a default map name so we can count the number of maps. --- These maps however shouldn't be stored --- The keepMap function will check if a map should be kept ---@param games table[] ---@return table[] function MatchFunctions.removeUnsetMaps(games) - return Array.filter(games, MapFunctions.keepMap) + return Array.filter(games, function(map) + return map.map ~= nil + end) end ---@param maps table[] @@ -101,18 +69,12 @@ end -- map related functions -- --- Check if a map should be discarded due to being redundant ----@param map table ----@return boolean -function MapFunctions.keepMap(map) - return map.map ~= nil -end - -- Parse extradata information, particularally info about halfs and operator bans +---@param match table ---@param map table ----@param opponentCount integer +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map, opponentCount) +function MapFunctions.getExtraData(match, map, opponents) local extradata = { comment = map.comment, t1firstside = {rt = map.t1firstside, ot = map.t1firstsideot}, @@ -121,7 +83,7 @@ function MapFunctions.getExtraData(map, opponentCount) } local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, CharacterNames) - Array.forEach(Array.range(1, opponentCount), function(opponentIndex) + Array.forEach(opponents, function(_, opponentIndex) extradata['t' .. opponentIndex .. 'bans'] = Array.map(Array.range(1, MAX_NUM_BANS), function(banIndex) local ban = map['t' .. opponentIndex .. 'ban' .. banIndex] return getCharacterName(ban) or '' diff --git a/components/match2/wikis/rocketleague/match_group_input_custom.lua b/components/match2/wikis/rocketleague/match_group_input_custom.lua index 6988ac9cd01..6297cb61770 100644 --- a/components/match2/wikis/rocketleague/match_group_input_custom.lua +++ b/components/match2/wikis/rocketleague/match_group_input_custom.lua @@ -48,7 +48,7 @@ end ---@return table[] function MatchFunctions.extractMaps(match, opponents) local maps = {} - for key, map, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do + for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do if map.map == nil then break end @@ -56,7 +56,6 @@ function MatchFunctions.extractMaps(match, opponents) local winnerInput = map.winner --[[@as string?]] map.extradata = MapFunctions.getExtraData(map) - map.vod = map.vod or String.nilIfEmpty(match['vodgame' .. mapIndex]) map.finished = MatchGroupInputUtil.mapIsFinished(map) local opponentInfo = Array.map(opponents, function(_, opponentIndex) diff --git a/components/match2/wikis/sideswipe/match_group_input_custom.lua b/components/match2/wikis/sideswipe/match_group_input_custom.lua index 8c60cfb6ed4..c3fe8d6444b 100644 --- a/components/match2/wikis/sideswipe/match_group_input_custom.lua +++ b/components/match2/wikis/sideswipe/match_group_input_custom.lua @@ -9,8 +9,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -32,45 +30,21 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end -- -- match related functions -- +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) +end + ---@param match table ---@param opponents table[] ---@return table @@ -90,9 +64,11 @@ end -- map related functions -- +---@param match table ---@param map table +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map) +function MapFunctions.getExtraData(match, map, opponents) return { ot = map.ot, otlength = map.otlength, diff --git a/components/match2/wikis/splitgate/match_group_input_custom.lua b/components/match2/wikis/splitgate/match_group_input_custom.lua index e76e3dd0bf6..1b83b00ab14 100644 --- a/components/match2/wikis/splitgate/match_group_input_custom.lua +++ b/components/match2/wikis/splitgate/match_group_input_custom.lua @@ -8,8 +8,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -36,39 +34,15 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map, #opponents) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) +end - return maps +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) end ---@param bestofInput string|integer? @@ -104,10 +78,11 @@ end -- map related functions -- +---@param match table ---@param map table ----@param opponentCount integer +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map, opponentCount) +function MapFunctions.getExtraData(match, map, opponents) return { comment = map.comment, } diff --git a/components/match2/wikis/teamfortress/match_group_input_custom.lua b/components/match2/wikis/teamfortress/match_group_input_custom.lua index c675108d562..7ac4ea533a2 100644 --- a/components/match2/wikis/teamfortress/match_group_input_custom.lua +++ b/components/match2/wikis/teamfortress/match_group_input_custom.lua @@ -8,8 +8,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -30,45 +28,21 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end -- -- match related functions -- +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) +end + ---@param maps table[] ---@return fun(opponentIndex: integer): integer function MatchFunctions.calculateMatchScore(maps) @@ -98,10 +72,11 @@ end -- map related functions -- --- Parse extradata information +---@param match table ---@param map table +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map) +function MapFunctions.getExtraData(match, map, opponents) return { comment = map.comment, } diff --git a/components/match2/wikis/tft/match_group_input_custom.lua b/components/match2/wikis/tft/match_group_input_custom.lua index a067fd4f082..65a488ab9d5 100644 --- a/components/match2/wikis/tft/match_group_input_custom.lua +++ b/components/match2/wikis/tft/match_group_input_custom.lua @@ -8,8 +8,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -28,6 +26,13 @@ function CustomMatchGroupInput.processMatch(match, options) return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) end +---@param match table +---@param opponents table[] +---@return table[] +function MatchFunctions.extractMaps(match, opponents) + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) +end + ---@param match table ---@return table function MatchFunctions.getExtraData(match) @@ -53,51 +58,21 @@ function MatchFunctions.getBestOf(bestofInput) return bestof end ----@param match table ----@param opponents table[] +---@param games table[] ---@return table[] -function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for mapKey, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }, MapFunctions.calculateMapScore(map.winner, map.finished)) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - map.extradata = MapFunctions.getExtradata(map) - - table.insert(maps, map) - match[mapKey] = nil - end - - return maps +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) end ----@param mapInput table +---@param match table +---@param map table +---@param opponents table[] ---@return table -function MapFunctions.getExtradata(mapInput) +function MapFunctions.getExtraData(match, map, opponents) return { - comment = mapInput.comment, + comment = map.comment, } end diff --git a/components/match2/wikis/trackmania/match_group_input_custom.lua b/components/match2/wikis/trackmania/match_group_input_custom.lua index 7a9849aeec2..6cca7f14579 100644 --- a/components/match2/wikis/trackmania/match_group_input_custom.lua +++ b/components/match2/wikis/trackmania/match_group_input_custom.lua @@ -10,8 +10,6 @@ local Array = require('Module:Array') local Logic = require('Module:Logic') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') local Opponent = Lua.import('Module:Opponent') @@ -35,39 +33,24 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) +end - return maps +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) +end + +---@param opponent MGIParsedOpponent +---@param opponentIndex integer +function MatchFunctions.adjustOpponent(opponent, opponentIndex) + opponent.extradata = CustomMatchGroupInput.getOpponentExtradata(opponent) + if opponent.extradata.additionalScores then + opponent.score = CustomMatchGroupInput._getSetWins(opponent) + end end ---@param opponent table @@ -105,10 +88,12 @@ function MatchFunctions.isFeatured(match) end ---@param match table +---@param games table[] +---@param opponents table[] ---@return table -function MatchFunctions.getExtraData(match) - local opponent1 = match.opponent1 or {} - local opponent2 = match.opponent2 or {} +function MatchFunctions.getExtraData(match, games, opponents) + local opponent1 = opponents[1] or {} + local opponent2 = opponents[2] or {} return { isfeatured = MatchFunctions.isFeatured(match), @@ -118,9 +103,11 @@ function MatchFunctions.getExtraData(match) } end +---@param match table ---@param map table +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map) +function MapFunctions.getExtraData(match, map, opponents) return { comment = map.comment, overtime = Logic.readBool(map.overtime) diff --git a/components/match2/wikis/wildrift/match_group_input_custom.lua b/components/match2/wikis/wildrift/match_group_input_custom.lua index a201a423a02..b7e971c3594 100644 --- a/components/match2/wikis/wildrift/match_group_input_custom.lua +++ b/components/match2/wikis/wildrift/match_group_input_custom.lua @@ -6,13 +6,10 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- -local Array = require('Module:Array') local ChampionNames = mw.loadData('Module:ChampionNames') local FnUtil = require('Module:FnUtil') local Logic = require('Module:Logic') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -45,36 +42,7 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map, #opponents) - - map.finished = MatchGroupInputUtil.mapIsFinished(map) - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }, MapFunctions.calculateMapScore(map.winner, map.finished)) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end -- @@ -110,17 +78,18 @@ end -- -- Parse extradata information +---@param match table ---@param map table ----@param opponentCount integer +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map, opponentCount) +function MapFunctions.getExtraData(match, map, opponents) local extraData = { comment = map.comment, } local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, ChampionNames) - for opponentIndex = 1, opponentCount do + for opponentIndex = 1, #opponents do extraData['team' .. opponentIndex .. 'side'] = string.lower(map['team' .. opponentIndex .. 'side'] or '') for playerIndex = 1, MAX_NUM_PLAYERS do local pick = getCharacterName(map['t' .. opponentIndex .. 'c' .. playerIndex]) diff --git a/components/match2/wikis/worldoftanks/match_group_input_custom.lua b/components/match2/wikis/worldoftanks/match_group_input_custom.lua index 9a3014f89e8..416cfdcfdbb 100644 --- a/components/match2/wikis/worldoftanks/match_group_input_custom.lua +++ b/components/match2/wikis/worldoftanks/match_group_input_custom.lua @@ -8,8 +8,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -31,44 +29,16 @@ end -- -- match related functions -- - ----@param match table ----@param opponents table[] ----@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map, #opponents) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) +end - return maps +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) end ---@param bestofInput string|integer? @@ -105,11 +75,11 @@ end -- -- map related functions -- - +---@param match table ---@param map table ----@param opponentCount integer +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map, opponentCount) +function MapFunctions.getExtraData(match, map, opponents) return { comment = map.comment, } diff --git a/components/match2/wikis/zula/match_group_input_custom.lua b/components/match2/wikis/zula/match_group_input_custom.lua index 9af6db7f933..ea015792972 100644 --- a/components/match2/wikis/zula/match_group_input_custom.lua +++ b/components/match2/wikis/zula/match_group_input_custom.lua @@ -8,8 +8,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -35,45 +33,15 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map, #opponents) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end --- Template:Map sets a default map name so we can count the number of maps. --- These maps however shouldn't be stored --- The keepMap function will check if a map should be kept ---@param games table[] ---@return table[] function MatchFunctions.removeUnsetMaps(games) - return Array.filter(games, MapFunctions.keepMap) + return Array.filter(games, function(map) + return map.map ~= nil + end) end ---@param maps table[] @@ -95,18 +63,11 @@ end -- -- map related functions -- - --- Check if a map should be discarded due to being redundant ----@param map table ----@return boolean -function MapFunctions.keepMap(map) - return map.map ~= nil -end - +---@param match table ---@param map table ----@param opponentCount integer +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map, opponentCount) +function MapFunctions.getExtraData(match, map, opponents) return {comment = map.comment} end