From e4d52e5c39366caa00124d1d0064e6cc25cc7ffe Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Sat, 20 Jun 2026 11:08:42 +0200 Subject: [PATCH] feat(match2): Add match based character bans support to brawlstars --- .../brawlstars/MatchGroup/Input/Custom.lua | 38 +++++++++++-------- lua/wikis/brawlstars/MatchSummary.lua | 30 +++++++++------ .../Match/Summary/CharacterBanTable.lua | 4 +- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/lua/wikis/brawlstars/MatchGroup/Input/Custom.lua b/lua/wikis/brawlstars/MatchGroup/Input/Custom.lua index 1efec503f96..e180639cd67 100644 --- a/lua/wikis/brawlstars/MatchGroup/Input/Custom.lua +++ b/lua/wikis/brawlstars/MatchGroup/Input/Custom.lua @@ -42,6 +42,24 @@ MatchFunctions.DATE_FALLBACKS = { local CustomMatchGroupInput = {} +---@param obj table #match or game +---@param numberOfOpponents integer +---@return {[1]: string[], [2]: string[]} +local getBans = function(obj, numberOfOpponents) + local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, BrawlerNames) + + local bans = {} + for opponentIndex = 1, numberOfOpponents do + bans['team' .. opponentIndex] = {} + for _, ban in Table.iter.pairsByPrefix(obj, 't' .. opponentIndex .. 'b') do + ban = getCharacterName(ban) + table.insert(bans['team' .. opponentIndex], ban) + end + end + + return bans +end + ---@param match table ---@param options table? ---@return table @@ -86,6 +104,7 @@ function MatchFunctions.getExtraData(match, games, opponents) return { mapveto = MatchGroupInputUtil.getMapVeto(match), mvp = MatchGroupInputUtil.readMvp(match, opponents), + globalbans = getBans(match, #opponents), } end @@ -106,25 +125,12 @@ end ---@param opponents MGIParsedOpponent[] ---@return table function MapFunctions.getExtraData(match, map, opponents) - local extradata = { + return { bestof = map.bestof, maptype = map.maptype, - firstpick = FIRST_PICK_CONVERSION[string.lower(map.firstpick or '')] + firstpick = FIRST_PICK_CONVERSION[string.lower(map.firstpick or '')], + bans = getBans(map, #opponents), } - - local bans = {} - local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, BrawlerNames) - for opponentIndex = 1, #opponents do - 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 - - extradata.bans = bans - - return extradata end ---@param map table diff --git a/lua/wikis/brawlstars/MatchSummary.lua b/lua/wikis/brawlstars/MatchSummary.lua index 969a1124077..f6375ece06e 100644 --- a/lua/wikis/brawlstars/MatchSummary.lua +++ b/lua/wikis/brawlstars/MatchSummary.lua @@ -9,11 +9,12 @@ local Lua = require('Module:Lua') local Array = Lua.import('Module:Array') local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper') +local Logic = Lua.import('Module:Logic') local MapTypeIcon = Lua.import('Module:MapType') local Operator = Lua.import('Module:Operator') local String = Lua.import('Module:StringUtils') -local HtmlWidgets = Lua.import('Module:Widget/Html/All') +local Html = Lua.import('Module:Widget/Html') local LinkWidget = Lua.import('Module:Widget/Basic/Link') local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All') local MatchSummary = Lua.import('Module:MatchSummary/Base') @@ -22,19 +23,24 @@ local WidgetUtil = Lua.import('Module:Widget/Util') local CustomMatchSummary = {} ---@param args table ----@return Widget +---@return Renderable function CustomMatchSummary.getByMatchId(args) return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, {width = '400px', teamStyle = 'bracket'}) end ---@param match MatchGroupUtilMatch ----@return Widget[] +---@return Renderable[] function CustomMatchSummary.createBody(match) - local characterBansData = Array.map(match.games, function (game) - local extradata = game.extradata or {} - local bans = extradata.bans or {} - return {bans.team1 or {}, bans.team2 or {}} - end) + local globalBans = (match.extradata or {}).globalbans + local characterBansData = Array.extend( + Logic.isNotDeepEmpty(globalBans) and {globalBans.team1 or {}, globalBans.team2 or {}, label = 'Global Bans'} or nil, + Array.map(match.games, function(game, gameIndex) + local extradata = game.extradata or {} + local bans = extradata.bans or {} + if Logic.isDeepEmpty(bans) then return end + return {bans.team1 or {}, bans.team2 or {}, label = 'Game ' .. gameIndex} + end) + ) return WidgetUtil.collect( Array.map(match.games, CustomMatchSummary._createMapRow), @@ -45,7 +51,7 @@ function CustomMatchSummary.createBody(match) end ---@param game MatchGroupUtilGame ----@return Widget? +---@return Renderable? function CustomMatchSummary._createMapRow(game) if not game.map then return @@ -77,13 +83,13 @@ function CustomMatchSummary._createMapRow(game) end ---@param game MatchGroupUtilGame ----@return Widget +---@return Renderable function CustomMatchSummary._getMapDisplay(game) local mapDisplay = LinkWidget{link = game.map} - return HtmlWidgets.Fragment{children = WidgetUtil.collect( + return Html.Fragment{children = WidgetUtil.collect( String.isNotEmpty(game.extradata.maptype) and MapTypeIcon.display(game.extradata.maptype) or nil, - game.status == 'notplayed' and HtmlWidgets.S{children = mapDisplay} or mapDisplay + game.status == 'notplayed' and Html.S{children = mapDisplay} or mapDisplay )} end diff --git a/lua/wikis/commons/Widget/Match/Summary/CharacterBanTable.lua b/lua/wikis/commons/Widget/Match/Summary/CharacterBanTable.lua index d301bb421e2..8e084909acb 100644 --- a/lua/wikis/commons/Widget/Match/Summary/CharacterBanTable.lua +++ b/lua/wikis/commons/Widget/Match/Summary/CharacterBanTable.lua @@ -29,7 +29,7 @@ local ICONS = { empty = Html.Span{}, } ----@param props {bans: {[1]: string[]?, [2]: string[]?, start: integer?}[], date: string?} +---@param props {bans: {[1]: string[]?, [2]: string[]?, start: integer?, label: string?}[], date: string?} ---@return VNode? local function MatchSummaryCharacterBanTable(props) if Logic.isDeepEmpty(props.bans) then @@ -70,7 +70,7 @@ local function MatchSummaryCharacterBanTable(props) classes = hasStartIndicator and {'brkts-popup-veto-row-indicator'} or nil, children = WidgetUtil.collect( hasStartIndicator and startIndicator(1, banData.start) or nil, - 'Game ' .. gameNumber, + banData.label or ('Game ' .. gameNumber), hasStartIndicator and startIndicator(2, banData.start) or nil ) },