-
Notifications
You must be signed in to change notification settings - Fork 104
feat(MatchTicker): add new match ticker display style #4363
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
afc6934
Adding dota2 filter styles
0b53e5d
Fixing pipeline
83f9e64
Merge branch 'main' into ticker-custom-dota
1e5b185
Adding new match ticker display component
2e25434
Reverting previous changes
701a006
Reverting previous changes
8dc6b77
Fixing pipeline
fe9cdba
Adding stream links + removing unused logic
c639faa
Fixing pipeline
5b446a7
Renaming class
759a32e
Reusing Versus + adding comments
05a3064
Implementing feedbacks
386255c
Refactoring stream display logic
3178186
Fixing pipeline
65fc469
Update components/match_ticker/commons/match_ticker_display_component…
Nadoxis 34154fc
Extracting factory
659ddbe
Merge branch 'ticker-custom-dota' of github.com:Liquipedia/Lua-Module…
91fe53c
Using new stream links logic
05b51a0
Merge branch 'main' into ticker-custom-dota
372e5b0
Moving Factory + Fixing CI
f4961de
Update components/match_ticker/commons/match_ticker_display_component…
Nadoxis ec3813d
Removing unused variable
985333e
Merge branch 'main' into ticker-custom-dota
Nadoxis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
240 changes: 240 additions & 0 deletions
240
components/match_ticker/commons/match_ticker_display_components_new.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,240 @@ | ||
| --- | ||
hjpalpha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| -- @Liquipedia | ||
| -- wiki=commons | ||
| -- page=Module:MatchTicker/DisplayComponents/New | ||
| -- | ||
| -- Please see https://github.com/Liquipedia/Lua-Modules to contribute | ||
| -- | ||
|
|
||
| -- Holds DisplayComponents for the MatchTicker module | ||
| -- It contains the new html structure intented to be use for the new Dota2 Main Page (for now) | ||
| -- Will most likely be expanded to other games in the future and other pages | ||
|
|
||
| local Class = require('Module:Class') | ||
| local Countdown = require('Module:Countdown') | ||
| local DateExt = require('Module:Date/Ext') | ||
| local LeagueIcon = require('Module:LeagueIcon') | ||
| local Logic = require('Module:Logic') | ||
| local Lua = require('Module:Lua') | ||
| local Timezone = require('Module:Timezone') | ||
| local StreamLinks = require('Module:Links/Stream') | ||
| local Page = require('Module:Page') | ||
| local DefaultMatchTickerDisplayComponents = require('Module:MatchTicker/DisplayComponents') | ||
|
|
||
| local HighlightConditions = Lua.import('Module:HighlightConditions') | ||
|
|
||
| local OpponentLibraries = require('Module:OpponentLibraries') | ||
| local Opponent = OpponentLibraries.Opponent | ||
| local OpponentDisplay = OpponentLibraries.OpponentDisplay | ||
|
|
||
| local CURRENT_PAGE = mw.title.getCurrentTitle().text | ||
| local HIGHLIGHT_CLASS = 'tournament-highlighted-bg' | ||
| local TOURNAMENT_DEFAULT_ICON = 'Generic_Tournament_icon.png' | ||
|
|
||
| ---Display class for matches shown within a match ticker | ||
| ---@class NewMatchTickerScoreBoard | ||
| ---@operator call(table): NewMatchTickerScoreBoard | ||
| ---@field root Html | ||
| ---@field match table | ||
| local ScoreBoard = Class.new( | ||
| function(self, match) | ||
| self.root = mw.html.create('div'):addClass('match-scoreboard') | ||
| self.match = match | ||
| end | ||
| ) | ||
|
|
||
| ---@return Html | ||
| function ScoreBoard:create() | ||
| local match = self.match | ||
| local winner = tonumber(match.winner) | ||
|
|
||
| return self.root | ||
| :node(self:opponent(match.match2opponents[1], winner == 1, true):addClass('team-left')) | ||
| :node(self:versus()) | ||
| :node(self:opponent(match.match2opponents[2], winner == 2):addClass('team-right')) | ||
| end | ||
|
|
||
| ---@param opponentData table | ||
| ---@param isWinner boolean | ||
| ---@param flip boolean? | ||
| ---@return Html | ||
| function ScoreBoard:opponent(opponentData, isWinner, flip) | ||
| local opponent = Opponent.fromMatch2Record(opponentData) | ||
| ---@cast opponent -nil | ||
| if Opponent.isEmpty(opponent) or Opponent.isTbd(opponent) and opponent.type ~= Opponent.literal then | ||
| opponent = Opponent.tbd(Opponent.literal) | ||
| end | ||
|
|
||
| local opponentName = Opponent.toName(opponent) | ||
| if not opponentName then | ||
| mw.logObject(opponent, 'Invalid Opponent, Opponent.toName returns nil') | ||
| opponentName = '' | ||
| end | ||
|
|
||
| local opponentDisplay = mw.html.create('div') | ||
| :node(OpponentDisplay.InlineOpponent{ | ||
| opponent = opponent, | ||
| teamStyle = 'short', | ||
| flip = flip, | ||
| showLink = opponentName:gsub('_', ' ') ~= CURRENT_PAGE | ||
| }) | ||
|
|
||
| if isWinner then | ||
| opponentDisplay:addClass('match-winner') | ||
| end | ||
|
|
||
| return opponentDisplay | ||
| end | ||
|
|
||
| ---@return Html | ||
| function ScoreBoard:versus() | ||
| return mw.html.create('div') | ||
| :addClass('versus') | ||
| :node(DefaultMatchTickerDisplayComponents.Versus(self.match):create()) | ||
| end | ||
|
|
||
| ---Display class for the details of a match displayed at the bottom of a match ticker | ||
| ---@class NewMatchTickerDetails | ||
| ---@operator call(table): NewMatchTickerMatch | ||
| ---@field root Html | ||
| ---@field hideTournament boolean | ||
| ---@field onlyHighlightOnValue string? | ||
| ---@field match table | ||
| local Details = Class.new( | ||
| function(self, args) | ||
| assert(args.match, 'No Match passed to MatchTickerDetails class') | ||
| self.root = mw.html.create('div'):addClass('match-details') | ||
| self.hideTournament = args.hideTournament | ||
| self.onlyHighlightOnValue = args.onlyHighlightOnValue | ||
| self.match = args.match | ||
| end | ||
| ) | ||
|
|
||
| ---@return Html | ||
| function Details:create() | ||
| local highlightCondition = HighlightConditions.match or HighlightConditions.tournament | ||
| if highlightCondition(self.match, {onlyHighlightOnValue = self.onlyHighlightOnValue}) then | ||
| self.root:addClass(HIGHLIGHT_CLASS) | ||
| end | ||
|
|
||
| return self.root | ||
| :node(self:streams()) | ||
| :node(self:tournament()) | ||
| :node(self:countdown()) | ||
| end | ||
|
|
||
| ---It will display both countdown and date of the match so the user can select which one to show | ||
| ---@return Html | ||
| function Details:countdown() | ||
| local match = self.match | ||
|
|
||
| local dateString | ||
| if Logic.readBool(match.dateexact) then | ||
| local timestamp = DateExt.readTimestamp(match.date) + (Timezone.getOffset(match.extradata.timezoneid) or 0) | ||
| dateString = DateExt.formatTimestamp('F j, Y - H:i', timestamp) .. ' ' | ||
| .. (Timezone.getTimezoneString(match.extradata.timezoneid) or (Timezone.getTimezoneString('UTC'))) | ||
| else | ||
| dateString = mw.getContentLanguage():formatDate('F j, Y', match.date) .. (Timezone.getTimezoneString('UTC')) | ||
Nadoxis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| local countdownArgs = { | ||
| date = dateString, | ||
| finished = match.finished | ||
| } | ||
|
|
||
| local countdownDisplay = mw.html.create('span') | ||
| :addClass('match-countdown') | ||
| :node(Countdown._create(countdownArgs)) | ||
|
|
||
| return countdownDisplay | ||
| end | ||
|
|
||
| ---@return Html? | ||
| function Details:streams() | ||
| local match = self.match | ||
| local links = mw.html.create('div') | ||
| :addClass('match-streams') | ||
|
|
||
| links:wikitext(table.concat(StreamLinks.buildDisplays(StreamLinks.filterStreams(match.stream)) or {})) | ||
|
|
||
| return links | ||
| end | ||
|
|
||
| ---@return Html? | ||
| function Details:tournament() | ||
| if self.hideTournament then | ||
| return | ||
| end | ||
|
|
||
| local match = self.match | ||
|
|
||
| local icon = LeagueIcon.display{ | ||
| icon = Logic.emptyOr(match.icon, TOURNAMENT_DEFAULT_ICON), | ||
| iconDark = match.icondark, | ||
| link = match.pagename, | ||
| name = match.tournament, | ||
| options = {noTemplate = true}, | ||
| } | ||
|
|
||
| local displayName = Logic.emptyOr( | ||
| match.tickername, | ||
| match.tournament, | ||
| match.parent:gsub('_', ' ') | ||
| ) | ||
|
|
||
| return mw.html.create('div') | ||
| :addClass('match-tournament') | ||
| :node(mw.html.create('div') | ||
| :addClass('tournament-icon') | ||
| :node(mw.html.create('div') | ||
| :wikitext(icon) | ||
| ) | ||
| ) | ||
| :node(mw.html.create('div') | ||
| :addClass('tournament-text') | ||
| :wikitext(Page.makeInternalLink({}, displayName, match.pagename)) | ||
| ) | ||
|
|
||
| end | ||
|
|
||
| ---Display class for matches shown within a match ticker | ||
| ---@class NewMatchTickerMatch | ||
| ---@operator call({config: MatchTickerConfig, match: table}): NewMatchTickerMatch | ||
| ---@field root Html | ||
| ---@field config MatchTickerConfig | ||
| ---@field match table | ||
| local Match = Class.new( | ||
| function(self, args) | ||
| self.root = mw.html.create('div'):addClass('match') | ||
| self.config = args.config | ||
| self.match = args.match | ||
| end | ||
| ) | ||
|
|
||
| ---@return Html | ||
| function Match:create() | ||
| self.root:node(self:standardMatchRow()) | ||
| self.root:node(self:detailsRow()) | ||
|
|
||
| return self.root | ||
| end | ||
Rathoz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ---@return Html | ||
| function Match:standardMatchRow() | ||
| return ScoreBoard(self.match):create() | ||
| end | ||
|
|
||
| ---@return Html | ||
| function Match:detailsRow() | ||
| return Details{ | ||
| match = self.match, | ||
| hideTournament = self.config.hideTournament, | ||
| onlyHighlightOnValue = self.config.onlyHighlightOnValue | ||
| }:create() | ||
| end | ||
|
|
||
| return { | ||
| Match = Match, | ||
| Details = Details, | ||
| ScoreBoard = ScoreBoard, | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.