From 2301fdd565efc74c955ac7f892c52138b8cbba83 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Tue, 3 Oct 2023 07:43:29 +0200 Subject: [PATCH 1/3] opponentDisplay Modules --- .../opponent/commons/opponent_display.lua | 14 +++++++++++--- .../opponent_display_starcraft.lua | 19 ++++++++----------- .../fortnite/opponent_display_custom.lua | 17 +++++++---------- .../warcraft/opponent_display_custom.lua | 13 ++++++++++--- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/components/opponent/commons/opponent_display.lua b/components/opponent/commons/opponent_display.lua index b4243f38e8d..2b7bfac3aa0 100644 --- a/components/opponent/commons/opponent_display.lua +++ b/components/opponent/commons/opponent_display.lua @@ -189,6 +189,8 @@ OpponentDisplay.propTypes.BlockOpponent = { ---@field abbreviateTbd boolean? ---@field playerClass string? ---@field teamStyle teamStyle? +---@field dq boolean? +---@field note string|number|nil --[[ Displays an opponent as a block element. The width of the component is @@ -228,9 +230,15 @@ end function OpponentDisplay.BlockPlayers(props) local opponent = props.opponent - local playerNodes = Array.map(opponent.players, function(player) - return PlayerDisplay.BlockPlayer(Table.merge(props, {player = player, team = player.team})) - :addClass(props.playerClass) + --only apply note to first player, hence extract it here + local note = Table.extract(props, 'note') + + local playerNodes = Array.map(opponent.players, function(player, playerIndex) + return PlayerDisplay.BlockPlayer(Table.merge(props, { + player = player, + team = player.team, + note = playerIndex == 1 and note or nil, + })):addClass(props.playerClass) end) local playersNode = mw.html.create('div') diff --git a/components/opponent/commons/starcraft_starcraft2/opponent_display_starcraft.lua b/components/opponent/commons/starcraft_starcraft2/opponent_display_starcraft.lua index 824d02303eb..a4264669321 100644 --- a/components/opponent/commons/starcraft_starcraft2/opponent_display_starcraft.lua +++ b/components/opponent/commons/starcraft_starcraft2/opponent_display_starcraft.lua @@ -178,19 +178,16 @@ function StarcraftOpponentDisplay.PlayerBlockOpponent(props) local opponent = props.opponent local showRace = props.showRace ~= false - local playerNodes = Array.map(opponent.players, function(player) - return StarcraftPlayerDisplay.BlockPlayer({ - flip = props.flip, - overflow = props.overflow, + --only apply note to first player, hence extract it here + local note = Table.extract(props, 'note') + + local playerNodes = Array.map(opponent.players, function(player, playerIndex) + return StarcraftPlayerDisplay.BlockPlayer(Table.merge(props, { player = player, - showFlag = props.showFlag, - showLink = props.showLink, - showPlayerTeam = props.showPlayerTeam, - showRace = showRace and not opponent.isArchon and not opponent.isSpecialArchon, team = player.team, - abbreviateTbd = props.abbreviateTbd, - }) - :addClass(props.playerClass) + note = playerIndex == 1 and note or nil, + showRace = showRace and not opponent.isArchon and not opponent.isSpecialArchon, + })):addClass(props.playerClass) end) if #opponent.players == 1 then diff --git a/components/opponent/wikis/fortnite/opponent_display_custom.lua b/components/opponent/wikis/fortnite/opponent_display_custom.lua index 2cd1443a9ad..e3b6239a13b 100644 --- a/components/opponent/wikis/fortnite/opponent_display_custom.lua +++ b/components/opponent/wikis/fortnite/opponent_display_custom.lua @@ -102,18 +102,15 @@ end function FortniteOpponentDisplay.PlayerBlockOpponent(props) local opponent = props.opponent - local playerNodes = Array.map(opponent.players, function(player) - return PlayerDisplay.BlockPlayer({ - flip = props.flip, - overflow = props.overflow, + --only apply note to first player, hence extract it here + local note = Table.extract(props, 'note') + + local playerNodes = Array.map(opponent.players, function(player, playerIndex) + return PlayerDisplay.BlockPlayer(Table.merge(props, { player = player, - showFlag = props.showFlag, - showLink = props.showLink, - showPlayerTeam = props.showPlayerTeam, team = player.team, - abbreviateTbd = props.abbreviateTbd, - }) - :addClass(props.playerClass) + note = playerIndex == 1 and note or nil, + })):addClass(props.playerClass) end) if #opponent.players == 1 then diff --git a/components/opponent/wikis/warcraft/opponent_display_custom.lua b/components/opponent/wikis/warcraft/opponent_display_custom.lua index be9f8d943f0..90230e3331e 100644 --- a/components/opponent/wikis/warcraft/opponent_display_custom.lua +++ b/components/opponent/wikis/warcraft/opponent_display_custom.lua @@ -95,9 +95,16 @@ function CustomOpponentDisplay.BlockPlayers(props) local opponent = props.opponent local showRace = props.showRace ~= false - local playerNodes = Array.map(opponent.players, function(player) - return PlayerDisplay.BlockPlayer(Table.merge(props, {team = player.team, player = player, showRace = showRace})) - :addClass(props.playerClass) + --only apply note to first player, hence extract it here + local note = Table.extract(props, 'note') + + local playerNodes = Array.map(opponent.players, function(player, playerIndex) + return PlayerDisplay.BlockPlayer(Table.merge(props, { + team = player.team, + player = player, + showRace = showRace, + note = playerIndex == 1 and note or nil, + })):addClass(props.playerClass) end) local playersNode = mw.html.create('div') From 0ff02f16787a582d31997c56264d8e543c7ae7bd Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Tue, 3 Oct 2023 07:50:57 +0200 Subject: [PATCH 2/3] player display modules --- components/opponent/commons/player_display.lua | 5 +++++ .../starcraft_starcraft2/player_display_starcraft.lua | 5 +++++ components/opponent/wikis/warcraft/player_display_custom.lua | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/components/opponent/commons/player_display.lua b/components/opponent/commons/player_display.lua index 384c89f938a..d109d272e4d 100644 --- a/components/opponent/commons/player_display.lua +++ b/components/opponent/commons/player_display.lua @@ -33,6 +33,7 @@ PlayerDisplay.propTypes.BlockPlayer = { showLink = 'boolean?', showPlayerTeam = 'boolean?', abbreviateTbd = 'boolean?', + note = 'string?', } --[[ @@ -64,11 +65,15 @@ function PlayerDisplay.BlockPlayer(props) :node(mw.ext.TeamTemplate.teampart(player.team)) end + local noteNode = props.note and mw.html.create('span'):addClass('note'):wikitext(props.note) or nil + return mw.html.create('div'):addClass('block-player') :addClass(props.flip and 'flipped' or nil) :addClass(props.showPlayerTeam and 'has-team' or nil) :node(flagNode) + :node(props.flip and noteNode or nil) :node(nameNode) + :node(not props.flip and noteNode or nil) :node(teamNode) end diff --git a/components/opponent/commons/starcraft_starcraft2/player_display_starcraft.lua b/components/opponent/commons/starcraft_starcraft2/player_display_starcraft.lua index ecb09020069..1f45b69eb0d 100644 --- a/components/opponent/commons/starcraft_starcraft2/player_display_starcraft.lua +++ b/components/opponent/commons/starcraft_starcraft2/player_display_starcraft.lua @@ -39,6 +39,7 @@ StarcraftPlayerDisplay.propTypes.BlockPlayer = { showPlayerTeam = 'boolean?', showRace = 'boolean?', abbreviateTbd = 'boolean?', + note = 'string?', } --[[ @@ -77,12 +78,16 @@ function StarcraftPlayerDisplay.BlockPlayer(props) :node(mw.ext.TeamTemplate.teampart(player.team)) end + local noteNode = props.note and mw.html.create('span'):addClass('note'):wikitext(props.note) or nil + return html.create('div'):addClass('block-player starcraft-block-player') :addClass(props.flip and 'flipped' or nil) :addClass(props.showPlayerTeam and 'has-team' or nil) :node(flagNode) :node(raceNode) + :node(props.flip and noteNode or nil) :node(nameNode) + :node(not props.flip and noteNode or nil) :node(teamNode) end diff --git a/components/opponent/wikis/warcraft/player_display_custom.lua b/components/opponent/wikis/warcraft/player_display_custom.lua index 4fb12948eb2..1df3f1d0bc9 100644 --- a/components/opponent/wikis/warcraft/player_display_custom.lua +++ b/components/opponent/wikis/warcraft/player_display_custom.lua @@ -33,6 +33,7 @@ CustomPlayerDisplay.propTypes.BlockPlayer = { showPlayerTeam = 'boolean?', showRace = 'boolean?', abbreviateTbd = 'boolean?', + note = 'string?', } function CustomPlayerDisplay.BlockPlayer(props) @@ -66,12 +67,16 @@ function CustomPlayerDisplay.BlockPlayer(props) :node(mw.ext.TeamTemplate.teampart(player.team)) end + local noteNode = props.note and mw.html.create('span'):addClass('note'):wikitext(props.note) or nil + return mw.html.create('div'):addClass('block-player starcraft-block-player') :addClass(props.flip and 'flipped' or nil) :addClass(props.showPlayerTeam and 'has-team' or nil) :node(flagNode) :node(raceNode) + :node(props.flip and noteNode or nil) :node(nameNode) + :node(not props.flip and noteNode or nil) :node(teamNode) end From 4e40324a69a7a0aad9f04b7de0d6c4fdfddb9056 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Wed, 4 Oct 2023 07:55:15 +0200 Subject: [PATCH 3/3] fix alignment issue --- components/opponent/commons/player_display.lua | 14 +++++++++----- .../player_display_starcraft.lua | 14 +++++++++----- .../wikis/warcraft/player_display_custom.lua | 14 +++++++++----- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/components/opponent/commons/player_display.lua b/components/opponent/commons/player_display.lua index d109d272e4d..0584dc811ce 100644 --- a/components/opponent/commons/player_display.lua +++ b/components/opponent/commons/player_display.lua @@ -45,7 +45,7 @@ function PlayerDisplay.BlockPlayer(props) local player = props.player local zeroWidthSpace = '​' - local nameNode = mw.html.create(props.dq and 's' or 'span'):addClass('name') + local nameNode = mw.html.create(props.dq and 's' or 'span') :wikitext(props.abbreviateTbd and Opponent.playerIsTbd(player) and TBD_ABBREVIATION or props.showLink ~= false and Logic.isNotEmpty(player.pageName) and '[[' .. player.pageName .. '|' .. player.displayName .. ']]' @@ -53,6 +53,14 @@ function PlayerDisplay.BlockPlayer(props) ) DisplayUtil.applyOverflowStyles(nameNode, props.overflow or 'ellipsis') + if props.note then + nameNode = mw.html.create('span'):addClass('name') + :node(nameNode) + :tag('sup'):addClass('note'):wikitext(props.note):done() + else + nameNode:addClass('name') + end + local flagNode if props.showFlag ~= false and player.flag then flagNode = PlayerDisplay.Flag(player.flag) @@ -65,15 +73,11 @@ function PlayerDisplay.BlockPlayer(props) :node(mw.ext.TeamTemplate.teampart(player.team)) end - local noteNode = props.note and mw.html.create('span'):addClass('note'):wikitext(props.note) or nil - return mw.html.create('div'):addClass('block-player') :addClass(props.flip and 'flipped' or nil) :addClass(props.showPlayerTeam and 'has-team' or nil) :node(flagNode) - :node(props.flip and noteNode or nil) :node(nameNode) - :node(not props.flip and noteNode or nil) :node(teamNode) end diff --git a/components/opponent/commons/starcraft_starcraft2/player_display_starcraft.lua b/components/opponent/commons/starcraft_starcraft2/player_display_starcraft.lua index 1f45b69eb0d..b864bcc8e98 100644 --- a/components/opponent/commons/starcraft_starcraft2/player_display_starcraft.lua +++ b/components/opponent/commons/starcraft_starcraft2/player_display_starcraft.lua @@ -51,7 +51,7 @@ function StarcraftPlayerDisplay.BlockPlayer(props) local player = props.player local zeroWidthSpace = '​' - local nameNode = html.create(props.dq and 's' or 'span'):addClass('name') + local nameNode = html.create(props.dq and 's' or 'span') :wikitext( props.abbreviateTbd and Opponent.playerIsTbd(player) and TBD_ABBREVIATION or props.showLink ~= false and player.pageName @@ -60,6 +60,14 @@ function StarcraftPlayerDisplay.BlockPlayer(props) ) DisplayUtil.applyOverflowStyles(nameNode, props.overflow or 'ellipsis') + if props.note then + nameNode = mw.html.create('span'):addClass('name') + :node(nameNode) + :tag('sup'):addClass('note'):wikitext(props.note):done() + else + nameNode:addClass('name') + end + local flagNode if props.showFlag ~= false and player.flag then flagNode = PlayerDisplay.Flag(player.flag) @@ -78,16 +86,12 @@ function StarcraftPlayerDisplay.BlockPlayer(props) :node(mw.ext.TeamTemplate.teampart(player.team)) end - local noteNode = props.note and mw.html.create('span'):addClass('note'):wikitext(props.note) or nil - return html.create('div'):addClass('block-player starcraft-block-player') :addClass(props.flip and 'flipped' or nil) :addClass(props.showPlayerTeam and 'has-team' or nil) :node(flagNode) :node(raceNode) - :node(props.flip and noteNode or nil) :node(nameNode) - :node(not props.flip and noteNode or nil) :node(teamNode) end diff --git a/components/opponent/wikis/warcraft/player_display_custom.lua b/components/opponent/wikis/warcraft/player_display_custom.lua index 1df3f1d0bc9..f346ebd70bf 100644 --- a/components/opponent/wikis/warcraft/player_display_custom.lua +++ b/components/opponent/wikis/warcraft/player_display_custom.lua @@ -40,7 +40,7 @@ function CustomPlayerDisplay.BlockPlayer(props) DisplayUtil.assertPropTypes(props, CustomPlayerDisplay.propTypes.BlockPlayer) local player = props.player - local nameNode = mw.html.create(props.dq and 's' or 'span'):addClass('name') + local nameNode = mw.html.create(props.dq and 's' or 'span') :wikitext( props.abbreviateTbd and Opponent.playerIsTbd(player) and TBD_ABBREVIATION or props.showLink ~= false and player.pageName @@ -49,6 +49,14 @@ function CustomPlayerDisplay.BlockPlayer(props) ) DisplayUtil.applyOverflowStyles(nameNode, props.overflow or 'ellipsis') + if props.note then + nameNode = mw.html.create('span'):addClass('name') + :node(nameNode) + :tag('sup'):addClass('note'):wikitext(props.note):done() + else + nameNode:addClass('name') + end + local flagNode if props.showFlag ~= false and player.flag then flagNode = PlayerDisplay.Flag(player.flag) @@ -67,16 +75,12 @@ function CustomPlayerDisplay.BlockPlayer(props) :node(mw.ext.TeamTemplate.teampart(player.team)) end - local noteNode = props.note and mw.html.create('span'):addClass('note'):wikitext(props.note) or nil - return mw.html.create('div'):addClass('block-player starcraft-block-player') :addClass(props.flip and 'flipped' or nil) :addClass(props.showPlayerTeam and 'has-team' or nil) :node(flagNode) :node(raceNode) - :node(props.flip and noteNode or nil) :node(nameNode) - :node(not props.flip and noteNode or nil) :node(teamNode) end