Skip to content

Commit

Permalink
MatchSummary for Tetris (#2480)
Browse files Browse the repository at this point in the history
* MatchSummary for Tetris

* 1st update

- Fix Abbreviation and Libraries unused variables
- I dont know how to tackle LINK_DATA, this  will come solved in 2nd update

* kick unused; refine opponent lib require

* cleanup

* more cleanup

* fontsize & unsued loop var

* check for vod when displaying links

* update to use Base/temp

* Update match_summary.lua

---------

Co-authored-by: hjpalpha <[email protected]>
Co-authored-by: hjpalpha <[email protected]>
  • Loading branch information
3 people authored Oct 13, 2023
1 parent dd49ba9 commit e43f7d6
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions components/match2/wikis/tetris/match_summary.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
-- @Liquipedia
-- wiki=tetris
-- page=Module:MatchSummary
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Array = require('Module:Array')
local DateExt = require('Module:Date/Ext')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')

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

local Opponent = require('Module:OpponentLibraries').Opponent

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

local CustomMatchSummary = {}

---@param args table
---@return Html
function CustomMatchSummary.getByMatchId(args)
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, {width = '400px'})
end

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

if match.dateIsExact or (match.timestamp ~= DateExt.epochZero) 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 Array.any(match.opponents, function(opponent) return opponent.type == Opponent.team end) then
error('Team matches not yet supported')
-- todo (in sep PR): team match submatch support
--return CustomMatchSummary._createTeamMatchBody(body, match)
end

-- Iterate each map
for _, game in ipairs(match.games) do
body:addRow(CustomMatchSummary._createGame(game))
end

return body
end

---@param game MatchGroupUtilGame
---@return MatchSummaryRow
function CustomMatchSummary._createGame(game)
local row = MatchSummary.Row()

row:addClass('brkts-popup-body-game')
:css('font-size', '84%')
:css('padding', '4px')
:css('min-height', '32px')
row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1))
row:addElement(mw.html.create('div')
:addClass('brkts-popup-body-element-vertical-centered')
:wikitext(game.map)
)
row:addElement(CustomMatchSummary._createCheckMark(game.winner == 2))

-- Add Comment
if not Logic.isEmpty(game.comment) then
row:addElement(MatchSummary.Break():create())
row:addElement(mw.html.create('div')
:wikitext(game.comment)
:css('margin', 'auto')
)
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

return CustomMatchSummary

0 comments on commit e43f7d6

Please sign in to comment.