Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(match2): MS on HoK, LoL, MLBB, Smite & WildRift #4929

Merged
merged 5 commits into from
Oct 22, 2024
Merged
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
2 changes: 1 addition & 1 deletion components/match2/wikis/dota2/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function CustomMatchSummary.createBody(match)
return MatchSummaryWidgets.Body{children = WidgetUtil.collect(
showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil,
showMatchPage and MatchSummaryWidgets.MatchPageLink{matchId = matchId} or nil,
unpack(Array.map(match.games, CustomMatchSummary._createGame)),
Array.map(match.games, CustomMatchSummary._createGame),
MatchSummaryWidgets.Mvp(match.extradata.mvp),
MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date},
casterRow and casterRow:create() or nil
Expand Down
144 changes: 44 additions & 100 deletions components/match2/wikis/honorofkings/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@

local CustomMatchSummary = {}

local Array = require('Module:Array')
local DateExt = require('Module:Date/Ext')
local DisplayHelper = require('Module:MatchGroup/Display/Helper')
local ExternalLinks = require('Module:ExternalLinks')
local Icon = require('Module:Icon')
local FnUtil = require('Module:FnUtil')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Table = require('Module:Table')

local MatchSummary = Lua.import('Module:MatchSummary/Base')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')
local WidgetUtil = Lua.import('Module:Widget/Util')

local MAX_NUM_BANS = 5
local NUM_CHAMPIONS_PICK = 5

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

---@param args table
---@return Html
function CustomMatchSummary.getByMatchId(args)
Expand All @@ -47,48 +47,22 @@ end
---@param match MatchGroupUtilMatch
---@return MatchSummaryBody
function CustomMatchSummary.createBody(match)
local body = MatchSummary.Body()

if match.dateIsExact or match.timestamp ~= DateExt.defaultTimestamp then
-- dateIsExact means we have both date and time. Show countdown
-- if match is not default date, we have a date, so display the date
body:addRow(MatchSummary.Row():addElement(
DisplayHelper.MatchCountdownBlock(match)
))
end

-- Iterate each map
for gameIndex, game in ipairs(match.games) do
local rowDisplay = CustomMatchSummary._createGame(game, gameIndex, match.date)
if rowDisplay then
body:addRow(rowDisplay)
end
end

-- Add Match MVP(s)
if Table.isNotEmpty(match.extradata.mvp) then
body.root:node(MatchSummaryWidgets.Mvp{
players = match.extradata.mvp.players,
points = match.extradata.mvp.points,
})
end

-- Add the Character Bans
local showCountdown = match.timestamp ~= DateExt.defaultTimestamp
local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS)
body.root:node(MatchSummaryWidgets.CharacterBanTable{
bans = characterBansData,
date = match.date,
})

return body
return MatchSummaryWidgets.Body{children = WidgetUtil.collect(
showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil,
Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date)),
MatchSummaryWidgets.Mvp(match.extradata.mvp),
MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}
)}
end

---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
---@param date string
---@return MatchSummaryRow?
function CustomMatchSummary._createGame(game, gameIndex, date)
local row = MatchSummary.Row()
function CustomMatchSummary._createGame(date, game, gameIndex)
local extradata = game.extradata or {}

-- TODO: Change to use participant data
Expand All @@ -101,67 +75,37 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
return nil
end

row :addClass('brkts-popup-body-game')
:css('font-size', '85%')
:css('overflow', 'hidden')

row:addElement(MatchSummaryWidgets.Characters{
flipped = false,
date = date,
characters = characterData[1],
bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''),
})
row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1))
row:addElement(mw.html.create('div')
:addClass('brkts-popup-body-element-vertical-centered')
:wikitext(CustomMatchSummary._createAbbreviation{
title = Logic.isEmpty(game.length) and ('Game ' .. gameIndex .. ' picks') or 'Match Length',
text = Logic.isEmpty(game.length) and ('Game ' .. gameIndex) or game.length,
})
)
row:addElement(CustomMatchSummary._createCheckMark(game.winner == 2))
row:addElement(MatchSummaryWidgets.Characters{
flipped = true,
date = date,
characters = characterData[2],
bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''),
})

-- Add Comment
if not Logic.isEmpty(game.comment) then
row:addElement(MatchSummary.Break():create())
local comment = mw.html.create('div')
comment :wikitext(game.comment)
:css('margin', 'auto')
:css('width', '100%')
row:addElement(comment)
end

return row
end

---@param isWinner boolean?
---@return Html
function CustomMatchSummary._createCheckMark(isWinner)
local container = mw.html.create('div')
:addClass('brkts-popup-spaced')
:css('line-height', '27px')
:css('margin-left', '3%')
:css('margin-right', '3%')

if isWinner then
container:node(GREEN_CHECK)
else
container:node(NO_CHECK)
end

return container
end

---@param args table
---@return string
function CustomMatchSummary._createAbbreviation(args)
return '<i><abbr title="' .. args.title .. '">' .. args.text .. '</abbr></i>'
-- Map Comment
local comment = Logic.isNotEmpty(game.comment) and {
MatchSummaryWidgets.Break{},
HtmlWidgets.Div{css = {margin = 'auto'}, children = game.comment},
} or {}

return MatchSummaryWidgets.Row{
classes = {'brkts-popup-body-game'},
css = {['font-size'] = '80%', padding = '4px'},
children = {
MatchSummaryWidgets.Characters{
flipped = false,
characters = characterData[1],
bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''),
date = date,
},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1},
HtmlWidgets.Div{
classes = {'brkts-popup-body-element-vertical-centered'},
children = {Logic.isNotEmpty(game.length) and game.length or ('Game ' .. gameIndex)},
},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2},
MatchSummaryWidgets.Characters{
flipped = true,
characters = characterData[2],
bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''),
date = date,
},
unpack(comment)
}
}
end

return CustomMatchSummary
152 changes: 50 additions & 102 deletions components/match2/wikis/leagueoflegends/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@

local CustomMatchSummary = {}

local Array = require('Module:Array')
local DateExt = require('Module:Date/Ext')
local Icon = require('Module:Icon')
local FnUtil = require('Module:FnUtil')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local MatchLinks = mw.loadData('Module:MatchLinks')
local Table = require('Module:Table')

local MatchPage = Lua.import('Module:MatchPage')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
local MatchPage = Lua.import('Module:MatchPage')
local MatchSummary = Lua.import('Module:MatchSummary/Base')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')
local WidgetUtil = Lua.import('Module:Widget/Util')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')

local MAX_NUM_BANS = 5
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=]]'

---@param args table
---@return Html
Expand All @@ -43,50 +43,28 @@ end
---@param match MatchGroupUtilMatch
---@return MatchSummaryBody
function CustomMatchSummary.createBody(match)
local body = MatchSummary.Body()

if match.dateIsExact or match.timestamp ~= DateExt.defaultTimestamp then
-- dateIsExact means we have both date and time. Show countdown
-- if match is not epoch=0, we have a date, so display the date
body:addRow(MatchSummary.Row():addElement(
DisplayHelper.MatchCountdownBlock(match)
))
end

if MatchPage.isEnabledFor(match) then
body.root:node(MatchSummaryWidgets.MatchPageLink{matchId = match.extradata.originalmatchid or match.matchId})
end

-- Iterate each map
for gameIndex, game in ipairs(match.games) do
local rowDisplay = CustomMatchSummary._createGame(game, gameIndex, match.date)
body:addRow(rowDisplay)
end
-- Original Match Id must be used to match page links if it exists.
-- It can be different from the matchId when shortened brackets are used.
local matchId = match.extradata.originalmatchid or match.matchId

-- Add Match MVP(s)
if Table.isNotEmpty(match.extradata.mvp) then
body.root:node(MatchSummaryWidgets.Mvp{
players = match.extradata.mvp.players,
points = match.extradata.mvp.points,
})
end

-- Add the Character Bans
local showCountdown = match.timestamp ~= DateExt.defaultTimestamp
local showMatchPage = MatchPage.isEnabledFor(match)
local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS)
body.root:node(MatchSummaryWidgets.CharacterBanTable{
bans = characterBansData,
date = match.date,
})

return body
return MatchSummaryWidgets.Body{children = WidgetUtil.collect(
showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil,
showMatchPage and MatchSummaryWidgets.MatchPageLink{matchId = matchId} or nil,
Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date)),
MatchSummaryWidgets.Mvp(match.extradata.mvp),
MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}
)}
end

---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
---@param date string
---@return MatchSummaryRow
function CustomMatchSummary._createGame(game, gameIndex, date)
local row = MatchSummary.Row()
function CustomMatchSummary._createGame(date, game, gameIndex)
local extradata = game.extradata or {}

-- TODO: Change to use participant data
Expand All @@ -95,67 +73,37 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
MatchSummary.buildCharacterList(extradata, 'team2champion', NUM_HEROES_PICK),
}

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

row:addElement(MatchSummaryWidgets.Characters{
flipped = false,
date = date,
characters = characterData[1],
bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''),
})
row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1))
row:addElement(mw.html.create('div')
:addClass('brkts-popup-body-element-vertical-centered')
:wikitext(CustomMatchSummary._createAbbreviation{
title = Logic.isEmpty(game.length) and ('Game ' .. gameIndex .. ' picks') or 'Match Length',
text = Logic.isEmpty(game.length) and ('Game ' .. gameIndex) or game.length,
})
)
row:addElement(CustomMatchSummary._createCheckMark(game.winner == 2))
row:addElement(MatchSummaryWidgets.Characters{
flipped = true,
date = date,
characters = characterData[2],
bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''),
})

-- Add Comment
if not Logic.isEmpty(game.comment) then
row:addElement(MatchSummary.Break():create())
local comment = mw.html.create('div')
comment:wikitext(game.comment)
:css('margin', 'auto')
row:addElement(comment)
end

return row
end

---@param isWinner boolean?
---@return Html
function CustomMatchSummary._createCheckMark(isWinner)
local container = mw.html.create('div')
:addClass('brkts-popup-body-element-vertical-centered')
:css('line-height', '17px')
:css('margin-left', '1%')
:css('margin-right', '1%')

if Logic.readBool(isWinner) then
container:node(GREEN_CHECK)
else
container:node(NO_CHECK)
end

return container
end

---@param args table
---@return string
function CustomMatchSummary._createAbbreviation(args)
return '<i><abbr title="' .. args.title .. '">' .. args.text .. '</abbr></i>'
-- Map Comment
local comment = Logic.isNotEmpty(game.comment) and {
MatchSummaryWidgets.Break{},
HtmlWidgets.Div{css = {margin = 'auto'}, children = game.comment},
} or {}

return MatchSummaryWidgets.Row{
classes = {'brkts-popup-body-game'},
css = {['font-size'] = '80%', padding = '4px', ['min-height'] = '32px'},
children = {
MatchSummaryWidgets.Characters{
flipped = false,
characters = characterData[1],
bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''),
date = date,
},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1},
HtmlWidgets.Div{
classes = {'brkts-popup-body-element-vertical-centered'},
children = {Logic.isNotEmpty(game.length) and game.length or ('Game ' .. gameIndex)},
},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2},
MatchSummaryWidgets.Characters{
flipped = true,
characters = characterData[2],
bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''),
date = date,
},
unpack(comment)
}
}
end

return CustomMatchSummary
Loading
Loading