@@ -9,7 +9,6 @@ local Lua = require('Module:Lua')
99
1010local Abbreviation = Lua .import (' Module:Abbreviation' )
1111local Array = Lua .import (' Module:Array' )
12- local Class = Lua .import (' Module:Class' )
1312local FnUtil = Lua .import (' Module:FnUtil' )
1413local Image = Lua .import (' Module:Image' )
1514local Logic = Lua .import (' Module:Logic' )
@@ -34,89 +33,11 @@ local TBD = Abbreviation.make{text = 'TBD', title = 'To Be Determined'}
3433--- @field createHeader ? fun ( match : MatchGroupUtilMatch , options : { teamStyle : teamStyle ?}?): Renderable
3534--- @field createBody ? fun ( match : MatchGroupUtilMatch ): Renderable | Renderable[]
3635--- @field createGame ? fun ( date : string , game : table , gameIndex : integer ): Renderable | Renderable[]
37- --- @field addToFooter ? fun ( match : MatchGroupUtilMatch , footer : MatchSummaryFooter ): MatchSummaryFooter
36+ --- @field createFooter ? fun ( match : MatchGroupUtilMatch ): Renderable | Renderable[]
3837--- @field createMatch ? fun ( matchData : MatchGroupUtilMatch ): VNode ?
3938
40- --- @class MatchSummaryFooter : BaseClass
41- --- @operator call : MatchSummaryFooter
42- --- @field elements Renderable[]
43- local Footer = Class .new (
44- function (self )
45- self .elements = {}
46- end
47- )
48-
49- --- @param element Renderable | nil
50- --- @return self
51- function Footer :addElement (element )
52- table.insert (self .elements , element )
53- return self
54- end
55-
56- --- @param link string
57- --- @param icon string
58- --- @param iconDark string ?
59- --- @param text string
60- --- @param class string ?
61- --- @return MatchSummaryFooter
62- function Footer :addLink (link , icon , iconDark , text , class )
63- table.insert (self .elements , Image .display (icon , iconDark , {
64- link = link , size = ' 32px' , caption = text , alt = link , class = class
65- }))
66- return self
67- end
68-
69- --- @param links table<string , string | table>
70- --- @return self
71- function Footer :addLinks (links )
72- local processLink = function (linkType , link )
73- local currentLinkData = Links .getMatchIconData (linkType )
74- if not currentLinkData then
75- mw .log (' Unknown link: ' .. linkType )
76- elseif type (link ) == ' table' then
77- for gameIdx , gameLink in Table .iter .spairs (link ) do
78- local newText = currentLinkData .text .. ' on Game ' .. gameIdx
79- self :addLink (gameLink , currentLinkData .icon , currentLinkData .iconDark , newText )
80- end
81- else
82- -- Temporary during MW/LH Migrations
83- local class
84- if linkType == ' headtohead_lh' then
85- class = ' hide-when-mediawiki'
86- elseif linkType == ' headtohead' then
87- class = ' hide-when-lighthouse'
88- end
89- self :addLink (link , currentLinkData .icon , currentLinkData .iconDark , currentLinkData .text , class )
90- end
91- end
92-
93- local processedLinks = {}
94- Array .forEach (MATCH_LINK_PRIORITY , function (linkType )
95- for linkKey , link in Table .iter .pairsByPrefix (links , linkType , {requireIndex = false }) do
96- processLink (linkKey , link )
97- processedLinks [linkKey ] = true
98- end
99- end )
100-
101- for linkKey , link in Table .iter .spairs (links ) do
102- -- Handle links not already processed via priority list
103- if not processedLinks [linkKey ] then
104- processLink (linkKey , link )
105- end
106- end
107-
108- return self
109- end
110-
111- --- @return VNode
112- function Footer :create ()
113- return MatchSummaryWidgets .Footer {children = self .elements }
114- end
115-
11639--- @class MatchSummary
117- local MatchSummary = {
118- Footer = Footer ,
119- }
40+ local MatchSummary = {}
12041
12142--- Default header function
12243--- @param match MatchGroupUtilMatch
@@ -151,35 +72,98 @@ function MatchSummary.createDefaultBody(match, createGame)
15172end
15273
15374--- Default footer function
154- --- @param match table
155- --- @param footer MatchSummaryFooter
156- --- @return MatchSummaryFooter
157- function MatchSummary .createDefaultFooter (match , footer )
158- return MatchSummary .addVodsToFooter (match , footer ):addLinks (match .links )
75+ --- @param match MatchGroupUtilMatch
76+ --- @return Renderable
77+ function MatchSummary .createDefaultFooter (match )
78+ return MatchSummaryWidgets .Footer {children = WidgetUtil .collect (
79+ MatchSummary .makeVodDisplay (match .vod , match .games ),
80+ MatchSummary .makeLinksDisplay (match .links )
81+ )}
15982end
16083
161- --- Creates a match footer with vods if vods are set
162- --- @param match table
163- --- @param footer MatchSummaryFooter
164- --- @return MatchSummaryFooter
165- function MatchSummary . addVodsToFooter ( match , footer )
166- if match . vod then
167- footer : addElement ( VodLink .display {
168- vod = match . vod ,
84+ --- @param matchVod string ?
85+ --- @param games MatchGroupUtilGame[]
86+ --- @return Renderable[]
87+ function MatchSummary . makeVodDisplay ( matchVod , games )
88+ local vods = {}
89+ if matchVod then
90+ table.insert ( vods , VodLink .display {
91+ vod = matchVod ,
16992 })
17093 end
17194
172- Array .forEach (match . games , function (game , gameIndex )
95+ Array .forEach (games , function (game , gameIndex )
17396 if not game .vod then
17497 return
17598 end
176- footer : addElement ( VodLink .display {
99+ table.insert ( vods , VodLink .display {
177100 gamenum = gameIndex ,
178101 vod = game .vod ,
179102 })
180103 end )
181104
182- return footer
105+ return vods
106+ end
107+
108+ --- @param link string
109+ --- @param icon string
110+ --- @param iconDark string ?
111+ --- @param text string
112+ --- @param class string ?
113+ --- @return string ?
114+ function MatchSummary .makeLinkDisplay (link , icon , iconDark , text , class )
115+ return Image .display (icon , iconDark , {
116+ link = link , size = ' 32px' , caption = text , alt = link , class = class
117+ })
118+ end
119+
120+ --- @param links table<string , string | table>
121+ --- @return Renderable[]
122+ function MatchSummary .makeLinksDisplay (links )
123+ local linkDisplays = {}
124+
125+ local makeAndSaveLink = function (link , icon , iconDark , text , class )
126+ local display = MatchSummary .makeLinkDisplay (link , icon , iconDark , text , class )
127+ table.insert (linkDisplays , display )
128+ end
129+
130+ local processLink = function (linkType , link )
131+ local currentLinkData = Links .getMatchIconData (linkType )
132+ if not currentLinkData then
133+ mw .log (' Unknown link: ' .. linkType )
134+ elseif type (link ) == ' table' then
135+ for gameIdx , gameLink in Table .iter .spairs (link ) do
136+ local newText = currentLinkData .text .. ' on Game ' .. gameIdx
137+ makeAndSaveLink (gameLink , currentLinkData .icon , currentLinkData .iconDark , newText )
138+ end
139+ else
140+ -- Temporary during MW/LH Migrations
141+ local class
142+ if linkType == ' headtohead_lh' then
143+ class = ' hide-when-mediawiki'
144+ elseif linkType == ' headtohead' then
145+ class = ' hide-when-lighthouse'
146+ end
147+ makeAndSaveLink (link , currentLinkData .icon , currentLinkData .iconDark , currentLinkData .text , class )
148+ end
149+ end
150+
151+ local processedLinks = {}
152+ Array .forEach (MATCH_LINK_PRIORITY , function (linkType )
153+ for linkKey , link in Table .iter .pairsByPrefix (links , linkType , {requireIndex = false }) do
154+ processLink (linkKey , link )
155+ processedLinks [linkKey ] = true
156+ end
157+ end )
158+
159+ for linkKey , link in Table .iter .spairs (links ) do
160+ -- Handle links not already processed via priority list
161+ if not processedLinks [linkKey ] then
162+ processLink (linkKey , link )
163+ end
164+ end
165+
166+ return linkDisplays
183167end
184168
185169--- Default createMatch function for usage in Custom MatchSummary
@@ -194,7 +178,7 @@ function MatchSummary.createMatch(matchData, CustomMatchSummary, options)
194178
195179 local createHeader = CustomMatchSummary .createHeader or MatchSummary .createDefaultHeader
196180 local createBody = CustomMatchSummary .createBody or MatchSummary .createDefaultBody
197- local createFooter = CustomMatchSummary .addToFooter or MatchSummary .createDefaultFooter
181+ local createFooter = CustomMatchSummary .createFooter or MatchSummary .createDefaultFooter
198182
199183 return Html .Fragment {children = WidgetUtil .collect (
200184 createHeader (matchData , options ),
@@ -212,7 +196,7 @@ function MatchSummary.createMatch(matchData, CustomMatchSummary, options)
212196 }
213197 }
214198 },
215- createFooter (matchData , MatchSummary . Footer ()): create ( )
199+ createFooter (matchData )
216200 )
217201 },
218202 MatchButtonBar {match = matchData , showVods = false , variant = ' primary' } -- Vods are in the footer currently
0 commit comments