Skip to content

Commit

Permalink
finish the canUseAutoScore, extract map loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz committed Oct 10, 2024
1 parent f69fb93 commit 90f66be
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 34 deletions.
11 changes: 8 additions & 3 deletions components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,16 @@ function MatchGroupInputUtil.getWalkoverType(opponents)
end
end

---@param match table
---@param dateProps {date: string, dateexact: boolean, timestamp: integer}
---@param maps {scores: integer[]?, winner: integer?}[]
---@return boolean
function MatchGroupInputUtil.canUseAutoScore(match, maps)
local matchHasStarted = MatchGroupUtil.computeMatchPhase(match) ~= 'upcoming'
function MatchGroupInputUtil.canUseAutoScore(dateProps, maps)
local matchPhase = MatchGroupUtil.computeMatchPhaseNew{
date = dateProps.date,
dateexact = dateProps.dateexact,
timestamp = dateProps.timestamp,
}
local matchHasStarted = matchPhase ~= 'upcoming'
local anyMapHasWinner = Table.any(maps, function(_, map)
return Logic.isNotEmpty(map.winner)
end)
Expand Down
15 changes: 15 additions & 0 deletions components/match2/commons/match_group_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,21 @@ function MatchGroupUtil.computeMatchPhase(match)
end
end

---Determines the phase of a match based on its properties.
---@param props {date: string?, dateexact: boolean?, timestamp: number?, finished?: boolean, winner: integer?}
---@return 'finished'|'ongoing'|'upcoming'
function MatchGroupUtil.computeMatchPhaseNew(props)
local isExact = Logic.readBoolOrNil(props.dateexact)
local matchStartTimestamp = props.timestamp or Date.readTimestampOrNil(props.date) or Date.defaultTimestamp
if props.winner or Logic.readBool(props.finished) then
return 'finished'
elseif isExact ~= false and matchStartTimestamp ~= Date.defaultTimestamp and matchStartTimestamp <= NOW then
return 'ongoing'
else
return 'upcoming'
end
end

---Normalizes subtypes (opponent, map) into a list
---@param match table
---@param type 'opponent'|'map'
Expand Down
64 changes: 33 additions & 31 deletions components/match2/wikis/rainbowsix/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ function CustomMatchGroupInput.processMatch(input, options)
local opponents = Array.mapIndexes(function(opponentIndex)
return MatchGroupInputUtil.readOpponent(input, opponentIndex, {})
end)
local games = MatchFunctions.extractMaps(input, #opponents)
local games = Array.mapIndexes(function (gameIndex)
return MatchGroupInputUtil.readGame(input, gameIndex, opponents)
end)
local bestof = MatchGroupInputUtil.getBestOf(nil, games)
games = MatchFunctions.removeUnsetMaps(games)

local dateDetails = MatchGroupInputUtil.readDate(input.date)
local tournamentContext = MatchGroupInputUtil.getTournamentContext(input)

local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(TODO, games)
local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(dateDetails, games)
and MatchFunctions.calculateMatchScore(games)
or nil
Array.forEach(opponents, function(opponent, opponentIndex)
Expand Down Expand Up @@ -84,39 +86,39 @@ end
--

---@param matchInput table
---@param opponentCount integer
---@return table[]
function MatchFunctions.extractMaps(matchInput, opponentCount)
local maps = {}

for _, input in Table.iter.pairsByPrefix(matchInput, 'map', {requireIndex = true}) do
local opponentInfo = Array.map(Array.range(1, opponentCount), function(opponentIndex)
local score, status = MatchGroupInputUtil.computeOpponentScore({
walkover = input.walkover,
winner = input.winner,
opponentIndex = opponentIndex,
score = input['score' .. opponentIndex],
}, MapFunctions.calculateMapScore(input))
return {score = score, status = status}
end)
---@param mapIndex integer
---@param opponents table[]
---@return table[]?
function MatchFunctions.readMap(matchInput, mapIndex, opponents)
local input = matchInput['map' .. mapIndex]
if not input then
return nil
end

local map = {
vod = input.vod,
extradata = MapFunctions.getExtraData(input, opponentCount),
finished = MatchGroupInputUtil.mapIsFinished(input),
scores = Array.map(opponentInfo, Operator.property('score'))
}

if map.finished then
map.resulttype = MatchGroupInputUtil.getResultType(input.winner, input.finished, opponentInfo)
map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo)
map.winner = MatchGroupInputUtil.getWinner(map.resulttype, input.winner, opponentInfo)
end
local opponentInfo = Array.map(opponents, function(_, opponentIndex)
local score, status = MatchGroupInputUtil.computeOpponentScore({
walkover = input.walkover,
winner = input.winner,
opponentIndex = opponentIndex,
score = input['score' .. opponentIndex],
}, MapFunctions.calculateMapScore(input))
return {score = score, status = status}
end)

local map = {
vod = input.vod,
extradata = MapFunctions.getExtraData(input, #opponents),
finished = MatchGroupInputUtil.mapIsFinished(input),
scores = Array.map(opponentInfo, Operator.property('score'))
}

table.insert(maps, input)
if map.finished then
map.resulttype = MatchGroupInputUtil.getResultType(input.winner, input.finished, opponentInfo)
map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo)
map.winner = MatchGroupInputUtil.getWinner(map.resulttype, input.winner, opponentInfo)
end

return maps
return map
end

-- Template:Map sets a default map name so we can count the number of maps.
Expand Down

0 comments on commit 90f66be

Please sign in to comment.