Skip to content

Commit

Permalink
refactor(match2): standardize character parsing in moba match summari…
Browse files Browse the repository at this point in the history
…es (#4916)

* refactor(match2): standardize character parsing in moba match summaries

* update annos to match new logic
  • Loading branch information
Rathoz authored Oct 21, 2024
1 parent 1f6da39 commit 3f97ec1
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 183 deletions.
37 changes: 15 additions & 22 deletions components/match2/commons/match_summary_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -840,32 +840,25 @@ end

---@param games table[]
---@param maxNumberOfBans integer
---@return {[1]: string[]?, [2]: string[]?}[]?
---@return {[1]: string[], [2]: string[]}[]
function MatchSummary.buildCharacterBanData(games, maxNumberOfBans)
local matchHasBans = false
local gamesBans = Array.map(games, function(game)
return Array.map(games, function(game)
local extradata = game.extradata or {}
local banData = {{}, {}}
local gameHasBans = false
for index = 1, maxNumberOfBans do
local team1ban = String.nilIfEmpty(extradata['team1ban' .. index])
local team2ban = String.nilIfEmpty(extradata['team2ban' .. index])
if team1ban or team2ban then
gameHasBans = true
end
table.insert(banData[1], team1ban)
table.insert(banData[2], team2ban)
end

if gameHasBans then
matchHasBans = true
return banData
else
return {}
end
return {
MatchSummary.buildCharacterList(extradata, 'team1ban', maxNumberOfBans),
MatchSummary.buildCharacterList(extradata, 'team2ban', maxNumberOfBans),
}
end)
end

return matchHasBans and gamesBans or nil
---@param data table
---@param prefix string
---@param maxNumberOfCharacters integer
---@return string[]
function MatchSummary.buildCharacterList(data, prefix, maxNumberOfCharacters)
return Array.map(Array.range(1, maxNumberOfCharacters), function(index)
return data[prefix .. index]
end)
end

return MatchSummary
10 changes: 4 additions & 6 deletions components/match2/wikis/deadlock/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ function CustomMatchSummary.createBody(match)

-- 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
body.root:node(MatchSummaryWidgets.CharacterBanTable{
bans = characterBansData,
date = match.date,
})

return body
end
Expand Down
26 changes: 8 additions & 18 deletions components/match2/wikis/dota2/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ local Icon = require('Module:Icon')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local MatchLinks = mw.loadData('Module:MatchLinks')
local String = require('Module:StringUtils')
local Table = require('Module:Table')

local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
Expand All @@ -23,8 +22,7 @@ local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')
local Opponent = Lua.import('Module:Opponent')

local MAX_NUM_BANS = 7
local NUM_HEROES_PICK_TEAM = 5
local NUM_HEROES_PICK_SOLO = 1
local NUM_HEROES_PICK = 5
local GREEN_CHECK = Icon.makeIcon{iconName = 'winner', color = 'forest-green-text', size = '110%'}
local NO_CHECK = '[[File:NoCheck.png|link=]]'

Expand Down Expand Up @@ -105,27 +103,19 @@ function CustomMatchSummary._createGame(game, gameIndex)
local row = MatchSummary.Row()
local extradata = game.extradata or {}

local numberOfHeroes = NUM_HEROES_PICK_TEAM
if game.mode == Opponent.solo then
numberOfHeroes = NUM_HEROES_PICK_SOLO
end
local heroesData = {{}, {}}
for heroIndex = 1, numberOfHeroes do
if String.isNotEmpty(extradata['team1hero' .. heroIndex]) then
heroesData[1][heroIndex] = extradata['team1hero' .. heroIndex]
end
if String.isNotEmpty(extradata['team2hero' .. heroIndex]) then
heroesData[2][heroIndex] = extradata['team2hero' .. heroIndex]
end
end
-- TODO: Change to use participant data
local characterData = {
MatchSummary.buildCharacterList(extradata, 'team1hero', NUM_HEROES_PICK),
MatchSummary.buildCharacterList(extradata, 'team2hero', NUM_HEROES_PICK),
}

row:addClass('brkts-popup-body-game')
:css('font-size', '80%')
:css('padding', '4px')

row:addElement(MatchSummaryWidgets.Characters{
flipped = false,
characters = heroesData[1],
characters = characterData[1],
bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''),
})
row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1))
Expand All @@ -139,7 +129,7 @@ function CustomMatchSummary._createGame(game, gameIndex)
row:addElement(CustomMatchSummary._createCheckMark(game.winner == 2))
row:addElement(MatchSummaryWidgets.Characters{
flipped = true,
characters = heroesData[2],
characters = characterData[2],
bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''),
})

Expand Down
28 changes: 8 additions & 20 deletions components/match2/wikis/heroes/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ local Icon = require('Module:Icon')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Page = require('Module:Page')
local String = require('Module:StringUtils')
local Table = require('Module:Table')

local MatchSummary = Lua.import('Module:MatchSummary/Base')
Expand Down Expand Up @@ -125,24 +124,13 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
local row = MatchSummary.Row()
local extradata = game.extradata or {}

local championsData = {{}, {}}
local championsDataIsEmpty = true
for champIndex = 1, NUM_CHAMPIONS_PICK do
if String.isNotEmpty(extradata['team1champion' .. champIndex]) then
championsData[1][champIndex] = extradata['team1champion' .. champIndex]
championsDataIsEmpty = false
end
if String.isNotEmpty(extradata['team2champion' .. champIndex]) then
championsData[2][champIndex] = extradata['team2champion' .. champIndex]
championsDataIsEmpty = false
end
end
-- TODO: Change to use participant data
local characterData = {
MatchSummary.buildCharacterList(extradata, 'team1champion', NUM_CHAMPIONS_PICK),
MatchSummary.buildCharacterList(extradata, 'team2champion', NUM_CHAMPIONS_PICK),
}

if
Logic.isEmpty(game.length) and
Logic.isEmpty(game.winner) and
championsDataIsEmpty
then
if Logic.isEmpty(game.length) and Logic.isEmpty(game.winner) and Logic.isDeepEmpty(characterData) then
return nil
end

Expand All @@ -154,7 +142,7 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
row:addElement(MatchSummaryWidgets.Characters{
flipped = false,
date = date,
characters = championsData[1],
characters = characterData[1],
bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''),
})
row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1))
Expand All @@ -172,7 +160,7 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
row:addElement(MatchSummaryWidgets.Characters{
flipped = true,
date = date,
characters = championsData[2],
characters = characterData[2],
bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''),
})

Expand Down
28 changes: 8 additions & 20 deletions components/match2/wikis/honorofkings/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ local ExternalLinks = require('Module:ExternalLinks')
local Icon = require('Module:Icon')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Table = require('Module:Table')

local MatchSummary = Lua.import('Module:MatchSummary/Base')
Expand Down Expand Up @@ -92,24 +91,13 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
local row = MatchSummary.Row()
local extradata = game.extradata or {}

local championsData = {{}, {}}
local championsDataIsEmpty = true
for champIndex = 1, NUM_CHAMPIONS_PICK do
if String.isNotEmpty(extradata['team1champion' .. champIndex]) then
championsData[1][champIndex] = extradata['team1champion' .. champIndex]
championsDataIsEmpty = false
end
if String.isNotEmpty(extradata['team2champion' .. champIndex]) then
championsData[2][champIndex] = extradata['team2champion' .. champIndex]
championsDataIsEmpty = false
end
end
-- TODO: Change to use participant data
local characterData = {
MatchSummary.buildCharacterList(extradata, 'team1champion', NUM_CHAMPIONS_PICK),
MatchSummary.buildCharacterList(extradata, 'team2champion', NUM_CHAMPIONS_PICK),
}

if
Logic.isEmpty(game.length) and
Logic.isEmpty(game.winner) and
championsDataIsEmpty
then
if Logic.isEmpty(game.length) and Logic.isEmpty(game.winner) and Logic.isDeepEmpty(characterData) then
return nil
end

Expand All @@ -120,7 +108,7 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
row:addElement(MatchSummaryWidgets.Characters{
flipped = false,
date = date,
characters = championsData[1],
characters = characterData[1],
bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''),
})
row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1))
Expand All @@ -135,7 +123,7 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
row:addElement(MatchSummaryWidgets.Characters{
flipped = true,
date = date,
characters = championsData[2],
characters = characterData[2],
bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''),
})

Expand Down
28 changes: 8 additions & 20 deletions components/match2/wikis/leagueoflegends/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@ local Icon = require('Module:Icon')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local MatchLinks = mw.loadData('Module:MatchLinks')
local String = require('Module:StringUtils')
local Table = require('Module:Table')

local MatchPage = Lua.import('Module:MatchPage')
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 Opponent = Lua.import('Module:Opponent')

local MAX_NUM_BANS = 5
local NUM_HEROES_PICK_TEAM = 5
local NUM_HEROES_PICK_SOLO = 1
local NUM_HEROES_PICK = 5
local GREEN_CHECK = Icon.makeIcon{iconName = 'winner', color = 'forest-green-text', size = '110%'}
local NO_CHECK = '[[File:NoCheck.png|link=]]'

Expand Down Expand Up @@ -92,20 +89,11 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
local row = MatchSummary.Row()
local extradata = game.extradata or {}

local numberOfHeroes = NUM_HEROES_PICK_TEAM
if game.mode == Opponent.solo then
numberOfHeroes = NUM_HEROES_PICK_SOLO
end

local heroesData = {{}, {}}
for heroIndex = 1, numberOfHeroes do
if String.isNotEmpty(extradata['team1champion' .. heroIndex]) then
heroesData[1][heroIndex] = extradata['team1champion' .. heroIndex]
end
if String.isNotEmpty(extradata['team2champion' .. heroIndex]) then
heroesData[2][heroIndex] = extradata['team2champion' .. heroIndex]
end
end
-- TODO: Change to use participant data
local characterData = {
MatchSummary.buildCharacterList(extradata, 'team1champion', NUM_HEROES_PICK),
MatchSummary.buildCharacterList(extradata, 'team2champion', NUM_HEROES_PICK),
}

row:addClass('brkts-popup-body-game')
:css('font-size', '80%')
Expand All @@ -115,7 +103,7 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
row:addElement(MatchSummaryWidgets.Characters{
flipped = false,
date = date,
characters = heroesData[1],
characters = characterData[1],
bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''),
})
row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1))
Expand All @@ -130,7 +118,7 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
row:addElement(MatchSummaryWidgets.Characters{
flipped = true,
date = date,
characters = heroesData[2],
characters = characterData[2],
bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''),
})

Expand Down
28 changes: 8 additions & 20 deletions components/match2/wikis/mobilelegends/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Table = require('Module:Table')
local ExternalLinks = require('Module:ExternalLinks')
local String = require('Module:StringUtils')

local MatchSummary = Lua.import('Module:MatchSummary/Base')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')
Expand Down Expand Up @@ -95,24 +94,13 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
local row = MatchSummary.Row()
local extradata = game.extradata or {}

local championsData = {{}, {}}
local championsDataIsEmpty = true
for champIndex = 1, NUM_CHAMPIONS_PICK do
if String.isNotEmpty(extradata['team1champion' .. champIndex]) then
championsData[1][champIndex] = extradata['team1champion' .. champIndex]
championsDataIsEmpty = false
end
if String.isNotEmpty(extradata['team2champion' .. champIndex]) then
championsData[2][champIndex] = extradata['team2champion' .. champIndex]
championsDataIsEmpty = false
end
end
-- TODO: Change to use participant data
local characterData = {
MatchSummary.buildCharacterList(extradata, 'team1champion', NUM_CHAMPIONS_PICK),
MatchSummary.buildCharacterList(extradata, 'team2champion', NUM_CHAMPIONS_PICK),
}

if
Logic.isEmpty(game.length) and
Logic.isEmpty(game.winner) and
championsDataIsEmpty
then
if Logic.isEmpty(game.length) and Logic.isEmpty(game.winner) and Logic.isDeepEmpty(characterData) then
return nil
end

Expand All @@ -123,7 +111,7 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
row:addElement(MatchSummaryWidgets.Characters{
flipped = false,
date = date,
characters = championsData[1],
characters = characterData[1],
bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''),
})
row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1))
Expand All @@ -138,7 +126,7 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
row:addElement(MatchSummaryWidgets.Characters{
flipped = true,
date = date,
characters = championsData[2],
characters = characterData[2],
bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''),
})

Expand Down
Loading

0 comments on commit 3f97ec1

Please sign in to comment.