diff --git a/components/match2/wikis/pokemon/match_group_input_custom.lua b/components/match2/wikis/pokemon/match_group_input_custom.lua index 1b902369048..125639de11c 100644 --- a/components/match2/wikis/pokemon/match_group_input_custom.lua +++ b/components/match2/wikis/pokemon/match_group_input_custom.lua @@ -14,92 +14,47 @@ 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 CustomMatchGroupInput = {} +local MatchFunctions = {} +local MapFunctions = {} -local OPPONENT_CONFIG = { +local DEFAULT_BESTOF = 3 +MatchFunctions.DEFAULT_MODE = 'team' +MatchFunctions.OPPONENT_CONFIG = { resolveRedirect = true, pagifyTeamNames = true, maxNumPlayers = 5, } +MatchFunctions.DATE_FALLBACKS = { + 'tournament_enddate', + 'tournament_startdate', +} -local MatchFunctions = {} -local MapFunctions = {} - -local CustomMatchGroupInput = {} -- 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.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 ---@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, diff --git a/components/match2/wikis/rainbowsix/match_group_input_custom.lua b/components/match2/wikis/rainbowsix/match_group_input_custom.lua index c7d4c32abe8..8c83a19bbea 100644 --- a/components/match2/wikis/rainbowsix/match_group_input_custom.lua +++ b/components/match2/wikis/rainbowsix/match_group_input_custom.lua @@ -9,76 +9,25 @@ local Array = require('Module:Array') local CharacterNames = require('Module:CharacterNames') local FnUtil = require('Module:FnUtil') -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 MAX_NUM_BANS = 2 -local DEFAULT_MODE = 'team' - --- containers for process helper functions +local CustomMatchGroupInput = {} local MatchFunctions = {} local MapFunctions = {} -local CustomMatchGroupInput = {} +local MAX_NUM_BANS = 2 +MatchFunctions.DEFAULT_MODE = 'team' +MatchFunctions.getBestOf = MatchGroupInputUtil.getBestOf --- 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.bestof = MatchGroupInputUtil.getBestOf(nil, games) - games = MatchFunctions.removeUnsetMaps(games) - 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 -- @@ -86,18 +35,18 @@ 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 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, diff --git a/components/match2/wikis/sideswipe/match_group_input_custom.lua b/components/match2/wikis/sideswipe/match_group_input_custom.lua index 58a88cd14a3..8c60cfb6ed4 100644 --- a/components/match2/wikis/sideswipe/match_group_input_custom.lua +++ b/components/match2/wikis/sideswipe/match_group_input_custom.lua @@ -6,76 +6,32 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- -local CustomMatchGroupInput = {} 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 DEFAULT_MODE = '2v2' - --- containers for process helper functions +local CustomMatchGroupInput = {} local MatchFunctions = {} local MapFunctions = {} +MatchFunctions.DEFAULT_MODE = '2v2' +MatchFunctions.DATE_FALLBACKS = {'tournament_enddate'} +MatchFunctions.getBestOf = MatchGroupInputUtil.getBestOf --- 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'})) - - local opponents = Array.mapIndexes(function(opponentIndex) - return MatchGroupInputUtil.readOpponent(match, opponentIndex, {}) - end) - local games = CustomMatchGroupInput.extractMaps(match, #opponents) - - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({ - walkover = match.walkover, - winner = match.winner, - opponentIndex = opponentIndex, - score = opponent.score, - }) - 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, opponents) - - return match + return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) end ---@param match table ----@param opponentCount integer ----@return table -function CustomMatchGroupInput.extractMaps(match, opponentCount) +---@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 @@ -87,7 +43,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 score, status = MatchGroupInputUtil.computeOpponentScore({ walkover = map.walkover, winner = map.winner, diff --git a/components/match2/wikis/smite/match_group_input_custom.lua b/components/match2/wikis/smite/match_group_input_custom.lua index 3c5e312b75e..6a1f8273dab 100644 --- a/components/match2/wikis/smite/match_group_input_custom.lua +++ b/components/match2/wikis/smite/match_group_input_custom.lua @@ -12,79 +12,30 @@ local GodNames = mw.loadData('Module:GodNames') 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 CustomMatchGroupInput = {} +local MatchFunctions = {} +local MapFunctions = {} + local DEFAULT_BESTOF = 3 -local DEFAULT_MODE = 'team' local MAX_NUM_PLAYERS = 15 -local OPPONENT_CONFIG = { +MatchFunctions.DEFAULT_MODE = 'team' +MatchFunctions.OPPONENT_CONFIG = { resolveRedirect = true, pagifyTeamNames = true, maxNumPlayers = MAX_NUM_PLAYERS, } --- containers for process helper functions -local MatchFunctions = {} -local MapFunctions = {} - -local CustomMatchGroupInput = {} - -- 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, OPPONENT_CONFIG) - end) - - local games = MatchFunctions.extractMaps(match, #opponents) - match.bestof = MatchFunctions.getBestOf(match.bestof) - 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 -- @@ -92,13 +43,13 @@ 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 - table.insert(maps, MapFunctions.readMap(map, opponentCount)) + table.insert(maps, MapFunctions.readMap(map, #opponents)) match[key] = nil end diff --git a/components/match2/wikis/splatoon/match_group_input_custom.lua b/components/match2/wikis/splatoon/match_group_input_custom.lua index c24245870c2..a919f511f95 100644 --- a/components/match2/wikis/splatoon/match_group_input_custom.lua +++ b/components/match2/wikis/splatoon/match_group_input_custom.lua @@ -11,70 +11,21 @@ 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 Streams = require('Module:Links/Stream') local WeaponNames = mw.loadData('Module:WeaponNames') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') -local DEFAULT_MODE = 'team' - --- containers for process helper functions +local CustomMatchGroupInput = {} local MatchFunctions = {} local MapFunctions = {} +MatchFunctions.DEFAULT_MODE = 'team' +MatchFunctions.getBestOf = MatchGroupInputUtil.getBestOf -local CustomMatchGroupInput = {} - --- 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.bestof = MatchGroupInputUtil.getBestOf(nil, games) - - 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 diff --git a/components/match2/wikis/splitgate/match_group_input_custom.lua b/components/match2/wikis/splitgate/match_group_input_custom.lua index 079c3857943..e76e3dd0bf6 100644 --- a/components/match2/wikis/splitgate/match_group_input_custom.lua +++ b/components/match2/wikis/splitgate/match_group_input_custom.lua @@ -7,77 +7,25 @@ -- 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 DEFAULT_BESTOF = 3 -local DEFAULT_MODE = 'team' - --- containers for process helper functions +local CustomMatchGroupInput = {} local MatchFunctions = {} local MapFunctions = {} -local CustomMatchGroupInput = {} +MatchFunctions.DEFAULT_MODE = 'team' +local DEFAULT_BESTOF = 3 --- 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 -- @@ -85,9 +33,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 @@ -96,10 +44,10 @@ function MatchFunctions.extractMaps(match, opponentCount) 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, diff --git a/components/match2/wikis/teamfortress/match_group_input_custom.lua b/components/match2/wikis/teamfortress/match_group_input_custom.lua index b9186bfc00c..521d1bcdf38 100644 --- a/components/match2/wikis/teamfortress/match_group_input_custom.lua +++ b/components/match2/wikis/teamfortress/match_group_input_custom.lua @@ -16,68 +16,23 @@ local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') -local DEFAULT_MODE = 'team' - --- containers for process helper functions +local CustomMatchGroupInput = {} local MatchFunctions = {} local MapFunctions = {} - -local CustomMatchGroupInput = {} +MatchFunctions.DEFAULT_MODE = 'team' +MatchFunctions.getBestOf = MatchGroupInputUtil.getBestOf ---@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 = MatchGroupInputUtil.getBestOf(match.bestof, games) - match.links = MatchFunctions.getLinks(match, games) - - 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 - - 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 not map.map then @@ -89,7 +44,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 score, status = MatchGroupInputUtil.computeOpponentScore({ walkover = map.walkover, winner = map.winner, @@ -129,7 +84,7 @@ end ---@param games table[] ---@return table function MatchFunctions.getLinks(match, games) - ---@type table + ---@type table local links = MatchGroupInputUtil.getLinks(match) links.logstf = {} links.logstfgold = {} diff --git a/components/match2/wikis/tetris/match_group_input_custom.lua b/components/match2/wikis/tetris/match_group_input_custom.lua index b52f911abd6..5d1a130c510 100644 --- a/components/match2/wikis/tetris/match_group_input_custom.lua +++ b/components/match2/wikis/tetris/match_group_input_custom.lua @@ -12,21 +12,21 @@ 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 DEFAULT_BESTOF = 99 +local CustomMatchGroupInput = {} -local OPPONENT_CONFIG = { +local DEFAULT_BESTOF = 99 +CustomMatchGroupInput.OPPONENT_CONFIG = { resolveRedirect = true, pagifyTeamNames = true, } +CustomMatchGroupInput.DEFAULT_MODE = 'solo' -local CustomMatchGroupInput = {} -- called from Module:MatchGroup ---@param match table @@ -38,52 +38,7 @@ function CustomMatchGroupInput.processMatch(match) if CustomMatchGroupInput._hasTeamOpponent(match) then error('Team opponents are currently not yet supported on tetris 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.bestof) - - 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 - - match.extradata = CustomMatchGroupInput.getExtraData(match) - - return match + return MatchGroupInputUtil.standardProcessMatch(match, CustomMatchGroupInput) end ---@param match table