From b787bc66725c7c68fa41a8160dcdc010514ceae1 Mon Sep 17 00:00:00 2001 From: LuckeLucky Date: Sun, 22 Dec 2024 14:09:10 +0000 Subject: [PATCH] add handling to non ffa --- .../autochess/match_group_input_custom.lua | 68 +++++++++++++++---- .../match2/wikis/autochess/match_summary.lua | 38 +++++++++++ 2 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 components/match2/wikis/autochess/match_summary.lua diff --git a/components/match2/wikis/autochess/match_group_input_custom.lua b/components/match2/wikis/autochess/match_group_input_custom.lua index fa271ed58b..41acdc2065 100644 --- a/components/match2/wikis/autochess/match_group_input_custom.lua +++ b/components/match2/wikis/autochess/match_group_input_custom.lua @@ -9,10 +9,13 @@ local Array = require('Module:Array') local Lua = require('Module:Lua') local Operator = require('Module:Operator') +local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') -local MapFunctions = {} +local DEFAULT_BESTOF = 3 + +local CustomMatchGroupInput = {} local MatchFunctions = { OPPONENT_CONFIG = { resolveRedirect = true, @@ -21,31 +24,70 @@ local MatchFunctions = { }, DEFAULT_MODE = 'team' } +local MapFunctions = {} + +local FfaMatchFunctions = { + OPPONENT_CONFIG = { + resolveRedirect = true, + applyUnderScores = true, + maxNumPlayers = 4, + }, + DEFAULT_MODE = 'team' +} +local FfaMapFunctions = {} -local CustomMatchGroupInput = {} ---@param match table ---@param options table? ---@return table function CustomMatchGroupInput.processMatch(match, options) - return MatchGroupInputUtil.standardProcessFfaMatch(match, MatchFunctions) + return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions, FfaMatchFunctions) end --- --- match related functions --- +-- "Normal" Match + +---@param match table +---@param opponents table[] +---@return table[] +function MatchFunctions.extractMaps(match, opponents) + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) +end + +---@param bestofInput string|integer? +---@return integer? +function MatchFunctions.getBestOf(bestofInput) + local bestof = tonumber(bestofInput) + + if bestof then + Variables.varDefine('bestof', bestof) + return bestof + end + + return tonumber(Variables.varDefault('bestof')) or DEFAULT_BESTOF +end + +---@param maps table[] +---@return fun(opponentIndex: integer): integer? +function MatchFunctions.calculateMatchScore(maps) + return function(opponentIndex) + return MatchGroupInputUtil.computeMatchScoreFromMapWinners(maps, opponentIndex) + end +end + +--- FFA Match + ---@param match table ---@param opponents table[] ---@param scoreSettings table ---@return table[] -function MatchFunctions.extractMaps(match, opponents, scoreSettings) - return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, MapFunctions) +function FfaMatchFunctions.extractMaps(match, opponents, scoreSettings) + return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, FfaMapFunctions) end ---@param opponents table[] ---@param maps table[] ---@return fun(opponentIndex: integer): integer? -function MatchFunctions.calculateMatchScore(opponents, maps) +function FfaMatchFunctions.calculateMatchScore(opponents, maps) return function(opponentIndex) return Array.reduce(Array.map(maps, function(map) return map.opponents[opponentIndex].score or 0 @@ -58,22 +100,18 @@ end ---@param opponents table[] ---@param settings table ---@return table -function MatchFunctions.getExtraData(match, games, opponents, settings) +function FfaMatchFunctions.getExtraData(match, games, opponents, settings) return { placementinfo = settings.placementInfo, settings = settings.settings, } end --- --- map related functions --- - ---@param match table ---@param map table ---@param opponents table[] ---@return table -function MapFunctions.getExtraData(match, map, opponents) +function FfaMapFunctions.getExtraData(match, map, opponents) return { dateexact = map.dateexact, comment = map.comment, diff --git a/components/match2/wikis/autochess/match_summary.lua b/components/match2/wikis/autochess/match_summary.lua new file mode 100644 index 0000000000..6753464394 --- /dev/null +++ b/components/match2/wikis/autochess/match_summary.lua @@ -0,0 +1,38 @@ +--- +-- @Liquipedia +-- wiki=autochess +-- page=Module:MatchSummary +-- +-- Please see https://github.com/Liquipedia/Lua-Modules to contribute +-- + +local Lua = require('Module:Lua') + +local MatchSummary = Lua.import('Module:MatchSummary/Base') +local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All') +local WidgetUtil = Lua.import('Module:Widget/Util') + +local CustomMatchSummary = {} + +---@param args table +---@return Html +function CustomMatchSummary.getByMatchId(args) + return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args) +end + +---@param date string +---@param game MatchGroupUtilGame +---@param gameIndex integer +---@return Widget? +function CustomMatchSummary.createGame(date, game, gameIndex) + return MatchSummaryWidgets.Row{ + classes = {'brkts-popup-body-game'}, + children = WidgetUtil.collect( + MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1}, + MatchSummaryWidgets.GameCenter{children = 'Game ' .. gameIndex}, + MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2} + ) + } +end + +return CustomMatchSummary