Skip to content

Commit

Permalink
feat(match2): Add non-BR support for Free Fire (#5294)
Browse files Browse the repository at this point in the history
* feat(match2): Add non-BR support for Free Fire

* add process

* Add generator
  • Loading branch information
Hesketh2 authored Jan 10, 2025
1 parent 1385cc9 commit 5a47087
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,65 @@ local Array = require('Module:Array')
local Class = require('Module:Class')
local Lua = require('Module:Lua')

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

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 FreefireMatchCopyPaste: Match2CopyPasteBase
local WikiCopyPaste = Class.new(BaseCopyPaste)

local INDENT = WikiCopyPaste.Indent

---returns the Code for a Match, depending on the input
--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)
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 = bestof == 0

local lines = Array.extend(
'{{Match',
showScore and (INDENT .. '|finished=') or nil,
{INDENT .. '|date='},
{INDENT .. '|twitch=|youtube='},
{INDENT .. '|vod='},
Array.map(Array.range(1, opponents), function(opponentIndex)
return INDENT .. '|opponent' .. opponentIndex .. '=' .. WikiCopyPaste.getOpponent(mode, showScore)
end),
Array.map(Array.range(1, bestof), function(mapIndex)
return INDENT .. '|map' .. mapIndex .. '={{Map|map=|score1=|score2=|finished=}}'
end),
'}}'
)

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=8 |p4=7 |p5=6 |p6=5 |p7=4 |p8=3 |p9=2 |p10=1 |p11=0 |p12=0',
Expand All @@ -37,19 +77,18 @@ function WikiCopyPaste.getMatchCode(bestof, mode, index, opponents, args)
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)
return INDENT .. '|opponent' .. opponentIndex .. '=' .. WikiCopyPaste._getFfaOpponent(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)
function WikiCopyPaste._getFfaOpponent(mode, mapCount)
local mapScores = table.concat(Array.map(Array.range(1, mapCount), function(idx)
return '|m' .. idx .. '={{MS||}}'
end))
Expand Down
85 changes: 68 additions & 17 deletions components/match2/wikis/freefire/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,100 @@
--

local Array = require('Module:Array')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
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 = 4,
},
DEFAULT_MODE = 'team'
DEFAULT_MODE = 'team',
getBestOf = MatchGroupInputUtil.getBestOf,
}

local CustomMatchGroupInput = {}
local FfaMatchFunctions = {
OPPONENT_CONFIG = {
resolveRedirect = true,
applyUnderScores = true,
maxNumPlayers = 4,
},
DEFAULT_MODE = 'team',
}
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

--- 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 maps table[]
---@return fun(opponentIndex: integer): integer?
function MatchFunctions.calculateMatchScore(maps)
return function(opponentIndex)
return MatchGroupInputUtil.computeMatchScoreFromMapWinners(maps, opponentIndex)
end
end

---@param games table[]
---@return table[]
function MatchFunctions.removeUnsetMaps(games)
return Array.filter(games, Logic.isNotDeepEmpty)
end

--
-- match related functions
--
---@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 +113,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/freefire/match_summary.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
-- @Liquipedia
-- wiki=freefire
-- 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

0 comments on commit 5a47087

Please sign in to comment.