From ae7406be9add6ab88bf14c0e1a6b276de6de26b9 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Wed, 6 Nov 2024 17:26:00 +0100 Subject: [PATCH] do some more wikis --- .../pokemon/match_group_input_custom.lua | 41 ++-------------- .../sideswipe/match_group_input_custom.lua | 48 +++++------------- .../splitgate/match_group_input_custom.lua | 47 +++++------------- .../teamfortress/match_group_input_custom.lua | 49 +++++-------------- .../wikis/tft/match_group_input_custom.lua | 14 +++--- 5 files changed, 47 insertions(+), 152 deletions(-) diff --git a/components/match2/wikis/pokemon/match_group_input_custom.lua b/components/match2/wikis/pokemon/match_group_input_custom.lua index 125639de11c..1bfa54986a1 100644 --- a/components/match2/wikis/pokemon/match_group_input_custom.lua +++ b/components/match2/wikis/pokemon/match_group_input_custom.lua @@ -6,12 +6,10 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- -local Array = require('Module:Array') local ChampionNames = mw.loadData('Module:HeroNames') local FnUtil = require('Module:FnUtil') local Logic = require('Module:Logic') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') local Table = require('Module:Table') local Variables = require('Module:Variables') @@ -46,42 +44,12 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map, #opponents) - - map.finished = MatchGroupInputUtil.mapIsFinished(map) - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }, MapFunctions.calculateMapScore(map.winner, map.finished)) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end -- -- match related functions -- - ---@param maps table[] ---@return fun(opponentIndex: integer): integer function MatchFunctions.calculateMatchScore(maps) @@ -110,10 +78,11 @@ end -- map related functions -- +---@param match table ---@param map table ----@param opponentCount integer +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map, opponentCount) +function MapFunctions.getExtraData(match, map, opponents) local extradata = { comment = map.comment, team1side = string.lower(map.team1side or ''), @@ -121,7 +90,7 @@ function MapFunctions.getExtraData(map, opponentCount) } local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, ChampionNames) - for opponentIndex = 1, opponentCount do + for opponentIndex = 1, #opponents do for _, ban, banIndex in Table.iter.pairsByPrefix(map, 't' .. opponentIndex .. 'b') do extradata['team' .. opponentIndex .. 'ban' .. banIndex] = getCharacterName(ban) end diff --git a/components/match2/wikis/sideswipe/match_group_input_custom.lua b/components/match2/wikis/sideswipe/match_group_input_custom.lua index 8c60cfb6ed4..c3fe8d6444b 100644 --- a/components/match2/wikis/sideswipe/match_group_input_custom.lua +++ b/components/match2/wikis/sideswipe/match_group_input_custom.lua @@ -9,8 +9,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -32,45 +30,21 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end -- -- match related functions -- +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) +end + ---@param match table ---@param opponents table[] ---@return table @@ -90,9 +64,11 @@ end -- map related functions -- +---@param match table ---@param map table +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map) +function MapFunctions.getExtraData(match, map, opponents) return { ot = map.ot, otlength = map.otlength, diff --git a/components/match2/wikis/splitgate/match_group_input_custom.lua b/components/match2/wikis/splitgate/match_group_input_custom.lua index e76e3dd0bf6..1b83b00ab14 100644 --- a/components/match2/wikis/splitgate/match_group_input_custom.lua +++ b/components/match2/wikis/splitgate/match_group_input_custom.lua @@ -8,8 +8,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -36,39 +34,15 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map, #opponents) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) +end - return maps +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) end ---@param bestofInput string|integer? @@ -104,10 +78,11 @@ end -- map related functions -- +---@param match table ---@param map table ----@param opponentCount integer +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map, opponentCount) +function MapFunctions.getExtraData(match, map, opponents) return { comment = map.comment, } diff --git a/components/match2/wikis/teamfortress/match_group_input_custom.lua b/components/match2/wikis/teamfortress/match_group_input_custom.lua index c675108d562..7ac4ea533a2 100644 --- a/components/match2/wikis/teamfortress/match_group_input_custom.lua +++ b/components/match2/wikis/teamfortress/match_group_input_custom.lua @@ -8,8 +8,6 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') -local Operator = require('Module:Operator') -local Table = require('Module:Table') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') @@ -30,45 +28,21 @@ end ---@param opponents table[] ---@return table[] function MatchFunctions.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if not map.map then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(map) - map.finished = MatchGroupInputUtil.mapIsFinished(map) - - local opponentInfo = Array.map(opponents, function(_, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }) - return {score = score, status = status} - end) - - map.scores = Array.map(opponentInfo, Operator.property('score')) - if map.finished then - map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) - map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) - map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end -- -- match related functions -- +---@param games table[] +---@return table[] +function MatchFunctions.removeUnsetMaps(games) + return Array.filter(games, function(map) + return map.map ~= nil + end) +end + ---@param maps table[] ---@return fun(opponentIndex: integer): integer function MatchFunctions.calculateMatchScore(maps) @@ -98,10 +72,11 @@ end -- map related functions -- --- Parse extradata information +---@param match table ---@param map table +---@param opponents table[] ---@return table -function MapFunctions.getExtraData(map) +function MapFunctions.getExtraData(match, map, opponents) return { comment = map.comment, } diff --git a/components/match2/wikis/tft/match_group_input_custom.lua b/components/match2/wikis/tft/match_group_input_custom.lua index 24191096284..65a488ab9d5 100644 --- a/components/match2/wikis/tft/match_group_input_custom.lua +++ b/components/match2/wikis/tft/match_group_input_custom.lua @@ -26,6 +26,13 @@ function CustomMatchGroupInput.processMatch(match, options) return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) end +---@param match table +---@param opponents table[] +---@return table[] +function MatchFunctions.extractMaps(match, opponents) + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) +end + ---@param match table ---@return table function MatchFunctions.getExtraData(match) @@ -59,13 +66,6 @@ function MatchFunctions.removeUnsetMaps(games) end) end ----@param match table ----@param opponents table[] ----@return table[] -function MatchFunctions.extractMaps(match, opponents) - return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) -end - ---@param match table ---@param map table ---@param opponents table[]