From 9567a20d5519a213f2cbaa5653a64da71474e850 Mon Sep 17 00:00:00 2001 From: Jasper Jacobs <97167868+Kanopedia@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:25:12 +0200 Subject: [PATCH] feat(match2): support for hero bans on deadlock (#4879) * Adding support for Hero Bans in Deadlock * Update match_summary.lua * Update match_summary.lua * Update components/match2/wikis/deadlock/match_summary.lua Co-authored-by: Rikard Blixt * Update components/match2/wikis/deadlock/match_summary.lua Co-authored-by: Rikard Blixt * Update components/match2/wikis/deadlock/match_summary.lua Co-authored-by: Rikard Blixt * Update match_summary.lua * Update match_summary.lua * Update Match Copy Paste * Update get_match_group_copy_paste_wiki.lua * Update get_match_group_copy_paste_wiki.lua * Update get_match_group_copy_paste_wiki.lua * Update match_summary.lua * Update get_match_group_copy_paste_wiki.lua * Update match_summary.lua * #4878 * Update components/match2/wikis/deadlock/match_summary.lua --------- Co-authored-by: Rikard Blixt --- .../get_match_group_copy_paste_wiki.lua | 19 ++++++++++++++----- .../deadlock/match_group_input_custom.lua | 19 +++++++++++++++---- .../match2/wikis/deadlock/match_summary.lua | 11 +++++++++++ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/components/match2/wikis/deadlock/get_match_group_copy_paste_wiki.lua b/components/match2/wikis/deadlock/get_match_group_copy_paste_wiki.lua index 484ce35e0d7..877de60012f 100644 --- a/components/match2/wikis/deadlock/get_match_group_copy_paste_wiki.lua +++ b/components/match2/wikis/deadlock/get_match_group_copy_paste_wiki.lua @@ -20,15 +20,19 @@ local INDENT = WikiCopyPaste.Indent function WikiCopyPaste.getMatchCode(bestof, mode, index, opponents, args) local showScore = Logic.nilOr(Logic.readBoolOrNil, bestof == 0) + local bans = Logic.readBool(args.bans) local lines = Array.extend( '{{Match|bestof=' .. (bestof ~= 0 and bestof or ''), + Logic.readBool(args.needsWinner) and INDENT .. '|winner=' or nil, Array.map(Array.range(1, opponents), function(opponentIndex) return INDENT .. '|opponent' .. opponentIndex .. '=' .. WikiCopyPaste.getOpponent(mode, showScore) end), - INDENT .. '|date=|finished=', + INDENT .. '|date=', INDENT .. '|twitch=|youtube=|vod=', - Array.map(Array.range(1, bestof), WikiCopyPaste._getMapCode), + Array.map(Array.range(1, bestof), function(mapIndex) + return WikiCopyPaste._getMapCode(mapIndex, bans) + end), '}}' ) @@ -36,13 +40,18 @@ function WikiCopyPaste.getMatchCode(bestof, mode, index, opponents, args) end ---@param mapIndex integer +---@param bans boolean ---@return string -function WikiCopyPaste._getMapCode(mapIndex) +function WikiCopyPaste._getMapCode(mapIndex, bans) return table.concat(Array.extend( - INDENT .. '|map' .. mapIndex .. '={{Map|length=|winner=|vod=', - INDENT .. INDENT .. '|team1side=|team2side=', + INDENT .. '|map' .. mapIndex .. '={{Map', + INDENT .. INDENT .. '|team1side=', INDENT .. INDENT .. '|t1h1=|t1h2=|t1h3=|t1h4=|t1h5=|t1h6=', + bans and (INDENT .. INDENT .. '|t1b1=|t1b2=|t1b3=|t1b4=|t1b5=|t1b6=') or nil, + INDENT .. INDENT .. '|team2side=', INDENT .. INDENT .. '|t2h1=|t2h2=|t2h3=|t2h4=|t2h5=|t2h6=', + bans and (INDENT .. INDENT .. '|t2b1=|t2b2=|t2b3=|t2b4=|t2b5=|t2b6=') or nil, + INDENT .. INDENT .. '|length=|winner=|matchid=|vod=', INDENT .. '}}' ), '\n') end diff --git a/components/match2/wikis/deadlock/match_group_input_custom.lua b/components/match2/wikis/deadlock/match_group_input_custom.lua index eecc27df3ec..09b12b575b1 100644 --- a/components/match2/wikis/deadlock/match_group_input_custom.lua +++ b/components/match2/wikis/deadlock/match_group_input_custom.lua @@ -88,7 +88,7 @@ function MatchFunctions.extractMaps(match, opponents) map.map = nil map.participants = MapFunctions.getParticipants(map, opponents) - map.extradata = MapFunctions.getExtraData(map) + map.extradata = MapFunctions.getExtraData(map, #opponents) map.finished = MatchGroupInputUtil.mapIsFinished(map) local opponentInfo = Array.map(opponents, function(_, opponentIndex) @@ -132,15 +132,26 @@ function MatchFunctions.getExtraData(match) end ---@param map table +---@param opponentCount integer ---@return table -function MapFunctions.getExtraData(map) - local extraData = { +function MapFunctions.getExtraData(map, opponentCount) + local extradata = { comment = map.comment, team1side = map.team1side, team2side = map.team2side, } - return extraData + local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, HeroNames) + for opponentIndex = 1, opponentCount do + for _, ban, banIndex in Table.iter.pairsByPrefix(map, 't' .. opponentIndex .. 'b') do + extradata['team' .. opponentIndex .. 'ban' .. banIndex] = getCharacterName(ban) + end + for _, pick, pickIndex in Table.iter.pairsByPrefix(map, 't' .. opponentIndex .. 'h') do + extradata['team' .. opponentIndex .. 'hero' .. pickIndex] = getCharacterName(pick) + end + end + + return extradata end ---@param map table diff --git a/components/match2/wikis/deadlock/match_summary.lua b/components/match2/wikis/deadlock/match_summary.lua index 272fcab3178..2fe5b2c1561 100644 --- a/components/match2/wikis/deadlock/match_summary.lua +++ b/components/match2/wikis/deadlock/match_summary.lua @@ -19,6 +19,7 @@ local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper') local MatchSummary = Lua.import('Module:MatchSummary/Base') local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All') +local MAX_NUM_BANS = 6 local ICONS = { winner = Icon.makeIcon{iconName = 'winner', color = 'forest-green-text', size = 'initial'}, loss = Icon.makeIcon{iconName = 'loss', color = 'cinnabar-text', size = 'initial'}, @@ -46,8 +47,18 @@ function CustomMatchSummary.createBody(match) )) end + -- Iterate each map Array.forEach(Array.map(match.games, CustomMatchSummary._createGame), FnUtil.curry(body.addRow, body)) + -- Add the Hero Bans + local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS) + if characterBansData then + body.root:node(MatchSummaryWidgets.CharacterBanTable{ + bans = characterBansData, + date = match.date, + }) + end + return body end