Skip to content

Commit

Permalink
refactor(match2): fully standardize game countdown and games schedule (
Browse files Browse the repository at this point in the history
…#5152)

* refactor(match2): fully standardize game countdown and games schedule

* Update components/widget/match/summary/ffa/widget_match_summary_ffa_games_schedule.lua

* update golden
  • Loading branch information
Rathoz authored Dec 2, 2024
1 parent 741b34e commit 9f2b5c8
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 125 deletions.
28 changes: 1 addition & 27 deletions components/match2/commons/match_summary_ffa.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
--

local Array = require('Module:Array')
local Date = require('Module:Date/Ext')
local FnUtil = require('Module:FnUtil')
local Lua = require('Module:Lua')
local Table = require('Module:Table')
local Timezone = require('Module:Timezone')
local VodLink = require('Module:VodLink')

local OpponentLibraries = require('Module:OpponentLibraries')
local OpponentDisplay = OpponentLibraries.OpponentDisplay
Expand Down Expand Up @@ -290,29 +287,6 @@ local GAME_STANDINGS_COLUMNS = {
},
}


---Creates a countdown block for a given game
---Attaches any VODs of the game as well
---@param game table
---@return Html?
function MatchSummaryFfa.gameCountdown(game)
local timestamp = Date.readTimestamp(game.date)
if not timestamp then
return
end
-- TODO Use local TZ
local dateString = Date.formatTimestamp('F j, Y - H:i', timestamp) .. ' ' .. Timezone.getTimezoneString('UTC')

local stream = Table.merge(game.stream, {
date = dateString,
finished = game.winner ~= nil and 'true' or nil,
})

return mw.html.create('div'):addClass('match-countdown-block')
:node(require('Module:Countdown')._create(stream))
:node(game.vod and VodLink.display{vod = game.vod} or nil)
end

---@param opponent1 table
---@param opponent2 table
---@return boolean
Expand Down Expand Up @@ -445,7 +419,7 @@ function MatchSummaryFfa.standardMatch(match)
}
}
},
MatchSummaryFfa.gameCountdown(game),
MatchSummaryWidgets.GameCountdown{game = game},
}
},
HtmlWidgets.Div{
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/apexlegends/game_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function CustomGameSummary._createGameDetails(game)
classes = {'panel-content__game-schedule__container'},
children = {
MatchSummaryWidgets.CountdownIcon{game = game, additionalClasses = {'panel-content__game-schedule__icon'}},
SummaryHelper.gameCountdown(game),
MatchSummaryWidgets.GameCountdown{game = game},
},
},
},
Expand Down
34 changes: 2 additions & 32 deletions components/match2/wikis/apexlegends/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function CustomMatchSummary.getByMatchId(props)
matchId = match.matchId,
idx = 0,
children = {
CustomMatchSummary._createSchedule(match),
MatchSummaryWidgets.GamesSchedule{games = match.games},
MatchSummaryWidgets.PointsDistribution{killScore = scoringData.kill, placementScore = scoringData.placement},
CustomMatchSummary._createMatchStandings(match)
}
Expand Down Expand Up @@ -257,36 +257,6 @@ function CustomMatchSummary._opponents(match)
end)
end

---@param match table
---@return Widget
function CustomMatchSummary._createSchedule(match)
return MatchSummaryWidgets.ContentItemContainer{collapsed = true, collapsible = true, title = 'Schedule', children = {
HtmlWidgets.Ul{
classes = {'panel-content__game-schedule'},
children = Array.map(match.games, function (game, idx)
return HtmlWidgets.Li{
children = {
HtmlWidgets.Span{
children = MatchSummaryWidgets.CountdownIcon{
game = game,
additionalClasses = {'panel-content__game-schedule__icon'}
},
},
HtmlWidgets.Span{
classes = {'panel-content__game-schedule__title'},
children = 'Game ' .. idx .. ':',
},
HtmlWidgets.Div{
classes = {'panel-content__game-schedule__container'},
children = SummaryHelper.gameCountdown(game),
},
},
}
end)
}
}}
end

---@param match table
---@return Html
function CustomMatchSummary._createMatchStandings(match)
Expand Down Expand Up @@ -372,7 +342,7 @@ function CustomMatchSummary._createMatchStandings(match)
}
}
},
SummaryHelper.gameCountdown(game),
MatchSummaryWidgets.GameCountdown{game = game},
}
},
HtmlWidgets.Div{
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/pubg/game_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function CustomGameSummary._createGameDetails(game)
classes = {'panel-content__game-schedule__container'},
children = {
MatchSummaryWidgets.CountdownIcon{game = game, additionalClasses = {'panel-content__game-schedule__icon'}},
SummaryHelper.gameCountdown(game),
MatchSummaryWidgets.GameCountdown{game = game},
},
},
},
Expand Down
32 changes: 1 addition & 31 deletions components/match2/wikis/pubg/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function CustomMatchSummary.getByMatchId(props)
matchId = match.matchId,
idx = 0,
children = {
CustomMatchSummary._createSchedule(match),
MatchSummaryWidgets.GamesSchedule{games = match.games},
MatchSummaryWidgets.PointsDistribution{killScore = scoringData.kill, placementScore = scoringData.placement},
SummaryHelper.standardMatch(match),
}
Expand All @@ -61,34 +61,4 @@ function CustomMatchSummary._opponents(match)
end)
end

---@param match table
---@return Widget
function CustomMatchSummary._createSchedule(match)
return MatchSummaryWidgets.ContentItemContainer{collapsed = true, collapsible = true, title = 'Schedule', children = {
HtmlWidgets.Ul{
classes = {'panel-content__game-schedule'},
children = Array.map(match.games, function (game, idx)
return HtmlWidgets.Li{
children = {
HtmlWidgets.Span{
children = MatchSummaryWidgets.CountdownIcon{
game = game,
additionalClasses = {'panel-content__game-schedule__icon'}
},
},
HtmlWidgets.Span{
classes = {'panel-content__game-schedule__title'},
children = 'Game ' .. idx .. ':',
},
HtmlWidgets.Div{
classes = {'panel-content__game-schedule__container'},
children = SummaryHelper.gameCountdown(game),
},
},
}
end)
}
}}
end

return CustomMatchSummary
2 changes: 1 addition & 1 deletion components/match2/wikis/pubgmobile/game_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function CustomGameSummary._createGameDetails(game)
classes = {'panel-content__game-schedule__container'},
children = {
MatchSummaryWidgets.CountdownIcon{game = game, additionalClasses = {'panel-content__game-schedule__icon'}},
SummaryHelper.gameCountdown(game),
MatchSummaryWidgets.GameCountdown{game = game},
},
},
},
Expand Down
32 changes: 1 addition & 31 deletions components/match2/wikis/pubgmobile/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function CustomMatchSummary.getByMatchId(props)
matchId = match.matchId,
idx = 0,
children = {
CustomMatchSummary._createSchedule(match),
MatchSummaryWidgets.GamesSchedule{games = match.games},
MatchSummaryWidgets.PointsDistribution{killScore = scoringData.kill, placementScore = scoringData.placement},
SummaryHelper.standardMatch(match),
}
Expand All @@ -61,34 +61,4 @@ function CustomMatchSummary._opponents(match)
end)
end

---@param match table
---@return Widget
function CustomMatchSummary._createSchedule(match)
return MatchSummaryWidgets.ContentItemContainer{collapsed = true, collapsible = true, title = 'Schedule', children = {
HtmlWidgets.Ul{
classes = {'panel-content__game-schedule'},
children = Array.map(match.games, function (game, idx)
return HtmlWidgets.Li{
children = {
HtmlWidgets.Span{
children = MatchSummaryWidgets.CountdownIcon{
game = game,
additionalClasses = {'panel-content__game-schedule__icon'}
},
},
HtmlWidgets.Span{
classes = {'panel-content__game-schedule__title'},
children = 'Game ' .. idx .. ':',
},
HtmlWidgets.Div{
classes = {'panel-content__game-schedule__container'},
children = SummaryHelper.gameCountdown(game),
},
},
}
end)
}
}}
end

return CustomMatchSummary
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ local Lua = require('Module:Lua')

Widgets.ContentItemContainer = Lua.import('Module:Widget/Match/Summary/Ffa/ContentItemContainer')
Widgets.CountdownIcon = Lua.import('Module:Widget/Match/Summary/Ffa/CountdownIcon')
Widgets.GameCountdown = Lua.import('Module:Widget/Match/Summary/Ffa/GameCountdown')
Widgets.GamesSchedule = Lua.import('Module:Widget/Match/Summary/Ffa/GamesSchedule')
Widgets.Header = Lua.import('Module:Widget/Match/Summary/Ffa/Header')
Widgets.PointsDistribution = Lua.import('Module:Widget/Match/Summary/Ffa/PointsDistribution')
Widgets.RankRange = Lua.import('Module:Widget/Match/Summary/Ffa/RankRange')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
-- @Liquipedia
-- wiki=commons
-- page=Module:Widget/Match/Summary/Ffa/GameCountdown
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Class = require('Module:Class')
local Date = require('Module:Date/Ext')
local Lua = require('Module:Lua')
local Table = require('Module:Table')
local Timezone = require('Module:Timezone')
local VodLink = require('Module:VodLink')

local Widget = Lua.import('Module:Widget')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')

---@class MatchSummaryFfaGameCountdown: Widget
---@operator call(table): MatchSummaryFfaGameCountdown
local MatchSummaryFfaGameCountdown = Class.new(Widget)

---@return Widget?
function MatchSummaryFfaGameCountdown:render()
local game = self.props.game
if not game then
return nil
end

local timestamp = Date.readTimestamp(game.date)
if not timestamp then
return
end
-- TODO Use local TZ
local dateString = Date.formatTimestamp('F j, Y - H:i', timestamp) .. ' ' .. Timezone.getTimezoneString('UTC')

local streamParameters = Table.merge(game.stream, {
date = dateString,
finished = game.winner ~= nil and 'true' or nil,
})

return HtmlWidgets.Div{
classes = {'match-countdown-block'},
children = {
require('Module:Countdown')._create(streamParameters),
game.vod and VodLink.display{vod = game.vod} or nil,
},
}
end

return MatchSummaryFfaGameCountdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
-- @Liquipedia
-- wiki=commons
-- page=Module:Widget/Match/Summary/Ffa/GamesSchedule
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Array = require('Module:Array')
local Class = require('Module:Class')
local Lua = require('Module:Lua')

local Widget = Lua.import('Module:Widget')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')
local ContentItemContainer = Lua.import('Module:Widget/Match/Summary/Ffa/ContentItemContainer')
local CountdownIcon = Lua.import('Module:Widget/Match/Summary/Ffa/CountdownIcon')
local GameCountdown = Lua.import('Module:Widget/Match/Summary/Ffa/GameCountdown')

---@class MatchSummaryFfaGamesSchedule: Widget
---@operator call(table): MatchSummaryFfaGamesSchedule
local MatchSummaryFfaGamesSchedule = Class.new(Widget)

---@return Widget?
function MatchSummaryFfaGamesSchedule:render()
if not self.props.games or #self.props.games == 0 then
return nil
end

return ContentItemContainer{collapsed = true, collapsible = true, title = 'Schedule', children = {
HtmlWidgets.Ul{
classes = {'panel-content__game-schedule'},
children = Array.map(self.props.games, function (game, idx)
return HtmlWidgets.Li{
children = {
HtmlWidgets.Span{
children = CountdownIcon{
game = game,
additionalClasses = {'panel-content__game-schedule__icon'}
},
},
HtmlWidgets.Span{
classes = {'panel-content__game-schedule__title'},
children = 'Game ' .. idx .. ':',
},
HtmlWidgets.Div{
classes = {'panel-content__game-schedule__container'},
children = GameCountdown{game = game},
},
},
}
end)
}
}}
end

return MatchSummaryFfaGamesSchedule
Loading

0 comments on commit 9f2b5c8

Please sign in to comment.