Skip to content

Commit

Permalink
feat(match2): support freefire (#5160)
Browse files Browse the repository at this point in the history
* copy paste of pubm

* add manual points support

* move `Horizontallist` check to commons

* rename `pointmodifier` to `startingpoints` (as this is what the code treats it as)
add support for it on all BR wikis

* setttings for game details

* missign check

* parsing typo

* add styling too

* update default points
  • Loading branch information
Rathoz authored Dec 4, 2024
1 parent 5407e44 commit 9185577
Show file tree
Hide file tree
Showing 15 changed files with 507 additions and 76 deletions.
6 changes: 5 additions & 1 deletion components/match2/commons/brkts_wiki_specific_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ Called from MatchGroup
-- @returns module
]]
function WikiSpecificBase.getMatchGroupContainer(matchGroupType)
if matchGroupType == 'matchlist' then
-- TODO Add a check if opponent count is > 2
if Lua.moduleExists('Module:GameSummary') then
local Horizontallist = Lua.import('Module:MatchGroup/Display/Horizontallist')
return Horizontallist.BracketContainer
elseif matchGroupType == 'matchlist' then
local MatchList = Lua.import('Module:MatchGroup/Display/Matchlist')
return MatchList.MatchlistContainer
end
Expand Down
2 changes: 1 addition & 1 deletion components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ function MatchGroupInputUtil.standardProcessFfaMatch(match, Parser, mapProps)
or nil
Array.forEach(opponents, function(opponent, opponentIndex)
opponent.extradata = opponent.extradata or {}
opponent.extradata.startingpoints = tonumber(opponent.pointmodifier)
opponent.extradata.startingpoints = tonumber(opponent.startingpoints)
opponent.placement = tonumber(opponent.placement)

opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({
Expand Down
30 changes: 30 additions & 0 deletions components/match2/commons/match_summary_ffa.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ local MATCH_OVERVIEW_COLUMNS = {
}
local GAME_OVERVIEW_COLUMNS = {
{
show = function(match)
return match.extradata.settings.showGameDetails
end,
class = 'panel-table__cell__game-placement',
icon = 'placement',
header = {
Expand Down Expand Up @@ -184,6 +187,9 @@ local GAME_OVERVIEW_COLUMNS = {
},
},
{
show = function(match)
return match.extradata.settings.showGameDetails
end,
class = 'panel-table__cell__game-kills',
icon = 'kills',
header = {
Expand All @@ -195,6 +201,21 @@ local GAME_OVERVIEW_COLUMNS = {
end,
},
},
{
show = function(match)
return not match.extradata.settings.showGameDetails
end,
class = 'panel-table__cell__game-total-points',
icon = 'points',
header = {
value = 'Pts.',
},
row = {
value = function (opponent)
return opponent.score
end,
},
},
}
local GAME_STANDINGS_COLUMNS = {
{
Expand Down Expand Up @@ -274,6 +295,9 @@ local GAME_STANDINGS_COLUMNS = {
},
},
{
show = function(match)
return match.extradata.settings.showGameDetails
end,
sortable = true,
sortType = 'placements',
class = 'cell--placements',
Expand All @@ -293,6 +317,9 @@ local GAME_STANDINGS_COLUMNS = {
},
},
{
show = function(match)
return match.extradata.settings.showGameDetails
end,
sortable = true,
sortType = 'kills',
class = 'cell--kills',
Expand Down Expand Up @@ -451,6 +478,9 @@ function MatchSummaryFfa.standardMatch(match)
HtmlWidgets.Div{
classes = {'panel-table__cell__game-details'},
children = Array.map(GAME_OVERVIEW_COLUMNS, function(column)
if column.show and not column.show(match) then
return
end
return MatchSummaryWidgets.TableHeaderCell{
class = column.class,
icon = column.icon,
Expand Down
24 changes: 0 additions & 24 deletions components/match2/wikis/apexlegends/brkts_wiki_specific.lua

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

local Array = require('Module:Array')
local Json = require('Module:Json')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Operator = require('Module:Operator')
local Table = require('Module:Table')
Expand Down Expand Up @@ -106,6 +107,9 @@ function MatchFunctions.parseSettings(match)
return {
score = scoreSettings,
status = statusSettings,
settings = {
showGameDetails = Logic.nilOr(Logic.readBoolOrNil(match.showgamedetails), true),
}
}
end

Expand All @@ -118,6 +122,7 @@ function MatchFunctions.getExtraData(match, games, opponents, settings)
return {
scoring = settings.score,
status = settings.status,
settings = settings.settings,
}
end

Expand Down
89 changes: 89 additions & 0 deletions components/match2/wikis/freefire/game_summary.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
-- @Liquipedia
-- wiki=freefire
-- 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 FreefireMatchGroupUtilGame: MatchGroupUtilGame
---@field stream table

---@param props {bracketId: string, matchId: string, gameIdx: integer}
---@return Html
function CustomGameSummary.getGameByMatchId(props)
---@class ApexMatchGroupUtilMatch
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,68 @@
---
-- @Liquipedia
-- wiki=freefire
-- 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 FreefireMatchCopyPaste: 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 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',
{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.team then
return '{{TeamOpponent|' .. mapScores .. '}}'
elseif mode == Opponent.literal then
return '{{Literal|' .. mapScores .. '}}'
end

return ''
end

return WikiCopyPaste
Loading

0 comments on commit 9185577

Please sign in to comment.