Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note support to (party) block opponents #3348

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 11 additions & 3 deletions components/opponent/commons/opponent_display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
hjpalpha marked this conversation as resolved.
Show resolved Hide resolved
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')
Expand Down
5 changes: 5 additions & 0 deletions components/opponent/commons/player_display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ PlayerDisplay.propTypes.BlockPlayer = {
showLink = 'boolean?',
showPlayerTeam = 'boolean?',
abbreviateTbd = 'boolean?',
note = 'string?',
}

--[[
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ StarcraftPlayerDisplay.propTypes.BlockPlayer = {
showPlayerTeam = 'boolean?',
showRace = 'boolean?',
abbreviateTbd = 'boolean?',
note = 'string?',
}

--[[
Expand Down Expand Up @@ -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

Expand Down
17 changes: 7 additions & 10 deletions components/opponent/wikis/fortnite/opponent_display_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions components/opponent/wikis/warcraft/opponent_display_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions components/opponent/wikis/warcraft/player_display_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ CustomPlayerDisplay.propTypes.BlockPlayer = {
showPlayerTeam = 'boolean?',
showRace = 'boolean?',
abbreviateTbd = 'boolean?',
note = 'string?',
}

function CustomPlayerDisplay.BlockPlayer(props)
Expand Down Expand Up @@ -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

Expand Down
Loading