Skip to content
42 changes: 40 additions & 2 deletions lua/wikis/tarkovarena/GetMatchGroupCopyPaste/wiki.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,27 @@ local INDENT = WikiCopyPaste.Indent
---@param args table
---@return string
function WikiCopyPaste.getMatchCode(bestof, mode, index, opponents, args)
local showScore = bestof == 0
if opponents > 2 then
return WikiCopyPaste.getFfaMatchCode(bestof, mode, index, opponents, args)
else
return WikiCopyPaste.getStandardMatchCode(bestof, mode, index, opponents, args)
end
end

---@param bestof integer
---@param mode string
---@param index integer
---@param opponents integer
---@param args table
---@return string
function WikiCopyPaste.getStandardMatchCode(bestof, mode, index, opponents, args)
local showScore = Logic.nilOr(Logic.readBool(args.score), bestof == 0)
local opponent = WikiCopyPaste.getOpponent(mode, showScore)

local lines = Array.extendWith({},
'{{Match',
showScore and (INDENT .. '|finished=') or nil,
index == 1 and (INDENT .. '|bestof=' .. (bestof ~= 0 and bestof or '')) or nil,
Logic.readBool(args.needsWinner) and (INDENT .. '|winner=') or nil,
INDENT .. '|date=',
Logic.readBool(args.streams) and (INDENT .. '|twitch=|youtube=|vod=') or nil,
Array.map(Array.range(1, opponents), function(opponentIndex)
Expand All @@ -46,4 +61,27 @@ function WikiCopyPaste.getMatchCode(bestof, mode, index, opponents, args)
return table.concat(lines, '\n')
end

---@param bestof integer
---@param mode string
---@param index integer
---@param opponents integer
---@param args table
---@return string
function WikiCopyPaste.getFfaMatchCode(bestof, mode, index, opponents, args)
local lines = Array.extend(
'{{Match|finished=',
INDENT .. '|p_kill=1 |p1=12 |p2=9 |p3=7 |p4=5 |p5=4 |p6=3 |p7=3 |p8=2 |p9=2 |p10=2 ' ..
INDENT .. '|twitch=|youtube=',
Array.mapRange(1, bestof, function(mapIndex)
return INDENT .. '|map' .. mapIndex .. '={{Map|map=|date=|finished=|vod=}}'
end),
Array.mapRange(1, opponents, function(opponentIndex)
return INDENT .. '|opponent' .. opponentIndex .. '=' .. WikiCopyPaste.getFfaOpponent(mode, bestof)
end),
'}}'
)

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

return WikiCopyPaste
41 changes: 37 additions & 4 deletions lua/wikis/tarkovarena/MatchGroup/Input/Custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,39 @@

local Lua = require('Module:Lua')

local Array = Lua.import('Module:Array')
local FnUtil = Lua.import('Module:FnUtil')
local Operator = Lua.import('Module:Operator')

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

local CustomMatchGroupInput = {}

---@class TarkovArenaMatchParser: MatchParserInterface
local MatchFunctions = {
DEFAULT_MODE = 'team',
getBestOf = MatchGroupInputUtil.getBestOf,
}

---@class TarkovArenaMapParser: MapParserInterface
local MapFunctions = {}

---@class TarkovArenaFfaMatchParser: FfaMatchParserInterface
local FfaMatchFunctions = {
DEFAULT_MODE = 'team',
}

---@class TarkovArenaFfaMapParser: FfaMapParserInterface
local FfaMapFunctions = {}

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

--
-- match related functions
--
-- "Normal" match
---@param match table
---@param opponents MGIParsedOpponent[]
---@return table[]
Expand All @@ -41,4 +53,25 @@ function MatchFunctions.calculateMatchScore(maps)
return FnUtil.curry(MatchGroupInputUtil.computeMatchScoreFromMapWinners, maps)
end

--- FFA Match

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

---@param opponents MGIParsedOpponent[]
---@param maps table[]
---@return fun(opponentIndex: integer): integer?
function FfaMatchFunctions.calculateMatchScore(opponents, maps)
return function(opponentIndex)
return Array.reduce(Array.map(maps, function(map)
return map.opponents[opponentIndex].score or 0
end), Operator.add, 0) + (opponents[opponentIndex].extradata.startingpoints or 0)
end
end

return CustomMatchGroupInput
42 changes: 42 additions & 0 deletions lua/wikis/tarkovarena/MatchSummary/Ffa.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
-- @Liquipedia
-- page=Module:MatchSummary/Ffa
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local CustomMatchSummary = {}

local Lua = require('Module:Lua')

local MatchGroupUtil = Lua.import('Module:MatchGroup/Util/Custom')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')

local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')
local Html = Lua.import('Module:Widget/Html')
local WidgetUtil = Lua.import('Module:Widget/Util')

---@param props {bracketId: string, matchId: string}
---@return Renderable
function CustomMatchSummary.getByMatchId(props)
Comment thread
Copilot marked this conversation as resolved.
Comment thread
ElectricalBoy marked this conversation as resolved.
local match = MatchGroupUtil.fetchMatchForBracketDisplay(props.bracketId, props.matchId)
---@cast match FFAMatchGroupUtilMatch
SummaryHelper.updateMatchOpponents(match)
local scoringData = SummaryHelper.createScoringData(match)

return Html.Fragment{children = {
MatchSummaryWidgets.Header{matchId = match.matchId, games = match.games},
MatchSummaryWidgets.Tab{
matchId = match.matchId,
idx = 0,
children = WidgetUtil.collect(
MatchSummaryWidgets.GamesSchedule{match = match},
MatchSummaryWidgets.PointsDistribution{scores = scoringData},
MatchSummaryWidgets.MatchInformation(match),
SummaryHelper.standardMatch(match)
)
}
}}
end

return CustomMatchSummary
Loading