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

feat(match2): Add non-BR support for Fortnite #5244

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
82 changes: 65 additions & 17 deletions components/match2/wikis/fortnite/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,92 @@ local Operator = require('Module:Operator')

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

local MapFunctions = {}
local CustomMatchGroupInput = {}
local MatchFunctions = {
OPPONENT_CONFIG = {
resolveRedirect = true,
applyUnderScores = true,
maxNumPlayers = 3,
},
DEFAULT_MODE = 'team'
DEFAULT_MODE = 'team',
getBestOf = MatchGroupInputUtil.getBestOf,
}

local CustomMatchGroupInput = {}
local FfaMatchFunctions = {}
local MapFunctions = {}
local FfaMapFunctions = {}

---@param match table
---@param options table?
---@return table
function CustomMatchGroupInput.processMatch(match, options)
return MatchGroupInputUtil.standardProcessFfaMatch(match, MatchFunctions)
return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions, FfaMatchFunctions)
end

--
-- match related functions
--
--- Normal 2-opponent Match

---@param match table
---@param opponents table[]
---@return table[]
function MatchFunctions.extractMaps(match, opponents)
return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions)
end

---@param match table
---@param games table[]
---@param opponents table[]
---@return table
function MatchFunctions.getExtraData(match, games, opponents)
return {
mvp = MatchGroupInputUtil.readMvp(match, opponents),
casters = MatchGroupInputUtil.readCasters(match),
}
end

---@param maps table[]
---@return fun(opponentIndex: integer): integer?
function MatchFunctions.calculateMatchScore(maps)
return function(opponentIndex)
return MatchGroupInputUtil.computeMatchScoreFromMapWinners(maps, opponentIndex)
end
end

---@param match table
---@param map table
---@param opponents table[]
---@return table
function MapFunctions.getExtraData(match, map, opponents)
return {
comment = map.comment,
}
end

---@param map table
---@return fun(opponentIndex: integer): integer?
function MapFunctions.calculateMapScore(map)
local winner = tonumber(map.winner)
return function(opponentIndex)
-- TODO Better to check if map has started, rather than finished, for a more correct handling
if not winner and not map.finished then
return
end
return winner == opponentIndex and 1 or 0
end
end

--- FFA Match

---@param match table
---@param opponents table[]
---@param scoreSettings table
---@return table[]
function MatchFunctions.extractMaps(match, opponents, scoreSettings)
return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, MapFunctions)
function FfaMatchFunctions.extractMaps(match, opponents, scoreSettings)
return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, FfaMapFunctions)
end

---@param opponents table[]
---@param maps table[]
---@return fun(opponentIndex: integer): integer?
function MatchFunctions.calculateMatchScore(opponents, maps)
function FfaMatchFunctions.calculateMatchScore(opponents, maps)
return function(opponentIndex)
return Array.reduce(Array.map(maps, function(map)
return map.opponents[opponentIndex].score or 0
Expand All @@ -58,22 +110,18 @@ end
---@param opponents table[]
---@param settings table
---@return table
function MatchFunctions.getExtraData(match, games, opponents, settings)
function FfaMatchFunctions.getExtraData(match, games, opponents, settings)
return {
placementinfo = settings.placementInfo,
settings = settings.settings,
}
end

--
-- map related functions
--

---@param match table
---@param map table
---@param opponents table[]
---@return table
function MapFunctions.getExtraData(match, map, opponents)
function FfaMapFunctions.getExtraData(match, map, opponents)
return {
dateexact = map.dateexact,
comment = map.comment,
Expand Down
51 changes: 51 additions & 0 deletions components/match2/wikis/fortnite/match_summary.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
-- @Liquipedia
-- wiki=fortnite
-- page=Module:MatchSummary
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Lua = require('Module:Lua')

local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
local MatchSummary = Lua.import('Module:MatchSummary/Base')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')
local WidgetUtil = Lua.import('Module:Widget/Util')

local CustomMatchSummary = {}

---@param args table
---@return Html
function CustomMatchSummary.getByMatchId(args)
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args)
end

---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
---@return Widget?
function CustomMatchSummary.createGame(date, game, gameIndex)
if not game.map then
return
end

local function makeTeamSection(opponentIndex)
return {
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.opponents[opponentIndex], game.status)
}
end

return MatchSummaryWidgets.Row{
classes = {'brkts-popup-body-game'},
children = WidgetUtil.collect(
MatchSummaryWidgets.GameTeamWrapper{children = makeTeamSection(1)},
MatchSummaryWidgets.GameCenter{children = DisplayHelper.Map(game)},
MatchSummaryWidgets.GameTeamWrapper{children = makeTeamSection(2), flipped = true},
MatchSummaryWidgets.GameComment{children = game.comment}
)
}
end

return CustomMatchSummary
Loading