Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions lua/wikis/brawlstars/MatchGroup/Input/Custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
30 changes: 18 additions & 12 deletions lua/wikis/brawlstars/MatchSummary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
},
Expand Down
Loading