Skip to content

Commit

Permalink
Update aov, cod and halo MS (#3324)
Browse files Browse the repository at this point in the history
* sort requires & remove leading underscore for const vars

* aov

* anno refines for brawlstars

* cod

* cod: remove redundant

* halo

* remove unused requires

* kick redundant

* kick redundant

* as per review in #3330
  • Loading branch information
hjpalpha authored Oct 4, 2023
1 parent 46c9b55 commit 3270450
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 194 deletions.
125 changes: 59 additions & 66 deletions components/match2/wikis/arenaofvalor/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,32 @@

local CustomMatchSummary = {}

local Array = require('Module:Array')
local ChampionIcon = require('Module:HeroIcon')
local Class = require('Module:Class')
local DisplayHelper = require('Module:MatchGroup/Display/Helper')
local ExternalLinks = require('Module:ExternalLinks')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local ChampionIcon = require('Module:HeroIcon')
local Table = require('Module:Table')
local ExternalLinks = require('Module:ExternalLinks')
local String = require('Module:StringUtils')
local Array = require('Module:Array')
local Table = require('Module:Table')

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 _MAX_NUM_BANS = 5
local _NUM_CHAMPIONS_PICK = 5
local MAX_NUM_BANS = 5
local NUM_CHAMPIONS_PICK = 5

local _GREEN_CHECK = '[[File:GreenCheck.png|14x14px|link=]]'
local _NO_CHECK = '[[File:NoCheck.png|link=]]'
local GREEN_CHECK = '[[File:GreenCheck.png|14x14px|link=]]'
local NO_CHECK = '[[File:NoCheck.png|link=]]'

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'

-- Champion Ban Class
---@class AovChampionBan: MatchSummaryRowInterface
---@operator call: AovChampionBan
---@field root Html
---@field table Html
local ChampionBan = Class.new(
function(self)
self.root = mw.html.create('div'):addClass('brkts-popup-mapveto')
Expand All @@ -40,6 +43,7 @@ local ChampionBan = Class.new(
end
)

---@return self
function ChampionBan:createHeader()
self.table:tag('tr')
:tag('th'):css('width','40%'):wikitext(''):done()
Expand All @@ -48,6 +52,11 @@ function ChampionBan:createHeader()
return self
end

---@param banData {numberOfBans: integer, [1]: table, [2]: table}
---@param gameNumber integer
---@param numberOfBans integer
---@param date string
---@return self
function ChampionBan:banRow(banData, gameNumber, numberOfBans, date)
self.table:tag('tr')
:tag('td')
Expand All @@ -64,66 +73,36 @@ function ChampionBan:banRow(banData, gameNumber, numberOfBans, date)
return self
end

---@return Html
function ChampionBan: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('420px')

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

if match.comment then
local comment = MatchSummary.Comment():content(match.comment)
matchSummary:comment(comment)
end

local vods = {}
for index, game in ipairs(match.games) do
if game.vod then
vods[index] = game.vod
end
end

match.links.lrthread = match.lrthread
match.links.vod = match.vod
if not Table.isEmpty(vods) or not Table.isEmpty(match.links) then
local footer = MatchSummary.Footer()

-- Game Vods
for index, vod in pairs(vods) do
match.links['vodgame' .. index] = vod
end

footer.inner = mw.html.create('div')
:addClass('bracket-popup-footer plainlinks vodlink')
:node(ExternalLinks.print(match.links))

matchSummary:footer(footer)
end

return matchSummary:create()
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, {width = '420px'})
end

function CustomMatchSummary._createHeader(match)
local header = MatchSummary.Header()
---@param match MatchGroupUtilMatch
---@param footer MatchSummaryFooter
---@return MatchSummaryFooter
function CustomMatchSummary.addToFooter(match, footer)
footer = MatchSummary.addVodsToFooter(match, footer)

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'))
if Table.isNotEmpty(match.links) then
footer:addElement(ExternalLinks.print(match.links))
end

return header
return footer
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 @@ -157,10 +136,10 @@ function CustomMatchSummary._createBody(match)
-- Pre-Process Champion Ban Data
local championBanData = {}
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 @@ -193,13 +172,17 @@ function CustomMatchSummary._createBody(match)
return body
end

---@param game MatchGroupUtilGame
---@param gameIndex integer
---@param date string
---@return MatchSummaryRow?
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
for champIndex = 1, NUM_CHAMPIONS_PICK do
if String.isNotEmpty(extradata['team1champion' .. champIndex]) then
championsData[1][champIndex] = extradata['team1champion' .. champIndex]
championsDataIsEmpty = false
Expand All @@ -224,7 +207,7 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
:css('font-size', '85%')
:css('overflow', 'hidden')

row:addElement(CustomMatchSummary._opponentChampionsDisplay(championsData[1], _NUM_CHAMPIONS_PICK, date, false))
row:addElement(CustomMatchSummary._opponentChampionsDisplay(championsData[1], NUM_CHAMPIONS_PICK, date, false))
row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1))
row:addElement(mw.html.create('div')
:addClass('brkts-popup-body-element-vertical-centered')
Expand All @@ -234,7 +217,7 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
})
)
row:addElement(CustomMatchSummary._createCheckMark(game.winner == 2))
row:addElement(CustomMatchSummary._opponentChampionsDisplay(championsData[2], _NUM_CHAMPIONS_PICK, date, true))
row:addElement(CustomMatchSummary._opponentChampionsDisplay(championsData[2], NUM_CHAMPIONS_PICK, date, true))

-- Add Comment
if not Logic.isEmpty(game.comment) then
Expand All @@ -248,6 +231,8 @@ function CustomMatchSummary._createGame(game, gameIndex, date)
return row
end

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

if 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 opponentChampionsData table
---@param numberOfChampions integer
---@param date string
---@param flip boolean?
---@param isBan boolean?
---@return Html
function CustomMatchSummary._opponentChampionsDisplay(opponentChampionsData, numberOfChampions, date, flip, isBan)
local opponentChampionsDisplay = {}
local color = opponentChampionsData.color or ''
Expand Down
16 changes: 8 additions & 8 deletions components/match2/wikis/brawlstars/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ local Brawler = Class.new(
end
)

---@return BrawlstarsMatchSummaryBrawler
---@return self
function Brawler:createHeader()
self.table:tag('tr')
:tag('th'):css('width','35%'):wikitext(''):done()
Expand All @@ -75,7 +75,7 @@ end
---@param numberBrawlers integer
---@param date string
---@param firstPick integer?
---@return BrawlstarsMatchSummaryBrawler
---@return self
function Brawler:row(brawlerData, gameNumber, numberBrawlers, date, firstPick)
if numberBrawlers > 0 then
self.table:tag('tr')
Expand Down Expand Up @@ -162,7 +162,7 @@ function CustomMatchSummary.getByMatchId(args)
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args)
end

---@param match table
---@param match MatchGroupUtilMatch
---@param footer MatchSummaryFooter
---@return MatchSummaryFooter
function CustomMatchSummary.addToFooter(match, footer)
Expand All @@ -172,7 +172,7 @@ function CustomMatchSummary.addToFooter(match, footer)
return footer:addLinks(LINK_DATA, match.links)
end

---@param match table
---@param match MatchGroupUtilMatch
---@return MatchSummaryBody
function CustomMatchSummary.createBody(match)
local body = MatchSummary.Body()
Expand Down Expand Up @@ -242,7 +242,7 @@ function CustomMatchSummary.createBody(match)
-- Pre-Process Brawler bans
local showGameBans = {}
for gameIndex, game in ipairs(match.games) do
local extradata = game.extradata
local extradata = game.extradata or {}
local bans = Json.parseIfString(extradata.bans or '{}')
if not Table.isEmpty(bans) then
bans.numberOfBans = math.max(#bans.team1, #bans.team2)
Expand All @@ -268,15 +268,15 @@ function CustomMatchSummary.createBody(match)
return body
end

---@param game table
---@param game MatchGroupUtilGame
---@param opponentIndex integer
---@return Html
function CustomMatchSummary._gameScore(game, opponentIndex)
local score = game.scores[opponentIndex] or ''
return htmlCreate('div'):wikitext(score)
end

---@param game table
---@param game MatchGroupUtilGame
---@return MatchSummaryRow
function CustomMatchSummary._createMapRow(game)
local row = MatchSummary.Row()
Expand Down Expand Up @@ -330,7 +330,7 @@ function CustomMatchSummary._createMapRow(game)
return row
end

---@param game table
---@param game MatchGroupUtilGame
---@return string
function CustomMatchSummary._getMapDisplay(game)
local mapDisplay = '[[' .. game.map .. ']]'
Expand Down
Loading

0 comments on commit 3270450

Please sign in to comment.