Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz committed Oct 17, 2024
1 parent 0a9096f commit 3649bbb
Show file tree
Hide file tree
Showing 12 changed files with 505 additions and 141 deletions.
2 changes: 1 addition & 1 deletion components/match2/commons/match_group_display_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function DisplayHelper.DefaultMatchSummaryContainer(props)
end

---@param props table
---@return Html
---@return Widget
function DisplayHelper.DefaultMatchPageContainer(props)
local MatchPageModule = Lua.import('Module:MatchPage')

Expand Down
131 changes: 70 additions & 61 deletions components/match2/wikis/dota2/match_page.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')
local Display = Lua.import('Module:MatchPage/Template')

local HtmlWidgets = Lua.import('Module:Widget/Html/All')
local Div = HtmlWidgets.Div
local MatchPageWidgets = Lua.import('Module:Widget/Match/Page/All')

local MatchPage = {}

local NO_CHARACTER = 'default'
Expand Down Expand Up @@ -50,20 +54,13 @@ end
---@field seriesDots string[]

---@param props {match: MatchGroupUtilMatch}
---@return Html
---@return Widget
function MatchPage.getByMatchId(props)
---@class Dota2MatchPageViewModel: MatchGroupUtilMatch
---@field games Dota2MatchPageViewModelGame[]
---@field opponents Dota2MatchPageViewModelOpponent[]
local viewModel = props.match

viewModel.isBestOfOne = #viewModel.games == 1
viewModel.dateCountdown = viewModel.timestamp ~= DateExt.defaultTimestamp and
DisplayHelper.MatchCountdownBlock(viewModel) or nil

local phase = MatchGroupUtil.computeMatchPhase(props.match)
viewModel.statusText = phase == 'ongoing' and 'live' or phase

local function makeItemDisplay(item)
if String.isEmpty(item.name) then
return '[[File:EmptyIcon itemicon dota2 gameasset.png|64px|Empty|link=]]'
Expand Down Expand Up @@ -121,45 +118,7 @@ function MatchPage.getByMatchId(props)
end)

-- Add more opponent data field
Array.forEach(viewModel.opponents, function(opponent, index)
opponent.opponentIndex = index

local teamTemplate = opponent.template and mw.ext.TeamTemplate.raw(opponent.template)
if not teamTemplate then
return
end

opponent.iconDisplay = mw.ext.TeamTemplate.teamicon(opponent.template)
opponent.shortname = teamTemplate.shortname
opponent.page = teamTemplate.page
opponent.name = teamTemplate.name

opponent.seriesDots = Array.map(viewModel.games, function(game)
return game.teams[index].scoreDisplay
end)
end)

viewModel.vods = Array.map(viewModel.games, function(game, gameIdx)
return game.vod and VodLink.display{
gamenum = gameIdx,
vod = game.vod,
} or ''
end)

-- Create an object array for links
local function processLink(site, link)
return Table.mergeInto({link = link}, MatchLinks[site])
end

viewModel.links = Array.flatMap(Table.entries(viewModel.links), function(linkData)
local site, link = unpack(linkData)
if type(link) == 'table' then
return Array.map(link, function(sublink)
return processLink(site, sublink)
end)
end
return {processLink(site, link)}
end)

viewModel.heroIcon = function(c)
local character = c
Expand All @@ -176,7 +135,13 @@ function MatchPage.getByMatchId(props)
local displayTitle = MatchPage.makeDisplayTitle(viewModel)
mw.getCurrentFrame():preprocess(table.concat{'{{DISPLAYTITLE:', displayTitle, '}}'})

return MatchPage.render(viewModel)
return Div{
children = {
MatchPage.header(viewModel),
MatchPage.games(viewModel),
MatchPage.footer(viewModel)
}
}
end

---@param viewModel table
Expand Down Expand Up @@ -214,18 +179,36 @@ function MatchPage._abbreviateNumber(number)
end

---@param model table
---@return Html
function MatchPage.render(model)
return mw.html.create('div')
:wikitext(MatchPage.header(model))
:node(MatchPage.games(model))
:wikitext(MatchPage.footer(model))
end

---@param model table
---@return string
---@return Widget
function MatchPage.header(model)
return TemplateEngine():render(Display.header, model)
local phase = MatchGroupUtil.computeMatchPhase(model)
local phaseDisplay = phase == 'ongoing' and 'live' or phase

local opponents = Array.map(model.opponents, function(opponent, index)
local teamTemplate = opponent.template and mw.ext.TeamTemplate.raw(opponent.template)
if not teamTemplate then
return {}
end

return {
icon = mw.ext.TeamTemplate.teamicon(opponent.template),
name = teamTemplate.name,
shortname = teamTemplate.shortname,
page = teamTemplate.page,
seriesDots = Array.map(model.games, function(game)
return game.teams[index].scoreDisplay
end),
}
end)

return MatchPageWidgets.header{
opponents = opponents,
matchPhase = phaseDisplay,
parent = model.parent,
tournament = model.tournament,
dateCountdown = model.timestamp ~= DateExt.defaultTimestamp and DisplayHelper.MatchCountdownBlock(model) or nil,
mvp = model.extradata.mvp,
}
end

---@param model table
Expand All @@ -234,7 +217,7 @@ function MatchPage.games(model)
local games = Array.map(Array.filter(model.games, function(game)
return game.resultType ~= NOT_PLAYED
end), function(game)
return TemplateEngine():render(Display.game, Table.merge(model, game))
return tostring(MatchPageWidgets.game(game)) .. TemplateEngine():render(Display.game, Table.merge(model, game))
end)

if #games < 2 then
Expand All @@ -256,9 +239,35 @@ function MatchPage.games(model)
end

---@param model table
---@return string
---@return Widget
function MatchPage.footer(model)
return TemplateEngine():render(Display.footer, model)
local vods = Array.map(model.games, function(game, gameIdx)
return game.vod and VodLink.display{
gamenum = gameIdx,
vod = game.vod,
} or ''
end)

-- Create an object array for links
local function processLink(site, link)
return Table.mergeInto({link = link}, MatchLinks[site])
end

local links = Array.flatMap(Table.entries(model.links), function(linkData)
local site, link = unpack(linkData)
if type(link) == 'table' then
return Array.map(link, function(sublink)
return processLink(site, sublink)
end)
end
return {processLink(site, link)}
end)

return MatchPageWidgets.footer{
vods = vods,
links = links,
patch = model.patch,
}
end

return MatchPage
79 changes: 0 additions & 79 deletions components/match2/wikis/dota2/match_page_template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,87 +11,8 @@

-- luacheck: ignore
return {
header =
[=[
<div class="match-bm-lol-match-header">
<div class="match-bm-match-header-powered-by">[[File:DataProvidedSAP.svg|link=]]</div>
<div class="match-bm-lol-match-header-overview">
<div class="match-bm-match-header-team">{{#opponents.1}}{{&iconDisplay}}<div class="match-bm-match-header-team-group"><div class="match-bm-match-header-team-long">{{#page}}[[{{page}}|{{name}}]]{{/page}}</div><div class="match-bm-match-header-team-short">[[{{page}}|{{shortname}}]]</div><div class="match-bm-lol-match-header-round-results">{{#seriesDots}}<div class="match-bm-lol-match-header-round-result result--{{.}}"></div>{{/seriesDots}}</div>{{/opponents.1}}</div></div>
<div class="match-bm-match-header-result">{{#isBestOfOne}}{{#games.1.apiInfo}}{{team1.scoreDisplay}}&ndash;{{team2.scoreDisplay}}{{/games.1.apiInfo}}{{/isBestOfOne}}{{^isBestOfOne}}{{opponents.1.score}}&ndash;{{opponents.2.score}}{{/isBestOfOne}}<div class="match-bm-match-header-result-text">{{statusText}}</div></div>
<div class="match-bm-match-header-team">{{#opponents.2}}{{&iconDisplay}}<div class="match-bm-match-header-team-group"><div class="match-bm-match-header-team-long">{{#page}}[[{{page}}|{{name}}]]{{/page}}</div><div class="match-bm-match-header-team-short">[[{{page}}|{{shortname}}]]</div><div class="match-bm-lol-match-header-round-results">{{#seriesDots}}<div class="match-bm-lol-match-header-round-result result--{{.}}"></div>{{/seriesDots}}</div>{{/opponents.2}}</div></div>
</div>
<div class="match-bm-lol-match-header-tournament">[[{{parent}}|{{tournament}}]]</div>
<div class="match-bm-lol-match-header-date">{{&dateCountdown}}</div>
</div>
{{#extradata.mvp}}<div class="match-bm-lol-match-mvp"><b>MVP</b>{{#players}} [[{{name}}|{{displayname}}]]{{/players}}</div>{{/extradata.mvp}}
]=],
footer =
[=[
<h3>Additional Information</h3>
<div class="match-bm-match-additional">
{{#vods.1}}
<div class="match-bm-match-additional-section">
<div class="match-bm-match-additional-section-header">VODs</div>
<div class="match-bm-match-additional-section-body">{{#vods}}{{&.}}{{/vods}}</div>
</div>{{/vods.1}}{{#links.1}}
<div class="match-bm-match-additional-section">
<div class="match-bm-match-additional-section-header">Socials</div>
<div class="match-bm-match-additional-section-body">{{#links}}[[{{icon}}|link={{link}}|15px|{{text}}]]{{/links}}</div>
</div>{{/links.1}}{{#patch}}
<div class="match-bm-match-additional-section">
<div class="match-bm-match-additional-section-header">Patch</div>
<div class="match-bm-match-additional-section-body">[[Version {{patch}}]]</div>
</div>
{{/patch}}
</div>
]=],
game =
[=[
<h3>Draft</h3>
<div class="match-bm-game-veto-wrapper">
<div class="match-bm-lol-game-veto-overview-team">
<div class="match-bm-game-veto-overview-team-header">{{&opponents.1.iconDisplay}}</div>
<div class="match-bm-game-veto-overview-team-veto">
<div class="match-bm-game-veto-overview-team-veto-row match-bm-game-veto-overview-team-veto-row--{{teams.1.side}}" aria-labelledby="picks">
{{#teams.1.picks}}
<div class="match-bm-game-veto-overview-team-veto-row-item">
<div class="match-bm-game-veto-overview-team-veto-row-item-icon">{{&heroIcon}}</div>
<div class="match-bm-game-veto-overview-team-veto-row-item-text">#{{vetoNumber}}</div>
</div>
{{/teams.1.picks}}
</div>
<div class="match-bm-game-veto-overview-team-veto-row match-bm-game-veto-overview-team-veto-row--ban" aria-labelledby="bans">
{{#teams.1.bans}}
<div class="match-bm-game-veto-overview-team-veto-row-item">
<div class="match-bm-game-veto-overview-team-veto-row-item-icon">{{&heroIcon}}</div>
<div class="match-bm-game-veto-overview-team-veto-row-item-text">#{{vetoNumber}}</div>
</div>
{{/teams.1.bans}}
</div>
</div>
</div>
<div class="match-bm-lol-game-veto-overview-team">
<div class="match-bm-game-veto-overview-team-header">{{&opponents.2.iconDisplay}}</div>
<div class="match-bm-game-veto-overview-team-veto">
<div class="match-bm-game-veto-overview-team-veto-row match-bm-game-veto-overview-team-veto-row--{{teams.2.side}}" aria-labelledby="picks">
{{#teams.2.picks}}
<div class="match-bm-game-veto-overview-team-veto-row-item">
<div class="match-bm-game-veto-overview-team-veto-row-item-icon">{{&heroIcon}}</div>
<div class="match-bm-game-veto-overview-team-veto-row-item-text">#{{vetoNumber}}</div>
</div>
{{/teams.2.picks}}
</div>
<div class="match-bm-game-veto-overview-team-veto-row match-bm-game-veto-overview-team-veto-row--ban" aria-labelledby="bans">
{{#teams.2.bans}}
<div class="match-bm-game-veto-overview-team-veto-row-item">
<div class="match-bm-game-veto-overview-team-veto-row-item-icon">{{&heroIcon}}</div>
<div class="match-bm-game-veto-overview-team-veto-row-item-text">#{{vetoNumber}}</div>
</div>
{{/teams.2.bans}}
</div>
</div>
</div>
</div>
<h3>Team Stats</h3>
<div class="match-bm-team-stats">
<div class="match-bm-team-stats-header">
Expand Down
1 change: 1 addition & 0 deletions components/widget/html/widget_html_all.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local Lua = require('Module:Lua')
Widgets.Abbr = Lua.import('Module:Widget/Html/Abbr')
Widgets.Div = Lua.import('Module:Widget/Html/Div')
Widgets.Fragment = Lua.import('Module:Widget/Html/Fragment')
Widgets.Header = Lua.import('Module:Widget/Html/Header')
Widgets.Li = Lua.import('Module:Widget/Html/Li')
Widgets.Span = Lua.import('Module:Widget/Html/Span')
Widgets.Table = Lua.import('Module:Widget/Html/Table')
Expand Down
26 changes: 26 additions & 0 deletions components/widget/html/widget_html_header.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
-- @Liquipedia
-- wiki=commons
-- page=Module:Widget/Html/Header
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

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

local WidgetHtml = Lua.import('Module:Widget/Html/Base')

---@class WidgetHeader: WidgetHtmlBase
---@operator call(table): WidgetHeader
local Header = Class.new(WidgetHtml)

---@return Html
function Header:render()
if not self.props.level then
error('Header level not provided')
end
return self:renderAs('h' .. self.props.level)
end

return Header
46 changes: 46 additions & 0 deletions components/widget/match/page/widget_match_page_footer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
-- @Liquipedia
-- wiki=commons
-- page=Module:Widget/Match/Page/Header
--
-- 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 WidgetUtil = Lua.import('Module:Widget/Util')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')
local Div, Fragment, Header = HtmlWidgets.Div, HtmlWidgets.Fragment, HtmlWidgets.Header
local Link = Lua.import('Module:Widget/Basic/Link')
local MatchPageFooterSection = Lua.import('Module:Widget/Match/Page/Footer/Section')

---@class MatchPageFooter: Widget
---@operator call(table): MatchPageFooter
local MatchPageFooter = Class.new(Widget)
MatchPageFooter.defaultProps = {
flipped = false,
}

---@return Widget[]?
function MatchPageFooter:render()
return Fragment{children = {
Header{level = 3, children = 'Additional Information'},
Div{
classes = {'match-bm-match-additional'},
children = WidgetUtil.collect(
self.props.vods and MatchPageFooterSection{header = 'VODs', children = self.props.vods} or nil,
self.props.links and MatchPageFooterSection{header = 'Socials', children = Array.map(self.props.links, function(link)
return '[['.. link.icon .. '|link='.. link.link .. '|15px|'.. link.text .. ']]'
end)} or nil,
self.props.patch and MatchPageFooterSection{header = 'Patch', children =
Link{link = 'Version ' .. self.props.patch, children = 'Version ' .. self.props.patch}
} or nil
)
}
}}
end

return MatchPageFooter
Loading

0 comments on commit 3649bbb

Please sign in to comment.