diff --git a/components/match2/wikis/hearthstone/match_group_input_custom.lua b/components/match2/wikis/hearthstone/match_group_input_custom.lua index 4d13365b951..2f31674b02a 100644 --- a/components/match2/wikis/hearthstone/match_group_input_custom.lua +++ b/components/match2/wikis/hearthstone/match_group_input_custom.lua @@ -14,72 +14,27 @@ 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 MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') local OpponentLibraries = require('Module:OpponentLibraries') local Opponent = OpponentLibraries.Opponent -local Streams = Lua.import('Module:Links/Stream') -local OPPONENT_CONFIG = { + +local CustomMatchGroupInput = {} +local MatchFunctions = {} +local MapFunctions = {} +MatchFunctions.OPPONENT_CONFIG = { resolveRedirect = true, pagifyTeamNames = true, pagifyPlayerNames = true, } local TBD = 'TBD' -local CustomMatchGroupInput = {} -local MatchFunctions = {} -local MapFunctions = {} - ---@param match table ---@param options table? ---@return table function CustomMatchGroupInput.processMatch(match, options) - local finishedInput = match.finished --[[@as string?]] - local winnerInput = match.winner --[[@as string?]] - - Table.mergeInto(match, MatchGroupInputUtil.readDate(match.date)) - - local opponents = Array.mapIndexes(function(opponentIndex) - return MatchGroupInputUtil.readOpponent(match, opponentIndex, OPPONENT_CONFIG) - end) - - local games = MatchFunctions.extractMaps(match, opponents) - - local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(match, games) - and MatchFunctions.calculateMatchScore(games) - or nil - - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({ - walkover = match.walkover, - winner = match.winner, - opponentIndex = opponentIndex, - score = opponent.score, - }, autoScoreFunction) - end) - - match.finished = MatchGroupInputUtil.matchIsFinished(match, opponents) - - if match.finished then - match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents) - match.walkover = MatchGroupInputUtil.getWalkover(match.resulttype, opponents) - match.winner = MatchGroupInputUtil.getWinner(match.resulttype, winnerInput, opponents) - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.placement = MatchGroupInputUtil.placementFromWinner(match.resulttype, match.winner, opponentIndex) - end) - end - - match.mode = Variables.varDefault('tournament_mode', 'singles') - Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match)) - - match.stream = Streams.processStreams(match) - - match.games = games - match.opponents = opponents - - return match + return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) end ---@param maps table[] @@ -111,7 +66,7 @@ function MatchFunctions.extractMaps(match, opponents) map.finished = MatchGroupInputUtil.mapIsFinished(map) - local opponentInfo = Array.map(Array.range(1, #opponents), function(opponentIndex) + local opponentInfo = Array.map(opponents, function(_, opponentIndex) local score, status = MatchGroupInputUtil.computeOpponentScore({ walkover = map.walkover, winner = map.winner, diff --git a/components/match2/wikis/heroes/match_group_input_custom.lua b/components/match2/wikis/heroes/match_group_input_custom.lua index 0afedcf85ae..77502a58980 100644 --- a/components/match2/wikis/heroes/match_group_input_custom.lua +++ b/components/match2/wikis/heroes/match_group_input_custom.lua @@ -14,89 +14,41 @@ local Lua = require('Module:Lua') local Operator = require('Module:Operator') local Table = require('Module:Table') local Variables = require('Module:Variables') -local Streams = require('Module:Links/Stream') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') -local DEFAULT_BESTOF = 3 -local DEFAULT_MODE = 'team' - -local OPPONENT_CONFIG = {} - --- containers for process helper functions +local CustomMatchGroupInput = {} local MatchFunctions = {} local MapFunctions = {} -local CustomMatchGroupInput = {} +local DEFAULT_BESTOF = 3 +MatchFunctions.DEFAULT_MODE = 'team' +MatchFunctions.OPPONENT_CONFIG = {} +MatchFunctions.DATE_FALLBACKS = { + 'tournament_enddate', + 'tournament_startdate', +} ---@param match table ---@param options table? ---@return table function CustomMatchGroupInput.processMatch(match, options) - local finishedInput = match.finished --[[@as string?]] - local winnerInput = match.winner --[[@as string?]] - Table.mergeInto(match, MatchGroupInputUtil.readDate(match.date, { - 'tournament_enddate', - 'tournament_startdate', - })) - - local opponents = Array.mapIndexes(function(opponentIndex) - return MatchGroupInputUtil.readOpponent(match, opponentIndex, OPPONENT_CONFIG) - end) - local games = CustomMatchGroupInput.extractMaps(match, #opponents) - match.bestof = MatchFunctions.getBestOf(match) - match.links = MatchGroupInputUtil.getLinks(match) - - local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(match, games) - and MatchFunctions.calculateMatchScore(games) - or nil - - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({ - walkover = match.walkover, - winner = match.winner, - opponentIndex = opponentIndex, - score = opponent.score, - }, autoScoreFunction) - end) - - match.finished = MatchGroupInputUtil.matchIsFinished(match, opponents) - - if match.finished then - match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents) - match.walkover = MatchGroupInputUtil.getWalkover(match.resulttype, opponents) - match.winner = MatchGroupInputUtil.getWinner(match.resulttype, winnerInput, opponents) - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.placement = MatchGroupInputUtil.placementFromWinner(match.resulttype, match.winner, opponentIndex) - end) - end - - match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', DEFAULT_MODE)) - Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match)) - - match.stream = Streams.processStreams(match) - - match.games = games - match.opponents = opponents - - match.extradata = MatchFunctions.getExtraData(match) - - return match + return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) end ---@param match table ----@param opponentCount integer +---@param opponents table[] ---@return table[] -function CustomMatchGroupInput.extractMaps(match, opponentCount) +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, opponentCount) + map.extradata = MapFunctions.getExtraData(map, #opponents) map.finished = MatchGroupInputUtil.mapIsFinished(map) - local opponentInfo = Array.map(Array.range(1, opponentCount), function(opponentIndex) + local opponentInfo = Array.map(opponents, function(_, opponentIndex) local score, status = MatchGroupInputUtil.computeOpponentScore({ walkover = map.walkover, winner = map.winner, @@ -120,7 +72,6 @@ function CustomMatchGroupInput.extractMaps(match, opponentCount) return maps end - -- -- match related functions --- diff --git a/components/match2/wikis/honorofkings/match_group_input_custom.lua b/components/match2/wikis/honorofkings/match_group_input_custom.lua index 2f6d453fa24..f35f9e810f8 100644 --- a/components/match2/wikis/honorofkings/match_group_input_custom.lua +++ b/components/match2/wikis/honorofkings/match_group_input_custom.lua @@ -14,87 +14,39 @@ local Lua = require('Module:Lua') local Operator = require('Module:Operator') local Table = require('Module:Table') local Variables = require('Module:Variables') -local Streams = require('Module:Links/Stream') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') -local MAX_NUM_PLAYERS = 5 -local DEFAULT_BESTOF = 3 -local DEFAULT_MODE = 'team' -local DUMMY_MAP = 'default' +local CustomMatchGroupInput = {} +local MatchFunctions = {} +local MapFunctions = {} -local OPPONENT_CONFIG = { +MatchFunctions.DEFAULT_MODE = 'team' +MatchFunctions.OPPONENT_CONFIG = { resolveRedirect = true, pagifyTeamNames = false, maxNumPlayers = 5, } +MatchFunctions.DATE_FALLBACKS = { + 'tournament_enddate', + 'tournament_startdate', +} --- containers for process helper functions -local MatchFunctions = {} -local MapFunctions = {} - -local CustomMatchGroupInput = {} +local MAX_NUM_PLAYERS = 5 +local DEFAULT_BESTOF = 3 +local DUMMY_MAP = 'default' --- called from Module:MatchGroup ---@param match table ---@param options table? ---@return table function CustomMatchGroupInput.processMatch(match, options) - local finishedInput = match.finished --[[@as string?]] - local winnerInput = match.winner --[[@as string?]] - Table.mergeInto(match, MatchGroupInputUtil.readDate(match.date, { - 'tournament_enddate', - 'tournament_startdate', - })) - - local opponents = Array.mapIndexes(function(opponentIndex) - return MatchGroupInputUtil.readOpponent(match, opponentIndex, OPPONENT_CONFIG) - end) - local games = CustomMatchGroupInput.extractMaps(match, #opponents) - match.bestof = MatchFunctions.getBestOf(match) - match.links = MatchGroupInputUtil.getLinks(match) - - local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(match, games) - and MatchFunctions.calculateMatchScore(games) - or nil - - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({ - walkover = match.walkover, - winner = match.winner, - opponentIndex = opponentIndex, - score = opponent.score, - }, autoScoreFunction) - end) - - match.finished = MatchGroupInputUtil.matchIsFinished(match, opponents) - - if match.finished then - match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents) - match.walkover = MatchGroupInputUtil.getWalkover(match.resulttype, opponents) - match.winner = MatchGroupInputUtil.getWinner(match.resulttype, winnerInput, opponents) - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.placement = MatchGroupInputUtil.placementFromWinner(match.resulttype, match.winner, opponentIndex) - end) - end - - match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', DEFAULT_MODE)) - Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match)) - - match.stream = Streams.processStreams(match) - - match.games = games - match.opponents = opponents - - match.extradata = MatchFunctions.getExtraData(match) - - return match + return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) end ---@param match table ----@param opponentCount integer +---@param opponents table[] ---@return table[] -function CustomMatchGroupInput.extractMaps(match, opponentCount) +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?]] @@ -104,10 +56,10 @@ function CustomMatchGroupInput.extractMaps(match, opponentCount) map.map = nil end - map.extradata = MapFunctions.getExtraData(map, opponentCount) + map.extradata = MapFunctions.getExtraData(map, #opponents) map.finished = MatchGroupInputUtil.mapIsFinished(map) - local opponentInfo = Array.map(Array.range(1, opponentCount), function(opponentIndex) + local opponentInfo = Array.map(opponents, function(_, opponentIndex) local score, status = MatchGroupInputUtil.computeOpponentScore({ walkover = map.walkover, winner = map.winner, diff --git a/components/match2/wikis/magic/match_group_input_custom.lua b/components/match2/wikis/magic/match_group_input_custom.lua index 22a32dda4bd..84c338e5511 100644 --- a/components/match2/wikis/magic/match_group_input_custom.lua +++ b/components/match2/wikis/magic/match_group_input_custom.lua @@ -12,21 +12,22 @@ local Lua = require('Module:Lua') local Operator = require('Module:Operator') local Table = require('Module:Table') local Variables = require('Module:Variables') -local Streams = require('Module:Links/Stream') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') local OpponentLibrary = require('Module:OpponentLibraries') local Opponent = OpponentLibrary.Opponent +local CustomMatchGroupInput = {} + local DEFAULT_BESTOF = 99 -local OPPONENT_CONFIG = { +CustomMatchGroupInput.OPPONENT_CONFIG = { resolveRedirect = true, pagifyTeamNames = true, } +CustomMatchGroupInput.DEFAULT_MODE = 'solo' -local CustomMatchGroupInput = {} -- called from Module:MatchGroup ---@param match table @@ -39,49 +40,7 @@ function CustomMatchGroupInput.processMatch(match) error('Team opponents are currently not yet supported on magic wiki') end - local finishedInput = match.finished --[[@as string?]] - local winnerInput = match.winner --[[@as string?]] - Table.mergeInto(match, MatchGroupInputUtil.readDate(match.date)) - - local opponents = Array.mapIndexes(function(opponentIndex) - return MatchGroupInputUtil.readOpponent(match, opponentIndex, OPPONENT_CONFIG) - end) - local games = CustomMatchGroupInput.extractMaps(match, opponents) - match.bestof = CustomMatchGroupInput.getBestOf(match) - - local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(match, games) - and CustomMatchGroupInput.calculateMatchScore(games) - or nil - - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({ - walkover = match.walkover, - winner = match.winner, - opponentIndex = opponentIndex, - score = opponent.score, - }, autoScoreFunction) - end) - - match.finished = MatchGroupInputUtil.matchIsFinished(match, opponents) - - if match.finished then - match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents) - match.walkover = MatchGroupInputUtil.getWalkover(match.resulttype, opponents) - match.winner = MatchGroupInputUtil.getWinner(match.resulttype, winnerInput, opponents) - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.placement = MatchGroupInputUtil.placementFromWinner(match.resulttype, match.winner, opponentIndex) - end) - end - - match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', 'solo')) - Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match)) - - match.stream = Streams.processStreams(match) - - match.games = games - match.opponents = opponents - - return match + return MatchGroupInputUtil.standardProcessMatch(match, CustomMatchGroupInput) end ---@param match table diff --git a/components/match2/wikis/mobilelegends/match_group_input_custom.lua b/components/match2/wikis/mobilelegends/match_group_input_custom.lua index 1752c8b6f99..dd299671a23 100644 --- a/components/match2/wikis/mobilelegends/match_group_input_custom.lua +++ b/components/match2/wikis/mobilelegends/match_group_input_custom.lua @@ -14,68 +14,26 @@ local Operator = require('Module:Operator') local String = require('Module:StringUtils') local Table = require('Module:Table') local Variables = require('Module:Variables') -local Streams = require('Module:Links/Stream') local ChampionNames = mw.loadData('Module:HeroNames') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') -local DEFAULT_BESTOF_MATCH = 3 - --- containers for process helper functions +local CustomMatchGroupInput = {} local MatchFunctions = {} local MapFunctions = {} -local CustomMatchGroupInput = {} +local DEFAULT_BESTOF_MATCH = 3 +MatchFunctions.DEFAULT_MODE = 'team' +MatchFunctions.OPPONENT_CONFIG = {} +MatchFunctions.DATE_FALLBACKS = { + 'tournament_enddate', +} ---@param match table ---@param options table? ---@return table function CustomMatchGroupInput.processMatch(match, options) - local finishedInput = match.finished --[[@as string?]] - local winnerInput = match.winner --[[@as string?]] - - Table.mergeInto(match, MatchGroupInputUtil.readDate(match.date, {'tournament_enddate'})) - - local opponents = Array.mapIndexes(function(opponentIndex) - return MatchGroupInputUtil.readOpponent(match, opponentIndex, {}) - end) - local games = CustomMatchGroupInput.extractMaps(match, opponents) - match.bestof = MatchFunctions.getBestOf(match) - - local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(match, games) - and MatchFunctions.calculateMatchScore(games, match.bestof) - or nil - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({ - walkover = match.walkover, - winner = match.winner, - opponentIndex = opponentIndex, - score = opponent.score, - }, autoScoreFunction) - end) - - match.finished = MatchGroupInputUtil.matchIsFinished(match, opponents) - - if match.finished then - match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents) - match.walkover = MatchGroupInputUtil.getWalkover(match.resulttype, opponents) - match.winner = MatchGroupInputUtil.getWinner(match.resulttype, winnerInput, opponents) - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.placement = MatchGroupInputUtil.placementFromWinner(match.resulttype, match.winner, opponentIndex) - end) - end - - match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', 'team')) - Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match)) - - match.stream = Streams.processStreams(match) - - match.games = games - match.opponents = opponents - - match.extradata = MatchFunctions.getExtraData(match) - - return match + return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) end ---@param match table diff --git a/components/match2/wikis/omegastrikers/match_group_input_custom.lua b/components/match2/wikis/omegastrikers/match_group_input_custom.lua index 1de9123b05a..b15b25c722a 100644 --- a/components/match2/wikis/omegastrikers/match_group_input_custom.lua +++ b/components/match2/wikis/omegastrikers/match_group_input_custom.lua @@ -13,73 +13,29 @@ local Lua = require('Module:Lua') local Operator = require('Module:Operator') local Table = require('Module:Table') local Variables = require('Module:Variables') -local Streams = require('Module:Links/Stream') local StrikerNames = mw.loadData('Module:StrikerNames') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') -local DEFAULT_BESTOF_MATCH = 5 -local DEFAULT_BESTOF_MAP = 3 - --- containers for process helper functions +local CustomMatchGroupInput = {} local MatchFunctions = {} local MapFunctions = {} -local CustomMatchGroupInput = {} +local DEFAULT_BESTOF_MATCH = 5 +local DEFAULT_BESTOF_MAP = 3 +MatchFunctions.DEFAULT_MODE = 'team' ---@param match table ---@param options table? ---@return table function CustomMatchGroupInput.processMatch(match, options) - local finishedInput = match.finished --[[@as string?]] - local winnerInput = match.winner --[[@as string?]] - - Table.mergeInto(match, MatchGroupInputUtil.readDate(match.date)) - - local opponents = Array.mapIndexes(function(opponentIndex) - return MatchGroupInputUtil.readOpponent(match, opponentIndex, {}) - end) - local games = CustomMatchGroupInput.extractMaps(match, opponents) - match.bestof = MatchFunctions.getBestOf(match) - - local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(match, games) - and MatchFunctions.calculateMatchScore(games, match.bestof) - or nil - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({ - walkover = match.walkover, - winner = match.winner, - opponentIndex = opponentIndex, - score = opponent.score, - }, autoScoreFunction) - end) - - match.finished = MatchGroupInputUtil.matchIsFinished(match, opponents) - - if match.finished then - match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents) - match.walkover = MatchGroupInputUtil.getWalkover(match.resulttype, opponents) - match.winner = MatchGroupInputUtil.getWinner(match.resulttype, winnerInput, opponents) - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.placement = MatchGroupInputUtil.placementFromWinner(match.resulttype, match.winner, opponentIndex) - end) - end - - match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', 'team')) - Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match)) - - match.stream = Streams.processStreams(match) - - match.games = games - match.opponents = opponents - - return match + return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) end ---@param match table ---@param opponents table[] ---@return table[] -function CustomMatchGroupInput.extractMaps(match, opponents) +function MatchFunctions.extractMaps(match, opponents) local maps = {} for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do if not map.map then @@ -123,9 +79,8 @@ end -- ---@param maps table[] ----@param bestOf integer ---@return fun(opponentIndex: integer): integer? -function MatchFunctions.calculateMatchScore(maps, bestOf) +function MatchFunctions.calculateMatchScore(maps) return function(opponentIndex) return MatchGroupInputUtil.computeMatchScoreFromMapWinners(maps, opponentIndex) end diff --git a/components/match2/wikis/osu/match_group_input_custom.lua b/components/match2/wikis/osu/match_group_input_custom.lua index 7fa6b7254c5..126876abdb7 100644 --- a/components/match2/wikis/osu/match_group_input_custom.lua +++ b/components/match2/wikis/osu/match_group_input_custom.lua @@ -7,78 +7,26 @@ -- local Array = require('Module:Array') -local Logic = require('Module:Logic') local Lua = require('Module:Lua') local Operator = require('Module:Operator') -local Streams = require('Module:Links/Stream') local Table = require('Module:Table') local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') -local ALLOWED_VETOES = Array.append(MatchGroupInputUtil.DEFAULT_ALLOWED_VETOES, 'protect') -local DEFAULT_BESTOF = 3 -local DEFAULT_MODE = 'team' - --- containers for process helper functions +local CustomMatchGroupInput = {} local MatchFunctions = {} local MapFunctions = {} -local CustomMatchGroupInput = {} +local ALLOWED_VETOES = Array.append(MatchGroupInputUtil.DEFAULT_ALLOWED_VETOES, 'protect') +local DEFAULT_BESTOF = 3 +MatchFunctions.DEFAULT_MODE = 'team' --- called from Module:MatchGroup ---@param match table ---@param options table? ---@return table function CustomMatchGroupInput.processMatch(match, options) - local finishedInput = match.finished --[[@as string?]] - local winnerInput = match.winner --[[@as string?]] - - Table.mergeInto(match, MatchGroupInputUtil.readDate(match.date)) - - local opponents = Array.mapIndexes(function(opponentIndex) - return MatchGroupInputUtil.readOpponent(match, opponentIndex, {}) - end) - - local games = MatchFunctions.extractMaps(match, #opponents) - match.links = MatchGroupInputUtil.getLinks(match) - - match.bestof = MatchFunctions.getBestOf(match.bestof) - - local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(match, games) - and MatchFunctions.calculateMatchScore(games) - or nil - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({ - walkover = match.walkover, - winner = match.winner, - opponentIndex = opponentIndex, - score = opponent.score, - }, autoScoreFunction) - end) - - match.finished = MatchGroupInputUtil.matchIsFinished(match, opponents) - - if match.finished then - match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents) - match.walkover = MatchGroupInputUtil.getWalkover(match.resulttype, opponents) - match.winner = MatchGroupInputUtil.getWinner(match.resulttype, winnerInput, opponents) - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.placement = MatchGroupInputUtil.placementFromWinner(match.resulttype, match.winner, opponentIndex) - end) - end - - match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode'), DEFAULT_MODE) - Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match)) - - match.stream = Streams.processStreams(match) - - match.games = games - match.opponents = opponents - - match.extradata = MatchFunctions.getExtraData(match) - - return match + return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) end -- @@ -86,9 +34,9 @@ end -- ---@param match table ----@param opponentCount integer +---@param opponents table[] ---@return table[] -function MatchFunctions.extractMaps(match, opponentCount) +function MatchFunctions.extractMaps(match, opponents) local maps = {} for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do if not map.map then @@ -100,7 +48,7 @@ function MatchFunctions.extractMaps(match, opponentCount) map.extradata = MapFunctions.getExtraData(map) map.finished = MatchGroupInputUtil.mapIsFinished(map) - local opponentInfo = Array.map(Array.range(1, opponentCount), function(opponentIndex) + local opponentInfo = Array.map(opponents, function(_, opponentIndex) local percentageScore = (map['score' .. opponentIndex] or ''):match('(%d+)%%') if percentageScore then return {score = map['score' .. opponentIndex], status = MatchGroupInputUtil.STATUS.SCORE} diff --git a/components/match2/wikis/overwatch/match_group_input_custom.lua b/components/match2/wikis/overwatch/match_group_input_custom.lua index cbc380e2f49..c1aec403fc3 100644 --- a/components/match2/wikis/overwatch/match_group_input_custom.lua +++ b/components/match2/wikis/overwatch/match_group_input_custom.lua @@ -16,70 +16,24 @@ local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') -local DEFAULT_BESTOF = 3 - --- containers for process helper functions +local CustomMatchGroupInput = {} local MatchFunctions = {} local MapFunctions = {} -local CustomMatchGroupInput = {} +local DEFAULT_BESTOF = 3 +MatchFunctions.DEFAULT_MODE = 'team' ---@param match table ---@param options table? ---@return table function CustomMatchGroupInput.processMatch(match, options) - local finishedInput = match.finished --[[@as string?]] - local winnerInput = match.winner --[[@as string?]] - - Table.mergeInto(match, MatchGroupInputUtil.readDate(match.date)) - - local opponents = Array.mapIndexes(function(opponentIndex) - return MatchGroupInputUtil.readOpponent(match, opponentIndex, {}) - end) - local games = CustomMatchGroupInput.extractMaps(match, #opponents) - match.bestof = MatchFunctions.getBestOf(match) - match.links = MatchGroupInputUtil.getLinks(match) - - local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(match, games) - and MatchFunctions.calculateMatchScore(games) - or nil - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({ - walkover = match.walkover, - winner = match.winner, - opponentIndex = opponentIndex, - score = opponent.score, - }, autoScoreFunction) - end) - - match.finished = MatchGroupInputUtil.matchIsFinished(match, opponents) - - if match.finished then - match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents) - match.walkover = MatchGroupInputUtil.getWalkover(match.resulttype, opponents) - match.winner = MatchGroupInputUtil.getWinner(match.resulttype, winnerInput, opponents) - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.placement = MatchGroupInputUtil.placementFromWinner(match.resulttype, match.winner, opponentIndex) - end) - end - - match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', 'team')) - Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match)) - - match.stream = Streams.processStreams(match) - - match.games = games - match.opponents = opponents - - match.extradata = MatchFunctions.getExtraData(match) - - return match + return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) end ---@param match table ----@param opponentCount integer +---@param opponents table[] ---@return table[] -function CustomMatchGroupInput.extractMaps(match, opponentCount) +function MatchFunctions.extractMaps(match, opponents) local maps = {} for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do if map.map == nil then @@ -91,7 +45,7 @@ function CustomMatchGroupInput.extractMaps(match, opponentCount) map.extradata = MapFunctions.getExtraData(map) map.finished = MatchGroupInputUtil.mapIsFinished(map) - local opponentInfo = Array.map(Array.range(1, opponentCount), function(opponentIndex) + local opponentInfo = Array.map(opponents, function(_, opponentIndex) local scoreInput = map['score' .. opponentIndex] if map.mode == 'Push' and scoreInput then scoreInput = scoreInput:gsub('m', '')