Skip to content

Commit

Permalink
Update dota, lol and splatoon MatchSummary (#3334)
Browse files Browse the repository at this point in the history
* remove leading underscore from const vars

* lol

* fix width (lol)

* dota2

* require correct module & remove unused requires & shut up anno

* splatoon

* as per review in #3330
  • Loading branch information
hjpalpha authored Oct 4, 2023
1 parent 0c73ab8 commit d178f36
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 223 deletions.
150 changes: 68 additions & 82 deletions components/match2/wikis/dota2/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@ local HeroIcon = require('Module:HeroIcon')
local Table = require('Module:Table')
local String = require('Module:StringUtils')
local Array = require('Module:Array')
local VodLink = require('Module:VodLink')

local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper', {requireDevIfEnabled = true})
local MatchGroupUtil = Lua.import('Module:MatchGroup/Util', {requireDevIfEnabled = true})
local MatchSummary = Lua.import('Module:MatchSummary/Base', {requireDevIfEnabled = true})
local MatchSummary = Lua.import('Module:MatchSummary/Base/temp', {requireDevIfEnabled = true})
local Opponent = Lua.import('Module:Opponent', {requireDevIfEnabled = true})

local _MAX_NUM_BANS = 7
local _NUM_HEROES_PICK_TEAM = 5
local _NUM_HEROES_PICK_SOLO = 1
local _SIZE_HERO = '57x32px'
local _GREEN_CHECK = '[[File:GreenCheck.png|14x14px|link=]]'
local _NO_CHECK = '[[File:NoCheck.png|link=]]'
local MAX_NUM_BANS = 7
local NUM_HEROES_PICK_TEAM = 5
local NUM_HEROES_PICK_SOLO = 1
local SIZE_HERO = '57x32px'
local GREEN_CHECK = '[[File:GreenCheck.png|14x14px|link=]]'
local NO_CHECK = '[[File:NoCheck.png|link=]]'
-- Normal links, from input/lpdb
local _LINK_DATA = {
local LINK_DATA = {
vod = {icon = 'File:VOD Icon.png', text = 'Watch VOD'},
preview = {icon = 'File:Preview Icon32.png', text = 'Preview'},
lrthread = {icon = 'File:LiveReport32.png', text = 'Live Report Thread'},
Expand All @@ -38,7 +36,7 @@ local _LINK_DATA = {
faceit = {icon = 'File:FACEIT-icon.png', text = 'FACEIT match room'},
}
-- Auto generated links from Publisher ID
local _AUTO_LINKS = {
local AUTO_LINKS = {
{icon = 'File:DOTABUFF-icon.png', url = 'https://www.dotabuff.com/matches/', name = 'DOTABUFF'},
{icon = 'File:DatDota-icon.png', url = 'https://www.datdota.com/matches/', name = 'datDota'},
{
Expand All @@ -49,10 +47,14 @@ local _AUTO_LINKS = {
},
}

local _EPOCH_TIME = '1970-01-01 00:00:00'
local _EPOCH_TIME_EXTENDED = '1970-01-01T00:00:00+00:00'
local EPOCH_TIME = '1970-01-01 00:00:00'
local EPOCH_TIME_EXTENDED = '1970-01-01T00:00:00+00:00'

-- Hero Ban Class
---@class DotaHeroBan: MatchSummaryRowInterface
---@operator call: DotaHeroBan
---@field root Html
---@field table Html
local HeroBan = Class.new(
function(self)
self.root = mw.html.create('div'):addClass('brkts-popup-mapveto')
Expand All @@ -62,6 +64,7 @@ local HeroBan = Class.new(
end
)

---@return self
function HeroBan:createHeader()
self.table:tag('tr')
:tag('th'):css('width','35%'):wikitext(''):done()
Expand All @@ -70,6 +73,10 @@ function HeroBan:createHeader()
return self
end

---@param banData {numberOfBans: integer, [1]: table, [2]: table}
---@param gameNumber integer
---@param numberOfBans integer
---@return self
function HeroBan:banRow(banData, gameNumber, numberOfBans)
self.table:tag('tr')
:tag('td'):attr('rowspan', '2'):node(mw.html.create('div')
Expand All @@ -88,36 +95,23 @@ function HeroBan:banRow(banData, gameNumber, numberOfBans)
return self
end

---@return Html
function HeroBan:create()
return self.root
end


---@param args table
---@return Html
function CustomMatchSummary.getByMatchId(args)
local match = MatchGroupUtil.fetchMatchForBracketDisplay(args.bracketId, args.matchId)

local matchSummary = MatchSummary():init('400px')

matchSummary:header(CustomMatchSummary._createHeader(match))
:body(CustomMatchSummary._createBody(match))

if match.comment then
local comment = MatchSummary.Comment():content(match.comment)
matchSummary:comment(comment)
end
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, {width = '400px'})
end

local vods = {}
local publisherids = {}
for index, game in ipairs(match.games) do
if not Logic.isEmpty(game.vod) then
vods[index] = game.vod
end
if not String.isEmpty(game.extradata.publisherid) then
publisherids[index] = game.extradata.publisherid
end
end
---@param match MatchGroupUtilMatch
---@param footer MatchSummaryFooter
---@return MatchSummaryFooter
function CustomMatchSummary.addToFooter(match, footer)
footer = MatchSummary.addVodsToFooter(match, footer)

match.links.vod = match.vod
if
Logic.readBool(match.extradata.headtohead) and
match.opponents[1].type == Opponent.team and
Expand All @@ -128,49 +122,29 @@ function CustomMatchSummary.getByMatchId(args)
'?pfRunQueryFormName=Match+history&Head_to_head_query%5Bplayer%5D=' .. team1 ..
'&Head_to_head_query%5Bopponent%5D=' .. team2 .. '&wpRunQuery=Run+query'
end
if not Table.isEmpty(vods) or not Table.isEmpty(publisherids) or not Table.isEmpty(match.links) then
local footer = MatchSummary.Footer()

-- Game Vods
for index, vod in pairs(vods) do
footer:addElement(VodLink.display{
gamenum = index,
vod = vod,
source = vod.url
})
end

for _, site in ipairs(_AUTO_LINKS) do
for index, publisherid in pairs(publisherids) do
local link = site.url .. publisherid
local text = 'Game '..index..' on '.. site.name
footer:addLink(link, site.icon, site.iconDark, text)
end
end

footer:addLinks(_LINK_DATA, match.links)

matchSummary:footer(footer)
end

return matchSummary:create()
end
local publisherIds = {}
Array.forEach(match.games, function(game, gameIndex)
publisherIds[gameIndex] = Logic.emptyOr(game.extradata.publisherid)
end)

function CustomMatchSummary._createHeader(match)
local header = MatchSummary.Header()

header:leftOpponent(header:createOpponent(match.opponents[1], 'left', 'bracket'))
:leftScore(header:createScore(match.opponents[1]))
:rightScore(header:createScore(match.opponents[2]))
:rightOpponent(header:createOpponent(match.opponents[2], 'right', 'bracket'))
Array.forEach(AUTO_LINKS, function(siteData)
for index, publisherId in pairs(publisherIds) do
local link = siteData.url .. publisherId
local text = 'Game ' .. index .. ' on ' .. siteData.name
footer:addLink(link, siteData.icon, siteData.iconDark, text)
end
end)

return header
return footer:addLinks(LINK_DATA, match.links)
end

function CustomMatchSummary._createBody(match)
---@param match MatchGroupUtilMatch
---@return MatchSummaryBody
function CustomMatchSummary.createBody(match)
local body = MatchSummary.Body()

if match.dateIsExact or (match.date ~= _EPOCH_TIME_EXTENDED and match.date ~= _EPOCH_TIME) then
if match.dateIsExact or (match.date ~= EPOCH_TIME_EXTENDED and match.date ~= EPOCH_TIME) 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(
Expand Down Expand Up @@ -202,10 +176,10 @@ function CustomMatchSummary._createBody(match)
-- Pre-Process Hero Ban Data
local showGameBans = {}
for gameIndex, game in ipairs(match.games) do
local extradata = game.extradata
local extradata = game.extradata or {}
local banData = {{}, {}}
local numberOfBans = 0
for index = 1, _MAX_NUM_BANS do
for index = 1, MAX_NUM_BANS do
if String.isNotEmpty(extradata['team1ban' .. index]) then
numberOfBans = index
banData[1][index] = extradata['team1ban' .. index]
Expand Down Expand Up @@ -241,13 +215,16 @@ function CustomMatchSummary._createBody(match)
return body
end

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

local numberOfHeroes = _NUM_HEROES_PICK_TEAM
local numberOfHeroes = NUM_HEROES_PICK_TEAM
if game.mode == Opponent.solo then
numberOfHeroes = _NUM_HEROES_PICK_SOLO
numberOfHeroes = NUM_HEROES_PICK_SOLO
end
local heroesData = {{}, {}}
for heroIndex = 1, numberOfHeroes do
Expand All @@ -270,8 +247,8 @@ function CustomMatchSummary._createGame(game, gameIndex)
row:addElement(mw.html.create('div')
:addClass('brkts-popup-body-element-vertical-centered')
:wikitext(CustomMatchSummary._createAbbreviation{
title = String.isEmpty(game.length) and ('Game ' .. gameIndex .. ' picks') or 'Match Length',
text = String.isEmpty(game.length) and ('Game ' .. gameIndex) or game.length,
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))
Expand All @@ -289,6 +266,8 @@ function CustomMatchSummary._createGame(game, gameIndex)
return row
end

---@param isWinner boolean?
---@return Html
function CustomMatchSummary._createCheckMark(isWinner)
local container = mw.html.create('div')
:addClass('brkts-popup-spaced')
Expand All @@ -297,18 +276,25 @@ function CustomMatchSummary._createCheckMark(isWinner)
:css('margin-right', '1%')

if Logic.readBool(isWinner) then
container:node(_GREEN_CHECK)
container:node(GREEN_CHECK)
else
container:node(_NO_CHECK)
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>'
end

---@param opponentHeroesData table
---@param numberOfHeroes integer
---@param flip boolean?
---@param isBan boolean?
---@return Html
function CustomMatchSummary._opponentHeroesDisplay(opponentHeroesData, numberOfHeroes, flip, isBan)
local opponentHeroesDisplay = {}
local color = opponentHeroesData.side or ''
Expand All @@ -320,9 +306,9 @@ function CustomMatchSummary._opponentHeroesDisplay(opponentHeroesData, numberOfH
:addClass('brkts-popup-side-hero-hover')
:node(HeroIcon._getImage{
hero = opponentHeroesData[index],
size = _SIZE_HERO,
size = SIZE_HERO,
})
if numberOfHeroes == _NUM_HEROES_PICK_SOLO then
if numberOfHeroes == NUM_HEROES_PICK_SOLO then
if flip then
heroDisplay:css('margin-right', '70px')
else
Expand Down
Loading

0 comments on commit d178f36

Please sign in to comment.