From 5ece2348b2dc583fef6edc88255718e5e88feead Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 12:56:17 +0100 Subject: [PATCH 01/22] wow --- .../wikis/worldofwarcraft/match_group_input_custom.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/components/match2/wikis/worldofwarcraft/match_group_input_custom.lua b/components/match2/wikis/worldofwarcraft/match_group_input_custom.lua index cb5e19e5acd..9bfe9a665de 100644 --- a/components/match2/wikis/worldofwarcraft/match_group_input_custom.lua +++ b/components/match2/wikis/worldofwarcraft/match_group_input_custom.lua @@ -69,7 +69,7 @@ function MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) local players = Array.mapIndexes(function(playerIndex) return opponent.match2players[playerIndex] or Logic.nilIfEmpty(map['t' .. opponentIndex .. 's' .. playerIndex]) end) - local participants, unattachedParticipants = MatchGroupInputUtil.parseParticipants( + return MatchGroupInputUtil.parseMapPlayers( opponent.match2players, players, function(playerIndex) @@ -83,10 +83,6 @@ function MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) } end ) - Array.forEach(unattachedParticipants, function(participant) - table.insert(participants, participant) - end) - return participants end ---@param map table From 7928cdc1e08bdd113a9cd9485fe524be90926702 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 13:16:46 +0100 Subject: [PATCH 02/22] mlbb --- .../wikis/mobilelegends/match_group_input_custom.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/components/match2/wikis/mobilelegends/match_group_input_custom.lua b/components/match2/wikis/mobilelegends/match_group_input_custom.lua index 483ae7ea2ab..e2515c78beb 100644 --- a/components/match2/wikis/mobilelegends/match_group_input_custom.lua +++ b/components/match2/wikis/mobilelegends/match_group_input_custom.lua @@ -108,9 +108,9 @@ end function MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, ChampionNames) local players = Array.mapIndexes(function(playerIndex) - return opponent.match2players[playerIndex] or Logic.nilIfEmpty(map['t' .. opponentIndex .. 'h' .. playerIndex]) + return map['t' .. opponentIndex .. 'p' .. playerIndex] or map['t' .. opponentIndex .. 'h' .. playerIndex] end) - local participants, unattachedParticipants = MatchGroupInputUtil.parseParticipants( + return MatchGroupInputUtil.parseMapPlayers( opponent.match2players, players, function(playerIndex) @@ -124,10 +124,6 @@ function MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) } end ) - Array.forEach(unattachedParticipants, function(participant) - table.insert(participants, participant) - end) - return participants end return CustomMatchGroupInput From 10d0f92ebf21ed77fdbf3db29da0ded9f13bb6c7 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 13:38:14 +0100 Subject: [PATCH 03/22] clashofclans (+ commons adjust for it) --- .../match2/commons/match_group_input_util.lua | 9 +++- .../clashofclans/match_group_input_custom.lua | 50 ++++++------------- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/components/match2/commons/match_group_input_util.lua b/components/match2/commons/match_group_input_util.lua index f4490b8b76e..0ac9043a191 100644 --- a/components/match2/commons/match_group_input_util.lua +++ b/components/match2/commons/match_group_input_util.lua @@ -1164,6 +1164,7 @@ end ---@field getPlayersOfMapOpponent? fun(game: table, opponent:table, opponentIndex: integer): table[] ---@field getPatch? fun(game: table): string? ---@field mapIsFinished? fun(map: table, opponents: table[], finishedInput: string?, winnerInput: string?): boolean +---@field extendMapOpponent? fun(map: table, opponentIndex: integer): table ---@field ADD_SUB_GROUP? boolean ---@field BREAK_ON_EMPTY? boolean @@ -1224,7 +1225,12 @@ function MatchGroupInputUtil.standardProcessMaps(match, opponents, Parser) local players = Parser.getPlayersOfMapOpponent and Parser.getPlayersOfMapOpponent(map, opponent, opponentIndex) or nil - return {score = score, status = status, players = players} + + local mapOpponent = {score = score, status = status, players = players} + if not Parser.extendMapOpponent then + return mapOpponent + end + return Table.merge(Parser.extendMapOpponent(map, opponentIndex), mapOpponent) end) -- needs map.opponents available! @@ -1463,6 +1469,7 @@ function MatchGroupInputUtil.calculatePlacementOfOpponents(opponents) end ---@param match table +---@param opponentCount integer ---@return {placementInfo: table[], settings: table} function MatchGroupInputUtil.parseSettings(match, opponentCount) -- Pre-parse Status colors (up/down etc) diff --git a/components/match2/wikis/clashofclans/match_group_input_custom.lua b/components/match2/wikis/clashofclans/match_group_input_custom.lua index fa2fff947ca..d84a8ce3058 100644 --- a/components/match2/wikis/clashofclans/match_group_input_custom.lua +++ b/components/match2/wikis/clashofclans/match_group_input_custom.lua @@ -52,41 +52,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.map = MapFunctions.getMapName(map) - map.extradata = MapFunctions.getExtraData(map) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - map.opponents = 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, - time = map.extradata.times[opponentIndex], - percentage = map.extradata.percentages[opponentIndex] or 0 - } - end) - - map.scores = Array.map(map.opponents, Operator.property('score')) - if map.finished then - map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput) - map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end ---@param bestofInput string|integer? @@ -119,9 +85,11 @@ function MapFunctions.getMapName(map) return nil 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, times = MapFunctions.readTimes(map), @@ -161,4 +129,14 @@ function MapFunctions.readTimes(map) return timesInSeconds end +function MapFunctions.extendMapOpponent(map, opponentIndex) + local times = MapFunctions.readTimes(map) + local percentages = MapFunctions.readPercentages(map) + + return { + time = times[opponentIndex], + percentage = percentages[opponentIndex] or 0, + } +end + return CustomMatchGroupInput From e09f9fb5eba1b70f8706de7e97dc41f40feb8e8c Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 13:51:51 +0100 Subject: [PATCH 04/22] brawlstars (+ commons adjustments needed) --- .../match2/commons/match_group_input_util.lua | 5 ++ .../brawlstars/match_group_input_custom.lua | 55 ++++--------------- 2 files changed, 16 insertions(+), 44 deletions(-) diff --git a/components/match2/commons/match_group_input_util.lua b/components/match2/commons/match_group_input_util.lua index 0ac9043a191..4edffe3b028 100644 --- a/components/match2/commons/match_group_input_util.lua +++ b/components/match2/commons/match_group_input_util.lua @@ -1165,6 +1165,7 @@ end ---@field getPatch? fun(game: table): string? ---@field mapIsFinished? fun(map: table, opponents: table[], finishedInput: string?, winnerInput: string?): boolean ---@field extendMapOpponent? fun(map: table, opponentIndex: integer): table +---@field getMapBestOf? fun(map: table): integer? ---@field ADD_SUB_GROUP? boolean ---@field BREAK_ON_EMPTY? boolean @@ -1215,6 +1216,10 @@ function MatchGroupInputUtil.standardProcessMaps(match, opponents, Parser) map.patch = Parser.getPatch(map) end + if Parser.getMapBestOf then + map.bestof = Parser.getMapBestOf(map) + end + map.opponents = Array.map(opponents, function(opponent, opponentIndex) local score, status = MatchGroupInputUtil.computeOpponentScore({ walkover = map.walkover, diff --git a/components/match2/wikis/brawlstars/match_group_input_custom.lua b/components/match2/wikis/brawlstars/match_group_input_custom.lua index 5b11def4c1a..680e73ce142 100644 --- a/components/match2/wikis/brawlstars/match_group_input_custom.lua +++ b/components/match2/wikis/brawlstars/match_group_input_custom.lua @@ -30,7 +30,9 @@ local DEFAULT_BESTOF_MAP = 3 -- containers for process helper functions local MatchFunctions = {} -local MapFunctions = {} +local MapFunctions = { + BREAK_ON_EMPTY = true, +} MatchFunctions.DEFAULT_MODE = 'team' MatchFunctions.DATE_FALLBACKS = { @@ -50,42 +52,11 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if map.map == nil then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.vod = map.vod or String.nilIfEmpty(match['vodgame' .. mapIndex]) - map.bestof = MapFunctions.getBestOf(map) - map.extradata = MapFunctions.getExtraData(map, #opponents) - - map.opponents = Array.map(opponents, function(opponent, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - local players = MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) - return {score = score, status = status, players = players} - end) - - map.finished = MatchGroupInputUtil.mapIsFinished(map, map.opponents) - - map.scores = Array.map(map.opponents, Operator.property('score')) - if map.finished then - map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput) - map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + local games = MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) + Array.forEach(games, function(game, gameINdex) + game.vod = game.vod or String.nilIfEmpty(match['vodgame' .. gameINdex]) + end) + return games end -- @@ -124,7 +95,7 @@ end ---@param map table ---@return integer -function MapFunctions.getBestOf(map) +function MapFunctions.getMapBestOf(map) local bestof = tonumber(Logic.emptyOr(map.bestof, Variables.varDefault('map_bestof'))) Variables.varDefine('map_bestof', bestof) return bestof or DEFAULT_BESTOF_MAP @@ -163,9 +134,9 @@ end function MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, BrawlerNames) local players = Array.mapIndexes(function(playerIndex) - return opponent.match2players[playerIndex] or Logic.nilIfEmpty(map['t' .. opponentIndex .. 'c' .. playerIndex]) + return map['t' .. opponentIndex .. 'p' .. playerIndex] or map['t' .. opponentIndex .. 'c' .. playerIndex] end) - local participants, unattachedParticipants = MatchGroupInputUtil.parseParticipants( + return MatchGroupInputUtil.parseMapPlayers( opponent.match2players, players, function(playerIndex) @@ -180,10 +151,6 @@ function MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) } end ) - Array.forEach(unattachedParticipants, function(participant) - table.insert(participants, participant) - end) - return participants end return CustomMatchGroupInput From b809f131fc7f8dd057468504a84dfd04729e8310 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 14:03:17 +0100 Subject: [PATCH 05/22] clashroyale --- .../clashroyale/match_group_input_custom.lua | 74 ++----------------- 1 file changed, 8 insertions(+), 66 deletions(-) diff --git a/components/match2/wikis/clashroyale/match_group_input_custom.lua b/components/match2/wikis/clashroyale/match_group_input_custom.lua index d9e1287a397..69ee764549d 100644 --- a/components/match2/wikis/clashroyale/match_group_input_custom.lua +++ b/components/match2/wikis/clashroyale/match_group_input_custom.lua @@ -23,7 +23,10 @@ local Opponent = OpponentLibraries.Opponent local CustomMatchGroupInput = {} local MatchFunctions = {} -local MapFunctions = {} +local MapFunctions = { + ADD_SUB_GROUP = true, + BREAK_ON_EMPTY = true, +} MatchFunctions.DEFAULT_MODE = 'solo' MatchFunctions.OPPONENT_CONFIG = { @@ -42,24 +45,7 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - local subGroup = 0 - for mapKey, mapInput, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if Table.isEmpty(mapInput) then - break - end - local map - map, subGroup = MapFunctions.readMap(mapInput, mapIndex, subGroup, opponents) - - map.extradata = MapFunctions.getExtraData(mapInput, map.opponents) - - map.vod = Logic.emptyOr(mapInput.vod, match['vodgame' .. mapIndex]) - - table.insert(maps, map) - match[mapKey] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end ---@param maps table[] @@ -102,41 +88,6 @@ function MatchFunctions.getExtraData(match, games, opponents) return extradata end ----@param mapInput table ----@param mapIndex integer ----@param subGroup integer ----@param opponents table[] ----@return table ----@return integer -function MapFunctions.readMap(mapInput, mapIndex, subGroup, opponents) - subGroup = tonumber(mapInput.subgroup) or (subGroup + 1) - - local map = { - subgroup = subGroup, - } - - map.finished = MatchGroupInputUtil.mapIsFinished(mapInput) - map.opponents = Array.map(opponents, function(opponent, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = mapInput.walkover, - winner = mapInput.winner, - opponentIndex = opponentIndex, - score = mapInput['score' .. opponentIndex], - }, MapFunctions.calculateMapScore(mapInput, map.finished)) - local players = MapFunctions.getPlayersOfMapOpponent(mapInput, opponent, opponentIndex) - return {score = score, status = status, players = players} - end) - - map.scores = Array.map(map.opponents, Operator.property('score')) - - if map.finished then - map.status = MatchGroupInputUtil.getMatchStatus(mapInput.winner, mapInput.finished) - map.winner = MatchGroupInputUtil.getWinner(map.status, mapInput.winner, map.opponents) - end - - return map, subGroup -end - ---@param mapInput table ---@param finished boolean ---@return fun(opponentIndex: integer): integer? @@ -174,7 +125,7 @@ function MapFunctions.getTeamParticipants(mapInput, opponent, opponentIndex) return Logic.nilIfEmpty(mapInput['t' .. opponentIndex .. 'p' .. playerIndex]) end) - local participants, unattachedParticipants = MatchGroupInputUtil.parseParticipants( + return MatchGroupInputUtil.parseMapPlayers( opponent.match2players, players, function(playerIndex) @@ -193,16 +144,6 @@ function MapFunctions.getTeamParticipants(mapInput, opponent, opponentIndex) } end ) - - Array.forEach(unattachedParticipants, function(participant) - table.insert(opponent.match2players, { - name = participant.player, - displayname = participant.player, - }) - participants[#opponent.match2players] = participant - end) - - return participants end ---@param mapInput table @@ -223,10 +164,11 @@ function MapFunctions.getPartyParticipants(mapInput, opponent, opponentIndex) end) end +---@param match table ---@param mapInput table ---@param mapOpponents {players: {player: string, played: boolean, cards: table}[]}[] ---@return table -function MapFunctions.getExtraData(mapInput, mapOpponents) +function MapFunctions.getExtraData(match, mapInput, mapOpponents) local extradata = { comment = mapInput.comment, } From b673b962f038d501af582c52d8a0b355b92e5eeb Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 14:05:21 +0100 Subject: [PATCH 06/22] fighters --- .../wikis/fighters/match_group_input_custom.lua | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/components/match2/wikis/fighters/match_group_input_custom.lua b/components/match2/wikis/fighters/match_group_input_custom.lua index 00af203a24e..671d9dc656a 100644 --- a/components/match2/wikis/fighters/match_group_input_custom.lua +++ b/components/match2/wikis/fighters/match_group_input_custom.lua @@ -79,11 +79,10 @@ function MapFunctions._processPlayerMapData(map, opponent, opponentIndex) local CharacterStandardizationData = mw.loadData('Module:CharacterStandardization/' .. game) local players = Array.mapIndexes(function(playerIndex) - return opponent.match2players[playerIndex] or - (map['t' .. opponentIndex .. 'p' .. playerIndex] and {}) or - nil + return map['t' .. opponentIndex .. 'p' .. playerIndex] or map['o' .. opponentIndex .. 'p' .. playerIndex] end) - local participants, unattachedParticipants = MatchGroupInputUtil.parseParticipants( + + return MatchGroupInputUtil.parseMapPlayers( opponent.match2players, players, function(playerIndex) @@ -105,10 +104,6 @@ function MapFunctions._processPlayerMapData(map, opponent, opponentIndex) } end ) - Array.forEach(unattachedParticipants, function(participant) - table.insert(participants, participant) - end) - return participants end ---@param map table From fb0dcb2f072ab8d3e6a7aead0eb4fb8278c4f6bf Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 14:08:42 +0100 Subject: [PATCH 07/22] goals --- .../wikis/goals/match_group_input_custom.lua | 39 +++---------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/components/match2/wikis/goals/match_group_input_custom.lua b/components/match2/wikis/goals/match_group_input_custom.lua index 2413dd6f282..a825881aedb 100644 --- a/components/match2/wikis/goals/match_group_input_custom.lua +++ b/components/match2/wikis/goals/match_group_input_custom.lua @@ -6,10 +6,7 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- -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 +14,10 @@ local CustomMatchGroupInput = {} CustomMatchGroupInput.DEFAULT_MODE = 'solo' CustomMatchGroupInput.getBestOf = MatchGroupInputUtil.getBestOf +local MapFunctions = { + BREAK_ON_EMPTY = true, +} + -- called from Module:MatchGroup ---@param match table ---@param options table? @@ -29,38 +30,10 @@ end ---@param opponents table[] ---@return table[] function CustomMatchGroupInput.extractMaps(match, opponents) - local maps = {} - for mapKey, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if Table.isEmpty(map) then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.finished = MatchGroupInputUtil.mapIsFinished(map) - map.opponents = 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(map.opponents, Operator.property('score')) - if map.finished then - map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput) - map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents) - end - - table.insert(maps, map) - match[mapKey] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end +---@param maps table[] ---@return fun(opponentIndex: integer): integer function CustomMatchGroupInput.calculateMatchScore(maps) return function(opponentIndex) From a6b73919a02a2ef2e2793450bd323ea30a638cac Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 14:12:26 +0100 Subject: [PATCH 08/22] omegastrikers --- .../match_group_input_custom.lua | 59 ++++--------------- 1 file changed, 12 insertions(+), 47 deletions(-) diff --git a/components/match2/wikis/omegastrikers/match_group_input_custom.lua b/components/match2/wikis/omegastrikers/match_group_input_custom.lua index fb12d4b149a..398b18a9027 100644 --- a/components/match2/wikis/omegastrikers/match_group_input_custom.lua +++ b/components/match2/wikis/omegastrikers/match_group_input_custom.lua @@ -19,7 +19,9 @@ local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') local CustomMatchGroupInput = {} local MatchFunctions = {} -local MapFunctions = {} +local MapFunctions = { + BREAK_ON_EMPTY = true, +} local DEFAULT_BESTOF_MATCH = 5 local DEFAULT_BESTOF_MAP = 3 @@ -36,41 +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 - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.bestof = MapFunctions.getBestOf(map) - map.extradata = MapFunctions.getExtraData(map, #opponents) - - map.opponents = Array.map(opponents, function(opponent, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - local players = MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) - return {score = score, status = status, players = players} - end) - - map.finished = MatchGroupInputUtil.mapIsFinished(map, map.opponents) - - map.scores = Array.map(map.opponents, Operator.property('score')) - if map.finished then - map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput) - map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end -- @@ -99,16 +67,17 @@ end ---@param map table ---@return integer -function MapFunctions.getBestOf(map) +function MapFunctions.getMapBestOf(map) local bestof = tonumber(Logic.emptyOr(map.bestof, Variables.varDefault('map_bestof'))) Variables.varDefine('map_bestof', bestof) return bestof or DEFAULT_BESTOF_MAP 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) local extradata = { bestof = map.bestof, comment = map.comment, @@ -116,13 +85,13 @@ function MapFunctions.getExtraData(map, opponentCount) local bans = {} local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, StrikerNames) - for opponentIndex = 1, opponentCount do + Array.forEach(opponents, function(_, opponentIndex) bans['team' .. opponentIndex] = {} for _, ban in Table.iter.pairsByPrefix(map, 't' .. opponentIndex .. 'b') do ban = getCharacterName(ban) table.insert(bans['team' .. opponentIndex], ban) end - end + end) extradata.bans = bans @@ -136,9 +105,9 @@ end function MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, StrikerNames) local players = Array.mapIndexes(function(playerIndex) - return opponent.match2players[playerIndex] or Logic.nilIfEmpty(map['t' .. opponentIndex .. 'c' .. playerIndex]) + return map['t' .. opponentIndex .. 'p' .. playerIndex] or map['t' .. opponentIndex .. 'c' .. playerIndex] end) - local participants, unattachedParticipants = MatchGroupInputUtil.parseParticipants( + return MatchGroupInputUtil.parseMapPlayers( opponent.match2players, players, function(playerIndex) @@ -153,10 +122,6 @@ function MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) } end ) - Array.forEach(unattachedParticipants, function(participant) - table.insert(participants, participant) - end) - return participants end return CustomMatchGroupInput From 0baef631cffd0a966b0e79a1e75905299572556a Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 14:15:16 +0100 Subject: [PATCH 09/22] linter: unused requires --- components/match2/wikis/brawlstars/match_group_input_custom.lua | 1 - .../match2/wikis/clashofclans/match_group_input_custom.lua | 1 - components/match2/wikis/clashroyale/match_group_input_custom.lua | 1 - .../match2/wikis/omegastrikers/match_group_input_custom.lua | 1 - 4 files changed, 4 deletions(-) diff --git a/components/match2/wikis/brawlstars/match_group_input_custom.lua b/components/match2/wikis/brawlstars/match_group_input_custom.lua index 680e73ce142..ac79ae9ace4 100644 --- a/components/match2/wikis/brawlstars/match_group_input_custom.lua +++ b/components/match2/wikis/brawlstars/match_group_input_custom.lua @@ -11,7 +11,6 @@ local BrawlerNames = mw.loadData('Module:BrawlerNames') 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') diff --git a/components/match2/wikis/clashofclans/match_group_input_custom.lua b/components/match2/wikis/clashofclans/match_group_input_custom.lua index d84a8ce3058..b606f4eb75d 100644 --- a/components/match2/wikis/clashofclans/match_group_input_custom.lua +++ b/components/match2/wikis/clashofclans/match_group_input_custom.lua @@ -9,7 +9,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') local MathUtil = require('Module:MathUtil') -local Operator = require('Module:Operator') local Table = require('Module:Table') local Variables = require('Module:Variables') diff --git a/components/match2/wikis/clashroyale/match_group_input_custom.lua b/components/match2/wikis/clashroyale/match_group_input_custom.lua index 69ee764549d..d4983badcdf 100644 --- a/components/match2/wikis/clashroyale/match_group_input_custom.lua +++ b/components/match2/wikis/clashroyale/match_group_input_custom.lua @@ -12,7 +12,6 @@ local FnUtil = require('Module:FnUtil') local Json = require('Module:Json') 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') diff --git a/components/match2/wikis/omegastrikers/match_group_input_custom.lua b/components/match2/wikis/omegastrikers/match_group_input_custom.lua index 398b18a9027..511f39f4f18 100644 --- a/components/match2/wikis/omegastrikers/match_group_input_custom.lua +++ b/components/match2/wikis/omegastrikers/match_group_input_custom.lua @@ -10,7 +10,6 @@ local Array = require('Module:Array') 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 StrikerNames = mw.loadData('Module:StrikerNames') From 185d7c338967b9bbd7e71a9fc43f84bc6d71250d Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 14:27:16 +0100 Subject: [PATCH 10/22] getMapName: pass along mapIndex and match (prep for easportsfc) --- components/match2/commons/match_group_input_util.lua | 6 +++--- .../starcraft_starcraft2/match_group_input_starcraft.lua | 4 +++- .../match2/wikis/brawlhalla/match_group_input_custom.lua | 4 +++- .../match2/wikis/clashofclans/match_group_input_custom.lua | 4 +++- .../match2/wikis/deadlock/match_group_input_custom.lua | 4 +++- .../match2/wikis/honorofkings/match_group_input_custom.lua | 4 +++- components/match2/wikis/magic/match_group_input_custom.lua | 4 +++- .../match2/wikis/stormgate/match_group_input_custom.lua | 4 +++- .../match2/wikis/warcraft/match_group_input_custom.lua | 4 +++- 9 files changed, 27 insertions(+), 11 deletions(-) diff --git a/components/match2/commons/match_group_input_util.lua b/components/match2/commons/match_group_input_util.lua index 4edffe3b028..cd80aca04d9 100644 --- a/components/match2/commons/match_group_input_util.lua +++ b/components/match2/commons/match_group_input_util.lua @@ -1159,7 +1159,7 @@ end ---@class MapParserInterface ---@field calculateMapScore? fun(map: table): fun(opponentIndex: integer): integer? ---@field getExtraData? fun(match: table, game: table, opponents: table[]): table? ----@field getMapName? fun(game: table): string? +---@field getMapName? fun(game: table, mapIndex: integer, match: table): string? ---@field getMapMode? fun(match: table, game: table, opponents: table[]): string? ---@field getPlayersOfMapOpponent? fun(game: table, opponent:table, opponentIndex: integer): table[] ---@field getPatch? fun(game: table): string? @@ -1190,7 +1190,7 @@ end function MatchGroupInputUtil.standardProcessMaps(match, opponents, Parser) local maps = {} local subGroup = 0 - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do + for key, map, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do if Parser.BREAK_ON_EMPTY and Logic.isEmpty(map) then break end @@ -1203,7 +1203,7 @@ function MatchGroupInputUtil.standardProcessMaps(match, opponents, Parser) end if Parser.getMapName then - map.map = Parser.getMapName(map) + map.map = Parser.getMapName(map, mapIndex, match) end if Parser.mapIsFinished then diff --git a/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft.lua b/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft.lua index 52a1e2696b9..525466a0fb7 100644 --- a/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft.lua +++ b/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft.lua @@ -417,8 +417,10 @@ function MapFunctions.isArchon(mapInput, opponent, opponentIndex) end ---@param game table +---@param gameIndex table +---@param match table ---@return string? -function MapFunctions.getMapName(game) +function MapFunctions.getMapName(game, gameIndex, match) local mapName = game.map if mapName and mapName:upper() ~= TBD then return mw.ext.TeamLiquidIntegration.resolve_redirect(game.map) diff --git a/components/match2/wikis/brawlhalla/match_group_input_custom.lua b/components/match2/wikis/brawlhalla/match_group_input_custom.lua index 80b7fb706ea..7bad9eedd21 100644 --- a/components/match2/wikis/brawlhalla/match_group_input_custom.lua +++ b/components/match2/wikis/brawlhalla/match_group_input_custom.lua @@ -94,8 +94,10 @@ function MapFunctions.calculateMapScore(map) end ---@param map table +---@param mapIndex integer +---@param match table ---@return string? -function MapFunctions.getMapName(map) +function MapFunctions.getMapName(map, mapIndex, match) if String.isNotEmpty(map.map) and map.map ~= 'TBD' then return mw.ext.TeamLiquidIntegration.resolve_redirect(map.map) end diff --git a/components/match2/wikis/clashofclans/match_group_input_custom.lua b/components/match2/wikis/clashofclans/match_group_input_custom.lua index b606f4eb75d..05a2a7e9d36 100644 --- a/components/match2/wikis/clashofclans/match_group_input_custom.lua +++ b/components/match2/wikis/clashofclans/match_group_input_custom.lua @@ -79,8 +79,10 @@ end -- map related functions -- ---@param map table +---@param mapIndex integer +---@param match table ---@return string? -function MapFunctions.getMapName(map) +function MapFunctions.getMapName(map, mapIndex, match) return nil end diff --git a/components/match2/wikis/deadlock/match_group_input_custom.lua b/components/match2/wikis/deadlock/match_group_input_custom.lua index 6f6248cfd2b..0a68ee6a389 100644 --- a/components/match2/wikis/deadlock/match_group_input_custom.lua +++ b/components/match2/wikis/deadlock/match_group_input_custom.lua @@ -55,8 +55,10 @@ function MatchFunctions.getExtraData(match) end ---@param map table +---@param mapIndex table +---@param match table ---@return string? -function MapFunctions.getMapName(map) +function MapFunctions.getMapName(map, mapIndex, match) return nil end diff --git a/components/match2/wikis/honorofkings/match_group_input_custom.lua b/components/match2/wikis/honorofkings/match_group_input_custom.lua index 83311a6fbfa..f18265845d3 100644 --- a/components/match2/wikis/honorofkings/match_group_input_custom.lua +++ b/components/match2/wikis/honorofkings/match_group_input_custom.lua @@ -82,8 +82,10 @@ end -- ---@param map table +---@param mapIndex integer +---@param match table ---@return string? -function MapFunctions.getMapName(map) +function MapFunctions.getMapName(map, mapIndex, match) if map.map == DUMMY_MAP then return nil end diff --git a/components/match2/wikis/magic/match_group_input_custom.lua b/components/match2/wikis/magic/match_group_input_custom.lua index e6ffea2efcc..5647101df52 100644 --- a/components/match2/wikis/magic/match_group_input_custom.lua +++ b/components/match2/wikis/magic/match_group_input_custom.lua @@ -94,8 +94,10 @@ function MapFunctions.calculateMapScore(winnerInput, finished) end ---@param map table +---@param mapIndex integer +---@param match table ---@return string? -function MapFunctions.getMapName(map) +function MapFunctions.getMapName(map, mapIndex, match) return nil end diff --git a/components/match2/wikis/stormgate/match_group_input_custom.lua b/components/match2/wikis/stormgate/match_group_input_custom.lua index bbcfbdda383..22472662710 100644 --- a/components/match2/wikis/stormgate/match_group_input_custom.lua +++ b/components/match2/wikis/stormgate/match_group_input_custom.lua @@ -158,8 +158,10 @@ function MatchFunctions.getExtraData(match, games, opponents) end ---@param game table +---@param gameIndex integer +---@param match table ---@return string? -function MapFunctions.getMapName(game) +function MapFunctions.getMapName(game, gameIndex, match) local mapName = game.map if mapName and mapName:upper() ~= TBD then return mw.ext.TeamLiquidIntegration.resolve_redirect(game.map) diff --git a/components/match2/wikis/warcraft/match_group_input_custom.lua b/components/match2/wikis/warcraft/match_group_input_custom.lua index 4419f8c8a24..a52b86bfa0c 100644 --- a/components/match2/wikis/warcraft/match_group_input_custom.lua +++ b/components/match2/wikis/warcraft/match_group_input_custom.lua @@ -192,8 +192,10 @@ function MatchFunctions.getHeadToHeadLink(match, opponents) end ---@param game table +---@param gameIndex integer +---@param match table ---@return string? -function MapFunctions.getMapName(game) +function MapFunctions.getMapName(game, gameIndex, match) return (MapsData[(game.map or ''):lower()] or {}).name or game.map end From 0d18aaaea64842848194ef9987780bd7ddecf6d3 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 14:32:19 +0100 Subject: [PATCH 11/22] easportsfc --- .../easportsfc/match_group_input_custom.lua | 99 ++++++++----------- 1 file changed, 41 insertions(+), 58 deletions(-) diff --git a/components/match2/wikis/easportsfc/match_group_input_custom.lua b/components/match2/wikis/easportsfc/match_group_input_custom.lua index 53e6e081843..917ed46133b 100644 --- a/components/match2/wikis/easportsfc/match_group_input_custom.lua +++ b/components/match2/wikis/easportsfc/match_group_input_custom.lua @@ -11,7 +11,6 @@ local Logic = require('Module:Logic') local Lua = require('Module:Lua') local Ordinal = require('Module:Ordinal') local Operator = require('Module:Operator') -local Table = require('Module:Table') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') local OpponentLibraries = Lua.import('Module:OpponentLibraries') @@ -20,6 +19,10 @@ local Opponent = OpponentLibraries.Opponent local CustomMatchGroupInput = {} CustomMatchGroupInput.DEFAULT_MODE = 'solo' +local MapFunctions = { + BREAK_ON_EMPTY = true, +} + ---@param match table ---@param options table? ---@return table @@ -54,49 +57,7 @@ end ---@param opponents table[] ---@return table[] function CustomMatchGroupInput.extractMaps(match, opponents) - local maps = {} - for mapKey, map, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if Table.isEmpty(map) then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - if Logic.readBool(match.hasSubmatches) then - -- generic map name (not displayed) - map.map = 'Game ' .. mapIndex - elseif Logic.readBool(map.penalty) then - map.map = 'Penalties' - else - map.map = mapIndex .. Ordinal.suffix(mapIndex) .. ' Leg' - end - - map.mode = Opponent.toMode(opponents[1].type, opponents[2].type) - map.extradata = CustomMatchGroupInput.getMapExtraData(map, opponents, Logic.readBool(match.hasSubmatches)) - - map.finished = MatchGroupInputUtil.mapIsFinished(map) - map.opponents = Array.map(opponents, function(opponent, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - local players = CustomMatchGroupInput.getPlayersOfMapOpponent(map, opponent, opponentIndex) - return {score = score, status = status, players = players} - end) - - map.scores = Array.map(map.opponents, Operator.property('score')) - if map.finished then - map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput) - map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents) - end - - table.insert(maps, map) - match[mapKey] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end ---@param bestOfInput string? @@ -129,17 +90,6 @@ function CustomMatchGroupInput.getExtraData(match, maps) } end ----@param map table ----@param opponents table[] ----@param hasSubmatches boolean ----@return table -function CustomMatchGroupInput.getMapExtraData(map, opponents, hasSubmatches) - return { - comment = map.comment, - penaltyscores = CustomMatchGroupInput._submatchPenaltyScores(map, opponents, hasSubmatches), - } -end - ---@param map table ---@param opponents table[] ---@param hasSubmatches boolean @@ -163,11 +113,11 @@ end ---@param opponent table ---@param opponentIndex integer ---@return table[] -function CustomMatchGroupInput.getPlayersOfMapOpponent(map, opponent, opponentIndex) +function MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) local players = Array.mapIndexes(function(playerIndex) return map['t' .. opponentIndex .. 'p' .. playerIndex] end) - local participants, _ = MatchGroupInputUtil.parseParticipants( + return MatchGroupInputUtil.parseMapPlayers( opponent.match2players, players, function(playerIndex) @@ -180,7 +130,40 @@ function CustomMatchGroupInput.getPlayersOfMapOpponent(map, opponent, opponentIn } end ) - return participants +end + +---@param map table +---@param mapIndex integer +---@param match table +---@return string +function MapFunctions.getMapName(map, mapIndex, match) + if Logic.readBool(match.hasSubmatches) then + -- generic map name (not displayed) + return 'Game ' .. mapIndex + elseif Logic.readBool(map.penalty) then + return 'Penalties' + else + return mapIndex .. Ordinal.suffix(mapIndex) .. ' Leg' + end +end + +---@param match table +---@param map table +---@param opponents table[] +---@return string +function MapFunctions.getMapMode(match, map, opponents) + return Opponent.toMode(opponents[1].type, opponents[2].type) +end + +---@param match table +---@param map table +---@param opponents table[] +---@return table +function MapFunctions.getExtraData(match, map, opponents) + return { + comment = map.comment, + penaltyscores = CustomMatchGroupInput._submatchPenaltyScores(map, opponents, Logic.readBool(match.hasSubmatches)), + } end return CustomMatchGroupInput From 19141385ae477d0a061de85eff6d01fd52a77d78 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 14:52:02 +0100 Subject: [PATCH 12/22] osu (+ commons adjust for it) --- .../match2/commons/match_group_input_util.lua | 7 ++- .../wikis/osu/match_group_input_custom.lua | 60 +++++++------------ 2 files changed, 27 insertions(+), 40 deletions(-) diff --git a/components/match2/commons/match_group_input_util.lua b/components/match2/commons/match_group_input_util.lua index cd80aca04d9..ad779c3be97 100644 --- a/components/match2/commons/match_group_input_util.lua +++ b/components/match2/commons/match_group_input_util.lua @@ -1166,6 +1166,7 @@ end ---@field mapIsFinished? fun(map: table, opponents: table[], finishedInput: string?, winnerInput: string?): boolean ---@field extendMapOpponent? fun(map: table, opponentIndex: integer): table ---@field getMapBestOf? fun(map: table): integer? +---@field computeOpponentScore? fun(props: table, autoScore?: fun(opponentIndex: integer):integer?): integer?, string? ---@field ADD_SUB_GROUP? boolean ---@field BREAK_ON_EMPTY? boolean @@ -1179,6 +1180,9 @@ end --- - getPlayersOfMapOpponent(map, opponent, opponentIndex): table[]? --- - getPatch(game): string? --- - mapIsFinished(map, opponents): boolean +--- - extendMapOpponent(map, opponentIndex): table +--- - getMapBestOf(map): integer? +--- - computeOpponentScore(props, autoScore): integer?, string? --- --- Additionally, the Parser may have the following properties: --- - ADD_SUB_GROUP boolean? @@ -1221,7 +1225,8 @@ function MatchGroupInputUtil.standardProcessMaps(match, opponents, Parser) end map.opponents = Array.map(opponents, function(opponent, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ + local computeOpponentScore = Parser.computeOpponentScore or MatchGroupInputUtil.computeOpponentScore + local score, status = computeOpponentScore({ walkover = map.walkover, winner = map.winner, opponentIndex = opponentIndex, diff --git a/components/match2/wikis/osu/match_group_input_custom.lua b/components/match2/wikis/osu/match_group_input_custom.lua index eb8843b5276..297faad01bb 100644 --- a/components/match2/wikis/osu/match_group_input_custom.lua +++ b/components/match2/wikis/osu/match_group_input_custom.lua @@ -16,7 +16,9 @@ local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') local CustomMatchGroupInput = {} local MatchFunctions = {} -local MapFunctions = {} +local MapFunctions = { + BREAK_ON_EMPTY = true, +} local ALLOWED_VETOES = Array.append(MatchGroupInputUtil.DEFAULT_ALLOWED_VETOES, 'protect') local DEFAULT_BESTOF = 3 @@ -37,43 +39,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 - 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) - - map.opponents = 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} - end - local scoreInput = string.gsub(map['score' .. opponentIndex] or '', ',', '') - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = scoreInput, - }) - return {score = score, status = status} - end) - - map.scores = Array.map(map.opponents, Operator.property('score')) - if map.finished then - map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput) - map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end ---@param bestofInput string|integer? @@ -113,12 +79,28 @@ 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, } end +---@param props {walkover: string|integer?, winner: string|integer?, score: string|integer?, opponentIndex: integer} +---@param autoScore? fun(opponentIndex: integer): integer? +---@return integer|string? #SCORE +---@return string? #STATUS +function MapFunctions.computeOpponentScore(props, autoScore) + local percentageScore = (props.score or ''):match('(%d+)%%') + if percentageScore then + return props.score, MatchGroupInputUtil.STATUS.SCORE + end + + props.score = string.gsub(props.score or '', ',', '') + + return MatchGroupInputUtil.computeOpponentScore(props) +end return CustomMatchGroupInput From f28766c5f3b79d87ad0527b553cac5a60c7be1bd Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 14:53:30 +0100 Subject: [PATCH 13/22] linter: unused import --- components/match2/wikis/osu/match_group_input_custom.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/match2/wikis/osu/match_group_input_custom.lua b/components/match2/wikis/osu/match_group_input_custom.lua index 297faad01bb..d0aadc3461e 100644 --- a/components/match2/wikis/osu/match_group_input_custom.lua +++ b/components/match2/wikis/osu/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') From 8c560f1fc757838ba607c4bc06773972b35c7102 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 14:59:21 +0100 Subject: [PATCH 14/22] overwatch --- .../overwatch/match_group_input_custom.lua | 58 +++++++------------ 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/components/match2/wikis/overwatch/match_group_input_custom.lua b/components/match2/wikis/overwatch/match_group_input_custom.lua index ae82b6650e1..0ab671a7074 100644 --- a/components/match2/wikis/overwatch/match_group_input_custom.lua +++ b/components/match2/wikis/overwatch/match_group_input_custom.lua @@ -17,7 +17,9 @@ local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') local CustomMatchGroupInput = {} local MatchFunctions = {} -local MapFunctions = {} +local MapFunctions = { + BREAK_ON_EMPTY = true, +} local DEFAULT_BESTOF = 3 MatchFunctions.DEFAULT_MODE = 'team' @@ -33,42 +35,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 - if map.map == nil 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) - - map.opponents = Array.map(opponents, function(_, opponentIndex) - local scoreInput = map['score' .. opponentIndex] - if map.mode == 'Push' and scoreInput then - scoreInput = scoreInput:gsub('m', '') - end - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = scoreInput, - }) - return {score = score, status = status} - end) - - map.scores = Array.map(map.opponents, Operator.property('score')) - if map.finished then - map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput) - map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end -- @@ -106,12 +73,27 @@ 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, } end +---@param props {walkover: string|integer?, winner: string|integer?, score: string|integer?, opponentIndex: integer} +---@param autoScore? fun(opponentIndex: integer): integer? +---@return integer? #SCORE +---@return string? #STATUS +function MapFunctions.computeOpponentScore(props, autoScore) + if props.score then + props.score = props.score:gsub('m', '') + end + + return MatchGroupInputUtil.computeOpponentScore(props) +end + + return CustomMatchGroupInput From 337cd61eb3d778f53ea6422232cca35d1b8363ba Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 15:11:21 +0100 Subject: [PATCH 15/22] tetris --- .../wikis/tetris/match_group_input_custom.lua | 58 ++++++------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/components/match2/wikis/tetris/match_group_input_custom.lua b/components/match2/wikis/tetris/match_group_input_custom.lua index 2e1aff6f484..cb55ac9aee5 100644 --- a/components/match2/wikis/tetris/match_group_input_custom.lua +++ b/components/match2/wikis/tetris/match_group_input_custom.lua @@ -19,7 +19,9 @@ local OpponentLibrary = require('Module:OpponentLibraries') local Opponent = OpponentLibrary.Opponent local CustomMatchGroupInput = {} -local MapFunctions = {} +local MapFunctions = { + BREAK_ON_EMPTY = true, +} local DEFAULT_BESTOF = 99 CustomMatchGroupInput.OPPONENT_CONFIG = { @@ -46,40 +48,7 @@ end ---@param opponents table[] ---@return table[] function CustomMatchGroupInput.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if Table.isEmpty(map) then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(match, map, opponents) - map.map = CustomMatchGroupInput.getMapName(map) - map.mode = Opponent.toMode(opponents[1].type, opponents[2].type) - - map.finished = MatchGroupInputUtil.mapIsFinished(map) - map.opponents = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }, CustomMatchGroupInput.calculateMapScore(map.winner, map.finished)) - return {score = score, status = status} - end) - - map.scores = Array.map(map.opponents, Operator.property('score')) - if map.finished then - map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput) - map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end ---@param maps table[] @@ -112,14 +81,13 @@ function CustomMatchGroupInput._hasTeamOpponent(match) return match.opponent1.type == Opponent.team or match.opponent2.type == Opponent.team end ----@param winnerInput string|integer|nil ----@param finished boolean +---@param map table ---@return fun(opponentIndex: integer): integer? -function CustomMatchGroupInput.calculateMapScore(winnerInput, finished) - local winner = tonumber(winnerInput) +function MapFunctions.calculateMapScore(map) + local winner = tonumber(map.winner) return function(opponentIndex) -- TODO Better to check if map has started, rather than finished, for a more correct handling - if not winner and not finished then + if not winner and not map.finished then return end return winner == opponentIndex and 1 or 0 @@ -128,7 +96,7 @@ end ---@param map table ---@return string? -function CustomMatchGroupInput.getMapName(map) +function MapFunctions.getMapName(map) return nil end @@ -142,4 +110,12 @@ function MapFunctions.getExtraData(match, map, opponents) } end +---@param match table +---@param map table +---@param opponents table[] +---@return string? +function MapFunctions.getMapMode(match, map, opponents) + return Opponent.toMode(opponents[1].type, opponents[2].type) +end + return CustomMatchGroupInput From 964446a4305eb4098da97b4cb038ae5fcf5ea094 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 15:15:43 +0100 Subject: [PATCH 16/22] valorant --- .../valorant/match_group_input_custom.lua | 38 +++---------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/components/match2/wikis/valorant/match_group_input_custom.lua b/components/match2/wikis/valorant/match_group_input_custom.lua index 764518eab4a..5afa5f8995c 100644 --- a/components/match2/wikis/valorant/match_group_input_custom.lua +++ b/components/match2/wikis/valorant/match_group_input_custom.lua @@ -37,36 +37,7 @@ end ---@param opponents MGIParsedOpponent[] ---@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.finished = MatchGroupInputUtil.mapIsFinished(map) - - map.opponents = Array.map(opponents, function(opponent, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }, MapFunctions.calculateMapScore(map)) - local players = MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) - return {score = score, status = status, players = players} - end) - - map.scores = Array.map(map.opponents, Operator.property('score')) - if map.finished then - map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput) - map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents) - end - - map.extradata = MapFunctions.getExtraData(map, map.opponents) - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end MatchFunctions.getBestOf = MatchGroupInputUtil.getBestOf @@ -109,10 +80,11 @@ function MapFunctions.keepMap(map) return map.map ~= nil end +---@param match table ---@param map table ----@param participants {players: {player: string?, agent: string?}[]}[] +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map, participants) +function MapFunctions.getExtraData(match, map, opponents) ---@type table local extraData = { comment = map.comment, @@ -121,7 +93,7 @@ function MapFunctions.getExtraData(map, participants) t2halfs = {atk = map.t2atk, def = map.t2def, otatk = map.t2otatk, otdef = map.t2otdef}, } - for opponentIdx, opponent in ipairs(participants) do + for opponentIdx, opponent in ipairs(map.opponents) do for playerIdx, player in pairs(opponent.players) do extraData['t' .. opponentIdx .. 'p' .. playerIdx] = player.player extraData['t' .. opponentIdx .. 'p' .. playerIdx .. 'agent'] = player.agent From 6bac19060fccb243ff5ce75ede483be04fc240ec Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 15:19:12 +0100 Subject: [PATCH 17/22] smite --- .../match2/commons/match_group_input_util.lua | 2 +- .../wikis/smite/match_group_input_custom.lua | 61 ++++--------------- 2 files changed, 12 insertions(+), 51 deletions(-) diff --git a/components/match2/commons/match_group_input_util.lua b/components/match2/commons/match_group_input_util.lua index ad779c3be97..5072c64e13b 100644 --- a/components/match2/commons/match_group_input_util.lua +++ b/components/match2/commons/match_group_input_util.lua @@ -1195,7 +1195,7 @@ function MatchGroupInputUtil.standardProcessMaps(match, opponents, Parser) local maps = {} local subGroup = 0 for key, map, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if Parser.BREAK_ON_EMPTY and Logic.isEmpty(map) then + if Parser.BREAK_ON_EMPTY and Logic.isDeepEmpty(map) then break end local finishedInput = map.finished --[[@as string?]] diff --git a/components/match2/wikis/smite/match_group_input_custom.lua b/components/match2/wikis/smite/match_group_input_custom.lua index c5bdf741777..38b946f5b00 100644 --- a/components/match2/wikis/smite/match_group_input_custom.lua +++ b/components/match2/wikis/smite/match_group_input_custom.lua @@ -19,7 +19,9 @@ local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') local CustomMatchGroupInput = {} local MatchFunctions = {} -local MapFunctions = {} +local MapFunctions = { + BREAK_ON_EMPTY = true, +} local DEFAULT_BESTOF = 3 local MAX_NUM_PLAYERS = 15 @@ -46,14 +48,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 - table.insert(maps, MapFunctions.readMap(map, #opponents)) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end ---@param bestofInput string|integer? @@ -88,63 +83,29 @@ end -- -- map related functions -- - ---@param map table ----@param opponentCount integer ----@return table? -function MapFunctions.readMap(map, opponentCount) - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - if Logic.isDeepEmpty(map) then - return nil - end - - map.extradata = MapFunctions.getExtraData(map, opponentCount) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - map.opponents = 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.winner, map.finished)) - return {score = score, status = status} - end) - - map.scores = Array.map(map.opponents, Operator.property('score')) - if map.finished then - map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput) - map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents) - end - - return map -end - ----@param winnerInput string|integer|nil ----@param finished boolean ---@return fun(opponentIndex: integer): integer? -function MapFunctions.calculateMapScore(winnerInput, finished) - local winner = tonumber(winnerInput) +function MapFunctions.calculateMapScore(map) + local winner = tonumber(map.winner) return function(opponentIndex) -- TODO Better to check if map has started, rather than finished, for a more correct handling - if not winner and not finished then + if not winner and not map.finished then return end return winner == opponentIndex and 1 or 0 end 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 Table.merge({ comment = map.comment, team1side = string.lower(map.team1side or ''), team2side = string.lower(map.team2side or ''), - }, MapFunctions.getPicksAndBans(map, opponentCount)) + }, MapFunctions.getPicksAndBans(map, #opponents)) end ---@param map table From b232cc69f9dcff2323865a8ddb495a7d811e3c07 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 15:20:00 +0100 Subject: [PATCH 18/22] linter: unused requires --- .../match2/wikis/overwatch/match_group_input_custom.lua | 3 --- .../match2/wikis/splatoon/match_group_input_custom.lua | 9 +++------ .../match2/wikis/tetris/match_group_input_custom.lua | 3 --- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/components/match2/wikis/overwatch/match_group_input_custom.lua b/components/match2/wikis/overwatch/match_group_input_custom.lua index 0ab671a7074..6e8737a045f 100644 --- a/components/match2/wikis/overwatch/match_group_input_custom.lua +++ b/components/match2/wikis/overwatch/match_group_input_custom.lua @@ -6,11 +6,8 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- -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') diff --git a/components/match2/wikis/splatoon/match_group_input_custom.lua b/components/match2/wikis/splatoon/match_group_input_custom.lua index f9c9855423b..6405d559f59 100644 --- a/components/match2/wikis/splatoon/match_group_input_custom.lua +++ b/components/match2/wikis/splatoon/match_group_input_custom.lua @@ -32,6 +32,7 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) local maps = {} for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do local finishedInput = map.finished --[[@as string?]] @@ -112,9 +113,9 @@ end ---@return table[] function MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) local players = Array.mapIndexes(function(playerIndex) - return opponent.match2players[playerIndex] or Logic.nilIfEmpty(map['t' .. opponentIndex .. 'w' .. playerIndex]) + return map['t' .. opponentIndex .. 'w' .. playerIndex] or map['t' .. opponentIndex .. 'w' .. playerIndex] end) - local participants, unattachedParticipants = MatchGroupInputUtil.parseParticipants( + return MatchGroupInputUtil.parseMapPlayers( opponent.match2players, players, function(playerIndex) @@ -129,10 +130,6 @@ function MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) } end ) - Array.forEach(unattachedParticipants, function(participant) - table.insert(participants, participant) - end) - return participants end ---@param weaponRaw string diff --git a/components/match2/wikis/tetris/match_group_input_custom.lua b/components/match2/wikis/tetris/match_group_input_custom.lua index cb55ac9aee5..6ab201330bf 100644 --- a/components/match2/wikis/tetris/match_group_input_custom.lua +++ b/components/match2/wikis/tetris/match_group_input_custom.lua @@ -6,11 +6,8 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- -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') From f2fac48d98d0872bcadec1ce9560d1ce58fe6c06 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 15:23:46 +0100 Subject: [PATCH 19/22] splatoon --- .../wikis/osu/match_group_input_custom.lua | 1 + .../splatoon/match_group_input_custom.lua | 46 +++++-------------- 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/components/match2/wikis/osu/match_group_input_custom.lua b/components/match2/wikis/osu/match_group_input_custom.lua index d0aadc3461e..f67bdd3380f 100644 --- a/components/match2/wikis/osu/match_group_input_custom.lua +++ b/components/match2/wikis/osu/match_group_input_custom.lua @@ -86,6 +86,7 @@ function MapFunctions.getExtraData(match, map, opponents) comment = map.comment, } end + ---@param props {walkover: string|integer?, winner: string|integer?, score: string|integer?, opponentIndex: integer} ---@param autoScore? fun(opponentIndex: integer): integer? ---@return integer|string? #SCORE diff --git a/components/match2/wikis/splatoon/match_group_input_custom.lua b/components/match2/wikis/splatoon/match_group_input_custom.lua index 6405d559f59..8e79ba1cb6b 100644 --- a/components/match2/wikis/splatoon/match_group_input_custom.lua +++ b/components/match2/wikis/splatoon/match_group_input_custom.lua @@ -33,40 +33,6 @@ end ---@return table[] function MatchFunctions.extractMaps(match, opponents) return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) - 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(match, map, opponents) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(opponent, opponentIndex) - local scoreInput = map['score' .. opponentIndex] - if map.maptype == 'Turf War' and scoreInput then - scoreInput = scoreInput:gsub('%%', '') - end - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = scoreInput, - }, MapFunctions.calculateMapScore(map)) - local players = MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) - return {score = score, status = status, players = players} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput) - map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps end -- @@ -154,4 +120,16 @@ function MapFunctions.calculateMapScore(map) end end +---@param props {walkover: string|integer?, winner: string|integer?, score: string|integer?, opponentIndex: integer} +---@param autoScore? fun(opponentIndex: integer): integer? +---@return integer|string? #SCORE +---@return string? #STATUS +function MapFunctions.computeOpponentScore(props, autoScore) + if props.score then + props.score = props.score:gsub('%%', '') + end + + return MatchGroupInputUtil.computeOpponentScore(props, MapFunctions.calculateMapScore) +end + return CustomMatchGroupInput From 850ea833adf0f4d6f24a1a17dd281714dbaa117b Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sun, 15 Dec 2024 15:48:45 +0100 Subject: [PATCH 20/22] linter & small fixes --- .../match2/commons/match_group_input_util.lua | 8 ++++---- .../brawlstars/match_group_input_custom.lua | 7 ++++--- .../clashroyale/match_group_input_custom.lua | 19 +++++++++---------- .../wikis/magic/match_group_input_custom.lua | 9 ++++----- .../wikis/smite/match_group_input_custom.lua | 3 --- .../splatoon/match_group_input_custom.lua | 3 --- .../wikis/tetris/match_group_input_custom.lua | 4 +++- .../valorant/match_group_input_custom.lua | 2 -- 8 files changed, 24 insertions(+), 31 deletions(-) diff --git a/components/match2/commons/match_group_input_util.lua b/components/match2/commons/match_group_input_util.lua index 5072c64e13b..e8bb68d6e58 100644 --- a/components/match2/commons/match_group_input_util.lua +++ b/components/match2/commons/match_group_input_util.lua @@ -1210,6 +1210,10 @@ function MatchGroupInputUtil.standardProcessMaps(match, opponents, Parser) map.map = Parser.getMapName(map, mapIndex, match) end + if Parser.getMapBestOf then + map.bestof = Parser.getMapBestOf(map) + end + if Parser.mapIsFinished then map.finished = Parser.mapIsFinished(map, opponents, finishedInput, winnerInput) else @@ -1220,10 +1224,6 @@ function MatchGroupInputUtil.standardProcessMaps(match, opponents, Parser) map.patch = Parser.getPatch(map) end - if Parser.getMapBestOf then - map.bestof = Parser.getMapBestOf(map) - end - map.opponents = Array.map(opponents, function(opponent, opponentIndex) local computeOpponentScore = Parser.computeOpponentScore or MatchGroupInputUtil.computeOpponentScore local score, status = computeOpponentScore({ diff --git a/components/match2/wikis/brawlstars/match_group_input_custom.lua b/components/match2/wikis/brawlstars/match_group_input_custom.lua index ac79ae9ace4..b83407e0b84 100644 --- a/components/match2/wikis/brawlstars/match_group_input_custom.lua +++ b/components/match2/wikis/brawlstars/match_group_input_custom.lua @@ -100,10 +100,11 @@ function MapFunctions.getMapBestOf(map) return bestof or DEFAULT_BESTOF_MAP 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) local extradata = { bestof = map.bestof, comment = map.comment, @@ -113,7 +114,7 @@ function MapFunctions.getExtraData(map, opponentCount) local bans = {} local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, BrawlerNames) - for opponentIndex = 1, opponentCount do + for opponentIndex = 1, #opponents do bans['team' .. opponentIndex] = {} for _, ban in Table.iter.pairsByPrefix(map, 't' .. opponentIndex .. 'b') do ban = getCharacterName(ban) diff --git a/components/match2/wikis/clashroyale/match_group_input_custom.lua b/components/match2/wikis/clashroyale/match_group_input_custom.lua index d4983badcdf..8f08c45bde3 100644 --- a/components/match2/wikis/clashroyale/match_group_input_custom.lua +++ b/components/match2/wikis/clashroyale/match_group_input_custom.lua @@ -87,14 +87,13 @@ function MatchFunctions.getExtraData(match, games, opponents) return extradata end ----@param mapInput table ----@param finished boolean +---@param map table ---@return fun(opponentIndex: integer): integer? -function MapFunctions.calculateMapScore(mapInput, finished) - local winner = tonumber(mapInput.winner) +function MapFunctions.calculateMapScore(map) + local winner = tonumber(map.winner) return function(opponentIndex) -- TODO Better to check if map has started, rather than finished, for a more correct handling - if not winner and not finished then + if not winner and not map.finished then return end @@ -164,15 +163,15 @@ function MapFunctions.getPartyParticipants(mapInput, opponent, opponentIndex) end ---@param match table ----@param mapInput table ----@param mapOpponents {players: {player: string, played: boolean, cards: table}[]}[] +---@param map table +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(match, mapInput, mapOpponents) +function MapFunctions.getExtraData(match, map, opponents) local extradata = { - comment = mapInput.comment, + comment = map.comment, } - return Table.merge(extradata, MapFunctions.getCardsExtradata(mapOpponents)) + return Table.merge(extradata, MapFunctions.getCardsExtradata(map.opponents)) end --- additionally store cards info in extradata so we can condition on them diff --git a/components/match2/wikis/magic/match_group_input_custom.lua b/components/match2/wikis/magic/match_group_input_custom.lua index 5647101df52..db4d71b3352 100644 --- a/components/match2/wikis/magic/match_group_input_custom.lua +++ b/components/match2/wikis/magic/match_group_input_custom.lua @@ -79,14 +79,13 @@ function CustomMatchGroupInput._hasTeamOpponent(match) return match.opponent1.type == Opponent.team or match.opponent2.type == Opponent.team end ----@param winnerInput string|integer|nil ----@param finished boolean +---@param map table ---@return fun(opponentIndex: integer): integer? -function MapFunctions.calculateMapScore(winnerInput, finished) - local winner = tonumber(winnerInput) +function MapFunctions.calculateMapScore(map) + local winner = tonumber(map.winner) return function(opponentIndex) -- TODO Better to check if map has started, rather than finished, for a more correct handling - if not winner and not finished then + if not winner and not map.finished then return end return winner == opponentIndex and 1 or 0 diff --git a/components/match2/wikis/smite/match_group_input_custom.lua b/components/match2/wikis/smite/match_group_input_custom.lua index 38b946f5b00..09a843998f2 100644 --- a/components/match2/wikis/smite/match_group_input_custom.lua +++ b/components/match2/wikis/smite/match_group_input_custom.lua @@ -6,12 +6,9 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- -local Array = require('Module:Array') local FnUtil = require('Module:FnUtil') local GodNames = mw.loadData('Module:GodNames') -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') diff --git a/components/match2/wikis/splatoon/match_group_input_custom.lua b/components/match2/wikis/splatoon/match_group_input_custom.lua index 8e79ba1cb6b..4582d00610a 100644 --- a/components/match2/wikis/splatoon/match_group_input_custom.lua +++ b/components/match2/wikis/splatoon/match_group_input_custom.lua @@ -7,10 +7,7 @@ -- 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 WeaponNames = mw.loadData('Module:WeaponNames') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') diff --git a/components/match2/wikis/tetris/match_group_input_custom.lua b/components/match2/wikis/tetris/match_group_input_custom.lua index 6ab201330bf..e3906fa62a4 100644 --- a/components/match2/wikis/tetris/match_group_input_custom.lua +++ b/components/match2/wikis/tetris/match_group_input_custom.lua @@ -92,8 +92,10 @@ function MapFunctions.calculateMapScore(map) end ---@param map table +---@param mapIndex integer +---@param match table ---@return string? -function MapFunctions.getMapName(map) +function MapFunctions.getMapName(map, mapIndex, match) return nil end diff --git a/components/match2/wikis/valorant/match_group_input_custom.lua b/components/match2/wikis/valorant/match_group_input_custom.lua index 5afa5f8995c..a9a9d870816 100644 --- a/components/match2/wikis/valorant/match_group_input_custom.lua +++ b/components/match2/wikis/valorant/match_group_input_custom.lua @@ -11,8 +11,6 @@ local AgentNames = require('Module:AgentNames') local FnUtil = require('Module:FnUtil') local Json = require('Module:Json') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') From 43de364dc2d71b2c0d26e18e97ddfeee2b824023 Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:48:34 +0100 Subject: [PATCH 21/22] Update components/match2/wikis/brawlstars/match_group_input_custom.lua Co-authored-by: Rikard Blixt --- .../match2/wikis/brawlstars/match_group_input_custom.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/match2/wikis/brawlstars/match_group_input_custom.lua b/components/match2/wikis/brawlstars/match_group_input_custom.lua index b83407e0b84..6890f1a78ac 100644 --- a/components/match2/wikis/brawlstars/match_group_input_custom.lua +++ b/components/match2/wikis/brawlstars/match_group_input_custom.lua @@ -52,8 +52,8 @@ end ---@return table[] function MatchFunctions.extractMaps(match, opponents) local games = MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) - Array.forEach(games, function(game, gameINdex) - game.vod = game.vod or String.nilIfEmpty(match['vodgame' .. gameINdex]) + Array.forEach(games, function(game, gameIndex) + game.vod = game.vod or String.nilIfEmpty(match['vodgame' .. gameIndex]) end) return games end From 3e0e44f60ae44748086767f7a0dcc51b4b8f4ca8 Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Thu, 19 Dec 2024 03:37:48 +0100 Subject: [PATCH 22/22] Apply suggestions from code review --- components/match2/wikis/osu/match_group_input_custom.lua | 2 +- components/match2/wikis/overwatch/match_group_input_custom.lua | 2 +- components/match2/wikis/splatoon/match_group_input_custom.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/match2/wikis/osu/match_group_input_custom.lua b/components/match2/wikis/osu/match_group_input_custom.lua index f67bdd3380f..9e90d4fea79 100644 --- a/components/match2/wikis/osu/match_group_input_custom.lua +++ b/components/match2/wikis/osu/match_group_input_custom.lua @@ -99,7 +99,7 @@ function MapFunctions.computeOpponentScore(props, autoScore) props.score = string.gsub(props.score or '', ',', '') - return MatchGroupInputUtil.computeOpponentScore(props) + return MatchGroupInputUtil.computeOpponentScore(props, autoScore) end return CustomMatchGroupInput diff --git a/components/match2/wikis/overwatch/match_group_input_custom.lua b/components/match2/wikis/overwatch/match_group_input_custom.lua index 6e8737a045f..beee93cac15 100644 --- a/components/match2/wikis/overwatch/match_group_input_custom.lua +++ b/components/match2/wikis/overwatch/match_group_input_custom.lua @@ -88,7 +88,7 @@ function MapFunctions.computeOpponentScore(props, autoScore) props.score = props.score:gsub('m', '') end - return MatchGroupInputUtil.computeOpponentScore(props) + return MatchGroupInputUtil.computeOpponentScore(props, autoScore) end diff --git a/components/match2/wikis/splatoon/match_group_input_custom.lua b/components/match2/wikis/splatoon/match_group_input_custom.lua index 4582d00610a..837d6ac8561 100644 --- a/components/match2/wikis/splatoon/match_group_input_custom.lua +++ b/components/match2/wikis/splatoon/match_group_input_custom.lua @@ -126,7 +126,7 @@ function MapFunctions.computeOpponentScore(props, autoScore) props.score = props.score:gsub('%%', '') end - return MatchGroupInputUtil.computeOpponentScore(props, MapFunctions.calculateMapScore) + return MatchGroupInputUtil.computeOpponentScore(props, autoScore) end return CustomMatchGroupInput