From b66665d281ec9eb6371570624352ab37028f66d0 Mon Sep 17 00:00:00 2001
From: Rikard Blixt <rikardblixt@gmail.com>
Date: Fri, 3 Jan 2025 14:26:06 +0100
Subject: [PATCH] parsing

---
 components/match2/commons/match_group_input_util.lua     | 8 +++++++-
 .../match2/wikis/trackmania/match_group_input_custom.lua | 9 ++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/components/match2/commons/match_group_input_util.lua b/components/match2/commons/match_group_input_util.lua
index c4c51f696a0..48e3f8b94e5 100644
--- a/components/match2/commons/match_group_input_util.lua
+++ b/components/match2/commons/match_group_input_util.lua
@@ -1064,6 +1064,7 @@ end
 ---@class MatchParserInterface
 ---@field extractMaps fun(match: table, opponents: table[], mapProps: any?): table[]
 ---@field getBestOf fun(bestOfInput: string|integer|nil, maps: table[]): integer?
+---@field switchToFfa? fun(match: table, opponents: table[]): boolean
 ---@field calculateMatchScore? fun(maps: table[], opponents: table[]): fun(opponentIndex: integer): integer?
 ---@field removeUnsetMaps? fun(maps: table[]): table[]
 ---@field getExtraData? fun(match: table, games: table[], opponents: table[]): table?
@@ -1083,6 +1084,7 @@ end
 --- - getBestOf(bestOfInput, maps): integer?
 ---
 --- It may optionally have the following functions:
+--- - switchToFfa(match, opponents): boolean
 --- - calculateMatchScore(maps, opponents): fun(opponentIndex): integer?
 --- - removeUnsetMaps(maps): table[]
 --- - getExtraData(match, games, opponents): table?
@@ -1116,7 +1118,11 @@ function MatchGroupInputUtil.standardProcessMatch(match, Parser, FfaParser, mapP
 		return opponent
 	end)
 
-	if FfaParser and #opponents > 2 then
+	local function defaultSwitchToFfa()
+		return #opponents > 2
+	end
+	local switchToFfa = Parser.switchToFfa or defaultSwitchToFfa
+	if FfaParser and switchToFfa(match, opponents) then
 		return MatchGroupInputUtil.standardProcessFfaMatch(matchInput, FfaParser, mapProps)
 	end
 
diff --git a/components/match2/wikis/trackmania/match_group_input_custom.lua b/components/match2/wikis/trackmania/match_group_input_custom.lua
index 7dfe32e4ffd..cc750de03af 100644
--- a/components/match2/wikis/trackmania/match_group_input_custom.lua
+++ b/components/match2/wikis/trackmania/match_group_input_custom.lua
@@ -36,7 +36,14 @@ function CustomMatchGroupInput.processMatch(match, options)
 	return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions, FfaMatchFunctions)
 end
 
---- Normal 2-opponent Match
+--- Up to 4-opponents
+
+---@param match table
+---@param opponents table[]
+---@return boolean
+function MatchFunctions.switchToFfa(match, opponents)
+	return #opponents > 4
+end
 
 ---@param match table
 ---@param opponents table[]