Skip to content

Commit

Permalink
feat(match2): support fortnite (#5162)
Browse files Browse the repository at this point in the history
* feat(match2): support fortnite

* update golden due to adding the team for parties

* store and retrieve team of player

* passthrough team on more places

* tweak the CSS
  • Loading branch information
Rathoz authored Dec 6, 2024
1 parent 8a246fb commit fa6641c
Show file tree
Hide file tree
Showing 11 changed files with 473 additions and 2 deletions.
9 changes: 8 additions & 1 deletion components/match2/commons/match.lua
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ function Match._prepareRecordsForStore(records)
for opponentIndex, opponentRecord in ipairs(records.opponentRecords) do
Match.clampFields(opponentRecord, Match.opponentFields)
for _, playerRecord in ipairs(records.playerRecords[opponentIndex]) do
Match.clampFields(playerRecord, Match.playerFields)
Match._preparePlayerRecordForStore(playerRecord)
end
end
for _, gameRecord in ipairs(records.gameRecords) do
Expand Down Expand Up @@ -387,6 +387,13 @@ function Match._prepareGameRecordForStore(matchRecord, gameRecord)
Match.clampFields(gameRecord, Match.gameFields)
end

---@param playerRecord table
function Match._preparePlayerRecordForStore(playerRecord)
playerRecord.extradata = playerRecord.extradata or {}
playerRecord.extradata.playerteam = playerRecord.team
Match.clampFields(playerRecord, Match.playerFields)
end

---Adds fields needed for backwards compatibility with API v3.
---walkover and resulttype are added to record.
---@param record table #game or match record
Expand Down
1 change: 1 addition & 0 deletions components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ function MatchGroupInputUtil.mergeRecordWithOpponent(record, opponent, substitut
displayname = player.displayName,
flag = player.flag,
name = player.pageName,
team = player.team,
extradata = player.faction and {faction = player.faction}
}
end)
Expand Down
1 change: 1 addition & 0 deletions components/match2/commons/match_group_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ function MatchGroupUtil.playerFromRecord(record)
extradata = extradata,
flag = nilIfEmpty(record.flag),
pageName = record.name,
team = Table.extract(extradata, 'playerteam'),
}
end

Expand Down
2 changes: 2 additions & 0 deletions components/match2/commons/match_summary_ffa.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ local MATCH_OVERVIEW_COLUMNS = {
showLink = true,
overflow = 'ellipsis',
teamStyle = 'hybrid',
showPlayerTeam = true,
}
end,
},
Expand Down Expand Up @@ -270,6 +271,7 @@ local GAME_STANDINGS_COLUMNS = {
showLink = true,
overflow = 'ellipsis',
teamStyle = 'hybrid',
showPlayerTeam = true,
}
end,
},
Expand Down
89 changes: 89 additions & 0 deletions components/match2/wikis/fortnite/game_summary.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
-- @Liquipedia
-- wiki=fortnite
-- page=Module:GameSummary
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local CustomGameSummary = {}

local Array = require('Module:Array')
local FnUtil = require('Module:FnUtil')
local Lua = require('Module:Lua')
local Page = require('Module:Page')
local Table = require('Module:Table')

local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')

local SummaryHelper = Lua.import('Module:MatchSummary/Ffa')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')
local IconWidget = Lua.import('Module:Widget/Image/Icon/Fontawesome')

---@class FortniteMatchGroupUtilGame: MatchGroupUtilGame
---@field stream table

---@param props {bracketId: string, matchId: string, gameIdx: integer}
---@return Html
function CustomGameSummary.getGameByMatchId(props)
---@class FortniteMatchGroupUtilMatch
local match = MatchGroupUtil.fetchMatchForBracketDisplay(props.bracketId, props.matchId)

local game = match.games[props.gameIdx]
assert(game, 'Error Game ID ' .. tostring(props.gameIdx) .. ' not found')

game.stream = match.stream

CustomGameSummary._opponents(game, match.opponents)
local scoringData = SummaryHelper.createScoringData(match)

return MatchSummaryWidgets.Tab{
matchId = match.matchId,
idx = props.gameIdx,
children = {
CustomGameSummary._createGameDetails(game),
MatchSummaryWidgets.PointsDistribution{killScore = scoringData.kill, placementScore = scoringData.placement},
SummaryHelper.standardGame(game)
}
}
end

---@param game table
---@return Widget
function CustomGameSummary._createGameDetails(game)
return MatchSummaryWidgets.ContentItemContainer{contentClass = 'panel-content__game-schedule',
items = {
{
icon = MatchSummaryWidgets.CountdownIcon{game = game},
content = MatchSummaryWidgets.GameCountdown{game = game},
},
game.map and {
icon = IconWidget{iconName = 'map'},
content = HtmlWidgets.Span{children = Page.makeInternalLink(game.map)},
} or nil,
}
}
end

---@param game table
---@param matchOpponents table[]
function CustomGameSummary._opponents(game, matchOpponents)
-- Add match opponent data to game opponent
game.opponents = Array.map(game.opponents,
function(gameOpponent, opponentIdx)
local matchOpponent = matchOpponents[opponentIdx]
local newGameOpponent = Table.merge(matchOpponent, gameOpponent)
-- These values are only allowed to come from Game and not Match
newGameOpponent.placement = gameOpponent.placement
newGameOpponent.score = gameOpponent.score
newGameOpponent.status = gameOpponent.status
return newGameOpponent
end
)

-- Sort game level based on placement
Array.sortInPlaceBy(game.opponents, FnUtil.identity, SummaryHelper.placementSortFunction)
end

return CustomGameSummary
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
-- @Liquipedia
-- wiki=fortnite
-- page=Module:GetMatchGroupCopyPaste/wiki
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Array = require('Module:Array')
local Class = require('Module:Class')
local Lua = require('Module:Lua')

local OpponentLibraries = require('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent

local BaseCopyPaste = Lua.import('Module:GetMatchGroupCopyPaste/wiki/Base')

---WikiSpecific Code for MatchList and Bracket Code Generators
---@class FortniteMatchCopyPaste: Match2CopyPasteBase
local WikiCopyPaste = Class.new(BaseCopyPaste)

local INDENT = WikiCopyPaste.Indent

---returns the Code for a Match, depending on the input
---@param bestof integer
---@param mode string
---@param index integer
---@param opponents integer
---@param args table
---@return string
function WikiCopyPaste.getMatchCode(bestof, mode, index, opponents, args)
local defaultScoring = '|p1= |p2= |p3= |p4= |p5= |p6= |p7= |p8= |p9= |p10= |p11= |p12= |p13= |p14= |p15= |p_kill=4'
if mode == Opponent.duo then
defaultScoring = '|p1=65|p2=56|p3=52|p4=48|p5=44|p6=40|p7=38|p8=36|p9=34|p10=32|p11=30|p12=28|p13=26|p14=24' ..
'|p15=22|p16=20|p17=18|p18=16|p19=14|p20=12|p21=10|p22=8|p23=6|p24=4|p25=2|p_kill=4'
elseif mode == Opponent.trio or mode == Opponent.team then
defaultScoring = '|p1=65|p2=54|p3=48|p4=44|p5=40|p6=36|p7=33|p8=30|p9=27|p10=24|p11=21|p12=18|p13=15|p14=12'..
'|p15=9|p16=6|p17=3|p_kill=4'
end

local lines = Array.extend(
'{{Match|finished=',
INDENT .. defaultScoring,
{INDENT .. '|twitch=|youtube='},
Array.map(Array.range(1, bestof), function(mapIndex)
return INDENT .. '|map' .. mapIndex .. '={{Map|date=|finished=|map=|vod=}}'
end),
Array.map(Array.range(1, opponents), function(opponentIndex)
return INDENT .. '|opponent' .. opponentIndex .. '=' .. WikiCopyPaste._getOpponent(mode, bestof)
end),
'}}'
)

return table.concat(lines, '\n')
end

--subfunction used to generate the code for the Opponent template, depending on the type of opponent
---@param mode string
---@param mapCount integer
---@return string
function WikiCopyPaste._getOpponent(mode, mapCount)
local mapScores = table.concat(Array.map(Array.range(1, mapCount), function(idx)
return '|m' .. idx .. '={{MS||}}'
end))

if mode == Opponent.solo then
return '{{SoloOpponent||flag=' .. mapScores .. '}}'
elseif mode == Opponent.duo then
return '{{2Opponent|' .. mapScores .. '}}'
elseif mode == Opponent.trio then
return '{{3Opponent|' .. mapScores .. '}}'
elseif mode == Opponent.team then
return '{{TeamOpponent|' .. mapScores .. '}}'
elseif mode == Opponent.literal then
return '{{Literal|' .. mapScores .. '}}'
end

return ''
end

return WikiCopyPaste
Loading

0 comments on commit fa6641c

Please sign in to comment.