Skip to content

Commit

Permalink
feat(match2): make standard BR-map parsing (#5186)
Browse files Browse the repository at this point in the history
* feat(match2): make standard BR-map parsing

* fix extradata interface
  • Loading branch information
Rathoz authored Dec 10, 2024
1 parent e56f6b5 commit 71c2c9a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 175 deletions.
40 changes: 39 additions & 1 deletion components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ end
---@field ADD_SUB_GROUP? boolean
---@field BREAK_ON_EMPTY? boolean

--- The standard way to process a match input.
--- The standard way to process a map input.
---
--- The Parser injection may optionally have the following functions:
--- - calculateMapScore(map): fun(opponentIndex): integer?
Expand Down Expand Up @@ -1345,6 +1345,44 @@ function MatchGroupInputUtil.standardProcessFfaMatch(match, Parser, mapProps)
return match
end

--- The standard way to process a ffa map input.
---
--- The Parser injection may optionally have the following functions:
--- - getExtraData(match, map, opponents): table?
---
---@param match table
---@param opponents table[]
---@param Parser MapParserInterface
---@return table
function MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, Parser)
local maps = {}
for key, map, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

Table.mergeInto(map, MatchGroupInputUtil.readDate(map.date))
map.finished = MatchGroupInputUtil.mapIsFinished(map)

map.opponents = Array.map(opponents, function(matchOpponent)
local opponentMapInput = Json.parseIfString(matchOpponent['m' .. mapIndex])
return MatchGroupInputUtil.makeBattleRoyaleMapOpponentDetails(opponentMapInput, scoreSettings)
end)

map.scores = Array.map(map.opponents, Operator.property('score'))
if map.finished then
map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput)
map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents)
end

map.extradata = Parser.getExtraData and Parser.getExtraData(match, map, opponents) or nil

table.insert(maps, map)
match[key] = nil
end

return maps
end

---@param opponents table[]
---@return integer[]
function MatchGroupInputUtil.calculatePlacementOfOpponents(opponents)
Expand Down
33 changes: 4 additions & 29 deletions components/match2/wikis/apexlegends/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
--

local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
local Operator = require('Module:Operator')
local Table = require('Module:Table')

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

Expand Down Expand Up @@ -41,32 +39,7 @@ end
---@param scoreSettings table
---@return table[]
function MatchFunctions.extractMaps(match, opponents, scoreSettings)
local maps = {}
for key, map, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

Table.mergeInto(map, MatchGroupInputUtil.readDate(map.date))
map.finished = MatchGroupInputUtil.mapIsFinished(map)

map.opponents = Array.map(opponents, function(matchOpponent)
local opponentMapInput = Json.parseIfString(matchOpponent['m' .. mapIndex])
return MatchGroupInputUtil.makeBattleRoyaleMapOpponentDetails(opponentMapInput, scoreSettings)
end)

map.scores = Array.map(map.opponents, Operator.property('score'))
if map.finished then
map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput)
map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents)
end

map.extradata = MapFunctions.getExtraData(map)

table.insert(maps, map)
match[key] = nil
end

return maps
return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, MapFunctions)
end

---@param opponents table[]
Expand Down Expand Up @@ -97,9 +70,11 @@ end
-- map related functions
--

---@param match table
---@param map table
---@param opponents table[]
---@return table
function MapFunctions.getExtraData(map)
function MapFunctions.getExtraData(match, map, opponents)
return {
dateexact = map.dateexact,
comment = map.comment,
Expand Down
33 changes: 4 additions & 29 deletions components/match2/wikis/fortnite/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
--

local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
local Operator = require('Module:Operator')
local Table = require('Module:Table')

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

Expand Down Expand Up @@ -41,32 +39,7 @@ end
---@param scoreSettings table
---@return table[]
function MatchFunctions.extractMaps(match, opponents, scoreSettings)
local maps = {}
for key, map, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

Table.mergeInto(map, MatchGroupInputUtil.readDate(map.date))
map.finished = MatchGroupInputUtil.mapIsFinished(map)

map.opponents = Array.map(opponents, function(matchOpponent)
local opponentMapInput = Json.parseIfString(matchOpponent['m' .. mapIndex])
return MatchGroupInputUtil.makeBattleRoyaleMapOpponentDetails(opponentMapInput, scoreSettings)
end)

map.scores = Array.map(map.opponents, Operator.property('score'))
if map.finished then
map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput)
map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents)
end

map.extradata = MapFunctions.getExtraData(map)

table.insert(maps, map)
match[key] = nil
end

return maps
return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, MapFunctions)
end

---@param opponents table[]
Expand Down Expand Up @@ -97,9 +70,11 @@ end
-- map related functions
--

---@param match table
---@param map table
---@param opponents table[]
---@return table
function MapFunctions.getExtraData(map)
function MapFunctions.getExtraData(match, map, opponents)
return {
dateexact = map.dateexact,
comment = map.comment,
Expand Down
33 changes: 4 additions & 29 deletions components/match2/wikis/freefire/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
--

local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
local Operator = require('Module:Operator')
local Table = require('Module:Table')

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

Expand Down Expand Up @@ -41,32 +39,7 @@ end
---@param scoreSettings table
---@return table[]
function MatchFunctions.extractMaps(match, opponents, scoreSettings)
local maps = {}
for key, map, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

Table.mergeInto(map, MatchGroupInputUtil.readDate(map.date))
map.finished = MatchGroupInputUtil.mapIsFinished(map)

map.opponents = Array.map(opponents, function(matchOpponent)
local opponentMapInput = Json.parseIfString(matchOpponent['m' .. mapIndex])
return MatchGroupInputUtil.makeBattleRoyaleMapOpponentDetails(opponentMapInput, scoreSettings)
end)

map.scores = Array.map(map.opponents, Operator.property('score'))
if map.finished then
map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput)
map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents)
end

map.extradata = MapFunctions.getExtraData(map)

table.insert(maps, map)
match[key] = nil
end

return maps
return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, MapFunctions)
end

---@param opponents table[]
Expand Down Expand Up @@ -97,9 +70,11 @@ end
-- map related functions
--

---@param match table
---@param map table
---@param opponents table[]
---@return table
function MapFunctions.getExtraData(map)
function MapFunctions.getExtraData(match, map, opponents)
return {
dateexact = map.dateexact,
comment = map.comment,
Expand Down
33 changes: 4 additions & 29 deletions components/match2/wikis/naraka/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
--

local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
local Operator = require('Module:Operator')
local Table = require('Module:Table')

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

Expand Down Expand Up @@ -41,32 +39,7 @@ end
---@param scoreSettings table
---@return table[]
function MatchFunctions.extractMaps(match, opponents, scoreSettings)
local maps = {}
for key, map, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

Table.mergeInto(map, MatchGroupInputUtil.readDate(map.date))
map.finished = MatchGroupInputUtil.mapIsFinished(map)

map.opponents = Array.map(opponents, function(matchOpponent)
local opponentMapInput = Json.parseIfString(matchOpponent['m' .. mapIndex])
return MatchGroupInputUtil.makeBattleRoyaleMapOpponentDetails(opponentMapInput, scoreSettings)
end)

map.scores = Array.map(map.opponents, Operator.property('score'))
if map.finished then
map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput)
map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents)
end

map.extradata = MapFunctions.getExtraData(map)

table.insert(maps, map)
match[key] = nil
end

return maps
return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, MapFunctions)
end

---@param opponents table[]
Expand Down Expand Up @@ -97,9 +70,11 @@ end
-- map related functions
--

---@param match table
---@param map table
---@param opponents table[]
---@return table
function MapFunctions.getExtraData(map)
function MapFunctions.getExtraData(match, map, opponents)
return {
dateexact = map.dateexact,
comment = map.comment,
Expand Down
33 changes: 4 additions & 29 deletions components/match2/wikis/pubg/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
--

local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
local Operator = require('Module:Operator')
local Table = require('Module:Table')

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

Expand Down Expand Up @@ -41,32 +39,7 @@ end
---@param scoreSettings table
---@return table[]
function MatchFunctions.extractMaps(match, opponents, scoreSettings)
local maps = {}
for key, map, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

Table.mergeInto(map, MatchGroupInputUtil.readDate(map.date))
map.finished = MatchGroupInputUtil.mapIsFinished(map)

map.opponents = Array.map(opponents, function(matchOpponent)
local opponentMapInput = Json.parseIfString(matchOpponent['m' .. mapIndex])
return MatchGroupInputUtil.makeBattleRoyaleMapOpponentDetails(opponentMapInput, scoreSettings)
end)

map.scores = Array.map(map.opponents, Operator.property('score'))
if map.finished then
map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput)
map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents)
end

map.extradata = MapFunctions.getExtraData(map)

table.insert(maps, map)
match[key] = nil
end

return maps
return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, MapFunctions)
end

---@param opponents table[]
Expand Down Expand Up @@ -97,9 +70,11 @@ end
-- map related functions
--

---@param match table
---@param map table
---@param opponents table[]
---@return table
function MapFunctions.getExtraData(map)
function MapFunctions.getExtraData(match, map, opponents)
return {
dateexact = map.dateexact,
comment = map.comment,
Expand Down
Loading

0 comments on commit 71c2c9a

Please sign in to comment.