diff --git a/lua/wikis/commons/TeamParticipants/Controller.lua b/lua/wikis/commons/TeamParticipants/Controller.lua index ff03ef69e71..7048a2938a4 100644 --- a/lua/wikis/commons/TeamParticipants/Controller.lua +++ b/lua/wikis/commons/TeamParticipants/Controller.lua @@ -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') @@ -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{ @@ -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 diff --git a/lua/wikis/commons/TeamParticipants/Parse/Wiki.lua b/lua/wikis/commons/TeamParticipants/Parse/Wiki.lua index 4d0589adb34..d59cdc2913b 100644 --- a/lua/wikis/commons/TeamParticipants/Parse/Wiki.lua +++ b/lua/wikis/commons/TeamParticipants/Parse/Wiki.lua @@ -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' diff --git a/lua/wikis/commons/Widget/Participants/Team/Roster.lua b/lua/wikis/commons/Widget/Participants/Team/Roster.lua index 442608350bd..dcaa3ccdf1b 100644 --- a/lua/wikis/commons/Widget/Participants/Team/Roster.lua +++ b/lua/wikis/commons/Widget/Participants/Team/Roster.lua @@ -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) @@ -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{ @@ -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