Skip to content
Open
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
25 changes: 25 additions & 0 deletions lua/wikis/commons/TeamParticipants/Controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local Info = Lua.import('Module:Info', {loadData = true})
local Json = Lua.import('Module:Json')
local Logic = Lua.import('Module:Logic')
local Lpdb = Lua.import('Module:Lpdb')
local Opponent = Lua.import('Module:Opponent/Custom')
local PageVariableNamespace = Lua.import('Module:PageVariableNamespace')
local Table = Lua.import('Module:Table')

Expand Down Expand Up @@ -50,6 +51,10 @@ function TeamParticipantsController.fromTemplate(frame)
end
Array.forEach(parsedData.participants, TeamParticipantsRepository.setPageVars)

if Logic.readBool(args.sortAlphabetically) then
parsedData.participants = TeamParticipantsController._sortAlphabetically(parsedData.participants)
end

local showControls = not teamParticipantsVars:get('externalControlsRendered')

return TeamParticipantsDisplay{
Expand Down Expand Up @@ -155,4 +160,24 @@ function TeamParticipantsController.fillIncompleteRosters(parsedData)
end)
end

---@private
---@param participants TeamParticipant[]
---@return TeamParticipant[]
function TeamParticipantsController._sortAlphabetically(participants)
if Logic.isEmpty(participants) then
return participants
end

Array.forEach(participants, function(participant)
Array.sortInPlaceBy(participant.opponent.players, function(player)
return (player.displayName or ''):lower()
end)
participant.playersAreSorted = true
end)

return Array.sortBy(participants, function(participant)
return Opponent.toName(participant.opponent):lower()
end)
end

return TeamParticipantsController
2 changes: 1 addition & 1 deletion lua/wikis/commons/TeamParticipants/Parse/Wiki.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local TeamParticipantsWikiParser = {}
---@alias TeamParticipant {opponent: standardOpponent, image: string?, imagedark: string?,
---notes: {text: string, highlighted: boolean}[], aliases: string[],
---qualification: QualificationStructure?, shouldImportFromDb: boolean, date: integer,
---potentialQualifiers: standardOpponent[]?, warnings: string[]?}
---potentialQualifiers: standardOpponent[]?, warnings: string[]?, playersAreSorted: boolean?}

---@alias QualificationMethod 'invite'|'qual'
---@alias QualificationType 'tournament'|'internal'|'external'|'other'
Expand Down
10 changes: 10 additions & 0 deletions lua/wikis/commons/Widget/Participants/Team/Roster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ function ParticipantsTeamRoster:render()
local participant = self.props.participant

-- Used for making the sorting stable
---@param players standardPlayer[]
---@return standardPlayer[]
local sortPlayers = function(players)
if participant.playersAreSorted then
return players
end

local playerToIndex = Table.map(players, function(index, player) return player, index end)
return Array.sortBy(players, FnUtil.identity, function(a, b)
local function getPlayerSortOrder(player)
Expand All @@ -119,6 +125,9 @@ function ParticipantsTeamRoster:render()
end)
end

---@param player standardPlayer
---@param index integer
---@return Widget
local makePlayerWidget = function(player, index)
local playerTeam = participant.opponent.template ~= player.team and player.team or nil
local playerTeamAsOpponent = playerTeam and Opponent.readOpponentArgs{
Expand All @@ -137,6 +146,7 @@ function ParticipantsTeamRoster:render()
end

---@param groups {label: string?, players: table[]}[]
---@return Widget
local makeRostersDisplay = function(groups)
local children = {}
for _, group in ipairs(groups) do
Expand Down
Loading