Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

local Lua = require('Module:Lua')

return Lua.import('Module:StreamPage/Team')
return Lua.import('Module:StreamPage/Faction')
136 changes: 124 additions & 12 deletions lua/wikis/commons/StreamPage/Base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@ local Arguments = Lua.import('Module:Arguments')
local Array = Lua.import('Module:Array')
local Class = Lua.import('Module:Class')
local Countdown = Lua.import('Module:Countdown')
local Currency = Lua.import('Module:Currency')
local DateExt = Lua.import('Module:Date/Ext')
local FnUtil = Lua.import('Module:FnUtil')
local HighlightConditions = Lua.import('Module:HighlightConditions')
local Image = Lua.import('Module:Image')
local Links = Lua.import('Module:Links')
local Logic = Lua.import('Module:Logic')
local Lpdb = Lua.import('Module:Lpdb')
local MatchGroup = Lua.import('Module:MatchGroup')
local MatchGroupUtil = Lua.import('Module:MatchGroup/Util/Custom')
local MatchPage = Lua.requireIfExists('Module:MatchPage')
local MatchTable = Lua.import('Module:MatchTable')
local MatchTicker = Lua.import('Module:MatchTicker')
local Opponent = Lua.import('Module:Opponent/Custom')
local OpponentDisplay = Lua.import('Module:OpponentDisplay/Custom')
local Page = Lua.import('Module:Page')
local PlayerDisplay = Lua.import('Module:Player/Display/Custom')
local Table = Lua.import('Module:Table')
local Tabs = Lua.import('Module:Tabs')
local TeamTemplate = Lua.import('Module:TeamTemplate')
local Tournament = Lua.import('Module:Tournament')

Expand All @@ -35,6 +43,7 @@ local ColumnName = Condition.ColumnName
local GridWidgets = Lua.import('Module:Widget/Grid')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')
local IconImage = Lua.import('Module:Widget/Image/Icon/Image')
local Link = Lua.import('Module:Widget/Basic/Link')
local MatchPageAdditionalSection = Lua.import('Module:Widget/Match/Page/AdditionalSection')
local MatchPageHeader = Lua.import('Module:Widget/Match/Page/Header')
local WidgetUtil = Lua.import('Module:Widget/Util')
Expand Down Expand Up @@ -158,7 +167,7 @@ function StreamPage:create()
}}
end

return HtmlWidgets.Fragment{children = WidgetUtil.collect(
return HtmlWidgets.Fragment{children = {
'__NOTOC__',
self:_header(),
GridWidgets.Container{gridCells = {
Expand All @@ -183,9 +192,8 @@ function StreamPage:create()
xxl = 3,
xxxl = 3,
}
}},
not self.suppressBottomContent and self:createBottomContent() or nil
)}
}}
}}
end

---@private
Expand All @@ -201,19 +209,28 @@ function StreamPage:_createMatchTicker()
end

---@protected
---@return string|Widget|Html|(string|Widget|Html)[]?
---@return Renderable?
function StreamPage:render()
end

---@protected
---@return Widget[]?
function StreamPage:createBottomContent()
local match = self.matches[1]

if Array.all(match.opponents, Opponent.isTbd) then
return
end

return Tabs.dynamic{
name1 = 'Players',
content1 = self:renderPlayerInformation(),
name2 = 'Head to Head',
content2 = self:createHeadToHead(),
name3 = 'Tournament Stage',
content3 = self:renderTournamentInformation()
}
end

---@protected
---@return Widget[]?
function StreamPage:createHeadToHead()
local match = self.matches[1]
local headToHead = self:_buildHeadToHeadMatchTable()

return WidgetUtil.collect(
Expand Down Expand Up @@ -252,8 +269,8 @@ function StreamPage:_createMatchTable(props)
return MatchTable(Table.mergeInto({
addCategory = false,
dateFormat = 'compact',
edate = match.timestamp - DateExt.daysToSeconds(1) --[[ MatchTable adds 1-day offset to make edate
inclusive, and we don't want that here ]],
-- MatchTable adds 1-day offset to make edate inclusive, and we don't want that here
edate = match.timestamp - DateExt.daysToSeconds(1),
limit = 5,
stats = false,
vod = false,
Expand Down Expand Up @@ -303,4 +320,99 @@ function StreamPage:_buildHeadToHeadMatchTable()
}
end

---@return Widget
function StreamPage:renderTournamentInformation()
local match = self.matches[1]
return HtmlWidgets.Div{children = MatchGroup.MatchGroupById{id = match.bracketId}}
end

---@protected
---@return Widget
function StreamPage:renderPlayerInformation()
return HtmlWidgets.Div{
classes = {'match-bm-players-wrapper'},
css = {width = '100%'},
children = Array.map(self.matches[1].opponents, StreamPage._opponentDisplay)
}
end

---@private
---@param opponent standardOpponent
---@return Widget
function StreamPage._opponentDisplay(opponent)
return HtmlWidgets.Div{
classes = {'match-bm-players-team'},
children = WidgetUtil.collect(
HtmlWidgets.Div{
classes = {'match-bm-players-team-header'},
children = OpponentDisplay.InlineOpponent{opponent = opponent, teamStyle = 'icon'}
},
Array.map(opponent.players, FnUtil.curry(StreamPage._playerDisplay, opponent.type))
)
}
end

---@param opponentType OpponentType
---@param player standardPlayer
---@return Widget
function StreamPage._playerDisplay(opponentType, player)
local lpdbData = mw.ext.LiquipediaDB.lpdb('player', {
conditions = '[[pagename::' .. (Page.pageifyLink(player.pageName) or '') .. ']]',
limit = 1
})[1] or {}

local image = Logic.nilIfEmpty(lpdbData.image) or 'Blank Player Image.png'
local imageDisplay = Image.display(image, nil, {class = 'img-fluid', size = '600px'})

local nameDisplay = opponentType ~= Opponent.solo and PlayerDisplay.InlinePlayer{
player = player
} or nil

return HtmlWidgets.Div{
classes = {'match-bm-players-player', 'match-bm-players-player--col-2'},
children = {
imageDisplay,
HtmlWidgets.Div{
css = {
display = 'flex',
['flex-direction'] = 'column',
},
children = WidgetUtil.collect(
nameDisplay,
lpdbData.name and HtmlWidgets.Span{children = {
HtmlWidgets.B{children = 'Name: '},
lpdbData.name
}} or nil,
Opponent.typeIsParty(opponentType) and Logic.isNotEmpty(lpdbData.team) and HtmlWidgets.Span{children = {
HtmlWidgets.B{children = 'Team: '},
OpponentDisplay.InlineTeamContainer{
template = lpdbData.team,
style = 'standard'
}
}} or nil,
not DateExt.isDefaultTimestamp(lpdbData.birthdate) and HtmlWidgets.Span{children = {
HtmlWidgets.B{children = 'Birth: '},
mw.getContentLanguage():formatDate('F j, Y', lpdbData.birthdate),
' (' .. DateExt.calculateAge(DateExt.getCurrentTimestamp(), lpdbData.birthdate) .. ')'
}} or nil,
(tonumber(lpdbData.earnings) or 0) > 0 and HtmlWidgets.Span{children = {
HtmlWidgets.B{children = 'Earnings: '},
Currency.display('usd', lpdbData.earnings, {formatValue = true})
}} or nil,
HtmlWidgets.Span{children = Array.interleave(
Array.extractValues(Table.map(lpdbData.links or {}, function(key, link)
return key, Link{
link = link,
children = Links.makeIcon(Links.removeAppendedNumber(key), 21),
linktype = 'external'
}
end), Table.iter.spairs),
' '
)}
)
}
}
}
end

return StreamPage
2 changes: 1 addition & 1 deletion lua/wikis/commons/StreamPage/Custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

local Lua = require('Module:Lua')

return Lua.import('Module:StreamPage')
return Lua.import('Module:StreamPage/Base')
120 changes: 3 additions & 117 deletions lua/wikis/commons/StreamPage/Faction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,23 @@

local Lua = require('Module:Lua')

local Abbreviation = Lua.import('Module:Abbreviation')
local Arguments = Lua.import('Module:Arguments')
local Array = Lua.import('Module:Array')
local BaseStreamPage = Lua.import('Module:StreamPage/Base')
local Class = Lua.import('Module:Class')
local Currency = Lua.import('Module:Currency')
local DateExt = Lua.import('Module:Date/Ext')
local Faction = Lua.import('Module:Faction')
local FnUtil = Lua.import('Module:FnUtil')
local Image = Lua.import('Module:Image')
local Json = Lua.import('Module:Json')
local Links = Lua.import('Module:Links')
local Logic = Lua.import('Module:Logic')
local MathUtil = Lua.import('Module:MathUtil')
local MatchGroup = Lua.import('Module:MatchGroup')
local Opponent = Lua.import('Module:Opponent/Custom')
local OpponentDisplay = Lua.import('Module:OpponentDisplay/Custom')
local Page = Lua.import('Module:Page')
local PlayerDisplay = Lua.import('Module:Player/Display/Custom')
local Tabs = Lua.import('Module:Tabs')
local Table = Lua.import('Module:Table')

local HtmlWidgets = Lua.import('Module:Widget/Html/All')
local Link = Lua.import('Module:Widget/Basic/Link')
local TableWidgets = Lua.import('Module:Widget/Table2/All')
local WidgetUtil = Lua.import('Module:Widget/Util')

local TBD = Abbreviation.make{title = 'To be determined (or to be decided)', text = 'TBD'}

---@class FactionStreamPage: BaseStreamPage
---@operator call(table): FactionStreamPage
local FactionStreamPage = Class.new(BaseStreamPage)
Expand All @@ -44,112 +32,10 @@ local FactionStreamPage = Class.new(BaseStreamPage)
---@return Widget?
function FactionStreamPage.run(frame)
local args = Arguments.getArgs(frame)
args.suppressBottomContent = true
local factionStreamPage = FactionStreamPage(args)
return factionStreamPage:create()
end

---@return string|Widget?
function FactionStreamPage:render()
return Tabs.dynamic{
name1 = 'Players',
content1 = self:renderPlayerInformation(),
name2 = 'Head to Head',
content2 = self:createBottomContent(),
name3 = 'Tournament Stage',
content3 = self:renderTournamentInformation()
}
end

---@protected
---@return Widget
function FactionStreamPage:renderPlayerInformation()
return HtmlWidgets.Div{
classes = {'match-bm-players-wrapper'},
css = {width = '100%'},
children = Array.map(self.matches[1].opponents, FactionStreamPage._opponentDisplay)
}
return FactionStreamPage(args):create()
end

---@private
---@param opponent standardOpponent
---@return Widget
function FactionStreamPage._opponentDisplay(opponent)
return HtmlWidgets.Div{
classes = {'match-bm-players-team'},
children = WidgetUtil.collect(
HtmlWidgets.Div{
classes = {'match-bm-players-team-header'},
children = OpponentDisplay.InlineOpponent{opponent = opponent, teamStyle = 'icon'}
},
Array.map(opponent.players, FnUtil.curry(FactionStreamPage._playerDisplay, opponent.type))
)
}
end

---@param opponentType OpponentType
---@param player standardPlayer
---@return Widget
function FactionStreamPage._playerDisplay(opponentType, player)
local lpdbData = mw.ext.LiquipediaDB.lpdb('player', {
conditions = '[[pagename::' .. (Page.pageifyLink(player.pageName) or '') .. ']]',
limit = 1
})[1] or {}

local image = Logic.nilIfEmpty(lpdbData.image) or 'Blank Player Image.png'
local imageDisplay = Image.display(image, nil, {class = 'img-fluid', size = '600px'})

local nameDisplay = opponentType ~= Opponent.solo and PlayerDisplay.InlinePlayer{
player = player
} or nil

return HtmlWidgets.Div{
classes = {'match-bm-players-player', 'match-bm-players-player--col-2'},
children = {
imageDisplay,
HtmlWidgets.Div{
css = {
display = 'flex',
['flex-direction'] = 'column',
},
children = WidgetUtil.collect(
nameDisplay,
lpdbData.name and HtmlWidgets.Span{children = {
HtmlWidgets.B{children = 'Name: '},
lpdbData.name
}} or nil,
Opponent.typeIsParty(opponentType) and Logic.isNotEmpty(lpdbData.team) and HtmlWidgets.Span{children = {
HtmlWidgets.B{children = 'Team: '},
OpponentDisplay.InlineTeamContainer{
template = lpdbData.team,
style = 'standard'
}
}} or nil,
not DateExt.isDefaultTimestamp(lpdbData.birthdate) and HtmlWidgets.Span{children = {
HtmlWidgets.B{children = 'Birth: '},
mw.getContentLanguage():formatDate('F j, Y', lpdbData.birthdate),
' (' .. DateExt.calculateAge(DateExt.getCurrentTimestamp(), lpdbData.birthdate) .. ')'
}} or nil,
(tonumber(lpdbData.earnings) or 0) > 0 and HtmlWidgets.Span{children = {
HtmlWidgets.B{children = 'Earnings: '},
Currency.display('usd', lpdbData.earnings, {formatValue = true})
}} or nil,
HtmlWidgets.Span{children = Array.interleave(
Array.extractValues(Table.map(lpdbData.links or {}, function(key, link)
return key, Link{
link = link,
children = Links.makeIcon(Links.removeAppendedNumber(key), 21),
linktype = 'external'
}
end), Table.iter.spairs),
' '
)}
)
}
}
}
end

function FactionStreamPage:renderTournamentInformation()
local match = self.matches[1]
return HtmlWidgets.Div{
Expand Down Expand Up @@ -244,11 +130,11 @@ function FactionStreamPage._queryMapWinrate(map, matchup)
})[1]

if type(LPDBoutput) ~= 'table' or Logic.isEmpty(LPDBoutput) then
return TBD
return '-'
end
local data = (LPDBoutput.extradata or {})[matchup]
if Logic.isEmpty(data) or data == '-' then
return TBD
return '-'
end
return MathUtil.formatPercentage(data)
end
Expand Down
Loading
Loading