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): support call of duty warzone (BR) #5199

Merged
merged 1 commit into from
Dec 12, 2024
Merged
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
46 changes: 46 additions & 0 deletions components/match2/wikis/callofduty/game_summary.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
-- @Liquipedia
-- wiki=callofduty
-- page=Module:GameSummary
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local CustomGameSummary = {}

local Lua = require('Module:Lua')

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

local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/Ffa/All')

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

---@param props {bracketId: string, matchId: string, gameIdx: integer}
---@return Html
function CustomGameSummary.getGameByMatchId(props)
---@class CoDFfaMatchGroupUtilMatch
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

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

return MatchSummaryWidgets.Tab{
matchId = match.matchId,
idx = props.gameIdx,
children = {
MatchSummaryWidgets.GameDetails{game = game},
MatchSummaryWidgets.PointsDistribution{scores = scoringData},
SummaryHelper.standardGame(game)
}
}
end

return CustomGameSummary
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ local Lua = require('Module:Lua')

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

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

---@class CallofDutyMatch2CopyPaste: Match2CopyPasteBase
local WikiCopyPaste = Class.new(BaseCopyPaste)

Expand All @@ -26,6 +29,20 @@ local INDENT = WikiCopyPaste.Indent
---@param args table
---@return string
function WikiCopyPaste.getMatchCode(bestof, mode, index, opponents, args)
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)

Expand All @@ -47,4 +64,50 @@ 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_kill=2 |p2_kill=1.8 |p3_kill=1.8 |p4_kill=1.8 |p5_kill=1.8 ' ..
'|p6_kill=1.6 |p7_kill=1.6 |p8_kill=1.6 |p9_kill=1.6 |p10_kill=1.6 ' ..
'|p11_kill=1.4 |p12_kill=1.4 |p13_kill=1.4 |p14_kill=1.4 |p15_kill=1.4 ' ..
'|p16_kill=1.2 |p17_kill=1.2 |p18_kill=1.2 |p19_kill=1.2 |p20_kill=1.2 ' ..
'|p21_kill=1.2 |p22_kill=1.2 |p23_kill=1.2 |p24_kill=1.2 |p25_kill=1.2 ' ..
INDENT .. '|twitch=|youtube=',
Array.map(Array.range(1, bestof), function(mapIndex)
return INDENT .. '|map' .. mapIndex .. '={{Map|map=|date=|finished=|vod=}}'
end),
Array.map(Array.range(1, opponents), function(opponentIndex)
return INDENT .. '|opponent' .. opponentIndex .. '=' .. WikiCopyPaste._getFfaOpponent(mode, bestof)
end),
'}}'
)

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

---@param mode string
---@param mapCount integer
---@return string
function WikiCopyPaste._getFfaOpponent(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.team then
return '{{TeamOpponent|' .. mapScores .. '}}'
elseif mode == Opponent.literal then
return '{{Literal|}}'
end

return ''
end

return WikiCopyPaste
65 changes: 54 additions & 11 deletions components/match2/wikis/callofduty/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,31 @@
local Array = require('Module:Array')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Operator = require('Module:Operator')
local Variables = require('Module:Variables')

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

local DEFAULT_BESTOF = 3

local CustomMatchGroupInput = {}
local MatchFunctions = {}
local MatchFunctions = {
DEFAULT_MODE = 'team',
}
local MapFunctions = {}

MatchFunctions.DEFAULT_MODE = 'team'
local FfaMatchFunctions = {
DEFAULT_MODE = 'team',
}
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 table[]
---@return table[]
Expand Down Expand Up @@ -72,10 +75,6 @@ function MatchFunctions.getExtraData(match, games, opponents)
}
end

--
-- map related functions
--

---@param match table
---@param map table
---@param opponents table[]
Expand All @@ -86,4 +85,48 @@ function MapFunctions.getExtraData(match, map, opponents)
}
end

--- FFA Match

---@param match table
---@param opponents table[]
---@param scoreSettings table
---@return table[]
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 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

---@param match table
---@param games table[]
---@param opponents table[]
---@param settings table
---@return table
function FfaMatchFunctions.getExtraData(match, games, opponents, settings)
return {
placementinfo = settings.placementInfo,
settings = settings.settings,
}
end

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

return CustomMatchGroupInput
44 changes: 44 additions & 0 deletions components/match2/wikis/callofduty/match_summary_ffa.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
-- @Liquipedia
-- wiki=callofduty
-- 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')
local SummaryHelper = Lua.import('Module:MatchSummary/Base/Ffa')

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

---@class CoDFfaMatchGroupUtilMatch: MatchGroupUtilMatch
---@field games CoDFfaMatchGroupUtilGame[]

---@param props {bracketId: string, matchId: string}
---@return Widget
function CustomMatchSummary.getByMatchId(props)
---@class CoDFfaMatchGroupUtilMatch
local match = MatchGroupUtil.fetchMatchForBracketDisplay(props.bracketId, props.matchId)
SummaryHelper.updateMatchOpponents(match)
local scoringData = SummaryHelper.createScoringData(match)

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

return CustomMatchSummary
Loading