Skip to content

Commit

Permalink
feat(match2): sort links in MatchSummary (#5074)
Browse files Browse the repository at this point in the history
* Add match link priority groups

* Fix typo

* add missing return

* Use single priority list

* Fix param order, do not require index

* Remove unused import

* fix ??

* Apply suggestions

* Iterate in alphabetical order for unspecified links

* Iterate over copy

* Remove import

* Update components/match2/commons/match_summary_base.lua

* Update components/match2/commons/match_summary_base.lua

Co-authored-by: hjpalpha <[email protected]>

* Rename vars

Co-authored-by: Rikard Blixt <[email protected]>

---------

Co-authored-by: hjpalpha <[email protected]>
Co-authored-by: Rikard Blixt <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent 371aeca commit ad318e9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
18 changes: 17 additions & 1 deletion components/match2/commons/match_summary_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ local OpponentLibraries = require('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent
local OpponentDisplay = OpponentLibraries.OpponentDisplay

local MATCH_LINK_PRIORITY = Lua.import('Module:Links/MatchPriorityGroups', {loadData = true})
local TBD = Abbreviation.make('TBD', 'To Be Determined')

---@class MatchSummaryHeader
Expand Down Expand Up @@ -170,7 +171,7 @@ end
---@param links table<string, string|table>
---@return MatchSummaryFooter
function Footer:addLinks(links)
for linkType, link in pairs(links) do
local processLink = function(linkType, link)
local currentLinkData = Links.getMatchIconData(linkType)
if not currentLinkData then
mw.log('Unknown link: ' .. linkType)
Expand All @@ -184,6 +185,21 @@ function Footer:addLinks(links)
end
end

local processedLinks = {}
Array.forEach(MATCH_LINK_PRIORITY, function(linkType)
for linkKey, link in Table.iter.pairsByPrefix(links, linkType, {requireIndex = false}) do
processLink(linkKey, link)
processedLinks[linkKey] = true
end
end)

for linkKey, link in Table.iter.spairs(links) do
-- Handle links not already processed via priority list
if not processedLinks[linkKey] then
processLink(linkKey, link)
end
end

return self
end

Expand Down
22 changes: 22 additions & 0 deletions standard/links/commons/links_match_priority_groups.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
-- @Liquipedia
-- wiki=commons
-- page=Module:Links/MatchPriorityGroups
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

return {
-- common
'vod',
'preview',
'interview',
'review',
'lrthread',
'recap',
'headtohead',

-- ageofempires
'mapdraft',
'civdraft'
}

0 comments on commit ad318e9

Please sign in to comment.