Skip to content

Commit

Permalink
feat(match2): support naraka (#5167)
Browse files Browse the repository at this point in the history
* feat(match2): support naraka

* update match level to account for change in interface

* rework kill points entirely

* fortnite too

* lint

* fix status column, update copy, update golden

* Update components/match2/commons/match_summary_ffa.lua

Co-authored-by: hjpalpha <[email protected]>

* Update components/match2/commons/match_summary_ffa.lua

Co-authored-by: hjpalpha <[email protected]>

---------

Co-authored-by: hjpalpha <[email protected]>
  • Loading branch information
Rathoz and hjpalpha authored Dec 9, 2024
1 parent 69562de commit 72433d6
Show file tree
Hide file tree
Showing 26 changed files with 525 additions and 218 deletions.
45 changes: 42 additions & 3 deletions components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ end

---@class FfaMatchParserInterface
---@field extractMaps fun(match: table, opponents: table[], mapProps: any?): table[]
---@field parseSettings fun(match: table): table
---@field parseSettings? fun(match: table, opponentCount: integer): table
---@field calculateMatchScore? fun(maps: table[], opponents: table[]): fun(opponentIndex: integer): integer?
---@field getExtraData? fun(match: table, games: table[], opponents: table[], settings: table): table?
---@field getMode? fun(opponents: table[]): string
Expand All @@ -1260,9 +1260,9 @@ end
---
--- The Parser injection must have the following functions:
--- - extractMaps(match, opponents, mapProps): table[]
--- - parseSettings(match): table
---
--- It may optionally have the following functions:
--- - parseSettings(match, opponentCount): table
--- - calculateMatchScore(maps, opponents): fun(opponentIndex): integer?
--- - getExtraData(match, games, opponents, settings): table?
--- - getMode(opponents): string?
Expand All @@ -1283,7 +1283,6 @@ function MatchGroupInputUtil.standardProcessFfaMatch(match, Parser, mapProps)
local finishedInput = match.finished --[[@as string?]]
local winnerInput = match.winner --[[@as string?]]

local settings = Parser.parseSettings(match)

local dateProps = Parser.readDate and Parser.readDate(match)
or MatchGroupInputUtil.readDate(match.date, Parser.DATE_FALLBACKS)
Expand All @@ -1297,6 +1296,9 @@ function MatchGroupInputUtil.standardProcessFfaMatch(match, Parser, mapProps)
return opponent
end)

local settings = Parser.parseSettings and Parser.parseSettings(match, #opponents)
or MatchGroupInputUtil.parseSettings(match, #opponents)

local games = Parser.extractMaps(match, opponents, settings.score)

local autoScoreFunction = Parser.calculateMatchScore and MatchGroupInputUtil.canUseAutoScore(match, games)
Expand Down Expand Up @@ -1419,5 +1421,42 @@ function MatchGroupInputUtil.calculatePlacementOfOpponents(opponents)
return placementOfTeams
end

---@param match table
---@return {score: table, status: table, settings: table}
function MatchGroupInputUtil.parseSettings(match, opponentCount)
-- Score Settings
local scoreSettings = {
kill = Array.map(Array.range(1, opponentCount), function(index)
return tonumber(match['p' .. index .. '_kill']) or tonumber(match.p_kill) or 1
end),
placement = Array.map(Array.range(1, opponentCount), function(index)
return tonumber(match['p' .. index]) or 0
end)
}

-- Status colors (up/down etc)
local statusParsed = {}
Array.forEach(Array.parseCommaSeparatedString(match.bg, ','), function (status)
local placements, color = unpack(Array.parseCommaSeparatedString(status, '='))
local pStart, pEnd = unpack(Array.parseCommaSeparatedString(placements, '-'))
local pStartNumber = tonumber(pStart) --[[@as integer]]
local pEndNumber = tonumber(pEnd) or pStartNumber
Array.forEach(Array.range(pStartNumber, pEndNumber), function(placement)
statusParsed[placement] = color
end)
end)

local statusSettings = Array.map(Array.range(1, opponentCount), function(index)
return statusParsed[index] or ''
end)

return {
score = scoreSettings,
status = statusSettings,
settings = {
showGameDetails = Logic.nilOr(Logic.readBoolOrNil(match.showgamedetails), true),
}
}
end

return MatchGroupInputUtil
47 changes: 21 additions & 26 deletions components/match2/commons/match_summary_ffa.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
--

local Array = require('Module:Array')
local FnUtil = require('Module:FnUtil')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Table = require('Module:Table')

Expand Down Expand Up @@ -44,7 +44,9 @@ local MATCH_OVERVIEW_COLUMNS = {
{
class = 'cell--status',
show = function(match)
return Table.isNotEmpty(match.extradata.status)
return Table.any(match.extradata.status or {}, function(_, value)
return Logic.isNotEmpty(value)
end)
end,
header = {
value = '',
Expand Down Expand Up @@ -297,9 +299,6 @@ local GAME_STANDINGS_COLUMNS = {
},
},
{
show = function(match)
return match.extradata.settings.showGameDetails
end,
sortable = true,
sortType = 'placements',
class = 'cell--placements',
Expand All @@ -319,9 +318,6 @@ local GAME_STANDINGS_COLUMNS = {
},
},
{
show = function(match)
return match.extradata.settings.showGameDetails
end,
sortable = true,
sortType = 'kills',
class = 'cell--kills',
Expand Down Expand Up @@ -366,27 +362,26 @@ end
function MatchSummaryFfa.createScoringData(match)
local scoreSettings = match.extradata.scoring

local scorePlacement = {}

local points = Table.groupBy(scoreSettings.placement, function (_, value)
return value
local scores = Array.map(scoreSettings.placement or {}, function(placementScore, placement)
return {placementPoints = placementScore, killPoints = (scoreSettings.kill or {})[placement]}
end)

for point, placements in Table.iter.spairs(points, function (_, a, b)
return a > b
end) do
local placementRange = Array.sortBy(Array.extractKeys(placements), FnUtil.identity)
table.insert(scorePlacement, {
rangeStart = placementRange[1],
rangeEnd = placementRange[#placementRange],
score = point,
})
local newScores = {}
local lastData = {}
for placement, score in ipairs(scores) do
if Table.deepEquals(lastData, score) then
newScores[#newScores].rangeEnd = newScores[#newScores].rangeEnd + 1
else
table.insert(newScores, {
rangeStart = placement,
rangeEnd = placement,
killScore = score.killPoints,
placementScore = score.placementPoints,
})
end
lastData = score
end

return {
kill = scoreSettings.kill,
placement = scorePlacement,
}
return newScores
end

---@param match table
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/apexlegends/game_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function CustomGameSummary.getGameByMatchId(props)
idx = props.gameIdx,
children = {
CustomGameSummary._createGameDetails(game),
MatchSummaryWidgets.PointsDistribution{killScore = scoringData.kill, placementScore = scoringData.placement},
MatchSummaryWidgets.PointsDistribution{scores = scoringData},
SummaryHelper.standardGame(game)
}
}
Expand Down
33 changes: 0 additions & 33 deletions components/match2/wikis/apexlegends/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

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 @@ -81,38 +80,6 @@ function MatchFunctions.calculateMatchScore(opponents, maps)
end
end

---@param match table
---@return {score: table, status: table}
function MatchFunctions.parseSettings(match)
-- Score Settings
local scoreSettings = {
kill = tonumber(match.p_kill) or 1,
matchPointThreshold = tonumber(match.matchpoint),
placement = Array.mapIndexes(function(idx)
return match['opponent' .. idx] and (tonumber(match['p' .. idx]) or 0) or nil
end)
}

-- Up/Down colors
local statusSettings = Array.flatMap(Array.parseCommaSeparatedString(match.bg, ','), function (status)
local placements, color = unpack(Array.parseCommaSeparatedString(status, '='))
local pStart, pEnd = unpack(Array.parseCommaSeparatedString(placements, '-'))
local pStartNumber = tonumber(pStart) --[[@as integer]]
local pEndNumber = tonumber(pEnd) or pStartNumber
return Array.map(Array.range(pStartNumber, pEndNumber), function()
return color
end)
end)

return {
score = scoreSettings,
status = statusSettings,
settings = {
showGameDetails = Logic.nilOr(Logic.readBoolOrNil(match.showgamedetails), true),
}
}
end

---@param match table
---@param games table[]
---@param opponents table[]
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/apexlegends/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function CustomMatchSummary.getByMatchId(props)
idx = 0,
children = {
MatchSummaryWidgets.GamesSchedule{games = match.games},
MatchSummaryWidgets.PointsDistribution{killScore = scoringData.kill, placementScore = scoringData.placement},
MatchSummaryWidgets.PointsDistribution{scores = scoringData},
SummaryHelper.standardMatch(match),
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/fortnite/game_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function CustomGameSummary.getGameByMatchId(props)
idx = props.gameIdx,
children = {
CustomGameSummary._createGameDetails(game),
MatchSummaryWidgets.PointsDistribution{killScore = scoringData.kill, placementScore = scoringData.placement},
MatchSummaryWidgets.PointsDistribution{scores = scoringData},
SummaryHelper.standardGame(game)
}
}
Expand Down
33 changes: 0 additions & 33 deletions components/match2/wikis/fortnite/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

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 @@ -81,38 +80,6 @@ function MatchFunctions.calculateMatchScore(opponents, maps)
end
end


---@param match table
---@return {score: table, status: table}
function MatchFunctions.parseSettings(match)
-- Score Settings
local scoreSettings = {
kill = tonumber(match.p_kill) or 1,
placement = Array.mapIndexes(function(idx)
return match['opponent' .. idx] and (tonumber(match['p' .. idx]) or 0) or nil
end)
}

-- Up/Down colors
local statusSettings = Array.flatMap(Array.parseCommaSeparatedString(match.bg, ','), function (status)
local placements, color = unpack(Array.parseCommaSeparatedString(status, '='))
local pStart, pEnd = unpack(Array.parseCommaSeparatedString(placements, '-'))
local pStartNumber = tonumber(pStart) --[[@as integer]]
local pEndNumber = tonumber(pEnd) or pStartNumber
return Array.map(Array.range(pStartNumber, pEndNumber), function()
return color
end)
end)

return {
score = scoreSettings,
status = statusSettings,
settings = {
showGameDetails = Logic.nilOr(Logic.readBoolOrNil(match.showgamedetails), true),
}
}
end

---@param match table
---@param games table[]
---@param opponents table[]
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/fortnite/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function CustomMatchSummary.getByMatchId(props)
idx = 0,
children = {
MatchSummaryWidgets.GamesSchedule{games = match.games},
MatchSummaryWidgets.PointsDistribution{killScore = scoringData.kill, placementScore = scoringData.placement},
MatchSummaryWidgets.PointsDistribution{scores = scoringData},
SummaryHelper.standardMatch(match),
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/freefire/game_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function CustomGameSummary.getGameByMatchId(props)
idx = props.gameIdx,
children = {
CustomGameSummary._createGameDetails(game),
MatchSummaryWidgets.PointsDistribution{killScore = scoringData.kill, placementScore = scoringData.placement},
MatchSummaryWidgets.PointsDistribution{scores = scoringData},
SummaryHelper.standardGame(game)
}
}
Expand Down
33 changes: 0 additions & 33 deletions components/match2/wikis/freefire/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

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 @@ -81,38 +80,6 @@ function MatchFunctions.calculateMatchScore(opponents, maps)
end
end


---@param match table
---@return {score: table, status: table}
function MatchFunctions.parseSettings(match)
-- Score Settings
local scoreSettings = {
kill = tonumber(match.p_kill) or 1,
placement = Array.mapIndexes(function(idx)
return match['opponent' .. idx] and (tonumber(match['p' .. idx]) or 0) or nil
end)
}

-- Up/Down colors
local statusSettings = Array.flatMap(Array.parseCommaSeparatedString(match.bg, ','), function (status)
local placements, color = unpack(Array.parseCommaSeparatedString(status, '='))
local pStart, pEnd = unpack(Array.parseCommaSeparatedString(placements, '-'))
local pStartNumber = tonumber(pStart) --[[@as integer]]
local pEndNumber = tonumber(pEnd) or pStartNumber
return Array.map(Array.range(pStartNumber, pEndNumber), function()
return color
end)
end)

return {
score = scoreSettings,
status = statusSettings,
settings = {
showGameDetails = Logic.nilOr(Logic.readBoolOrNil(match.showgamedetails), true),
}
}
end

---@param match table
---@param games table[]
---@param opponents table[]
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/freefire/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function CustomMatchSummary.getByMatchId(props)
idx = 0,
children = {
MatchSummaryWidgets.GamesSchedule{games = match.games},
MatchSummaryWidgets.PointsDistribution{killScore = scoringData.kill, placementScore = scoringData.placement},
MatchSummaryWidgets.PointsDistribution{scores = scoringData},
SummaryHelper.standardMatch(match),
}
}
Expand Down
Loading

0 comments on commit 72433d6

Please sign in to comment.